12
cdef unicode text = u'abcäöüöéèâÁÀABC'
18
>>> default() == 'abcdefg'.encode()
21
return u'abcdefg'.encode()
23
def encode_non_constant(encoding):
25
>>> isinstance(encode_non_constant('utf8'), _bytes)
27
>>> encode_non_constant('utf8') == u.encode('UTF-8')
30
return text.encode(encoding)
32
@cython.test_assert_path_exists('//PythonCapiFunctionNode[@cname = "PyUnicode_AsUTF8String"]')
35
>>> isinstance(utf8(), _bytes)
37
>>> utf8() == u.encode('UTF-8')
40
return text.encode(u'UTF-8')
42
@cython.test_assert_path_exists('//PythonCapiFunctionNode[@cname = "PyUnicode_AsUTF8String"]')
45
>>> isinstance(utf8_strict(), _bytes)
47
>>> utf8_strict() == u.encode('UTF-8', 'strict')
50
return text.encode(u'UTF-8', u'strict')
52
@cython.test_assert_path_exists('//PythonCapiFunctionNode[@cname = "PyUnicode_AsUTF8String"]')
55
>>> isinstance(utf8_str_strict(), _bytes)
57
>>> utf8_str_strict() == u.encode('UTF-8', 'strict')
60
return text.encode('UTF-8', 'strict')
62
@cython.test_assert_path_exists('//PythonCapiFunctionNode[@cname = "PyUnicode_AsUTF8String"]')
63
def utf8_bytes_strict():
65
>>> isinstance(utf8_bytes_strict(), _bytes)
67
>>> utf8_bytes_strict() == u.encode('UTF-8', 'strict')
70
return text.encode(b'UTF-8', b'strict')
72
@cython.test_assert_path_exists('//PythonCapiFunctionNode[@cname = "PyUnicode_AsEncodedString"]')
75
>>> isinstance(ascii_replace(), _bytes)
77
>>> ascii_replace() == u.encode('ASCII', 'replace')
80
return text.encode(u'ASCII', u'replace')
84
>>> isinstance(cp850_strict(), _bytes)
86
>>> cp850_strict() == u.encode('cp850', 'strict')
89
return text.encode(u'cp850', u'strict')
91
@cython.test_assert_path_exists('//PythonCapiFunctionNode[@cname = "PyUnicode_AsLatin1String"]')
94
>>> isinstance(latin1(), _bytes)
96
>>> latin1() == u.encode('latin-1')
99
return text.encode(u'latin-1')
101
@cython.test_fail_if_path_exists('//PythonCapiFunctionNode', '//SimpleCallNode')
102
def latin1_constant():
104
>>> isinstance(latin1_constant(), _bytes)
106
>>> latin1_constant() == latin1()
109
return u'abcäöüöéèâÁÀABC'.encode('latin1')