本文整理匯總了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__))