[Checkins] SVN: zope.schema/branches/jinty-python3/ Port to Python 3. This adds a dependency on six and removes support for
Brian Sutherland
jinty at web.de
Mon Oct 10 05:46:35 EST 2011
Log message for revision 123043:
Port to Python 3. This adds a dependency on six and removes support for
Python 2.5.
It should be relatively easy to remove the dependency on six and support Python
2.5 as well. But the code will be quite a bit uglier.
Changed:
U zope.schema/branches/jinty-python3/CHANGES.txt
U zope.schema/branches/jinty-python3/setup.py
U zope.schema/branches/jinty-python3/src/zope/schema/README.txt
U zope.schema/branches/jinty-python3/src/zope/schema/_bootstrapfields.py
U zope.schema/branches/jinty-python3/src/zope/schema/_bootstrapinterfaces.py
U zope.schema/branches/jinty-python3/src/zope/schema/_field.py
U zope.schema/branches/jinty-python3/src/zope/schema/_messageid.py
U zope.schema/branches/jinty-python3/src/zope/schema/_schema.py
U zope.schema/branches/jinty-python3/src/zope/schema/fieldproperty.py
U zope.schema/branches/jinty-python3/src/zope/schema/fields.txt
U zope.schema/branches/jinty-python3/src/zope/schema/interfaces.py
U zope.schema/branches/jinty-python3/src/zope/schema/sources.txt
U zope.schema/branches/jinty-python3/src/zope/schema/tests/__init__.py
U zope.schema/branches/jinty-python3/src/zope/schema/tests/states.py
U zope.schema/branches/jinty-python3/src/zope/schema/tests/test_accessors.py
U zope.schema/branches/jinty-python3/src/zope/schema/tests/test_boolfield.py
U zope.schema/branches/jinty-python3/src/zope/schema/tests/test_choice.py
U zope.schema/branches/jinty-python3/src/zope/schema/tests/test_containerfield.py
U zope.schema/branches/jinty-python3/src/zope/schema/tests/test_date.py
U zope.schema/branches/jinty-python3/src/zope/schema/tests/test_datetime.py
U zope.schema/branches/jinty-python3/src/zope/schema/tests/test_decimalfield.py
U zope.schema/branches/jinty-python3/src/zope/schema/tests/test_dictfield.py
U zope.schema/branches/jinty-python3/src/zope/schema/tests/test_docs.py
U zope.schema/branches/jinty-python3/src/zope/schema/tests/test_dotted_name.py
U zope.schema/branches/jinty-python3/src/zope/schema/tests/test_equality.py
U zope.schema/branches/jinty-python3/src/zope/schema/tests/test_field.py
U zope.schema/branches/jinty-python3/src/zope/schema/tests/test_fieldproperty.py
U zope.schema/branches/jinty-python3/src/zope/schema/tests/test_floatfield.py
U zope.schema/branches/jinty-python3/src/zope/schema/tests/test_interfacefield.py
U zope.schema/branches/jinty-python3/src/zope/schema/tests/test_intfield.py
U zope.schema/branches/jinty-python3/src/zope/schema/tests/test_iterablefield.py
U zope.schema/branches/jinty-python3/src/zope/schema/tests/test_listfield.py
U zope.schema/branches/jinty-python3/src/zope/schema/tests/test_objectfield.py
U zope.schema/branches/jinty-python3/src/zope/schema/tests/test_schema.py
U zope.schema/branches/jinty-python3/src/zope/schema/tests/test_setfield.py
U zope.schema/branches/jinty-python3/src/zope/schema/tests/test_states.py
U zope.schema/branches/jinty-python3/src/zope/schema/tests/test_strfield.py
U zope.schema/branches/jinty-python3/src/zope/schema/tests/test_timedelta.py
U zope.schema/branches/jinty-python3/src/zope/schema/tests/test_tuplefield.py
U zope.schema/branches/jinty-python3/src/zope/schema/tests/test_vocabulary.py
U zope.schema/branches/jinty-python3/src/zope/schema/validation.txt
U zope.schema/branches/jinty-python3/src/zope/schema/vocabulary.py
-=-
Modified: zope.schema/branches/jinty-python3/CHANGES.txt
===================================================================
--- zope.schema/branches/jinty-python3/CHANGES.txt 2011-10-10 10:44:37 UTC (rev 123042)
+++ zope.schema/branches/jinty-python3/CHANGES.txt 2011-10-10 10:46:35 UTC (rev 123043)
@@ -2,10 +2,11 @@
CHANGES
=======
-3.8.2 (unreleased)
+3.9.0 (unreleased)
------------------
-- ...
+- Port to Python 3. This adds a dependency on six and removes support for
+ Python 2.5.
3.8.1 (2011-09-23)
------------------
Modified: zope.schema/branches/jinty-python3/setup.py
===================================================================
--- zope.schema/branches/jinty-python3/setup.py 2011-10-10 10:44:37 UTC (rev 123042)
+++ zope.schema/branches/jinty-python3/setup.py 2011-10-10 10:46:35 UTC (rev 123043)
@@ -82,9 +82,22 @@
extras_require={'test': ['zope.testing'],
'docs': ['z3c.recipe.sphinxdoc']},
install_requires=['setuptools',
- 'zope.interface',
+ 'zope.interface >= 3.6.0',
'zope.event',
+ 'six',
],
+ classifiers=[
+ "Development Status :: 5 - Production/Stable",
+ "Intended Audience :: Developers",
+ "License :: OSI Approved :: Zope Public License",
+ "Operating System :: OS Independent",
+ "Programming Language :: Python :: 2.6",
+ "Programming Language :: Python :: 2.7",
+ "Programming Language :: Python :: 3",
+ "Programming Language :: Python :: 3.1",
+ "Programming Language :: Python :: 3.2",
+ "Topic :: Software Development :: Libraries :: Python Modules",
+ ],
include_package_data = True,
zip_safe = False,
test_suite='__main__.alltests',
Modified: zope.schema/branches/jinty-python3/src/zope/schema/README.txt
===================================================================
--- zope.schema/branches/jinty-python3/src/zope/schema/README.txt 2011-10-10 10:44:37 UTC (rev 123042)
+++ zope.schema/branches/jinty-python3/src/zope/schema/README.txt 2011-10-10 10:46:35 UTC (rev 123043)
@@ -35,24 +35,25 @@
>>> import zope.interface
>>> import zope.schema
+ >>> from six import u, b
>>> class IBookmark(zope.interface.Interface):
... title = zope.schema.TextLine(
- ... title=u'Title',
- ... description=u'The title of the bookmark',
+ ... title=u('Title'),
+ ... description=u('The title of the bookmark'),
... required=True)
...
... url = zope.schema.URI(
- ... title=u'Bookmark URL',
- ... description=u'URL of the Bookmark',
+ ... title=u('Bookmark URL'),
+ ... description=u('URL of the Bookmark'),
... required=True)
...
Now we create a class that implements this interface and create an instance of
it:
- >>> class Bookmark(object):
- ... zope.interface.implements(IBookmark)
+ >>> @zope.interface.implementer(IBookmark)
+ ... class Bookmark(object):
...
... title = None
... url = None
@@ -63,8 +64,8 @@
by first validating and then setting the value on the object. The first step
is to define some data:
- >>> title = u'Zope 3 Website'
- >>> url = 'http://dev.zope.org/Zope3'
+ >>> title = u('Zope 3 Website')
+ >>> url = b('http://dev.zope.org/Zope3')
Now we, get the fields from the interface:
@@ -85,12 +86,12 @@
If the validation is successful, ``None`` is returned. If a validation error
occurs a ``ValidationError`` will be raised; for example:
- >>> url_bound.validate(u'http://zope.org/foo')
+ >>> url_bound.validate(u('http://zope.org/foo'))
Traceback (most recent call last):
...
WrongType: (u'http://zope.org/foo', <type 'str'>, 'url')
- >>> url_bound.validate('foo.bar')
+ >>> url_bound.validate(b('foo.bar'))
Traceback (most recent call last):
...
InvalidURI: foo.bar
@@ -128,16 +129,16 @@
>>> class IContact(zope.interface.Interface):
... """Provides access to basic contact information."""
...
- ... first = zope.schema.TextLine(title=u"First name")
+ ... first = zope.schema.TextLine(title=u("First name"))
...
- ... last = zope.schema.TextLine(title=u"Last name")
+ ... last = zope.schema.TextLine(title=u("Last name"))
...
- ... email = zope.schema.TextLine(title=u"Electronic mail address")
+ ... email = zope.schema.TextLine(title=u("Electronic mail address"))
...
- ... address = zope.schema.Text(title=u"Postal address")
+ ... address = zope.schema.Text(title=u("Postal address"))
...
... postalCode = zope.schema.TextLine(
- ... title=u"Postal code",
+ ... title=u("Postal code"),
... constraint=re.compile("\d{5,5}(-\d{4,4})?$").match)
``TextLine`` is a field and expresses that an attribute is a single line
@@ -161,8 +162,8 @@
Now you can see if an instance of ``Contact`` actually implements the
schema:
- >>> someone = Contact(u'Tim', u'Roberts', u'tim at roberts', u'',
- ... u'12032-3492')
+ >>> someone = Contact(u('Tim'), u('Roberts'), u('tim at roberts'), u(''),
+ ... u('12032-3492'))
>>> for field in zope.schema.getFields(IContact).values():
... bound = field.bind(someone)
Modified: zope.schema/branches/jinty-python3/src/zope/schema/_bootstrapfields.py
===================================================================
--- zope.schema/branches/jinty-python3/src/zope/schema/_bootstrapfields.py 2011-10-10 10:44:37 UTC (rev 123042)
+++ zope.schema/branches/jinty-python3/src/zope/schema/_bootstrapfields.py 2011-10-10 10:46:35 UTC (rev 123043)
@@ -17,7 +17,8 @@
import sys
-from zope.interface import Attribute, providedBy, implements
+from six import u, b, text_type, integer_types
+from zope.interface import Attribute, providedBy, implementer
from zope.schema._bootstrapinterfaces import StopValidation
from zope.schema._bootstrapinterfaces import IFromUnicode
from zope.schema._bootstrapinterfaces import RequiredMissing, WrongType
@@ -102,7 +103,7 @@
interface = None
_Element__tagged_values = None
- def __init__(self, title=u'', description=u'', __name__='',
+ def __init__(self, title=u(''), description=u(''), __name__='',
required=True, readonly=False, constraint=None, default=None,
defaultFactory=None, missing_value=__missing_value_marker):
"""Pass in field values as keyword parameters.
@@ -122,11 +123,11 @@
>>> f.__doc__, f.title, f.description
('', u'', u'')
- >>> f = Field(title=u'sample')
+ >>> f = Field(title=u('sample'))
>>> f.__doc__, f.title, f.description
(u'sample', u'sample', u'')
- >>> f = Field(title=u'sample', description=u'blah blah\\nblah')
+ >>> f = Field(title=u('sample'), description=u('blah blah\\nblah'))
>>> f.__doc__, f.title, f.description
(u'sample\\n\\nblah blah\\nblah', u'sample', u'blah blah\\nblah')
"""
@@ -304,25 +305,24 @@
raise TooLong(value, self.max_length)
+ at implementer(IFromUnicode)
class Text(MinMaxLen, Field):
"""A field containing text used for human discourse."""
- _type = unicode
+ _type = text_type
- implements(IFromUnicode)
-
def __init__(self, *args, **kw):
super(Text, self).__init__(*args, **kw)
def fromUnicode(self, str):
"""
>>> t = Text(constraint=lambda v: 'x' in v)
- >>> t.fromUnicode("foo x spam")
+ >>> t.fromUnicode(b("foo x spam"))
Traceback (most recent call last):
...
WrongType: ('foo x spam', <type 'unicode'>, '')
- >>> t.fromUnicode(u"foo x spam")
+ >>> t.fromUnicode(u("foo x spam"))
u'foo x spam'
- >>> t.fromUnicode(u"foo spam")
+ >>> t.fromUnicode(u("foo spam"))
Traceback (most recent call last):
...
ConstraintNotSatisfied: foo spam
@@ -410,12 +410,11 @@
return v
+ at implementer(IFromUnicode)
class Int(Orderable, Field):
"""A field representing an Integer."""
- _type = int, long
+ _type = integer_types
- implements(IFromUnicode)
-
def __init__(self, *args, **kw):
super(Int, self).__init__(*args, **kw)
Modified: zope.schema/branches/jinty-python3/src/zope/schema/_bootstrapinterfaces.py
===================================================================
--- zope.schema/branches/jinty-python3/src/zope/schema/_bootstrapinterfaces.py 2011-10-10 10:44:37 UTC (rev 123042)
+++ zope.schema/branches/jinty-python3/src/zope/schema/_bootstrapinterfaces.py 2011-10-10 10:46:35 UTC (rev 123043)
@@ -35,6 +35,13 @@
return -1
return cmp(self.args, other.args)
+ def __eq__(self, other):
+ if not hasattr(other, 'args'):
+ return False
+ return self.args == other.args
+
+ __hash__ = zope.interface.Invalid.__hash__ # python3
+
def __repr__(self):
return '%s(%s)' % (self.__class__.__name__,
', '.join(repr(arg) for arg in self.args))
Modified: zope.schema/branches/jinty-python3/src/zope/schema/_field.py
===================================================================
--- zope.schema/branches/jinty-python3/src/zope/schema/_field.py 2011-10-10 10:44:37 UTC (rev 123042)
+++ zope.schema/branches/jinty-python3/src/zope/schema/_field.py 2011-10-10 10:46:35 UTC (rev 123043)
@@ -22,8 +22,9 @@
from datetime import datetime, date, timedelta, time
from zope.event import notify
-from zope.interface import classImplements, implements, Interface
+from zope.interface import classImplements, implementer, Interface
from zope.interface.interfaces import IInterface, IMethod
+from six import u, b, text_type, string_types, binary_type, PY3
from zope.schema.interfaces import IField
from zope.schema.interfaces import IMinMaxLen, IText, ITextLine
@@ -72,39 +73,61 @@
classImplements(Bool, IFromUnicode)
classImplements(Int, IInt)
+if PY3:
+ def _to_string(str):
+ return str.decode('ascii')
+ def _max_string_ord(bytes):
+ return max(bytes)
+else:
+ def _to_string(str):
+ return str
+
+ def _max_string_ord(bytes):
+ return max(map(ord, bytes))
+
+def _re_on_bytes(re):
+ if PY3:
+ def f(in_bytes):
+ return re(_to_string(in_bytes))
+ return f
+ return re
+
+ at implementer(ISourceText)
class SourceText(Text):
__doc__ = ISourceText.__doc__
- implements(ISourceText)
- _type = unicode
+ _type = text_type
+ at implementer(IBytes, IFromUnicode)
class Bytes(MinMaxLen, Field):
__doc__ = IBytes.__doc__
- implements(IBytes, IFromUnicode)
- _type = str
+ _type = binary_type
def fromUnicode(self, u):
"""
- >>> b = Bytes(constraint=lambda v: 'x' in v)
+ >>> obj = Bytes(constraint=lambda v: b('x') in v)
- >>> b.fromUnicode(u" foo x.y.z bat")
+ >>> obj.fromUnicode(u(" foo x.y.z bat"))
' foo x.y.z bat'
- >>> b.fromUnicode(u" foo y.z bat")
+ >>> obj.fromUnicode(u(" foo y.z bat"))
Traceback (most recent call last):
...
ConstraintNotSatisfied: foo y.z bat
"""
- v = str(u)
+ if PY3:
+ v = b(u)
+ else:
+ v = str(u)
self.validate(v)
return v
+ at implementer(IASCII)
class ASCII(Bytes):
__doc__ = IASCII.__doc__
- implements(IASCII)
def _validate(self, value):
"""
@@ -112,15 +135,15 @@
Make sure we accept empty strings:
- >>> empty = ''
+ >>> empty = b('')
>>> ascii._validate(empty)
and all kinds of alphanumeric strings:
- >>> alphanumeric = "Bob\'s my 23rd uncle"
+ >>> alphanumeric = b("Bob\'s my 23rd uncle")
>>> ascii._validate(alphanumeric)
- >>> umlauts = "KöhlerstraÃe"
+ >>> umlauts = b("KöhlerstraÃe")
>>> ascii._validate(umlauts)
Traceback (most recent call last):
...
@@ -129,33 +152,31 @@
super(ASCII, self)._validate(value)
if not value:
return
- if not max(map(ord, value)) < 128:
+ if not _max_string_ord(value) < 128:
raise InvalidValue
+ at implementer(IBytesLine)
class BytesLine(Bytes):
"""A Text field with no newlines."""
- implements(IBytesLine)
-
def constraint(self, value):
# TODO: we should probably use a more general definition of newlines
- return '\n' not in value
+ return b('\n') not in value
+ at implementer(IASCIILine)
class ASCIILine(ASCII):
__doc__ = IASCIILine.__doc__
- implements(IASCIILine)
-
def constraint(self, value):
# TODO: we should probably use a more general definition of newlines
- return '\n' not in value
+ return b('\n') not in value
+ at implementer(IFloat, IFromUnicode)
class Float(Orderable, Field):
__doc__ = IFloat.__doc__
- implements(IFloat, IFromUnicode)
_type = float
def __init__(self, *args, **kw):
@@ -176,9 +197,9 @@
return v
+ at implementer(IDecimal, IFromUnicode)
class Decimal(Orderable, Field):
__doc__ = IDecimal.__doc__
- implements(IDecimal, IFromUnicode)
_type = decimal.Decimal
def __init__(self, *args, **kw):
@@ -205,18 +226,18 @@
return v
+ at implementer(IDatetime)
class Datetime(Orderable, Field):
__doc__ = IDatetime.__doc__
- implements(IDatetime)
_type = datetime
def __init__(self, *args, **kw):
super(Datetime, self).__init__(*args, **kw)
+ at implementer(IDate)
class Date(Orderable, Field):
__doc__ = IDate.__doc__
- implements(IDate)
_type = date
def _validate(self, value):
@@ -225,28 +246,28 @@
raise WrongType(value, self._type, self.__name__)
+ at implementer(ITimedelta)
class Timedelta(Orderable, Field):
__doc__ = ITimedelta.__doc__
- implements(ITimedelta)
_type = timedelta
+ at implementer(ITime)
class Time(Orderable, Field):
__doc__ = ITime.__doc__
- implements(ITime)
_type = time
+ at implementer(IChoice, IFromUnicode)
class Choice(Field):
"""Choice fields can have a value found in a constant or dynamic set of
values given by the field definition.
"""
- implements(IChoice, IFromUnicode)
def __init__(self, values=None, vocabulary=None, source=None, **kw):
"""Initialize object."""
if vocabulary is not None:
- assert (isinstance(vocabulary, basestring)
+ assert (isinstance(vocabulary, string_types)
or IBaseVocabulary.providedBy(vocabulary))
assert source is None, (
"You cannot specify both source and vocabulary.")
@@ -262,7 +283,7 @@
self.vocabularyName = None
if values is not None:
self.vocabulary = SimpleVocabulary.fromValues(values)
- elif isinstance(vocabulary, (unicode, str)):
+ elif isinstance(vocabulary, string_types):
self.vocabularyName = vocabulary
else:
assert (ISource.providedBy(vocabulary) or
@@ -296,16 +317,16 @@
def fromUnicode(self, str):
"""
- >>> from vocabulary import SimpleVocabulary
+ >>> from zope.schema.vocabulary import SimpleVocabulary
>>> t = Choice(
- ... vocabulary=SimpleVocabulary.fromValues([u'foo',u'bar']))
+ ... vocabulary=SimpleVocabulary.fromValues([u('foo'),u('bar')]))
>>> IFromUnicode.providedBy(t)
True
- >>> t.fromUnicode(u"baz")
+ >>> t.fromUnicode(u("baz"))
Traceback (most recent call last):
...
ConstraintNotSatisfied: baz
- >>> t.fromUnicode(u"foo")
+ >>> t.fromUnicode(u("foo"))
u'foo'
"""
self.validate(str)
@@ -327,9 +348,9 @@
raise ConstraintNotSatisfied(value)
+ at implementer(IInterfaceField)
class InterfaceField(Field):
__doc__ = IInterfaceField.__doc__
- implements(IInterfaceField)
def _validate(self, value):
super(InterfaceField, self)._validate(value)
@@ -352,9 +373,9 @@
To validate a sequence of various values:
- >>> errors = _validate_sequence(field, ('foo', u'bar', 1))
+ >>> errors = _validate_sequence(field, (b('foo'), u('bar'), 1))
>>> errors
- [WrongType('foo', <type 'unicode'>, ''), WrongType(1, <type 'unicode'>, '')]
+ [WrongType(b'foo', <type 'unicode'>, ''), WrongType(1, <type 'unicode'>, '')]
The only valid value in the sequence is the second item. The others
generated errors.
@@ -362,9 +383,9 @@
We can use the optional errors argument to collect additional errors
for a new sequence:
- >>> errors = _validate_sequence(field, (2, u'baz'), errors)
+ >>> errors = _validate_sequence(field, (2, u('baz')), errors)
>>> errors
- [WrongType('foo', <type 'unicode'>, ''), WrongType(1, <type 'unicode'>, ''), WrongType(2, <type 'unicode'>, '')]
+ [WrongType(b'foo', <type 'unicode'>, ''), WrongType(1, <type 'unicode'>, ''), WrongType(2, <type 'unicode'>, '')]
"""
if errors is None:
@@ -374,7 +395,7 @@
for item in value:
try:
value_type.validate(item)
- except ValidationError, error:
+ except ValidationError as error:
errors.append(error)
return errors
@@ -418,21 +439,21 @@
_validate_uniqueness(value)
+ at implementer(ITuple)
class Tuple(AbstractCollection):
"""A field representing a Tuple."""
- implements(ITuple)
_type = tuple
+ at implementer(IList)
class List(AbstractCollection):
"""A field representing a List."""
- implements(IList)
_type = list
+ at implementer(ISet)
class Set(AbstractCollection):
"""A field representing a set."""
- implements(ISet)
_type = set
def __init__(self, **kw):
@@ -442,8 +463,8 @@
super(Set, self).__init__(unique=True, **kw)
+ at implementer(IFrozenSet)
class FrozenSet(AbstractCollection):
- implements(IFrozenSet)
_type = frozenset
def __init__(self, **kw):
@@ -483,9 +504,9 @@
if IField.providedBy(attribute):
# validate attributes that are fields
attribute.validate(getattr(value, name))
- except ValidationError, error:
+ except ValidationError as error:
errors.append(error)
- except AttributeError, error:
+ except AttributeError as error:
# property for the given name is not implemented
errors.append(SchemaNotFullyImplemented(error))
finally:
@@ -493,9 +514,9 @@
return errors
+ at implementer(IObject)
class Object(Field):
__doc__ = IObject.__doc__
- implements(IObject)
def __init__(self, schema, **kw):
if not IInterface.providedBy(schema):
@@ -528,20 +549,19 @@
super(Object, self).set(object, value)
+ at implementer(IBeforeObjectAssignedEvent)
class BeforeObjectAssignedEvent(object):
"""An object is going to be assigned to an attribute on another object."""
- implements(IBeforeObjectAssignedEvent)
-
def __init__(self, object, name, context):
self.object = object
self.name = name
self.context = context
+ at implementer(IDict)
class Dict(MinMaxLen, Iterable):
"""A field representing a Dict."""
- implements(IDict)
_type = dict
key_type = None
value_type = None
@@ -588,20 +608,19 @@
r"[a-zA-z0-9+.-]+:"
# non space (should be pickier)
r"\S*$").match
+_isuri = _re_on_bytes(_isuri)
-
+ at implementer(IURI, IFromUnicode)
class URI(BytesLine):
"""URI schema field
"""
- implements(IURI, IFromUnicode)
-
def _validate(self, value):
"""
>>> uri = URI(__name__='test')
- >>> uri.validate("http://www.python.org/foo/bar")
- >>> uri.validate("DAV:")
- >>> uri.validate("www.python.org/foo/bar")
+ >>> uri.validate(b("http://www.python.org/foo/bar"))
+ >>> uri.validate(b("DAV:"))
+ >>> uri.validate(b("www.python.org/foo/bar"))
Traceback (most recent call last):
...
InvalidURI: www.python.org/foo/bar
@@ -627,7 +646,7 @@
...
InvalidURI: http://www.python.org/ foo/bar
"""
- v = str(value.strip())
+ v = value.strip().encode('ascii')
self.validate(v)
return v
@@ -637,26 +656,26 @@
r"([.][a-zA-Z][a-zA-Z0-9_]*)*"
# use the whole line
r"$").match
+_isdotted = _re_on_bytes(_isdotted)
+ at implementer(IId, IFromUnicode)
class Id(BytesLine):
"""Id field
Values of id fields must be either uris or dotted names.
"""
- implements(IId, IFromUnicode)
-
def _validate(self, value):
"""
>>> id = Id(__name__='test')
- >>> id.validate("http://www.python.org/foo/bar")
- >>> id.validate("zope.app.content")
- >>> id.validate("zope.app.content/a")
+ >>> id.validate(b("http://www.python.org/foo/bar"))
+ >>> id.validate(b("zope.app.content"))
+ >>> id.validate(b("zope.app.content/a"))
Traceback (most recent call last):
...
InvalidId: zope.app.content/a
- >>> id.validate("http://zope.app.content x y")
+ >>> id.validate(b("http://zope.app.content x y"))
Traceback (most recent call last):
...
InvalidId: http://zope.app.content x y
@@ -664,7 +683,7 @@
super(Id, self)._validate(value)
if _isuri(value):
return
- if _isdotted(value) and "." in value:
+ if _isdotted(value) and b(".") in value:
return
raise InvalidId(value)
@@ -674,7 +693,7 @@
>>> id = Id(__name__='test')
>>> id.fromUnicode("http://www.python.org/foo/bar")
'http://www.python.org/foo/bar'
- >>> id.fromUnicode(u" http://www.python.org/foo/bar ")
+ >>> id.fromUnicode(u(" http://www.python.org/foo/bar "))
'http://www.python.org/foo/bar'
>>> id.fromUnicode("http://www.python.org/ foo/bar")
Traceback (most recent call last):
@@ -684,19 +703,20 @@
'x.y.z'
"""
- v = str(value.strip())
+ v = value.strip()
+ if not isinstance(v, self._type):
+ v = v.encode('ascii')
self.validate(v)
return v
+ at implementer(IDottedName)
class DottedName(BytesLine):
"""Dotted name field.
Values of DottedName fields must be Python-style dotted names.
"""
- implements(IDottedName)
-
def __init__(self, *args, **kw):
"""
>>> DottedName(min_dots=-1)
@@ -742,44 +762,44 @@
def _validate(self, value):
"""
>>> dotted_name = DottedName(__name__='test')
- >>> dotted_name.validate("a.b.c")
- >>> dotted_name.validate("a")
- >>> dotted_name.validate(" a")
+ >>> dotted_name.validate(b("a.b.c"))
+ >>> dotted_name.validate(b("a"))
+ >>> dotted_name.validate(b(" a"))
Traceback (most recent call last):
...
InvalidDottedName: a
>>> dotted_name = DottedName(__name__='test', min_dots=1)
- >>> dotted_name.validate('a.b')
- >>> dotted_name.validate('a.b.c.d')
- >>> dotted_name.validate('a')
+ >>> dotted_name.validate(b('a.b'))
+ >>> dotted_name.validate(b('a.b.c.d'))
+ >>> dotted_name.validate(b('a'))
Traceback (most recent call last):
...
InvalidDottedName: ('too few dots; 1 required', 'a')
>>> dotted_name = DottedName(__name__='test', max_dots=0)
- >>> dotted_name.validate('a')
- >>> dotted_name.validate('a.b')
+ >>> dotted_name.validate(b('a'))
+ >>> dotted_name.validate(b('a.b'))
Traceback (most recent call last):
...
InvalidDottedName: ('too many dots; no more than 0 allowed', 'a.b')
>>> dotted_name = DottedName(__name__='test', max_dots=2)
- >>> dotted_name.validate('a')
- >>> dotted_name.validate('a.b')
- >>> dotted_name.validate('a.b.c')
- >>> dotted_name.validate('a.b.c.d')
+ >>> dotted_name.validate(b('a'))
+ >>> dotted_name.validate(b('a.b'))
+ >>> dotted_name.validate(b('a.b.c'))
+ >>> dotted_name.validate(b('a.b.c.d'))
Traceback (most recent call last):
...
InvalidDottedName: ('too many dots; no more than 2 allowed', 'a.b.c.d')
>>> dotted_name = DottedName(__name__='test', max_dots=1, min_dots=1)
- >>> dotted_name.validate('a.b')
- >>> dotted_name.validate('a')
+ >>> dotted_name.validate(b('a.b'))
+ >>> dotted_name.validate(b('a'))
Traceback (most recent call last):
...
InvalidDottedName: ('too few dots; 1 required', 'a')
- >>> dotted_name.validate('a.b.c')
+ >>> dotted_name.validate(b('a.b.c'))
Traceback (most recent call last):
...
InvalidDottedName: ('too many dots; no more than 1 allowed', 'a.b.c')
@@ -788,7 +808,7 @@
super(DottedName, self)._validate(value)
if not _isdotted(value):
raise InvalidDottedName(value)
- dots = value.count(".")
+ dots = _to_string(value).count(".")
if dots < self.min_dots:
raise InvalidDottedName("too few dots; %d required" % self.min_dots,
value)
@@ -797,6 +817,6 @@
self.max_dots, value)
def fromUnicode(self, value):
- v = str(value.strip())
+ v = b(value.strip())
self.validate(v)
return v
Modified: zope.schema/branches/jinty-python3/src/zope/schema/_messageid.py
===================================================================
--- zope.schema/branches/jinty-python3/src/zope/schema/_messageid.py 2011-10-10 10:44:37 UTC (rev 123042)
+++ zope.schema/branches/jinty-python3/src/zope/schema/_messageid.py 2011-10-10 10:46:35 UTC (rev 123043)
@@ -15,6 +15,7 @@
try:
from zope.i18nmessageid import MessageFactory
except ImportError:
- _ = lambda x: unicode(x)
+ from six import u
+ _ = lambda x: u(x)
else:
_ = MessageFactory("zope")
Modified: zope.schema/branches/jinty-python3/src/zope/schema/_schema.py
===================================================================
--- zope.schema/branches/jinty-python3/src/zope/schema/_schema.py 2011-10-10 10:44:37 UTC (rev 123042)
+++ zope.schema/branches/jinty-python3/src/zope/schema/_schema.py 2011-10-10 10:46:35 UTC (rev 123043)
@@ -35,13 +35,17 @@
fields[name] = attr
return fields
+_field_key = lambda x: x[1].order
def getFieldsInOrder(schema,
- _fieldsorter=lambda x, y: cmp(x[1].order, y[1].order)):
+ _fieldsorter=None):
"""Return a list of (name, value) tuples in native schema order.
"""
- fields = getFields(schema).items()
- fields.sort(_fieldsorter)
+ fields = list(getFields(schema).items())
+ if _fieldsorter is not None:
+ fields.sort(_fieldsorter)
+ else:
+ fields.sort(key=_field_key)
return fields
@@ -82,13 +86,13 @@
continue
try:
value = getattr(object, name)
- except AttributeError, error:
+ except AttributeError as error:
# property for the given name is not implemented
errors.append((
name, zope.schema.interfaces.SchemaNotFullyImplemented(error)))
else:
try:
attribute.bind(object).validate(value)
- except zope.schema.ValidationError, e:
+ except zope.schema.ValidationError as e:
errors.append((name, e))
return errors
Modified: zope.schema/branches/jinty-python3/src/zope/schema/fieldproperty.py
===================================================================
--- zope.schema/branches/jinty-python3/src/zope/schema/fieldproperty.py 2011-10-10 10:44:37 UTC (rev 123042)
+++ zope.schema/branches/jinty-python3/src/zope/schema/fieldproperty.py 2011-10-10 10:46:35 UTC (rev 123043)
@@ -50,7 +50,7 @@
def __set__(self, inst, value):
field = self.__field.bind(inst)
field.validate(value)
- if field.readonly and inst.__dict__.has_key(self.__name):
+ if field.readonly and self.__name in inst.__dict__:
raise ValueError(self.__name, 'field is readonly')
inst.__dict__[self.__name] = value
Modified: zope.schema/branches/jinty-python3/src/zope/schema/fields.txt
===================================================================
--- zope.schema/branches/jinty-python3/src/zope/schema/fields.txt 2011-10-10 10:44:37 UTC (rev 123042)
+++ zope.schema/branches/jinty-python3/src/zope/schema/fields.txt 2011-10-10 10:46:35 UTC (rev 123043)
@@ -26,11 +26,12 @@
>>> from zope.interface import Interface
>>> from zope.schema import List, Float
+ >>> from six import u
>>> class IInventoryItem(Interface):
... pricePoints = List(
- ... title=u"Price Points",
+ ... title=u("Price Points"),
... unique=True,
- ... value_type=Float(title=u"Price", min=0.0)
+ ... value_type=Float(title=u("Price"), min=0.0)
... )
This indicates several things.
Modified: zope.schema/branches/jinty-python3/src/zope/schema/interfaces.py
===================================================================
--- zope.schema/branches/jinty-python3/src/zope/schema/interfaces.py 2011-10-10 10:44:37 UTC (rev 123042)
+++ zope.schema/branches/jinty-python3/src/zope/schema/interfaces.py 2011-10-10 10:46:35 UTC (rev 123043)
@@ -16,6 +16,7 @@
__docformat__ = "reStructuredText"
from zope.interface import Interface, Attribute
+from six import u
from zope.schema._messageid import _
@@ -107,46 +108,46 @@
"""
title = TextLine(
- title=_(u"Title"),
- description=_(u"A short summary or label"),
- default=u"",
+ title=_("Title"),
+ description=_("A short summary or label"),
+ default=u(""),
required=False,
)
description = Text(
- title=_(u"Description"),
- description=_(u"A description of the field"),
- default=u"",
+ title=_("Description"),
+ description=_("A description of the field"),
+ default=u(""),
required=False,
)
required = Bool(
- title=_(u"Required"),
+ title=_("Required"),
description=(
- _(u"Tells whether a field requires its value to exist.")),
+ _("Tells whether a field requires its value to exist.")),
default=True)
readonly = Bool(
- title=_(u"Read Only"),
- description=_(u"If true, the field's value cannot be changed."),
+ title=_("Read Only"),
+ description=_("If true, the field's value cannot be changed."),
required=False,
default=False)
default = Field(
- title=_(u"Default Value"),
- description=_(u"""The field default value may be None or a legal
+ title=_("Default Value"),
+ description=_("""The field default value may be None or a legal
field value""")
)
missing_value = Field(
- title=_(u"Missing Value"),
- description=_(u"""If input for this Field is missing, and that's ok,
+ title=_("Missing Value"),
+ description=_("""If input for this Field is missing, and that's ok,
then this is the value to use""")
)
order = Int(
- title=_(u"Field Order"),
- description=_(u"""
+ title=_("Field Order"),
+ description=_("""
The order attribute can be used to determine the order in
which fields in a schema were defined. If one field is created
after another (in the same thread), its order will be
@@ -159,7 +160,7 @@
)
def constraint(value):
- u"""Check a customized constraint on the value.
+ """Check a customized constraint on the value.
You can implement this method with your Field to
require a certain constraint. This relaxes the need
@@ -168,7 +169,7 @@
"""
def validate(value):
- u"""Validate that the given value is a valid field value.
+ """Validate that the given value is a valid field value.
Returns nothing but raises an error if the value is invalid.
It checks everything specific to a Field and also checks
@@ -191,7 +192,7 @@
"""
class IIterable(IField):
- u"""Fields with a value that can be iterated over.
+ """Fields with a value that can be iterated over.
The value needs to support iteration; the implementation mechanism
is not constrained. (Either `__iter__()` or `__getitem__()` may be
@@ -199,7 +200,7 @@
"""
class IContainer(IField):
- u"""Fields whose value allows an ``x in value`` check.
+ """Fields whose value allows an ``x in value`` check.
The value needs to support the `in` operator, but is not
constrained in how it does so (whether it defines `__contains__()`
@@ -207,7 +208,7 @@
"""
class IOrderable(IField):
- u"""Field requiring its value to be orderable.
+ """Field requiring its value to be orderable.
The set of value needs support a complete ordering; the
implementation mechanism is not constrained. Either `__cmp__()` or
@@ -215,36 +216,36 @@
"""
class ILen(IField):
- u"""A Field requiring its value to have a length.
+ """A Field requiring its value to have a length.
The value needs to have a conventional __len__ method.
"""
class IMinMax(IOrderable):
- u"""Field requiring its value to be between min and max.
+ """Field requiring its value to be between min and max.
This implies that the value needs to support the IOrderable interface.
"""
min = Field(
- title=_(u"Start of the range"),
+ title=_("Start of the range"),
required=False,
default=None
)
max = Field(
- title=_(u"End of the range (including the value itself)"),
+ title=_("End of the range (including the value itself)"),
required=False,
default=None
)
class IMinMaxLen(ILen):
- u"""Field requiring the length of its value to be within a range"""
+ """Field requiring the length of its value to be within a range"""
min_length = Int(
- title=_(u"Minimum length"),
- description=_(u"""
+ title=_("Minimum length"),
+ description=_("""
Value after whitespace processing cannot have less than
`min_length` characters (if a string type) or elements (if
another sequence type). If `min_length` is ``None``, there is
@@ -255,8 +256,8 @@
default=0)
max_length = Int(
- title=_(u"Maximum length"),
- description=_(u"""
+ title=_("Maximum length"),
+ description=_("""
Value after whitespace processing cannot have greater
or equal than `max_length` characters (if a string type) or
elements (if another sequence type). If `max_length` is
@@ -266,87 +267,87 @@
default=None)
class IInterfaceField(IField):
- u"""Fields with a value that is an interface (implementing
+ """Fields with a value that is an interface (implementing
zope.interface.Interface)."""
class IBool(IField):
- u"""Boolean Field."""
+ """Boolean Field."""
default = Bool(
- title=_(u"Default Value"),
- description=_(u"""The field default value may be None or a legal
+ title=_("Default Value"),
+ description=_("""The field default value may be None or a legal
field value""")
)
class IBytes(IMinMaxLen, IIterable, IField):
- u"""Field containing a byte string (like the python str).
+ """Field containing a byte string (like the python str).
The value might be constrained to be with length limits.
"""
class IASCII(IBytes):
- u"""Field containing a 7-bit ASCII string. No characters > DEL
+ """Field containing a 7-bit ASCII string. No characters > DEL
(chr(127)) are allowed
The value might be constrained to be with length limits.
"""
class IBytesLine(IBytes):
- u"""Field containing a byte string without newlines."""
+ """Field containing a byte string without newlines."""
class IASCIILine(IASCII):
- u"""Field containing a 7-bit ASCII string without newlines."""
+ """Field containing a 7-bit ASCII string without newlines."""
class IText(IMinMaxLen, IIterable, IField):
- u"""Field containing a unicode string."""
+ """Field containing a unicode string."""
class ISourceText(IText):
- u"""Field for source text of object."""
+ """Field for source text of object."""
class ITextLine(IText):
- u"""Field containing a unicode string without newlines."""
+ """Field containing a unicode string without newlines."""
class IPassword(ITextLine):
- u"Field containing a unicode string without newlines that is a password."
+ "Field containing a unicode string without newlines that is a password."
class IInt(IMinMax, IField):
- u"""Field containing an Integer Value."""
+ """Field containing an Integer Value."""
min = Int(
- title=_(u"Start of the range"),
+ title=_("Start of the range"),
required=False,
default=None
)
max = Int(
- title=_(u"End of the range (excluding the value itself)"),
+ title=_("End of the range (excluding the value itself)"),
required=False,
default=None
)
default = Int(
- title=_(u"Default Value"),
- description=_(u"""The field default value may be None or a legal
+ title=_("Default Value"),
+ description=_("""The field default value may be None or a legal
field value""")
)
class IFloat(IMinMax, IField):
- u"""Field containing a Float."""
+ """Field containing a Float."""
class IDecimal(IMinMax, IField):
- u"""Field containing a Decimal."""
+ """Field containing a Decimal."""
class IDatetime(IMinMax, IField):
- u"""Field containing a DateTime."""
+ """Field containing a DateTime."""
class IDate(IMinMax, IField):
- u"""Field containing a date."""
+ """Field containing a date."""
class ITimedelta(IMinMax, IField):
- u"""Field containing a timedelta."""
+ """Field containing a timedelta."""
class ITime(IMinMax, IField):
- u"""Field containing a time."""
+ """Field containing a time."""
def _is_field(value):
if not IField.providedBy(value):
@@ -378,34 +379,34 @@
"""
min_dots = Int(
- title=_(u"Minimum number of dots"),
+ title=_("Minimum number of dots"),
required=True,
min=0,
default=0
)
max_dots = Int(
- title=_(u"Maximum number of dots (should not be less than min_dots)"),
+ title=_("Maximum number of dots (should not be less than min_dots)"),
required=False,
default=None
)
class IChoice(IField):
- u"""Field whose value is contained in a predefined set
+ """Field whose value is contained in a predefined set
Only one, values or vocabulary, may be specified for a given choice.
"""
vocabulary = Field(
- title=_(u"Vocabulary or source providing values"),
- description=_(u"The ISource, IContextSourceBinder or IBaseVocabulary "
- u"object that provides values for this field."),
+ title=_("Vocabulary or source providing values"),
+ description=_("The ISource, IContextSourceBinder or IBaseVocabulary "
+ "object that provides values for this field."),
required=False,
default=None
)
vocabularyName = TextLine(
- title=_(u"Vocabulary name"),
- description=_(u"Vocabulary name to lookup in the vocabulary registry"),
+ title=_("Vocabulary name"),
+ description=_("Vocabulary name to lookup in the vocabulary registry"),
required=False,
default=None
)
@@ -415,15 +416,15 @@
# Abstract
class ICollection(IMinMaxLen, IIterable, IContainer):
- u"""Abstract interface containing a collection value.
+ """Abstract interface containing a collection value.
The Value must be iterable and may have a min_length/max_length.
"""
value_type = Field(
title = _("Value Type"),
- description = _(u"Field value items must conform to the given type, "
- u"expressed via a Field."))
+ description = _("Field value items must conform to the given type, "
+ "expressed via a Field."))
unique = Bool(
title = _('Unique Members'),
@@ -432,47 +433,47 @@
default=False)
class ISequence(ICollection):
- u"""Abstract interface specifying that the value is ordered"""
+ """Abstract interface specifying that the value is ordered"""
class IUnorderedCollection(ICollection):
- u"""Abstract interface specifying that the value cannot be ordered"""
+ """Abstract interface specifying that the value cannot be ordered"""
class IAbstractSet(IUnorderedCollection):
- u"""An unordered collection of unique values."""
+ """An unordered collection of unique values."""
- unique = Attribute(u"This ICollection interface attribute must be True")
+ unique = Attribute("This ICollection interface attribute must be True")
class IAbstractBag(IUnorderedCollection):
- u"""An unordered collection of values, with no limitations on whether
+ """An unordered collection of values, with no limitations on whether
members are unique"""
- unique = Attribute(u"This ICollection interface attribute must be False")
+ unique = Attribute("This ICollection interface attribute must be False")
# Concrete
class ITuple(ISequence):
- u"""Field containing a value that implements the API of a conventional
+ """Field containing a value that implements the API of a conventional
Python tuple."""
class IList(ISequence):
- u"""Field containing a value that implements the API of a conventional
+ """Field containing a value that implements the API of a conventional
Python list."""
class ISet(IAbstractSet):
- u"""Field containing a value that implements the API of a Python2.4+ set.
+ """Field containing a value that implements the API of a Python2.4+ set.
"""
class IFrozenSet(IAbstractSet):
- u"""Field containing a value that implements the API of a conventional
+ """Field containing a value that implements the API of a conventional
Python 2.4+ frozenset."""
# (end Collections)
class IObject(IField):
- u"""Field containing an Object value."""
+ """Field containing an Object value."""
schema = Attribute("schema",
- _(u"The Interface that defines the Fields comprising the Object."))
+ _("The Interface that defines the Fields comprising the Object."))
class IBeforeObjectAssignedEvent(Interface):
"""An object is going to be assigned to an attribute on another object.
@@ -494,19 +495,19 @@
class IDict(IMinMaxLen, IIterable, IContainer):
- u"""Field containing a conventional dict.
+ """Field containing a conventional dict.
The key_type and value_type fields allow specification
of restrictions for keys and values contained in the dict.
"""
key_type = Attribute("key_type",
- _(u"""Field keys must conform to the given type, expressed
+ _("""Field keys must conform to the given type, expressed
via a Field.
"""))
value_type = Attribute("value_type",
- _(u"""Field values must conform to the given type, expressed
+ _("""Field values must conform to the given type, expressed
via a Field.
"""))
@@ -533,7 +534,7 @@
class ITitledTokenizedTerm(ITokenizedTerm):
"""A tokenized term that includes a title."""
- title = TextLine(title=_(u"Title"))
+ title = TextLine(title=_("Title"))
class ISource(Interface):
"""A set of values from which to choose
Modified: zope.schema/branches/jinty-python3/src/zope/schema/sources.txt
===================================================================
--- zope.schema/branches/jinty-python3/src/zope/schema/sources.txt 2011-10-10 10:44:37 UTC (rev 123042)
+++ zope.schema/branches/jinty-python3/src/zope/schema/sources.txt 2011-10-10 10:46:35 UTC (rev 123043)
@@ -39,8 +39,8 @@
>>> from zope import interface
>>> from zope.schema.interfaces import ISource, IContextSourceBinder
- >>> class MySource(object):
- ... interface.implements(ISource)
+ >>> @interface.implementer(ISource)
+ ... class MySource(object):
... divisor = 2
... def __contains__(self, value):
... return bool(value % self.divisor)
@@ -60,8 +60,9 @@
`bind` method will be called with the context as its only argument. The
result must implement ISource and will be used as the source.
+ >>> from six import print_
>>> def my_binder(context):
- ... print "Binder was called."
+ ... print_("Binder was called.")
... source = MySource()
... source.divisor = context.divisor
... return source
Modified: zope.schema/branches/jinty-python3/src/zope/schema/tests/__init__.py
===================================================================
--- zope.schema/branches/jinty-python3/src/zope/schema/tests/__init__.py 2011-10-10 10:44:37 UTC (rev 123042)
+++ zope.schema/branches/jinty-python3/src/zope/schema/tests/__init__.py 2011-10-10 10:46:35 UTC (rev 123043)
@@ -1,2 +1,46 @@
#
# This file is necessary to make this directory a package.
+
+import re
+
+from six import PY3
+from zope.testing import renormalizing
+
+if PY3:
+ py3_checker = renormalizing.RENormalizing([
+ (re.compile(r"u'([^']*)'"),
+ r"'\1'"),
+ (re.compile(r"^b'([^']*)'"),
+ r"'\1'"),
+ (re.compile(r"([^'])b'([^']*)'"),
+ r"\1'\2'"),
+ (re.compile(r"<class 'bytes'>"),
+ r"<type 'str'>"),
+ (re.compile(r"<class 'str'>"),
+ r"<type 'unicode'>"),
+ (re.compile(r"zope.schema._bootstrapinterfaces.InvalidValue"),
+ r"InvalidValue"),
+ (re.compile(r"zope.schema.interfaces.InvalidId: '([^']*)'"),
+ r"InvalidId: \1"),
+ (re.compile(r"zope.schema.interfaces.InvalidId:"),
+ r"InvalidId:"),
+ (re.compile(r"zope.schema.interfaces.InvalidURI: '([^']*)'"),
+ r"InvalidURI: \1"),
+ (re.compile(r"zope.schema.interfaces.InvalidURI:"),
+ r"InvalidURI:"),
+ (re.compile(r"zope.schema.interfaces.InvalidDottedName: '([^']*)'"),
+ r"InvalidDottedName: \1"),
+ (re.compile(r"zope.schema.interfaces.InvalidDottedName:"),
+ r"InvalidDottedName:"),
+ (re.compile(r"zope.schema._bootstrapinterfaces.ConstraintNotSatisfied: '([^']*)'"),
+ r"ConstraintNotSatisfied: \1"),
+ (re.compile(r"zope.schema._bootstrapinterfaces.ConstraintNotSatisfied:"),
+ r"ConstraintNotSatisfied:"),
+ (re.compile(r"zope.schema._bootstrapinterfaces.WrongType:"),
+ r"WrongType:"),
+ ])
+else:
+ py3_checker = renormalizing.RENormalizing([
+ (re.compile(r"([^'])b'([^']*)'"),
+ r"\1'\2'"),
+ ])
Modified: zope.schema/branches/jinty-python3/src/zope/schema/tests/states.py
===================================================================
--- zope.schema/branches/jinty-python3/src/zope/schema/tests/states.py 2011-10-10 10:44:37 UTC (rev 123042)
+++ zope.schema/branches/jinty-python3/src/zope/schema/tests/states.py 2011-10-10 10:46:35 UTC (rev 123043)
@@ -13,84 +13,85 @@
##############################################################################
"""Sample vocabulary supporting state abbreviations.
"""
-from zope.interface import implements
+from six import u
+from zope.interface import implementer
from zope.schema import interfaces
from zope.schema import Choice
# This table is based on information from the United States Postal Service:
# http://www.usps.com/ncsc/lookups/abbreviations.html#states
_states = {
- 'AL': u'Alabama',
- 'AK': u'Alaska',
- 'AS': u'American Samoa',
- 'AZ': u'Arizona',
- 'AR': u'Arkansas',
- 'CA': u'California',
- 'CO': u'Colorado',
- 'CT': u'Connecticut',
- 'DE': u'Delaware',
- 'DC': u'District of Columbia',
- 'FM': u'Federated States of Micronesia',
- 'FL': u'Florida',
- 'GA': u'Georgia',
- 'GU': u'Guam',
- 'HI': u'Hawaii',
- 'ID': u'Idaho',
- 'IL': u'Illinois',
- 'IN': u'Indiana',
- 'IA': u'Iowa',
- 'KS': u'Kansas',
- 'KY': u'Kentucky',
- 'LA': u'Louisiana',
- 'ME': u'Maine',
- 'MH': u'Marshall Islands',
- 'MD': u'Maryland',
- 'MA': u'Massachusetts',
- 'MI': u'Michigan',
- 'MN': u'Minnesota',
- 'MS': u'Mississippi',
- 'MO': u'Missouri',
- 'MT': u'Montana',
- 'NE': u'Nebraska',
- 'NV': u'Nevada',
- 'NH': u'New Hampshire',
- 'NJ': u'New Jersey',
- 'NM': u'New Mexico',
- 'NY': u'New York',
- 'NC': u'North Carolina',
- 'ND': u'North Dakota',
- 'MP': u'Northern Mariana Islands',
- 'OH': u'Ohio',
- 'OK': u'Oklahoma',
- 'OR': u'Oregon',
- 'PW': u'Palau',
- 'PA': u'Pennsylvania',
- 'PR': u'Puerto Rico',
- 'RI': u'Rhode Island',
- 'SC': u'South Carolina',
- 'SD': u'South Dakota',
- 'TN': u'Tennessee',
- 'TX': u'Texas',
- 'UT': u'Utah',
- 'VT': u'Vermont',
- 'VI': u'Virgin Islands',
- 'VA': u'Virginia',
- 'WA': u'Washington',
- 'WV': u'West Virginia',
- 'WI': u'Wisconsin',
- 'WY': u'Wyoming',
+ 'AL': u('Alabama'),
+ 'AK': u('Alaska'),
+ 'AS': u('American Samoa'),
+ 'AZ': u('Arizona'),
+ 'AR': u('Arkansas'),
+ 'CA': u('California'),
+ 'CO': u('Colorado'),
+ 'CT': u('Connecticut'),
+ 'DE': u('Delaware'),
+ 'DC': u('District of Columbia'),
+ 'FM': u('Federated States of Micronesia'),
+ 'FL': u('Florida'),
+ 'GA': u('Georgia'),
+ 'GU': u('Guam'),
+ 'HI': u('Hawaii'),
+ 'ID': u('Idaho'),
+ 'IL': u('Illinois'),
+ 'IN': u('Indiana'),
+ 'IA': u('Iowa'),
+ 'KS': u('Kansas'),
+ 'KY': u('Kentucky'),
+ 'LA': u('Louisiana'),
+ 'ME': u('Maine'),
+ 'MH': u('Marshall Islands'),
+ 'MD': u('Maryland'),
+ 'MA': u('Massachusetts'),
+ 'MI': u('Michigan'),
+ 'MN': u('Minnesota'),
+ 'MS': u('Mississippi'),
+ 'MO': u('Missouri'),
+ 'MT': u('Montana'),
+ 'NE': u('Nebraska'),
+ 'NV': u('Nevada'),
+ 'NH': u('New Hampshire'),
+ 'NJ': u('New Jersey'),
+ 'NM': u('New Mexico'),
+ 'NY': u('New York'),
+ 'NC': u('North Carolina'),
+ 'ND': u('North Dakota'),
+ 'MP': u('Northern Mariana Islands'),
+ 'OH': u('Ohio'),
+ 'OK': u('Oklahoma'),
+ 'OR': u('Oregon'),
+ 'PW': u('Palau'),
+ 'PA': u('Pennsylvania'),
+ 'PR': u('Puerto Rico'),
+ 'RI': u('Rhode Island'),
+ 'SC': u('South Carolina'),
+ 'SD': u('South Dakota'),
+ 'TN': u('Tennessee'),
+ 'TX': u('Texas'),
+ 'UT': u('Utah'),
+ 'VT': u('Vermont'),
+ 'VI': u('Virgin Islands'),
+ 'VA': u('Virginia'),
+ 'WA': u('Washington'),
+ 'WV': u('West Virginia'),
+ 'WI': u('Wisconsin'),
+ 'WY': u('Wyoming'),
}
+ at implementer(interfaces.ITerm)
class State(object):
__slots__ = 'value', 'title'
- implements(interfaces.ITerm)
def __init__(self, value, title):
self.value = value
self.title = title
-for v,p in _states.iteritems():
+for v,p in _states.items():
_states[v] = State(v, p)
@@ -98,9 +99,9 @@
"""Vocabularies that support the states database conform to this."""
+ at implementer(IStateVocabulary)
class StateVocabulary(object):
__slots__ = ()
- implements(IStateVocabulary)
def __init__(self, object=None):
pass
@@ -109,7 +110,7 @@
return value in _states
def __iter__(self):
- return _states.itervalues()
+ return iter(_states.values())
def __len__(self):
return len(_states)
Modified: zope.schema/branches/jinty-python3/src/zope/schema/tests/test_accessors.py
===================================================================
--- zope.schema/branches/jinty-python3/src/zope/schema/tests/test_accessors.py 2011-10-10 10:44:37 UTC (rev 123042)
+++ zope.schema/branches/jinty-python3/src/zope/schema/tests/test_accessors.py 2011-10-10 10:46:35 UTC (rev 123043)
@@ -14,7 +14,8 @@
"""Test Interface accessor methods.
"""
import unittest
-from zope.interface import Interface, implements
+from zope.interface import Interface, implementer
+from six import u
from zope.schema import Text, accessors
from zope.schema.interfaces import IText
from zope.schema.accessors import FieldReadAccessor, FieldWriteAccessor
@@ -26,23 +27,24 @@
def test(self):
- field = Text(title=u"Foo thing")
+ field = Text(title=u("Foo thing"))
class I(Interface):
getFoo, setFoo = accessors(field)
+ @implementer(I)
class Bad(object):
- implements(I)
+ pass
+ @implementer(I)
class Good(object):
- implements(I)
def __init__(self):
self.set = 0
def getFoo(self):
- return u"foo"
+ return u("foo")
def setFoo(self, v):
self.set += 1
@@ -52,7 +54,7 @@
self.assertEqual(names, ['getFoo', 'setFoo'])
self.assertEqual(I['getFoo'].field, field)
self.assertEqual(I['getFoo'].__name__, 'getFoo')
- self.assertEqual(I['getFoo'].__doc__, u'get Foo thing')
+ self.assertEqual(I['getFoo'].__doc__, u('get Foo thing'))
self.assertEqual(I['getFoo'].__class__, FieldReadAccessor)
self.assertEqual(I['getFoo'].writer, I['setFoo'])
@@ -67,7 +69,7 @@
self.assertEqual(I['setFoo'].field, field)
self.assertEqual(I['setFoo'].__name__, 'setFoo')
- self.assertEqual(I['setFoo'].__doc__, u'set Foo thing')
+ self.assertEqual(I['setFoo'].__doc__, u('set Foo thing'))
self.assertEqual(I['setFoo'].__class__, FieldWriteAccessor)
self.assertRaises(Exception, verifyClass, I, Bad)
@@ -79,15 +81,15 @@
verifyClass(I, Good)
verifyObject(I, Good())
- self.assertEquals(I['getFoo'].query(Good(), 42), u'foo')
- self.assertEquals(I['getFoo'].get(Good()), u'foo')
+ self.assertEquals(I['getFoo'].query(Good(), 42), u('foo'))
+ self.assertEquals(I['getFoo'].get(Good()), u('foo'))
instance = Good()
- I['getFoo'].set(instance, u'whatever')
+ I['getFoo'].set(instance, u('whatever'))
self.assertEquals(instance.set, 1)
def test_doc(self):
- field = Text(title=u"Foo thing")
+ field = Text(title=u("Foo thing"))
class I(Interface):
Modified: zope.schema/branches/jinty-python3/src/zope/schema/tests/test_boolfield.py
===================================================================
--- zope.schema/branches/jinty-python3/src/zope/schema/tests/test_boolfield.py 2011-10-10 10:44:37 UTC (rev 123042)
+++ zope.schema/branches/jinty-python3/src/zope/schema/tests/test_boolfield.py 2011-10-10 10:46:35 UTC (rev 123043)
@@ -14,6 +14,8 @@
"""Boolean field tests
"""
from unittest import main, makeSuite
+
+from six import u
from zope.schema import Bool
from zope.schema.interfaces import RequiredMissing, IBool, IFromUnicode
from zope.schema.tests.test_field import FieldTestBase
@@ -27,14 +29,14 @@
_Field_Factory = Bool
def testValidate(self):
- field = Bool(title=u'Bool field', description=u'',
+ field = Bool(title=u('Bool field'), description=u(''),
readonly=False, required=False)
field.validate(None)
field.validate(True)
field.validate(False)
def testValidateRequired(self):
- field = Bool(title=u'Bool field', description=u'',
+ field = Bool(title=u('Bool field'), description=u(''),
readonly=False, required=True)
field.validate(True)
field.validate(False)
@@ -53,10 +55,10 @@
class IAdaptTo(zope.interface.Interface):
pass
- registry.register((IBool,), IAdaptTo, u'', adapt_bool)
- registry.register((IFromUnicode,), IAdaptTo, u'', adapt_from_unicode)
+ registry.register((IBool,), IAdaptTo, u(''), adapt_bool)
+ registry.register((IFromUnicode,), IAdaptTo, u(''), adapt_from_unicode)
- field = Bool(title=u'Bool field', description=u'',
+ field = Bool(title=u('Bool field'), description=u(''),
readonly=False, required=True)
self.assertEqual('bool', registry.queryAdapter(field, IAdaptTo))
Modified: zope.schema/branches/jinty-python3/src/zope/schema/tests/test_choice.py
===================================================================
--- zope.schema/branches/jinty-python3/src/zope/schema/tests/test_choice.py 2011-10-10 10:44:37 UTC (rev 123042)
+++ zope.schema/branches/jinty-python3/src/zope/schema/tests/test_choice.py 2011-10-10 10:46:35 UTC (rev 123043)
@@ -15,13 +15,14 @@
"""
import unittest
+from six import u
from zope.schema import vocabulary
from zope.schema import Choice
from zope.schema.interfaces import ConstraintNotSatisfied
from zope.schema.interfaces import ValidationError
from zope.schema.interfaces import InvalidValue, NotAContainer, NotUnique
-from test_vocabulary import SampleVocabulary, DummyRegistry
+from zope.schema.tests.test_vocabulary import SampleVocabulary, DummyRegistry
class Value_ChoiceFieldTests(unittest.TestCase):
@@ -41,7 +42,7 @@
choice = Choice(values=['a', 'c'])
choice.validate('a')
choice.validate('c')
- choice.validate(u'c')
+ choice.validate(u('c'))
self.assertRaises(ConstraintNotSatisfied, choice.validate, 'd')
def test_validate_tuple(self):
Modified: zope.schema/branches/jinty-python3/src/zope/schema/tests/test_containerfield.py
===================================================================
--- zope.schema/branches/jinty-python3/src/zope/schema/tests/test_containerfield.py 2011-10-10 10:44:37 UTC (rev 123042)
+++ zope.schema/branches/jinty-python3/src/zope/schema/tests/test_containerfield.py 2011-10-10 10:46:35 UTC (rev 123043)
@@ -13,7 +13,12 @@
##############################################################################
"""Container field tests
"""
-from UserDict import UserDict
+from six import PY3, u
+if not PY3:
+ from UserDict import UserDict
+else:
+ #python3
+ from collections import UserDict
from unittest import main, makeSuite
from zope.schema import Container
from zope.schema.interfaces import RequiredMissing, NotAContainer
@@ -25,7 +30,7 @@
_Field_Factory = Container
def testValidate(self):
- field = self._Field_Factory(title=u'test field', description=u'',
+ field = self._Field_Factory(title=u('test field'), description=u(''),
readonly=False, required=False)
field.validate(None)
field.validate('')
@@ -38,7 +43,7 @@
self.assertRaises(NotAContainer, field.validate, True)
def testValidateRequired(self):
- field = self._Field_Factory(title=u'test field', description=u'',
+ field = self._Field_Factory(title=u('test field'), description=u(''),
readonly=False, required=True)
field.validate('')
Modified: zope.schema/branches/jinty-python3/src/zope/schema/tests/test_date.py
===================================================================
--- zope.schema/branches/jinty-python3/src/zope/schema/tests/test_date.py 2011-10-10 10:44:37 UTC (rev 123042)
+++ zope.schema/branches/jinty-python3/src/zope/schema/tests/test_date.py 2011-10-10 10:46:35 UTC (rev 123043)
@@ -14,6 +14,8 @@
"""Date field tests
"""
from unittest import main, makeSuite
+
+from six import u
from zope.schema import Date
from zope.schema.interfaces import RequiredMissing, InvalidValue, WrongType
from zope.schema.interfaces import TooSmall, TooBig
@@ -31,14 +33,14 @@
verifyObject(IDate, self._Field_Factory())
def testValidate(self):
- field = self._Field_Factory(title=u'Date field', description=u'',
+ field = self._Field_Factory(title=u('Date field'), description=u(''),
readonly=False, required=False)
field.validate(None)
field.validate(datetime.now().date())
self.assertRaises(WrongType, field.validate, datetime.now())
def testValidateRequired(self):
- field = self._Field_Factory(title=u'Date field', description=u'',
+ field = self._Field_Factory(title=u('Date field'), description=u(''),
readonly=False, required=True)
field.validate(datetime.now().date())
@@ -47,7 +49,7 @@
def testValidateMin(self):
d1 = date(2000,10,1)
d2 = date(2000,10,2)
- field = self._Field_Factory(title=u'Date field', description=u'',
+ field = self._Field_Factory(title=u('Date field'), description=u(''),
readonly=False, required=False, min=d1)
field.validate(None)
field.validate(d1)
@@ -60,7 +62,7 @@
d1 = date(2000,10,1)
d2 = date(2000,10,2)
d3 = date(2000,10,3)
- field = self._Field_Factory(title=u'Date field', description=u'',
+ field = self._Field_Factory(title=u('Date field'), description=u(''),
readonly=False, required=False, max=d2)
field.validate(None)
field.validate(d1)
@@ -75,7 +77,7 @@
d4 = date(2000,10,4)
d5 = date(2000,10,5)
- field = self._Field_Factory(title=u'Date field', description=u'',
+ field = self._Field_Factory(title=u('Date field'), description=u(''),
readonly=False, required=False,
min=d2, max=d4)
field.validate(None)
Modified: zope.schema/branches/jinty-python3/src/zope/schema/tests/test_datetime.py
===================================================================
--- zope.schema/branches/jinty-python3/src/zope/schema/tests/test_datetime.py 2011-10-10 10:44:37 UTC (rev 123042)
+++ zope.schema/branches/jinty-python3/src/zope/schema/tests/test_datetime.py 2011-10-10 10:46:35 UTC (rev 123043)
@@ -14,6 +14,8 @@
"""Datetime Field tests
"""
from unittest import main, makeSuite
+
+from six import u
from zope.schema import Datetime
from zope.schema.interfaces import RequiredMissing, InvalidValue
from zope.schema.interfaces import TooSmall, TooBig
@@ -26,13 +28,13 @@
_Field_Factory = Datetime
def testValidate(self):
- field = self._Field_Factory(title=u'Datetime field', description=u'',
+ field = self._Field_Factory(title=u('Datetime field'), description=u(''),
readonly=False, required=False)
field.validate(None)
field.validate(datetime.now())
def testValidateRequired(self):
- field = self._Field_Factory(title=u'Datetime field', description=u'',
+ field = self._Field_Factory(title=u('Datetime field'), description=u(''),
readonly=False, required=True)
field.validate(datetime.now())
@@ -41,7 +43,7 @@
def testValidateMin(self):
d1 = datetime(2000,10,1)
d2 = datetime(2000,10,2)
- field = self._Field_Factory(title=u'Datetime field', description=u'',
+ field = self._Field_Factory(title=u('Datetime field'), description=u(''),
readonly=False, required=False, min=d1)
field.validate(None)
field.validate(d1)
@@ -54,7 +56,7 @@
d1 = datetime(2000,10,1)
d2 = datetime(2000,10,2)
d3 = datetime(2000,10,3)
- field = self._Field_Factory(title=u'Datetime field', description=u'',
+ field = self._Field_Factory(title=u('Datetime field'), description=u(''),
readonly=False, required=False, max=d2)
field.validate(None)
field.validate(d1)
@@ -69,7 +71,7 @@
d4 = datetime(2000,10,4)
d5 = datetime(2000,10,5)
- field = self._Field_Factory(title=u'Datetime field', description=u'',
+ field = self._Field_Factory(title=u('Datetime field'), description=u(''),
readonly=False, required=False,
min=d2, max=d4)
field.validate(None)
Modified: zope.schema/branches/jinty-python3/src/zope/schema/tests/test_decimalfield.py
===================================================================
--- zope.schema/branches/jinty-python3/src/zope/schema/tests/test_decimalfield.py 2011-10-10 10:44:37 UTC (rev 123042)
+++ zope.schema/branches/jinty-python3/src/zope/schema/tests/test_decimalfield.py 2011-10-10 10:46:35 UTC (rev 123043)
@@ -14,6 +14,8 @@
"""Decimal field tests
"""
import decimal
+
+from six import u
from unittest import main, makeSuite
from zope.schema import Decimal
from zope.schema.interfaces import RequiredMissing, InvalidValue
@@ -26,7 +28,7 @@
_Field_Factory = Decimal
def testValidate(self):
- field = self._Field_Factory(title=u'Decimal field', description=u'',
+ field = self._Field_Factory(title=u('Decimal field'), description=u(''),
readonly=False, required=False)
field.validate(None)
field.validate(decimal.Decimal("10.0"))
@@ -34,7 +36,7 @@
field.validate(decimal.Decimal("1000.0003"))
def testValidateRequired(self):
- field = self._Field_Factory(title=u'Decimal field', description=u'',
+ field = self._Field_Factory(title=u('Decimal field'), description=u(''),
readonly=False, required=True)
field.validate(decimal.Decimal("10.0"))
field.validate(decimal.Decimal("0.93"))
@@ -43,7 +45,7 @@
self.assertRaises(RequiredMissing, field.validate, None)
def testValidateMin(self):
- field = self._Field_Factory(title=u'Decimal field', description=u'',
+ field = self._Field_Factory(title=u('Decimal field'), description=u(''),
readonly=False, required=False,
min=decimal.Decimal("10.5"))
field.validate(None)
@@ -54,7 +56,7 @@
self.assertRaises(TooSmall, field.validate, decimal.Decimal("10.4"))
def testValidateMax(self):
- field = self._Field_Factory(title=u'Decimal field', description=u'',
+ field = self._Field_Factory(title=u('Decimal field'), description=u(''),
readonly=False, required=False,
max=decimal.Decimal("10.5"))
field.validate(None)
@@ -65,7 +67,7 @@
self.assertRaises(TooBig, field.validate, decimal.Decimal("20.7"))
def testValidateMinAndMax(self):
- field = self._Field_Factory(title=u'Decimal field', description=u'',
+ field = self._Field_Factory(title=u('Decimal field'), description=u(''),
readonly=False, required=False,
min=decimal.Decimal("-0.6"),
max=decimal.Decimal("10.1"))
Modified: zope.schema/branches/jinty-python3/src/zope/schema/tests/test_dictfield.py
===================================================================
--- zope.schema/branches/jinty-python3/src/zope/schema/tests/test_dictfield.py 2011-10-10 10:44:37 UTC (rev 123042)
+++ zope.schema/branches/jinty-python3/src/zope/schema/tests/test_dictfield.py 2011-10-10 10:46:35 UTC (rev 123043)
@@ -14,6 +14,8 @@
"""Dictionary field tests
"""
from unittest import main, makeSuite
+
+from six import u
from zope.schema import Dict, Int
from zope.schema.interfaces import RequiredMissing, WrongContainedType
from zope.schema.interfaces import TooShort, TooLong
@@ -25,16 +27,16 @@
_Field_Factory = Dict
def testValidate(self):
- field = Dict(title=u'Dict field',
- description=u'', readonly=False, required=False)
+ field = Dict(title=u('Dict field'),
+ description=u(''), readonly=False, required=False)
field.validate(None)
field.validate({})
field.validate({1: 'foo'})
field.validate({'a': 1})
def testValidateRequired(self):
- field = Dict(title=u'Dict field',
- description=u'', readonly=False, required=True)
+ field = Dict(title=u('Dict field'),
+ description=u(''), readonly=False, required=True)
field.validate({})
field.validate({1: 'foo'})
field.validate({'a': 1})
@@ -42,8 +44,8 @@
self.assertRaises(RequiredMissing, field.validate, None)
def testValidateMinValues(self):
- field = Dict(title=u'Dict field',
- description=u'', readonly=False, required=False,
+ field = Dict(title=u('Dict field'),
+ description=u(''), readonly=False, required=False,
min_length=1)
field.validate(None)
field.validate({1: 'a'})
@@ -52,8 +54,8 @@
self.assertRaises(TooShort, field.validate, {})
def testValidateMaxValues(self):
- field = Dict(title=u'Dict field',
- description=u'', readonly=False, required=False,
+ field = Dict(title=u('Dict field'),
+ description=u(''), readonly=False, required=False,
max_length=1)
field.validate(None)
field.validate({})
@@ -63,8 +65,8 @@
self.assertRaises(TooLong, field.validate, {1: 'a', 2: 'b', 3: 'c'})
def testValidateMinValuesAndMaxValues(self):
- field = Dict(title=u'Dict field',
- description=u'', readonly=False, required=False,
+ field = Dict(title=u('Dict field'),
+ description=u(''), readonly=False, required=False,
min_length=1, max_length=2)
field.validate(None)
field.validate({1: 'a'})
@@ -74,8 +76,8 @@
self.assertRaises(TooLong, field.validate, {1: 'a', 2: 'b', 3: 'c'})
def testValidateValueType(self):
- field = Dict(title=u'Dict field',
- description=u'', readonly=False, required=False,
+ field = Dict(title=u('Dict field'),
+ description=u(''), readonly=False, required=False,
value_type=Int())
field.validate(None)
field.validate({'a': 5})
@@ -86,8 +88,8 @@
self.assertRaises(WrongContainedType, field.validate, {'a': ()} )
def testValidateKeyTypes(self):
- field = Dict(title=u'Dict field',
- description=u'', readonly=False, required=False,
+ field = Dict(title=u('Dict field'),
+ description=u(''), readonly=False, required=False,
key_type=Int())
field.validate(None)
field.validate({5: 'a'})
@@ -101,7 +103,7 @@
def test_bind_binds_key_and_value_types(self):
field = self._Field_Factory(
__name__ = 'x',
- title=u'Not required field', description=u'',
+ title=u('Not required field'), description=u(''),
readonly=False, required=False,
key_type=Int(),
value_type=Int(),
Modified: zope.schema/branches/jinty-python3/src/zope/schema/tests/test_docs.py
===================================================================
--- zope.schema/branches/jinty-python3/src/zope/schema/tests/test_docs.py 2011-10-10 10:44:37 UTC (rev 123042)
+++ zope.schema/branches/jinty-python3/src/zope/schema/tests/test_docs.py 2011-10-10 10:46:35 UTC (rev 123043)
@@ -18,16 +18,20 @@
import unittest
from zope.testing import renormalizing
+import zope.schema.tests
def test_suite():
checker = renormalizing.RENormalizing([
(re.compile(r"\[\(None, Invalid\('8<=10',\)\)\]"),
r"[(None, <zope.interface.exceptions.Invalid instance at 0x...>)]",)
])
+ checker = checker + zope.schema.tests.py3_checker
return unittest.TestSuite((
- doctest.DocFileSuite('../sources.txt', optionflags=doctest.ELLIPSIS),
- doctest.DocFileSuite('../fields.txt'),
- doctest.DocFileSuite('../README.txt'),
+ doctest.DocFileSuite('../sources.txt',
+ optionflags=doctest.ELLIPSIS,
+ checker=zope.schema.tests.py3_checker),
+ doctest.DocFileSuite('../fields.txt', checker=zope.schema.tests.py3_checker),
+ doctest.DocFileSuite('../README.txt', checker=zope.schema.tests.py3_checker),
doctest.DocFileSuite(
'../validation.txt', checker=checker,
optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS),
Modified: zope.schema/branches/jinty-python3/src/zope/schema/tests/test_dotted_name.py
===================================================================
--- zope.schema/branches/jinty-python3/src/zope/schema/tests/test_dotted_name.py 2011-10-10 10:44:37 UTC (rev 123042)
+++ zope.schema/branches/jinty-python3/src/zope/schema/tests/test_dotted_name.py 2011-10-10 10:46:35 UTC (rev 123043)
@@ -14,6 +14,8 @@
"""DottedName field tests
"""
from unittest import main, makeSuite
+
+from six import b
from zope.schema import DottedName
from zope.schema.tests.test_field import FieldTestBase
from zope.schema.interfaces import InvalidDottedName, RequiredMissing
@@ -27,21 +29,21 @@
field = self._Field_Factory(required=False)
field.validate(None)
- field.validate('foo.bar')
- field.validate('foo.bar0')
- field.validate('foo0.bar')
+ field.validate(b('foo.bar'))
+ field.validate(b('foo.bar0'))
+ field.validate(b('foo0.bar'))
# We used to incorrectly allow ^: https://bugs.launchpad.net/zope.schema/+bug/191236
- self.assertRaises(InvalidDottedName, field.validate, 'foo.bar^foobar')
- self.assertRaises(InvalidDottedName, field.validate, 'foo^foobar.bar')
+ self.assertRaises(InvalidDottedName, field.validate, b('foo.bar^foobar'))
+ self.assertRaises(InvalidDottedName, field.validate, b('foo^foobar.bar'))
# dotted names cannot start with digits
- self.assertRaises(InvalidDottedName, field.validate, 'foo.0bar')
- self.assertRaises(InvalidDottedName, field.validate, '0foo.bar')
+ self.assertRaises(InvalidDottedName, field.validate, b('foo.0bar'))
+ self.assertRaises(InvalidDottedName, field.validate, b('0foo.bar'))
def testValidateRequired(self):
field = self._Field_Factory(required=True)
- field.validate('foo.bar')
+ field.validate(b('foo.bar'))
self.assertRaises(RequiredMissing, field.validate, None)
Modified: zope.schema/branches/jinty-python3/src/zope/schema/tests/test_equality.py
===================================================================
--- zope.schema/branches/jinty-python3/src/zope/schema/tests/test_equality.py 2011-10-10 10:44:37 UTC (rev 123042)
+++ zope.schema/branches/jinty-python3/src/zope/schema/tests/test_equality.py 2011-10-10 10:46:35 UTC (rev 123043)
@@ -14,13 +14,15 @@
"""Field equality tests
"""
from unittest import TestCase, TestSuite, makeSuite
+
+from six import u
from zope.schema import Text, Int
class FieldEqualityTests(TestCase):
equality = [
- 'Text(title=u"Foo", description=u"Bar")',
- 'Int(title=u"Foo", description=u"Bar")',
+ 'Text(title=u("Foo"), description=u("Bar"))',
+ 'Int(title=u("Foo"), description=u("Bar"))',
]
def test_equality(self):
Modified: zope.schema/branches/jinty-python3/src/zope/schema/tests/test_field.py
===================================================================
--- zope.schema/branches/jinty-python3/src/zope/schema/tests/test_field.py 2011-10-10 10:44:37 UTC (rev 123042)
+++ zope.schema/branches/jinty-python3/src/zope/schema/tests/test_field.py 2011-10-10 10:46:35 UTC (rev 123043)
@@ -19,19 +19,21 @@
from doctest import DocTestSuite
from unittest import TestCase, TestSuite, makeSuite
+from six import u, b
from zope.interface import Interface, provider
from zope.schema import Field, Text, Int
from zope.schema.interfaces import IContextAwareDefaultFactory
from zope.schema.interfaces import ValidationError, RequiredMissing
from zope.schema.interfaces import ConstraintNotSatisfied, WrongType
from zope.testing import renormalizing
+import zope.schema.tests
class FieldTestBase(TestCase):
def test_bind(self):
field = self._Field_Factory(
__name__ = 'x',
- title=u'Not required field', description=u'',
+ title=u('Not required field'), description=u(''),
readonly=False, required=False)
field.interface = Interface
@@ -51,7 +53,7 @@
def testValidate(self):
field = self._Field_Factory(
- title=u'Not required field', description=u'',
+ title=u('Not required field'), description=u(''),
readonly=False, required=False)
field.validate(None)
field.validate('foo')
@@ -61,7 +63,7 @@
def testValidateRequired(self):
field = self._Field_Factory(
- title=u'Required field', description=u'',
+ title=u('Required field'), description=u(''),
readonly=False, required=True)
field.validate('foo')
field.validate(1)
@@ -75,7 +77,7 @@
def test_bind_binds_value_type(self):
field = self._Field_Factory(
__name__ = 'x',
- title=u'Not required field', description=u'',
+ title=u('Not required field'), description=u(''),
readonly=False, required=False,
value_type=Int(),
)
@@ -94,20 +96,20 @@
_Field_Factory = Field
def testSillyDefault(self):
- self.assertRaises(ValidationError, Text, default="")
+ self.assertRaises(ValidationError, Text, default=b(""))
def test__doc__(self):
- field = Text(title=u"test fiield",
+ field = Text(title=u("test fiield"),
description=(
- u"To make sure that\n"
- u"doc strings are working correctly\n"
+ u("To make sure that\n"
+ "doc strings are working correctly\n")
)
)
self.assertEqual(
field.__doc__,
- u"test fiield\n\n"
- u"To make sure that\n"
- u"doc strings are working correctly\n"
+ u("test fiield\n\n"
+ "To make sure that\n"
+ "doc strings are working correctly\n")
)
def testOrdering(self):
@@ -130,7 +132,7 @@
def isodd(x):
return x % 2 == 1
- i = Int(title=u'my constrained integer',
+ i = Int(title=u('my constrained integer'),
constraint=isodd)
i.validate(11)
@@ -168,7 +170,7 @@
def test_required_defaults_to_true(self):
class MyField(Field):
pass
- field = MyField(title=u'my')
+ field = MyField(title=u('my'))
self.assert_(field.required)
def test_suite():
@@ -176,9 +178,10 @@
(re.compile(r" with base 10: '125.6'"),
r': 125.6')
])
+ checker = checker + zope.schema.tests.py3_checker
return TestSuite((
makeSuite(FieldTest),
makeSuite(FieldDefaultBehaviour),
- DocTestSuite("zope.schema._field"),
+ DocTestSuite("zope.schema._field", checker=zope.schema.tests.py3_checker),
DocTestSuite("zope.schema._bootstrapfields",checker=checker),
))
Modified: zope.schema/branches/jinty-python3/src/zope/schema/tests/test_fieldproperty.py
===================================================================
--- zope.schema/branches/jinty-python3/src/zope/schema/tests/test_fieldproperty.py 2011-10-10 10:44:37 UTC (rev 123042)
+++ zope.schema/branches/jinty-python3/src/zope/schema/tests/test_fieldproperty.py 2011-10-10 10:46:35 UTC (rev 123043)
@@ -16,6 +16,7 @@
from unittest import TestCase, TestSuite, main, makeSuite
+from six import u, b
from zope.interface import Interface
from zope.schema import Float, Text, Bytes
from zope.schema.interfaces import ValidationError
@@ -25,10 +26,10 @@
class I(Interface):
- title = Text(description=u"Short summary", default=u'say something')
+ title = Text(description=u("Short summary"), default=u('say something'))
weight = Float(min=0.0)
- code = Bytes(min_length=6, max_length=6, default='xxxxxx')
- date = Float(title=u'Date', readonly=True)
+ code = Bytes(min_length=6, max_length=6, default=b('xxxxxx'))
+ date = Float(title=u('Date'), readonly=True)
class C(object):
@@ -44,24 +45,24 @@
def test_basic(self):
c = self.klass()
- self.assertEqual(c.title, u'say something')
+ self.assertEqual(c.title, u('say something'))
self.assertEqual(c.weight, None)
- self.assertEqual(c.code, 'xxxxxx')
- self.assertRaises(ValidationError, setattr, c, 'title', 'foo')
- self.assertRaises(ValidationError, setattr, c, 'weight', 'foo')
+ self.assertEqual(c.code, b('xxxxxx'))
+ self.assertRaises(ValidationError, setattr, c, 'title', b('foo'))
+ self.assertRaises(ValidationError, setattr, c, 'weight', b('foo'))
self.assertRaises(ValidationError, setattr, c, 'weight', -1.0)
self.assertRaises(ValidationError, setattr, c, 'weight', 2)
self.assertRaises(ValidationError, setattr, c, 'code', -1)
- self.assertRaises(ValidationError, setattr, c, 'code', 'xxxx')
- self.assertRaises(ValidationError, setattr, c, 'code', u'xxxxxx')
+ self.assertRaises(ValidationError, setattr, c, 'code', b('xxxx'))
+ self.assertRaises(ValidationError, setattr, c, 'code', u('xxxxxx'))
- c.title = u'c is good'
+ c.title = u('c is good')
c.weight = 10.0
- c.code = 'abcdef'
+ c.code = b('abcdef')
- self.assertEqual(c.title, u'c is good')
+ self.assertEqual(c.title, u('c is good'))
self.assertEqual(c.weight, 10)
- self.assertEqual(c.code, 'abcdef')
+ self.assertEqual(c.code, b('abcdef'))
def test_readonly(self):
c = self.klass()
Modified: zope.schema/branches/jinty-python3/src/zope/schema/tests/test_floatfield.py
===================================================================
--- zope.schema/branches/jinty-python3/src/zope/schema/tests/test_floatfield.py 2011-10-10 10:44:37 UTC (rev 123042)
+++ zope.schema/branches/jinty-python3/src/zope/schema/tests/test_floatfield.py 2011-10-10 10:46:35 UTC (rev 123043)
@@ -14,6 +14,8 @@
"""Float field tests
"""
from unittest import main, makeSuite
+
+from six import u
from zope.schema import Float
from zope.schema.interfaces import RequiredMissing, InvalidValue
from zope.schema.interfaces import TooSmall, TooBig
@@ -25,7 +27,7 @@
_Field_Factory = Float
def testValidate(self):
- field = self._Field_Factory(title=u'Float field', description=u'',
+ field = self._Field_Factory(title=u('Float field'), description=u(''),
readonly=False, required=False)
field.validate(None)
field.validate(10.0)
@@ -33,7 +35,7 @@
field.validate(1000.0003)
def testValidateRequired(self):
- field = self._Field_Factory(title=u'Float field', description=u'',
+ field = self._Field_Factory(title=u('Float field'), description=u(''),
readonly=False, required=True)
field.validate(10.0)
field.validate(0.93)
@@ -42,7 +44,7 @@
self.assertRaises(RequiredMissing, field.validate, None)
def testValidateMin(self):
- field = self._Field_Factory(title=u'Float field', description=u'',
+ field = self._Field_Factory(title=u('Float field'), description=u(''),
readonly=False, required=False, min=10.5)
field.validate(None)
field.validate(10.6)
@@ -52,7 +54,7 @@
self.assertRaises(TooSmall, field.validate, 10.4)
def testValidateMax(self):
- field = self._Field_Factory(title=u'Float field', description=u'',
+ field = self._Field_Factory(title=u('Float field'), description=u(''),
readonly=False, required=False, max=10.5)
field.validate(None)
field.validate(5.3)
@@ -62,7 +64,7 @@
self.assertRaises(TooBig, field.validate, 20.7)
def testValidateMinAndMax(self):
- field = self._Field_Factory(title=u'Float field', description=u'',
+ field = self._Field_Factory(title=u('Float field'), description=u(''),
readonly=False, required=False,
min=-0.6, max=10.1)
field.validate(None)
Modified: zope.schema/branches/jinty-python3/src/zope/schema/tests/test_interfacefield.py
===================================================================
--- zope.schema/branches/jinty-python3/src/zope/schema/tests/test_interfacefield.py 2011-10-10 10:44:37 UTC (rev 123042)
+++ zope.schema/branches/jinty-python3/src/zope/schema/tests/test_interfacefield.py 2011-10-10 10:46:35 UTC (rev 123043)
@@ -14,6 +14,8 @@
"""Interface field tests
"""
from unittest import main, makeSuite
+
+from six import u
from zope.schema import InterfaceField
from zope.schema.interfaces import RequiredMissing, WrongType
from zope.schema.tests.test_field import FieldTestBase
@@ -28,13 +30,13 @@
_Field_Factory = InterfaceField
def testValidate(self):
- field = InterfaceField(title=u'Interface field', description=u'',
+ field = InterfaceField(title=u('Interface field'), description=u(''),
readonly=False, required=False)
field.validate(DummyInterface)
self.assertRaises(WrongType, field.validate, object())
def testValidateRequired(self):
- field = InterfaceField(title=u'Interface field', description=u'',
+ field = InterfaceField(title=u('Interface field'), description=u(''),
readonly=False, required=True)
self.assertRaises(RequiredMissing, field.validate, None)
Modified: zope.schema/branches/jinty-python3/src/zope/schema/tests/test_intfield.py
===================================================================
--- zope.schema/branches/jinty-python3/src/zope/schema/tests/test_intfield.py 2011-10-10 10:44:37 UTC (rev 123042)
+++ zope.schema/branches/jinty-python3/src/zope/schema/tests/test_intfield.py 2011-10-10 10:46:35 UTC (rev 123043)
@@ -14,6 +14,8 @@
"""Integer field tests
"""
from unittest import main, makeSuite
+
+from six import u
from zope.schema import Int
from zope.schema.interfaces import RequiredMissing, InvalidValue
from zope.schema.interfaces import TooSmall, TooBig
@@ -25,7 +27,7 @@
_Field_Factory = Int
def testValidate(self):
- field = self._Field_Factory(title=u'Int field', description=u'',
+ field = self._Field_Factory(title=u('Int field'), description=u(''),
readonly=False, required=False)
field.validate(None)
field.validate(10)
@@ -33,7 +35,7 @@
field.validate(-1)
def testValidateRequired(self):
- field = self._Field_Factory(title=u'Int field', description=u'',
+ field = self._Field_Factory(title=u('Int field'), description=u(''),
readonly=False, required=True)
field.validate(10)
field.validate(0)
@@ -42,7 +44,7 @@
self.assertRaises(RequiredMissing, field.validate, None)
def testValidateMin(self):
- field = self._Field_Factory(title=u'Int field', description=u'',
+ field = self._Field_Factory(title=u('Int field'), description=u(''),
readonly=False, required=False, min=10)
field.validate(None)
field.validate(10)
@@ -52,7 +54,7 @@
self.assertRaises(TooSmall, field.validate, -10)
def testValidateMax(self):
- field = self._Field_Factory(title=u'Int field', description=u'',
+ field = self._Field_Factory(title=u('Int field'), description=u(''),
readonly=False, required=False, max=10)
field.validate(None)
field.validate(5)
@@ -63,7 +65,7 @@
self.assertRaises(TooBig, field.validate, 20)
def testValidateMinAndMax(self):
- field = self._Field_Factory(title=u'Int field', description=u'',
+ field = self._Field_Factory(title=u('Int field'), description=u(''),
readonly=False, required=False,
min=0, max=10)
field.validate(None)
Modified: zope.schema/branches/jinty-python3/src/zope/schema/tests/test_iterablefield.py
===================================================================
--- zope.schema/branches/jinty-python3/src/zope/schema/tests/test_iterablefield.py 2011-10-10 10:44:37 UTC (rev 123042)
+++ zope.schema/branches/jinty-python3/src/zope/schema/tests/test_iterablefield.py 2011-10-10 10:46:35 UTC (rev 123043)
@@ -13,7 +13,12 @@
##############################################################################
"""Iterable field tests
"""
-from UserDict import UserDict, IterableUserDict
+from six import PY3, u
+if not PY3:
+ from UserDict import UserDict, IterableUserDict
+else:
+ #python3
+ from collections import UserDict as IterableUserDict, UserDict
from unittest import main, makeSuite
from zope.schema import Iterable
from zope.schema.interfaces import RequiredMissing
@@ -26,7 +31,7 @@
_Field_Factory = Iterable
def testValidate(self):
- field = self._Field_Factory(title=u'test field', description=u'',
+ field = self._Field_Factory(title=u('test field'), description=u(''),
readonly=False, required=False)
field.validate(None)
field.validate('')
@@ -40,7 +45,7 @@
self.assertRaises(NotAnIterator, field.validate, UserDict)
def testValidateRequired(self):
- field = self._Field_Factory(title=u'test field', description=u'',
+ field = self._Field_Factory(title=u('test field'), description=u(''),
readonly=False, required=True)
field.validate('')
Modified: zope.schema/branches/jinty-python3/src/zope/schema/tests/test_listfield.py
===================================================================
--- zope.schema/branches/jinty-python3/src/zope/schema/tests/test_listfield.py 2011-10-10 10:44:37 UTC (rev 123042)
+++ zope.schema/branches/jinty-python3/src/zope/schema/tests/test_listfield.py 2011-10-10 10:46:35 UTC (rev 123043)
@@ -15,7 +15,8 @@
"""
from unittest import main, makeSuite
-from zope.interface import implements
+from six import u
+from zope.interface import implementer
from zope.schema import Field, List, Int
from zope.schema.interfaces import IField
from zope.schema.interfaces import ICollection, ISequence, IList
@@ -30,7 +31,7 @@
_Field_Factory = List
def testValidate(self):
- field = List(title=u'List field', description=u'',
+ field = List(title=u('List field'), description=u(''),
readonly=False, required=False)
field.validate(None)
field.validate([])
@@ -38,7 +39,7 @@
field.validate([3,])
def testValidateRequired(self):
- field = List(title=u'List field', description=u'',
+ field = List(title=u('List field'), description=u(''),
readonly=False, required=True)
field.validate([])
field.validate([1, 2])
@@ -47,7 +48,7 @@
self.assertRaises(RequiredMissing, field.validate, None)
def testValidateMinValues(self):
- field = List(title=u'List field', description=u'',
+ field = List(title=u('List field'), description=u(''),
readonly=False, required=False, min_length=2)
field.validate(None)
field.validate([1, 2])
@@ -57,7 +58,7 @@
self.assertRaises(TooShort, field.validate, [1,])
def testValidateMaxValues(self):
- field = List(title=u'List field', description=u'',
+ field = List(title=u('List field'), description=u(''),
readonly=False, required=False, max_length=2)
field.validate(None)
field.validate([])
@@ -67,7 +68,7 @@
self.assertRaises(TooLong, field.validate, [1, 2, 3])
def testValidateMinValuesAndMaxValues(self):
- field = List(title=u'List field', description=u'',
+ field = List(title=u('List field'), description=u(''),
readonly=False, required=False,
min_length=1, max_length=2)
field.validate(None)
@@ -78,7 +79,7 @@
self.assertRaises(TooLong, field.validate, [1, 2, 3])
def testValidateValueTypes(self):
- field = List(title=u'List field', description=u'',
+ field = List(title=u('List field'), description=u(''),
readonly=False, required=False,
value_type=Int())
field.validate(None)
@@ -98,12 +99,13 @@
# however, allow anything that implements IField
List(value_type=Field())
+ @implementer(IField)
class FakeField(object):
- implements(IField)
+ pass
List(value_type=FakeField())
def testUnique(self):
- field = self._Field_Factory(title=u'test field', description=u'',
+ field = self._Field_Factory(title=u('test field'), description=u(''),
readonly=False, required=True, unique=True)
field.validate([1, 2])
self.assertRaises(NotUnique, field.validate, [1, 2, 1])
Modified: zope.schema/branches/jinty-python3/src/zope/schema/tests/test_objectfield.py
===================================================================
--- zope.schema/branches/jinty-python3/src/zope/schema/tests/test_objectfield.py 2011-10-10 10:44:37 UTC (rev 123042)
+++ zope.schema/branches/jinty-python3/src/zope/schema/tests/test_objectfield.py 2011-10-10 10:46:35 UTC (rev 123043)
@@ -16,8 +16,9 @@
"""
from unittest import TestSuite, main, makeSuite
+from six import u
import zope.event
-from zope.interface import Attribute, Interface, implements
+from zope.interface import Attribute, Interface, implementer
from zope.schema import Object, TextLine
from zope.schema.fieldproperty import FieldProperty
from zope.schema.interfaces import ValidationError
@@ -34,35 +35,34 @@
"""A test schema"""
foo = TextLine(
- title=_(u"Foo"),
- description=_(u"Foo description"),
- default=u"",
+ title=_("Foo"),
+ description=_("Foo description"),
+ default=u(""),
required=True)
bar = TextLine(
- title=_(u"Bar"),
- description=_(u"Bar description"),
- default=u"",
+ title=_("Bar"),
+ description=_("Bar description"),
+ default=u(""),
required=False)
attribute = Attribute("Test attribute, an attribute can't be validated.")
+ at implementer(ITestSchema)
class TestClass(object):
- implements(ITestSchema)
+ _foo = u('')
+ _bar = u('')
+ _attribute = u('')
- _foo = u''
- _bar = u''
- _attribute = u''
-
def getfoo(self):
return self._foo
def setfoo(self, value):
self._foo = value
- foo = property(getfoo, setfoo, None, u'foo')
+ foo = property(getfoo, setfoo, None, u('foo'))
def getbar(self):
return self._bar
@@ -70,7 +70,7 @@
def setbar(self, value):
self._bar = value
- bar = property(getbar, setbar, None, u'foo')
+ bar = property(getbar, setbar, None, u('foo'))
def getattribute(self):
return self._attribute
@@ -78,23 +78,21 @@
def setattribute(self, value):
self._attribute = value
- attribute = property(getattribute, setattribute, None, u'attribute')
+ attribute = property(getattribute, setattribute, None, u('attribute'))
+ at implementer(ITestSchema)
class FieldPropertyTestClass(object):
- implements(ITestSchema)
-
foo = FieldProperty(ITestSchema['foo'])
bar = FieldProperty(ITestSchema['bar'])
attribute = FieldProperty(ITestSchema['attribute'])
+ at implementer(ITestSchema)
class NotFullyImplementedTestClass(object):
- implements(ITestSchema)
-
foo = FieldProperty(ITestSchema['foo'])
# bar = FieldProperty(ITestSchema['bar']): bar is not implemented
# attribute
@@ -104,15 +102,14 @@
obj = Object(
schema=Interface,
- title=_(u"Object"),
- description=_(u"object description"),
+ title=_("Object"),
+ description=_("object description"),
required=False)
+ at implementer(ISchemaWithObjectFieldAsInterface)
class ClassWithObjectFieldAsInterface(object):
- implements(ISchemaWithObjectFieldAsInterface)
-
_obj = None
def getobj(self):
@@ -121,7 +118,7 @@
def setobj(self, value):
self._obj = value
- obj = property(getobj, setobj, None, u'obj')
+ obj = property(getobj, setobj, None, u('obj'))
class IUnit(Interface):
@@ -129,15 +126,15 @@
boss = Object(
schema=Interface,
- title=_(u"Boss"),
- description=_(u"Boss description"),
+ title=_("Boss"),
+ description=_("Boss description"),
required=False,
)
members = List(
value_type=Object(schema=Interface),
- title=_(u"Member List"),
- description=_(u"Member list description"),
+ title=_("Member List"),
+ description=_("Member list description"),
required=False,
)
@@ -147,8 +144,8 @@
unit = Object(
schema=IUnit,
- title=_(u"Unit"),
- description=_(u"Unit description"),
+ title=_("Unit"),
+ description=_("Unit description"),
required=False,
)
@@ -156,19 +153,17 @@
IUnit['members'].value_type.schema = IPerson
+ at implementer(IUnit)
class Unit(object):
- implements(IUnit)
-
def __init__(self, person, person_list):
self.boss = person
self.members = person_list
+ at implementer(IPerson)
class Person(object):
- implements(IPerson)
-
def __init__(self, unit):
self.unit = unit
@@ -179,9 +174,9 @@
def getErrors(self, f, *args, **kw):
try:
f(*args, **kw)
- except WrongContainedType, e:
+ except WrongContainedType as e:
try:
- return e[0]
+ return e.args[0]
except:
return []
self.fail('Expected WrongContainedType Error')
@@ -224,7 +219,7 @@
def test_validate_required(self):
field = self._Field_Factory(
- title=u'Required field', description=u'',
+ title=u('Required field'), description=u(''),
readonly=False, required=True)
self.assertRaises(RequiredMissing, field.validate, None)
Modified: zope.schema/branches/jinty-python3/src/zope/schema/tests/test_schema.py
===================================================================
--- zope.schema/branches/jinty-python3/src/zope/schema/tests/test_schema.py 2011-10-10 10:44:37 UTC (rev 123042)
+++ zope.schema/branches/jinty-python3/src/zope/schema/tests/test_schema.py 2011-10-10 10:46:35 UTC (rev 123043)
@@ -14,6 +14,7 @@
"""Schema field tests
"""
from unittest import TestCase, main, makeSuite
+from six import u, b
from zope.interface import Interface
from zope.schema import Bytes
from zope.schema import getFields, getFieldsInOrder
@@ -21,28 +22,28 @@
class ISchemaTest(Interface):
title = Bytes(
- title=u"Title",
- description=u"Title",
- default="",
+ title=u("Title"),
+ description=u("Title"),
+ default=b(""),
required=True)
description = Bytes(
- title=u"Description",
- description=u"Description",
- default="",
+ title=u("Description"),
+ description=u("Description"),
+ default=b(""),
required=True)
spam = Bytes(
- title=u"Spam",
- description=u"Spam",
- default="",
+ title=u("Spam"),
+ description=u("Spam"),
+ default=b(""),
required=True)
class ISchemaTestSubclass(ISchemaTest):
foo = Bytes(
- title=u'Foo',
- description=u'Fooness',
- default="",
+ title=u('Foo'),
+ description=u('Fooness'),
+ default=b(""),
required=False)
@@ -66,24 +67,24 @@
def test_getFields(self):
fields = getFields(ISchemaTest)
- self.assert_(fields.has_key('title'))
- self.assert_(fields.has_key('description'))
- self.assert_(fields.has_key('spam'))
+ self.assert_('title' in fields)
+ self.assert_('description' in fields)
+ self.assert_('spam' in fields)
# test whether getName() has the right value
- for key, value in fields.iteritems():
+ for key, value in fields.items():
self.assertEquals(key, value.getName())
def test_getFieldsAll(self):
fields = getFields(ISchemaTestSubclass)
- self.assert_(fields.has_key('title'))
- self.assert_(fields.has_key('description'))
- self.assert_(fields.has_key('spam'))
- self.assert_(fields.has_key('foo'))
+ self.assert_('title' in fields)
+ self.assert_('description' in fields)
+ self.assert_('spam' in fields)
+ self.assert_('foo' in fields)
# test whether getName() has the right value
- for key, value in fields.iteritems():
+ for key, value in fields.items():
self.assertEquals(key, value.getName())
def test_getFieldsInOrder(self):
Modified: zope.schema/branches/jinty-python3/src/zope/schema/tests/test_setfield.py
===================================================================
--- zope.schema/branches/jinty-python3/src/zope/schema/tests/test_setfield.py 2011-10-10 10:44:37 UTC (rev 123042)
+++ zope.schema/branches/jinty-python3/src/zope/schema/tests/test_setfield.py 2011-10-10 10:46:35 UTC (rev 123043)
@@ -15,7 +15,8 @@
"""
from unittest import TestSuite, main, makeSuite
-from zope.interface import implements, providedBy
+from six import u
+from zope.interface import implementer, providedBy
from zope.schema import Field, Set, Int, FrozenSet
from zope.schema.interfaces import IField
from zope.schema.interfaces import (
@@ -32,7 +33,7 @@
_Field_Factory = Set
def testValidate(self):
- field = Set(title=u'Set field', description=u'',
+ field = Set(title=u('Set field'), description=u(''),
readonly=False, required=False)
field.validate(None)
field.validate(set())
@@ -50,7 +51,7 @@
self.assertRaises(WrongType, field.validate, frozenset((1, 2, 3)))
def testValidateRequired(self):
- field = Set(title=u'Set field', description=u'',
+ field = Set(title=u('Set field'), description=u(''),
readonly=False, required=True)
field.validate(set())
field.validate(set((1, 2)))
@@ -79,7 +80,7 @@
field.default = missing
def testValidateMinValues(self):
- field = Set(title=u'Set field', description=u'',
+ field = Set(title=u('Set field'), description=u(''),
readonly=False, required=False, min_length=2)
field.validate(None)
field.validate(set((1, 2)))
@@ -93,7 +94,7 @@
self.assertRaises(TooShort, field.validate, set((3,)))
def testValidateMaxValues(self):
- field = Set(title=u'Set field', description=u'',
+ field = Set(title=u('Set field'), description=u(''),
readonly=False, required=False, max_length=2)
field.validate(None)
field.validate(set())
@@ -107,7 +108,7 @@
self.assertRaises(TooLong, field.validate, set((1, 2, 3)))
def testValidateMinValuesAndMaxValues(self):
- field = Set(title=u'Set field', description=u'',
+ field = Set(title=u('Set field'), description=u(''),
readonly=False, required=False,
min_length=1, max_length=2)
field.validate(None)
@@ -122,7 +123,7 @@
self.assertRaises(TooLong, field.validate, set((1, 2, 3)))
def testValidateValueTypes(self):
- field = Set(title=u'Set field', description=u'',
+ field = Set(title=u('Set field'), description=u(''),
readonly=False, required=False,
value_type=Int())
field.validate(None)
@@ -149,8 +150,9 @@
# however, allow anything that implements IField
Set(value_type=Field())
+ @implementer(IField)
class FakeField(object):
- implements(IField)
+ pass
Set(value_type=FakeField())
def testNoUniqueArgument(self):
@@ -171,7 +173,7 @@
_Field_Factory = FrozenSet
def testValidate(self):
- field = FrozenSet(title=u'Set field', description=u'',
+ field = FrozenSet(title=u('Set field'), description=u(''),
readonly=False, required=False)
field.validate(None)
field.validate(frozenset())
@@ -187,7 +189,7 @@
self.assertRaises(WrongType, field.validate, set((1, 2, 3)))
def testValidateRequired(self):
- field = FrozenSet(title=u'Set field', description=u'',
+ field = FrozenSet(title=u('Set field'), description=u(''),
readonly=False, required=True)
field.validate(frozenset())
field.validate(frozenset((1, 2)))
@@ -212,7 +214,7 @@
field.default = missing
def testValidateMinValues(self):
- field = FrozenSet(title=u'FrozenSet field', description=u'',
+ field = FrozenSet(title=u('FrozenSet field'), description=u(''),
readonly=False, required=False, min_length=2)
field.validate(None)
field.validate(frozenset((1, 2)))
@@ -222,7 +224,7 @@
self.assertRaises(TooShort, field.validate, frozenset((3,)))
def testValidateMaxValues(self):
- field = FrozenSet(title=u'FrozenSet field', description=u'',
+ field = FrozenSet(title=u('FrozenSet field'), description=u(''),
readonly=False, required=False, max_length=2)
field.validate(None)
field.validate(frozenset())
@@ -232,7 +234,7 @@
self.assertRaises(TooLong, field.validate, frozenset((1, 2, 3)))
def testValidateMinValuesAndMaxValues(self):
- field = FrozenSet(title=u'FrozenSet field', description=u'',
+ field = FrozenSet(title=u('FrozenSet field'), description=u(''),
readonly=False, required=False,
min_length=1, max_length=2)
field.validate(None)
@@ -243,7 +245,7 @@
self.assertRaises(TooLong, field.validate, frozenset((1, 2, 3)))
def testValidateValueTypes(self):
- field = FrozenSet(title=u'FrozenSet field', description=u'',
+ field = FrozenSet(title=u('FrozenSet field'), description=u(''),
readonly=False, required=False,
value_type=Int())
field.validate(None)
@@ -264,8 +266,9 @@
# however, allow anything that implements IField
FrozenSet(value_type=Field())
+ @implementer(IField)
class FakeField(object):
- implements(IField)
+ pass
FrozenSet(value_type=FakeField())
def testNoUniqueArgument(self):
Modified: zope.schema/branches/jinty-python3/src/zope/schema/tests/test_states.py
===================================================================
--- zope.schema/branches/jinty-python3/src/zope/schema/tests/test_states.py 2011-10-10 10:44:37 UTC (rev 123042)
+++ zope.schema/branches/jinty-python3/src/zope/schema/tests/test_states.py 2011-10-10 10:46:35 UTC (rev 123043)
@@ -15,6 +15,7 @@
"""
import unittest
+from six import u
from zope.interface import Interface
from zope.interface.verify import verifyObject
@@ -26,25 +27,25 @@
class IBirthInfo(Interface):
state1 = Choice(
- title=u'State of Birth',
- description=u'The state in which you were born.',
+ title=u('State of Birth'),
+ description=u('The state in which you were born.'),
vocabulary="states",
default="AL",
)
state2 = Choice(
- title=u'State of Birth',
- description=u'The state in which you were born.',
+ title=u('State of Birth'),
+ description=u('The state in which you were born.'),
vocabulary="states",
default="AL",
)
state3 = Choice(
- title=u'Favorite State',
- description=u'The state you like the most.',
+ title=u('Favorite State'),
+ description=u('The state you like the most.'),
vocabulary=states.StateVocabulary(),
)
state4 = Choice(
- title=u"Name",
- description=u"The name of your new state",
+ title=u("Name"),
+ description=u("The name of your new state"),
vocabulary="states",
)
Modified: zope.schema/branches/jinty-python3/src/zope/schema/tests/test_strfield.py
===================================================================
--- zope.schema/branches/jinty-python3/src/zope/schema/tests/test_strfield.py 2011-10-10 10:44:37 UTC (rev 123042)
+++ zope.schema/branches/jinty-python3/src/zope/schema/tests/test_strfield.py 2011-10-10 10:46:35 UTC (rev 123043)
@@ -14,6 +14,7 @@
"""String field tests
"""
from unittest import TestSuite, main, makeSuite
+from six import b, u
from zope.schema import Bytes, BytesLine, Text, TextLine, Password
from zope.schema.interfaces import ValidationError, WrongType
from zope.schema.interfaces import RequiredMissing, InvalidValue
@@ -24,7 +25,7 @@
"""Test the Str Field."""
def testValidate(self):
- field = self._Field_Factory(title=u'Str field', description=u'',
+ field = self._Field_Factory(title=u('Str field'), description=u(''),
readonly=False, required=False)
field.validate(None)
field.validate(self._convert('foo'))
@@ -36,7 +37,7 @@
# we need to set the min-length to 1.
field = self._Field_Factory(
- title=u'Str field', description=u'',
+ title=u('Str field'), description=u(''),
readonly=False, required=True, min_length=1)
field.validate(self._convert('foo'))
@@ -45,7 +46,7 @@
def testValidateMinLength(self):
field = self._Field_Factory(
- title=u'Str field', description=u'',
+ title=u('Str field'), description=u(''),
readonly=False, required=False, min_length=3)
field.validate(None)
field.validate(self._convert('333'))
@@ -57,7 +58,7 @@
def testValidateMaxLength(self):
field = self._Field_Factory(
- title=u'Str field', description=u'',
+ title=u('Str field'), description=u(''),
readonly=False, required=False, max_length=5)
field.validate(None)
field.validate(self._convert(''))
@@ -69,7 +70,7 @@
def testValidateMinLengthAndMaxLength(self):
field = self._Field_Factory(
- title=u'Str field', description=u'',
+ title=u('Str field'), description=u(''),
readonly=False, required=False,
min_length=3, max_length=5)
@@ -87,32 +88,34 @@
class MultiLine(object):
def test_newlines(self):
- field = self._Field_Factory(title=u'Str field')
+ field = self._Field_Factory(title=u('Str field'))
field.validate(self._convert('hello\nworld'))
class BytesTest(StrTest, MultiLine):
_Field_Factory = Bytes
- _convert = str
+ def _convert(self, v):
+ return b(v)
+
def testBadStringType(self):
field = self._Field_Factory()
- self.assertRaises(ValidationError, field.validate, u'hello')
+ self.assertRaises(ValidationError, field.validate, u('hello'))
class TextTest(StrTest, MultiLine):
_Field_Factory = Text
def _convert(self, v):
- return unicode(v, 'ascii')
+ return u(v)
def testBadStringType(self):
field = self._Field_Factory()
- self.assertRaises(ValidationError, field.validate, 'hello')
+ self.assertRaises(ValidationError, field.validate, b('hello'))
class SingleLine(object):
def test_newlines(self):
- field = self._Field_Factory(title=u'Str field')
+ field = self._Field_Factory(title=u('Str field'))
self.assertRaises(ConstraintNotSatisfied,
field.validate,
self._convert('hello\nworld'))
@@ -125,7 +128,7 @@
password = None
dummy = Dummy()
- field = self._Field_Factory(title=u'Str field', description=u'',
+ field = self._Field_Factory(title=u('Str field'), description=u(''),
readonly=False, required=True, __name__='password')
field = field.bind(dummy)
@@ -136,12 +139,12 @@
field.validate(field.UNCHANGED_PASSWORD)
# Using a normal value, the field gets updated
- field.set(dummy, u'test')
- self.assertEquals(u'test', dummy.password)
+ field.set(dummy, u('test'))
+ self.assertEquals(u('test'), dummy.password)
# Using UNCHANGED_PASSWORD the field is not updated.
field.set(dummy, field.UNCHANGED_PASSWORD)
- self.assertEquals(u'test', dummy.password)
+ self.assertEquals(u('test'), dummy.password)
class LineTest(SingleLine, BytesTest):
Modified: zope.schema/branches/jinty-python3/src/zope/schema/tests/test_timedelta.py
===================================================================
--- zope.schema/branches/jinty-python3/src/zope/schema/tests/test_timedelta.py 2011-10-10 10:44:37 UTC (rev 123042)
+++ zope.schema/branches/jinty-python3/src/zope/schema/tests/test_timedelta.py 2011-10-10 10:46:35 UTC (rev 123043)
@@ -14,6 +14,8 @@
"""Timedelta Field tests
"""
from unittest import main, makeSuite
+
+from six import u
from zope.schema import Timedelta
from zope.schema.interfaces import RequiredMissing, InvalidValue
from zope.schema.interfaces import TooSmall, TooBig
@@ -31,13 +33,13 @@
verifyObject(ITimedelta, self._Field_Factory())
def testValidate(self):
- field = self._Field_Factory(title=u'Timedelta field', description=u'',
+ field = self._Field_Factory(title=u('Timedelta field'), description=u(''),
readonly=False, required=False)
field.validate(None)
field.validate(timedelta(minutes=15))
def testValidateRequired(self):
- field = self._Field_Factory(title=u'Timedelta field', description=u'',
+ field = self._Field_Factory(title=u('Timedelta field'), description=u(''),
readonly=False, required=True)
field.validate(timedelta(minutes=15))
@@ -46,7 +48,7 @@
def testValidateMin(self):
t1 = timedelta(hours=2)
t2 = timedelta(hours=3)
- field = self._Field_Factory(title=u'Timedelta field', description=u'',
+ field = self._Field_Factory(title=u('Timedelta field'), description=u(''),
readonly=False, required=False, min=t1)
field.validate(None)
field.validate(t1)
@@ -58,7 +60,7 @@
t1 = timedelta(minutes=1)
t2 = timedelta(minutes=2)
t3 = timedelta(minutes=3)
- field = self._Field_Factory(title=u'Timedelta field', description=u'',
+ field = self._Field_Factory(title=u('Timedelta field'), description=u(''),
readonly=False, required=False, max=t2)
field.validate(None)
field.validate(t1)
@@ -73,7 +75,7 @@
t4 = timedelta(days=4)
t5 = timedelta(days=5)
- field = self._Field_Factory(title=u'Timedelta field', description=u'',
+ field = self._Field_Factory(title=u('Timedelta field'), description=u(''),
readonly=False, required=False,
min=t2, max=t4)
field.validate(None)
Modified: zope.schema/branches/jinty-python3/src/zope/schema/tests/test_tuplefield.py
===================================================================
--- zope.schema/branches/jinty-python3/src/zope/schema/tests/test_tuplefield.py 2011-10-10 10:44:37 UTC (rev 123042)
+++ zope.schema/branches/jinty-python3/src/zope/schema/tests/test_tuplefield.py 2011-10-10 10:46:35 UTC (rev 123043)
@@ -15,7 +15,8 @@
"""
from unittest import TestSuite, main, makeSuite
-from zope.interface import implements
+from six import u
+from zope.interface import implementer
from zope.schema import Field, Tuple, Int
from zope.schema.interfaces import IField
from zope.schema.interfaces import ICollection, ISequence, ITuple
@@ -30,7 +31,7 @@
_Field_Factory = Tuple
def testValidate(self):
- field = Tuple(title=u'Tuple field', description=u'',
+ field = Tuple(title=u('Tuple field'), description=u(''),
readonly=False, required=False)
field.validate(None)
field.validate(())
@@ -43,7 +44,7 @@
self.assertRaises(WrongType, field.validate, {})
def testValidateRequired(self):
- field = Tuple(title=u'Tuple field', description=u'',
+ field = Tuple(title=u('Tuple field'), description=u(''),
readonly=False, required=True)
field.validate(())
field.validate((1, 2))
@@ -52,7 +53,7 @@
self.assertRaises(RequiredMissing, field.validate, None)
def testValidateMinValues(self):
- field = Tuple(title=u'Tuple field', description=u'',
+ field = Tuple(title=u('Tuple field'), description=u(''),
readonly=False, required=False, min_length=2)
field.validate(None)
field.validate((1, 2))
@@ -62,7 +63,7 @@
self.assertRaises(TooShort, field.validate, (1,))
def testValidateMaxValues(self):
- field = Tuple(title=u'Tuple field', description=u'',
+ field = Tuple(title=u('Tuple field'), description=u(''),
readonly=False, required=False, max_length=2)
field.validate(None)
field.validate(())
@@ -72,7 +73,7 @@
self.assertRaises(TooLong, field.validate, (1, 2, 3))
def testValidateMinValuesAndMaxValues(self):
- field = Tuple(title=u'Tuple field', description=u'',
+ field = Tuple(title=u('Tuple field'), description=u(''),
readonly=False, required=False,
min_length=1, max_length=2)
field.validate(None)
@@ -83,7 +84,7 @@
self.assertRaises(TooLong, field.validate, (1, 2, 3))
def testValidateValueTypes(self):
- field = Tuple(title=u'Tuple field', description=u'',
+ field = Tuple(title=u('Tuple field'), description=u(''),
readonly=False, required=False,
value_type=Int())
field.validate(None)
@@ -103,12 +104,13 @@
# however, allow anything that implements IField
Tuple(value_type=Field())
+ @implementer(IField)
class FakeField(object):
- implements(IField)
+ pass
Tuple(value_type=FakeField())
def testUnique(self):
- field = self._Field_Factory(title=u'test field', description=u'',
+ field = self._Field_Factory(title=u('test field'), description=u(''),
readonly=False, required=True, unique=True)
field.validate((1, 2))
self.assertRaises(NotUnique, field.validate, (1, 2, 1))
Modified: zope.schema/branches/jinty-python3/src/zope/schema/tests/test_vocabulary.py
===================================================================
--- zope.schema/branches/jinty-python3/src/zope/schema/tests/test_vocabulary.py 2011-10-10 10:44:37 UTC (rev 123042)
+++ zope.schema/branches/jinty-python3/src/zope/schema/tests/test_vocabulary.py 2011-10-10 10:46:35 UTC (rev 123043)
@@ -17,7 +17,7 @@
from zope.interface.verify import verifyObject
from zope.interface.exceptions import DoesNotImplement
-from zope.interface import Interface, implements
+from zope.interface import Interface, implementer
from zope.schema import interfaces
from zope.schema import vocabulary
@@ -59,8 +59,8 @@
class SampleTerm(object):
pass
+ at implementer(interfaces.IVocabulary)
class SampleVocabulary(object):
- implements(interfaces.IVocabulary)
def __iter__(self):
return iter([self.getTerm(x) for x in range(0, 10)])
@@ -161,13 +161,13 @@
def test_nonunique_token_message(self):
try:
vocabulary.SimpleVocabulary.fromValues([2, '2'])
- except ValueError, e:
+ except ValueError as e:
self.assertEquals(str(e), "term tokens must be unique: '2'")
def test_nonunique_token_messages(self):
try:
vocabulary.SimpleVocabulary.fromItems([(0, 'one'), (1, 'one')])
- except ValueError, e:
+ except ValueError as e:
self.assertEquals(str(e), "term values must be unique: 'one'")
def test_overriding_createTerm(self):
Modified: zope.schema/branches/jinty-python3/src/zope/schema/validation.txt
===================================================================
--- zope.schema/branches/jinty-python3/src/zope/schema/validation.txt 2011-10-10 10:44:37 UTC (rev 123042)
+++ zope.schema/branches/jinty-python3/src/zope/schema/validation.txt 2011-10-10 10:46:35 UTC (rev 123043)
@@ -16,13 +16,14 @@
>>> import zope.interface
>>> import zope.schema
+ >>> from six import print_
>>> class ITwoInts(zope.interface.Interface):
... a = zope.schema.Int(max=10)
... b = zope.schema.Int(min=5)
...
... @zope.interface.invariant
... def a_greater_b(obj):
- ... print "Checking if a > b"
+ ... print_("Checking if a > b")
... if obj.a <= obj.b:
... raise zope.interface.Invalid("%s<=%s" % (obj.a, obj.b))
...
Modified: zope.schema/branches/jinty-python3/src/zope/schema/vocabulary.py
===================================================================
--- zope.schema/branches/jinty-python3/src/zope/schema/vocabulary.py 2011-10-10 10:44:37 UTC (rev 123042)
+++ zope.schema/branches/jinty-python3/src/zope/schema/vocabulary.py 2011-10-10 10:46:35 UTC (rev 123043)
@@ -13,7 +13,7 @@
##############################################################################
"""Vocabulary support for schema.
"""
-from zope.interface.declarations import directlyProvides, implements
+from zope.interface.declarations import directlyProvides, implementer
from zope.schema.interfaces import ValidationError
from zope.schema.interfaces import IVocabularyRegistry
from zope.schema.interfaces import IVocabulary, IVocabularyTokenized
@@ -23,11 +23,10 @@
_marker = object()
+ at implementer(ITokenizedTerm)
class SimpleTerm(object):
"""Simple tokenized term used by SimpleVocabulary."""
- implements(ITokenizedTerm)
-
def __init__(self, value, token=None, title=None):
"""Create a term for value and token. If token is omitted,
str(value) is used for the token. If title is provided,
@@ -41,11 +40,10 @@
if title is not None:
directlyProvides(self, ITitledTokenizedTerm)
+ at implementer(IVocabularyTokenized)
class SimpleVocabulary(object):
"""Vocabulary that works from a sequence of terms."""
- implements(IVocabularyTokenized)
-
def __init__(self, terms, *interfaces):
"""Initialize the vocabulary given a list of terms.
@@ -151,9 +149,9 @@
return "unknown vocabulary: %r" % self.name
+ at implementer(IVocabularyRegistry)
class VocabularyRegistry(object):
__slots__ = '_map',
- implements(IVocabularyRegistry)
def __init__(self):
self._map = {}
More information about the checkins
mailing list