Commits

Lynn Rees committed 61db781

- update

Comments (0)

Files changed (10)

 include LICENSE.txt
 include MANIFEST.in
 include README.rst
-include requirements.txt
+include reqs/reqs.txt
 include setup.cfg
 recursive-include webstring *.py

depends/docs_requirements.txt

-sphinx
-sphinxcontrib.spelling
-lxml>=1.1.1
-stuf>=0.8.14

depends/fabfile.py

-# -*- coding: utf-8 -*-
-'''webstring fabfile'''
-
-from fabric.api import prompt, local, settings, env, lcd
-
-regup = '../setup.py register sdist --format=bztar,gztar,zip upload'
-nodist = 'rm -rf ../dist'
-sphinxup = '../setup.py upload_sphinx'
-
-
-def _promptup():
-    prompt('Enter tag: ', 'tag')
-    with settings(warn_only=True):
-        local('hg tag "%(tag)s"' % env)
-        local('hg push ssh://hg@bitbucket.org/lcrees/webstring')
-        local('hg push github')
-
-
-def _test(val):
-    truth = val in ['py26', 'py27', 'py31', 'py32', 'pypy']
-    if truth is False:
-        raise KeyError(val)
-    return val
-
-
-def docs():
-    with lcd('../docs/'):
-        local('make clean')
-        local('make html')
-        local('make linkcheck')
-        local('make doctest')
-
-
-def tox():
-    '''
-    test webstring
-    '''
-    with lcd('../'):
-        local('tox')
-
-
-def update_docs():
-    '''
-    update webstring docs
-    '''
-    docs()
-    with settings(warn_only=True):
-        local('hg ci -m docmerge')
-        local('hg push ssh://hg@bitbucket.org/lcrees/webstring')
-        local('hg push github')
-    local(sphinxup)
-
-
-def tox_recreate():
-    '''
-    recreate webstring test env
-    '''
-    with lcd('../'):
-        prompt(
-            'Enter testenv: [py26, py27, py31, py32, pypy]',
-            'testenv',
-            validate=_test,
-        )
-        local('tox --recreate -e %(testenv)s' % env)
-
-
-def release():
-    '''
-    release webstring
-    '''
-    docs()
-    local('hg update pu')
-    local('hg update next')
-    local('hg merge pu; hg ci -m automerge')
-    local('hg update maint')
-    local('hg merge default; hg ci -m automerge')
-    local('hg update default')
-    local('hg merge next; hg ci -m automerge')
-    local('hg update pu')
-    local('hg merge default; hg ci -m automerge')
-    _promptup()
-    local(regup)
-    local(sphinxup)
-    local(nodist)
-
-
-def releaser():
-    '''
-    webstring releaser
-    '''
-    docs()
-    _promptup()
-    local(regup)
-    local(sphinxup)
-    local(nodist)
-
-
-def inplace():
-    '''
-    in-place webstring
-    '''
-    docs()
-    with settings(warn_only=True):
-        local('hg push ssh://hg@bitbucket.org/lcrees/webstring')
-        local('hg push github')
-    local('../setup.py sdist --format=bztar,gztar,zip upload')
-    local(sphinxup)
-    local(nodist)
-
-
-def release_next():
-    '''
-    release webstring from next branch
-    '''
-    docs()
-    local('hg update maint')
-    local('hg merge default; hg ci -m automerge')
-    local('hg update default')
-    local('hg merge next; hg ci -m automerge')
-    local('hg update next')
-    local('hg merge default; hg ci -m automerge')
-    _promptup()
-    local(regup)
-    local(sphinxup)
-    local(nodist)

depends/requirements.txt

-stuf>=0.8.14
-lxml>=1.1.1

reqs/docs_reqs.txt

