Ejemplo n.º 1
0
 def _build(self, obj, stream, context):
     if self.encoding:
         if isinstance(self.encoding, str):
             obj = obj.encode(self.encoding)
         else:
             obj = self.encoding.encode(obj)
     else:
         if not isinstance(obj, bytes):
             raise StringError("no encoding provided but building from unicode string?")
     self.lengthfield._build(len(obj), stream, context)
     _write_stream(stream, len(obj), obj)
Ejemplo n.º 2
0
 def _build(self, obj, stream, context):
     result = bytearray()
     value = int(obj)
     if obj == 0:
         _write_stream(stream, 1, chr(0))
         return
     while value > 0:
         byte = value & 0x7f
         value >>= 7
         if value != 0:
             byte |= 0x80
         result.insert(0, byte)
     if len(result) > 1:
         result[0] |= 0x80
         result[-1] ^= 0x80
     _write_stream(stream, len(result), "".join([chr(x) for x in result]))
Ejemplo n.º 3
0
 def _build(self, obj, stream, context):
     result = bytearray()
     value = int(obj)
     if obj == 0:
         _write_stream(stream, 1, chr(0))
         return
     while value > 0:
         byte = value & 0x7f
         value >>= 7
         if value != 0:
             byte |= 0x80
         result.insert(0, byte)
     if len(result) > 1:
         result[0] |= 0x80
         result[-1] ^= 0x80
     _write_stream(stream, len(result), "".join([chr(x) for x in result]))
Ejemplo n.º 4
0
 def _build(self, obj, stream, context):
     _write_stream(stream, len(obj), VLQ("").build(len(obj))+obj)
Ejemplo n.º 5
0
 def _build(self, obj, stream, context):
     if len(obj) == 32:
         _write_stream(stream, 1, chr(3))
         _write_stream(stream, 1, chr(1))
         _write_stream(stream, len(obj.decode("hex")), obj.decode("hex"))
         return
     elif obj is "outpost":
         _write_stream(stream, 1, chr(1))
         star_string()._build(obj, stream, context)
         return
     elif obj is None:
         _write_stream(stream, 1, chr(4))
         _write_stream(stream, 1, chr(0))
         return
Ejemplo n.º 6
0
 def _build(self, obj, stream, context, path):
     _write_stream(stream, 1, '\xff')
Ejemplo n.º 7
0
 def _build(self, obj, stream, context, path):
     if obj < 0:
         raise ConstructError(
             "DotNetUInt cannot build from negative number")
     if obj > 0x1fffffff:
         raise ConstructError("DotNetUInt encountered too large a number")
     if obj < 0x80:
         _write_stream(stream, 1, int2byte(obj))
     elif obj < 0x3fff:
         _write_stream(stream, 1, int2byte((obj >> 8) | 0x80))
         _write_stream(stream, 1, int2byte(obj & 0xff))
     else:
         _write_stream(stream, 1, int2byte((obj >> 24) | 0xc0))
         _write_stream(stream, 1, int2byte((obj >> 16) & 0xff))
         _write_stream(stream, 1, int2byte((obj >> 8) & 0xff))
         _write_stream(stream, 1, int2byte(obj & 0xff))
Ejemplo n.º 8
0
 def _build(self, obj, stream, context):
     _write_stream(stream, len(obj), VLQ("").build(len(obj)) + obj)
Ejemplo n.º 9
0
 def _build(self, obj, stream, context):
     if len(obj) == 32:
         _write_stream(stream, 1, chr(3))
         _write_stream(stream, 1, chr(1))
         _write_stream(stream, len(obj.decode("hex")), obj.decode("hex"))
         return
     elif obj is "outpost":
         _write_stream(stream, 1, chr(1))
         star_string()._build(obj, stream, context)
         return
     elif obj is None:
         _write_stream(stream, 1, chr(4))
         _write_stream(stream, 1, chr(0))
         return