[Zope3-checkins] CVS: Zope3/src/zope/configuration - config.py:1.6 xmlconfig.py:1.12
Sidnei da Silva
sidnei@x3ng.com.br
Wed, 30 Jul 2003 11:07:23 -0400
Update of /cvs-repository/Zope3/src/zope/configuration
In directory cvs.zope.org:/tmp/cvs-serv6195/zope/configuration
Modified Files:
config.py xmlconfig.py
Log Message:
Whitespace and two typos
=== Zope3/src/zope/configuration/config.py 1.5 => 1.6 ===
--- Zope3/src/zope/configuration/config.py:1.5 Wed Jul 30 10:34:54 2003
+++ Zope3/src/zope/configuration/config.py Wed Jul 30 11:06:47 2003
@@ -82,7 +82,7 @@
For brevity, trailing items after the callable in the tuples are
ommitted if they are empty.
-
+
"""
def resolve(self, dottedname):
@@ -113,16 +113,16 @@
>>> c.resolve('..interface') is zope.interface
1
"""
-
+
name = dottedname.strip()
if not name:
raise ValueError("The given name is blank")
-
+
names = name.split('.')
if not names[-1]:
raise ValueError(
"Trailing dots are no longer supported in dotted names")
-
+
if not names[0]:
# Got a relative name. Conver it to abs using package info
if self.package is None:
@@ -152,7 +152,7 @@
# Just got a single name. Must me a module
mname = oname
oname = ''
-
+
try:
mod = __import__(mname, *_import_chickens)
except ImportError, v:
@@ -163,7 +163,7 @@
if not oname:
# see not mname case above
return mod
-
+
try:
return getattr(mod, oname)
@@ -174,11 +174,11 @@
except ImportError:
raise ConfigurationError("Module %s has no global %s"
% (mname, oname))
-
+
def path(self, filename):
"""
Examples:
-
+
>>> c = ConfigurationContext()
>>> c.path("/x/y/z") == os.path.normpath("/x/y/z")
1
@@ -255,7 +255,7 @@
>>> c.action(None)
>>> c.actions[-1]
(None, None, (), {}, ('foo.zcml',), '?')
-
+
"""
action = (discriminator, callable, args, kw,
getattr(self, 'includepath', ()),
@@ -265,7 +265,7 @@
# remove trailing false items
while (len(action) > 2) and not action[-1]:
action = action[:-1]
-
+
self.actions.append(action)
class ConfigurationAdapterRegistry(object):
@@ -278,7 +278,7 @@
...
ConfigurationError: ('Unknown directive', 'http://www.zope.com', 'xxx')
>>> from zope.configuration.interfaces import IConfigurationContext
- >>> def f():
+ >>> def f():
... pass
>>> r.register(IConfigurationContext, ('http://www.zope.com', 'xxx'), f)
@@ -295,7 +295,7 @@
def __init__(self):
- self._registry = {}
+ self._registry = {}
def register(self, interface, name, factory):
r = self._registry.get(name)
@@ -313,13 +313,13 @@
r = self._registry.get(n)
if r is None:
raise ConfigurationError("Unknown directive", ns, n)
-
+
f = r.getForObject(context, Interface)
if f is None:
raise ConfigurationError(
"The directive %s cannot ne used in this context" % (name, ))
return f
-
+
class ConfigurationMachine(ConfigurationAdapterRegistry, ConfigurationContext):
"""Configuration machine
@@ -351,13 +351,13 @@
basepath = None
includepath = ()
info = ''
-
+
def __init__(self):
ConfigurationAdapterRegistry.__init__(self)
self.actions = []
self.stack = [RootStackItem(self)]
- self.i18n_strings = {}
+ self.i18n_strings = {}
_bootstrap(self)
def begin(self, __name, __data=None, __info=None, **kw):
@@ -425,11 +425,11 @@
Note that actions executed before the error still have an effect:
-
+
>>> output
[('f', (1,), {}), ('f', (2,), {})]
-
-
+
+
"""
for action in resolveConflicts(self.actions):
(discriminator, callable, args, kw, includepath, info
@@ -448,7 +448,7 @@
if clear:
del self.actions[:]
-
+
class ConfigurationExecutionError(ConfigurationError):
"""An error occurred during execution of a configuration action
@@ -468,7 +468,7 @@
Stack items are created when a directive if being processed.
- A stack item is created for each directive use.
+ A stack item is created for each directive use.
"""
def contained(name, data, info):
@@ -530,10 +530,10 @@
def contained(self, name, data, info):
"""Handle a contained directive
-
+
We have to compute a new stack item by getting a named adapter
for the current context object.
-
+
"""
factory = self.context.factory(self.context, name)
if factory is None:
@@ -564,7 +564,7 @@
We need a callable to use in configuration actions. We'll use a
convenient one from the tests:
-
+
>>> from zope.configuration.tests.directives import f
We need a handler for the grouping directive. This is a class
@@ -589,7 +589,7 @@
Note that the keyword arguments are made attributes of the
decorator.
- Now we'll create the stack item.
+ Now we'll create the stack item.
>>> item = GroupingStackItem(dec)
@@ -618,7 +618,7 @@
>>> item.contained((testns, 'simple'), {'z': 'zope'}, "someinfo")
'someinfo'
-
+
we can verify thet the simple method was called by looking at the
context actions:
@@ -640,7 +640,7 @@
"""
-
+
implements(IStackItem)
def __init__(self, context):
@@ -674,12 +674,12 @@
We need a callable to use in configuration actions. We'll use a
convenient one from the tests:
-
+
>>> from zope.configuration.tests.directives import f
We need a handler for the complex directive. This is a class
with a method for each subdirective:
-
+
>>> class Handler:
... def __init__(self, context, x, y):
... self.context, self.x, self.y = context, x, y
@@ -734,7 +734,7 @@
The new stack item returned by contained is one that doesn't allow
any more subdirectives,
- When all of the subdirectives have been provided, the ``finish``
+ When all of the subdirectives have been provided, the ``finish``
method is called:
>>> item.finish()
@@ -745,8 +745,8 @@
[('init', f, (), {}, (), 'foo'),
(('sub', u'av', u'bv'), f, (), {}, (), 'baz'),
(('call', u'xv', u'yv'), f, (), {}, (), 'foo')]
-
-
+
+
"""
@@ -806,13 +806,13 @@
"""
implements(IConfigurationContext)
-
+
def __init__(self, context, **kw):
self.context = context
for name, v in kw.items():
setattr(self, name, v)
- directlyProvides(self)
+ directlyProvides(self)
def __getattr__(self, name,
getattr=getattr, setattr=setattr):
@@ -826,7 +826,7 @@
def after(self):
pass
-
+
##############################################################################
# Directive-definition
@@ -857,7 +857,7 @@
This is just a grouping directive that adds a namespace attribute
to the normal directive context.
-
+
"""
implements(IDirectivesContext)
@@ -935,7 +935,7 @@
>>> context.actions
[(('s', u'vx', u'vy'), f)]
- """
+ """
namespace = namespace or context.namespace
if namespace != '*':
@@ -966,7 +966,7 @@
just use GroupingContextDecorator, which simple sets up a grouping
context that has extra attributes defined by a schema:
- >>> defineGroupingDirective(context, 'g', Ixy,
+ >>> defineGroupingDirective(context, 'g', Ixy,
... GroupingContextDecorator, testns)
>>> context.begin((testns, "g"), x=u"vx", y=u"vy")
@@ -981,7 +981,7 @@
ConfigurationError: ('Unknown directive', 'http://www.zope.com/t1', 'g')
>>> context = ConfigurationMachine()
- >>> defineGroupingDirective(context, 'g', Ixy,
+ >>> defineGroupingDirective(context, 'g', Ixy,
... GroupingContextDecorator, "*")
>>> context.begin(('http://www.zope.com/t1', "g"), x=u"vx", y=u"vy")
@@ -989,7 +989,7 @@
u'vx'
>>> context.stack[-1].context.y
u'vy'
-
+
"""
namespace = namespace or context.namespace
@@ -1003,7 +1003,7 @@
return GroupingStackItem(newcontext)
context.register(usedIn, name, factory)
-
+
class IComplexDirectiveContext(IFullInfo, IConfigurationContext):
pass
@@ -1090,10 +1090,10 @@
'n': u'bob',
'u': 'http://www.zope.org',
'x': 'x.y.z'}
-
+
If we ommit required data we get an error telling us what was omitted:
-
+
>>> pprint(toargs(context, schema,
... {'in': u'1', 'f': u'1.2', 'n': u'bob', 'x': u'x.y.z'}))
Traceback (most recent call last):
@@ -1113,7 +1113,7 @@
And we can ommit required fields if they have valid defaults
(defaults that are valid values):
-
+
>>> pprint(toargs(context, schema,
... {'in': u'1', 'f': u'1.2',
@@ -1125,7 +1125,7 @@
'u': 'http://www.zope.org'}
We also get an error if any data was invalid:
-
+
>>> pprint(toargs(context, schema,
... {'in': u'0', 'f': u'1.2', 'n': u'bob', 'x': u'x.y.z',
... 'u': u'http://www.zope.org', 'a': u'1'}))
@@ -1161,7 +1161,7 @@
except zope.schema.ValidationError:
raise ConfigurationError("Missing parameter:", n)
args[str(name)] = default
-
+
if data:
# we had data left over
try:
@@ -1230,7 +1230,7 @@
For: 1
eek
ack
-
+
"""
# organize actions by discriminators
@@ -1248,7 +1248,7 @@
)
continue
-
+
a = unique.setdefault(discriminator, [])
a.append(
(includepath, i, callable, args, kw, info)
@@ -1274,7 +1274,7 @@
if discriminator not in conflicts:
conflicts[discriminator] = [baseinfo]
conflicts[discriminator].append(info)
-
+
if conflicts:
raise ConfigurationConflictError(conflicts)
@@ -1287,7 +1287,7 @@
while len(action) > 2 and not action[-1]:
action = action[:-1]
r.append(action)
-
+
return r
class ConfigurationConflictError(ConfigurationError):
@@ -1342,7 +1342,7 @@
handler="zope.configuration.config.DirectivesHandler",
schema="zope.configuration.config.IDirectivesInfo"
)
-
+
# directive and groupingDirective inside directives
context((metans, 'directive'),
name='directive',
@@ -1358,7 +1358,7 @@
handler="zope.configuration.config.defineGroupingDirective",
schema="zope.configuration.config.IFullInfo"
)
-
+
# Setup complex directive directive, both standalone, and in
# directives directive
context((metans, 'groupingDirective'),
=== Zope3/src/zope/configuration/xmlconfig.py 1.11 => 1.12 ===
--- Zope3/src/zope/configuration/xmlconfig.py:1.11 Wed Jul 30 10:35:00 2003
+++ Zope3/src/zope/configuration/xmlconfig.py Wed Jul 30 11:06:48 2003
@@ -46,7 +46,7 @@
>>> print v
'blah'
AttributeError: xxx
-
+
"""
def __init__(self, info, etype, evalue):
@@ -64,9 +64,9 @@
>>> v = ZopeSAXParseException("foo.xml:12:3:Not well formed")
>>> print v
File "foo.xml", line 12.3, Not well formed
-
+
"""
-
+
def __init__(self, v):
self._v = v
@@ -109,8 +109,8 @@
handler="zope.configuration.metaconfigure.hook" />
</directives>
</zopeConfigure>
-
-
+
+
"""
text = u''
@@ -126,7 +126,7 @@
if (self.line, self.column) == (self.eline, self.ecolumn):
return 'File "%s", line %s.%s' % (
self.file, self.line, self.column)
-
+
return 'File "%s", line %s.%s-%s.%s' % (
self.file, self.line, self.column, self.eline, self.ecolumn)
@@ -140,7 +140,7 @@
# special case for testing
file = os.path.join(os.path.split(__file__)[0],
'tests', 'sample.zcml')
-
+
try:
f = open(file)
except IOError:
@@ -168,8 +168,8 @@
def characters(self, characters):
self.text += characters
-
-
+
+
class ConfigurationHandler(ContentHandler):
"""Interface toi the cml parser
@@ -187,7 +187,7 @@
self.context.getInfo().characters(text)
def startElementNS(self, name, qname, attrs):
-
+
data = {}
for (ns, aname), value in attrs.items():
if ns is None:
@@ -210,7 +210,7 @@
), sys.exc_info()[2]
self.context.setInfo(info)
-
+
def endElementNS(self, name, qname):
info = self.context.getInfo()
@@ -218,7 +218,7 @@
self.locator.getLineNumber(),
self.locator.getColumnNumber(),
)
-
+
try:
self.context.end()
except:
@@ -236,7 +236,7 @@
The package to be used for evaluating relative imports and file names.
""",
required=False)
-
+
domain = schema.BytesLine(__doc__="""Internationalization domain
This is a name for the software project. It must be a legal file-system
@@ -257,7 +257,7 @@
# if we have a package, we want to also define basepath
# so we don't acquire one
self.basepath = os.path.split(self.package.__file__)[0]
-
+
def _register_configure(context):
@@ -277,7 +277,7 @@
schema=IZopeConfigure,
handler=ZopeConfigure,
)
-
+
def processxmlfile(file, context, testing=0):
"""Process a configuration file
@@ -323,7 +323,7 @@
>>> f = openInOrPlain(path)
>>> f.name[-11:]
'foo.zcml.in'
-
+
"""
try:
fp = open(filename)
@@ -345,7 +345,7 @@
The name of a configuration file to be included,
relative to the directive containing the
including configuration file.
-
+
""",
default="configure.zcml",
)
@@ -363,12 +363,12 @@
def include(_context, file, package=None):
"""Include a zcml file
-
+
See examples in tests/text_xmlconfig.py
"""
-
+
logger.debug("include %s" % file)
-
+
# This is a tad tricky. We want to behave a a grouping directive.
context = config.GroupingContextDecorator(_context)
if package is not None:
@@ -376,11 +376,11 @@
context.basepath = None
path = context.path(file)
f = openInOrPlain(path)
-
+
logger.debug("include %s" % f.name)
context.basepath = os.path.split(path)[0]
- context.includepath = _context.includepath + (f.name, )
+ context.includepath = _context.includepath + (f.name, )
_context.stack.append(config.GroupingStackItem(context))
processxmlfile(f, context)
@@ -426,7 +426,7 @@
context, "include", IInclude, include, namespace="*")
config.defineSimpleDirective(
context, "includeOverrides", IInclude, includeOverrides, namespace="*")
-
+
_register_configure(context)
def file(name, package=None, context=None, execute=True):
@@ -437,11 +437,11 @@
context = config.ConfigurationMachine()
_registerIncludes(context)
context.package = package
-
+
include(context, name, package)
if execute:
context.execute_actions()
-
+
return context
def string(s, context=None, name="test.string", execute=True):
@@ -452,14 +452,14 @@
if context is None:
context = config.ConfigurationMachine()
_registerIncludes(context)
-
+
f = StringIO(s)
f.name = name
processxmlfile(f, context)
if execute:
context.execute_actions()
-
+
return context
@@ -472,7 +472,7 @@
global _context
_context = config.ConfigurationMachine()
_registerIncludes(_context)
-
+
def _getContext():
global _context
if _context is None:
@@ -484,7 +484,7 @@
class XMLConfig:
"""Provide high-level handling of configuration files.
- See examples in tests/text_xmlconfig.py
+ See examples in tests/text_xmlconfig.py
"""
def __init__(self, file_name, module=None):