+sphinx
+sphinxcontrib.spelling
+lxml>=1.1.1
+stuf>=0.8.14
+# -*- coding: utf-8 -*-
+'''webstring fabfile'''
+
+from fabric.api import prompt, local, settings, env, lcd
+
+regup = '../setup.py register sdist --format=bztar,gztar,zip upload'
+nodist = 'rm -rf ../dist'
+sphinxup = '../setup.py upload_sphinx'
+
+
+def _promptup():
+    prompt('Enter tag: ', 'tag')
+    with settings(warn_only=True):
+        local('hg tag "%(tag)s"' % env)
+        local('hg push ssh://hg@bitbucket.org/lcrees/webstring')
+        local('hg push github')
+
+
+def _test(val):
+    truth = val in ['py26', 'py27', 'py31', 'py32', 'pypy']
+    if truth is False:
+        raise KeyError(val)
+    return val
+
+
+def docs():
+    with lcd('../docs/'):
+        local('make clean')
+        local('make html')
+        local('make linkcheck')
+        local('make doctest')
+
+
+def tox():
+    '''
+    test webstring
+    '''
+    with lcd('../'):
+        local('tox')
+
+
+def update_docs():
+    '''
+    update webstring docs
+    '''
+    docs()
+    with settings(warn_only=True):
+        local('hg ci -m docmerge')
+        local('hg push ssh://hg@bitbucket.org/lcrees/webstring')
+        local('hg push github')
+    local(sphinxup)
+
+
+def tox_recreate():
+    '''
+    recreate webstring test env
+    '''
+    with lcd('../'):
+        prompt(
+            'Enter testenv: [py26, py27, py31, py32, pypy]',
+            'testenv',
+            validate=_test,
+        )
+        local('tox --recreate -e %(testenv)s' % env)
+
+
+def release():
+    '''
+    release webstring
+    '''
+    docs()
+    local('hg update pu')
+    local('hg update next')
+    local('hg merge pu; hg ci -m automerge')
+    local('hg update maint')
+    local('hg merge default; hg ci -m automerge')
+    local('hg update default')
+    local('hg merge next; hg ci -m automerge')
+    local('hg update pu')
+    local('hg merge default; hg ci -m automerge')
+    _promptup()
+    local(regup)
+    local(sphinxup)
+    local(nodist)
+
+
+def releaser():
+    '''
+    webstring releaser
+    '''
+    docs()
+    _promptup()
+    local(regup)
+    local(sphinxup)
+    local(nodist)
+
+
+def inplace():
+    '''
+    in-place webstring
+    '''
+    docs()
+    with settings(warn_only=True):
+        local('hg push ssh://hg@bitbucket.org/lcrees/webstring')
+        local('hg push github')
+    local('../setup.py sdist --format=bztar,gztar,zip upload')
+    local(sphinxup)
+    local(nodist)
+
+
+def release_next():
+    '''
+    release webstring from next branch
+    '''
+    docs()
+    local('hg update maint')
+    local('hg merge default; hg ci -m automerge')
+    local('hg update default')
+    local('hg merge next; hg ci -m automerge')
+    local('hg update next')
+    local('hg merge default; hg ci -m automerge')
+    _promptup()
+    local(regup)
+    local(sphinxup)
+    local(nodist)
+stuf>=0.8.14
+lxml>=1.1.1

webstring/base.py

 
 from stuf.six import items
 
-# Exceptions
+# exceptions
 _exceptions = [
     'maximum allowed repetitions exceeded',
-    'invalid Template source',
+    'invalid template source',
     'invalid type for formatting',
     'not all arguments converted during formatting',
     'not enough arguments for format', '', '',
     'invalid inline template source',
     'delimiter "$" or "%" not found',
-    'invalid Template filter type',
+    'invalid template filter type',
 ]
 _Stemplate = string.Template
-# Illegal characters for Python names
+# illegal characters for Python names
 _ichar = '()[]{}@,:.`=;+-*/%&|^><\'"#\\$?!~'
