Opened 18 years ago
#86 new defect
add Constraint for Copyables
| Reported by: | Brian Warner | Owned by: | |
|---|---|---|---|
| Priority: | major | Milestone: | undecided |
| Component: | schemas | Version: | 0.3.0 |
| Keywords: | Cc: |
Description
As Marco Giusti noted on the twisted-dev mailing list, we don't currently have a Constraint that means "I expect a Copyable of type X". There's the attrdict constraint, but that's for use by a RemoteCopy to describe which attributes are expected to be provided: it's one level lower than what we want.
The desired syntax for this is just to use the Copyable class inside the constraint:
class Label(Copyable):
typeToCopy = "label.example.com"
def __init__(self, text):
self.text = text
class CopiedLabel(RemoteCopy):
copytype = "label.example.com"
stateSchema = AttributeDictConstraint( ("text", str) )
class IFoo(RemoteInterface):
def getLabel():
return Label
To do this, we need:
- create a CopyableConstraint class, inheriting from constraint.Constraint,
and created with a Copyable subclass (or maybe a RemoteCopy subclass)
- implement CopyableConstraint.checkObject(), somehow. If inbound=False then it should probably assert an isinstance(obj, myCopyableClass). If inbound=True, it should probably check against myRemoteCopyClass instead. checkObject() is used outbound before serialization, and inbound post-deserialization; i.e. it examines fully-formed objects rather than individual tokens.
- add code to schema.adapt_obj_to_iconstraint() (or register an adapter) that knows how to create a CopyableConstraint from a Copyable or RemoteCopy class.
Note: See
TracTickets for help on using
tickets.
