Skip to content

Commit 6c7c4aa

Browse files
author
Sky NSS
committed
Updated comments. Removed test_basic_auth_self_signed
1 parent 6bd471c commit 6c7c4aa

File tree

3 files changed

+51
-36
lines changed

3 files changed

+51
-36
lines changed

pandas/io/common.py

+32
Original file line numberDiff line numberDiff line change
@@ -257,13 +257,45 @@ def file_path_to_url(path):
257257

258258

259259
def split_auth_from_url(url_with_uname):
260+
"""
261+
If a url contains username and password, it is extracted and returned
262+
along with a url that does not contain it.
263+
264+
Parameters
265+
----------
266+
url_with_uname : a url that may or may not contain username and password
267+
see section 3.1 RFC 1738 https://www.ietf.org/rfc/rfc1738.txt
268+
//<user>:<password>@<host>:<port>/<url-path>
269+
270+
Returns
271+
-------
272+
(username, password), url_no_usrpwd : username or "", password or "",
273+
url without username or password (if it contained it )
274+
"""
260275
o = parse_url(url_with_uname)
261276
usrch = '{}:{}@{}'.format(o.username, o.password, o.hostname)
262277
url_no_usrpwd = url_with_uname.replace(usrch, o.hostname)
263278
return (o.username, o.password), url_no_usrpwd
264279

265280

266281
def get_urlopen_args(url_with_uname, auth=None, verify_ssl=True):
282+
"""
283+
generate args to pass to urlopen - including basic auth and and support
284+
for disabling verification of SSL certificates ( useful where
285+
self-signed SSL certificates are acceptable security risk -eg: Testing )
286+
287+
Parameters
288+
----------
289+
url_with_uname : a url that may or may not contain username and password
290+
see section 3.1 RFC 1738 https://www.ietf.org/rfc/rfc1738.txt
291+
//<user>:<password>@<host>:<port>/<url-path>
292+
auth : ( username/""/None, password/"", None) tuple
293+
verify_ssl: If False, SSL certificate verification is disabled.
294+
295+
Returns
296+
-------
297+
Request, kwargs to pass to urlopen. kwargs may be {} or {'context': obj }
298+
"""
267299
uname = pwd = None
268300
if auth and len(auth) == 2:
269301
uname, pwd = auth

pandas/tests/io/test_common.py

+19
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,25 @@ def test_write_fspath_hdf5(self):
190190

191191
tm.assert_frame_equal(result, expected)
192192

193+
def test_split_url_extract_uname_pwd(self):
194+
"""
195+
Test extraction of username, pwd from url, if contained.
196+
"""
197+
for url, uname, pwd, nurl in [('https://aaa:[email protected]:1010/aaa.txt',
198+
'aaa',
199+
'bbb',
200+
'https://ccc.com:1010/aaa.txt'
201+
),
202+
('https://ccc.com:1010/aaa.txt',
203+
'',
204+
'',
205+
'https://ccc.com:1010/aaa.txt'
206+
)]:
207+
un, pw, mod_url = common.split_uname_from_url(url)
208+
assert mod_url == nurl
209+
assert un == uname
210+
assert pw == pwd
211+
193212

194213
class TestMMapWrapper(object):
195214

pandas/tests/test_basic_auth_self_signed.py

-36
This file was deleted.

0 commit comments

Comments
 (0)