Skip to content

Instantly share code, notes, and snippets.

@jmahmood
Created July 9, 2012 03:54
Show Gist options
  • Save jmahmood/3074148 to your computer and use it in GitHub Desktop.
Save jmahmood/3074148 to your computer and use it in GitHub Desktop.
3 years of python
A few years ago:
def parseBugzillaCookies(self,s):
if s is None: return {self.SESSION_ID_STRING:None}
ret = {}
tmp = s.split(';')
for t in tmp:
t = t.replace('HttpOnly, ','')
coppia = t.split('=')
if coppia[0].strip() in ['Bugzilla_logincookie','Bugzilla_login']:
k = coppia[0].strip()
v = coppia[1].strip()
ret[k]=v
return ret
Now:
(Probably less efficient, but much easier to read)
def parseBugzillaCookies(self,s):
if s is None:
return {self.SESSION_ID_STRING:None}
BugzillaCookieKeys = ['Bugzilla_logincookie','Bugzilla_login']
headers = [t.replace('HttpOnly, ','').split("=") for t in s.split(';')]
return dict((k.strip(),v.strip()) for (k,v) in headers if k in BugzillaCookieKeys)
@jmahmood
Copy link
Author

Thanks for the bugfix - I applied it in py-bugziller :D

I was concerned that I was running through the same array twice when I could do everything in a single loop previously. However, in retrospect, that wasn't really such a big deal.

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