Exemplo n.º 1
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.º 2
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.º 3
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.º 4
0
 def test_map(self):
     a = fields.Map(fields.Object(Piwo), fields.Object(Zlew))
     a.validate({})
     a.validate({Piwo(): Zlew()})
     with self.assertRaises(SchemaError):
         a.validate(Piwo())
     with self.assertRaises(SchemaError):
         a.validate(Zlew())
     with self.assertRaises(SchemaError):
         a.validate([])
     with self.assertRaises(SchemaError):
         a.validate(None)
     with self.assertRaises(SchemaError):
         a.validate({Piwo(): Piwo()})
     with self.assertRaises(SchemaError):
         a.validate({Zlew(): Zlew()})
     with self.assertRaises(SchemaError):
         a.validate({Zlew(): Piwo()})
     with self.assertRaises(SchemaError):
         a.validate({Piwo(): None})
     with self.assertRaises(SchemaError):
         a.validate({None: Zlew()})
     self.assertEqual(a.load({}), {})
     self.assertEqual(a.load({'piwo': 'zlew'}), {Piwo(): Zlew()})
     with self.assertRaises(SchemaError):
         a.validate(a.load([]))
     with self.assertRaises(SchemaError):
         a.validate(a.load(None))
     with self.assertRaises(SchemaError):
         a.validate(a.load('piwo'))
     with self.assertRaises(SchemaError):
         a.validate(a.load({'piwo': 'piwo'}))
     with self.assertRaises(SchemaError):
         a.validate(a.load({'piwo', 'zlew'}))
     self.assertEqual(a.dump({}), {})
     self.assertEqual(a.dump({Piwo(): Zlew()}), {'piwo': 'zlew'})
     fields.Map(fields.Integer(), fields.String(), default={1: 'a'})
Exemplo n.º 5
0
class MapOptional(model.Model):
    a = fields.Map(fields.String(),
                   fields.SmallInteger(),
                   optional=True,
                   default=None)
Exemplo n.º 6
0
class Map(model.Model):
    a = fields.Map(fields.String(), fields.SmallInteger())
Exemplo n.º 7
0
class Zlew(Model):
    b = fields.List(fields.Map(fields.String(), fields.BinData()))