Skip to content

Commit

Permalink
Merge pull request #27 from zopefoundation/issue26
Browse files Browse the repository at this point in the history
Remove unneeded internal _compat functions and aliases
  • Loading branch information
jamadden committed Sep 24, 2018
2 parents aac9d8e + a5e291a commit 82eacf5
Show file tree
Hide file tree
Showing 14 changed files with 194 additions and 263 deletions.
6 changes: 5 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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``.

Expand Down
5 changes: 2 additions & 3 deletions docs/api/fields.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand All @@ -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']
Expand Down
67 changes: 4 additions & 63 deletions src/zope/configuration/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,12 @@

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):
Expand All @@ -38,63 +30,12 @@ def reraise(tp, value, tb=None):
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("""\
Expand Down
61 changes: 33 additions & 28 deletions src/zope/configuration/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
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'
Expand Down Expand Up @@ -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):
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -935,8 +940,8 @@ def __str__(self): #pragma NO COVER
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)

Expand Down
4 changes: 2 additions & 2 deletions src/zope/configuration/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@

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)


Expand Down
8 changes: 4 additions & 4 deletions src/zope/configuration/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand All @@ -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
Expand Down
8 changes: 3 additions & 5 deletions src/zope/configuration/tests/conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []

Expand Down
52 changes: 28 additions & 24 deletions src/zope/configuration/tests/nested.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
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 = {}
Expand All @@ -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
Expand Down Expand Up @@ -75,43 +75,47 @@ def after(self):
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)
Expand All @@ -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
)
Expand Down

0 comments on commit 82eacf5

Please sign in to comment.