本文整理匯總了Python中future_builtins.oct方法的典型用法代碼示例。如果您正苦於以下問題:Python future_builtins.oct方法的具體用法?Python future_builtins.oct怎麽用?Python future_builtins.oct使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類future_builtins
的用法示例。
在下文中一共展示了future_builtins.oct方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_access_token_credentials
# 需要導入模塊: import future_builtins [as 別名]
# 或者: from future_builtins import oct [as 別名]
def test_access_token_credentials(self):
access_token = 'foo'
user_agent = 'refresh_checker/1.0'
credentials = client.AccessTokenCredentials(access_token, user_agent)
storage = file_module.Storage(FILENAME)
credentials = storage.put(credentials)
credentials = storage.get()
self.assertIsNotNone(credentials)
self.assertEquals('foo', credentials.access_token)
self.assertTrue(os.path.exists(FILENAME))
if os.name == 'posix': # pragma: NO COVER
mode = os.stat(FILENAME).st_mode
self.assertEquals('0o600', oct(stat.S_IMODE(mode)))
示例2: test_oct
# 需要導入模塊: import future_builtins [as 別名]
# 或者: from future_builtins import oct [as 別名]
def test_oct(self):
self.assertEqual(oct(0), '0o0')
self.assertEqual(oct(100), '0o144')
self.assertEqual(oct(100L), '0o144')
self.assertEqual(oct(-100), '-0o144')
self.assertEqual(oct(-100L), '-0o144')
self.assertRaises(TypeError, oct, ())
示例3: oct
# 需要導入模塊: import future_builtins [as 別名]
# 或者: from future_builtins import oct [as 別名]
def oct(arg):
result = _builtin_oct(arg).rstrip('L')
if result == '0':
return '0o0'
i = result.index('0') + 1
return result[:i] + 'o' + result[i:]
示例4: test_pep19546
# 需要導入模塊: import future_builtins [as 別名]
# 或者: from future_builtins import oct [as 別名]
def test_pep19546():
'''
Just a small sanity test. CPython's test_int.py covers this PEP quite
well.
'''
#Octal
AreEqual(0O21, 17)
AreEqual(021, 0o21)
AreEqual(0O21, 0o21)
AreEqual(0o0, 0)
AreEqual(-0o1, -1)
AreEqual(0o17777777776, 2147483646)
AreEqual(0o17777777777, 2147483647)
AreEqual(0o20000000000, 2147483648)
AreEqual(-0o17777777777, -2147483647)
AreEqual(-0o20000000000, -2147483648)
AreEqual(-0o20000000001, -2147483649)
#Binary
AreEqual(0B11, 3)
AreEqual(0B11, 0b11)
AreEqual(0b0, 0)
AreEqual(-0b1, -1)
AreEqual(0b1111111111111111111111111111110, 2147483646)
AreEqual(0b1111111111111111111111111111111, 2147483647)
AreEqual(0b10000000000000000000000000000000, 2147483648)
AreEqual(-0b1111111111111111111111111111111, -2147483647)
AreEqual(-0b10000000000000000000000000000000, -2147483648)
AreEqual(-0b10000000000000000000000000000001, -2147483649)
#bin and future_builtins.oct
from future_builtins import oct as fb_oct
test_cases = [ (0B11, "0b11", "0o3"),
(2147483648, "0b10000000000000000000000000000000", "0o20000000000"),
(-2147483649L, "-0b10000000000000000000000000000001", "-0o20000000001"),
(-1L, "-0b1", "-0o1"),
(-0b10000000000000000000000000000000, "-0b10000000000000000000000000000000", "-0o20000000000"),
(-0o17777777777, "-0b1111111111111111111111111111111", "-0o17777777777"),
(0o17777777777, "0b1111111111111111111111111111111", "0o17777777777"),
]
for val, bin_exp, oct_exp in test_cases:
AreEqual(bin(val), bin_exp)
AreEqual(fb_oct(val), oct_exp)