Python sys.maxunicode() Examples
The following are 30 code examples for showing how to use sys.maxunicode(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.
You may check out the related API usage on the sidebar.
You may also want to check out all available functions/classes of the module
sys
, or try the search function
.
Example 1
Project: oscrypto Author: wbond File: _pep425.py License: MIT License | 6 votes |
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)
Example 2
Project: qgis-cartodb Author: gkudos File: test_unicode.py License: GNU General Public License v2.0 | 6 votes |
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"')
Example 3
Project: ironpython2 Author: IronLanguages File: test_builtin.py License: Apache License 2.0 | 6 votes |
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")
Example 4
Project: ironpython2 Author: IronLanguages File: test_codeccallbacks.py License: Apache License 2.0 | 6 votes |
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)
Example 5
Project: ironpython2 Author: IronLanguages File: test_codecs.py License: Apache License 2.0 | 6 votes |
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")
Example 6
Project: ironpython2 Author: IronLanguages File: test_builtinfunc.py License: Apache License 2.0 | 6 votes |
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)
Example 7
Project: BinderFilter Author: dxwu File: test_builtin.py License: MIT License | 6 votes |
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")
Example 8
Project: BinderFilter Author: dxwu File: test_unicode.py License: MIT License | 6 votes |
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'))
Example 9
Project: BinderFilter Author: dxwu File: test_codeccallbacks.py License: MIT License | 6 votes |
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)
Example 10
Project: BinderFilter Author: dxwu File: test_codecs.py License: MIT License | 6 votes |
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")
Example 11
Project: oss-ftp Author: aliyun File: test_builtin.py License: MIT License | 6 votes |
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")
Example 12
Project: fine-lm Author: akzaidi File: bleu_hook.py License: MIT License | 5 votes |
def property_chars(self, prefix): return "".join(six.unichr(x) for x in range(sys.maxunicode) if unicodedata.category(six.unichr(x)).startswith(prefix))
Example 13
Project: dcc Author: amimo File: __init__.py License: Apache License 2.0 | 5 votes |
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
Example 14
Project: recruit Author: Frank-qlu File: pep425tags.py License: Apache License 2.0 | 5 votes |
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
Example 15
Project: avalanche Author: MozillaSecurity File: test_avalanche.py License: Apache License 2.0 | 5 votes |
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)))
Example 16
Project: jbox Author: jpush File: pep425tags.py License: MIT License | 5 votes |
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
Example 17
Project: jbox Author: jpush File: pep425tags.py License: MIT License | 5 votes |
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
Example 18
Project: concurrency2017 Author: fluentpython File: signs.py License: MIT License | 5 votes |
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
Example 19
Project: lingvo Author: tensorflow File: ml_perf_bleu_metric.py License: Apache License 2.0 | 5 votes |
def property_chars(self, prefix): return "".join( six.unichr(x) for x in range(sys.maxunicode) if unicodedata.category(six.unichr(x)).startswith(prefix))
Example 20
Project: python-netsurv Author: sofia-netsurv File: pep425tags.py License: MIT License | 5 votes |
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
Example 21
Project: python-netsurv Author: sofia-netsurv File: pep425tags.py License: MIT License | 5 votes |
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
Example 22
Project: pyaxmlparser Author: appknox File: axmlprinter.py License: Apache License 2.0 | 5 votes |
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
Example 23
Project: lambda-packs Author: ryfeus File: pep425tags.py License: MIT License | 5 votes |
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
Example 24
Project: poetry Author: python-poetry File: tags.py License: MIT License | 5 votes |
def get_abi_tag(env): """Return the ABI tag based on SOABI (if available) or emulate SOABI (CPython 2, PyPy).""" soabi = env.config_var("SOABI") impl = get_abbr_impl(env) if not soabi and impl in ("cp", "pp") and hasattr(sys, "maxunicode"): d = "" m = "" u = "" if get_flag( env, "Py_DEBUG", lambda: hasattr(sys, "gettotalrefcount"), warn=(impl == "cp" and env.version_info < (3, 8)), ): d = "d" if env.version_info < (3, 8): if get_flag( env, "WITH_PYMALLOC", lambda: impl == "cp", warn=(impl == "cp") ): m = "m" if get_flag( env, "Py_UNICODE_SIZE", lambda: sys.maxunicode == 0x10FFFF, expected=4, warn=(impl == "cp" and env.version_info < (3, 3)), ) and env.version_info < (3, 3): u = "u" abi = "%s%s%s%s%s" % (impl, get_impl_ver(env), 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
Example 25
Project: ironpython2 Author: IronLanguages File: test_builtin.py License: Apache License 2.0 | 5 votes |
def test_getattr(self): import sys self.assertTrue(getattr(sys, 'stdout') is sys.stdout) self.assertRaises(TypeError, getattr, sys, 1) self.assertRaises(TypeError, getattr, sys, 1, "foo") self.assertRaises(TypeError, getattr) if have_unicode: self.assertRaises(UnicodeError, getattr, sys, unichr(sys.maxunicode))
Example 26
Project: ironpython2 Author: IronLanguages File: test_builtin.py License: Apache License 2.0 | 5 votes |
def test_ord(self): self.assertEqual(ord(' '), 32) self.assertEqual(ord('A'), 65) self.assertEqual(ord('a'), 97) if have_unicode: self.assertEqual(ord(unichr(sys.maxunicode)), sys.maxunicode) self.assertRaises(TypeError, ord, 42) if have_unicode: self.assertRaises(TypeError, ord, unicode("12"))
Example 27
Project: ironpython2 Author: IronLanguages File: test_builtin.py License: Apache License 2.0 | 5 votes |
def test_unichr(self): if have_unicode: self.assertEqual(unichr(32), unicode(' ')) self.assertEqual(unichr(65), unicode('A')) self.assertEqual(unichr(97), unicode('a')) self.assertEqual( unichr(sys.maxunicode), unicode('\\U%08x' % (sys.maxunicode), 'unicode-escape') ) self.assertRaises(ValueError, unichr, sys.maxunicode+1) self.assertRaises(TypeError, unichr) self.assertRaises((OverflowError, ValueError), unichr, 2**32) # We don't want self in vars(), so these are static methods
Example 28
Project: ironpython2 Author: IronLanguages File: test_unicode.py License: Apache License 2.0 | 5 votes |
def test_raiseMemError(self): # Ensure that the freelist contains a consistent object, even # when a string allocation fails with a MemoryError. # This used to crash the interpreter, # or leak references when the number was smaller. charwidth = 4 if sys.maxunicode >= 0x10000 else 2 # Note: sys.maxsize is half of the actual max allocation because of # the signedness of Py_ssize_t. alloc = lambda: u"a" * (sys.maxsize // charwidth * 2) self.assertRaises(MemoryError, alloc) self.assertRaises(MemoryError, alloc)
Example 29
Project: ironpython2 Author: IronLanguages File: test_codeccallbacks.py License: Apache License 2.0 | 5 votes |
def test_decodeunicodeinternal(self): self.assertRaises( UnicodeDecodeError, "\x00\x00\x00\x00\x00".decode, "unicode-internal", ) if sys.maxunicode > 0xffff: def handler_unicodeinternal(exc): if not isinstance(exc, UnicodeDecodeError): raise TypeError("don't know how to handle %r" % exc) return (u"\x01", 1) self.assertEqual( "\x00\x00\x00\x00\x00".decode("unicode-internal", "ignore"), u"\u0000" ) self.assertEqual( "\x00\x00\x00\x00\x00".decode("unicode-internal", "replace"), u"\u0000\ufffd" ) codecs.register_error("test.hui", handler_unicodeinternal) self.assertEqual( "\x00\x00\x00\x00\x00".decode("unicode-internal", "test.hui"), u"\u0000\u0001\u0000" )
Example 30
Project: ironpython2 Author: IronLanguages File: test_codeccallbacks.py License: Apache License 2.0 | 5 votes |
def test_unicodeencodeerror(self): self.check_exceptionobjectargs( UnicodeEncodeError, ["ascii", u"g\xfcrk", 1, 2, "ouch"], "'ascii' codec can't encode character u'\\xfc' in position 1: ouch" ) self.check_exceptionobjectargs( UnicodeEncodeError, ["ascii", u"g\xfcrk", 1, 4, "ouch"], "'ascii' codec can't encode characters in position 1-3: ouch" ) self.check_exceptionobjectargs( UnicodeEncodeError, ["ascii", u"\xfcx", 0, 1, "ouch"], "'ascii' codec can't encode character u'\\xfc' in position 0: ouch" ) self.check_exceptionobjectargs( UnicodeEncodeError, ["ascii", u"\u0100x", 0, 1, "ouch"], "'ascii' codec can't encode character u'\\u0100' in position 0: ouch" ) self.check_exceptionobjectargs( UnicodeEncodeError, ["ascii", u"\uffffx", 0, 1, "ouch"], "'ascii' codec can't encode character u'\\uffff' in position 0: ouch" ) if sys.maxunicode > 0xffff: self.check_exceptionobjectargs( UnicodeEncodeError, ["ascii", u"\U00010000x", 0, 1, "ouch"], "'ascii' codec can't encode character u'\\U00010000' in position 0: ouch" )