本文整理汇总了Python中rsa._compat.ZERO_BYTE属性的典型用法代码示例。如果您正苦于以下问题:Python _compat.ZERO_BYTE属性的具体用法?Python _compat.ZERO_BYTE怎么用?Python _compat.ZERO_BYTE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类rsa._compat
的用法示例。
在下文中一共展示了_compat.ZERO_BYTE属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: bytes_leading
# 需要导入模块: from rsa import _compat [as 别名]
# 或者: from rsa._compat import ZERO_BYTE [as 别名]
def bytes_leading(raw_bytes, needle=ZERO_BYTE):
"""
Finds the number of prefixed byte occurrences in the haystack.
Useful when you want to deal with padding.
:param raw_bytes:
Raw bytes.
:param needle:
The byte to count. Default \000.
:returns:
The number of leading needle bytes.
"""
leading = 0
# Indexing keeps compatibility between Python 2.x and Python 3.x
_byte = needle[0]
for x in raw_bytes:
if x == _byte:
leading += 1
else:
break
return leading
示例2: bytes_leading
# 需要导入模块: from rsa import _compat [as 别名]
# 或者: from rsa._compat import ZERO_BYTE [as 别名]
def bytes_leading(raw_bytes, needle=ZERO_BYTE):
'''
Finds the number of prefixed byte occurrences in the haystack.
Useful when you want to deal with padding.
:param raw_bytes:
Raw bytes.
:param needle:
The byte to count. Default \000.
:returns:
The number of leading needle bytes.
'''
leading = 0
# Indexing keeps compatibility between Python 2.x and Python 3.x
_byte = needle[0]
for x in raw_bytes:
if x == _byte:
leading += 1
else:
break
return leading