Commits

Lynn Rees committed f04dcd6 Merge

- merg

Comments (0)

Files changed (6)

+# -*- 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)

reqs/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)

tests/test_text.py

 from webstring import TextTemplate
 
 
-class Testwebstring(unittest.TestCase):
+class TestTextString(unittest.TestCase):
 
     '''Test class for webstring text template'''
 

webstring/base.py

     '''
 
     def __init__(self, auto, **kw):
-        # controls if templates become object attrs of a root/group Template
+        # controls if templates become object attrs of a root/group template
         self._auto = auto
 
     def __repr__(self):
     Base for Templates with subtemplates (groups or fields).
     '''
 
-    def __init__(self, auto, omax, **kw):
+    def __init__(self, auto, maxlen, **kw):
         super(_Many, self).__init__(auto, **kw)
         # sets maximum allowed repetitions of a template
-        self._max = omax
+        self._max = maxlen
         # internal tracking structures
         self._fielddict, self._fields, self._filter = dict(), list(), set()
 
         # set group delimiter.
         self._groupmark = mark
 
-    def _setmax(self, omax):
+    def _setmax(self, maxlen):
         '''
         Sets the maximum repetition value for all Templates.
         '''
         # set group or root to max
-        self._max = omax
+        self._max = maxlen
         # set max on all children
         for field in self._fields:
-            field.max = omax
+            field.max = maxlen
 
     # property for setting a maximum repetition value
     max = property(lambda self: self._max, _setmax)
     Field base.
     '''
 
-    def __init__(self, auto, omax, **kw):
+    def __init__(self, auto, maxlen, **kw):
         super(_Field, self).__init__(auto, **kw)
         # maximum repetition value and internal trackers
-        self.max, self._siblings = omax, kw.get('siblings', list())
+        self.max, self._siblings = maxlen, kw.get('siblings', list())
         self._tempfields = kw.get('tempfields', list())
 
     def __imod__(self, data):
     Group base.
     '''
 
-    def __init__(self, auto, omax, **kw):
-        super(_Group, self).__init__(auto, omax, **kw)
+    def __init__(self, auto, maxlen, **kw):
+        super(_Group, self).__init__(auto, maxlen, **kw)
         # Internal trackers
         self._siblings = kw.get('siblings', list())
         self._tempfields = kw.get('tempfields', list())
     Root template base.
     '''
 
-    def __init__(self, auto, omax, **kw):
-        super(_Template, self).__init__(auto, omax, **kw)
+    def __init__(self, auto, maxlen, **kw):
+        super(_Template, self).__init__(auto, maxlen, **kw)
 
     def append(self, data):
         '''

webstring/markup.py

 # -*- coding: utf-8 -*-
-'''
-XML templates.
-'''
+'''XML templates.'''
 
 import md5 as _md5
 import random as _random
 
 
 def _copytree(tree):
-    '''
-    Copies an element.
-    '''
+    # copies an element.
     element = tree.makeelement(tree.tag, tree.attrib)
     element.tail, element.text = tree.tail, tree.text
     eappend = element.append
 
 
 def _copyetree(tree, builder):
-    '''
-    Copies an element to a different ElementTree implementation.
-    '''
+    # copies an element to a different ElementTree implementation.
     element = builder(tree.tag, dict(items(tree.attrib)))
     element.tail, element.text = tree.tail, tree.text
     eappend = element.append
 
 class _XMLMany(object):
 
-    '''
-    Base class for XML template with sub-templates.
-    '''
+    '''Base class for XML template with sub-templates.'''
 
     # XML attribute indicating fields and groups
     _mark = 'id'
 
 class _XMLOne(_Field, _NonRoot):
 
-    '''
-    Base XML template field.
-    '''
+    '''Base XML template field.'''
 
     # attribute indicating fields
     _mark = 'id'
 
-    def __init__(self, src, parent=None, auto=True, omax=25, **kw):
+    def __init__(self, src, parent=None, auto=True, maxlen=25, **kw):
         '''
         :argument src: element source
         :keyword parent: parent element of the source
         :keyword bool auto: turns automagic on and off
-        :keyword int omax: maximum number of times a field can repeat
+        :keyword int maxlen: maximum number of times a field can repeat
         '''
-        super(_XMLOne, self).__init__(auto, omax, **kw)
+        super(_XMLOne, self).__init__(auto, maxlen, **kw)
         self._group = _XMLGroup
         # parent and inline text template
         self._parent, self._template = parent, kw.get('template')
         return super(_XMLOne, self).__imod__(data)
 
     def __getitem__(self, key):
-        '''
-        Returns the attribute with the given key.
-        '''
+        '''Returns the attribute with the given key.'''
         return self._attrib[key]
 
     def __setitem__(self, key, value):
-        '''
-        Sets the XML attribute at the given key.
-        '''
+        '''Sets the XML attribute at the given key.'''
         # set attribute property if automagic on
         if hasattr(self, key):
             setattr(self, key, value)
             self._setattr(key, value)
 
     def __delitem__(self, key):
-        '''
-        Deletes an XML attribute.
-        '''
+        '''Deletes an XML attribute.'''
         # delete the property if automagic on
         try:
             delattr(self, _checkname(key))
             pass
 
     def __contains__(self, key):
-        '''
-        If an XML attribute is in a field.
-        '''
+        '''If an XML attribute is in a field.'''
         return key in self._attrib
 
     def __len__(self):
