What steps will reproduce the problem?
import httplib2
def test_add_same_credentials_twice():
CREDENTIALS = ('username', 'password', 'domain')
http = httplib2.Http()
http.add_credentials(*CREDENTIALS)
assert len(http.credentials.crendentials) == 1
assert http.credentials.credentials == [('domain', 'username', 'password')]
http.add_credentials(*CREDENTIALS)
assert len(http.credentials.crendentials) == 1
assert http.credentials.credentials == [('domain', 'username', 'password')]
What is the expected output? What do you see instead?
Nothing. AssertionError
What version of the product are you using? On what operating system?
0.7.0
Please provide any additional information below.
There are two ways to fix it:
* quick and dirty, used in my project:
# Begin httplib2 monkey patching to fix Credentials leak
def _httplib2_fix_Credentials_add(self, name, password, domain=""):
item = (domain.lower(), name, password)
if item not in self.credentials:
self.credentials.append(item)
httplib2.Credentials.add = _httplib2_fix_Credentials_add
# End httplib2 monkey patching to fix Credentials leak
* one that would work well with >50 credentials:
class Credentials(object):
def __init__(self):
self.credentials = set()
def add(...):
self.credentials.add(...)
def clear(self):
self.credentials.clear()
Probably would require few more changes in places which use credentials and
testing. May break other people's code that rely on
Http().credentials.credentials being a list.
Original issue reported on code.google.com by temotor on 19 Nov 2011 at 11:33
Original issue reported on code.google.com by
temotor
on 19 Nov 2011 at 11:33