Skip to content

Commit

Permalink
Docstring cleanups from review.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamadden committed Sep 28, 2018
1 parent 8da1212 commit e313ece
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 40 deletions.
16 changes: 8 additions & 8 deletions src/zope/configuration/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ def processFile(self, filename):
>>> d = os.path.dirname(zope.configuration.__file__)
>>> c.processFile('bar.zcml')
True
>>> c.processFile('bar.zcml')
>>> c.processFile(os.path.join(d, 'bar.zcml'))
False
"""
path = self.path(filename)
Expand Down Expand Up @@ -397,7 +397,7 @@ def action(self, discriminator, callable=None, args=(), kw=None, order=0,
>>> from zope.configuration.tests.directives import f
>>> c.action(1, f, (1, ), {'x': 1})
>>> from pprint import PrettyPrinter
>>> pprint=PrettyPrinter(width=60).pprint
>>> pprint = PrettyPrinter(width=60).pprint
>>> pprint(c.actions)
[{'args': (1,),
'callable': f,
Expand Down Expand Up @@ -550,22 +550,22 @@ class ConfigurationAdapterRegistry(object):
>>> from zope.configuration.config import ConfigurationMachine
>>> r = ConfigurationAdapterRegistry()
>>> c = ConfigurationMachine()
>>> r.factory(c, ('http://www.zope.com','xxx'))
>>> r.factory(c, ('http://www.zope.com', 'xxx'))
Traceback (most recent call last):
...
ConfigurationError: ('Unknown directive', 'http://www.zope.com', 'xxx')
>>> def f():
... pass
>>> r.register(IConfigurationContext, ('http://www.zope.com', 'xxx'), f)
>>> r.factory(c, ('http://www.zope.com','xxx')) is f
>>> r.factory(c, ('http://www.zope.com', 'xxx')) is f
True
>>> r.factory(c, ('http://www.zope.com','yyy')) is f
>>> r.factory(c, ('http://www.zope.com', 'yyy')) is f
Traceback (most recent call last):
...
ConfigurationError: ('Unknown directive', 'http://www.zope.com', 'yyy')
>>> r.register(IConfigurationContext, 'yyy', f)
>>> r.factory(c, ('http://www.zope.com','yyy')) is f
>>> r.factory(c, ('http://www.zope.com', 'yyy')) is f
True
Test the documentation feature:
Expand Down Expand Up @@ -714,7 +714,7 @@ def execute_actions(self, clear=True, testing=False):
>>> from zope.configuration.config import ConfigurationMachine
>>> output = []
>>> def f(*a, **k): #* syntax highlighting
>>> def f(*a, **k):
... output.append(('f', a, k))
>>> context = ConfigurationMachine()
>>> context.actions = [
Expand Down Expand Up @@ -1580,7 +1580,7 @@ def toargs(context, schema, data):
>>> context = ConfigurationMachine()
>>> from pprint import PrettyPrinter
>>> pprint=PrettyPrinter(width=50).pprint
>>> pprint = PrettyPrinter(width=50).pprint
>>> pprint(toargs(context, schema,
... {'in': u'1', 'f': u'1.2', 'n': u'bob', 'x': u'x.y.z',
Expand Down
52 changes: 26 additions & 26 deletions src/zope/configuration/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@


class PythonIdentifier(schema_PythonIdentifier):
"""
r"""
This class is like `zope.schema.PythonIdentifier`.
Expand All @@ -70,14 +70,14 @@ class PythonIdentifier(schema_PythonIdentifier):
>>> for value in (u'foo', u'foo3', u'foo_', u'_foo3', u'foo_3', u'foo3_'):
... _ = field.fromUnicode(value)
>>> from zope.schema import ValidationError
>>> for value in (u'3foo', u'foo:', u'\\\\', u''):
>>> for value in (u'3foo', u'foo:', u'\\', u''):
... try:
... field.fromUnicode(value)
... except ValidationError:
... print('Validation Error ' + repr(value))
Validation Error '3foo'
Validation Error 'foo:'
Validation Error '\\\\'
Validation Error '\\'
Validation Error ''
.. versionchanged:: 4.2.0
Expand Down Expand Up @@ -112,7 +112,7 @@ def _validate(self, value):
self.value_type.validate(value)

def fromUnicode(self, value):
"""
r"""
Find and return the module global at the path *value*.
>>> d = {'x': 1, 'y': 42, 'z': 'zope'}
Expand All @@ -127,7 +127,7 @@ def fromUnicode(self, value):
>>> gg = g.bind(fake)
>>> gg.fromUnicode("x")
1
>>> gg.fromUnicode(" x \\n ")
>>> gg.fromUnicode(" x \n ")
1
>>> gg.fromUnicode("y")
42
Expand Down Expand Up @@ -222,7 +222,7 @@ class Tokens(List):
"""

