• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python six.byte2int函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中six.byte2int函数的典型用法代码示例。如果您正苦于以下问题:Python byte2int函数的具体用法?Python byte2int怎么用?Python byte2int使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了byte2int函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: decode

 def decode(self, encoded_packet):
     """Decode a transmitted package."""
     b64 = False
     self.packet_type = six.byte2int(encoded_packet[0:1])
     if self.packet_type == 98:  # 'b' --> binary base64 encoded packet
         self.binary = True
         encoded_packet = encoded_packet[1:]
         self.packet_type = six.byte2int(encoded_packet[0:1])
         self.packet_type -= 48
         b64 = True
     elif self.packet_type >= 48:
         self.packet_type -= 48
         self.binary = False
     else:
         self.binary = True
     self.data = None
     if len(encoded_packet) > 1:
         if self.binary:
             if b64:
                 self.data = base64.b64decode(encoded_packet[1:])
             else:
                 self.data = encoded_packet[1:]
         else:
             try:
                 self.data = self.json.loads(
                     encoded_packet[1:].decode('utf-8'))
             except ValueError:
                 self.data = encoded_packet[1:].decode('utf-8')
开发者ID:ThumbGen,项目名称:ropi,代码行数:28,代码来源:packet.py


示例2: decode

    def decode(self, encoded_payload):
        """Decode a transmitted payload."""
        self.packets = []
        while encoded_payload:
            if six.byte2int(encoded_payload[0:1]) <= 1:
                packet_len = 0
                i = 1
                while six.byte2int(encoded_payload[i:i + 1]) != 255:
                    packet_len = packet_len * 10 + six.byte2int(
                        encoded_payload[i:i + 1])
                    i += 1
                self.packets.append(packet.Packet(
                    encoded_packet=encoded_payload[i + 1:i + 1 + packet_len]))
            else:
                i = encoded_payload.find(b':')
                if i == -1:
                    raise ValueError('invalid payload')

                # extracting the packet out of the payload is extremely
                # inefficient, because the payload needs to be treated as
                # binary, but the non-binary packets have to be parsed as
                # unicode. Luckily this complication only applies to long
                # polling, as the websocket transport sends packets
                # individually wrapped.
                packet_len = int(encoded_payload[0:i])
                pkt = encoded_payload.decode('utf-8', errors='ignore')[
                    i + 1: i + 1 + packet_len].encode('utf-8')
                self.packets.append(packet.Packet(encoded_packet=pkt))

                # the engine.io protocol sends the packet length in
                # utf-8 characters, but we need it in bytes to be able to
                # jump to the next packet in the payload
                packet_len = len(pkt)
            encoded_payload = encoded_payload[i + 1 + packet_len:]
开发者ID:miguelgrinberg,项目名称:python-engineio,代码行数:34,代码来源:payload.py


示例3: decode_version

def decode_version(version):
    """ Takes a byte version and decodes it into human-readable <major>.<minor> format. """
    if len(version) != 1:
        raise ValueError("Can only decode a single byte!")
    major = six.byte2int(version) >> 4
    minor = six.byte2int(version) & 15
    return ('%d.%d' % (major, minor)).encode('ascii')
开发者ID:thusoy,项目名称:nuts-auth,代码行数:7,代码来源:utils.py


示例4: validate

    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.")
开发者ID:trakt,项目名称:Plex-Trakt-Scrobbler,代码行数:26,代码来源:_abnf.py


示例5: _wait_close

 def _wait_close(self):
     logger.debug('hxsocks _wait_close')
     self.settimeout(8)
     while 1:
         try:
             ctlen = self._rfile_read(2)
             if not ctlen:
                 raise IOError(0, '')
             ctlen = struct.unpack('>H', self.pskcipher.decrypt(ctlen))[0]
             ct = self._rfile_read(ctlen)
             mac = self._rfile_read(MAC_LEN)
             data = self.cipher.decrypt(ct, mac)
             pad_len = byte2int(data)
             if 0 < pad_len < 8:
                 # fake chunk, drop
                 if pad_len == 1:
                     self.send_fake_chunk(2)
                 # server should be sending another chunk right away
                 continue
             data = data[1:0-pad_len] if byte2int(data) else data[1:]
             if not data:
                 logger.debug('hxsocks add to pool')
                 self.pooled = 1
                 POOL.put(self.hxsServer.parse.hostname, self, self.hxsServer.name)
                 self.readable = 0
                 break
         except Exception:
             self._sock.close()
             return
