Ejemplo n.º 1
0
 def serialize_safe(cls, items):
     subtype, = cls.subtypes
     buf = StringIO()
     buf.write(uint16_pack(len(items)))
     for item in items:
         itembytes = subtype.to_binary(item)
         buf.write(uint16_pack(len(itembytes)))
         buf.write(itembytes)
     return buf.getvalue()
Ejemplo n.º 2
0
    def serialize_safe(cls, items):
        if isinstance(items, basestring):
            raise TypeError("Received a string for a type that expects a sequence")

        subtype, = cls.subtypes
        buf = StringIO()
        buf.write(uint16_pack(len(items)))
        for item in items:
            itembytes = subtype.to_binary(item)
            buf.write(uint16_pack(len(itembytes)))
            buf.write(itembytes)
        return buf.getvalue()
Ejemplo n.º 3
0
 def serialize_safe(cls, themap):
     subkeytype, subvaltype = cls.subtypes
     buf = StringIO()
     buf.write(uint16_pack(len(themap)))
     for key, val in themap.iteritems():
         keybytes = subkeytype.to_binary(key)
         valbytes = subvaltype.to_binary(val)
         buf.write(uint16_pack(len(keybytes)))
         buf.write(keybytes)
         buf.write(uint16_pack(len(valbytes)))
         buf.write(valbytes)
     return buf.getvalue()
Ejemplo n.º 4
0
    def serialize_safe(cls, items):
        if isinstance(items, basestring):
            raise TypeError(
                "Received a string for a type that expects a sequence")

        subtype, = cls.subtypes
        buf = StringIO()
        buf.write(uint16_pack(len(items)))
        for item in items:
            itembytes = subtype.to_binary(item)
            buf.write(uint16_pack(len(itembytes)))
            buf.write(itembytes)
        return buf.getvalue()
Ejemplo n.º 5
0
 def serialize_safe(cls, themap):
     subkeytype, subvaltype = cls.subtypes
     buf = StringIO()
     buf.write(uint16_pack(len(themap)))
     try:
         items = themap.iteritems()
     except AttributeError:
         raise TypeError("Got a non-map object for a map value")
     for key, val in items:
         keybytes = subkeytype.to_binary(key)
         valbytes = subvaltype.to_binary(val)
         buf.write(uint16_pack(len(keybytes)))
         buf.write(keybytes)
         buf.write(uint16_pack(len(valbytes)))
         buf.write(valbytes)
     return buf.getvalue()
Ejemplo n.º 6
0
 def serialize_safe(cls, themap):
     subkeytype, subvaltype = cls.subtypes
     buf = StringIO()
     buf.write(uint16_pack(len(themap)))
     try:
         items = themap.iteritems()
     except AttributeError:
         raise TypeError("Got a non-map object for a map value")
     for key, val in items:
         keybytes = subkeytype.to_binary(key)
         valbytes = subvaltype.to_binary(val)
         buf.write(uint16_pack(len(keybytes)))
         buf.write(keybytes)
         buf.write(uint16_pack(len(valbytes)))
         buf.write(valbytes)
     return buf.getvalue()
Ejemplo n.º 7
0
def write_short(f, s):
    f.write(uint16_pack(s))
Ejemplo n.º 8
0
def write_short(f, s):
    f.write(uint16_pack(s))
Ejemplo n.º 9
0
 def test_comparison(self):
     tok = BytesToken.from_string(six.text_type('0123456789abcdef'))
     token_high_order = uint16_unpack(tok.value[0:2])
     self.assertLess(BytesToken(uint16_pack(token_high_order - 1)), tok)
     self.assertGreater(BytesToken(uint16_pack(token_high_order + 1)), tok)
Ejemplo n.º 10
0
 def test_comparison(self):
     tok = BytesToken.from_string(six.text_type('0123456789abcdef'))
     token_high_order = uint16_unpack(tok.value[0:2])
     self.assertLess(BytesToken(uint16_pack(token_high_order - 1)), tok)
     self.assertGreater(BytesToken(uint16_pack(token_high_order + 1)), tok)