williamh / pybugz

Python interface to Bugzilla.
http://www.liquidx.net/pybugz/
GNU General Public License v2.0
80 stars 60 forks source link

strip HTTP auth credentials from base when printing #77

Closed sleep-walker closed 10 years ago

sleep-walker commented 10 years ago

fix for https://github.com/williamh/pybugz/issues/76

instead of:
* Info: Using [novell] (https://user:pass@apibugzilla.novell.com/xmlrpc.cgi)

print:
* Info: Using [novell] (https://apibugzilla.novell.com/xmlrpc.cgi)
williamh commented 10 years ago

I think safe_base could be an attribute instead of a method, so can you please set self.safe_base in the constructor?

Also, did you check into using liburl.parse? That may make it easier to get rid of the username and password without using re.

Thanks,

William

sleep-walker commented 10 years ago

First part was easy.

Second - I'm no Pythonist and I have no knowledge of liburl (and what I found on Google didn't seem relevant for URL manipulation). On the other hand regular expressions are my mother tongue.

I found urllib.parse and produced:

parse_result = urllib.parse.urlparse(self.base)
new_netloc = parse_result.netloc.split('@')[-1]
safe_base = parse_result._replace(netloc=new_netloc).geturl()

Do you find it more elegant?

williamh commented 10 years ago

Yes, the reason being that it doesn't matter whether the url is http or https, and I think it did with your regular expression. One more small change: Please move those three lines down to be directly above this one, and add a blank line:

if getattr(self, 'encoding', None) is not none:

I would rather figure out safe_base after we have all of the parameters from the config file and command line parsed.

Thanks,

William