Show More
@@ -32,12 +32,47 b' from urlparse import urlparse' | |||
|
32 | 32 | |
|
33 | 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 | 46 | def monkeypatch_method(cls): |
|
36 | 47 | def decorator(func): |
|
37 | 48 | setattr(cls, func.__name__, func) |
|
38 | 49 | return func |
|
39 | 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 | 76 | @monkeypatch_method(passwordmgr) |
|
42 | 77 | def find_user_password(self, realm, authuri): |
|
43 | 78 | """ |
@@ -52,23 +87,19 b' def find_user_password(self, realm, auth' | |||
|
52 | 87 | base_url = "%s://%s%s" % (parsed_url.scheme, parsed_url.netloc, parsed_url.path) |
|
53 | 88 | print "find_user_password", realm, base_url |
|
54 | 89 | |
|
55 | ||
|
56 | # TODO: odczyt danych z cache w procesie | |
|
57 | ||
|
58 | # TODO: odczyt danych już obecnych w keyring-u | |
|
90 | user, pwd = password_store.get_password(base_url) | |
|
91 | if user and pwd: | |
|
92 | return user, pwd | |
|
59 | 93 | |
|
60 | 94 | if not self.ui.interactive(): |
|
61 | 95 | raise util.Abort(_('mercurial_keyring: http authorization required')) |
|
62 | 96 | self.ui.write(_("http authorization required\n")) |
|
63 | 97 | self.ui.status(_("realm: %s, url: %s\n" % (realm, base_url))) |
|
64 |
user |
|
|
65 |
p |
|
|
66 | ||
|
67 | # TODO: zapis w keyringu | |
|
98 | user = self.ui.prompt(_("user:"), default = user) | |
|
99 | pwd = self.ui.getpass(_("password: ")) | |
|
68 | 100 | |
|
69 | # TODO: zapis w cache w procesie | |
|
70 | ||
|
101 | password_store.save_password(base_url, user, pwd) | |
|
71 | 102 | |
|
72 |
return user |
|
|
103 | return user, pwd | |
|
73 | 104 | #return None, None |
|
74 | ||
|
105 |
General Comments 0
You need to be logged in to leave comments.
Login now