annotate Objects/bytes_methods.c @ 87690:66c1c9f32567 default tip

Add use_weakref option to functools.lru_cache The use_weakref option makes lru_cache create weak references to the function arguments when creating the cache key, which prevents them from staying in the memory forever even after all other references to them are gone. This is a proof of concept for http://bugs.python.org/issue19859
author Radomir Dopieralski <devel@sheep.art.pl>
date Tue, 03 Dec 2013 16:02:48 +0100
parents e7f6cef7a4cc
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
1 #include "Python.h"
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
2 #include "bytes_methods.h"
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
3
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
4 PyDoc_STRVAR_shared(_Py_isspace__doc__,
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
5 "B.isspace() -> bool\n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
6 \n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
7 Return True if all characters in B are whitespace\n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
8 and there is at least one character in B, False otherwise.");
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
9
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
10 PyObject*
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
11 _Py_bytes_isspace(const char *cptr, Py_ssize_t len)
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
12 {
85157
e7f6cef7a4cc Issue #18722: Remove uses of the "register" keyword in C code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 74301
diff changeset
13 const unsigned char *p
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
14 = (unsigned char *) cptr;
85157
e7f6cef7a4cc Issue #18722: Remove uses of the "register" keyword in C code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 74301
diff changeset
15 const unsigned char *e;
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
16
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
17 /* Shortcut for single character strings */
53543
4b4b59f278bf Merged revisions 72040 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 53094
diff changeset
18 if (len == 1 && Py_ISSPACE(*p))
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
19 Py_RETURN_TRUE;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
20
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
21 /* Special case for empty strings */
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
22 if (len == 0)
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
23 Py_RETURN_FALSE;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
24
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
25 e = p + len;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
26 for (; p < e; p++) {
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 56515
diff changeset
27 if (!Py_ISSPACE(*p))
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
28 Py_RETURN_FALSE;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
29 }
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
30 Py_RETURN_TRUE;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
31 }
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
32
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
33
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
34 PyDoc_STRVAR_shared(_Py_isalpha__doc__,
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
35 "B.isalpha() -> bool\n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
36 \n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
37 Return True if all characters in B are alphabetic\n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
38 and there is at least one character in B, False otherwise.");
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
39
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
40 PyObject*
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
41 _Py_bytes_isalpha(const char *cptr, Py_ssize_t len)
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
42 {
85157
e7f6cef7a4cc Issue #18722: Remove uses of the "register" keyword in C code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 74301
diff changeset
43 const unsigned char *p
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
44 = (unsigned char *) cptr;
85157
e7f6cef7a4cc Issue #18722: Remove uses of the "register" keyword in C code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 74301
diff changeset
45 const unsigned char *e;
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
46
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
47 /* Shortcut for single character strings */
53543
4b4b59f278bf Merged revisions 72040 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 53094
diff changeset
48 if (len == 1 && Py_ISALPHA(*p))
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 56515
diff changeset
49 Py_RETURN_TRUE;
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
50
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
51 /* Special case for empty strings */
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
52 if (len == 0)
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 56515
diff changeset
53 Py_RETURN_FALSE;
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
54
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
55 e = p + len;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
56 for (; p < e; p++) {
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 56515
diff changeset
57 if (!Py_ISALPHA(*p))
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 56515
diff changeset
58 Py_RETURN_FALSE;
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
59 }
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
60 Py_RETURN_TRUE;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
61 }
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
62
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
63
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
64 PyDoc_STRVAR_shared(_Py_isalnum__doc__,
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
65 "B.isalnum() -> bool\n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
66 \n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
67 Return True if all characters in B are alphanumeric\n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
68 and there is at least one character in B, False otherwise.");
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
69
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
70 PyObject*
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
71 _Py_bytes_isalnum(const char *cptr, Py_ssize_t len)
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
72 {
85157
e7f6cef7a4cc Issue #18722: Remove uses of the "register" keyword in C code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 74301
diff changeset
73 const unsigned char *p
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
74 = (unsigned char *) cptr;
85157
e7f6cef7a4cc Issue #18722: Remove uses of the "register" keyword in C code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 74301
diff changeset
75 const unsigned char *e;
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
76
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
77 /* Shortcut for single character strings */
53543
4b4b59f278bf Merged revisions 72040 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 53094
diff changeset
78 if (len == 1 && Py_ISALNUM(*p))
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 56515
diff changeset
79 Py_RETURN_TRUE;
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
80
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
81 /* Special case for empty strings */
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
82 if (len == 0)
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 56515
diff changeset
83 Py_RETURN_FALSE;
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
84
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
85 e = p + len;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
86 for (; p < e; p++) {
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 56515
diff changeset
87 if (!Py_ISALNUM(*p))
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 56515
diff changeset
88 Py_RETURN_FALSE;
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
89 }
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
90 Py_RETURN_TRUE;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
91 }
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
92
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
93
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
94 PyDoc_STRVAR_shared(_Py_isdigit__doc__,
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
95 "B.isdigit() -> bool\n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
96 \n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
97 Return True if all characters in B are digits\n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
98 and there is at least one character in B, False otherwise.");
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
99
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
100 PyObject*
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
101 _Py_bytes_isdigit(const char *cptr, Py_ssize_t len)
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
102 {
85157
e7f6cef7a4cc Issue #18722: Remove uses of the "register" keyword in C code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 74301
diff changeset
103 const unsigned char *p
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
104 = (unsigned char *) cptr;
85157
e7f6cef7a4cc Issue #18722: Remove uses of the "register" keyword in C code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 74301
diff changeset
105 const unsigned char *e;
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
106
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
107 /* Shortcut for single character strings */
53543
4b4b59f278bf Merged revisions 72040 via svnmerge from
Eric Smith <eric@trueblade.com>
parents: 53094
diff changeset
108 if (len == 1 && Py_ISDIGIT(*p))
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 56515
diff changeset
109 Py_RETURN_TRUE;
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
110
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
111 /* Special case for empty strings */
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
112 if (len == 0)
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 56515
diff changeset
113 Py_RETURN_FALSE;
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
114
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
115 e = p + len;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
116 for (; p < e; p++) {
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 56515
diff changeset
117 if (!Py_ISDIGIT(*p))
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 56515
diff changeset
118 Py_RETURN_FALSE;
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
119 }
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
120 Py_RETURN_TRUE;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
121 }
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
122
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
123
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
124 PyDoc_STRVAR_shared(_Py_islower__doc__,
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
125 "B.islower() -> bool\n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
126 \n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
127 Return True if all cased characters in B are lowercase and there is\n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
128 at least one cased character in B, False otherwise.");
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
129
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
130 PyObject*
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
131 _Py_bytes_islower(const char *cptr, Py_ssize_t len)
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
132 {
85157
e7f6cef7a4cc Issue #18722: Remove uses of the "register" keyword in C code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 74301
diff changeset
133 const unsigned char *p
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
134 = (unsigned char *) cptr;
85157
e7f6cef7a4cc Issue #18722: Remove uses of the "register" keyword in C code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 74301
diff changeset
135 const unsigned char *e;
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
136 int cased;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
137
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
138 /* Shortcut for single character strings */
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
139 if (len == 1)
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 56515
diff changeset
140 return PyBool_FromLong(Py_ISLOWER(*p));
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
141
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
142 /* Special case for empty strings */
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
143 if (len == 0)
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 56515
diff changeset
144 Py_RETURN_FALSE;
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
145
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
146 e = p + len;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
147 cased = 0;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
148 for (; p < e; p++) {
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 56515
diff changeset
149 if (Py_ISUPPER(*p))
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 56515
diff changeset
150 Py_RETURN_FALSE;
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 56515
diff changeset
151 else if (!cased && Py_ISLOWER(*p))
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 56515
diff changeset
152 cased = 1;
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
153 }
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
154 return PyBool_FromLong(cased);
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
155 }
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
156
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
157
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
158 PyDoc_STRVAR_shared(_Py_isupper__doc__,
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
159 "B.isupper() -> bool\n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
160 \n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
161 Return True if all cased characters in B are uppercase and there is\n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
162 at least one cased character in B, False otherwise.");
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
163
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
164 PyObject*
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
165 _Py_bytes_isupper(const char *cptr, Py_ssize_t len)
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
166 {
85157
e7f6cef7a4cc Issue #18722: Remove uses of the "register" keyword in C code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 74301
diff changeset
167 const unsigned char *p
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
168 = (unsigned char *) cptr;
85157
e7f6cef7a4cc Issue #18722: Remove uses of the "register" keyword in C code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 74301
diff changeset
169 const unsigned char *e;
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
170 int cased;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
171
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
172 /* Shortcut for single character strings */
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
173 if (len == 1)
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 56515
diff changeset
174 return PyBool_FromLong(Py_ISUPPER(*p));
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
175
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
176 /* Special case for empty strings */
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
177 if (len == 0)
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 56515
diff changeset
178 Py_RETURN_FALSE;
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
179
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
180 e = p + len;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
181 cased = 0;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
182 for (; p < e; p++) {
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 56515
diff changeset
183 if (Py_ISLOWER(*p))
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 56515
diff changeset
184 Py_RETURN_FALSE;
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 56515
diff changeset
185 else if (!cased && Py_ISUPPER(*p))
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 56515
diff changeset
186 cased = 1;
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
187 }
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
188 return PyBool_FromLong(cased);
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
189 }
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
190
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
191
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
192 PyDoc_STRVAR_shared(_Py_istitle__doc__,
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
193 "B.istitle() -> bool\n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
194 \n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
195 Return True if B is a titlecased string and there is at least one\n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
196 character in B, i.e. uppercase characters may only follow uncased\n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
197 characters and lowercase characters only cased ones. Return False\n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
198 otherwise.");
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
199
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
200 PyObject*
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
201 _Py_bytes_istitle(const char *cptr, Py_ssize_t len)
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
202 {
85157
e7f6cef7a4cc Issue #18722: Remove uses of the "register" keyword in C code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 74301
diff changeset
203 const unsigned char *p
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
204 = (unsigned char *) cptr;
85157
e7f6cef7a4cc Issue #18722: Remove uses of the "register" keyword in C code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 74301
diff changeset
205 const unsigned char *e;
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
206 int cased, previous_is_cased;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
207
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
208 /* Shortcut for single character strings */
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
209 if (len == 1)
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 56515
diff changeset
210 return PyBool_FromLong(Py_ISUPPER(*p));
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
211
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
212 /* Special case for empty strings */
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
213 if (len == 0)
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 56515
diff changeset
214 Py_RETURN_FALSE;
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
215
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
216 e = p + len;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
217 cased = 0;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
218 previous_is_cased = 0;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
219 for (; p < e; p++) {
85157
e7f6cef7a4cc Issue #18722: Remove uses of the "register" keyword in C code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 74301
diff changeset
220 const unsigned char ch = *p;
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
221
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 56515
diff changeset
222 if (Py_ISUPPER(ch)) {
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 56515
diff changeset
223 if (previous_is_cased)
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 56515
diff changeset
224 Py_RETURN_FALSE;
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 56515
diff changeset
225 previous_is_cased = 1;
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 56515
diff changeset
226 cased = 1;
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 56515
diff changeset
227 }
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 56515
diff changeset
228 else if (Py_ISLOWER(ch)) {
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 56515
diff changeset
229 if (!previous_is_cased)
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 56515
diff changeset
230 Py_RETURN_FALSE;
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 56515
diff changeset
231 previous_is_cased = 1;
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 56515
diff changeset
232 cased = 1;
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 56515
diff changeset
233 }
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 56515
diff changeset
234 else
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 56515
diff changeset
235 previous_is_cased = 0;
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
236 }
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
237 return PyBool_FromLong(cased);
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
238 }
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
239
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
240
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
241 PyDoc_STRVAR_shared(_Py_lower__doc__,
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
242 "B.lower() -> copy of B\n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
243 \n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
244 Return a copy of B with all ASCII characters converted to lowercase.");
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
245
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
246 void
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
247 _Py_bytes_lower(char *result, const char *cptr, Py_ssize_t len)
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
248 {
64042
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
249 Py_ssize_t i;
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
250
64042
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
251 for (i = 0; i < len; i++) {
74301
9683d59170ee Issue #13738: Simplify implementation of bytes.lower() and bytes.upper().
Antoine Pitrou <solipsis@pitrou.net>
parents: 71016
diff changeset
252 result[i] = Py_TOLOWER((unsigned char) cptr[i]);
64042
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
253 }
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
254 }
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
255
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
256
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
257 PyDoc_STRVAR_shared(_Py_upper__doc__,
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
258 "B.upper() -> copy of B\n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
259 \n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
260 Return a copy of B with all ASCII characters converted to uppercase.");
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
261
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
262 void
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
263 _Py_bytes_upper(char *result, const char *cptr, Py_ssize_t len)
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
264 {
64042
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
265 Py_ssize_t i;
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
266
64042
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
267 for (i = 0; i < len; i++) {
74301
9683d59170ee Issue #13738: Simplify implementation of bytes.lower() and bytes.upper().
Antoine Pitrou <solipsis@pitrou.net>
parents: 71016
diff changeset
268 result[i] = Py_TOUPPER((unsigned char) cptr[i]);
64042
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
269 }
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
270 }
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
271
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
272
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
273 PyDoc_STRVAR_shared(_Py_title__doc__,
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
274 "B.title() -> copy of B\n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
275 \n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
276 Return a titlecased version of B, i.e. ASCII words start with uppercase\n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
277 characters, all remaining cased characters have lowercase.");
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
278
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
279 void
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
280 _Py_bytes_title(char *result, char *s, Py_ssize_t len)
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
281 {
64042
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
282 Py_ssize_t i;
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
283 int previous_is_cased = 0;
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
284
64042
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
285 for (i = 0; i < len; i++) {
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
286 int c = Py_CHARMASK(*s++);
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
287 if (Py_ISLOWER(c)) {
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
288 if (!previous_is_cased)
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
289 c = Py_TOUPPER(c);
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
290 previous_is_cased = 1;
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
291 } else if (Py_ISUPPER(c)) {
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
292 if (previous_is_cased)
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
293 c = Py_TOLOWER(c);
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
294 previous_is_cased = 1;
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
295 } else
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
296 previous_is_cased = 0;
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
297 *result++ = c;
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
298 }
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
299 }
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
300
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
301
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
302 PyDoc_STRVAR_shared(_Py_capitalize__doc__,
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
303 "B.capitalize() -> copy of B\n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
304 \n\
62802
cf4f7f98f19e Fix the docstrings of the capitalize method.
Senthil Kumaran <orsenthil@gmail.com>
parents: 61466
diff changeset
305 Return a copy of B with only its first character capitalized (ASCII)\n\
cf4f7f98f19e Fix the docstrings of the capitalize method.
Senthil Kumaran <orsenthil@gmail.com>
parents: 61466
diff changeset
306 and the rest lower-cased.");
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
307
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
308 void
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
309 _Py_bytes_capitalize(char *result, char *s, Py_ssize_t len)
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
310 {
64042
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
311 Py_ssize_t i;
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
312
64042
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
313 if (0 < len) {
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
314 int c = Py_CHARMASK(*s++);
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
315 if (Py_ISLOWER(c))
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
316 *result = Py_TOUPPER(c);
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
317 else
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
318 *result = c;
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
319 result++;
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
320 }
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
321 for (i = 1; i < len; i++) {
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
322 int c = Py_CHARMASK(*s++);
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
323 if (Py_ISUPPER(c))
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
324 *result = Py_TOLOWER(c);
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
325 else
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
326 *result = c;
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
327 result++;
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
328 }
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
329 }
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
330
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
331
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
332 PyDoc_STRVAR_shared(_Py_swapcase__doc__,
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
333 "B.swapcase() -> copy of B\n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
334 \n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
335 Return a copy of B with uppercase ASCII characters converted\n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
336 to lowercase ASCII and vice versa.");
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
337
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
338 void
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
339 _Py_bytes_swapcase(char *result, char *s, Py_ssize_t len)
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
340 {
64042
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
341 Py_ssize_t i;
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
342
64042
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
343 for (i = 0; i < len; i++) {
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
344 int c = Py_CHARMASK(*s++);
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
345 if (Py_ISLOWER(c)) {
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
346 *result = Py_TOUPPER(c);
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 56515
diff changeset
347 }
64042
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
348 else if (Py_ISUPPER(c)) {
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
349 *result = Py_TOLOWER(c);
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
350 }
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
351 else
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
352 *result = c;
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
353 result++;
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
354 }
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
355 }
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
356
53094
4407e4d07084 Add bytes/bytearray.maketrans() to mirror str.maketrans(), and deprecate
Georg Brandl <georg@python.org>
parents: 47301
diff changeset
357
4407e4d07084 Add bytes/bytearray.maketrans() to mirror str.maketrans(), and deprecate
Georg Brandl <georg@python.org>
parents: 47301
diff changeset
358 PyDoc_STRVAR_shared(_Py_maketrans__doc__,
4407e4d07084 Add bytes/bytearray.maketrans() to mirror str.maketrans(), and deprecate
Georg Brandl <georg@python.org>
parents: 47301
diff changeset
359 "B.maketrans(frm, to) -> translation table\n\
4407e4d07084 Add bytes/bytearray.maketrans() to mirror str.maketrans(), and deprecate
Georg Brandl <georg@python.org>
parents: 47301
diff changeset
360 \n\
71016
586745894ab8 Fix closes Issue12385 - Clarify maketrans method docstring for bytes and bytearray object.
Senthil Kumaran <senthil@uthcode.com>
parents: 64044
diff changeset
361 Return a translation table (a bytes object of length 256) suitable\n\
586745894ab8 Fix closes Issue12385 - Clarify maketrans method docstring for bytes and bytearray object.
Senthil Kumaran <senthil@uthcode.com>
parents: 64044
diff changeset
362 for use in the bytes or bytearray translate method where each byte\n\
586745894ab8 Fix closes Issue12385 - Clarify maketrans method docstring for bytes and bytearray object.
Senthil Kumaran <senthil@uthcode.com>
parents: 64044
diff changeset
363 in frm is mapped to the byte at the same position in to.\n\
586745894ab8 Fix closes Issue12385 - Clarify maketrans method docstring for bytes and bytearray object.
Senthil Kumaran <senthil@uthcode.com>
parents: 64044
diff changeset
364 The bytes objects frm and to must be of the same length.");
53094
4407e4d07084 Add bytes/bytearray.maketrans() to mirror str.maketrans(), and deprecate
Georg Brandl <georg@python.org>
parents: 47301
diff changeset
365
4407e4d07084 Add bytes/bytearray.maketrans() to mirror str.maketrans(), and deprecate
Georg Brandl <georg@python.org>
parents: 47301
diff changeset
366 static Py_ssize_t
4407e4d07084 Add bytes/bytearray.maketrans() to mirror str.maketrans(), and deprecate
Georg Brandl <georg@python.org>
parents: 47301
diff changeset
367 _getbuffer(PyObject *obj, Py_buffer *view)
4407e4d07084 Add bytes/bytearray.maketrans() to mirror str.maketrans(), and deprecate
Georg Brandl <georg@python.org>
parents: 47301
diff changeset
368 {
4407e4d07084 Add bytes/bytearray.maketrans() to mirror str.maketrans(), and deprecate
Georg Brandl <georg@python.org>
parents: 47301
diff changeset
369 PyBufferProcs *buffer = Py_TYPE(obj)->tp_as_buffer;
4407e4d07084 Add bytes/bytearray.maketrans() to mirror str.maketrans(), and deprecate
Georg Brandl <georg@python.org>
parents: 47301
diff changeset
370
4407e4d07084 Add bytes/bytearray.maketrans() to mirror str.maketrans(), and deprecate
Georg Brandl <georg@python.org>
parents: 47301
diff changeset
371 if (buffer == NULL || buffer->bf_getbuffer == NULL)
4407e4d07084 Add bytes/bytearray.maketrans() to mirror str.maketrans(), and deprecate
Georg Brandl <georg@python.org>
parents: 47301
diff changeset
372 {
4407e4d07084 Add bytes/bytearray.maketrans() to mirror str.maketrans(), and deprecate
Georg Brandl <georg@python.org>
parents: 47301
diff changeset
373 PyErr_Format(PyExc_TypeError,
4407e4d07084 Add bytes/bytearray.maketrans() to mirror str.maketrans(), and deprecate
Georg Brandl <georg@python.org>
parents: 47301
diff changeset
374 "Type %.100s doesn't support the buffer API",
4407e4d07084 Add bytes/bytearray.maketrans() to mirror str.maketrans(), and deprecate
Georg Brandl <georg@python.org>
parents: 47301
diff changeset
375 Py_TYPE(obj)->tp_name);
4407e4d07084 Add bytes/bytearray.maketrans() to mirror str.maketrans(), and deprecate
Georg Brandl <georg@python.org>
parents: 47301
diff changeset
376 return -1;
4407e4d07084 Add bytes/bytearray.maketrans() to mirror str.maketrans(), and deprecate
Georg Brandl <georg@python.org>
parents: 47301
diff changeset
377 }
4407e4d07084 Add bytes/bytearray.maketrans() to mirror str.maketrans(), and deprecate
Georg Brandl <georg@python.org>
parents: 47301
diff changeset
378
4407e4d07084 Add bytes/bytearray.maketrans() to mirror str.maketrans(), and deprecate
Georg Brandl <georg@python.org>
parents: 47301
diff changeset
379 if (buffer->bf_getbuffer(obj, view, PyBUF_SIMPLE) < 0)
64042
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
380 return -1;
53094
4407e4d07084 Add bytes/bytearray.maketrans() to mirror str.maketrans(), and deprecate
Georg Brandl <georg@python.org>
parents: 47301
diff changeset
381 return view->len;
4407e4d07084 Add bytes/bytearray.maketrans() to mirror str.maketrans(), and deprecate
Georg Brandl <georg@python.org>
parents: 47301
diff changeset
382 }
4407e4d07084 Add bytes/bytearray.maketrans() to mirror str.maketrans(), and deprecate
Georg Brandl <georg@python.org>
parents: 47301
diff changeset
383
4407e4d07084 Add bytes/bytearray.maketrans() to mirror str.maketrans(), and deprecate
Georg Brandl <georg@python.org>
parents: 47301
diff changeset
384 PyObject *
4407e4d07084 Add bytes/bytearray.maketrans() to mirror str.maketrans(), and deprecate
Georg Brandl <georg@python.org>
parents: 47301
diff changeset
385 _Py_bytes_maketrans(PyObject *args)
4407e4d07084 Add bytes/bytearray.maketrans() to mirror str.maketrans(), and deprecate
Georg Brandl <georg@python.org>
parents: 47301
diff changeset
386 {
64042
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
387 PyObject *frm, *to, *res = NULL;
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
388 Py_buffer bfrm, bto;
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
389 Py_ssize_t i;
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
390 char *p;
61466
cab14be0ada1 Recorded merge of revisions 81029 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents: 56515
diff changeset
391
64042
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
392 bfrm.len = -1;
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
393 bto.len = -1;
53094
4407e4d07084 Add bytes/bytearray.maketrans() to mirror str.maketrans(), and deprecate
Georg Brandl <georg@python.org>
parents: 47301
diff changeset
394
64042
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
395 if (!PyArg_ParseTuple(args, "OO:maketrans", &frm, &to))
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
396 return NULL;
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
397 if (_getbuffer(frm, &bfrm) < 0)
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
398 return NULL;
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
399 if (_getbuffer(to, &bto) < 0)
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
400 goto done;
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
401 if (bfrm.len != bto.len) {
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
402 PyErr_Format(PyExc_ValueError,
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
403 "maketrans arguments must have same length");
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
404 goto done;
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
405 }
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
406 res = PyBytes_FromStringAndSize(NULL, 256);
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
407 if (!res) {
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
408 goto done;
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
409 }
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
410 p = PyBytes_AS_STRING(res);
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
411 for (i = 0; i < 256; i++)
64044
98686b10314e Fix (harmless) warning with MSVC.
Antoine Pitrou <solipsis@pitrou.net>
parents: 64042
diff changeset
412 p[i] = (char) i;
64042
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
413 for (i = 0; i < bfrm.len; i++) {
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
414 p[((unsigned char *)bfrm.buf)[i]] = ((char *)bto.buf)[i];
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
415 }
53094
4407e4d07084 Add bytes/bytearray.maketrans() to mirror str.maketrans(), and deprecate
Georg Brandl <georg@python.org>
parents: 47301
diff changeset
416
64042
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
417 done:
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
418 if (bfrm.len != -1)
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
419 PyBuffer_Release(&bfrm);
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
420 if (bto.len != -1)
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
421 PyBuffer_Release(&bto);
e783c7d5ae36 Fix indentation and remove dead code.
Antoine Pitrou <solipsis@pitrou.net>
parents: 62802
diff changeset
422 return res;
53094
4407e4d07084 Add bytes/bytearray.maketrans() to mirror str.maketrans(), and deprecate
Georg Brandl <georg@python.org>
parents: 47301
diff changeset
423 }