-        '''
-        Number of XML attributes in a field.
-        '''
+        '''Number of XML attributes in a field.'''
         return len(self._attrib)
 
     def __iter__(self):
-        '''
-        Iterate over internal XML attribute :class:`dict`.
-        '''
+        '''Iterate over internal XML attribute :class:`dict`.'''
         return iter(self._attrib)
 
     def _delmark(self):
 
     @property
     def current(self):
-        '''
-        Returns the current state of self.
-        '''
+        '''Returns the current state of self.'''
         return self._getcurrent(
             self._field, template=self._template, tattrib=self._tattrib,
         )
 
     @property
     def default(self):
-        '''
-        Returns the default state of self.
-        '''
+        '''Returns the default state of self.'''
         return self._getdefault(
             self._field, template=self._template, tattrib=self._tattrib,
         )
             delitem(item)
 
     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
 
 
 class _XMLGroup(_XMLMany, _Group, _NonRoot):
 
-    '''
-    XML group template.
-    '''
+    '''XML group template.'''
 
     _field = _XMLField
 
-    def __init__(self, src=None, parent=None, auto=True, omax=25, **kw):
+    def __init__(self, src=None, parent=None, auto=True, maxlen=25, **kw):
         '''
         :keyword src: element source
         :keyword parent: parent element of the source
         :keyword bool auto: turns automagic on and off
-        :keyword int omax: maximum number of times a field can repeat
+        :keyword int maxlen: maximum number of times a field can repeat
         '''
-        super(_XMLGroup, self).__init__(auto, omax, **kw)
+        super(_XMLGroup, self).__init__(auto, maxlen, **kw)
         self._parent = parent
         if hasattr(src, 'tag'):
             self._setelement(src)
 
     @property
     def current(self):
-        '''
-        Property that returns the current state of this group.
-        '''
+        '''Current state of this group.'''
         return self._getcurrent(_XMLGroup, templates=self._templates)
 
     @property
     def default(self):
-        '''
-        Property that returns the default state of this group.
-        '''
+        '''Default state of this group.'''
         return self._getdefault(_XMLGroup, templates=self._templates)
 
     def reset(self, **kw):
-        '''
-        Resets a group back to its default state.
-        '''
+        '''Resets group back to its default state. '''
         super(_XMLGroup, self).reset(templates=self._templates)
 
 
     _group = _XMLGroup
     _parent = None
 
-    def __init__(self, src=None, auto=True, omax=25, **kw):
+    def __init__(self, src=None, auto=True, maxlen=25, **kw):
         '''
         :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 maxlen: maximum number of times a template can repeat
         '''
-        super(Template, self).__init__(auto, omax, **kw)
+        super(Template, self).__init__(auto, maxlen, **kw)
         # process element if source is an element
         if hasattr(src, 'tag'):
             self._setelement(src)
                 field.groupmark = mark
 
     def _setxslt(self, stylesheet):
-        '''
-        Sets the XSLT stylesheet for a template.
-        '''
+        '''Sets XSLT stylesheet for template.'''
         self._xslt = XSLT(XML(stylesheet))
 
     def transform(self, stylesheet=None, **kw):
         '''
-        Transforms a template based on an XSLT stylesheet.
+        Transforms template based on XSLT stylesheet.
 
         :keyword str stylesheet: XSLT document
         :param kw: keyword arguments
         return u(self._xslt(self._tree, **kw))
 
     def xinclude(self):
-        '''
-        Processes any xinclude statements in the internal template.
-        '''
+        '''Processes xinclude statements in template.'''
         ElementTree(self._tree).xinclude()
 
     def fromfile(self, path):
         '''
-        Creates an internal element from a file source.
+        Creates element from file source.
 
         :argument str path: path to template source
         '''
 
     def fromstring(self, instring):
         '''
-        Creates an internal element from a :class:`str` source.
+        Creates element from :class:`str` source.
 
         :argument str instring: :class:`str` source for internal element
         '''
 
     def render(self, info=None, format='xml'):
         '''
-        :class:`str` version of the internal element.
+        :class:`str` version of element.
 
         :keyword info: data to substitute into an XML document
         :keyword str format: format of document
         return xtostring(self._tree)
 
     def reset(self):
-        '''
-        Return a :class:`template` to its default state.
-        '''
+        '''Return template to its default state.'''
         self.__init__(
             self._btree, self._auto, self._max, templates=self._templates
         )
 
 class HTMLTemplate(Template):
 
-    '''
-    HTML template.
-    '''
+    '''HTML template.'''
 
     def fromfile(self, path):
         '''
-        Creates an internal element from a file source.
+        Load template from file source.
 
-        :param str path: path to a template source
+        :param str path: path to template
         '''
         # try ordinary XML parsing
         try:
 
     def fromstring(self, instring):
         '''
-        Creates an internal element from a source.
+        Load template from string.
 
         :argument str path: source for internal template
         '''
 
     def render(self, info=None, format='html', encoding='unicode'):
         '''
-        A string version of the internal element's parent.
+        Render string from template.
 
         :keyword info: data to substitute into a document
         :keyword str format: HTML doctype to use for string
 
     def write(self, path, info=None, format='html', encoding='unicode'):
         '''
-        Writes the string of an internal element to a file.
+        Write rendered template to file.
 
         :argument str path: path of destination file
         :keyword info: data to substitute into a document

webstring/version.py

 Template engine where Python is the template language.
 '''
 
-__version__ = (0, 5, 0)
+__version__ = (0, 6, 0)