Skip to content

Commit

Permalink
pep 8
Browse files Browse the repository at this point in the history
  • Loading branch information
thet committed Nov 24, 2013
1 parent d6f96be commit a7b65d6
Show file tree
Hide file tree
Showing 13 changed files with 225 additions and 105 deletions.
1 change: 0 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ ignore-files=examples.py
[aliases]
dev = develop easy_install zope.schema[testing]
docs = easy_install zope.schema[docs]

59 changes: 33 additions & 26 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,18 @@
import sys
from setuptools import setup, find_packages


def read(*rnames):
return open(os.path.join(os.path.dirname(__file__), *rnames)).read()


def _modname(path, base, name=''):
if path == base:
return name
dirname, basename = os.path.split(path)
return _modname(dirname, base, basename + '.' + name)


def alltests():
import logging
import pkg_resources
Expand Down Expand Up @@ -61,32 +64,36 @@ def emit(self, record):
suite.addTest(mod.test_suite())
return suite


REQUIRES = [
'setuptools',
'zope.interface >= 3.6.0',
'zope.event',
]
'setuptools',
'zope.interface >= 3.6.0',
'zope.event',
]


if sys.version_info < (2, 7):
REQUIRES += ['ordereddict']


TESTS_REQUIRE = ['zope.testing']

setup(name='zope.schema',
version='4.3.3.dev0',
url='http://pypi.python.org/pypi/zope.schema',
license='ZPL 2.1',
description='zope.interface extension for defining data schemas',
author='Zope Foundation and Contributors',
author_email='zope-dev@zope.org',
long_description=(read('README.rst') + '\n\n' + read('CHANGES.rst')),
packages=find_packages('src'),
package_dir = {'': 'src'},
namespace_packages=['zope',],
#extras_require={
# 'docs': ['z3c.recipe.sphinxdoc']},
install_requires=REQUIRES,
classifiers=[

setup(
name='zope.schema',
version='4.3.3.dev0',
url='http://pypi.python.org/pypi/zope.schema',
license='ZPL 2.1',
description='zope.interface extension for defining data schemas',
author='Zope Foundation and Contributors',
author_email='zope-dev@zope.org',
long_description=(read('README.rst') + '\n\n' + read('CHANGES.rst')),
packages=find_packages('src'),
package_dir = {'': 'src'},
namespace_packages=['zope', ],
#extras_require={'docs': ['z3c.recipe.sphinxdoc']},
install_requires=REQUIRES,
classifiers=[
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"License :: OSI Approved :: Zope Public License",
Expand All @@ -102,14 +109,14 @@ def emit(self, record):
"Programming Language :: Python :: Implementation :: PyPy",
"Framework :: Zope3",
"Topic :: Software Development :: Libraries :: Python Modules",
],
include_package_data = True,
zip_safe = False,
test_suite='__main__.alltests',
tests_require=TESTS_REQUIRE,
extras_require={
],
include_package_data = True,
zip_safe = False,
test_suite='__main__.alltests',
tests_require=TESTS_REQUIRE,
extras_require={
'docs': ['Sphinx'],
'test': TESTS_REQUIRE,
'testing': TESTS_REQUIRE + ['nose', 'coverage'],
},
},
)
23 changes: 17 additions & 6 deletions src/zope/schema/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,26 @@
from zope.schema._field import URI

# Schema APIs
from zope.schema._schema import getFields
from zope.schema._schema import getFieldsInOrder
from zope.schema._schema import getFieldNames
from zope.schema._schema import getFieldNamesInOrder
from zope.schema._schema import getValidationErrors
from zope.schema._schema import getSchemaValidationErrors
from zope.schema._schema import getFields
from zope.schema._schema import getFieldsInOrder
from zope.schema._schema import getFieldNames
from zope.schema._schema import getFieldNamesInOrder
from zope.schema._schema import getValidationErrors
from zope.schema._schema import getSchemaValidationErrors

# Acessor API
from zope.schema.accessors import accessors

# Error API
from zope.schema.interfaces import ValidationError


# pep 8 friendlyness
ASCII, ASCIILine, Bool, Bytes, BytesLine, Choice, Container, Date, Datetime
Decimal, Dict, DottedName, Field, Float, FrozenSet, Id, Int, InterfaceField
Iterable, List, MinMaxLen, NativeString, NativeStringLine, Object, Orderable
Password, Set, SourceText, Text, TextLine, Time, Timedelta, Tuple, URI
getFields, getFieldsInOrder, getFieldNames, getFieldNamesInOrder,
getValidationErrors, getSchemaValidationErrors
accessors
ValidationError
8 changes: 6 additions & 2 deletions src/zope/schema/_bootstrapfields.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,17 @@
from zope.schema._bootstrapinterfaces import TooSmall
from zope.schema._bootstrapinterfaces import WrongType
from zope.schema._compat import u
from zope.schema._compat import b # used in docstring doctests
from zope.schema._compat import b # used in docstring doctests
from zope.schema._compat import text_type
from zope.schema._compat import integer_types

from zope.schema._schema import getFields


# pep 8 friendlyness
b


class ValidatedProperty(object):

def __init__(self, name, check=None):
Expand Down Expand Up @@ -190,7 +194,7 @@ def __eq__(self, other):
return False

# should have the same properties
names = {} # used as set of property names, ignoring values
names = {} # used as set of property names, ignoring values
for interface in providedBy(self):
names.update(getFields(interface))

Expand Down
20 changes: 16 additions & 4 deletions src/zope/schema/_bootstrapinterfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@

from zope.schema._messageid import _


class StopValidation(Exception):
"""Raised if the validation is completed early.
Note that this exception should be always caught, since it is just
a way for the validator to save time.
"""


class ValidationError(zope.interface.Invalid):
"""Raised if the Validation process fails."""

Expand All @@ -40,39 +42,49 @@ def __eq__(self, other):
return False
return self.args == other.args

__hash__ = zope.interface.Invalid.__hash__ # python3
__hash__ = zope.interface.Invalid.__hash__ # python3

def __repr__(self): #pragma NO COVER
def __repr__(self): # pragma NO COVER
return '%s(%s)' % (self.__class__.__name__,
', '.join(repr(arg) for arg in self.args))
', '.join(repr(arg) for arg in self.args))


