Mercurial > cpython-lru_cache-weakref
annotate Objects/stringlib/partition.h @ 84007:dbfbdf2b5c19 3.3
Fix #17967: For ftp urls CWD to target instead of hopping to each directory
towards target. This fixes a bug where target is accessible, but parent
directories are restricted.
| author | Senthil Kumaran <senthil@uthcode.com> |
|---|---|
| date | Sat, 01 Jun 2013 08:27:06 -0700 |
| parents | 8beaa9a37387 |
| children | 9d9371d4ff7b |
| rev | line source |
|---|---|
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
1 /* stringlib: partition implementation */ |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
2 |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
3 #ifndef STRINGLIB_FASTSEARCH_H |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
4 #error must include "stringlib/fastsearch.h" before including this module |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
5 #endif |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
6 |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
7 Py_LOCAL_INLINE(PyObject*) |
| 72475 | 8 STRINGLIB(partition)(PyObject* str_obj, |
|
58289
5ca1948a8fd6
Merged revisions 77461 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58095
diff
changeset
|
9 const STRINGLIB_CHAR* str, Py_ssize_t str_len, |
|
5ca1948a8fd6
Merged revisions 77461 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58095
diff
changeset
|
10 PyObject* sep_obj, |
|
5ca1948a8fd6
Merged revisions 77461 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58095
diff
changeset
|
11 const STRINGLIB_CHAR* sep, Py_ssize_t sep_len) |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
12 { |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
13 PyObject* out; |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
14 Py_ssize_t pos; |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
15 |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
16 if (sep_len == 0) { |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
17 PyErr_SetString(PyExc_ValueError, "empty separator"); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
40450
diff
changeset
|
18 return NULL; |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
19 } |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
20 |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
21 out = PyTuple_New(3); |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
22 if (!out) |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
40450
diff
changeset
|
23 return NULL; |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
24 |
| 72475 | 25 pos = FASTSEARCH(str, str_len, sep, sep_len, -1, FAST_SEARCH); |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
26 |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
27 if (pos < 0) { |
|
58289
5ca1948a8fd6
Merged revisions 77461 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58095
diff
changeset
|
28 #if STRINGLIB_MUTABLE |
|
5ca1948a8fd6
Merged revisions 77461 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58095
diff
changeset
|
29 PyTuple_SET_ITEM(out, 0, STRINGLIB_NEW(str, str_len)); |
|
5ca1948a8fd6
Merged revisions 77461 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58095
diff
changeset
|
30 PyTuple_SET_ITEM(out, 1, STRINGLIB_NEW(NULL, 0)); |
|
5ca1948a8fd6
Merged revisions 77461 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58095
diff
changeset
|
31 PyTuple_SET_ITEM(out, 2, STRINGLIB_NEW(NULL, 0)); |
|
5ca1948a8fd6
Merged revisions 77461 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58095
diff
changeset
|
32 #else |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
40450
diff
changeset
|
33 Py_INCREF(str_obj); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
40450
diff
changeset
|
34 PyTuple_SET_ITEM(out, 0, (PyObject*) str_obj); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
40450
diff
changeset
|
35 Py_INCREF(STRINGLIB_EMPTY); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
40450
diff
changeset
|
36 PyTuple_SET_ITEM(out, 1, (PyObject*) STRINGLIB_EMPTY); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
40450
diff
changeset
|
37 Py_INCREF(STRINGLIB_EMPTY); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
40450
diff
changeset
|
38 PyTuple_SET_ITEM(out, 2, (PyObject*) STRINGLIB_EMPTY); |
|
58289
5ca1948a8fd6
Merged revisions 77461 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58095
diff
changeset
|
39 #endif |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
40450
diff
changeset
|
40 return out; |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
41 } |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
42 |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
43 PyTuple_SET_ITEM(out, 0, STRINGLIB_NEW(str, pos)); |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
44 Py_INCREF(sep_obj); |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
45 PyTuple_SET_ITEM(out, 1, sep_obj); |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
46 pos += sep_len; |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
47 PyTuple_SET_ITEM(out, 2, STRINGLIB_NEW(str + pos, str_len - pos)); |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
48 |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
49 if (PyErr_Occurred()) { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
40450
diff
changeset
|
50 Py_DECREF(out); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
40450
diff
changeset
|
51 return NULL; |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
52 } |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
53 |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
54 return out; |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
55 } |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
56 |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
57 Py_LOCAL_INLINE(PyObject*) |
| 72475 | 58 STRINGLIB(rpartition)(PyObject* str_obj, |
|
58289
5ca1948a8fd6
Merged revisions 77461 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58095
diff
changeset
|
59 const STRINGLIB_CHAR* str, Py_ssize_t str_len, |
|
5ca1948a8fd6
Merged revisions 77461 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58095
diff
changeset
|
60 PyObject* sep_obj, |
|
5ca1948a8fd6
Merged revisions 77461 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58095
diff
changeset
|
61 const STRINGLIB_CHAR* sep, Py_ssize_t sep_len) |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
62 { |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
63 PyObject* out; |
|
58095
a1035cb4a925
Merged revisions 77241 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
40450
diff
changeset
|
64 Py_ssize_t pos; |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
65 |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
66 if (sep_len == 0) { |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
67 PyErr_SetString(PyExc_ValueError, "empty separator"); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
40450
diff
changeset
|
68 return NULL; |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
69 } |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
70 |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
71 out = PyTuple_New(3); |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
72 if (!out) |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
40450
diff
changeset
|
73 return NULL; |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
74 |
| 72475 | 75 pos = FASTSEARCH(str, str_len, sep, sep_len, -1, FAST_RSEARCH); |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
76 |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
77 if (pos < 0) { |
|
58289
5ca1948a8fd6
Merged revisions 77461 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58095
diff
changeset
|
78 #if STRINGLIB_MUTABLE |
|
5ca1948a8fd6
Merged revisions 77461 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58095
diff
changeset
|
79 PyTuple_SET_ITEM(out, 0, STRINGLIB_NEW(NULL, 0)); |
|
5ca1948a8fd6
Merged revisions 77461 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58095
diff
changeset
|
80 PyTuple_SET_ITEM(out, 1, STRINGLIB_NEW(NULL, 0)); |
|
5ca1948a8fd6
Merged revisions 77461 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58095
diff
changeset
|
81 PyTuple_SET_ITEM(out, 2, STRINGLIB_NEW(str, str_len)); |
|
5ca1948a8fd6
Merged revisions 77461 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58095
diff
changeset
|
82 #else |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
40450
diff
changeset
|
83 Py_INCREF(STRINGLIB_EMPTY); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
40450
diff
changeset
|
84 PyTuple_SET_ITEM(out, 0, (PyObject*) STRINGLIB_EMPTY); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
40450
diff
changeset
|
85 Py_INCREF(STRINGLIB_EMPTY); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
40450
diff
changeset
|
86 PyTuple_SET_ITEM(out, 1, (PyObject*) STRINGLIB_EMPTY); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
40450
diff
changeset
|
87 Py_INCREF(str_obj); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
40450
diff
changeset
|
88 PyTuple_SET_ITEM(out, 2, (PyObject*) str_obj); |
|
58289
5ca1948a8fd6
Merged revisions 77461 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
58095
diff
changeset
|
89 #endif |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
40450
diff
changeset
|
90 return out; |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
91 } |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
92 |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
93 PyTuple_SET_ITEM(out, 0, STRINGLIB_NEW(str, pos)); |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
94 Py_INCREF(sep_obj); |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
95 PyTuple_SET_ITEM(out, 1, sep_obj); |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
96 pos += sep_len; |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
97 PyTuple_SET_ITEM(out, 2, STRINGLIB_NEW(str + pos, str_len - pos)); |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
98 |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
99 if (PyErr_Occurred()) { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
40450
diff
changeset
|
100 Py_DECREF(out); |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
40450
diff
changeset
|
101 return NULL; |
|
38453
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
102 } |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
103 |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
104 return out; |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
105 } |
|
29ae5e0fc348
Much-needed merge (using svnmerge.py this time) of trunk changes into p3yk.
Thomas Wouters <thomas@python.org>
parents:
diff
changeset
|
106 |
