1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
# mode: run
# tag: unicode
__doc__ = u"""
>>> u('test')
u'test'
>>> e
u''
>>> z
u'test'
>>> c('testing')
u'testing'
>>> subu('testing a Python subtype')
u'testing a Python subtype'
>>> sub('testing a Python subtype')
u'testing a Python subtype'
# >>> csubu('testing a C subtype')
# u'testing a C subtype'
# >>> csub('testing a C subtype')
# u'testing a C subtype'
"""
cimport cython
import sys
if sys.version_info[0] >= 3:
__doc__ = __doc__.replace(u" u'", u" '")
u = unicode
e = unicode()
z = unicode(u'test')
def c(string):
return unicode(string)
class subu(unicode):
pass
def sub(string):
return subu(string)
#cdef class csubu(unicode):
# pass
#def csub(string):
# return csubu(string)
@cython.test_fail_if_path_exists("//SimpleCallNode")
@cython.test_assert_path_exists("//PythonCapiCallNode")
def typed(unicode s):
"""
>>> print(typed(None))
None
>>> type(typed(None)) is u or type(typed(None))
True
>>> print(typed(u'abc'))
abc
>>> type(typed(u'abc')) is u or type(typed(u'abc'))
True
"""
return unicode(s)
@cython.test_fail_if_path_exists(
"//SimpleCallNode",
"//PythonCapiCallNode",
)
def typed_not_none(unicode s not None):
"""
>>> print(typed(u'abc'))
abc
>>> type(typed(u'abc')) is u or type(typed(u'abc'))
True
"""
return unicode(s)
|