[Checkins] SVN: zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/ Python 3.2 compatibility via 'straddling'.
Tres Seaver
cvs-admin at zope.org
Tue May 8 01:19:26 UTC 2012
Log message for revision 125724:
Python 3.2 compatibility via 'straddling'.
Changed:
A zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/_compat.py
U zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/config.py
U zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/fields.py
U zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/interfaces.py
U zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/tests/directives.py
U zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/tests/samplepackage/foo.py
U zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/tests/test_config.py
U zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/tests/test_xmlconfig.py
U zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/xmlconfig.py
U zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/zopeconfigure.py
-=-
Added: zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/_compat.py
===================================================================
--- zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/_compat.py (rev 0)
+++ zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/_compat.py 2012-05-08 01:19:23 UTC (rev 125724)
@@ -0,0 +1,103 @@
+##############################################################################
+#
+# Copyright (c) 2012 Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+import sys
+
+PY3 = sys.version_info[0] >= 3
+
+if PY3: #pragma NO COVER
+
+ import builtins
+ from io import StringIO
+
+ string_types = str,
+ text_type = str
+ def b(s):
+ return s.encode("latin-1")
+ def u(s):
+ return s
+
+ # borrowed from 'six'
+ print_ = getattr(builtins, "print")
+
+ # borrowed from 'six'
+ def reraise(tp, value, tb=None):
+ if value is None:
+ value = tp
+ if value.__traceback__ is not tb:
+ raise value.with_traceback(tb)
+ raise value
+
+else: #pragma NO COVER
+
+ import __builtin__ as builtins
+ from StringIO import StringIO
+
+ text_type = unicode
+ string_types = basestring,
+ def b(s):
+ return s
+ def u(s):
+ return unicode(s, "unicode_escape")
+
+ # borrowed from 'six'
+ def print_(*args, **kwargs):
+ """The new-style print function."""
+ fp = kwargs.pop("file", sys.stdout)
+ if fp is None:
+ return
+ def write(data):
+ if not isinstance(data, basestring):
+ data = str(data)
+ fp.write(data)
+ want_unicode = False
+ sep = kwargs.pop("sep", None)
+ if sep is not None:
+ if isinstance(sep, unicode):
+ want_unicode = True
+ elif not isinstance(sep, str):
+ raise TypeError("sep must be None or a string")
+ end = kwargs.pop("end", None)
+ if end is not None:
+ if isinstance(end, unicode):
+ want_unicode = True
+ elif not isinstance(end, str):
+ raise TypeError("end must be None or a string")
+ if kwargs:
+ raise TypeError("invalid keyword arguments to print()")
+ if not want_unicode:
+ for arg in args:
+ if isinstance(arg, unicode):
+ want_unicode = True
+ break
+ if want_unicode:
+ newline = unicode("\n")
+ space = unicode(" ")
+ else:
+ newline = "\n"
+ space = " "
+ if sep is None:
+ sep = space
+ if end is None:
+ end = newline
+ for i, arg in enumerate(args):
+ if i:
+ write(sep)
+ write(arg)
+ write(end)
+
+ # borrowed from 'six'
+ exec("""\
+def reraise(tp, value, tb=None):
+ raise tp, value, tb
+""")
Modified: zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/config.py
===================================================================
--- zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/config.py 2012-05-08 01:19:18 UTC (rev 125723)
+++ zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/config.py 2012-05-08 01:19:23 UTC (rev 125724)
@@ -13,7 +13,6 @@
##############################################################################
"""Configuration processor
"""
-import __builtin__
from keyword import iskeyword
import operator
import os.path
@@ -21,7 +20,7 @@
from zope.interface.adapter import AdapterRegistry
from zope.interface import Interface
-from zope.interface import implements
+from zope.interface import implementer
from zope.interface import providedBy
from zope.schema import TextLine
from zope.schema import URI
@@ -32,6 +31,11 @@
from zope.configuration.interfaces import IGroupingContext
from zope.configuration.fields import GlobalInterface
from zope.configuration.fields import GlobalObject
+from zope.configuration._compat import builtins
+from zope.configuration._compat import reraise
+from zope.configuration._compat import string_types
+from zope.configuration._compat import text_type
+from zope.configuration._compat import u
zopens = 'http://namespaces.zope.org/zope'
@@ -112,7 +116,7 @@
if len(names) == 1:
# Check for built-in objects
marker = object()
- obj = getattr(__builtin__, names[0], marker)
+ obj = getattr(builtins, names[0], marker)
if obj is not marker:
return obj
@@ -148,7 +152,7 @@
try:
mod = __import__(mname, *_import_chickens)
- except ImportError, v:
+ except ImportError as v:
if sys.exc_info()[2].tb_next is not None:
# ImportError was caused deeper
raise
@@ -296,7 +300,7 @@
r.register([interface], Interface, '', factory)
def document(self, name, schema, usedIn, handler, info, parent=None):
- if isinstance(name, (str, unicode)):
+ if isinstance(name, string_types):
name = ('', name)
self._docRegistry.append((name, schema, usedIn, handler, info, parent))
@@ -315,11 +319,10 @@
"The directive %s cannot be used in this context" % (name, ))
return f
+ at implementer(IConfigurationContext)
class ConfigurationMachine(ConfigurationAdapterRegistry, ConfigurationContext):
"""Configuration machine
"""
- implements(IConfigurationContext)
-
package = None
basepath = None
includepath = ()
@@ -376,7 +379,8 @@
raise
t, v, tb = sys.exc_info()
try:
- raise ConfigurationExecutionError(t, v, info), None, tb
+ reraise(ConfigurationExecutionError(t, v, info),
+ None, tb)
finally:
del t, v, tb
@@ -420,6 +424,7 @@
"""Finish processing a directive
"""
+ at implementer(IStackItem)
class SimpleStackItem(object):
"""Simple stack item
@@ -430,8 +435,6 @@
It also defers any computation until the end of the directive
has been reached.
"""
- implements(IStackItem)
-
def __init__(self, context, handler, info, *argdata):
newcontext = GroupingContextDecorator(context)
newcontext.info = info
@@ -457,8 +460,8 @@
action = expand_action(*action) # b/c
context.action(**action)
+ at implementer(IStackItem)
class RootStackItem(object):
- implements(IStackItem)
def __init__(self, context):
self.context = context
@@ -478,6 +481,7 @@
def finish(self):
pass
+ at implementer(IStackItem)
class GroupingStackItem(RootStackItem):
"""Stack item for a grouping directive
@@ -489,7 +493,6 @@
A grouping stack item is created with a grouping directive
definition, a configuration context, and directive data.
"""
- implements(IStackItem)
def __init__(self, context):
super(GroupingStackItem, self).__init__(context)
@@ -519,6 +522,8 @@
def noop():
pass
+
+ at implementer(IStackItem)
class ComplexStackItem(object):
"""Complex stack item
@@ -529,7 +534,6 @@
definition (IComplexDirectiveContext), a configuration context,
and directive data.
"""
- implements(IStackItem)
def __init__(self, meta, context, data, info):
newcontext = GroupingContextDecorator(context)
@@ -559,7 +563,7 @@
# Need to save and restore old info
try:
actions = self.handler()
- except AttributeError, v:
+ except AttributeError as v:
if v[0] == '__call__':
return # noncallable
raise
@@ -576,12 +580,12 @@
##############################################################################
# Helper classes
+ at implementer(IConfigurationContext, IGroupingContext)
class GroupingContextDecorator(ConfigurationContext):
"""Helper mix-in class for building grouping directives
See the discussion (and test) in GroupingStackItem.
"""
- implements(IConfigurationContext, IGroupingContext)
def __init__(self, context, **kw):
self.context = context
@@ -613,13 +617,17 @@
"""
namespace = URI(
- title=u"Namespace",
- description=u"The namespace in which directives' names will be defined",
+ title=u("Namespace"),
+ description=u("The namespace in which directives' names "
+ "will be defined"),
)
+
class IDirectivesContext(IDirectivesInfo, IConfigurationContext):
pass
+
+ at implementer(IDirectivesContext)
class DirectivesHandler(GroupingContextDecorator):
"""Handler for the directives directive
@@ -627,7 +635,6 @@
to the normal directive context.
"""
- implements(IDirectivesContext)
class IDirectiveInfo(Interface):
@@ -635,13 +642,13 @@
"""
name = TextLine(
- title = u"Directive name",
- description = u"The name of the directive being defined",
+ title = u("Directive name"),
+ description = u("The name of the directive being defined"),
)
schema = DirectiveSchema(
- title = u"Directive handler",
- description = u"The dotted name of the directive handler",
+ title = u("Directive handler"),
+ description = u("The dotted name of the directive handler"),
)
class IFullInfo(IDirectiveInfo):
@@ -649,14 +656,14 @@
"""
handler = GlobalObject(
- title = u"Directive handler",
- description = u"The dotted name of the directive handler",
+ title = u("Directive handler"),
+ description = u("The dotted name of the directive handler"),
)
usedIn = GlobalInterface(
- title = u"The directive types the directive can be used in",
- description = (u"The interface of the directives that can contain "
- u"the directive"
+ title = u("The directive types the directive can be used in"),
+ description = u("The interface of the directives that can contain "
+ "the directive"
),
default = IConfigurationContext,
)
@@ -711,13 +718,13 @@
class IComplexDirectiveContext(IFullInfo, IConfigurationContext):
pass
+
+ at implementer(IComplexDirectiveContext)
class ComplexDirectiveDefinition(GroupingContextDecorator, dict):
"""Handler for defining complex directives
See the description and tests for ComplexStackItem.
"""
- implements(IComplexDirectiveContext)
-
def before(self):
def factory(context, data, info):
@@ -741,11 +748,11 @@
"""Information for a <meta:provides> directive"""
feature = TextLine(
- title = u"Feature name",
- description = u"""The name of the feature being provided
+ title = u("Feature name"),
+ description = u("""The name of the feature being provided
You can test available features with zcml:condition="have featurename".
- """,
+ """),
)
def provides(context, feature):
@@ -782,14 +789,14 @@
s = data.get(n, data)
if s is not data:
- s = unicode(s)
+ s = text_type(s)
del data[n]
try:
args[str(name)] = field.fromUnicode(s)
- except ValidationError, v:
- raise ConfigurationError(
- "Invalid value for", n, str(v)), None, sys.exc_info()[2]
+ except ValidationError as v:
+ reraise(ConfigurationError("Invalid value for", n, str(v)),
+ None, sys.exc_info()[2])
elif field.required:
# if the default is valid, we can use that:
default = field.default
@@ -926,8 +933,8 @@
for discriminator, infos in items:
r.append(" For: %s" % (discriminator, ))
for info in infos:
- for line in unicode(info).rstrip().split(u'\n'):
- r.append(u" "+line)
+ for line in text_type(info).rstrip().split(u('\n')):
+ r.append(u(" ") + line)
return "\n".join(r)
Modified: zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/fields.py
===================================================================
--- zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/fields.py 2012-05-08 01:19:18 UTC (rev 125723)
+++ zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/fields.py 2012-05-08 01:19:23 UTC (rev 125724)
@@ -13,36 +13,43 @@
##############################################################################
"""Configuration-specific schema fields
"""
-__docformat__ = 'restructuredtext'
-import os, re, warnings
-from zope import schema
+import os
+import re
+import warnings
+
+from zope.interface import implementer
+from zope.schema import Bool
+from zope.schema import Field
+from zope.schema import InterfaceField
+from zope.schema import List
+from zope.schema import Text
+from zope.schema import TextLine
+from zope.schema import ValidationError
from zope.schema.interfaces import IFromUnicode
-from zope.schema.interfaces import ConstraintNotSatisfied
+
from zope.configuration.exceptions import ConfigurationError
-from zope.interface import implements
from zope.configuration.interfaces import InvalidToken
+from zope.configuration._compat import u
-PYIDENTIFIER_REGEX = u'\\A[a-zA-Z_]+[a-zA-Z0-9_]*\\Z'
+PYIDENTIFIER_REGEX = u('\\A[a-zA-Z_]+[a-zA-Z0-9_]*\\Z')
pyidentifierPattern = re.compile(PYIDENTIFIER_REGEX)
-class PythonIdentifier(schema.TextLine):
+ at implementer(IFromUnicode)
+class PythonIdentifier(TextLine):
"""This field describes a python identifier, i.e. a variable name.
"""
- implements(IFromUnicode)
-
def fromUnicode(self, u):
return u.strip()
def _validate(self, value):
super(PythonIdentifier, self)._validate(value)
if pyidentifierPattern.match(value) is None:
- raise schema.ValidationError(value)
+ raise ValidationError(value)
-class GlobalObject(schema.Field):
+ at implementer(IFromUnicode)
+class GlobalObject(Field):
"""An object that can be accessed as a module global.
"""
- implements(IFromUnicode)
-
def __init__(self, value_type=None, **kw):
self.value_type = value_type
super(GlobalObject, self).__init__(**kw)
@@ -61,8 +68,8 @@
try:
value = self.context.resolve(name)
- except ConfigurationError, v:
- raise schema.ValidationError(v)
+ except ConfigurationError as v:
+ raise ValidationError(v)
self.validate(value)
return value
@@ -71,13 +78,12 @@
"""An interface that can be accessed from a module.
"""
def __init__(self, **kw):
- super(GlobalInterface, self).__init__(schema.InterfaceField(), **kw)
+ super(GlobalInterface, self).__init__(InterfaceField(), **kw)
-class Tokens(schema.List):
+ at implementer(IFromUnicode)
+class Tokens(List):
"""A list that can be read from a space-separated string.
"""
- implements(IFromUnicode)
-
def fromUnicode(self, u):
u = u.strip()
if u:
@@ -86,7 +92,7 @@
for s in u.split():
try:
v = vt.fromUnicode(s)
- except schema.ValidationError, v:
+ except ValidationError as v:
raise InvalidToken("%s in %s" % (v, u))
else:
values.append(v)
@@ -97,14 +103,12 @@
return values
-class Path(schema.Text):
+ at implementer(IFromUnicode)
+class Path(Text):
"""A file path name, which may be input as a relative path
Input paths are converted to absolute paths and normalized.
"""
-
- implements(IFromUnicode)
-
def fromUnicode(self, u):
u = u.strip()
if os.path.isabs(u):
@@ -113,29 +117,28 @@
return self.context.path(u)
-class Bool(schema.Bool):
+ at implementer(IFromUnicode)
+class Bool(Bool):
"""A boolean value
Values may be input (in upper or lower case) as any of:
yes, no, y, n, true, false, t, or f.
"""
- implements(IFromUnicode)
-
def fromUnicode(self, u):
u = u.lower()
if u in ('1', 'true', 'yes', 't', 'y'):
return True
if u in ('0', 'false', 'no', 'f', 'n'):
return False
- raise schema.ValidationError
+ raise ValidationError
-class MessageID(schema.Text):
+ at implementer(IFromUnicode)
+class MessageID(Text):
"""Text string that should be translated.
When a string is converted to a message ID, it is also
recorded in the context.
"""
- implements(IFromUnicode)
__factories = {}
Modified: zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/interfaces.py
===================================================================
--- zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/interfaces.py 2012-05-08 01:19:18 UTC (rev 125723)
+++ zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/interfaces.py 2012-05-08 01:19:23 UTC (rev 125724)
@@ -16,6 +16,7 @@
from zope.interface import Interface
from zope.schema import BytesLine
from zope.schema.interfaces import ValidationError
+from zope.configuration._compat import u
class InvalidToken(ValidationError):
"""Invaid token in list."""
@@ -30,12 +31,12 @@
"""
package = BytesLine(
- title=u"The current package name",
- description=u"""\
+ title=u("The current package name"),
+ description=u("""\
This is the name of the package containing the configuration
file being executed. If the configuration file was not
included by package, then this is None.
- """,
+ """),
required=False,
)
Modified: zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/tests/directives.py
===================================================================
--- zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/tests/directives.py 2012-05-08 01:19:18 UTC (rev 125723)
+++ zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/tests/directives.py 2012-05-08 01:19:23 UTC (rev 125724)
@@ -13,11 +13,15 @@
##############################################################################
"""Test directives
"""
-from zope.interface import Interface, implements
-from zope.schema import Text, BytesLine
+from zope.interface import Interface
+from zope.interface import implementer
+from zope.schema import BytesLine
+from zope.schema import Text
+
from zope.configuration.config import GroupingContextDecorator
from zope.configuration.interfaces import IConfigurationContext
from zope.configuration.fields import GlobalObject
+from zope.configuration._compat import u
class F(object):
@@ -34,10 +38,10 @@
b = Text(required=False)
c = BytesLine()
-def simple(context, a=None, c=None, b=u"xxx"):
+def simple(context, a=None, c=None, b=u("xxx")):
return [(('simple', a, b, c), f, (a, b, c))]
-def newsimple(context, a, c, b=u"xxx"):
+def newsimple(context, a, c, b=u("xxx")):
context.action(('newsimple', a, b, c), f, (a, b, c))
@@ -45,14 +49,16 @@
package = GlobalObject()
+
class IPackagedContext(IPackaged, IConfigurationContext):
pass
+
+ at implementer(IPackagedContext)
class Packaged(GroupingContextDecorator):
+ pass
- implements(IPackagedContext)
-
class IFactory(Interface):
factory = GlobalObject()
@@ -62,7 +68,7 @@
class Complex(object):
- def __init__(self, context, a, c, b=u"xxx"):
+ def __init__(self, context, a, c, b=u("xxx")):
self.a, self.b, self.c = a, b, c
context.action("Complex.__init__")
Modified: zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/tests/samplepackage/foo.py
===================================================================
--- zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/tests/samplepackage/foo.py 2012-05-08 01:19:18 UTC (rev 125723)
+++ zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/tests/samplepackage/foo.py 2012-05-08 01:19:23 UTC (rev 125724)
@@ -28,8 +28,7 @@
) = args, info, basepath, package, includepath
def handler(_context, **kw):
- args = kw.items()
- args.sort()
+ args = sorted(kw.items())
args = tuple(args)
discriminator = args
args = (stuff(args, _context.info, _context.basepath, _context.package,
Modified: zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/tests/test_config.py
===================================================================
--- zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/tests/test_config.py 2012-05-08 01:19:18 UTC (rev 125723)
+++ zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/tests/test_config.py 2012-05-08 01:19:23 UTC (rev 125724)
@@ -34,7 +34,7 @@
else:
if hasattr(excClass,'__name__'): excName = excClass.__name__
else: excName = str(excClass)
- raise self.failureException, "%s not raised" % excName
+ raise self.failureException("%s not raised" % excName)
def test_resolve_trailing_dot_in_resolve(self):
#Dotted names are no longer allowed to end in dots
@@ -134,6 +134,8 @@
def test_keyword_handling(self):
from zope.configuration.config import metans
from zope.configuration.tests.directives import f
+ from zope.configuration._compat import b
+ from zope.configuration._compat import u
machine = self._makeOne()
ns = "http://www.zope.org/testing"
@@ -157,13 +159,13 @@
schema=".Ik", handler=".k")
machine((ns, "k"), "yee ha",
- **{"for": u"f", "class": u"c", "x": u"x"})
+ **{"for": u("f"), "class": u("c"), "x": u("x")})
self.assertEqual(len(machine.actions), 1)
self.assertEqual(machine.actions[0],
- {'args': ('f', 'c', 'x'),
+ {'args': (b('f'), b('c'), b('x')),
'callable': f,
- 'discriminator': ('k', 'f'),
+ 'discriminator': ('k', b('f')),
'includepath': (),
'info': 'yee ha',
'kw': {},
Modified: zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/tests/test_xmlconfig.py
===================================================================
--- zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/tests/test_xmlconfig.py 2012-05-08 01:19:18 UTC (rev 125723)
+++ zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/tests/test_xmlconfig.py 2012-05-08 01:19:23 UTC (rev 125724)
@@ -15,17 +15,19 @@
"""
import unittest
-NS = u'ns'
-FOO = u'foo'
-XXX = u'xxx'
-SPLAT = u'splat'
-SPLATV = u'splatv'
-A = u'a'
-AVALUE = u'avalue'
-B = u'b'
-BVALUE = u'bvalue'
+from zope.configuration._compat import u
+NS = u('ns')
+FOO = u('foo')
+XXX = u('xxx')
+SPLAT = u('splat')
+SPLATV = u('splatv')
+A = u('a')
+AVALUE = u('avalue')
+B = u('b')
+BVALUE = u('bvalue')
+
class ZopeXMLConfigurationErrorTests(unittest.TestCase):
def _getTargetClass(self):
@@ -134,6 +136,7 @@
def test_it(self):
from zope.configuration.config import ConfigurationMachine
from zope.configuration.xmlconfig import registerCommonDirectives
+ from zope.configuration._compat import b
from zope.configuration.tests.samplepackage import foo
file = open(path("samplepackage", "configure.zcml"))
context = ConfigurationMachine()
@@ -142,8 +145,8 @@
self.assertEqual(foo.data, [])
context.execute_actions()
data = foo.data.pop()
- self.assertEqual(data.args, (('x', 'blah'), ('y', 0)))
- self.assertEqual(clean_info_path(`data.info`),
+ self.assertEqual(data.args, (('x', b('blah')), ('y', 0)))
+ self.assertEqual(clean_info_path(repr(data.info)),
'File "tests/samplepackage/configure.zcml", line 12.2-12.29')
self.assertEqual(clean_info_path(str(data.info)),
'File "tests/samplepackage/configure.zcml", line 12.2-12.29\n'
@@ -168,6 +171,7 @@
def test_include_by_package(self):
from zope.configuration.config import ConfigurationMachine
from zope.configuration.xmlconfig import registerCommonDirectives
+ from zope.configuration._compat import b
from zope.configuration.tests.samplepackage import foo
import zope.configuration.tests.samplepackage as package
context = ConfigurationMachine()
@@ -175,8 +179,8 @@
self._callFUT(context, 'configure.zcml', package)
context.execute_actions()
data = foo.data.pop()
- self.assertEqual(data.args, (('x', 'blah'), ('y', 0)))
- self.assertEqual(clean_info_path(`data.info`),
+ self.assertEqual(data.args, (('x', b('blah')), ('y', 0)))
+ self.assertEqual(clean_info_path(repr(data.info)),
'File "tests/samplepackage/configure.zcml", line 12.2-12.29')
self.assertEqual(clean_info_path(str(data.info)),
'File "tests/samplepackage/configure.zcml", line 12.2-12.29\n'
@@ -200,6 +204,7 @@
import os
from zope.configuration.config import ConfigurationMachine
from zope.configuration.xmlconfig import registerCommonDirectives
+ from zope.configuration._compat import b
from zope.configuration.tests.samplepackage import foo
context = ConfigurationMachine()
registerCommonDirectives(context)
@@ -208,8 +213,8 @@
self._callFUT(context, path)
context.execute_actions()
data = foo.data.pop()
- self.assertEqual(data.args, (('x', 'foo'), ('y', 2)))
- self.assertEqual(clean_info_path(`data.info`),
+ self.assertEqual(data.args, (('x', b('foo')), ('y', 2)))
+ self.assertEqual(clean_info_path(repr(data.info)),
'File "tests/samplepackage/foo.zcml.in", line 12.2-12.28')
self.assertEqual(clean_info_path(str(data.info)),
'File "tests/samplepackage/foo.zcml.in", line 12.2-12.28\n'
@@ -223,6 +228,7 @@
import os
from zope.configuration.config import ConfigurationMachine
from zope.configuration.xmlconfig import registerCommonDirectives
+ from zope.configuration._compat import b
from zope.configuration.tests.samplepackage import foo
context = ConfigurationMachine()
registerCommonDirectives(context)
@@ -232,8 +238,8 @@
context.execute_actions()
data = foo.data.pop()
- self.assertEqual(data.args, (('x', 'foo'), ('y', 3)))
- self.assertEqual(clean_info_path(`data.info`),
+ self.assertEqual(data.args, (('x', b('foo')), ('y', 3)))
+ self.assertEqual(clean_info_path(repr(data.info)),
'File "tests/samplepackage/baz3.zcml", line 5.2-5.28')
self.assertEqual(clean_info_path(str(data.info)),
@@ -245,8 +251,8 @@
['tests/samplepackage/baz3.zcml'])
data = foo.data.pop()
- self.assertEqual(data.args, (('x', 'foo'), ('y', 2)))
- self.assertEqual(clean_info_path(`data.info`),
+ self.assertEqual(data.args, (('x', b('foo')), ('y', 2)))
+ self.assertEqual(clean_info_path(repr(data.info)),
'File "tests/samplepackage/baz2.zcml", line 5.2-5.28')
self.assertEqual(clean_info_path(str(data.info)),
'File "tests/samplepackage/baz2.zcml", line 5.2-5.28\n'
@@ -278,12 +284,13 @@
return file(*args, **kw)
def test_simple(self):
+ from zope.configuration._compat import b
from zope.configuration.tests.samplepackage import foo
file_name = path("samplepackage", "configure.zcml")
context = self._callFUT(file_name)
data = foo.data.pop()
- self.assertEqual(data.args, (('x', 'blah'), ('y', 0)))
- self.assertEqual(clean_info_path(`data.info`),
+ self.assertEqual(data.args, (('x', b('blah')), ('y', 0)))
+ self.assertEqual(clean_info_path(repr(data.info)),
'File "tests/samplepackage/configure.zcml", line 12.2-12.29')
self.assertEqual(clean_info_path(str(data.info)),
'File "tests/samplepackage/configure.zcml", line 12.2-12.29\n' +
@@ -319,6 +326,7 @@
def test_XMLConfig(self):
import os
+ from zope.configuration._compat import b
from zope.configuration.tests.samplepackage import foo
here = os.path.dirname(__file__)
path = os.path.join(here, "samplepackage", "baro.zcml")
@@ -327,21 +335,22 @@
self.assertEqual(len(foo.data), 3)
data = foo.data.pop(0)
- self.assertEqual(data.args, (('x', 'blah'), ('y', 0)))
- self.assertEqual(clean_info_path(`data.info`),
+ self.assertEqual(data.args, (('x', b('blah')), ('y', 0)))
+ self.assertEqual(clean_info_path(repr(data.info)),
'File "tests/samplepackage/bar21.zcml", line 3.2-3.24')
data = foo.data.pop(0)
- self.assertEqual(data.args, (('x', 'blah'), ('y', 2)))
- self.assertEqual(clean_info_path(`data.info`),
+ self.assertEqual(data.args, (('x', b('blah')), ('y', 2)))
+ self.assertEqual(clean_info_path(repr(data.info)),
'File "tests/samplepackage/bar2.zcml", line 5.2-5.24')
data = foo.data.pop(0)
- self.assertEqual(data.args, (('x', 'blah'), ('y', 1)))
- self.assertEqual(clean_info_path(`data.info`),
+ self.assertEqual(data.args, (('x', b('blah')), ('y', 1)))
+ self.assertEqual(clean_info_path(repr(data.info)),
'File "tests/samplepackage/bar2.zcml", line 6.2-6.24')
def test_XMLConfig_w_module(self):
+ from zope.configuration._compat import b
from zope.configuration.tests.samplepackage import foo
from zope.configuration.tests import samplepackage as module
x = self._makeOne("baro.zcml", module)
@@ -349,18 +358,18 @@
self.assertEqual(len(foo.data), 3)
data = foo.data.pop(0)
- self.assertEqual(data.args, (('x', 'blah'), ('y', 0)))
- self.assertEqual(clean_info_path(`data.info`),
+ self.assertEqual(data.args, (('x', b('blah')), ('y', 0)))
+ self.assertEqual(clean_info_path(repr(data.info)),
'File "tests/samplepackage/bar21.zcml", line 3.2-3.24')
data = foo.data.pop(0)
- self.assertEqual(data.args, (('x', 'blah'), ('y', 2)))
- self.assertEqual(clean_info_path(`data.info`),
+ self.assertEqual(data.args, (('x', b('blah')), ('y', 2)))
+ self.assertEqual(clean_info_path(repr(data.info)),
'File "tests/samplepackage/bar2.zcml", line 5.2-5.24')
data = foo.data.pop(0)
- self.assertEqual(data.args, (('x', 'blah'), ('y', 1)))
- self.assertEqual(clean_info_path(`data.info`),
+ self.assertEqual(data.args, (('x', b('blah')), ('y', 1)))
+ self.assertEqual(clean_info_path(repr(data.info)),
'File "tests/samplepackage/bar2.zcml", line 6.2-6.24')
@@ -425,7 +434,7 @@
def clean_actions(actions):
return [
{'discriminator': action['discriminator'],
- 'info': clean_info_path(`action['info']`),
+ 'info': clean_info_path(repr(action['info'])),
'includepath': [clean_path(p) for p in action['includepath']],
}
for action in actions
Modified: zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/xmlconfig.py
===================================================================
--- zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/xmlconfig.py 2012-05-08 01:19:18 UTC (rev 125723)
+++ zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/xmlconfig.py 2012-05-08 01:19:23 UTC (rev 125724)
@@ -30,7 +30,7 @@
from xml.sax import SAXParseException
from zope.interface import Interface
-from zope.schema import BytesLine
+from zope.schema import NativeStringLine
from zope.configuration.config import ConfigurationMachine
from zope.configuration.config import defineGroupingDirective
@@ -42,11 +42,13 @@
from zope.configuration.fields import GlobalObject
from zope.configuration.zopeconfigure import IZopeConfigure
from zope.configuration.zopeconfigure import ZopeConfigure
+from zope.configuration._compat import u
+from zope.configuration._compat import reraise
logger = logging.getLogger("config")
ZCML_NAMESPACE = "http://namespaces.zope.org/zcml"
-ZCML_CONDITION = (ZCML_NAMESPACE, u"condition")
+ZCML_CONDITION = (ZCML_NAMESPACE, u("condition"))
class ZopeXMLConfigurationError(ConfigurationError):
@@ -62,7 +64,7 @@
# Only use the repr of the info. This is because we expect to
# get a parse info and we only want the location information.
return "%s\n %s: %s" % (
- `self.info`, self.etype.__name__, self.evalue)
+ repr(self.info), self.etype.__name__, self.evalue)
class ZopeSAXParseException(ConfigurationError):
"""Sax Parser errors, reformatted in an emacs friendly way
@@ -84,7 +86,7 @@
This includes the directive location, as well as text data
contained in the directive.
"""
- text = u''
+ text = u('')
def __init__(self, file, line, column):
self.file, self.line, self.column = file, line, column
@@ -133,17 +135,19 @@
# Remove text before start if it's noy whitespace
lines[0] = lines[0][self.column:]
+ pad = u(' ')
+ blank = u('')
try:
- src = u''.join([u" "+l for l in lines])
+ src = blank.join([pad + l for l in lines])
except UnicodeDecodeError:
# XXX:
# I hope so most internation zcml will use UTF-8 as encoding
# otherwise this code must be made more clever
- src = u''.join([u" "+l.decode('utf-8') for l in lines])
+ src = blank.join([pad + l.decode('utf-8') for l in lines])
# unicode won't be printable, at least on my console
src = src.encode('ascii','replace')
- return "%s\n%s" % (`self`, src)
+ return "%s\n%s" % (repr(self), src)
def characters(self, characters):
self.text += characters
@@ -201,8 +205,10 @@
except:
if self.testing:
raise
- raise ZopeXMLConfigurationError(info, sys.exc_info()[0],
- sys.exc_info()[1]), None, sys.exc_info()[2]
+ reraise(ZopeXMLConfigurationError(info,
+ sys.exc_info()[0],
+ sys.exc_info()[1]),
+ None, sys.exc_info()[2])
self.context.setInfo(info)
@@ -267,8 +273,10 @@
except:
if self.testing:
raise
- raise ZopeXMLConfigurationError(info, sys.exc_info()[0],
- sys.exc_info()[1]), None, sys.exc_info()[2]
+ reraise(ZopeXMLConfigurationError(info,
+ sys.exc_info()[0],
+ sys.exc_info()[1]),
+ None, sys.exc_info()[2])
def processxmlfile(file, context, testing=False):
@@ -284,7 +292,8 @@
try:
parser.parse(src)
except SAXParseException:
- raise ZopeSAXParseException(sys.exc_info()[1]), None, sys.exc_info()[2]
+ reraise(ZopeSAXParseException(sys.exc_info()[1]),
+ None, sys.exc_info()[2])
def openInOrPlain(filename):
@@ -296,7 +305,8 @@
"""
try:
fp = open(filename)
- except IOError, (code, msg):
+ except IOError as e:
+ code, msg = e.args
if code == errno.ENOENT:
fn = filename + ".in"
if os.path.exists(fn):
@@ -315,17 +325,17 @@
files in each package and then link them together.
"""
- file = BytesLine(
- title=u"Configuration file name",
- description=u"The name of a configuration file to be included/excluded, "
- u"relative to the directive containing the "
- u"including configuration file.",
+ file = NativeStringLine(
+ title=u("Configuration file name"),
+ description=u("The name of a configuration file to be included/excluded, "
+ "relative to the directive containing the "
+ "including configuration file."),
required=False,
)
- files = BytesLine(
- title=u"Configuration file name pattern",
- description=u"""
+ files = NativeStringLine(
+ title=u("Configuration file name pattern"),
+ description=u("""
The names of multiple configuration files to be included/excluded,
expressed as a file-name pattern, relative to the directive
containing the including or excluding configuration file. The pattern
@@ -341,16 +351,16 @@
The file names are included in sorted order, where sorting is
without regard to case.
- """,
+ """),
required=False,
)
package = GlobalObject(
- title=u"Include or exclude package",
- description=u"""
+ title=u("Include or exclude package"),
+ description=u("""
Include or exclude the named file (or configure.zcml) from the directory
of this package.
- """,
+ """),
required=False,
)
@@ -376,8 +386,7 @@
if files:
paths = glob(context.path(files))
- paths = zip([path.lower() for path in paths], paths)
- paths.sort()
+ paths = sorted(zip([path.lower() for path in paths], paths))
paths = [path for (l, path) in paths]
else:
paths = [context.path(file)]
Modified: zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/zopeconfigure.py
===================================================================
--- zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/zopeconfigure.py 2012-05-08 01:19:18 UTC (rev 125723)
+++ zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/zopeconfigure.py 2012-05-08 01:19:23 UTC (rev 125724)
@@ -105,6 +105,7 @@
from zope.configuration.config import GroupingContextDecorator
from zope.configuration.fields import GlobalObject
+from zope.configuration._compat import u
class IZopeConfigure(Interface):
"""The ``zope:configure`` Directive
@@ -120,19 +121,19 @@
"""
package = GlobalObject(
- title=u"Package",
- description=u"The package to be used for evaluating relative imports "
- u"and file names.",
+ title=u("Package"),
+ description=u("The package to be used for evaluating relative imports "
+ "and file names."),
required=False)
i18n_domain = BytesLine(
- title=u"Internationalization domain",
- description=u"This is a name for the software project. It must be a "
- u"legal file-system name as it will be used to contruct "
- u"names for directories containing translation data. "
- u"\n"
- u"The domain defines a namespace for the message ids "
- u"used by a project.",
+ title=u("Internationalization domain"),
+ description=u("This is a name for the software project. It must be a "
+ "legal file-system name as it will be used to contruct "
+ "names for directories containing translation data. "
+ "\n"
+ "The domain defines a namespace for the message ids "
+ "used by a project."),
required=False)
More information about the checkins
mailing list