1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 '''
32 HttxLib password manager implementation
33 '''
34
35 from copy import deepcopy
36 from urllib2 import HTTPPasswordMgrWithDefaultRealm
37
38 from httxobject import HttxObject
39
40
42 '''
43 An object manages username and password for url and realms
44 with locking semantics to be used in L{HttxOptions}
45
46 @ivar passmanager: storage for username, password credentials
47 @type passmanager: HTTPPasswordMgrWithDefaultRealm
48 '''
49
51 '''
52 Constructor. It delegates construction to the base class
53 L{HttxObject} and initializes the member variables
54 '''
55 HttxObject.__init__(self)
56
57 self.passmanager = HTTPPasswordMgrWithDefaultRealm()
58
59
61 '''
62 Deepcopy support.
63
64 @param memo: standard __deepcopy__ parameter to avoid circular references
65 @type memo: dict
66 @return: a cloned object
67 @rtype: L{HttxPassManager}
68 '''
69 clone = self.__class__()
70 with self.lock:
71 clone.passmanager = deepcopy(self.passmanager)
72 return clone
73
74
76 '''
77 Stub replica for HTTPPasswordManagerWithDefaultRealm to
78 add a username and a password for a real, url combination
79
80 @param realm: where the credentials should be applied
81 None is a catch-all value
82 @type realm: str|None
83 @param url: base url for application of username, password
84 if realm matches. It can be empty to catch-all
85 @type url: str
86 @param user: username
87 @type user: str
88 @param passwd: username
89 @type passwd: str
90 '''
91 with self.lock:
92 self.passmanager.add_password(realm, url, user, passwd)
93
94
96 '''
97 Stub replica for HTTPPasswordManagerWithDefaultRealm to
98 retrieve username, password for the given realm and url
99
100 @param realm: where the credentials should be applied
101 None is a catch-all value
102 @type realm: str|None
103 @param url: base url for application of username, password
104 if realm matches. It can be empty to catch-all
105 @return: tuple with the username, password values. It can be
106 None, None if not found
107 @rtype: tuple
108 '''
109 with self.lock:
110 return self.passmanager.find_user_password(realm, url)
111