开发者ID:v3aqb,项目名称:fwlite,代码行数:29,代码来源:hxsocks.py


示例6: test_array_infinite_nested_block

    def test_array_infinite_nested_block():
        random.seed(0)

        class leaf(pint.uint32_t): pass
        class rootcontainer(parray.block):
            _object_ = leaf

        class acontainer(rootcontainer):
            blocksize = lambda x: 8

        class bcontainer(rootcontainer):
            _object_ = pint.uint16_t
            blocksize = lambda x: 8

        class ccontainer(rootcontainer):
            _object_ = pint.uint8_t
            blocksize = lambda x: 8

        class arr(parray.infinite):
            def randomcontainer(self):
                l = [ acontainer, bcontainer, ccontainer ]
                return random.sample(l, 1)[0]

            _object_ = randomcontainer

        string = str().join([ six.int2byte(random.randint(six.byte2int('A'),six.byte2int('Z'))) for x in six.moves.range(0x100) ])
        a = arr(source=provider.string(string))
        a=a.l
        if a.blocksize() == 0x108:
            raise Success
开发者ID:arizvisa,项目名称:syringe,代码行数:30,代码来源:parray.py


示例7: __getvalue__

 def __getvalue__(self):
     if not self.initializedQ():
         raise error.InitializationError(self, 'int')
     if self.byteorder is config.byteorder.bigendian:
         return six.moves.reduce(lambda x,y: x << 8 | six.byte2int(y), self.serialize(), 0)
     elif self.byteorder is config.byteorder.littleendian:
         return six.moves.reduce(lambda x,y: x << 8 | six.byte2int(y), reversed(self.serialize()), 0)
     raise error.SyntaxError(self, 'integer_t.int', message='Unknown integer endianness {!r}'.format(self.byteorder))
开发者ID:arizvisa,项目名称:syringe,代码行数:8,代码来源:pint.py


示例8: _decode_carddata

    def _decode_carddata(data, card_type, reftime = None):
        """Decodes a data record read from an SI Card."""

        ret = {}
        card = SIReader.CARD[card_type]
        
        # the slicing of data is necessary for Python 3 to get a bytes object instead
        # of an int
        ret['card_number'] = SIReader._decode_cardnr(b'\x00'
                                                     + data[card['CN2']:card['CN2']+1]
                                                     + data[card['CN1']:card['CN1']+1]
                                                     + data[card['CN0']:card['CN0']+1])

        ret['start'] = SIReader._decode_time(data[card['ST']:card['ST']+2],
                                             data[card['STD']] if card['STD'] else None,
                                             reftime)
        ret['finish'] = SIReader._decode_time(data[card['FT']:card['FT']+2],
                                              data[card['FTD']] if card['FTD'] is not None else None,
                                             reftime)
        ret['check'] = SIReader._decode_time(data[card['CT']:card['CT']+2],
                                             data[card['CTD']] if card['CTD'] is not None else None,
                                             reftime)
        if card['LT'] is not None:
            ret['clear'] = SIReader._decode_time(data[card['LT']:card['LT']+2],
                                                 data[card['LTD']] if card['LTD'] is not None else None,
                                                 reftime)
        else:
            ret['clear'] = None # SI 5 and 9 cards don't store the clear time

        punch_count = byte2int(data[card['RC']:card['RC']+1])
        if card_type == 'SI5':
            # RC is the index of the next punch on SI5
            punch_count -= 1
            
        if punch_count > card['PM']:
            punch_count = card['PM']
            
        ret['punches'] = []
        p = 0
        i = card['P1']
        while p < punch_count:
            if card_type == 'SI5' and i % 16 == 0:
                # first byte of each block is reserved for punches 31-36
                i += 1

            ptd = data[i + card['PTD']] if card['PTD'] is not None else None
            cn  = byte2int(data[i + card['CN']])
            pt  = data[i + card['PTH']:i + card['PTL']+1]

            SIReader._append_punch(ret['punches'], cn, pt, ptd, reftime)

            i += card['PL']
            p += 1
            
        return ret
