本文整理汇总了Python中sys.maxunicode方法的典型用法代码示例。如果您正苦于以下问题:Python sys.maxunicode方法的具体用法?Python sys.maxunicode怎么用?Python sys.maxunicode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sys
的用法示例。
在下文中一共展示了sys.maxunicode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _pep425_get_abi
# 需要导入模块: import sys [as 别名]
# 或者: from sys import maxunicode [as 别名]
def _pep425_get_abi():
"""
:return:
A unicode string of the system abi. Will be something like: "cp27m",
"cp33m", etc.
"""
try:
soabi = sysconfig.get_config_var('SOABI')
if soabi:
if soabi.startswith('cpython-'):
return 'cp%s' % soabi.split('-')[1]
return soabi.replace('.', '_').replace('-', '_')
except (IOError, NameError):
pass
impl = _pep425_implementation()
suffix = ''
if impl == 'cp':
suffix += 'm'
if sys.maxunicode == 0x10ffff and sys.version_info < (3, 3):
suffix += 'u'
return '%s%s%s' % (impl, ''.join(map(str_cls, _pep425_version())), suffix)
示例2: test_invalid_escape_sequences
# 需要导入模块: import sys [as 别名]
# 或者: from sys import maxunicode [as 别名]
def test_invalid_escape_sequences(self):
# incomplete escape sequence
self.assertRaises(json.JSONDecodeError, json.loads, '"\\u')
self.assertRaises(json.JSONDecodeError, json.loads, '"\\u1')
self.assertRaises(json.JSONDecodeError, json.loads, '"\\u12')
self.assertRaises(json.JSONDecodeError, json.loads, '"\\u123')
self.assertRaises(json.JSONDecodeError, json.loads, '"\\u1234')
# invalid escape sequence
self.assertRaises(json.JSONDecodeError, json.loads, '"\\u123x"')
self.assertRaises(json.JSONDecodeError, json.loads, '"\\u12x4"')
self.assertRaises(json.JSONDecodeError, json.loads, '"\\u1x34"')
self.assertRaises(json.JSONDecodeError, json.loads, '"\\ux234"')
if sys.maxunicode > 65535:
# invalid escape sequence for low surrogate
self.assertRaises(json.JSONDecodeError, json.loads, '"\\ud800\\u"')
self.assertRaises(json.JSONDecodeError, json.loads, '"\\ud800\\u0"')
self.assertRaises(json.JSONDecodeError, json.loads, '"\\ud800\\u00"')
self.assertRaises(json.JSONDecodeError, json.loads, '"\\ud800\\u000"')
self.assertRaises(json.JSONDecodeError, json.loads, '"\\ud800\\u000x"')
self.assertRaises(json.JSONDecodeError, json.loads, '"\\ud800\\u00x0"')
self.assertRaises(json.JSONDecodeError, json.loads, '"\\ud800\\u0x00"')
self.assertRaises(json.JSONDecodeError, json.loads, '"\\ud800\\ux000"')
示例3: test_hasattr
# 需要导入模块: import sys [as 别名]
# 或者: from sys import maxunicode [as 别名]
def test_hasattr(self):
import sys
self.assertTrue(hasattr(sys, 'stdout'))
self.assertRaises(TypeError, hasattr, sys, 1)
self.assertRaises(TypeError, hasattr)
if have_unicode:
self.assertRaises(UnicodeError, hasattr, sys, unichr(sys.maxunicode))
# Check that hasattr allows SystemExit and KeyboardInterrupts by
class A:
def __getattr__(self, what):
raise KeyboardInterrupt
self.assertRaises(KeyboardInterrupt, hasattr, A(), "b")
class B:
def __getattr__(self, what):
raise SystemExit
self.assertRaises(SystemExit, hasattr, B(), "b")
示例4: test_backslashescape
# 需要导入模块: import sys [as 别名]
# 或者: from sys import maxunicode [as 别名]
def test_backslashescape(self):
# Does the same as the "unicode-escape" encoding, but with different
# base encodings.
sin = u"a\xac\u1234\u20ac\u8000"
if sys.maxunicode > 0xffff:
sin += unichr(sys.maxunicode)
sout = "a\\xac\\u1234\\u20ac\\u8000"
if sys.maxunicode > 0xffff:
sout += "\\U%08x" % sys.maxunicode
self.assertEqual(sin.encode("ascii", "backslashreplace"), sout)
sout = "a\xac\\u1234\\u20ac\\u8000"
if sys.maxunicode > 0xffff:
sout += "\\U%08x" % sys.maxunicode
self.assertEqual(sin.encode("latin-1", "backslashreplace"), sout)
sout = "a\xac\\u1234\xa4\\u8000"
if sys.maxunicode > 0xffff:
sout += "\\U%08x" % sys.maxunicode
self.assertEqual(sin.encode("iso-8859-15", "backslashreplace"), sout)
示例5: test_bug1251300
# 需要导入模块: import sys [as 别名]
# 或者: from sys import maxunicode [as 别名]
def test_bug1251300(self):
# Decoding with unicode_internal used to not correctly handle "code
# points" above 0x10ffff on UCS-4 builds.
if sys.maxunicode > 0xffff:
ok = [
("\x00\x10\xff\xff", u"\U0010ffff"),
("\x00\x00\x01\x01", u"\U00000101"),
("", u""),
]
not_ok = [
"\x7f\xff\xff\xff",
"\x80\x00\x00\x00",
"\x81\x00\x00\x00",
"\x00",
"\x00\x00\x00\x00\x00",
]
for internal, uni in ok:
if sys.byteorder == "little":
internal = "".join(reversed(internal))
self.assertEqual(uni, internal.decode("unicode_internal"))
for internal in not_ok:
if sys.byteorder == "little":
internal = "".join(reversed(internal))
self.assertRaises(UnicodeDecodeError, internal.decode,
"unicode_internal")
示例6: test_unichr
# 需要导入模块: import sys [as 别名]
# 或者: from sys import maxunicode [as 别名]
def test_unichr(self):
#Added the following to resolve Codeplex WorkItem #3220.
max_uni = sys.maxunicode
self.assertTrue(max_uni==0xFFFF or max_uni==0x10FFFF)
max_uni_plus_one = max_uni + 1
huger_than_max = 100000
max_ok_value = u'\uffff'
#special case for WorkItem #3220
if max_uni==0x10FFFF:
huger_than_max = 10000000
max_ok_value = u'\U0010FFFF'
self.assertRaises(ValueError, unichr, -1) # arg must be in the range [0...65535] or [0...1114111] inclusive
self.assertRaises(ValueError, unichr, max_uni_plus_one)
self.assertRaises(ValueError, unichr, huger_than_max)
self.assertTrue(unichr(0) == '\x00')
self.assertTrue(unichr(max_uni) == max_ok_value)
示例7: test_utf8_decode_valid_sequences
# 需要导入模块: import sys [as 别名]
# 或者: from sys import maxunicode [as 别名]
def test_utf8_decode_valid_sequences(self):
sequences = [
# single byte
('\x00', u'\x00'), ('a', u'a'), ('\x7f', u'\x7f'),
# 2 bytes
('\xc2\x80', u'\x80'), ('\xdf\xbf', u'\u07ff'),
# 3 bytes
('\xe0\xa0\x80', u'\u0800'), ('\xed\x9f\xbf', u'\ud7ff'),
('\xee\x80\x80', u'\uE000'), ('\xef\xbf\xbf', u'\uffff'),
# 4 bytes
('\xF0\x90\x80\x80', u'\U00010000'),
('\xf4\x8f\xbf\xbf', u'\U0010FFFF')
]
for seq, res in sequences:
self.assertEqual(seq.decode('utf-8'), res)
for ch in map(unichr, range(0, sys.maxunicode)):
self.assertEqual(ch, ch.encode('utf-8').decode('utf-8'))
示例8: property_chars
# 需要导入模块: import sys [as 别名]
# 或者: from sys import maxunicode [as 别名]
def property_chars(self, prefix):
return "".join(six.unichr(x) for x in range(sys.maxunicode)
if unicodedata.category(six.unichr(x)).startswith(prefix))
示例9: _fix_value
# 需要导入模块: import sys [as 别名]
# 或者: from sys import maxunicode [as 别名]
def _fix_value(self, value):
"""
Return a cleaned version of a value
according to the specification:
> Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]
See https://www.w3.org/TR/xml/#charsets
:param value: a value to clean
:return: the cleaned value
"""
if not self.__charrange or not self.__replacement:
if sys.maxunicode == 0xFFFF:
# Fix for python 2.x, surrogate pairs does not match in regex
self.__charrange = re.compile(u'^([\u0020-\uD7FF\u0009\u000A\u000D\uE000-\uFFFD]|[\uD800-\uDBFF][\uDC00-\uDFFF])*$')
# TODO: this regex is slightly wrong... surrogates are not matched as pairs.
self.__replacement = re.compile(u'[^\u0020-\uDBFF\u0009\u000A\u000D\uE000-\uFFFD\uDC00-\uDFFF]')
else:
self.__charrange = re.compile(u'^[\u0020-\uD7FF\u0009\u000A\u000D\uE000-\uFFFD\U00010000-\U0010FFFF]*$')
self.__replacement = re.compile(u'[^\u0020-\uD7FF\u0009\u000A\u000D\uE000-\uFFFD\U00010000-\U0010FFFF]')
# Reading string until \x00. This is the same as aapt does.
if "\x00" in value:
self.packerwarning = True
log.warning("Null byte found in attribute value at position {}: "
"Value(hex): '{}'".format(
value.find("\x00"),
binascii.hexlify(value.encode("utf-8"))))
value = value[:value.find("\x00")]
if not self.__charrange.match(value):
log.warning("Invalid character in value found. Replacing with '_'.")
self.packerwarning = True
value = self.__replacement.sub('_', value)
return value
示例10: get_abi_tag
# 需要导入模块: import sys [as 别名]
# 或者: from sys import maxunicode [as 别名]
def get_abi_tag():
"""Return the ABI tag based on SOABI (if available) or emulate SOABI
(CPython 2, PyPy)."""
soabi = get_config_var('SOABI')
impl = get_abbr_impl()
if not soabi and impl in ('cp', 'pp') and hasattr(sys, 'maxunicode'):
d = ''
m = ''
u = ''
if get_flag('Py_DEBUG',
lambda: hasattr(sys, 'gettotalrefcount'),
warn=(impl == 'cp')):
d = 'd'
if get_flag('WITH_PYMALLOC',
lambda: impl == 'cp',
warn=(impl == 'cp')):
m = 'm'
if get_flag('Py_UNICODE_SIZE',
lambda: sys.maxunicode == 0x10ffff,
expected=4,
warn=(impl == 'cp' and
sys.version_info < (3, 3))) \
and sys.version_info < (3, 3):
u = 'u'
abi = '%s%s%s%s%s' % (impl, get_impl_ver(), d, m, u)
elif soabi and soabi.startswith('cpython-'):
abi = 'cp' + soabi.split('-')[1]
elif soabi:
abi = soabi.replace('.', '_').replace('-', '_')
else:
abi = None
return abi
示例11: test_4
# 需要导入模块: import sys [as 别名]
# 或者: from sys import maxunicode [as 别名]
def test_4(self):
"test unicode ranges"
iters = 100000
out = Grammar('root /[\U0001f300-\U0001f5ff]/{%d}' % iters).generate()
if sys.maxunicode == 65535:
out = {out[i:i+2] for i in range(0, len(out), 2)}
else:
out = set(out)
self.assertEqual(set(out), set(unichr_(c) for c in range(0x1f300, 0x1f600)))
示例12: named_chars
# 需要导入模块: import sys [as 别名]
# 或者: from sys import maxunicode [as 别名]
def named_chars():
for code in range(sys.maxunicode):
char = chr(code)
name = unicodedata.name(char, None)
if name is not None:
yield char, name
示例13: property_chars
# 需要导入模块: import sys [as 别名]
# 或者: from sys import maxunicode [as 别名]
def property_chars(self, prefix):
return "".join(
six.unichr(x)
for x in range(sys.maxunicode)
if unicodedata.category(six.unichr(x)).startswith(prefix))
示例14: _fix_value
# 需要导入模块: import sys [as 别名]
# 或者: from sys import maxunicode [as 别名]
def _fix_value(self, value):
"""
Return a cleaned version of a value
according to the specification:
> Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]
See https://www.w3.org/TR/xml/#charsets
:param value: a value to clean
:return: the cleaned value
"""
if not self.__charrange or not self.__replacement:
if sys.maxunicode == 0xFFFF:
# Fix for python 2.x, surrogate pairs does not match in regex
self.__charrange = re.compile(
u'^([\u0020-\uD7FF\u0009\u000A\u000D\uE000-\uFFFD]|[\uD800-\uDBFF][\uDC00-\uDFFF])*$')
# TODO: this regex is slightly wrong... surrogates are not matched as pairs.
self.__replacement = re.compile(u'[^\u0020-\uDBFF\u0009\u000A\u000D\uE000-\uFFFD\uDC00-\uDFFF]')
else:
self.__charrange = re.compile(u'^[\u0020-\uD7FF\u0009\u000A\u000D\uE000-\uFFFD\U00010000-\U0010FFFF]*$')
self.__replacement = re.compile(u'[^\u0020-\uD7FF\u0009\u000A\u000D\uE000-\uFFFD\U00010000-\U0010FFFF]')
# Reading string until \x00. This is the same as aapt does.
if "\x00" in value:
self.packerwarning = True
log.warning(
"Null byte found in attribute value at position {}: "
"Value(hex): '{}'".format(
value.find("\x00"),
binascii.hexlify(value.encode("utf-8"))
)
)
value = value[:value.find("\x00")]
if not self.__charrange.match(value):
log.warning("Invalid character in value found. Replacing with '_'.")
self.packerwarning = True
value = self.__replacement.sub('_', value)
return value
示例15: get_abi_tag
# 需要导入模块: import sys [as 别名]
# 或者: from sys import maxunicode [as 别名]
def get_abi_tag():
"""Return the ABI tag based on SOABI (if available) or emulate SOABI
(CPython 2, PyPy)."""
soabi = get_config_var('SOABI')
impl = get_abbr_impl()
if not soabi and impl in {'cp', 'pp'} and hasattr(sys, 'maxunicode'):
d = ''
m = ''
u = ''
if get_flag('Py_DEBUG',
lambda: hasattr(sys, 'gettotalrefcount'),
warn=(impl == 'cp')):
d = 'd'
if get_flag('WITH_PYMALLOC',
lambda: impl == 'cp',
warn=(impl == 'cp')):
m = 'm'
if get_flag('Py_UNICODE_SIZE',
lambda: sys.maxunicode == 0x10ffff,
expected=4,
warn=(impl == 'cp' and
six.PY2)) \
and six.PY2:
u = 'u'
abi = '%s%s%s%s%s' % (impl, get_impl_ver(), d, m, u)
elif soabi and soabi.startswith('cpython-'):
abi = 'cp' + soabi.split('-')[1]
elif soabi:
abi = soabi.replace('.', '_').replace('-', '_')
else:
abi = None
return abi