piranha/nomad — pull request #5 by pcdinh (2013-01-16 10:35:35+00:00)
Title: Invalid URL parsing

I just installed nomad in my development server. However it is unable to parse URL defined nomad.ini correctly

My URL: pgsql://my_username:my_password@host_name/database_name

When I run: nomad init I got an exception: no 'root' role defined. I expect that nomad should use "my_username" role instead.

I found a small bug in the code to parse the URL

{code}
def path2dict(p, **renames):
'''Convert urlparse result to dict
'''
result = {}
for k in 'hostname port path user password'.split():
value = getattr(p, k, None)
if not value:
continue
if k == 'path':
value = value.lstrip('/')
result[renames.get(k, k)] = value
return result
{code}

where p is produced by
{code}
p = urlparse.urlparse("pgsql://my_username:my_password@host_name/database_name")
{code}

It looks like that you expect "user" is an attribute of p. However, it is not the case

{code}
>>> p = urlparse.urlparse("pgsql://my_username:my_password@host_name/database_name")
>>> p.username
'my_username'
>>> p.user
Traceback (most recent call last):
File "", line 1, in
AttributeError: 'ParseResult' object has no attribute 'user'
>>>
{code}