开发者ID:Paukert,项目名称:quickbox,代码行数:55,代码来源:sireader.py


示例9: _get_close_args

 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 not self.on_close or len(inspect.getargspec(self.on_close).args) != 3:
         return []
     if data and len(data) >=2:
         code = 256*six.byte2int(data[0]) + six.byte2int(data[1])
         reason = data[2:].decode('utf-8')
         return [code,reason]
     return [None,None]
开发者ID:ekeydar,项目名称:websocket-client,代码行数:12,代码来源:_app.py


示例10: _read_command

    def _read_command(self, timeout = None):

        try:
            if timeout != None:
                old_timeout = self._serial.timeout
                self._serial.timeout = timeout
            char = self._serial.read()
            if timeout != None:
                self._serial.timeout = old_timeout

            if char == b'':
                raise SIReaderTimeout('No data available')
            elif char == SIReader.NAK:
                raise SIReaderException('Invalid command or parameter.')
            elif char != SIReader.STX:
                self._serial.flushInput()
                raise SIReaderException('Invalid start byte %s' % hex(byte2int(char)))

            # Read command, length, data, crc, ETX
            cmd = self._serial.read()
            length = self._serial.read()
            station = self._serial.read(2)
            self.station_code = SIReader._to_int(station)
            data = self._serial.read(byte2int(length)-2)
            crc = self._serial.read(2)
            etx = self._serial.read()

            if self._debug:
                print("<<== command '%s', len %i, station %s, data %s, crc %s, etx %s" % (hexlify(cmd).decode('ascii'),
                                                                                          byte2int(length),
                                                                                          hexlify(station).decode('ascii'),
                                                                                          ' '.join([hexlify(int2byte(c)).decode('ascii') for c in data]),
                                                                                          hexlify(crc).decode('ascii'),
                                                                                          hexlify(etx).decode('ascii'),
                                                                                          ))

            if etx != SIReader.ETX:
                raise SIReaderException('No ETX byte received.')
            if not SIReader._crc_check(cmd + length + station + data, crc):
                raise SIReaderException('CRC check failed')

            if self._logfile:
                self._logfile.write('r %s %s\n' % (datetime.now(), char + cmd + length + station + data + crc + etx))
                self._logfile.flush()
                os.fsync(self._logfile)
                
        except (SerialException, OSError) as msg:
            raise SIReaderException('Error reading command: %s' % msg)

        return (cmd, data)
开发者ID:Paukert,项目名称:quickbox,代码行数:50,代码来源:sireader.py


示例11: derive

    def derive(self, type, site, counter=1):
        value = ""
        seed = self.seed(site, counter)
        try:
            templates = Templates[type].value
        except KeyError as e:
            log.error("Unknown key type '{}'".format(type))
            raise e
        template = templates[six.byte2int(seed[0]) % len(templates)]
        for i in range(0, len(template)):
            passChars = CHARACTER_CLASSES[template[i]]
            passChar = passChars[six.byte2int(seed[i + 1]) % len(passChars)]
            value += passChar

        return value
开发者ID:tangfeixiong,项目名称:cicd-openstack-and-cloudfoundry,代码行数:15,代码来源:masterpassword.py


示例12: poll_punch

    def poll_punch(self, timeout=0):
        """Polls for new punches.
        @return: list of (cardnr, punchtime) tuples, empty list if no new punches are available
        """

        if not self.proto_config['ext_proto']:
            raise SIReaderException('This command only supports stations in "Extended Protocol" '
                                    'mode. Switch mode first')

        if not self.proto_config['auto_send']:
            raise SIReaderException('This command only supports stations in "Autosend" '
                                    'mode. Switch mode first')

        punches = []
        while True:
            try:
                c = self._read_command(timeout = timeout)
            except SIReaderTimeout:
                break 
        
            if c[0] == SIReader.C_TRANS_REC:
                cur_offset = SIReader._to_int(c[1][SIReader.T_OFFSET:SIReader.T_OFFSET+3])
                if self._next_offset is not None:
                    while self._next_offset < cur_offset:
                        # recover lost punches
                        punches.append(self._read_punch(self._next_offset))
                        self._next_offset += SIReader.REC_LEN

                self._next_offset = cur_offset + SIReader.REC_LEN
            punches.append( (self._decode_cardnr(c[1][SIReader.T_CN:SIReader.T_CN+4]), 
                             self._decode_time(c[1][SIReader.T_TIME:SIReader.T_TIME+2])) )
        else:
            raise SIReaderException('Unexpected command %s received' % hex(byte2int(c[0])))
        
        return punches
