~lazr-developers/lazr.restful/trunk

« back to all changes in this revision

Viewing changes to src/lazr/restful/fields.py

  • Committer: Colin Watson
  • Date: 2016-02-17 01:07:21 UTC
  • Revision ID: cjwatson@canonical.com-20160217010721-4d5fqqml5q97ss59
Switch zope.interface, zope.component, and lazr.delegates users from class advice to class decorators.

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
    'ReferenceChoice',
10
10
    ]
11
11
 
12
 
from zope.interface import implements
 
12
from zope.interface import implementer
13
13
from zope.schema import Choice, Field, Object
14
14
from zope.schema.interfaces import IObject, SchemaNotProvided
15
15
from zope.schema._field import AbstractCollection
18
18
    ICollectionField, IReference, IReferenceChoice)
19
19
 
20
20
 
 
21
@implementer(ICollectionField)
21
22
class CollectionField(AbstractCollection):
22
23
    """A collection associated with an entry."""
23
24
    # We subclass AbstractCollection instead of List because List
24
25
    # has a _type of list, and we don't want to have to implement list
25
26
    # semantics for this class.
26
 
    implements(ICollectionField)
27
27
 
28
28
    def __init__(self, *args, **kwargs):
29
29
        """A generic collection field.
36
36
        super(CollectionField, self).__init__(*args, **kwargs)
37
37
 
38
38
 
 
39
@implementer(IReference)
39
40
class Reference(Object):
40
41
    """An Object-like field which doesn't validate all fields of the schema.
41
42
 
44
45
    the Field class and then check that the given value provides the specified
45
46
    schema.
46
47
    """
47
 
    implements(IReference)
48
48
 
49
49
    def _validate(self, value):
50
50
        Field._validate(self, value)
52
52
            raise SchemaNotProvided()
53
53
 
54
54
 
 
55
@implementer(IReferenceChoice)
55
56
class ReferenceChoice(Choice):
56
57
    """A choice among objects."""
57
 
    implements(IReferenceChoice)
58
58
 
59
59
    def __init__(self, *args, **kwargs):
60
60
        """Initialize a choice among a certain kind of object.