コード例 #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
ファイル: messages.py プロジェクト: yuttasakcom/veles
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
ファイル: messages.py プロジェクト: yuttasakcom/veles
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
ファイル: messages.py プロジェクト: yuttasakcom/veles
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
ファイル: messages.py プロジェクト: yuttasakcom/veles
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
ファイル: messages.py プロジェクト: yuttasakcom/veles
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
ファイル: check.py プロジェクト: yuttasakcom/veles
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
ファイル: messages.py プロジェクト: yuttasakcom/veles
class MsgConnectionError(MsgpackMsg):
    """
    Sent by the server in reply to MsgConnect.
    """

    object_type = 'connection_error'

    err = fields.Object(VelesException)
コード例 #12
0
ファイル: messages.py プロジェクト: yuttasakcom/veles
class MsgProtoError(MsgpackMsg):
    """
    Sent by the server in reply to a malformed packet.
    """

    object_type = 'proto_error'

    err = fields.Object(VelesException)
コード例 #13
0
ファイル: messages.py プロジェクト: yuttasakcom/veles
class MsgGetReply(MsgpackMsg):
    """
    Sent by server in reply to MsgGet.
    """

    object_type = 'get_reply'

    qid = fields.SmallUnsignedInteger()
    obj = fields.Object(Node)
コード例 #14
0
ファイル: messages.py プロジェクト: yuttasakcom/veles
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
ファイル: messages.py プロジェクト: yuttasakcom/veles
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
ファイル: messages.py プロジェクト: yuttasakcom/veles
class MsgMethodError(MsgpackMsg):
    """
    Sent by the server in reply to MsgMethodRun.
    """

    object_type = 'method_error'

    mid = fields.SmallUnsignedInteger()
    err = fields.Object(VelesException)
コード例 #17
0
ファイル: messages.py プロジェクト: yuttasakcom/veles
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
ファイル: messages.py プロジェクト: yuttasakcom/veles
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
ファイル: messages.py プロジェクト: yuttasakcom/veles
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
ファイル: messages.py プロジェクト: yuttasakcom/veles
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
ファイル: messages.py プロジェクト: yuttasakcom/veles
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
ファイル: messages.py プロジェクト: yuttasakcom/veles
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
ファイル: test_polymodel.py プロジェクト: yuttasakcom/veles
class PietroZlew(WieloZlew):
    object_type = 'pietrozlew'
    pietra = fields.List(fields.Object(BaseZlew))
コード例 #27
0
class Object(model.Model):
    a = fields.Object(String)
コード例 #28
0
ファイル: messages.py プロジェクト: yuttasakcom/veles
class MsgGetQueryReply(MsgpackMsg):
    object_type = 'get_query_reply'

    qid = fields.SmallUnsignedInteger()
    result = fields.Any(optional=True)
    checks = fields.List(fields.Object(Check))
コード例 #29
0
ファイル: test_polymodel.py プロジェクト: yuttasakcom/veles
class DwuZlew(WieloZlew):
    object_type = 'dwuzlew'
    lewy = fields.Object(Zlew)
    prawy = fields.Object(Zlew)
コード例 #30
0
ファイル: messages.py プロジェクト: yuttasakcom/veles
class MsgConnectionsReply(MsgpackMsg):
    object_type = 'connections_reply'

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