本文整理汇总了Python中rsa._compat.is_integer方法的典型用法代码示例。如果您正苦于以下问题:Python _compat.is_integer方法的具体用法?Python _compat.is_integer怎么用?Python _compat.is_integer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rsa._compat
的用法示例。
在下文中一共展示了_compat.is_integer方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: assert_int
# 需要导入模块: from rsa import _compat [as 别名]
# 或者: from rsa._compat import is_integer [as 别名]
def assert_int(var, name):
if is_integer(var):
return
raise TypeError('%s should be an integer, not %s' % (name, var.__class__))
示例2: bit_size
# 需要导入模块: from rsa import _compat [as 别名]
# 或者: from rsa._compat import is_integer [as 别名]
def bit_size(num):
"""
Number of bits needed to represent a integer excluding any prefix
0 bits.
Usage::
>>> bit_size(1023)
10
>>> bit_size(1024)
11
>>> bit_size(1025)
11
:param num:
Integer value. If num is 0, returns 0. Only the absolute value of the
number is considered. Therefore, signed integers will be abs(num)
before the number's bit length is determined.
:returns:
Returns the number of bits in the integer.
"""
if num == 0:
return 0
if num < 0:
num = abs(num)
if not is_integer(num):
raise TypeError('not integer')
try:
return bit_length(num)
except AttributeError:
raise TypeError('bit_size(num) only supports integers, not %r' % type(num))
示例3: assert_int
# 需要导入模块: from rsa import _compat [as 别名]
# 或者: from rsa._compat import is_integer [as 别名]
def assert_int(var, name):
if is_integer(var):
return
raise TypeError('%s should be an integer, not %s' % (name, var.__class__))