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