开发者ID:guizmo51,项目名称:sireader,代码行数:35,代码来源:sireader.py


示例13: decode_name

def decode_name(name):
    # ToDo: Rewrite this simpler, we're using less than written
    """
    Perform first and second level decoding of name as specified in RFC 1001 (Section 4)

    :param string name: the name to dencode

    :return string: the decoded name.
    """

    name_length = ord(name[0])
    assert name_length == 32

    decoded_name = re.sub('..', _do_first_level_decoding, name[1:33])
    if name[33] == '\0':
        return 34, decoded_name, ''
    else:
        decoded_domain = ''
        offset = 34
        while 1:
            domain_length = byte2int(name[offset:offset+1])
            if domain_length == 0:
                break
            decoded_domain = '.' + name[offset:offset + domain_length]
            offset += domain_length
        return offset + 1, decoded_name, decoded_domain
开发者ID:awesome-security,项目名称:impacket,代码行数:26,代码来源:nmb.py


示例14: extract_message

 def extract_message(cls, raw_bytes):
     if len(raw_bytes) < 2:
         return None, raw_bytes
     if six.byte2int(raw_bytes) != 123:
         raise FramingError(
             'Broken state. Expected JSON Object, got: %s' % raw_bytes)
     stack = [123]
     uniesc = 0
     poppers = {91: [93], 123: [125], 34: [34]}
     adders = {91: [34, 91, 123], 123: [34, 91, 123], 34: [92], 92: [117]}
     for idx in range(1, len(raw_bytes)):
         cbyte = six.indexbytes(raw_bytes, idx)
         if cbyte in poppers.get(stack[-1], []):
             stack.pop()
         elif cbyte in adders.get(stack[-1], []):
             stack.append(cbyte)
         elif stack[-1] == 92:
             stack.pop()
         elif stack[-1] == 117:
             uniesc += 1
             if uniesc >= 4:
                 stack = stack[:-2]
                 uniesc = 0
         if not stack:
             return raw_bytes[:idx + 1], raw_bytes[idx + 1:]
     return None, raw_bytes
开发者ID:gitter-badger,项目名称:py-bson-rpc,代码行数:26,代码来源:framing.py


示例15: decode

    def decode(self, input, errors='strict'):
        """
        Decode byte array to string
        :param input: byte array to convert to unicode string
        :param errors: defines the error handling to apply
        :return: returns a tuple (output object, length consumed)
        """
        decode_buffer = u""
        consumed = 0

        num = 0
        for value in input:
            consumed += 1
            num |= byte2int([value])
            if num == self._ESCAPE:
                num <<= 8
                continue
            try:
                decode_buffer += unichr(self._decode_map[num])
            except KeyError as ex:
                if errors == 'replace':
                    decode_buffer += u'\ufffd'
                elif errors == 'ignore':
                    pass
                else:
                    if num & (self._ESCAPE << 8):
                        raise ValueError("'%s' codec can't decode byte 0x%x in position %d" %
                                         (self.NAME, ex.args[0] & 0xff, consumed - 1))
                    else:
                        raise ValueError("'%s' codec can't decode byte 0x%x in position %d" %
                                         (self.NAME, ex.args[0], consumed - 1))
            num = 0
        return decode_buffer, consumed
开发者ID:edersohe,项目名称:gsm0338,代码行数:33,代码来源:codec.py


示例16: read_loose

