~ubuntu-branches/ubuntu/utopic/gozerbot/utopic

« back to all changes in this revision

Viewing changes to debian/gozerbot/usr/lib/python2.5/site-packages/gozerbot/examples.py

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Malcolm
  • Date: 2009-09-14 09:00:29 UTC
  • mfrom: (1.1.4 upstream) (3.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20090914090029-uval0ekt72kmklxw
Tags: 0.9.1.3-3
Changed dependency on python-setuptools to python-pkg-resources
(Closes: #546435) 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# gozerbot/examples.py
2
 
#
3
 
#
4
 
 
5
 
""" examples is a dict of example objects """
6
 
 
7
 
__copyright__ = 'this file is in the public domain'
8
 
 
9
 
import re
10
 
 
11
 
class Example(object):
12
 
 
13
 
    """ an example """
14
 
 
15
 
    def __init__(self, descr, ex):
16
 
        self.descr = descr
17
 
        self.example = ex
18
 
 
19
 
class Examples(dict):
20
 
 
21
 
    """ examples object is a dict """
22
 
 
23
 
    def add(self, name, descr, ex):
24
 
        """ add description and example """
25
 
        self[name.lower()] = Example(descr, ex)
26
 
 
27
 
    def size(self):
28
 
        """ return size of examples dict """
29
 
        return len(self.keys())
30
 
 
31
 
    def getexamples(self):
32
 
        """ get all examples in list """
33
 
        result = []
34
 
        for i in self.values():
35
 
            ex = i.example.lower()
36
 
            exampleslist = re.split('\d\)', ex)
37
 
            for example in exampleslist:
38
 
                if example:
39
 
                    result.append(example.strip())
40
 
        return result
41
 
 
42
 
    def getexamplesplug(self):
43
 
        """ get all examples in list """
44
 
        result = []
45
 
        for i in self.values():
46
 
            ex = i.example.lower()
47
 
            exampleslist = re.split('\d\)', ex)
48
 
            for example in exampleslist:
49
 
                if example:
50
 
                    result.append(example.strip())
51
 
        return result
52
 
 
53
 
examples = Examples()