@@ -115,39 +115,6 @@ def __str__(self):
115
115
return self .url
116
116
117
117
118
- def split_first (s , delims ):
119
- """
120
- Given a string and an iterable of delimiters, split on the first found
121
- delimiter. Return two split parts and the matched delimiter.
122
-
123
- If not found, then the first part is the full input string.
124
-
125
- Example::
126
-
127
- >>> split_first('foo/bar?baz', '?/=')
128
- ('foo', 'bar?baz', '/')
129
- >>> split_first('foo/bar?baz', '123')
130
- ('foo/bar?baz', '', None)
131
-
132
- Scales linearly with number of delims. Not ideal for large number of delims.
133
- """
134
- min_idx = None
135
- min_delim = None
136
- for d in delims :
137
- idx = s .find (d )
138
- if idx < 0 :
139
- continue
140
-
141
- if min_idx is None or idx < min_idx :
142
- min_idx = idx
143
- min_delim = d
144
-
145
- if min_idx is None or min_idx < 0 :
146
- return s , '' , None
147
-
148
- return s [:min_idx ], s [min_idx + 1 :], min_delim
149
-
150
-
151
118
def patched_parse_url (url ):
152
119
"""
153
120
Given a url, return a parsed :class:`.Url` namedtuple. Best-effort is
@@ -170,6 +137,38 @@ def patched_parse_url(url):
170
137
# Additionally, this implementations does silly things to be optimal
171
138
# on CPython.
172
139
140
+ def split_first (s , delims ):
141
+ """
142
+ Given a string and an iterable of delimiters, split on the first found
143
+ delimiter. Return two split parts and the matched delimiter.
144
+
145
+ If not found, then the first part is the full input string.
146
+
147
+ Example::
148
+
149
+ >>> split_first('foo/bar?baz', '?/=')
150
+ ('foo', 'bar?baz', '/')
151
+ >>> split_first('foo/bar?baz', '123')
152
+ ('foo/bar?baz', '', None)
153
+
154
+ Scales linearly with number of delims. Not ideal for large number of delims.
155
+ """
156
+ min_idx = None
157
+ min_delim = None
158
+ for d in delims :
159
+ idx = s .find (d )
160
+ if idx < 0 :
161
+ continue
162
+
163
+ if min_idx is None or idx < min_idx :
164
+ min_idx = idx
165
+ min_delim = d
166
+
167
+ if min_idx is None or min_idx < 0 :
168
+ return s , '' , None
169
+
170
+ return s [:min_idx ], s [min_idx + 1 :], min_delim
171
+
173
172
if not url :
174
173
# Empty
175
174
return Url ()
0 commit comments