def fromUnicode(self, value):
"""
r"""
Split the input string and convert it to *value_type*.
Consider GlobalObject tokens:
Expand All @@ -239,7 +239,7 @@ def fromUnicode(self, value):
>>> from zope.configuration.fields import GlobalObject
>>> g = Tokens(value_type=GlobalObject())
>>> gg = g.bind(fake)
>>> gg.fromUnicode(" \\n x y z \\n")
>>> gg.fromUnicode(" \n x y z \n")
[1, 42, 'zope']
>>> from zope.schema import Int
Expand Down Expand Up @@ -306,15 +306,15 @@ class Path(Text):
"""

def fromUnicode(self, value):
"""
r"""
Convert the input path to a normalized, absolute path.
Let's look at an example:
First, we need a "context" for the field that has a path
function for converting relative path to an absolute path.
We'll be careful to do this in an os-independent fashion.
We'll be careful to do this in an operating system independent fashion.
>>> from zope.configuration.fields import Path
>>> class FauxContext(object):
Expand All @@ -333,7 +333,7 @@ def fromUnicode(self, value):
This should also work with extra spaces around the path:
>>> p = " \\n %s \\n\\n " % p
>>> p = " \n %s \n\n " % p
>>> n = field.fromUnicode(p)
>>> n.split(os.sep)
['', 'a', 'b']
Expand Down Expand Up @@ -393,7 +393,7 @@ class Bool(schema_Bool):
Do not confuse this with :class:`zope.schema.Bool`.
That class will only parse ``"True"`` and ``"true"`` as
`True` values. Any other value will silently be accepted as
`False`. This class raises a validation error for unrecognized
`False`. This class raises a validation error for unrecognized
input.
"""
Expand All @@ -404,19 +404,19 @@ def fromUnicode(self, value):
Example:
>>> from zope.configuration.fields import Bool
>>> Bool().fromUnicode(u"yes")
True
>>> Bool().fromUnicode(u"y")
True
>>> Bool().fromUnicode(u"true")
True
>>> Bool().fromUnicode(u"no")
False
>>> Bool().fromUnicode(u"surprise")
Traceback (most recent call last):
...
zope.schema._bootstrapinterfaces.InvalidValue
>>> from zope.configuration.fields import Bool
>>> Bool().fromUnicode(u"yes")
True
>>> Bool().fromUnicode(u"y")
True
>>> Bool().fromUnicode(u"true")
True
>>> Bool().fromUnicode(u"no")
False
>>> Bool().fromUnicode(u"surprise")
Traceback (most recent call last):
...
zope.schema._bootstrapinterfaces.InvalidValue
"""
value = value.lower()
if value in ('1', 'true', 'yes', 't', 'y'):
Expand Down Expand Up @@ -459,7 +459,7 @@ def fromUnicode(self, u):
has been issued
>>> warned = None
>>> def fakewarn(*args, **kw): #* syntax highlighting
>>> def fakewarn(*args, **kw):
... global warned
... warned = args
Expand Down Expand Up @@ -529,7 +529,7 @@ def fromUnicode(self, u):
domain = 'untranslated'
warnings.warn(
"You did not specify an i18n translation domain for the "\
"'%s' field in %s" % (self.getName(), context.info.file )
"'%s' field in %s" % (self.getName(), context.info.file)
)
if not isinstance(domain, str):
# IZopeConfigure specifies i18n_domain as a BytesLine, but that's
Expand Down
3 changes: 1 addition & 2 deletions src/zope/configuration/tests/test_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,9 @@ def test_suite():

for mod_name in api_to_test:
mod_name = 'zope.configuration.' + mod_name
__import__(mod_name)
suite.addTest(
doctest.DocTestSuite(
sys.modules[mod_name],
mod_name,
checker=checker,
optionflags=optionflags
)
Expand Down
8 changes: 4 additions & 4 deletions src/zope/configuration/xmlconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def __str__(self):
return str(v)

class ParserInfo(object):
"""
r"""
Information about a directive based on parser data
This includes the directive location, as well as text data
Expand All @@ -133,10 +133,10 @@ class ParserInfo(object):
>>> print(info)
File "tests//sample.zcml", line 1.0
>>> info.characters("blah\\n")
>>> info.characters("blah\n")
>>> info.characters("blah")
>>> info.text
'blah\\nblah'
'blah\nblah'
>>> info.end(7, 0)
>>> info
Expand Down Expand Up @@ -221,7 +221,7 @@ def characters(self, characters):

class ConfigurationHandler(ContentHandler):
"""
Interface to the xml parser
Interface to the XML parser
Translate parser events into calls into the configuration system.
"""
Expand Down

0 comments on commit e313ece

Please sign in to comment.