Show More
@@ -32,12 +32,47 b' from urlparse import urlparse' | |||||
32 |
|
32 | |||
33 | KEYRING_SERVICE = "Mercurial" |
|
33 | KEYRING_SERVICE = "Mercurial" | |
34 |
|
34 | |||
|
35 | ############################################################ | |||
|
36 | ||||
|
37 | def monkeypatch_class(name, bases, namespace): | |||
|
38 | """http://mail.python.org/pipermail/python-dev/2008-January/076194.html""" | |||
|
39 | assert len(bases) == 1, "Exactly one base class required" | |||
|
40 | base = bases[0] | |||
|
41 | for name, value in namespace.iteritems(): | |||
|
42 | if name != "__metaclass__": | |||
|
43 | setattr(base, name, value) | |||
|
44 | return base | |||
|
45 | ||||
35 | def monkeypatch_method(cls): |
|
46 | def monkeypatch_method(cls): | |
36 | def decorator(func): |
|
47 | def decorator(func): | |
37 | setattr(cls, func.__name__, func) |
|
48 | setattr(cls, func.__name__, func) | |
38 | return func |
|
49 | return func | |
39 | return decorator |
|
50 | return decorator | |
40 |
|
51 | |||
|
52 | ############################################################ | |||
|
53 | ||||
|
54 | class PasswordStore(object): | |||
|
55 | """ | |||
|
56 | Helper object handling password save&restore. Passwords | |||
|
57 | are saved both in local memory cache, and keyring, and are | |||
|
58 | restored from those. | |||
|
59 | """ | |||
|
60 | def __init__(self): | |||
|
61 | self.cache = dict() | |||
|
62 | def save_password(self, url, username, password): | |||
|
63 | self.cache[url] = (username, password) | |||
|
64 | # TODO: keyring save | |||
|
65 | def get_password(self, url): | |||
|
66 | r = self.cache.get(url) | |||
|
67 | if r: | |||
|
68 | return r | |||
|
69 | # TODO: keyring restore | |||
|
70 | return None, None | |||
|
71 | ||||
|
72 | password_store = PasswordStore() | |||
|
73 | ||||
|
74 | ############################################################ | |||
|
75 | ||||
41 | @monkeypatch_method(passwordmgr) |
|
76 | @monkeypatch_method(passwordmgr) | |
42 | def find_user_password(self, realm, authuri): |
|
77 | def find_user_password(self, realm, authuri): | |
43 | """ |
|
78 | """ | |
@@ -52,23 +87,19 b' def find_user_password(self, realm, auth' | |||||
52 | base_url = "%s://%s%s" % (parsed_url.scheme, parsed_url.netloc, parsed_url.path) |
|
87 | base_url = "%s://%s%s" % (parsed_url.scheme, parsed_url.netloc, parsed_url.path) | |
53 | print "find_user_password", realm, base_url |
|
88 | print "find_user_password", realm, base_url | |
54 |
|
89 | |||
55 |
|
90 | user, pwd = password_store.get_password(base_url) | ||
56 | # TODO: odczyt danych z cache w procesie |
|
91 | if user and pwd: | |
57 |
|
92 | return user, pwd | ||
58 | # TODO: odczyt danych już obecnych w keyring-u |
|
|||
59 |
|
93 | |||
60 | if not self.ui.interactive(): |
|
94 | if not self.ui.interactive(): | |
61 | raise util.Abort(_('mercurial_keyring: http authorization required')) |
|
95 | raise util.Abort(_('mercurial_keyring: http authorization required')) | |
62 | self.ui.write(_("http authorization required\n")) |
|
96 | self.ui.write(_("http authorization required\n")) | |
63 | self.ui.status(_("realm: %s, url: %s\n" % (realm, base_url))) |
|
97 | self.ui.status(_("realm: %s, url: %s\n" % (realm, base_url))) | |
64 |
user |
|
98 | user = self.ui.prompt(_("user:"), default = user) | |
65 |
p |
|
99 | pwd = self.ui.getpass(_("password: ")) | |
66 |
|
||||
67 | # TODO: zapis w keyringu |
|
|||
68 |
|
100 | |||
69 | # TODO: zapis w cache w procesie |
|
101 | password_store.save_password(base_url, user, pwd) | |
70 |
|
||||
71 |
|
102 | |||
72 |
return user |
|
103 | return user, pwd | |
73 | #return None, None |
|
104 | #return None, None | |
74 |
|
105 |
General Comments 0
You need to be logged in to leave comments.
Login now