class CheckList(Check): object_type = 'list' parent = fields.NodeID() tags = fields.Set(fields.String()) pos_filter = fields.Object(PosFilter) nodes = fields.Set(fields.NodeID())
class Node(model.Model): """ Stores the lightweight data associated with a node, and an index of heavy data (which has to be downloaded separately). This includes: - ``id``: self-descriptive. The ID of a node cannot be changed. - ``parent``: the node parent's ID. - ``pos_start`` and ``pos_end``: for nodes where it makes sense (mostly chunka), the range of positions occupied by this object. ``pos_start`` is inclusive, while ``pos_end`` is exclusive. - ``tags``: an unordered set of tags, which are simple strings. - ``attr``: a string-keyed dict of attributes with arbitrary data. - ``data``: an unordered set of keys with non-null heavyweight data. The data has to be downloaded separately. - ``bindata``: a dict with an index of available bindata. The keys in this dict correspond to bindata keys, and the values are size of the corresponding binary data in bytes. The actual bindata has to be downloaded separately. - ``triggers``: a dict containing active triggers for the given node. The keys are trigger names, and they are mapped to the state of the given trigger. """ id = fields.NodeID() parent = fields.NodeID(default=NodeID.root_id) pos_start = fields.Integer(optional=True) pos_end = fields.Integer(optional=True) tags = fields.Set(fields.String()) attr = fields.Map(fields.String(), fields.Any()) data = fields.Set(fields.String()) bindata = fields.Map(fields.String(), fields.SmallUnsignedInteger()) triggers = fields.Map(fields.String(), fields.Enum(TriggerState))
class MsgSetParent(MsgpackMsg): """ Changes the parent of a given node. It is an error if new parent is a child of the given node. Server replies with MsgRequestAck or MsgRequestError. """ object_type = 'set_parent' rid = fields.SmallUnsignedInteger() id = fields.NodeID() parent = fields.NodeID(default=NodeID.root_id)
class MsgGetList(MsgpackMsg): """ Sent by client, requests a list of children of the given node matching the given filters. Children can be filtered by tags (the set of tags in the query must be a subset of the node's tags for it to match) and by a position filter. If sub is False, server will reply with a single MsgGetListReply with gone=[], or with a single MsgQueryError. If sub is True, the first reply will be like for sub=False, but subsequent replies will only mention changed nodes - nodes that are new on the list, along with changed nodes remaining on the list are sent in the objs field of the reply, while the IDs of nodes no longer on the list are sent in the gone field of the reply. The list may fail with ObjectGoneError if the parent node is gone. If it reappears in the future, a MsgGetListReply will be sent with a complete list of children. """ object_type = 'get_list' qid = fields.SmallUnsignedInteger() parent = fields.NodeID(default=NodeID.root_id) tags = fields.Set(fields.String()) pos_filter = fields.Object(PosFilter, default=PosFilter()) sub = fields.Boolean(default=False)
class CheckBinData(Check): object_type = 'bindata' node = fields.NodeID() key = fields.String() start = fields.SmallUnsignedInteger() end = fields.SmallUnsignedInteger(optional=True) data = fields.Binary()
class MsgGetQuery(MsgpackMsg): object_type = 'get_query' qid = fields.SmallUnsignedInteger() node = fields.NodeID() query = fields.String() params = fields.Any(optional=True) trace = fields.Boolean(default=False) sub = fields.Boolean(default=False)
class MsgGetListReply(MsgpackMsg): """ Sent by server in reply to MsgGetList. """ object_type = 'get_list_reply' qid = fields.SmallUnsignedInteger() objs = fields.List(fields.Object(Node)) gone = fields.List(fields.NodeID())
class OperationCreate(Operation): object_type = 'create' parent = fields.NodeID(default=NodeID.root_id) pos_start = fields.Integer(optional=True) pos_end = fields.Integer(optional=True) tags = fields.Set(fields.String()) attr = fields.Map(fields.String(), fields.Any()) data = fields.Map(fields.String(), fields.Any()) bindata = fields.Map(fields.String(), fields.Binary()) triggers = fields.Set(fields.String())
class MsgCreate(MsgpackMsg): """ Creates a node on the server. It is an error if a node with given id already exists. Server replies with MsgRequestAck or MsgRequestError. Replies are matched to requests by ``rid``, which is assigned by the client. """ object_type = 'create' rid = fields.SmallUnsignedInteger() id = fields.NodeID() parent = fields.NodeID(default=NodeID.root_id) pos_start = fields.Integer(optional=True) pos_end = fields.Integer(optional=True) tags = fields.Set(fields.String()) attr = fields.Map(fields.String(), fields.Any()) data = fields.Map(fields.String(), fields.Any()) bindata = fields.Map(fields.String(), fields.Binary()) triggers = fields.Set(fields.String())
class MsgDelTag(MsgpackMsg): """ Removes a tag from a given node. Server replies with MsgRequestAck or MsgRequestError. If the node doesn't have the given tag, nothing happens. """ object_type = 'del_tag' rid = fields.SmallUnsignedInteger() id = fields.NodeID() tag = fields.String()
class MsgAddTag(MsgpackMsg): """ Adds a tag to a given node. Server replies with MsgRequestAck or MsgRequestError. If the node already has the given tag, nothing happens. """ object_type = 'add_tag' rid = fields.SmallUnsignedInteger() id = fields.NodeID() tag = fields.String()
class MsgSetPos(MsgpackMsg): """ Changes the position of a given node. Server replies with MsgRequestAck or MsgRequestError. """ object_type = 'set_pos' rid = fields.SmallUnsignedInteger() id = fields.NodeID() pos_start = fields.Integer(optional=True) pos_end = fields.Integer(optional=True)
class MsgDelete(MsgpackMsg): """ Deletes the node with a given ID, along with all of its children (recursively). It is not an error if the node doesn't exist (nothing is done in this case). Server replies with MsgRequestAck or MsgRequestError. """ object_type = 'delete' rid = fields.SmallUnsignedInteger() id = fields.NodeID()
class MsgGetData(MsgpackMsg): """ Sent by client, requests the data associated with the given node and key. Works like MsgGet, but replies with MsgGetData. It is not an error if a key doesn't exist - None will be returned in this case. """ object_type = 'get_data' qid = fields.SmallUnsignedInteger() id = fields.NodeID() key = fields.String() sub = fields.Boolean(default=False)
class MsgMethodRun(MsgpackMsg): """ Sent by the client to request running a given method on a given object. ``mid`` is an arbitrary number selected by the client to associate replies to this request. """ object_type = 'method_run' mid = fields.SmallUnsignedInteger() node = fields.NodeID() method = fields.String() params = fields.Any(optional=True)
def test_nodeid(self): a = fields.NodeID() id = NodeID() a.validate(id) with self.assertRaises(SchemaError): a.validate(b'abcd') with self.assertRaises(SchemaError): a.validate(1234) self.assertEqual(a.dump(id), id) self.assertEqual(a.load(id), id) with self.assertRaises(SchemaError): a.load(b'abcd') with self.assertRaises(SchemaError): a.load(1234)
class MsgSetData(MsgpackMsg): """ Sets a data value on a given node. Server replies with MsgRequestAck or MsgRequestError. Setting a data value to None is equivalent to deleting it. """ object_type = 'set_data' rid = fields.SmallUnsignedInteger() id = fields.NodeID() key = fields.String() data = fields.Any(optional=True)
class MsgGet(MsgpackMsg): """ Sent by the client to request information about the given node. If sub is True, a subscription is established - the server will send a MsgGetReply (or MsgQueryError) immediately, then send it again every time any part of the reply changes, until a MsgCancelSubscription is received. If sub is False, only one reply will be sent. The replies are matched with queries via ``qid``, which are assigned by the client. It's an error to send a query with a ``qid`` that is already in use for an active subscription. """ object_type = 'get' qid = fields.SmallUnsignedInteger() id = fields.NodeID() sub = fields.Boolean(default=False)
class MsgGetBinData(MsgpackMsg): """ Sent by client, requests a range of bindata associated with the given node and key. Works like MsgGet, but replies with MsgGetBinData. The range is left-inclusive and right-exclusive. It is not an error if the key doesn't exist - empty bytestring will be returned in this case. It is also not an error if the range is out of bounds for the bindata - it will be truncated if it's partially in range, or an empty bytestring will be returned if it's completely out of range. """ object_type = 'get_bindata' qid = fields.SmallUnsignedInteger() id = fields.NodeID() key = fields.String() start = fields.SmallUnsignedInteger() end = fields.SmallUnsignedInteger(optional=True) sub = fields.Boolean(default=False)
class MsgSetBinData(MsgpackMsg): """ Sets a range of bindata on a given node. Server replies with MsgRequestAck or MsgRequestError. The bindata is modified starting from a given start position - it is an error if the position is after the current end of bindata (but not if it's equal). The bindata is expanded if necessary to hold the new data. If truncate is set, the bindata is truncated after the end of the new data. If bindata would become 0-length, it is deleted. """ object_type = 'set_bindata' rid = fields.SmallUnsignedInteger() id = fields.NodeID() key = fields.String() start = fields.SmallUnsignedInteger(default=0) data = fields.Binary() truncate = fields.Boolean(default=False)
class CheckTrigger(Check): object_type = 'trigger' node = fields.NodeID() key = fields.String() state = fields.Enum(TriggerState, optional=True)
class OperationSetParent(Operation): object_type = 'set_parent' parent = fields.NodeID(default=NodeID.root_id)
class CheckBinDataSize(Check): object_type = 'bindata_size' node = fields.NodeID() key = fields.String() size = fields.SmallUnsignedInteger()
class CheckData(Check): object_type = 'data' node = fields.NodeID() key = fields.String() data = fields.Any(optional=True)
class CheckAttr(Check): object_type = 'attr' node = fields.NodeID() key = fields.String() data = fields.Any(optional=True)
class CheckTag(Check): object_type = 'tag' node = fields.NodeID() tag = fields.String() present = fields.Boolean()
class CheckTags(Check): object_type = 'tags' node = fields.NodeID() tags = fields.Set(fields.String())
class CheckPos(Check): object_type = 'pos' node = fields.NodeID() pos_start = fields.Integer(optional=True) pos_end = fields.Integer(optional=True)
class CheckParent(Check): object_type = 'parent' node = fields.NodeID() parent = fields.NodeID()
class CheckGone(Check): object_type = 'gone' node = fields.NodeID()