Exemplo n.º 1
0
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())
Exemplo n.º 2
0
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))
Exemplo n.º 3
0
class MsgBroadcastResult(MsgpackMsg):
    """
    Sent by the server in reply to MsgBroadcastRun.
    """

    object_type = 'broadcast_result'

    bid = fields.SmallUnsignedInteger()
    results = fields.List(fields.Any(optional=True))
Exemplo n.º 4
0
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)
Exemplo n.º 5
0
class MsgGetDataReply(MsgpackMsg):
    """
    Sent by server in reply to MsgGetData.
    """

    object_type = 'get_data_reply'

    qid = fields.SmallUnsignedInteger()
    data = fields.Any(optional=True)
Exemplo n.º 6
0
class MsgPluginMethodResult(MsgpackMsg):
    """
    Sent by the client in reply to MsgPluginMethodRun.
    """

    object_type = 'plugin_method_result'

    pmid = fields.SmallUnsignedInteger()
    result = fields.Any(optional=True)
Exemplo n.º 7
0
class MsgPluginBroadcastResult(MsgpackMsg):
    """
    Sent by the client in reply to MsgPluginBroadcastRun.
    """

    object_type = 'plugin_broadcast_result'

    pbid = fields.SmallUnsignedInteger()
    results = fields.List(fields.Any(optional=True))
Exemplo n.º 8
0
class MsgMethodResult(MsgpackMsg):
    """
    Sent by the server in reply to MsgMethodRun.
    """

    object_type = 'method_result'

    mid = fields.SmallUnsignedInteger()
    result = fields.Any(optional=True)
Exemplo n.º 9
0
class MsgPluginQueryResult(MsgpackMsg):
    """
    Sent by the client in reply to MsgPluginQueryGet.
    """

    object_type = 'plugin_query_result'

    pqid = fields.SmallUnsignedInteger()
    result = fields.Any(optional=True)
    checks = fields.List(fields.Object(Check))
Exemplo n.º 10
0
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())
Exemplo n.º 11
0
class MsgBroadcastRun(MsgpackMsg):
    """
    Sent by the client to request running a given broadcast.
    ``bid`` is an arbitrary number selected by the client to associate
    replies to this request.
    """

    object_type = 'broadcast_run'

    bid = fields.SmallUnsignedInteger()
    broadcast = fields.String()
    params = fields.Any(optional=True)
Exemplo n.º 12
0
    def test_field(self):
        a = fields.Any(default='zlew')
        a.__set_name__(None, 'a')
        self.assertEqual(a.name, 'a')
        a.validate(1234)
        a.validate({})
        with self.assertRaises(SchemaError):
            a.validate(None)
        tv = {
            'a': 123,
            'b': 'c',
        }
        self.assertEqual(a.dump(tv), tv)
        self.assertEqual(a.load(tv), tv)
        with self.assertRaises(SchemaError):
            a.load(None)

        with self.assertRaises(TypeError):
            fields.Any(optional='zlew')
        with self.assertRaises(ValueError):
            a = fields.Any(optional=True, default='zlew')
Exemplo n.º 13
0
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)
Exemplo n.º 14
0
class MsgPluginBroadcastRun(MsgpackMsg):
    """
    Sent by the server to a plugin client to request running a broadcast.
    ``pbid`` is chosen arbitrarily by the server to match replies to
    requests, ``phid`` is the id of the broadcast handler registered by
    the client earlier.
    """

    object_type = 'plugin_broadcast_run'

    pbid = fields.SmallUnsignedInteger()
    phid = fields.SmallUnsignedInteger()
    params = fields.Any(optional=True)
Exemplo n.º 15
0
class MsgPluginQueryGet(MsgpackMsg):
    """
    Sent by the server to a plugin client to request running a query.
    ``pqid`` is chosen arbitrarily by the server to match replies to
    requests, ``phid`` is the id of the handler registered by the client
    earlier.
    """

    object_type = 'plugin_query_get'

    pqid = fields.SmallUnsignedInteger()
    phid = fields.SmallUnsignedInteger()
    node = fields.Object(Node)
    params = fields.Any(optional=True)
Exemplo n.º 16
0
class MsgPluginMethodRun(MsgpackMsg):
    """
    Sent by the server to a plugin client to request running a method.
    ``pmid`` is chosen arbitrarily by the server to match replies to
    requests, ``phid`` is the id of the method handler registered by the client
    earlier.
    """

    object_type = 'plugin_method_run'

    pmid = fields.SmallUnsignedInteger()
    phid = fields.SmallUnsignedInteger()
    node = fields.Object(Node)
    params = fields.Any(optional=True)
Exemplo n.º 17
0
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)
Exemplo n.º 18
0
class CheckData(Check):
    object_type = 'data'

    node = fields.NodeID()
    key = fields.String()
    data = fields.Any(optional=True)
Exemplo n.º 19
0
class CheckAttr(Check):
    object_type = 'attr'

    node = fields.NodeID()
    key = fields.String()
    data = fields.Any(optional=True)
Exemplo n.º 20
0
class AnyOptional(model.Model):
    a = fields.Any(optional=True)
Exemplo n.º 21
0
class OperationSetAttr(Operation):
    object_type = 'set_attr'

    key = fields.String()
    data = fields.Any(optional=True)
Exemplo n.º 22
0
class OperationSetData(Operation):
    object_type = 'set_data'

    key = fields.String()
    data = fields.Any(optional=True)
Exemplo n.º 23
0
class MsgGetQueryReply(MsgpackMsg):
    object_type = 'get_query_reply'

    qid = fields.SmallUnsignedInteger()
    result = fields.Any(optional=True)
    checks = fields.List(fields.Object(Check))
Exemplo n.º 24
0
class Any(model.Model):
    a = fields.Any()