class RequiredMissing(ValidationError):
__doc__ = _("""Required input is missing.""")


class WrongType(ValidationError):
__doc__ = _("""Object is of wrong type.""")


class TooBig(ValidationError):
__doc__ = _("""Value is too big""")


class TooSmall(ValidationError):
__doc__ = _("""Value is too small""")


class TooLong(ValidationError):
__doc__ = _("""Value is too long""")


class TooShort(ValidationError):
__doc__ = _("""Value is too short""")


class InvalidValue(ValidationError):
__doc__ = _("""Invalid value""")


class ConstraintNotSatisfied(ValidationError):
__doc__ = _("""Constraint not satisfied""")


class NotAContainer(ValidationError):
__doc__ = _("""Not a container""")


class NotAnIterator(ValidationError):
__doc__ = _("""Not an iterator""")

Expand All @@ -83,13 +95,13 @@ class IFromUnicode(zope.interface.Interface):
We will often adapt fields to this interface to support views and
other applications that need to conver raw data as unicode
values.
"""

def fromUnicode(str):
"""Convert a unicode string to a value.
"""


class IContextAwareDefaultFactory(zope.interface.Interface):
"""A default factory that requires a context.
Expand Down
10 changes: 7 additions & 3 deletions src/zope/schema/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@

try:
from collections import OrderedDict
except ImportError: #pragma NO COVER
except ImportError: # pragma NO COVER
from ordereddict import OrderedDict

if PY3: #pragma NO COVER
# pep 8 friendlyness
OrderedDict


if PY3: # pragma NO COVER
import builtins
def b(s):
return s.encode("latin-1")
Expand All @@ -25,7 +29,7 @@ def make_binary(x):
if isinstance(x, bytes):
return x
return x.encode('ascii')
else: #pragma NO COVER
else: # pragma NO COVER
def b(s):
return s
def u(s):
Expand Down
Loading

0 comments on commit a7b65d6

Please sign in to comment.