Python builtins 模块,hex() 实例源码
我们从Python开源项目中,提取了以下6个代码示例,用于说明如何使用builtins.hex()。
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
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)
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))
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
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_code)
if control:
self.control_map[(event_type, event_code)] = control
self.controls.append(control)
os.close(fileno)
super(EvdevDevice, self).__init__(display, name)
def __init__(self, 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, name)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。