Skip to content

Commit

Permalink
Fix when zope.schema is not installed.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamadden committed Jul 23, 2019
1 parent 71d7980 commit 280038f
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/relstorage/adapters/interfaces.py
Expand Up @@ -24,31 +24,34 @@

try:
from zope.schema import Tuple
from zope.schema import Field
from zope.schema import Object
from zope.interface.common.interfaces import IException
except ImportError: # pragma: no cover
# We have nti.testing -> zope.schema as a test dependency; but we
# don't have it as a hard-coded runtime dependency because we
# don't want to force a version on consumers of RelStorage.
def Tuple(description='', **_kw):
return Attribute(description)
def Tuple(*_args, **kwargs):
return Attribute(kwargs['description'])

Object = Tuple

def Factory(schema, description='', **_kw):
return Attribute(description + " (Must implement %s)" % schema)

IException = Interface
else:
from zope.schema.interfaces import SchemaNotProvided
class Factory(Field):
from zope.schema.interfaces import SchemaNotProvided as _SchemaNotProvided
from zope.schema import Field as _Field

class Factory(_Field):
def __init__(self, schema, **kw):
self.schema = schema
Field.__init__(self, **kw)
_Field.__init__(self, **kw)

def _validate(self, value):
super(Factory, self)._validate(value)
if not self.schema.implementedBy(value):
raise SchemaNotProvided(self.schema, value).with_field_and_value(self, value)
raise _SchemaNotProvided(self.schema, value).with_field_and_value(self, value)



Expand Down

0 comments on commit 280038f

Please sign in to comment.