1# -*- coding: utf-8 -*-
2
3cimport cython
4
5unicode_str = u'ab jd  üöä ôñ ÄÖ'
6bytes_str   = b'ab jd  sdflk as sa  sadas asdas fsdf '
7
8_frozenset = frozenset
9_set = set
10
11@cython.test_assert_path_exists(
12    "//CoerceToPyTypeNode",
13    "//PythonCapiCallNode")
14def len_unicode(unicode s):
15    """
16    >>> len(unicode_str)
17    16
18    >>> len_unicode(unicode_str)
19    16
20    >>> len_unicode(None)
21    Traceback (most recent call last):
22    TypeError: object of type 'NoneType' has no len()
23    """
24    return len(s)
25
26@cython.test_assert_path_exists(
27    "//CoerceToPyTypeNode",
28    "//PythonCapiCallNode")
29def len_bytes(bytes s):
30    """
31    >>> len(bytes_str)
32    37
33    >>> len_bytes(bytes_str)
34    37
35    >>> len_bytes(None)
36    Traceback (most recent call last):
37    TypeError: object of type 'NoneType' has no len()
38    """
39    return len(s)
40
41#@cython.test_assert_path_exists(
42#    "//CoerceToPyTypeNode",
43#    "//PythonCapiCallNode")
44def len_str(str s):
45    """
46    >>> len('abcdefg')
47    7
48    >>> len_str('abcdefg')
49    7
50    >>> len_unicode(None)
51    Traceback (most recent call last):
52    TypeError: object of type 'NoneType' has no len()
53    """
54    return len(s)
55
56@cython.test_assert_path_exists(
57    "//CoerceToPyTypeNode",
58    "//PythonCapiCallNode")
59def len_list(list s):
60    """
61    >>> l = [1,2,3,4]
62    >>> len(l)
63    4
64    >>> len_list(l)
65    4
66    >>> len_list(None)
67    Traceback (most recent call last):
68    TypeError: object of type 'NoneType' has no len()
69    """
70    return len(s)
71
72@cython.test_assert_path_exists(
73    "//CoerceToPyTypeNode",
74    "//PythonCapiCallNode")
75def len_tuple(tuple s):
76    """
77    >>> t = (1,2,3,4)
78    >>> len(t)
79    4
80    >>> len_tuple(t)
81    4
82    >>> len_tuple(None)
83    Traceback (most recent call last):
84    TypeError: object of type 'NoneType' has no len()
85    """
86    return len(s)
87
88@cython.test_assert_path_exists(
89    "//CoerceToPyTypeNode",
90    "//PythonCapiCallNode")
91def len_dict(dict s):
92    """
93    >>> d = dict(a=1, b=2, c=3, d=4)
94    >>> len(d)
95    4
96    >>> len_dict(d)
97    4
98    >>> len_dict(None)
99    Traceback (most recent call last):
100    TypeError: object of type 'NoneType' has no len()
101    """
102    return len(s)
103
104@cython.test_assert_path_exists(
105    "//CoerceToPyTypeNode",
106    "//PythonCapiCallNode")
107def len_set(set s):
108    """
109    >>> s = _set((1,2,3,4))
110    >>> len(s)
111    4
112    >>> len_set(s)
113    4
114    >>> len_set(None)
115    Traceback (most recent call last):
116    TypeError: object of type 'NoneType' has no len()
117    """
118    return len(s)
119
120@cython.test_assert_path_exists(
121    "//CoerceToPyTypeNode",
122    "//PythonCapiCallNode")
123def len_frozenset(frozenset s):
124    """
125    >>> s = _frozenset((1,2,3,4))
126    >>> len(s)
127    4
128    >>> len_frozenset(s)
129    4
130    >>> len_set(None)
131    Traceback (most recent call last):
132    TypeError: object of type 'NoneType' has no len()
133    """
134    return len(s)
135