Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# https://bugs.python.org/issue33342
# from six.moves.urllib import parse as urllib_parse
from urllib.parse import urlparse
def parsefn(url):
# return urllib_parse.urlparse(url)
return urlparse(url)
def try_parse(url):
uri_parts = parsefn(url)
print(f"\tURI Parts={uri_parts}")
if uri_parts.fragment:
print("\t\t***FAILED PARSE - fragment should be empty***")
if uri_parts.query != 'sslmode=required':
print("\t\t***FAILED PARSE - actual query parm not parsed***")
def make_url(password):
url = f'postgresql://kara_admin:{password}@hifi-kara-db-dev.do.aws/kara?sslmode=required'
return url
passwords = """
bob
vLrnXUW1.DQ+3ya#=p}7gy{KS+3d
vLrnXUW1.DQ+3ya?=p}7gy{KS+3d
vLrnXUW1.DQ+3ya=p}7gy{KS+3d
""".split()
for password in passwords:
print(f"------------------------\nPassword={password}")
url = make_url(password)
try_parse(url)
@metaperl
Copy link
Author

metaperl commented Jan 23, 2019


(env-reahl) c:\prg\tmp>python parsetest.py 
python parsetest.py 
------------------------
Password=bob
	URI Parts=ParseResult(scheme='postgresql', netloc='kara_admin:bob@hifi-kara-db-dev.do.aws', path='/kara', params='', query='sslmode=required', fragment='')
------------------------
Password=vLrnXUW1.DQ+3ya#=p}7gy{KS+3d
	URI Parts=ParseResult(scheme='postgresql', netloc='kara_admin:vLrnXUW1.DQ+3ya', path='', params='', query='', fragment='=p}7gy{KS+3d@hifi-kara-db-dev.do.aws/kara?sslmode=required')
		***FAILED PARSE - fragment should be empty***
		***FAILED PARSE - actual query parm not parsed***
------------------------
Password=vLrnXUW1.DQ+3ya?=p}7gy{KS+3d
	URI Parts=ParseResult(scheme='postgresql', netloc='kara_admin:vLrnXUW1.DQ+3ya', path='', params='', query='=p}7gy{KS+3d@hifi-kara-db-dev.do.aws/kara?sslmode=required', fragment='')
		***FAILED PARSE - actual query parm not parsed***
------------------------
Password=vLrnXUW1.DQ+3ya=p}7gy{KS+3d
	URI Parts=ParseResult(scheme='postgresql', netloc='kara_admin:vLrnXUW1.DQ+3ya=p}7gy{KS+3d@hifi-kara-db-dev.do.aws', path='/kara', params='', query='sslmode=required', fragment='')

(env-reahl) c:\prg\tmp>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment