Esempio n. 1
0
 def String(value, encoding=None, errors=STRICT):
     """
     Match or read a string (to read a value, give the number of bytes).
     """
     if isinstance(value, int):
         return _String(value, encoding=encoding, errors=errors)
     else:
         return _Constant(BitString.from_str(value, encoding=encoding, errors=errors))
Esempio n. 2
0
 def String(value, encoding=None, errors=STRICT):
     '''
     Match or read a string (to read a value, give the number of bytes).
     '''
     if isinstance(value, int):
         return _String(value, encoding=encoding, errors=errors)
     else:
         return _Constant(
             BitString.from_str(value, encoding=encoding, errors=errors))
Esempio n. 3
0
 def dispatch_table(big_endian=True, encoding=None, errors=STRICT):
     '''
     Convert types appropriately.
     '''
     # pylint: disable-msg=W0108
     # consistency
     return {int: lambda n: BitString.from_int(n, ordered=big_endian),
             str: lambda s: BitString.from_str(s, encoding, errors),
             bytes: lambda b: BitString.from_bytearray(b),
             bytearray: lambda b: BitString.from_bytearray(b),
             BitString: lambda x: x}
Esempio n. 4
0
 def dispatch_table(big_endian=True, encoding=None, errors=STRICT):
     '''
     Convert types appropriately.
     '''
     # pylint: disable-msg=W0108
     # consistency
     return {
         int: lambda n: BitString.from_int(n, ordered=big_endian),
         str: lambda s: BitString.from_str(s, encoding, errors),
         bytes: lambda b: BitString.from_bytearray(b),
         bytearray: lambda b: BitString.from_bytearray(b),
         BitString: lambda x: x
     }