Skip to content

Commit 15ab0a9

Browse files
author
Mike Dirolf
committed
fix for 2.4 - use our own partition method
1 parent d3a97cd commit 15ab0a9

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

pymongo/connection.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,34 +174,41 @@ def __init__(self, host=None, port=None, pool_size=None,
174174
if _connect:
175175
self.__find_master()
176176

177+
@staticmethod
178+
def __partition(source, sub):
179+
i = source.find(sub)
180+
if i == -1:
181+
return (source, None)
182+
return (source[:i], source[i+len(sub):])
183+
177184
@staticmethod
178185
def _parse_uri(uri):
179186
info = {}
180187

181188
if uri.startswith("mongodb://"):
182189
uri = uri[len("mongodb://"):]
183190
elif "://" in uri:
184-
raise InvalidURI("Invalid uri scheme: %s" % uri.partition("://")[0])
191+
raise InvalidURI("Invalid uri scheme: %s" % Connection.__partition(uri, "://")[0])
185192

186-
(hosts, _, database) = uri.partition("/")
193+
(hosts, database) = Connection.__partition(uri, "/")
187194

188195
if not database:
189196
database = None
190197

191198
username = None
192199
password = None
193200
if "@" in hosts:
194-
(auth, _, hosts) = hosts.partition("@")
201+
(auth, hosts) = Connection.__partition(hosts, "@")
195202

196203
if ":" not in auth:
197204
raise InvalidURI("auth must be specified as 'username:password@'")
198-
(username, _, password) = auth.partition(":")
205+
(username, password) = Connection.__partition(auth, ":")
199206

200207
host_list = []
201208
for host in hosts.split(","):
202209
if not host:
203210
raise InvalidURI("empty host (or extra comma in host list)")
204-
(hostname, _, port) = host.partition(":")
211+
(hostname, port) = Connection.__partition(host, ":")
205212
if port:
206213
port = int(port)
207214
else:

0 commit comments

Comments
 (0)