Пример #1
0
    def test_object(self):
        a = fields.Object(Piwo, optional=True)
        a.validate(None)
        a.validate(Piwo())
        with self.assertRaises(SchemaError):
            a.validate('piwo')
        with self.assertRaises(SchemaError):
            a.validate(Zlew())
        self.assertIsInstance(a.load('piwo'), Piwo)
        with self.assertRaises(SchemaError):
            a.load('zlew')
        self.assertEqual(a.load(None), None)
        self.assertEqual(a.dump(Piwo()), 'piwo')
        self.assertEqual(a.dump(None), None)

        a = fields.Object(Zlew)
        a.validate(Zlew())
        with self.assertRaises(SchemaError):
            a.validate('zlew')
        with self.assertRaises(SchemaError):
            a.validate(Piwo())
        with self.assertRaises(SchemaError):
            a.validate(None)
        self.assertIsInstance(a.load('zlew'), Zlew)
        with self.assertRaises(SchemaError):
            a.load('piwo')
        with self.assertRaises(SchemaError):
            a.load(None)
        self.assertEqual(a.dump(Zlew()), 'zlew')

        fields.Object(Zlew, default=Zlew())
        with self.assertRaises(SchemaError):
            fields.Object(Zlew, default=Piwo())
Пример #2
0
class ChunkDataItemField(ChunkDataItem):
    pos_start = fields.Integer()
    pos_end = fields.Integer()
    name = fields.String()
    repack = fields.Object(Repacker)
    num_elements = fields.SmallUnsignedInteger()
    type = fields.Object(FieldType)
    raw_value = fields.BinData()
Пример #3
0
class MsgPluginQueryError(MsgpackMsg):
    """
    Sent by the client in reply to MsgPluginQueryGet.
    """

    object_type = 'plugin_query_error'

    pqid = fields.SmallUnsignedInteger()
    err = fields.Object(VelesException)
    checks = fields.List(fields.Object(Check))
Пример #4
0
class MsgPluginTriggerError(MsgpackMsg):
    """
    Sent by the client in reply to MsgPluginTriggerRun.
    """

    object_type = 'plugin_trigger_error'

    ptid = fields.SmallUnsignedInteger()
    err = fields.Object(VelesException)
    checks = fields.List(fields.Object(Check))
Пример #5
0
class MsgQueryError(MsgpackMsg):
    """
    Sent by the server in reply to MsgGet*.  Note that receiving this doesn't
    kill the subscription - a successful reply may be sent later if
    the situation improves.
    """

    object_type = 'query_error'

    qid = fields.SmallUnsignedInteger()
    err = fields.Object(VelesException)
    checks = fields.List(fields.Object(Check))
Пример #6
0
class MsgTransaction(MsgpackMsg):
    """
    Sent by the client to request a list of database-modifying operations.
    The operations are executed atomically, and only if the attached checks
    are still valid.
    """

    object_type = 'transaction'

    rid = fields.SmallUnsignedInteger()
    checks = fields.List(fields.Object(Check))
    operations = fields.List(fields.Object(Operation))
Пример #7
0
 def test_list(self):
     a = fields.List(fields.Object(Piwo))
     a.validate([])
     a.validate([Piwo()])
     a.validate([Piwo(), Piwo(), Piwo()])
     with self.assertRaises(SchemaError):
         a.validate(Piwo())
     with self.assertRaises(SchemaError):
         a.validate(set())
     with self.assertRaises(SchemaError):
         a.validate(None)
     with self.assertRaises(SchemaError):
         a.validate([Piwo(), Zlew(), Piwo()])
     with self.assertRaises(SchemaError):
         a.validate([Piwo(), None])
     self.assertEqual(a.load([]), [])
     self.assertEqual(a.load(['piwo', 'piwo']), [Piwo(), Piwo()])
     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(['zlew']))
     with self.assertRaises(SchemaError):
         a.validate(a.load(['piwo', None]))
     self.assertEqual(a.dump([]), [])
     self.assertEqual(a.dump([Piwo(), Piwo()]), ['piwo', 'piwo'])
     fields.List(fields.Integer(), default=[1, 2, 3])
Пример #8
0
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)
Пример #9
0
 def test_set(self):
     a = fields.Set(fields.Object(Piwo))
     a.validate(set())
     a.validate({Piwo()})
     with self.assertRaises(SchemaError):
         a.validate(Piwo())
     with self.assertRaises(SchemaError):
         a.validate([])
     with self.assertRaises(SchemaError):
         a.validate(None)
     with self.assertRaises(SchemaError):
         a.validate({Piwo(), Zlew()})
     with self.assertRaises(SchemaError):
         a.validate({Piwo(), None})
     self.assertEqual(a.load([]), set())
     self.assertEqual(a.load(['piwo']), {Piwo()})
     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(['zlew']))
     with self.assertRaises(SchemaError):
         a.validate(a.load(['piwo', None]))
     self.assertEqual(a.dump({}), [])
     self.assertEqual(a.dump({Piwo()}), ['piwo'])
     fields.Set(fields.Integer(), default={1, 2, 3})
Пример #10
0
class CheckList(Check):
    object_type = 'list'

    parent = fields.NodeID()
    tags = fields.Set(fields.String())
    pos_filter = fields.Object(PosFilter)
    nodes = fields.Set(fields.NodeID())