def read_loose(stream):
    """Turn a HL7-like blob of text into a real HL7 messages"""
    # look for the START_BLOCK to delineate messages
    START_BLOCK = b'MSH|^~\&|'

    # load all the data
    data = stream.read()

    # take out all the typical MLLP separators. In Python 3, iterating
    # through a bytestring returns ints, so we need to filter out the int
    # versions of the separators, then convert back from a list of ints to
    # a bytestring (In Py3, we could just call bytes([ints]))
    separators = [six.byte2int(bs) for bs in [EB, FF, SB]]
    data = b''.join([six.int2byte(c) for c in six.iterbytes(data) if c not in separators])

    # Windows & Unix new lines to segment separators
    data = data.replace(b'\r\n', b'\r').replace(b'\n', b'\r')

    for m in data.split(START_BLOCK):
        if not m:
            # the first element will not have any data from the split
            continue

        # strip any trailing whitespace
        m = m.strip(CR + b'\n ')

        # re-insert the START_BLOCK, which was removed via the split
        yield START_BLOCK + m
开发者ID:jgambox,项目名称:python-hl7,代码行数:28,代码来源:client.py


示例17: _update_proto_config

    def _update_proto_config(self):
        # Read protocol configuration
        ret = self._send_command(SIReader.C_GET_SYS_VAL, SIReader.O_PROTO+b'\x01')
        config_byte = byte2int(ret[1][1])
        self.proto_config = {}
        self.proto_config['ext_proto']  = config_byte & (1 << 0) != 0
        self.proto_config['auto_send']  = config_byte & (1 << 1) != 0
        self.proto_config['handshake']  = config_byte & (1 << 2) != 0
        self.proto_config['pw_access']  = config_byte & (1 << 4) != 0
        self.proto_config['punch_read'] = config_byte & (1 << 7) != 0

        # Read operating mode
        ret = self._send_command(SIReader.C_GET_SYS_VAL, SIReader.O_MODE+b'\x01')
        self.proto_config['mode'] = byte2int(ret[1][1])

        return self.proto_config
开发者ID:Paukert,项目名称:quickbox,代码行数:16,代码来源:sireader.py


示例18: decode_caveat

def decode_caveat(key, caveat):
    '''Decode caveat by decrypting the encrypted part using key.

    @param key the nacl private key to decode.
    @param caveat bytes.
    @return ThirdPartyCaveatInfo
    '''
    if len(caveat) == 0:
        raise VerificationError('empty third party caveat')

    first = caveat[:1]
    if first == b'e':
        # 'e' will be the first byte if the caveatid is a base64
        # encoded JSON object.
        return _decode_caveat_v1(key, caveat)
    first_as_int = six.byte2int(first)
    if (first_as_int == VERSION_2 or
            first_as_int == VERSION_3):
        if (len(caveat) < _VERSION3_CAVEAT_MIN_LEN
                and first_as_int == VERSION_3):
            # If it has the version 3 caveat tag and it's too short, it's
            # almost certainly an id, not an encrypted payload.
            raise VerificationError(
                'caveat id payload not provided for caveat id {}'.format(
                    caveat))
        return _decode_caveat_v2_v3(first_as_int, key, caveat)
    raise VerificationError('unknown version for caveat')
开发者ID:go-macaroon-bakery,项目名称:py-macaroon-bakery,代码行数:27,代码来源:_codec.py


示例19: unpackbyte

def unpackbyte(b):
   """
   Given a one-byte long byte string, returns an integer. Equivalent
   to struct.unpack("B", b)
   """
   if isinstance(b, bytes):
       return six.byte2int(b)
   return b
开发者ID:joeatwork,项目名称:python-lzw,代码行数:8,代码来源:__init__.py


示例20: decode

 def decode(self, text):
     '''
     Remove the PKCS#7 padding from a text string
     '''
     val = six.byte2int([text[-1]])
     if val > self.k:
         raise ValueError('Input is not padded or padding is corrupt')
     return text[:-val]
开发者ID:arthurdarcet,项目名称:RNCryptor,代码行数:8,代码来源:pkcs7.py



注:本文中的six.byte2int函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python six.callable函数代码示例发布时间:2022-05-27
下一篇:
Python six.binary_type函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap