Python builtins 模块,hex() 实例源码

我们从Python开源项目中,提取了以下6个代码示例,用于说明如何使用builtins.hex()

项目:idealoom    作者:conversence    | 项目源码 | 文件源码
def flatten_source_post_id(cls, source_post_id, extra_length=0):
        # Ensure that a source_post_id can be used as part 1 of message_id
        sanitized = cls._non_email_chars.subn(
            lambda c: '_' + hex(ord(c.group()))[2:], source_post_id)[0]
        if len(sanitized) + extra_length > 64:
            # 64 is max according to RFC 5322
            # cut it short and add a digest of original
            import hashlib
            import base64
            d = hashlib.md5()
            d.update(source_post_id)
            d = base64.urlsafe_b64encode(d.digest())
            sanitized = sanitized[
                :max(0, 64-len(d)-extra_length-1)]
            if sanitized:
                sanitized += "_" + d
            else:
                sanitized = d
        return sanitized
项目:pycrate    作者:ANSSI-FR    | 项目源码 | 文件源码
def hex(obj):
    if isinstance(obj, Element):
        return obj.hex()
    elif hasattr(obj, '__hex__') and callable(obj.__hex__):
        return obj.__hex__()
    else:
        # will certainly raise
        return builtins.hex(obj)
项目:qtpandas    作者:draperjames    | 项目源码 | 文件源码
def processDataDrops(self, mimeData):
        """if you have more complicated stuff to do and you want to match some models, might be possible like that"""
        mimeDataPayload = mimeData.data()
        if isinstance(mimeDataPayload, PandasCellPayload):
            if self.dataModel is not None:
                if hex(id(self.dataModel)) == mimeDataPayload.parentId:
                    self.dropWidget.setText("complex stuff done after drop event. {0}".format(mimeDataPayload.column))
项目:qtpandas    作者:draperjames    | 项目源码 | 文件源码
def __repr__(self):
        unformatted = "DataSearch({}): {} ({})"
        formatted_string = unformatted.format(hex(id(self)),
                                              self.name,
                                              self._filterString)
        if python_version < 3:
            formatted_string = unformatted.encode("utf-8")

        return formatted_string
项目:FightstickDisplay    作者:calexil    | 项目源码 | 文件源码
def __init__(self, display, filename):
        self._filename = filename

        fileno = os.open(filename, os.O_RDONLY)
        # event_version = EVIOCGVERSION(fileno).value

        self._id = EVIOCGID(fileno)
        self.id_bustype = self._id.bustype
        self.id_vendor = hex(self._id.vendor)
        self.id_product = hex(self._id.product)
        self.id_version = self._id.version

        name = EVIOCGNAME(fileno)
        try:
            name = name.decode('utf-8')
        except UnicodeDecodeError:
            try:
                name = name.decode('latin-1')
            except UnicodeDecodeError:
                pass

        try:
            self.phys = EVIOCGPHYS(fileno)
        except OSError:
            self.phys = ''
        try:
            self.uniq = EVIOCGUNIQ(fileno)
        except OSError:
            self.uniq = ''

        self.controls = []
        self.control_map = {}

        event_types_bits = (ctypes.c_byte * 4)()
        EVIOCGBIT(fileno, 0, event_types_bits)
        for event_type in get_set_bits(event_types_bits):
            if event_type not in event_types:
                continue
            max_code = event_types[event_type]
            nbytes = max_code // 8 + 1
            event_codes_bits = (ctypes.c_byte * nbytes)()
            EVIOCGBIT(fileno, event_type, event_codes_bits)
            for event_code in get_set_bits(event_codes_bits):
                control = _create_control(fileno, event_type, event_code)
                if control:
                    self.control_map[(event_type, event_code)] = control 
                    self.controls.append(control)

        os.close(fileno)

        super(EvdevDevice, self).__init__(display, name)
项目:cryptogram    作者:xinmingzhang    | 项目源码 | 文件源码
def __init__(self, display, filename):
        self._filename = filename

        fileno = os.open(filename, os.O_RDONLY)
        #event_version = EVIOCGVERSION(fileno).value

        id = EVIOCGID(fileno)
        self.id_bustype = id.bustype
        self.id_vendor = hex(id.vendor)
        self.id_product = hex(id.product)
        self.id_version = id.version

        name = EVIOCGNAME(fileno)
        try:
            name = name.decode('utf-8')
        except UnicodeDecodeError:
            try:
                name = name.decode('latin-1')
            except UnicodeDecodeError:
                pass

        try:
            self.phys = EVIOCGPHYS(fileno)
        except OSError:
            self.phys = ''
        try:
            self.uniq = EVIOCGUNIQ(fileno)
        except OSError:
            self.uniq = ''

        self.controls = []
        self.control_map = {}

        event_types_bits = (ctypes.c_byte * 4)()
        EVIOCGBIT(fileno, 0, event_types_bits)
        for event_type in get_set_bits(event_types_bits):
            if event_type not in event_types:
                continue
            max_code = event_types[event_type]
            nbytes = max_code // 8 + 1
            event_codes_bits = (ctypes.c_byte * nbytes)()
            EVIOCGBIT(fileno, event_type, event_codes_bits)
            for event_code in get_set_bits(event_codes_bits):
                control = _create_control(fileno, event_type, event_code)
                if control:
                    self.control_map[(event_type, event_code)] = control 
                    self.controls.append(control)

        os.close(fileno)

        super(EvdevDevice, self).__init__(display, name)