Пример #11
0
class MsgConnectionError(MsgpackMsg):
    """
    Sent by the server in reply to MsgConnect.
    """

    object_type = 'connection_error'

    err = fields.Object(VelesException)
Пример #12
0
class MsgProtoError(MsgpackMsg):
    """
    Sent by the server in reply to a malformed packet.
    """

    object_type = 'proto_error'

    err = fields.Object(VelesException)
Пример #13
0
class MsgGetReply(MsgpackMsg):
    """
    Sent by server in reply to MsgGet.
    """

    object_type = 'get_reply'

    qid = fields.SmallUnsignedInteger()
    obj = fields.Object(Node)
Пример #14
0
class MsgRequestError(MsgpackMsg):
    """
    Sent by the server in reply to modification requests.
    """

    object_type = 'request_error'

    rid = fields.SmallUnsignedInteger()
    err = fields.Object(VelesException)
Пример #15
0
class MsgPluginTriggerDone(MsgpackMsg):
    """
    Sent by the client in reply to MsgPluginTriggerRun.
    """

    object_type = 'plugin_trigger_done'

    ptid = fields.SmallUnsignedInteger()
    checks = fields.List(fields.Object(Check))
Пример #16
0
class MsgMethodError(MsgpackMsg):
    """
    Sent by the server in reply to MsgMethodRun.
    """

    object_type = 'method_error'

    mid = fields.SmallUnsignedInteger()
    err = fields.Object(VelesException)
Пример #17
0
class MsgPluginMethodError(MsgpackMsg):
    """
    Sent by the client in reply to MsgPluginMethodRun.
    """

    object_type = 'plugin_method_error'

    pmid = fields.SmallUnsignedInteger()
    err = fields.Object(VelesException)
Пример #18
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))
Пример #19
0
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())
Пример #20
0
class MsgPluginTriggerRun(MsgpackMsg):
    """
    Sent by the server to a plugin client to request running a trigger.
    ``ptid`` is chosen arbitrarily by the server to match replies to
    requests, ``phid`` is the id of the trigger handler registered by
    the client earlier.
    """

    object_type = 'plugin_trigger_run'

    ptid = fields.SmallUnsignedInteger()
    phid = fields.SmallUnsignedInteger()
    node = fields.Object(Node)
Пример #21
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)
Пример #22
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)
Пример #23
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'})
Пример #24
0
 def test_exception(self):
     a = fields.Object(VelesException)
     a.validate(VelesException('abc', 'def'))
     a.validate(SchemaError())
     with self.assertRaises(SchemaError):
         a.validate('zlew')
     with self.assertRaises(SchemaError):
         a.validate(Exception())
     de = a.dump(VelesException('abc', 'def'))
     self.assertEqual(de, {
         'type': 'abc',
         'message': 'def',
     })
     for k, v in de.items():
         self.assertIsInstance(k, six.text_type)
         self.assertIsInstance(v, six.text_type)
     de = a.dump(SchemaError())
     self.assertEqual(de, {
         'type': 'schema_error',
         'message': SchemaError.msg,
     })
     for k, v in de.items():
         self.assertIsInstance(k, six.text_type)
         self.assertIsInstance(v, six.text_type)
     exc = a.load({
         'type': 'abc',
         'message': 'def',
     })
     self.assertIs(type(exc), VelesException)
     self.assertEqual(exc.code, 'abc')
     self.assertEqual(exc.msg, 'def')
     exc = a.load({
         'type': 'schema_error',
         'message': 'ghi',
     })
     self.assertIs(type(exc), SchemaError)
     self.assertEqual(exc.code, 'schema_error')
     self.assertEqual(exc.msg, 'ghi')
     with self.assertRaises(SchemaError):
         a.load([])
     with self.assertRaises(SchemaError):
         a.load({})
     with self.assertRaises(SchemaError):
         a.load({'type': 'abc', 'message': 'def', 'hgw': 'zlew'})
     with self.assertRaises(SchemaError):
         a.load({'type': b'zlew', 'message': 'def'})
     with self.assertRaises(SchemaError):
         a.load({'type': 'zlew', 'message': b'def'})
Пример #25
0
class ObjectOptional(model.Model):
    a = fields.Object(String, optional=True)
Пример #26
0
class PietroZlew(WieloZlew):
    object_type = 'pietrozlew'
    pietra = fields.List(fields.Object(BaseZlew))
Пример #27
0
class Object(model.Model):
    a = fields.Object(String)
Пример #28
0
class MsgGetQueryReply(MsgpackMsg):
    object_type = 'get_query_reply'

    qid = fields.SmallUnsignedInteger()
    result = fields.Any(optional=True)
    checks = fields.List(fields.Object(Check))
Пример #29
0
class DwuZlew(WieloZlew):
    object_type = 'dwuzlew'
    lewy = fields.Object(Zlew)
    prawy = fields.Object(Zlew)
Пример #30
0
class MsgConnectionsReply(MsgpackMsg):
    object_type = 'connections_reply'

    qid = fields.SmallUnsignedInteger()
    connections = fields.List(fields.Object(Connection))