-# Reserve webstring specific words
+# reserve webstring specific words
 kwlist.extend([
     'append', 'atemplates', 'current', 'default', 'exclude', 'fromfile',
     'fromstring', 'groupmark', 'include', 'mark', 'max', 'pipe', 'purge',
 
     def __add__(self, data):
         '''
-        Inserts data or another Template's fields after the internal
-        template and returns a modified copy of the Template.
+        Inserts data or another template's fields after the internal
+        template and returns a modified copy of the template.
         '''
         self.__iadd__(data)
         newself = self.current
     def __mul__(self, num):
         '''
         Inserts a copy of the internal field after the internal field "num"
-        number of times and returns a modified copy of the Template.
+        number of times and returns a modified copy of the template.
         '''
         self.__imul__(num)
         newself = self.current
     def __imul__(self, num):
         '''
         Inserts a copy of the internal field after the internal field "num"
-        number of times and the Template (self) is returned modified.
+        number of times and the template (self) is returned modified.
         '''
         # ensure "num" is not greater than maximum allowed repetitions
         if num <= self.max:
     def __mod__(self, data):
         '''
         Substitutes text data into the internal template and returns a
-        modified copy of the Template.
+        modified copy of the template.
         '''
         self.__imod__(data)
         newself = self.current
         '''
         For each item in a tuple, the internal template is copied, the item is
         substituted into the copy's template, and the copy is inserted after
-        the internal template. Finally, a modified copy of the Template
+        the internal template. Finally, a modified copy of the template
         is returned.
         '''
         self.__ipow__(data)
         '''
         For each item in a tuple, the internal template is copied, the content
         of the item is substituted into the copy's template, and the copy is
-        inserted after the internal template. Finally, the modified Template
+        inserted after the internal template. Finally, the modified template
         (self) is returned.
         '''
         if len(data) <= self.max:
     def pipe(self, info=None, format='xml'):
         '''
         Returns the string output of the internal template and resets the
-        Template.
+        template.
 
         :keyword info: data to substitute into a template
         :keyword str format: document format
 
     def write(self, path, info=None, format='xml'):
         '''
-        Writes a Template's :class:`str` output to a file.
+        Writes a template's :class:`str` output to a file.
 
         :argument path: output file path
         :keyword info: data to substitute into a template
 
     def __init__(self, auto, omax, **kw):
         super(_Many, self).__init__(auto, **kw)
-        # sets maximum allowed repetitions of a Template
+        # sets maximum allowed repetitions of a template
         self._max = omax
         # internal tracking structures
         self._fielddict, self._fields, self._filter = dict(), list(), set()
 
+    def __getitem__(self, key):
+        # try getting field by position from list
+        try:
+            return self._fields[key]
+        # try getting field by keyword from dictionary
+        except TypeError:
+            return self._fielddict[key]
+
+    def __delitem__(self, key):
+        # handle positional indexes
+        try:
+            # get field
+            obj = self._fields[key]
+            # get field name
+            for name, element in items(self._fielddict):
+                if element == obj:
+                    break
+        # handle keys
+        except TypeError:
+            name = key
+        # delete object attribute
+        self.__delattr__(name)
+
     def __imod__(self, data):
         '''
-        Substitutes text data into each field's template and the
-        modified Template (self) is returned.
+        Substitutes text data into each field's template and the modified
+        template (self) is returned.
         '''
         # get any templates
         try:
             raise TypeError(_exceptions[4])
         return self
 
-    def __getitem__(self, key):
-        # try getting field by position from list
-        try:
-            return self._fields[key]
-        # try getting field by keyword from dictionary
-        except TypeError:
-            return self._fielddict[key]
-
-    def __delitem__(self, key):
-        # handle positional indexes
-        try:
-            # get field
-            obj = self._fields[key]
-            # get field name
-            for name, element in items(self._fielddict):
-                if element == obj:
-                    break
-        # handle keys
-        except TypeError:
-            name = key
-        # delete object attribute
-        self.__delattr__(name)
-
     def __contains__(self, key):
-        # if a field of a given name is in a Template.
+        # if a field of a given name is in a template.
         return key in self._fielddict
 
     def __len__(self):
-        # number of fields in a Template.
+        # number of fields in a template.
         return len(self._fields)
 
     def __iter__(self):
             setattr(self, key, node)
 
     def _setmark(self, mark):
-        # sets the variable delimiter for all subtemplates in a Template.
+        # sets the variable delimiter for all subtemplates in a template.
         super(_Many, self)._setmark(mark)
         # set variable delimiter on all children
         for field in self._fields:
         '''
         Sets the maximum repetition value for all Templates.
         '''
-        # Set group or root to max
+        # set group or root to max
         self._max = omax
-        # Set max on all children
+        # set max on all children
         for field in self._fields:
             field.max = omax
 
-    # Property for setting a maximum repetition value
+    # property for setting a maximum repetition value
     max = property(lambda self: self._max, _setmax)
 
 
 class _Field(_Base):
 
-    '''Field base class.'''
+    '''
+    Field base.
+    '''
 
     def __init__(self, auto, omax, **kw):
         super(_Field, self).__init__(auto, **kw)
-        # Maximum repetition value and internal trackers
+        # maximum repetition value and internal trackers
         self.max, self._siblings = omax, kw.get('siblings', list())
         self._tempfields = kw.get('tempfields', list())
 
     def __imod__(self, data):
         '''
-        Substitutes text data into the internal element's text and
-        attributes and returns this field (self) modified.
+        Substitutes text data into the internal element's text and attributes
+        and returns this field (self) modified.
         '''
         if isinstance(data, basestring):
             self.text = data
         elif isinstance(data, dict):
-            # Try popping inline text content
+            # try popping inline text content
             try:
                 self.text = data.pop('text')
             except KeyError:
                 pass
-            # Try popping substitutions
+            # try popping substitutions
             try:
                 self.__ipow__(data.pop('sub'))
             except KeyError:
 
 class _Group(_Many):
 
-    '''Group base class.'''
+    '''
+    Group base.
+    '''
 
     def __init__(self, auto, omax, **kw):
         super(_Group, self).__init__(auto, omax, **kw)
 
 class _Template(_Many):
 
-    '''Base class for root Templates.'''
+    '''
+    Root template base.
+    '''
 
     def __init__(self, auto, omax, **kw):
         super(_Template, self).__init__(auto, omax, **kw)
 
     def append(self, data):
         '''
-        Makes a string or another Template's internal template part of
-        the Template's internal template.
+        Makes a string or another template's internal template part of the
+        template's internal template.
 
-        :param data: Template or element
+        :param data: template or element
         '''
         self.__iadd__(data)
 
     def exclude(self, *args):
         '''
-        Excludes fields or groups from a Template.
+        Excludes fields or groups from a template.
 
-        :param args: Names of a field or group
+        :param args: names of a field or group
         '''
-        # Remove fields from root
+        # remove fields from root
         checkname_ = _checkname
         fadd = self._filter.add
         sdelitem = self.__delitem__
         for arg in args:
             name = checkname_(arg)
-            # Add to internal filter list
+            # add to internal filter list
             fadd(name)
-            # Remove field if present
+            # remove field if present
             sdelitem(name)
-        # Remove fields from children
+        # remove fields from children
         for index, field in enumerate(self._fields):
-            # Run only on groups
+            # run only on groups
             if hasattr(field, 'groupmark'):
                 for arg in args:
                     name = checkname_(arg)
-                    # Remove subfield if present
+                    # remove subfield if present
                     field.__delitem__(name)
-                # Remove empty groups
+                # remove empty groups
                 if len(field) == 0:
                     sdelitem(index)
 
     def include(self, *args):
         '''
-        Includes a field or group in a Template.
+        Includes a field or group in a template.
 
-        @param args Names of fields or groups
+        :param args: names of fields or groups
         '''
-        # Remove from internal tracker
+        # remove from internal tracker
         self._filter -= set(args)
         self.reset()

webstring/markup.py

 # -*- coding: utf-8 -*-
-'''XML template.'''
+'''
+XML templates.
+'''
 
 import md5 as _md5
 import random as _random
 )
 
 # HTML 5 doctype
-_html5 = u'<!DOCTYPE html>'
+_html5 = u('<!DOCTYPE html>')
 # XHTML 1.0 strict doctype
-_xhtml10 = u'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" ' \
+_xhtml10 = u(
+    '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" '
     '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'
+)
 # XHTML 1.1 strict doctype
-_xhtml11 = u'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" ' \
+_xhtml11 = u(
+    '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" '
     '"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">'
+)
 
 
 def _copytree(tree):
 class _XMLMany(object):
 
     '''
-    Base class for XML Templates with sub-templates.
+    Base class for XML template with sub-templates.
     '''
 
     # XML attribute indicating fields and groups
 
     def __iadd__(self, data):
         '''
-        Inserts an element or another Template's elements after the internal
-        element and this Template (self) is returned modified.
+        Inserts an element or another template's elements after the internal
+        element and this template (self) is returned modified.
         '''
-        # process Templates
+        # process template
         if hasattr(data, 'mark'):
             # get fresh copy of data (needed for lxml compatibility)
             if data._parent is not None:
                 data = data.current
             # add to _tempfields
             self._tempfields.append(data)
-            # make Template's internal tree the data
+            # make template's internal tree the data
             data = data._tree
         # process elements
         if hasattr(data, 'tag'):
 
     def append(self, data):
         '''
-        Makes an element or another Template's elements children of this
-        Template's internal element.
+        Makes an element or another template's elements children of this
+        template's internal element.
 
-        :argument data: :class:`Template` or element
+        :argument data: :class:`template` or element
         '''
         # process elements
         if hasattr(data, 'tag'):
             # make element child of internal element
             self._tree.append(data)
-        # process Templates
+        # process template
         elif hasattr(data, 'mark'):
-            # make the other Template's children children of internal element
+            # make the other template's children children of internal element
             self._tree.append(data._tree)
             self._tempfields.append(data)
         else:
 
     def reset(self, **kw):
         '''
-        Returns a :class:`Template` object to its default state.
+        Returns a :class:`template` object to its default state.
         '''
         # remove any new siblings
         remove = self._parent.remove
         if isinstance(value, basestring):
             self._tree.set(key, value)
         elif isinstance(value, dict):
-            # try string.Template substitution
+            # try string.template substitution
             try:
                 self._tree.set(key, self._tattrib[key].substitute(value))
             # try string interpolation
     def _settemplate(self, text):
         # sets inline text templates for the internal element.
         if isinstance(text, basestring):
-            # make string.Template instance if delimiter '$' found.
+            # make string.template instance if delimiter '$' found.
             if '$' in text:
                 self._template = _Stemplate(text)
             # use standard Python format string if delimiter '%' found
         if isinstance(text, basestring):
             self._tree.text = text
         elif isinstance(text, dict):
-            # try string.Template substitution
+            # try string.template substitution
             try:
                 self._tree.text = self._template.substitute(text)
             # try string interpolation
             # set template for each item in attrib dict
             Stemplate = _Stemplate
             for key, value in items(attr):
-                # make string.Template instance if delimiter '$' is found
+                # make string.template instance if delimiter '$' is found
                 if '$' in value:
                     tattrib[key] = Stemplate(value)
                 # use standard Python format string if delimiter '%' found
 
     def reset(self, **kw):
         '''
-        Return :class:`Template` object to its default state.
+        Return :class:`template` object to its default state.
         '''
         super(_XMLOne, self).reset(
             template=self._template, tattrib=self._tattrib,
 
 class _XMLField(object):
 
-    '''Dispatcher for XML template fields.'''
+    '''
+    Dispatcher for XML template fields.
+    '''
 
     _group, _klass = None, _XMLOne
 
         '''
         :keyword src: path, string, or element source
         :keyword bool auto: turns automagic on or off
-        :keyword int omax: maximum number of times a Template can repeat
+        :keyword int omax: maximum number of times a template can repeat
         '''
         super(Template, self).__init__(auto, omax, **kw)
         # process element if source is an element
 
     def __iadd__(self, data):
         '''
-        Inserts an element or another Template's internal elements after
-        the internal element and returns the modified Template (self).
+        Inserts an element or another template's internal elements after
+        the internal element and returns the modified template (self).
 
         :argument data: template or element
         '''
         # process element
         if hasattr(data, 'tag'):
             self._tree.append(data)
-        # process Template
+        # process template
         elif hasattr(data, 'mark'):
-            # make internal element of other Template child of this internal
+            # make internal element of other template child of this internal
             # element
             self._tree.append(_copytree(data._tree))
-            # extend Template's internal fields with group Template's fields
+            # extend template's internal fields with group template's fields
             if hasattr(data, 'groupmark'):
                 self._fields.extend(data._fields)
-            # append standalone fields to Template's field's
+            # append standalone fields to template's field's
             else:
                 self._fields.append(data)
         else:
                     addgroup(element, child)
                 except KeyError:
                     pass
-            # make new group Template w/o passing group's element to __init__
+            # make new group template w/o passing group's element to __init__
             node = self._group(None, parent, self._auto, self._max)
             # add self's filter to avoid duplicate children
             node._filter = self._filter
             # process group's element
             node._setelement(child)
-            # only attach groups with children to root Template
+            # only attach groups with children to root template
             if len(node):
                 self._setfield(name, node)
 
 
     def reset(self):
         '''
-        Return a :class:`Template` to its default state.
+        Return a :class:`template` to its default state.
         '''
         self.__init__(
             self._btree, self._auto, self._max, templates=self._templates
         )
 
-    # create property that returns the current Template state
+    # create property that returns the current template state
     current = property(lambda self: Template(_copytree(self._tree),
         self._auto, self._max, templates=self._templates))
-    # create property that returns the default Template state
+    # create property that returns the default template state
     default = property(lambda self: Template(_copytree(self._btree),
         self._auto, self._max, templates=self._templates))
     # XSLT property

webstring/text.py

 # -*- coding: utf-8 -*-
-'''Text template base classes.'''
+'''
+Text templates.
+'''
 
 import re
 from copy import deepcopy
 
+from stuf.six import u
+
 from webstring.base import _Template, _Field, _Group, _exceptions, _checkname
 
-__all__ = ['TextTemplate', 'WSGITextTemplate', 'texttemplate']
+__all__ = ('TextTemplate', 'texttemplate')
 
-# Default variable and group delimiter
+# default variable and group delimiter
 MARK = GROUPMARK = '$'
-# Variable and group discovery regex
+# variable and group discovery regex
 PATTERN = r'%s{2}(.+?)%s{2}|%s{1}(\w+?)%s{1}'
 
 
 def getpattern(mark=MARK, group=GROUPMARK):
     '''
-    Fetches a regex pattern set with the current delimiters for a Template.
+    Get regular expression pattern with current delimiters for a template set.
 
-    @param mark Variable delimiter (default: MARK)
-    @param group Group delimiter (default: GROUPMARK)
+    :keyword str mark: variable delimiter
+    :keyword str group: group delimiter
     '''
-    # Escape delimiters
+    # escape delimiters
     mark, group = re.escape(mark), re.escape(group)
-    # Arrange in tuple
+    # arrange in tuple
     marks = (group, group, mark, mark)
-    # Return compiled regex pattern
     return re.compile(PATTERN % marks, re.DOTALL | re.UNICODE)
 
 
-# Default regex pattern
+# default regex pattern
 _match = getpattern()
 
 
 class _NonRoot(object):
 
     '''
-    Base class for non-root text Templates.
+    Base for non-root text templates.
     '''
 
     def append(self, data):
         '''
-        Appends a string or another Template's template to the Template's
-        internal template.
+        Appends string or template to this template.
 
-        @param data Template or string
+        :argument data: template or string
         '''
         return self.__iadd__(data)
 
-    # Create property that returns the current state
+    # create property that returns the current state
     current = property(lambda self: deepcopy(self))
 
 
 class _TextField(_Field, _NonRoot):
 
-    '''Base class for Fields.'''
+    '''
+    Text field base.
+    '''
 
-    # Default variable delimiter
+    # default variable delimiter
     _mark = MARK
 
-    def __init__(self, name, auto=True, omax=25, **kw):
+    def __init__(self, name, auto=True, maxlen=25, **kw):
         '''
-        @param src Field name
-        @param auto Turns automagic on and off (default: True)
-        @param omax Maximum number of times a field can repeat (default: 25)
+        :argument str name: field name
+        :keyword bool auto: turns automagic on and off
+        :keyword int maxlen: maximum number of times a field can repeat
         '''
-        super(_TextField, self).__init__(auto, omax, **kw)
+        super(_TextField, self).__init__(auto, maxlen, **kw)
         self.__name__ = name
-        # Set text to empty unicode string
-        self.text = self._btext = u''
+        # set text to empty unicode string
+        self.text = self._btext = u('')
 
     def __iadd__(self, data):
         '''
-        Inserts a string or another Template's strings after the internal
-        string and the Field (self) is returned modified.
+        Inserts string or template after current content.
         '''
-        # Process strings
+        # process strings
         if isinstance(data, basestring):
-            # Insert into sibling tracking list
+            # insert into sibling tracking list
             self._siblings.append(data)
-        # Process Templates
+        # process Templates
         elif hasattr(data, 'mark'):
-            # Append rendered string of other Templates
+            # append rendered string of other Templates
             self._siblings.append(data.render())
         else:
             raise TypeError(_exceptions[2])
 
     def render(self, info=None, format='text', encoding='utf-8'):
         '''
-        Returns a string version of this Field.
+        Get string version of field.
 
-        @param info Data to substitute into a template (default: None)
-        @param format Text format (default: 'text')
-        @param encoding Encoding of return string (default: 'utf-8')
+        :keyword info: data to substitute into template
+        :keyword str format: text format
+        :keyword str encoding: encoding of output
         '''
         if info is not None:
             self.__imod__(info)
-        # Join internal text with any sibling text
+        # join internal text with any sibling text
         self.text = u''.join([self.text, u''.join(self._siblings)])
-        # Return with encoding
+        # return with encoding
         return self.text.encode(encoding)
 
     def reset(self, **kw):
         '''
-        Returns a Template object to its default state.
+        Return template to original version.
         '''
         self.__init__(self.__name__, self._auto, self.max)
 
-    # Sets the delimiter for template variables
+    # sets the delimiter for template variables
     mark = property(lambda self: self._mark, _Field._setmark)
-    # Create property that returns the default Template state
+    # create property that returns the default Template state
     default = property(
         lambda self: _TextField(self.__name__, self._auto, self.max)
     )
 class _TextMany(object):
 
     '''
-    Base class for text root and group Templates.
+    Text root and group template base.
     '''
 
-    # Variable and group delimiters
+    # variable and group delimiters
     _mark, _groupmark = MARK, GROUPMARK
 
-    def __init__(self, auto, omax, **kw):
-        super(_TextMany, self).__init__(auto, omax, **kw)
-        # Assign match object to internal reference
+    def __init__(self, auto, maxlen, **kw):
+        super(_TextMany, self).__init__(auto, maxlen, **kw)
+        # assign match object to internal reference
         self._match = _match
 
     def __delattr__(self, attr):
-        '''
-        Delete a _TextMany attribute.
-        '''
         try:
-            # Try removing field
+            # try removing field
             try:
-                # Delete from internal field dictionary
+                # delete from internal field dictionary
                 obj = self._fielddict.pop(attr)
-                # Get object's index
+                # get object's index
                 index = self._fields.index(obj)
-                # Remove from internal field list
+                # remove from internal field list
                 self._fields.remove(obj)
                 splits, cnt = self._template.split('%s'), 0
-                # Remove '%s' from template string
+                # remove '%s' from template string
                 for idx, item in enumerate(splits):
-                    # Find a split point
+                    # find a split point
                     if item.rstrip() == u'':
-                        # Find the corresponding split point
+                        # find the corresponding split point
                         if cnt == index:
-                            # Remove the split point and break
+                            # remove the split point and break
                             del splits[idx]
                             break
-                        # Increment separate counter
+                        # increment separate counter
                         cnt += 1
-                # Recreate internal template
+                # recreate internal template
                 self._template = '%s'.join(splits)
             except KeyError:
                 pass
-        # Always delete object attribute if set
+        # always delete object attribute if set
         finally:
             if hasattr(self, attr):
                 object.__delattr__(self, attr)
 
     def _addfield(self, name):
-        '''
-        Adds a field from an element.
-        '''
-        # Check if processed already
+        # adds a field from an element
         if name not in self._filter:
-            # Add to filter list if unprocessed
+            # add to filter list if unprocessed
             self._filter.add(name)
-            # Add child as field
+            # add child as field
             self._setfield(name, _TextField(name, self._auto, self._max))
 
     def render(self, info=None, format='text', encoding='utf-8'):
         '''
-        Returns the string version of the internal template's current state.
+        Get string rendering of template.
 
-        @param info Data to substitute into internal template (default: None)
-        @param format Format of document (default:'text')
-        @param encoding Encoding type for output string (default: 'utf-8')
+        :keyword info: data to substitute into template
+        :keyword str format: format of document
+        :keyword str encoding: encoding type for output
         '''
         if info is not None:
             self.__imod__(info)
-        # Render internal fields and store in tuple
+        # render internal fields and store in tuple
         content = tuple(i.render(None, format, encoding) for i in self._fields)
-        # Interpolate into template
+        # interpolate into template
         self._text = self._template % content
-        # Output w/ correct encoding
+        # output with correct encoding
         return self._text.encode(encoding)
 
     def reset(self, **kw):
         '''
-        Returns a Template object to its default state.
+        Returns template to original version.
         '''
         self.__init__(self._btext, self._auto, self._max)
 
 
 class _TextGroup(_TextMany, _Group, _NonRoot):
 
-    '''Class for text group Templates.'''
+    '''
+    Text group template.
+    '''
 
-    def __init__(self, src=None, auto=True, omax=25, **kw):
+    def __init__(self, src=None, auto=True, maxlen=25, **kw):
         '''
-        @param src Template string (default: None)
-        @param auto Turns automagic on and off (default: True)
-        @param omax Maximum number of times a group can repeat (default: 25)
+        :keyword src: template string
+        :keyword bool auto: turns automagic on and off
+        :keyword int maxlen: maximum number of times a group can repeat
         '''
-        super(_TextGroup, self).__init__(auto, omax, **kw)
-        # Internal temp field tracker and temp template
+        super(_TextGroup, self).__init__(auto, maxlen, **kw)
+        # internal temp field tracker and temp template
         self._tempfields, self._ttemplate = list(), ''
         if src is not None:
             self._settemplate(src)
 
     def __iadd__(self, data):
         '''
-        Inserts a string or another Template's strings after the internal
-        string and the Template (self) is returned modified.
+        Inserts string or template after current content.
         '''
-        # Process strings
+        # process strings
         if isinstance(data, basestring):
-            # Append string onto internal template
+            # append string onto internal template
             self._template = u''.join([self._template, data])
-        # Process Templates
+        # process templates
         elif hasattr(data, 'mark'):
             if hasattr(data, 'groupmark'):
-                # Add group-like Template fields to _tempfield tracker
+                # add group-like template fields to _tempfield tracker
                 self._tempfields.extend(data._fields)
-                # Add group-like Template's template to temporary template
-                self._ttemplate = u''.join([self._ttemplate, data._template])
+                # add group-like template's template to temporary template
+                self._ttemplate = u('').join((self._ttemplate, data._template))
             else:
-                # Add fields to _tempfield tracker
+                # add fields to _tempfield tracker
                 self._tempfields.append(data)
-                # Add delimiter onto temp template
-                self._ttemplate = u''.join([self._ttemplate, '%s'])
+                # add delimiter onto temp template
+                self._ttemplate = u('').join((self._ttemplate, u('%s')))
         else:
             raise TypeError(_exceptions[2])
         return self
     def __deepcopy__(self, memo):
         # Python 2.4 deepcopy copies regexes while Python 2.5 does not
         idict = self.__dict__
-        # Remove _match regex if present
+        # remove _match regex if present
         try:
             match = idict.pop('_match')
-        # Use global if object does not have _match attribute
+        # use global if object does not have _match attribute
         except KeyError:
             match = _match
-        # Deep copy original object's __dict__
+        # deep copy original object's __dict__
         ndict = deepcopy(idict)
-        # Re-add _match object
+        # re-add _match object
         ndict['_match'] = match
-        # Create blank group Template
+        # create blank group template
         cls = _TextGroup()
-        # Update with self's dictionary
+        # update with self's dictionary
         cls.__dict__.update(ndict)
         return cls
 
     def _changematch(self):
-        '''
-        Changes the delimiter regex pattern.
-        '''
-        self._match = getpattern(self._mark, self._groupmark)
-        # Change delimiter on children
+        # changes the delimiter regex pattern
+        match = self._match = getpattern(self._mark, self._groupmark)
+        # change delimiter on children
         for field in self._fields:
             if hasattr(field, 'groupmark'):
-                field._match = self._match
+                field._match = match
 
     def _setgmark(self, mark):
-        '''
-        Sets the group delimiter for the Template and its children.
-        '''
+        # sets the group delimiter for the template and its children
         super(_TextGroup, self)._setgmark(mark)
         self._changematch()
 
     def _setmark(self, mark):
-        '''
-        Sets the variable delimiter for the Template and its children.
-        '''
+        # sets the variable delimiter for the template and its children
         super(_TextGroup, self)._setmark(mark)
         self._changematch()
 
     def _settemplate(self, instr):
-        '''
-        Sets the internal group template.
-        '''
-        # Iterate over any found fields
+        # sets the internal group template
+        addfield = self._addfield
+        # iterate over any found fields
         for mo in self._match.finditer(instr):
             _, second = mo.groups()
-            # Extract field if found
+            # extract field if found
             if second is not None:
-                self._addfield(second)
-        # Check if field is empty
+                addfield(second)
+        # check if field is empty
         if self._fields:
-            # Create internal template
+            # create internal template
             self._template = self._match.sub('%s', instr)
-            # Create text stubs and backup text
+            # create text stubs and backup text
             self._text, self._btext = u'', instr
 
     def render(self, info=None, format='text', encoding='utf-8'):
         '''
-        Returns the string version of the internal template's current state.
+        Returns the string rendering of current template.
 
-        @param info Data to substitute into internal template (default: None)
-        @param format Format of document (default:'text')
-        @param encoding Encoding type for output string (default: 'utf-8')
+        :keyword info: data substituted into template
+        :keyword str format: format of document
+        keyword str encoding: encoding for outpu
         '''
-        # Run superclass render
+        # run superclass render
         text = super(_TextGroup, self).render(info, format, encoding)
-        # Render any tempfield siblings and store in tuple
+        # render any tempfield siblings and store in tuple
         content = tuple(
             i.render(None, format, encoding) for i in self._tempfields
         )
-        # Join existing content with temporary content
+        # join existing content with temporary content
         self._text = u''.join([text, self._ttemplate % content])
-        # Return with correct encoding
+        # return with correct encoding
         return self._text.encode(encoding)
 
-    # Sets the delimiter for template variables
+    # sets the delimiter for template variables
     mark = property(lambda self: self._mark, _setmark)
-    # Sets the delimiter for template groups
+    # sets the delimiter for template groups
     groupmark = property(lambda self: self._groupmark, _setgmark)
-    # Create property that returns the default Template state
+    # create property that returns the default template state
     default = property(
         lambda self: _TextGroup(self._btext, self._auto, self._max)
     )
 class TextTemplate(_TextMany, _Template):
 
     '''
-    Text root Template class.
+    Text root template.
     '''
 
     __name__ = 'root'
-    # Pattern to split group name from group template
+    # pattern to split group name from group template
     _groupbr = re.compile('(\w+)(\W.+)', re.DOTALL | re.UNICODE)
 
-    def __init__(self, src=None, auto=True, omax=25, **kw):
+    def __init__(self, src=None, auto=True, maxlen=25, **kw):
         '''
-        @param src Path or string source (default: None)
-        @param auto Turns automagic on or off (default: True)
-        @param omax Max number of times a Template can repeat (default: 25)
+        :keyword src: file path or string source
+        :keyword bool auto: turns automagic on or off
+        :keyword int maxlen: maximum number of times a template can repeat
         '''
-        super(TextTemplate, self).__init__(auto, omax, **kw)
-        # Check if source exists
+        super(TextTemplate, self).__init__(auto, maxlen, **kw)
+        # check if source exists
         if src is not None:
-            # Try reading text source from a file
+            # try reading text source from a file
             try:
                 self.fromfile(src)
             except IOError:
-                # Try reading from a string
+                # try reading from  string
                 try:
                     self.fromstring(src)
                 except SyntaxError:
 
     def __iadd__(self, data):
         '''
-        Inserts a string or another Template's strings after the internal
-        string and the Template (self) is returned modified.
+        Inserts string or template after current content.
         '''
-        # Process strings
+        # process strings
         if isinstance(data, basestring):
-            # Append string to internal template
+            # append string to internal template
             self._template = u''.join([self._template, data])
-        # Process Templates
+        # process templates
         elif hasattr(data, 'mark'):
             if hasattr(data, 'groupmark'):
-                # Extend internal fields with other Template's fields
+                # extend internal fields with other template's fields
                 self._fields.extend(data._fields)
-                # Append other Template's internal template
+                # append other template
                 self._template = u''.join([self._template, data._template])
             else:
-                # Append field to internal field list
+                # append field to internal field list
                 self._fields.append(data)
-                # Append delimiter to internal template
+                # append delimiter to internal template
                 self._template = u''.join([self._template, '%s'])
         else:
             raise TypeError(_exceptions[2])
         return self
 
     def __deepcopy__(self, memo):
-        '''
-        Customizes deep copies w/ 'deepcopy'.
-        '''
-        # Python 2.4 deepcopy copies regex objects while Python 2.5 does not
+        # python 2.4 deepcopy copies regex objects while Python 2.5 does not
         idict = self.__dict__
-        # Remove _match regex if present
+        # remove _match regex if present
         try:
             match = idict.pop('_match')
-        # Use global if object does not have _match attribute
+        # use global if object does not have _match attribute
         except KeyError:
             match = _match
-        # Deep copy original object's __dict__
+        # deep copy original object's __dict__
         ndict = deepcopy(idict)
-        # Re-add _match object
+        # re-add _match object
         ndict['_match'] = match
-        # Create blank group Template
+        # create blank group template
         cls = _TextGroup()
-        # Update with deepcopied dictionary
+        # update with deepcopied dictionary
         cls.__dict__.update(ndict)
-        # Return copied class
         return cls
 
     def _addgroup(self, group):
-        '''
-        Creates group Templates.
-        '''
-        # Separate group name and template
+        # create group templates
         realname, template = self._groupbr.match(group).groups()
+        # separate group name and template
         name = _checkname(realname)
-        # Check if group already processed
+        # check if group already processed
         if name not in self._filter:
-            # Mark as processed
+            # mark as processed
             self._filter.add(name)
-            # Make new group Template w/o passing child
+            # make new group template without passing child
             node = _TextGroup(template, self._auto, self._max)
-            # Name group
+            # name group
             node.__name__ = name
-            # Set field
+            # set field
             self._setfield(name, node)
 
     def _setgmark(self, mark):
-        '''
-        Sets the group delimiter for the Template and its children.
-        '''
+        # set group delimiter for template and its children.
         super(TextTemplate, self)._setgmark(mark)
         self._changematch()
 
     def _setmark(self, mark):
-        '''
-        Sets the variable delimiter for the Template and its children.
-        '''
+        # set variable delimiter for template and its children.
         super(TextTemplate, self)._setmark(mark)
         self._changematch()
 
     def fromfile(self, path):
         '''
-        Creates an internal element from a file source.
+        Create element from file source.
 
-        @param path Path to source
+        :argument str path: source file
         '''
         self.fromstring(open(path, 'rb').read())
 
     def fromstring(self, instr):
         '''
-        Creates an internal template from a string source.
+        Create template from source string.
 
-        @param instr String source
+        :argument str instr: template source
         '''
-        # Extract fields, groups from source
+        # extract fields, groups from source
         addgroup = self._addgroup
         addfield = self._addfield
         for mo in self._match.finditer(instr):
             first, second = mo.groups()
-            # Add groups
+            # add groups
             if first is not None:
                 addgroup(first)
-            # Add fields
+            # add fields
             elif second is not None:
                 addfield(second)
-        # Only initialize Template's w/ fields
+        # pnly initialize templates with fields
         if self._fields:
-            # Create internal template
+            # internal template
             self._template = self._match.sub(u'%s', instr)
-            # Create text stub and backup text
-            self._text, self._btext = u'', instr
+            # text stub
+            self._text = u('')
+            # backup text
+            self._btext = instr
 
-    # Sets the delimiter for template variables
+    # sets the delimiter for template variables
     mark = property(lambda self: self._mark, _setmark)
-    # Sets the delimiter for template variables
+    # sets the delimiter for template variables
     groupmark = property(lambda self: self._groupmark, _setgmark)
-    # Create property that returns the current Template state
+    # create property that returns the current template state
     current = property(lambda self: deepcopy(self))
-    # Create property that returns the default Template state
+    # create property that returns the default template state
     default = property(
         lambda self: TextTemplate(self._btext, self._auto, self._max)
     )