Message230715
I don't think having to call a method with a weird secret underscored name to update a value in a URL named tuple is very elegant. Neither is creating a handful of pointless objects to make one simple validator function like the one I had to code today. I would urge some reconsideration of this, like a way to get back a named yet mutable object when needed, instead of trying to force everybody to do this one way which isn't always that great.
def validate_url(url):
parts = urlparse.urlparse(url.strip())
# scheme, netloc, path, params, query, fragment
# XXX: preserve backward compatibility w/ old code
if not parts.scheme:
parts = parts._replace(scheme='http', netloc=parts.path.strip('/'), path='')
# remove params, query, and fragment
# params is nearly never used anywhere
# (NOTE: it does NOT mean the stuff after '?')
# it actually means this http://domain/page.py;param1=foo?query1=bar
# query and fragment are used but aren't helpful for our application
parts = parts._replace(params='', query='', fragment='')
if parts.scheme not in URI_SCHEMES:
raise ValueError('scheme=%s is not valid' % parts.scheme)
if '.' not in parts.netloc:
raise ValueError('location=%s does not contain a domain' % parts.netloc)
if len(parts.path) and not parts.path.startswith('/'):
raise ValueError('path=%s appears invalid' % parts.path)
elif not parts.path:
parts=parts._replace(path='/')
validated_url = parts.geturl()
return validated_url, parts |
|
Date |
User |
Action |
Args |
2014-11-05 21:57:40 | mhcptg | set | recipients:
+ mhcptg, orsenthil, ezio.melotti, eric.araujo, r.david.murray, mastahyeti |
2014-11-05 21:57:40 | mhcptg | set | messageid: <1415224660.49.0.294850518923.issue15824@psf.upfronthosting.co.za> |
2014-11-05 21:57:40 | mhcptg | link | issue15824 messages |
2014-11-05 21:57:40 | mhcptg | create | |
|