summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Madden <jason+github@nextthought.com>2018-09-24 16:09:02 -0500
committerGitHub <noreply@github.com>2018-09-24 16:09:02 -0500
commit82eacf528df7293d52d19e981ace634204c5bbe1 (patch)
tree60a2bfe96536940bd5f7deb4224ae15597a33e0f
parentaac9d8e351cfad29ed9d55538201752b8152f3fb (diff)
parenta5e291a90a460c6f8767a744bc971c2f6d21264d (diff)
downloadzope-configuration-82eacf528df7293d52d19e981ace634204c5bbe1.tar.gz
Merge pull request #27 from zopefoundation/issue26
Remove unneeded internal _compat functions and aliases
-rw-r--r--CHANGES.rst6
-rw-r--r--docs/api/fields.rst5
-rw-r--r--src/zope/configuration/_compat.py67
-rw-r--r--src/zope/configuration/config.py61
-rw-r--r--src/zope/configuration/fields.py4
-rw-r--r--src/zope/configuration/interfaces.py8
-rw-r--r--src/zope/configuration/tests/conditions.py8
-rw-r--r--src/zope/configuration/tests/nested.py52
-rw-r--r--src/zope/configuration/tests/simple.py17
-rw-r--r--src/zope/configuration/tests/test_config.py3
-rw-r--r--src/zope/configuration/tests/test_fields.py33
-rw-r--r--src/zope/configuration/tests/test_xmlconfig.py149
-rw-r--r--src/zope/configuration/xmlconfig.py12
-rw-r--r--src/zope/configuration/zopeconfigure.py32
14 files changed, 194 insertions, 263 deletions
diff --git a/CHANGES.rst b/CHANGES.rst
index 3bab7f1..83ed2cb 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -6,7 +6,11 @@ Changes
- Add support for Python 3.7.
-- Drop support for Python 3.3.
+- Drop support for Python 3.3 and remove internal compatibility
+ functions needed to support it. See `issue 20
+ <https://github.com/zopefoundation/zope.configuration/issues/20>`_
+ and `issue 26
+ <https://github.com/zopefoundation/zope.configuration/issues/26>`_.
- Drop support for ``python setup.py test``.
diff --git a/docs/api/fields.rst b/docs/api/fields.rst
index f7c65cd..dd542dc 100644
--- a/docs/api/fields.rst
+++ b/docs/api/fields.rst
@@ -189,8 +189,7 @@
.. doctest::
>>> import os
- >>> from zope.configuration._compat import u as unicode
- >>> p = unicode(os.path.join(os.sep, 'a', 'b'))
+ >>> p = os.path.join(os.sep, u'a', u'b')
>>> n = field.fromUnicode(p)
>>> n.split(os.sep)
['', 'a', 'b']
@@ -208,7 +207,7 @@
.. doctest::
- >>> p = unicode(os.path.join('a', 'b'))
+ >>> p = os.path.join(u'a', u'b')
>>> n = field.fromUnicode(p)
>>> n.split(os.sep)
['', 'faux', 'context', 'a', 'b']
diff --git a/src/zope/configuration/_compat.py b/src/zope/configuration/_compat.py
index 650fdde..a7d8286 100644
--- a/src/zope/configuration/_compat.py
+++ b/src/zope/configuration/_compat.py
@@ -15,20 +15,12 @@ import sys
PY3 = sys.version_info[0] >= 3
-if PY3: #pragma NO COVER
+if PY3: # pragma: no cover
import builtins
- from io import StringIO
- string_types = str,
+ 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):
@@ -38,63 +30,12 @@ if PY3: #pragma NO COVER
raise value.with_traceback(tb)
raise value
-else: #pragma NO COVER
+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)
+ string_types = (basestring,)
# borrowed from 'six'
exec("""\
diff --git a/src/zope/configuration/config.py b/src/zope/configuration/config.py
index 8b41420..09871cf 100644
--- a/src/zope/configuration/config.py
+++ b/src/zope/configuration/config.py
@@ -35,7 +35,7 @@ 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'
@@ -621,10 +621,11 @@ class IDirectivesInfo(Interface):
"""
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 "
+ u"will be defined"),
+ )
class IDirectivesContext(IDirectivesInfo, IConfigurationContext):
@@ -642,35 +643,39 @@ class DirectivesHandler(GroupingContextDecorator):
class IDirectiveInfo(Interface):
- """Information common to all directive definitions have
+ """Information common to all directive definitions.
"""
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):
- """Information that all top-level directives (not subdirectives) have
+ """Information that all top-level directives (not subdirectives)
+ have.
"""
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 "
- "the directive"
- ),
- default = IConfigurationContext,
- )
+ title=u"The directive types the directive can be used in",
+ description=(
+ u"The interface of the directives that can contain "
+ u"the directive"
+ ),
+ default=IConfigurationContext,
+ )
+
class IStandaloneDirectiveInfo(IDirectivesInfo, IFullInfo):
"""Info for full directives defined outside a directives directives
@@ -752,12 +757,12 @@ class IProvidesDirectiveInfo(Interface):
"""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):
"""Declare that a feature is provided in context.
@@ -935,8 +940,8 @@ class ConfigurationConflictError(ConfigurationError):
for discriminator, infos in sorted(self._conflicts.items()):
r.append(" For: %s" % (discriminator, ))
for info in infos:
- for line in text_type(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)
diff --git a/src/zope/configuration/fields.py b/src/zope/configuration/fields.py
index dd8405e..bb27c07 100644
--- a/src/zope/configuration/fields.py
+++ b/src/zope/configuration/fields.py
@@ -30,9 +30,9 @@ from zope.schema.interfaces import IFromUnicode
from zope.configuration.exceptions import ConfigurationError
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)
diff --git a/src/zope/configuration/interfaces.py b/src/zope/configuration/interfaces.py
index 8990ad6..67ee132 100644
--- a/src/zope/configuration/interfaces.py
+++ b/src/zope/configuration/interfaces.py
@@ -16,7 +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."""
@@ -31,14 +31,14 @@ class IConfigurationContext(Interface):
"""
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,
- )
+ )
def resolve(dottedname):
"""Resolve a dotted name to an object
diff --git a/src/zope/configuration/tests/conditions.py b/src/zope/configuration/tests/conditions.py
index a8283cc..b79fdce 100644
--- a/src/zope/configuration/tests/conditions.py
+++ b/src/zope/configuration/tests/conditions.py
@@ -16,17 +16,15 @@
from zope.interface import Interface
from zope.schema import Id
-from zope.configuration._compat import u
-
class IRegister(Interface):
"""Trivial sample registry."""
id = Id(
- title=u("Identifier"),
- description=u("Some identifier that can be checked."),
+ title=u"Identifier",
+ description=u"Some identifier that can be checked.",
required=True,
- )
+ )
registry = []
diff --git a/src/zope/configuration/tests/nested.py b/src/zope/configuration/tests/nested.py
index 3d63f9b..f9f930c 100644
--- a/src/zope/configuration/tests/nested.py
+++ b/src/zope/configuration/tests/nested.py
@@ -25,7 +25,7 @@ from zope.schema import TextLine
from zope.configuration.config import GroupingContextDecorator
from zope.configuration.config import IConfigurationContext
from zope.configuration.fields import Bool
-from zope.configuration._compat import u
+
schema_registry = {}
@@ -35,11 +35,11 @@ class ISchemaInfo(Interface):
"""
name = TextLine(
- title=u("The schema name"),
- description=u("This is a descriptive name for the schema."),
+ title=u"The schema name",
+ description=u"This is a descriptive name for the schema.",
)
- id = Id(title=u("The unique id for the schema"))
+ id = Id(title=u"The unique id for the schema")
class ISchema(Interface):
"""Interface that distinguishes the schema directive
@@ -75,43 +75,47 @@ class Schema(GroupingContextDecorator):
class IFieldInfo(Interface):
name = NativeStringLine(
- title=u("The field name"),
- )
+ title=u"The field name",
+ )
title = TextLine(
- title=u("Title"),
- description=u("A short summary or label"),
- default=u(""),
+ title=u"Title",
+ description=u"A short summary or label",
+ default=u"",
required=False,
- )
+ )
required = Bool(
- title=u("Required"),
- description=u("Determines whether a value is required."),
+ title=u"Required",
+ description=u"Determines whether a value is required.",
default=True)
readonly = Bool(
- title=u("Read Only"),
- description=u("Can the value be modified?"),
+ title=u"Read Only",
+ description=u"Can the value be modified?",
required=False,
default=False)
class ITextInfo(IFieldInfo):
min_length = Int(
- title=u("Minimum length"),
- description=u("Value after whitespace processing cannot have less than "
- "min_length characters. If min_length is None, there is "
- "no minimum."),
+ title=u"Minimum length",
+ description=(
+ u"Value after whitespace processing cannot have less than "
+ u"min_length characters. If min_length is None, there is "
+ u"no minimum."
+ ),
required=False,
min=0, # needs to be a positive number
default=0)
max_length = Int(
- title=u("Maximum length"),
- description=u("Value after whitespace processing cannot have greater "
- "or equal than max_length characters. If max_length is "
- "None, there is no maximum."),
+ title=u"Maximum length",
+ description=(
+ u"Value after whitespace processing cannot have greater "
+ u"or equal than max_length characters. If max_length is "
+ u"None, there is no maximum."
+ ),
required=False,
min=0, # needs to be a positive number
default=None)
@@ -134,13 +138,13 @@ def textField(context, **kw):
class IIntInfo(IFieldInfo):
min = Int(
- title=u("Start of the range"),
+ title=u"Start of the range",
required=False,
default=None
)
max = Int(
- title=u("End of the range (excluding the value itself)"),
+ title=u"End of the range (excluding the value itself)",
required=False,
default=None
)
diff --git a/src/zope/configuration/tests/simple.py b/src/zope/configuration/tests/simple.py
index 6f410cc..60c95ff 100644
--- a/src/zope/configuration/tests/simple.py
+++ b/src/zope/configuration/tests/simple.py
@@ -18,20 +18,19 @@ from zope.interface import Interface
from zope.schema import Text
from zope.configuration.fields import Path
-from zope.configuration._compat import u
class IRegisterFile(Interface):
path = Path(
- title=u("File path"),
- description=u("This is the path name of the file to be registered."),
- )
+ title=u"File path",
+ description=u"This is the path name of the file to be registered.",
+ )
title = Text(
- title=u("Short summary of the file"),
- description=u("This will be used in file listings"),
- required = False
- )
+ title=u"Short summary of the file",
+ description=u"This will be used in file listings",
+ required=False
+ )
class FileInfo(object):
@@ -41,7 +40,7 @@ class FileInfo(object):
file_registry = []
-def registerFile(context, path, title=u("")):
+def registerFile(context, path, title=u""):
info = context.info
description = info.text.strip()
context.action(discriminator=('RegisterFile', path),
diff --git a/src/zope/configuration/tests/test_config.py b/src/zope/configuration/tests/test_config.py
index f894812..1a88397 100644
--- a/src/zope/configuration/tests/test_config.py
+++ b/src/zope/configuration/tests/test_config.py
@@ -1703,9 +1703,8 @@ class Test_toargs(unittest.TestCase):
def test_w_field_missing_but_default(self):
from zope.interface import Interface
from zope.schema import Text
- from zope.configuration._compat import u
class ISchema(Interface):
- w_default = Text(default=u('default'))
+ w_default = Text(default=u'default')
context = FauxContext()
self.assertEqual(self._callFUT(context, ISchema, {}),
{'w_default': 'default'})
diff --git a/src/zope/configuration/tests/test_fields.py b/src/zope/configuration/tests/test_fields.py
index 641e136..282fb00 100644
--- a/src/zope/configuration/tests/test_fields.py
+++ b/src/zope/configuration/tests/test_fields.py
@@ -53,15 +53,13 @@ class PythonIdentifierTests(unittest.TestCase, _ConformsToIFromUnicode):
def test__validate_miss(self):
from zope.schema import ValidationError
- from zope.configuration._compat import u
pi = self._makeOne()
with self.assertRaises(ValidationError):
- pi._validate(u('not-an-identifier'))
+ pi._validate(u'not-an-identifier')
def test__validate_hit(self):
- from zope.configuration._compat import u
pi = self._makeOne()
- pi._validate(u('is_an_identifier'))
+ pi._validate(u'is_an_identifier')
class GlobalObjectTests(unittest.TestCase, _ConformsToIFromUnicode):
@@ -74,20 +72,16 @@ class GlobalObjectTests(unittest.TestCase, _ConformsToIFromUnicode):
return self._getTargetClass()(*args, **kw)
def test__validate_wo_value_type(self):
- from zope.configuration._compat import u
- from zope.configuration._compat import b
go = self._makeOne(value_type=None)
- for value in [0, 0.0, (), [], set(), frozenset(), u(''), b('')]:
+ for value in [0, 0.0, (), [], set(), frozenset(), u'', b'']:
go._validate(value) #noraise
def test__validate_w_value_type(self):
from zope.schema import Text
from zope.schema.interfaces import WrongType
- from zope.configuration._compat import u
- from zope.configuration._compat import b
go = self._makeOne(value_type=Text())
- go.validate(u(''))
- for value in [0, 0.0, (), [], set(), frozenset(), b('')]:
+ go.validate(u'')
+ for value in [0, 0.0, (), [], set(), frozenset(), b'']:
with self.assertRaises(WrongType):
go._validate(value)
@@ -167,20 +161,18 @@ class TokensTests(unittest.TestCase, _ConformsToIFromUnicode):
def test_fromUnicode_strips_ws(self):
from zope.schema import Text
- from zope.configuration._compat import u
tok = self._makeOne(value_type=Text())
context = object()
- self.assertEqual(tok.fromUnicode(u(' one two three ')),
- [u('one'), u('two'), u('three')])
+ self.assertEqual(tok.fromUnicode(u' one two three '),
+ [u'one', u'two', u'three'])
def test_fromUnicode_invalid(self):
from zope.schema import Int
from zope.configuration.interfaces import InvalidToken
- from zope.configuration._compat import u
tok = self._makeOne(value_type=Int(min=0))
context = object()
with self.assertRaises(InvalidToken):
- tok.fromUnicode(u(' 1 -1 3 '))
+ tok.fromUnicode(u' 1 -1 3 ')
class PathTests(unittest.TestCase, _ConformsToIFromUnicode):
@@ -261,12 +253,11 @@ class MessageIDTests(unittest.TestCase, _ConformsToIFromUnicode):
def test_wo_domain(self):
import warnings
- from zope.configuration._compat import u
mid = self._makeOne()
context = self._makeContext(None)
bound = mid.bind(context)
with warnings.catch_warnings(record=True) as log:
- msgid = bound.fromUnicode(u('testing'))
+ msgid = bound.fromUnicode(u'testing')
self.assertEqual(len(log), 1)
self.assertTrue(str(log[0].message).startswith(
'You did not specify an i18n translation domain'))
@@ -278,12 +269,11 @@ class MessageIDTests(unittest.TestCase, _ConformsToIFromUnicode):
def test_w_empty_id(self):
import warnings
- from zope.configuration._compat import u
mid = self._makeOne()
context = self._makeContext()
bound = mid.bind(context)
with warnings.catch_warnings(record=True) as log:
- msgid = bound.fromUnicode(u('[] testing'))
+ msgid = bound.fromUnicode(u'[] testing')
self.assertEqual(len(log), 0)
self.assertEqual(msgid, 'testing')
self.assertEqual(msgid.default, None)
@@ -293,12 +283,11 @@ class MessageIDTests(unittest.TestCase, _ConformsToIFromUnicode):
def test_w_id_and_default(self):
import warnings
- from zope.configuration._compat import u
mid = self._makeOne()
context = self._makeContext()
bound = mid.bind(context)
with warnings.catch_warnings(record=True) as log:
- msgid = bound.fromUnicode(u('[testing] default'))
+ msgid = bound.fromUnicode(u'[testing] default')
self.assertEqual(len(log), 0)
self.assertEqual(msgid, 'testing')
self.assertEqual(msgid.default, 'default')
diff --git a/src/zope/configuration/tests/test_xmlconfig.py b/src/zope/configuration/tests/test_xmlconfig.py
index d59bae9..283aa86 100644
--- a/src/zope/configuration/tests/test_xmlconfig.py
+++ b/src/zope/configuration/tests/test_xmlconfig.py
@@ -15,19 +15,18 @@
"""
import unittest
-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')
+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'
+# pylint:disable=protected-access
class ZopeXMLConfigurationErrorTests(unittest.TestCase):
@@ -96,8 +95,8 @@ class ParserInfoTests(unittest.TestCase):
pi = self._makeOne('/path/to/nonesuch.xml', 24, 32)
pi.end(33, 21)
self.assertEqual(str(pi),
- 'File "/path/to/nonesuch.xml", line 24.32-33.21\n'
- ' Could not read source.')
+ 'File "/path/to/nonesuch.xml", line 24.32-33.21\n'
+ ' Could not read source.')
def test___str___w_good_file(self):
pi = self._makeOne('tests//sample.zcml', 3, 2)
@@ -167,8 +166,8 @@ class ConfigurationHandlerTests(unittest.TestCase):
def test_startElementNS_context_begin_raises_wo_testing(self):
from zope.configuration.xmlconfig import ZopeXMLConfigurationError
class ErrorContext(FauxContext):
- def begin(self, *args):
- raise AttributeError("xxx")
+ def begin(self, *args):
+ raise AttributeError("xxx")
context = ErrorContext()
locator = FauxLocator('tests//sample.zcml', 1, 1)
handler = self._makeOne(context)
@@ -187,8 +186,8 @@ class ConfigurationHandlerTests(unittest.TestCase):
def test_startElementNS_context_begin_raises_w_testing(self):
class ErrorContext(FauxContext):
- def begin(self, *args):
- raise AttributeError("xxx")
+ def begin(self, *args):
+ raise AttributeError("xxx")
context = ErrorContext()
locator = FauxLocator('tests//sample.zcml', 1, 1)
handler = self._makeOne(context, True)
@@ -233,8 +232,8 @@ class ConfigurationHandlerTests(unittest.TestCase):
def test_endElementNS_context_end_raises_wo_testing(self):
from zope.configuration.xmlconfig import ZopeXMLConfigurationError
class ErrorContext(FauxContext):
- def end(self):
- raise AttributeError("xxx")
+ def end(self):
+ raise AttributeError("xxx")
class Info(object):
_line = _col = None
def end(self, line, col):
@@ -254,8 +253,8 @@ class ConfigurationHandlerTests(unittest.TestCase):
def test_endElementNS_context_end_raises_w_testing(self):
class ErrorContext(FauxContext):
- def end(self):
- raise AttributeError("xxx")
+ def end(self):
+ raise AttributeError("xxx")
class Info(object):
_line = _col = None
def end(self, line, col):
@@ -314,7 +313,7 @@ class ConfigurationHandlerTests(unittest.TestCase):
context = FauxContext()
handler = self._makeOne(context)
with self.assertRaises(ValueError) as exc:
- handler.evaluateCondition('installed')
+ handler.evaluateCondition('installed')
self.assertEqual(str(exc.exception.args[0]),
"Package name missing: 'installed'")
@@ -346,7 +345,7 @@ class ConfigurationHandlerTests(unittest.TestCase):
context = FauxContext()
handler = self._makeOne(context)
self.assertTrue(
- handler.evaluateCondition('not-installed nonsuch.package'))
+ handler.evaluateCondition('not-installed nonsuch.package'))
def test_evaluateCondition_w_unknown_verb(self):
context = FauxContext()
@@ -380,10 +379,11 @@ class Test_processxmlfile(unittest.TestCase):
return processxmlfile(*args, **kw)
def test_w_empty_xml(self):
+ from io import StringIO
from zope.configuration.config import ConfigurationMachine
from zope.configuration.xmlconfig import registerCommonDirectives
from zope.configuration.xmlconfig import ZopeSAXParseException
- from zope.configuration._compat import StringIO
+
context = ConfigurationMachine()
registerCommonDirectives(context)
with self.assertRaises(ZopeSAXParseException) as exc:
@@ -395,21 +395,22 @@ class Test_processxmlfile(unittest.TestCase):
# Integration test, really
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()
registerCommonDirectives(context)
- self._callFUT(file, context)
+
+ with open(path("samplepackage", "configure.zcml")) as file:
+ self._callFUT(file, context)
self.assertEqual(foo.data, [])
context.execute_actions()
data = foo.data.pop()
- self.assertEqual(data.args, (('x', b('blah')), ('y', 0)))
+ 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')
+ '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'
- + ' <test:foo x="blah" y="0" />')
+ 'File "tests/samplepackage/configure.zcml", line 12.2-12.29\n'
+ + ' <test:foo x="blah" y="0" />')
self.assertEqual(data.package, None)
self.assertEqual(data.basepath, None)
@@ -536,7 +537,6 @@ class Test_include(unittest.TestCase):
from zope.configuration import xmlconfig
from zope.configuration.config import ConfigurationMachine
from zope.configuration.xmlconfig import registerCommonDirectives
- from zope.configuration._compat import b
from zope.configuration.tests import samplepackage
from zope.configuration.tests.samplepackage import foo
context = ConfigurationMachine()
@@ -557,12 +557,12 @@ class Test_include(unittest.TestCase):
self.assertEqual(action['callable'], foo.data.append)
self.assertEqual(action['includepath'], (fqn2,))
self.assertIsInstance(action['args'][0], foo.stuff)
- self.assertEqual(action['args'][0].args, (('x', b('foo')), ('y', 2)))
+ self.assertEqual(action['args'][0].args, (('x', (b'foo')), ('y', 2)))
action = context.actions[1]
self.assertEqual(action['callable'], foo.data.append)
self.assertEqual(action['includepath'], (fqn3,))
self.assertIsInstance(action['args'][0], foo.stuff)
- self.assertEqual(action['args'][0].args, (('x', b('foo')), ('y', 3)))
+ self.assertEqual(action['args'][0].args, (('x', (b'foo')), ('y', 3)))
self.assertEqual(context.stack, before_stack)
self.assertEqual(len(context._seen_files), 3)
self.assertIn(fqn1, context._seen_files)
@@ -698,7 +698,6 @@ class Test_file(unittest.TestCase):
def test_wo_execute_wo_context_wo_package(self):
from zope.configuration import xmlconfig
- from zope.configuration._compat import b
from zope.configuration.tests.samplepackage import foo
file_name = path("samplepackage", "configure.zcml")
logger = LoggerStub()
@@ -710,12 +709,11 @@ class Test_file(unittest.TestCase):
self.assertEqual(len(context.actions), 1)
action = context.actions[0]
self.assertEqual(action['discriminator'],
- (('x', b('blah')), ('y', 0)))
+ (('x', (b'blah')), ('y', 0)))
self.assertEqual(action['callable'], foo.data.append)
def test_wo_execute_wo_context_w_package(self):
from zope.configuration import xmlconfig
- from zope.configuration._compat import b
from zope.configuration.tests import samplepackage
from zope.configuration.tests.samplepackage import foo
file_name = path("samplepackage", "configure.zcml")
@@ -730,14 +728,13 @@ class Test_file(unittest.TestCase):
self.assertEqual(len(context.actions), 1)
action = context.actions[0]
self.assertEqual(action['discriminator'],
- (('x', b('blah')), ('y', 0)))
+ (('x', (b'blah')), ('y', 0)))
self.assertEqual(action['callable'], foo.data.append)
def test_wo_execute_w_context(self):
from zope.configuration import xmlconfig
from zope.configuration.config import ConfigurationMachine
from zope.configuration.xmlconfig import registerCommonDirectives
- from zope.configuration._compat import b
from zope.configuration.tests import samplepackage
from zope.configuration.tests.samplepackage import foo
context = ConfigurationMachine()
@@ -755,22 +752,21 @@ class Test_file(unittest.TestCase):
self.assertEqual(len(context.actions), 1)
action = context.actions[0]
self.assertEqual(action['discriminator'],
- (('x', b('blah')), ('y', 0)))
+ (('x', (b'blah')), ('y', 0)))
self.assertEqual(action['callable'], foo.data.append)
def test_w_execute(self):
import os
from zope.configuration import xmlconfig
- from zope.configuration._compat import b
from zope.configuration.tests.samplepackage import foo
file_name = path("samplepackage", "configure.zcml")
logger = LoggerStub()
with _Monkey(xmlconfig, logger=logger):
- context = self._callFUT(file_name)
+ self._callFUT(file_name)
self.assertEqual(len(logger.debugs), 1)
self.assertEqual(logger.debugs[0], ('include %s', (file_name,), {}))
data = foo.data.pop()
- self.assertEqual(data.args, (('x', b('blah')), ('y', 0)))
+ self.assertEqual(data.args, (('x', (b'blah')), ('y', 0)))
self.assertTrue(
data.info.file.endswith(
os.path.normpath('tests/samplepackage/configure.zcml')))
@@ -780,7 +776,7 @@ class Test_file(unittest.TestCase):
self.assertEqual(data.info.ecolumn, 29)
self.assertEqual(data.package, None)
self.assertTrue(data.basepath.endswith(
- os.path.normpath('tests/samplepackage')))
+ os.path.normpath('tests/samplepackage')))
class Test_string(unittest.TestCase):
@@ -790,7 +786,6 @@ class Test_string(unittest.TestCase):
return string(*args, **kw)
def test_wo_execute_wo_context(self):
- from zope.configuration._compat import b
from zope.configuration.tests.samplepackage import foo
file_name = path("samplepackage", "configure.zcml")
with open(file_name) as f:
@@ -800,13 +795,12 @@ class Test_string(unittest.TestCase):
self.assertEqual(len(context.actions), 1)
action = context.actions[0]
self.assertEqual(action['discriminator'],
- (('x', b('blah')), ('y', 0)))
+ (('x', (b'blah')), ('y', 0)))
self.assertEqual(action['callable'], foo.data.append)
def test_wo_execute_w_context(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
context = ConfigurationMachine()
registerCommonDirectives(context)
@@ -819,18 +813,17 @@ class Test_string(unittest.TestCase):
self.assertEqual(len(context.actions), 1)
action = context.actions[0]
self.assertEqual(action['discriminator'],
- (('x', b('blah')), ('y', 0)))
+ (('x', (b'blah')), ('y', 0)))
self.assertEqual(action['callable'], foo.data.append)
def test_w_execute(self):
- from zope.configuration._compat import b
from zope.configuration.tests.samplepackage import foo
file_name = path("samplepackage", "configure.zcml")
with open(file_name) as f:
xml = f.read()
- context = self._callFUT(xml)
+ self._callFUT(xml)
data = foo.data.pop()
- self.assertEqual(data.args, (('x', b('blah')), ('y', 0)))
+ self.assertEqual(data.args, (('x', (b'blah')), ('y', 0)))
self.assertTrue(data.info.file, '<string>')
self.assertEqual(data.info.line, 12)
self.assertEqual(data.info.column, 2)
@@ -864,7 +857,6 @@ class XMLConfigTests(unittest.TestCase):
def test_ctor_w_global_context_missing(self):
import os
from zope.configuration import xmlconfig
- from zope.configuration._compat import b
from zope.configuration.tests.samplepackage import foo
here = os.path.dirname(__file__)
path = os.path.join(here, "samplepackage", "configure.zcml")
@@ -878,12 +870,11 @@ class XMLConfigTests(unittest.TestCase):
self.assertEqual(len(xc.context.actions), 1)
action = xc.context.actions[0]
self.assertEqual(action['discriminator'],
- (('x', b('blah')), ('y', 0)))
+ (('x', (b'blah')), ('y', 0)))
self.assertEqual(action['callable'], foo.data.append)
def test_ctor(self):
from zope.configuration import xmlconfig
- from zope.configuration._compat import b
from zope.configuration.tests import samplepackage
from zope.configuration.tests.samplepackage import foo
fqn = _packageFile(samplepackage, 'configure.zcml')
@@ -896,12 +887,11 @@ class XMLConfigTests(unittest.TestCase):
self.assertEqual(len(xc.context.actions), 1)
action = xc.context.actions[0]
self.assertEqual(action['discriminator'],
- (('x', b('blah')), ('y', 0)))
+ (('x', (b'blah')), ('y', 0)))
self.assertEqual(action['callable'], foo.data.append)
def test_ctor_w_module(self):
from zope.configuration import xmlconfig
- from zope.configuration._compat import b
from zope.configuration.tests.samplepackage import foo
from zope.configuration.tests import samplepackage
fqn = _packageFile(samplepackage, 'configure.zcml')
@@ -914,13 +904,12 @@ class XMLConfigTests(unittest.TestCase):
self.assertEqual(len(xc.context.actions), 1)
action = xc.context.actions[0]
self.assertEqual(action['discriminator'],
- (('x', b('blah')), ('y', 0)))
+ (('x', (b'blah')), ('y', 0)))
self.assertEqual(action['callable'], foo.data.append)
def test___call__(self):
import os
from zope.configuration import xmlconfig
- from zope.configuration._compat import b
from zope.configuration.tests import samplepackage
from zope.configuration.tests.samplepackage import foo
fqn = _packageFile(samplepackage, 'configure.zcml')
@@ -933,7 +922,7 @@ class XMLConfigTests(unittest.TestCase):
xc() # call to process the actions
self.assertEqual(len(foo.data), 1)
data = foo.data.pop(0)
- self.assertEqual(data.args, (('x', b('blah')), ('y', 0)))
+ self.assertEqual(data.args, (('x', (b'blah')), ('y', 0)))
self.assertTrue(
data.info.file.endswith(
os.path.normpath('tests/samplepackage/configure.zcml')))
@@ -965,24 +954,23 @@ class Test_xmlconfig(unittest.TestCase):
def test_wo_testing_passed(self):
import os
from zope.configuration import xmlconfig
- from zope.configuration._compat import b
from zope.configuration.tests import samplepackage
from zope.configuration.tests.samplepackage import foo
def _assertTestingFalse(func):
def _wrapper(*args, **kw):
- assert(not kw['testing'])
+ assert not kw['testing']
return func(*args, **kw)
return _wrapper
fqn = _packageFile(samplepackage, 'configure.zcml')
context = xmlconfig._getContext()
context.execute_actions = _assertTestingFalse(context.execute_actions)
with _Monkey(xmlconfig,
- processxmlfile=_assertTestingFalse(
- xmlconfig.processxmlfile)):
+ processxmlfile=_assertTestingFalse(
+ xmlconfig.processxmlfile)):
self._callFUT(open(fqn), False)
self.assertEqual(len(foo.data), 1)
data = foo.data.pop(0)
- self.assertEqual(data.args, (('x', b('blah')), ('y', 0)))
+ self.assertEqual(data.args, (('x', (b'blah')), ('y', 0)))
self.assertTrue(
data.info.file.endswith(
os.path.normpath('tests/samplepackage/configure.zcml')))
@@ -994,24 +982,23 @@ class Test_xmlconfig(unittest.TestCase):
def test_w_testing_passed(self):
import os
from zope.configuration import xmlconfig
- from zope.configuration._compat import b
from zope.configuration.tests import samplepackage
from zope.configuration.tests.samplepackage import foo
def _assertTestingTrue(func):
def _wrapper(*args, **kw):
- assert(kw['testing'])
+ assert kw['testing']
return func(*args, **kw)
return _wrapper
fqn = _packageFile(samplepackage, 'configure.zcml')
context = xmlconfig._getContext()
context.execute_actions = _assertTestingTrue(context.execute_actions)
with _Monkey(xmlconfig,
- processxmlfile=_assertTestingTrue(
- xmlconfig.processxmlfile)):
+ processxmlfile=_assertTestingTrue(
+ xmlconfig.processxmlfile)):
self._callFUT(open(fqn), True)
self.assertEqual(len(foo.data), 1)
data = foo.data.pop(0)
- self.assertEqual(data.args, (('x', b('blah')), ('y', 0)))
+ self.assertEqual(data.args, (('x', (b'blah')), ('y', 0)))
self.assertTrue(
data.info.file.endswith(
os.path.normpath('tests/samplepackage/configure.zcml')))
@@ -1042,24 +1029,23 @@ class Test_testxmlconfig(unittest.TestCase):
def test_w_testing_passed(self):
import os
from zope.configuration import xmlconfig
- from zope.configuration._compat import b
from zope.configuration.tests import samplepackage
from zope.configuration.tests.samplepackage import foo
def _assertTestingTrue(func):
def _wrapper(*args, **kw):
- assert(kw['testing'])
+ assert kw['testing']
return func(*args, **kw)
return _wrapper
fqn = _packageFile(samplepackage, 'configure.zcml')
context = xmlconfig._getContext()
context.execute_actions = _assertTestingTrue(context.execute_actions)
with _Monkey(xmlconfig,
- processxmlfile=_assertTestingTrue(
- xmlconfig.processxmlfile)):
+ processxmlfile=_assertTestingTrue(
+ xmlconfig.processxmlfile)):
self._callFUT(open(fqn))
self.assertEqual(len(foo.data), 1)
data = foo.data.pop(0)
- self.assertEqual(data.args, (('x', b('blah')), ('y', 0)))
+ self.assertEqual(data.args, (('x', (b'blah')), ('y', 0)))
self.assertTrue(
data.info.file.endswith(
os.path.normpath('tests/samplepackage/configure.zcml')))
@@ -1119,12 +1105,13 @@ def clean_path(s):
def clean_actions(actions):
return [
- {'discriminator': action['discriminator'],
- 'info': clean_info_path(repr(action['info'])),
- 'includepath': [clean_path(p) for p in action['includepath']],
- }
- for action in actions
- ]
+ {
+ 'discriminator': action['discriminator'],
+ 'info': clean_info_path(repr(action['info'])),
+ 'includepath': [clean_path(p) for p in action['includepath']],
+ }
+ for action in actions
+ ]
def clean_text_w_paths(error):
r = []
@@ -1158,7 +1145,7 @@ class _Monkey(object):
setattr(self.module, k, v)
def __exit__(self, *exc_info):
- for k, v in self.replacements.items():
+ for k in self.replacements:
if k in self.orig:
setattr(self.module, k, self.orig[k])
else: #pragma NO COVERSGE
diff --git a/src/zope/configuration/xmlconfig.py b/src/zope/configuration/xmlconfig.py
index 55d1aee..d33cd69 100644
--- a/src/zope/configuration/xmlconfig.py
+++ b/src/zope/configuration/xmlconfig.py
@@ -22,6 +22,7 @@ __docformat__ = 'restructuredtext'
import errno
from glob import glob
import logging
+import io
import os
import sys
from xml.sax import make_parser
@@ -42,7 +43,6 @@ from zope.configuration.exceptions import ConfigurationError
from zope.configuration.fields import GlobalObject
from zope.configuration.zopeconfigure import IZopeConfigure
from zope.configuration.zopeconfigure import ZopeConfigure
-from zope.configuration._compat import StringIO
from zope.configuration._compat import reraise
logger = logging.getLogger("config")
@@ -326,9 +326,11 @@ class IInclude(Interface):
file = NativeStringLine(
title=u"Configuration file name",
- description=(u"The name of a configuration file to be included/"
- u"excluded, relative to the directive containing the "
- u"including configuration file."),
+ description=(
+ u"The name of a configuration file to be included/"
+ u"excluded, relative to the directive containing the "
+ u"including configuration file."
+ ),
required=False,
)
@@ -510,7 +512,7 @@ def string(s, context=None, name="<string>", execute=True):
context = ConfigurationMachine()
registerCommonDirectives(context)
- f = StringIO(s)
+ f = io.BytesIO(s) if isinstance(s, bytes) else io.StringIO(s)
f.name = name
processxmlfile(f, context)
diff --git a/src/zope/configuration/zopeconfigure.py b/src/zope/configuration/zopeconfigure.py
index 48ced1a..7204aeb 100644
--- a/src/zope/configuration/zopeconfigure.py
+++ b/src/zope/configuration/zopeconfigure.py
@@ -105,7 +105,7 @@ from zope.schema import BytesLine
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
@@ -117,24 +117,29 @@ class IZopeConfigure(Interface):
information collected is used by subdirectives.
It may seem that this directive can only be used once per file, but it can
- be applied whereever it is convenient.
+ be applied whereever it is convenient.
"""
package = GlobalObject(
- title=u("Package"),
- description=u("The package to be used for evaluating relative imports "
- "and file names."),
+ title=u"Package",
+ description=(
+ u"The package to be used for evaluating relative imports "
+ u"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 "
- "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)
+ 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."
+ ),
+ required=False
+ )
class ZopeConfigure(GroupingContextDecorator):
@@ -146,4 +151,3 @@ class ZopeConfigure(GroupingContextDecorator):
# if we have a package, we want to also define basepath
# so we don't acquire one
self.basepath = os.path.dirname(self.package.__file__)
-