本文整理汇总了Python中six.byte2int方法的典型用法代码示例。如果您正苦于以下问题:Python six.byte2int方法的具体用法?Python six.byte2int怎么用?Python six.byte2int使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类six
的用法示例。
在下文中一共展示了six.byte2int方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_close_args
# 需要导入模块: import six [as 别名]
# 或者: from six import byte2int [as 别名]
def _get_close_args(self, data):
""" this functions extracts the code, reason from the close body
if they exists, and if the self.on_close except three arguments """
import inspect
# if the on_close callback is "old", just return empty list
if sys.version_info < (3, 0):
if not self.on_close or len(inspect.getargspec(self.on_close).args) != 3:
return []
else:
if not self.on_close or len(inspect.getfullargspec(self.on_close).args) != 3:
return []
if data and len(data) >= 2:
code = 256 * six.byte2int(data[0:1]) + six.byte2int(data[1:2])
reason = data[2:].decode('utf-8')
return [code, reason]
return [None, None]
示例2: read_bits
# 需要导入模块: import six [as 别名]
# 或者: from six import byte2int [as 别名]
def read_bits(self, bits):
result = 0
resultbits = 0
while resultbits != bits:
if self._nextbits == 0:
if self.done():
raise TruncatedError(self)
self._next = six.byte2int([self._data[self._used]])
self._used += 1
self._nextbits = 8
copybits = min(bits - resultbits, self._nextbits)
copy = self._next & ((1 << copybits) - 1)
if self._bigendian:
result |= copy << (bits - resultbits - copybits)
else:
result |= copy << resultbits
self._next >>= copybits
self._nextbits -= copybits
resultbits += copybits
return result
示例3: _get_close_args
# 需要导入模块: import six [as 别名]
# 或者: from six import byte2int [as 别名]
def _get_close_args(self, data):
""" this functions extracts the code, reason from the close body
if they exists, and if the self.on_close except three arguments """
# if the on_close callback is "old", just return empty list
if sys.version_info < (3, 0):
if not self.on_close or len(inspect.getargspec(self.on_close).args) != 3:
return []
else:
if not self.on_close or len(inspect.getfullargspec(self.on_close).args) != 3:
return []
if data and len(data) >= 2:
code = 256 * six.byte2int(data[0:1]) + six.byte2int(data[1:2])
reason = data[2:].decode('utf-8')
return [code, reason]
return [None, None]
示例4: generate_scalars_binary
# 需要导入模块: import six [as 别名]
# 或者: from six import byte2int [as 别名]
def generate_scalars_binary(scalars_map, preceding_symbols=0):
for ion_type, values in six.iteritems(scalars_map):
for native, expected in values:
native_expected = expected
has_symbols = False
if native is None:
# An un-adorned 'None' doesn't contain enough information to determine its Ion type
native_expected = b'\x0f'
elif ion_type is IonType.CLOB:
# All six.binary_type are treated as BLOBs unless wrapped by an _IonNature
tid = six.byte2int(expected) + 0x10 # increment upper nibble for clob -> blob; keep lower nibble
native_expected = bytearray([tid]) + expected[1:]
elif ion_type is IonType.SYMBOL and native is not None:
has_symbols = True
elif ion_type is IonType.STRING:
# Encode all strings as symbols too.
symbol_expected = _serialize_symbol(
IonEvent(IonEventType.SCALAR, IonType.SYMBOL, SymbolToken(None, 10 + preceding_symbols)))
yield _Parameter(IonType.SYMBOL.name + ' ' + native,
IonPyText.from_value(IonType.SYMBOL, native), symbol_expected, True)
yield _Parameter('%s %s' % (ion_type.name, native), native, native_expected, has_symbols)
wrapper = _FROM_ION_TYPE[ion_type].from_value(ion_type, native)
yield _Parameter(repr(wrapper), wrapper, expected, has_symbols)
示例5: _bytes_text
# 需要导入模块: import six [as 别名]
# 或者: from six import byte2int [as 别名]
def _bytes_text(code_point_iter, quote, prefix=b'', suffix=b''):
quote_code_point = None if len(quote) == 0 else six.byte2int(quote)
buf = BytesIO()
buf.write(prefix)
buf.write(quote)
for code_point in code_point_iter:
if code_point == quote_code_point:
buf.write(b'\\' + quote)
elif code_point == six.byte2int(b'\\'):
buf.write(b'\\\\')
elif _is_printable_ascii(code_point):
buf.write(six.int2byte(code_point))
else:
buf.write(_escape(code_point))
buf.write(quote)
buf.write(suffix)
return buf.getvalue()
示例6: decode_spans
# 需要导入模块: import six [as 别名]
# 或者: from six import byte2int [as 别名]
def decode_spans(self, spans):
"""Decodes an encoded list of spans.
:param spans: encoded list of spans
:type spans: bytes
:return: list of spans
:rtype: list of Span
"""
decoded_spans = []
transport = TMemoryBuffer(spans)
if six.byte2int(spans) == TType.STRUCT:
_, size = read_list_begin(transport)
else:
size = 1
for _ in range(size):
span = zipkin_core.Span()
span.read(TBinaryProtocol(transport))
decoded_spans.append(self._decode_thrift_span(span))
return decoded_spans
示例7: parse_binary_value
# 需要导入模块: import six [as 别名]
# 或者: from six import byte2int [as 别名]
def parse_binary_value(self, data, display, length, format):
values = []
while 1:
if len(data) < 2:
break
# font change
if byte2int(data) == 255:
values.append(struct.unpack('>L', bytes(data[1:5]))[0])
data = data[5:]
# skip null strings
elif byte2int(data) == 0 and indexbytes(data, 1) == 0:
data = data[2:]
# string with delta
else:
v, data = self.string_textitem.parse_binary(data, display)
values.append(v)
return values, ''
示例8: new
# 需要导入模块: import six [as 别名]
# 或者: from six import byte2int [as 别名]
def new(self, name, bits, idaname=None, **kwargs):
'''Add a register to the architecture's cache.'''
# older
if idaapi.__version__ < 7.0:
dtype_by_size = internal.utils.fcompose(idaapi.get_dtyp_by_size, six.byte2int)
dt_bitfield = idaapi.dt_bitfield
# newer
else:
dtype_by_size = idaapi.get_dtype_by_size
dt_bitfield = idaapi.dt_bitfild
#dtyp = kwargs.get('dtyp', idaapi.dt_bitfild if bits == 1 else dtype_by_size(bits//8))
dtype = six.next((kwargs[n] for n in ('dtyp', 'dtype', 'type') if n in kwargs), dt_bitfield if bits == 1 else dtype_by_size(bits // 8))
namespace = dict(register_t.__dict__)
namespace.update({'__name__':name, '__parent__':None, '__children__':{}, '__dtype__':dtype, '__position__':0, '__size__':bits})
namespace['realname'] = idaname
namespace['alias'] = kwargs.get('alias', set())
namespace['architecture'] = self
res = type(name, (register_t,), namespace)()
self.__register__.__state__[name] = res
self.__cache__[idaname or name, dtype] = name
return res
示例9: child
# 需要导入模块: import six [as 别名]
# 或者: from six import byte2int [as 别名]
def child(self, parent, name, position, bits, idaname=None, **kwargs):
'''Add a child register to the architecture's cache.'''
# older
if idaapi.__version__ < 7.0:
dtype_by_size = internal.utils.fcompose(idaapi.get_dtyp_by_size, six.byte2int)
dt_bitfield = idaapi.dt_bitfield
# newer
else:
dtype_by_size = idaapi.get_dtype_by_size
dt_bitfield = idaapi.dt_bitfild
dtype = six.next((kwargs[n] for n in ('dtyp', 'dtype', 'type') if n in kwargs), dt_bitfield if bits == 1 else dtype_by_size(bits // 8))
#dtyp = kwargs.get('dtyp', idaapi.dt_bitfild if bits == 1 else dtype_by_size(bits//8))
namespace = dict(register_t.__dict__)
namespace.update({'__name__':name, '__parent__':parent, '__children__':{}, '__dtype__':dtype, '__position__':position, '__size__':bits})
namespace['realname'] = idaname
namespace['alias'] = kwargs.get('alias', set())
namespace['architecture'] = self
res = type(name, (register_t,), namespace)()
self.__register__.__state__[name] = res
self.__cache__[idaname or name, dtype] = name
parent.__children__[position] = res
return res
示例10: repr
# 需要导入模块: import six [as 别名]
# 或者: from six import byte2int [as 别名]
def repr(cls, item):
"""Given an item, return the `repr()` of it whilst ensuring that a proper ascii string is returned.
All unicode strings are encoded to UTF-8 in order to guarantee
the resulting string can be emitted.
"""
if isinstance(item, basestring):
res = cls.escape(item, '\'')
if all(six.byte2int(ch) < 0x100 for ch in item):
return "'{:s}'".format(res)
return u"u'{:s}'".format(res)
elif isinstance(item, tuple):
res = map(cls.repr, item)
return "({:s}{:s})".format(', '.join(res), ',' if len(item) == 1 else '')
elif isinstance(item, list):
res = map(cls.repr, item)
return "[{:s}]".format(', '.join(res))
elif isinstance(item, set):
res = map(cls.repr, item)
return "set([{:s}])".format(', '.join(res))
elif isinstance(item, dict):
res = ("{:s}: {:s}".format(cls.repr(k), cls.repr(v)) for k, v in six.iteritems(item))
return "{{{:s}}}".format(', '.join(res))
return repr(item)
示例11: validate
# 需要导入模块: import six [as 别名]
# 或者: from six import byte2int [as 别名]
def validate(self, skip_utf8_validation=False):
"""
validate the ABNF frame.
skip_utf8_validation: skip utf8 validation.
"""
if self.rsv1 or self.rsv2 or self.rsv3:
raise WebSocketProtocolException("rsv is not implemented, yet")
if self.opcode not in ABNF.OPCODES:
raise WebSocketProtocolException("Invalid opcode %r", self.opcode)
if self.opcode == ABNF.OPCODE_PING and not self.fin:
raise WebSocketProtocolException("Invalid ping frame.")
if self.opcode == ABNF.OPCODE_CLOSE:
l = len(self.data)
if not l:
return
if l == 1 or l >= 126:
raise WebSocketProtocolException("Invalid close frame.")
if l > 2 and not skip_utf8_validation and not validate_utf8(self.data[2:]):
raise WebSocketProtocolException("Invalid close frame.")
code = 256 * \
six.byte2int(self.data[0:1]) + six.byte2int(self.data[1:2])
if not self._is_valid_close_status(code):
raise WebSocketProtocolException("Invalid close opcode.")
示例12: __str__
# 需要导入模块: import six [as 别名]
# 或者: from six import byte2int [as 别名]
def __str__(self):
s = (
'{:02x}'.format(six.byte2int([self._data[self._used]]))
if self._used < len(self._data)
else '--'
)
return 'buffer({0:02x}/{1:d},[{2:d}]={3:s})'.format(
self._nextbits and self._next or 0, self._nextbits, self._used, s
)
示例13: to_string
# 需要导入模块: import six [as 别名]
# 或者: from six import byte2int [as 别名]
def to_string(self):
""" A helper for converting a List of chars to a native string. Dies if
the list contents are not something that could be reasonably converted
to a string. """
return ''.join(chr(six.byte2int(i)) for i in self)
示例14: __init__
# 需要导入模块: import six [as 别名]
# 或者: from six import byte2int [as 别名]
def __init__(self, value=0):
if not isinstance(value, six.integer_types):
value = six.byte2int(value)
self.v = C + norm(abs(int(value)))
示例15: _scalar_event_pairs
# 需要导入模块: import six [as 别名]
# 或者: from six import byte2int [as 别名]
def _scalar_event_pairs(data, events, info):
"""Generates event pairs for all scalars.
Each scalar is represented by a sequence whose first element is the raw data and whose following elements are the
expected output events.
"""
first = True
delimiter, in_container = info
space_delimited = not (b',' in delimiter)
for event in events:
input_event = NEXT
if first:
input_event = e_read(data + delimiter)
if space_delimited and event.value is not None \
and ((event.ion_type is IonType.SYMBOL) or
(event.ion_type is IonType.STRING and
six.byte2int(b'"') != six.indexbytes(data, 0))): # triple-quoted strings
# Because annotations and field names are symbols, a space delimiter after a symbol isn't enough to
# generate a symbol event immediately. Similarly, triple-quoted strings may be followed by another
# triple-quoted string if only delimited by whitespace or comments.
yield input_event, INC
if in_container:
# Within s-expressions, these types are delimited in these tests by another value - in this case,
# int 0 (but it could be anything).
yield e_read(b'0' + delimiter), event
input_event, event = (NEXT, e_int(0))
else:
# This is a top-level value, so it may be flushed with NEXT after INCOMPLETE.
input_event, event = (NEXT, event)
first = False
yield input_event, event