Exemplo n.º 1
0
 def _parse(self, stream, context, path):
     b = byte2int(_read_stream(stream, 1))
     if b & 0x80 == 0:
         num = b
     elif b & 0xc0 == 0x80:
         num = ((b & 0x3f) << 8) + byte2int(_read_stream(stream, 1))
     elif b & 0xe0 == 0xc0:
         num = (b & 0x1f) << 24
         num += byte2int(_read_stream(stream, 1)) << 16
         num += byte2int(_read_stream(stream, 1)) << 8
         num += byte2int(_read_stream(stream, 1))
     else:
         raise ConstructError('DotNetUInt encountered an invalid string')
     return num
Exemplo n.º 2
0
 def _parse(self, stream, context):
     value = 0
     while True:
         tmp = ord(_read_stream(stream, 1))
         value = (value << 7) | (tmp & 0x7f)
         if tmp & 0x80 == 0:
             break
     return value
Exemplo n.º 3
0
 def _parse(self, stream, context):
     value = 0
     while True:
         tmp = ord(_read_stream(stream, 1))
         value = (value << 7) | (tmp & 0x7f)
         if tmp & 0x80 == 0:
             break
     return value
Exemplo n.º 4
0
 def _parse(self, stream, context):
     length = self.lengthfield._parse(stream, context)
     obj = _read_stream(stream, length)
     if self.encoding:
         if isinstance(self.encoding, str):
             obj = obj.decode(self.encoding)
         else:
             obj = self.encoding.decode(obj)
     return obj
Exemplo n.º 5
0
 def _parse(self, stream, context):
     value = 0
     while True:
         tmp = ord(_read_stream(stream, 1))
         value = (value << 7) | (tmp & 0x7f)
         if tmp & 0x80 == 0:
             break
     if (value & 1) == 0x00:
         return value >> 1
     else:
         return -((value >> 1) + 1)
Exemplo n.º 6
0
 def _parse(self, stream, context):
     value = 0
     while True:
         tmp = ord(_read_stream(stream, 1))
         value = (value << 7) | (tmp & 0x7f)
         if tmp & 0x80 == 0:
             break
     if (value & 1) == 0x00:
         return value >> 1
     else:
         return -((value >> 1) + 1)
Exemplo n.º 7
0
    def _parse(self, stream, context):
        tag = ord(_read_stream(stream, 1))

        # single byte or longer?
        if tag & 0x08:
            # 11 bits or longer?
            if tag & 0x10:
                # longer. 3-bit length or longer?
                if tag & 0xe0 == 0xe0:
                    # long length!
                    length = self._parse(stream, context) + (tag >> 5) + 2
                    return self._decode_bigint(_read_stream(stream, length))
                else:
                    # 3-bit length
                    return self._decode_bigint(
                        _read_stream(stream, 2 + (tag >> 5)))
            else:
                # 11 bits
                w = ord(_read_stream(stream, 1))
                return ((tag & 0xe0) << 3) | w
        else:
            # four bits
            return tag >> 4
Exemplo n.º 8
0
 def _parse(self, stream, context):
     l = VLQ("").parse_stream(stream)
     return _read_stream(stream, l)
Exemplo n.º 9
0
 def _parse(self, stream, context, path):
     if _read_stream(stream, 1) != '\xff':
         raise ConstructError('DotNetNullString encounted an invalid byte.')
     return None
Exemplo n.º 10
0
 def _parse(self, stream, context):
     l = VLQ("").parse_stream(stream)
     return _read_stream(stream, l)