##// END OF EJS Templates
Fixed some bad indentation
Marcin Kasperski -
r19:a45229f9 default
parent child Browse files
Show More
@@ -119,9 +119,9 b' is described in the comments inside the '
119 from mercurial import hg, repo, util
119 from mercurial import hg, repo, util
120 from mercurial.i18n import _
120 from mercurial.i18n import _
121 try:
121 try:
122 from mercurial.url import passwordmgr
122 from mercurial.url import passwordmgr
123 except:
123 except:
124 from mercurial.httprepo import passwordmgr
124 from mercurial.httprepo import passwordmgr
125 from mercurial.httprepo import httprepository
125 from mercurial.httprepo import httprepository
126
126
127 import keyring
127 import keyring
@@ -174,7 +174,7 b' class PasswordHandler(object):'
174 def __init__(self):
174 def __init__(self):
175 self.pwd_cache = {}
175 self.pwd_cache = {}
176 self.last_reply = None
176 self.last_reply = None
177
177
178 def find_auth(self, pwmgr, realm, authuri):
178 def find_auth(self, pwmgr, realm, authuri):
179 """
179 """
180 Actual implementation of find_user_password - different
180 Actual implementation of find_user_password - different
@@ -187,8 +187,8 b' class PasswordHandler(object):'
187 # wrong. So we note this to force password prompt (and avoid
187 # wrong. So we note this to force password prompt (and avoid
188 # reusing bad password indifinitely).
188 # reusing bad password indifinitely).
189 after_bad_auth = (self.last_reply \
189 after_bad_auth = (self.last_reply \
190 and (self.last_reply['realm'] == realm) \
190 and (self.last_reply['realm'] == realm) \
191 and (self.last_reply['authuri'] == authuri))
191 and (self.last_reply['authuri'] == authuri))
192
192
193 # Strip arguments to get actual remote repository url.
193 # Strip arguments to get actual remote repository url.
194 base_url = self.canonical_url(authuri)
194 base_url = self.canonical_url(authuri)
@@ -196,72 +196,72 b' class PasswordHandler(object):'
196 # Extracting possible username (or password)
196 # Extracting possible username (or password)
197 # stored directly in repository url
197 # stored directly in repository url
198 user, pwd = urllib2.HTTPPasswordMgrWithDefaultRealm.find_user_password(
198 user, pwd = urllib2.HTTPPasswordMgrWithDefaultRealm.find_user_password(
199 pwmgr, realm, authuri)
199 pwmgr, realm, authuri)
200 if user and pwd:
200 if user and pwd:
201 self._debug_reply(ui, _("Auth data found in repository URL"),
201 self._debug_reply(ui, _("Auth data found in repository URL"),
202 base_url, user, pwd)
202 base_url, user, pwd)
203 self.last_reply = dict(realm=realm,authuri=authuri,user=user)
203 self.last_reply = dict(realm=realm,authuri=authuri,user=user)
204 return user, pwd
204 return user, pwd
205
205
206 # Checking the memory cache (there may be many http calls per command)
206 # Checking the memory cache (there may be many http calls per command)
207 cache_key = (realm, base_url)
207 cache_key = (realm, base_url)
208 if not after_bad_auth:
208 if not after_bad_auth:
209 cached_auth = self.pwd_cache.get(cache_key)
209 cached_auth = self.pwd_cache.get(cache_key)
210 if cached_auth:
210 if cached_auth:
211 user, pwd = cached_auth
211 user, pwd = cached_auth
212 self._debug_reply(ui, _("Cached auth data found"),
212 self._debug_reply(ui, _("Cached auth data found"),
213 base_url, user, pwd)
213 base_url, user, pwd)
214 self.last_reply = dict(realm=realm,authuri=authuri,user=user)
214 self.last_reply = dict(realm=realm,authuri=authuri,user=user)
215 return user, pwd
215 return user, pwd
216
216
217 # Loading username and maybe password from [auth] in .hg/hgrc
217 # Loading username and maybe password from [auth] in .hg/hgrc
218 nuser, pwd = self.load_hgrc_auth(ui, base_url)
218 nuser, pwd = self.load_hgrc_auth(ui, base_url)
219 if nuser:
219 if nuser:
220 if user:
220 if user:
221 raise util.Abort(_('mercurial_keyring: username for %s specified both in repository path (%s) and in .hg/hgrc/[auth] (%s). Please, leave only one of those' % (base_url, user, nuser)))
221 raise util.Abort(_('mercurial_keyring: username for %s specified both in repository path (%s) and in .hg/hgrc/[auth] (%s). Please, leave only one of those' % (base_url, user, nuser)))
222 user = nuser
222 user = nuser
223 if pwd:
223 if pwd:
224 self.pwd_cache[cache_key] = user, pwd
224 self.pwd_cache[cache_key] = user, pwd
225 self._debug_reply(ui, _("Auth data set in .hg/hgrc"),
225 self._debug_reply(ui, _("Auth data set in .hg/hgrc"),
226 base_url, user, pwd)
226 base_url, user, pwd)
227 self.last_reply = dict(realm=realm,authuri=authuri,user=user)
227 self.last_reply = dict(realm=realm,authuri=authuri,user=user)
228 return user, pwd
228 return user, pwd
229 else:
229 else:
230 ui.debug(_("Username found in .hg/hgrc: %s\n" % user))
230 ui.debug(_("Username found in .hg/hgrc: %s\n" % user))
231
231
232 # Loading password from keyring.
232 # Loading password from keyring.
233 # Only if username is known (so we know the key) and we are
233 # Only if username is known (so we know the key) and we are
234 # not after failure (so we don't reuse the bad password).
234 # not after failure (so we don't reuse the bad password).
235 if user and not after_bad_auth:
235 if user and not after_bad_auth:
236 pwd = password_store.get_password(base_url, user)
236 pwd = password_store.get_password(base_url, user)
237 if pwd:
237 if pwd:
238 self.pwd_cache[cache_key] = user, pwd
238 self.pwd_cache[cache_key] = user, pwd
239 self._debug_reply(ui, _("Keyring password found"),
239 self._debug_reply(ui, _("Keyring password found"),
240 base_url, user, pwd)
240 base_url, user, pwd)
241 self.last_reply = dict(realm=realm,authuri=authuri,user=user)
241 self.last_reply = dict(realm=realm,authuri=authuri,user=user)
242 return user, pwd
242 return user, pwd
243
243
244 # Is the username permanently set?
244 # Is the username permanently set?
245 fixed_user = (user and True or False)
245 fixed_user = (user and True or False)
246
246
247 # Last resort: interactive prompt
247 # Last resort: interactive prompt
248 if not ui.interactive():
248 if not ui.interactive():
249 raise util.Abort(_('mercurial_keyring: http authorization required'))
249 raise util.Abort(_('mercurial_keyring: http authorization required'))
250 ui.write(_("http authorization required\n"))
250 ui.write(_("http authorization required\n"))
251 ui.status(_("realm: %s\n") % realm)
251 ui.status(_("realm: %s\n") % realm)
252 if fixed_user:
252 if fixed_user:
253 ui.write(_("user: %s (fixed in .hg/hgrc)\n" % user))
253 ui.write(_("user: %s (fixed in .hg/hgrc)\n" % user))
254 else:
254 else:
255 user = ui.prompt(_("user:"), default=None)
255 user = ui.prompt(_("user:"), default=None)
256 pwd = ui.getpass(_("password: "))
256 pwd = ui.getpass(_("password: "))
257
257
258 if fixed_user:
258 if fixed_user:
259 # Saving password to the keyring.
259 # Saving password to the keyring.
260 # It is done only if username is permanently set.
260 # It is done only if username is permanently set.
261 # Otherwise we won't be able to find the password so it
261 # Otherwise we won't be able to find the password so it
262 # does not make much sense to preserve it
262 # does not make much sense to preserve it
263 ui.debug("Saving password for %s to keyring\n" % user)
263 ui.debug("Saving password for %s to keyring\n" % user)
264 password_store.set_password(base_url, user, pwd)
264 password_store.set_password(base_url, user, pwd)
265
265
266 # Saving password to the memory cache
266 # Saving password to the memory cache
267 self.pwd_cache[cache_key] = user, pwd
267 self.pwd_cache[cache_key] = user, pwd
@@ -276,28 +276,28 b' class PasswordHandler(object):'
276 Loading username and possibly password from [auth] in local
276 Loading username and possibly password from [auth] in local
277 repo .hgrc
277 repo .hgrc
278 """
278 """
279 # Theoretically 3 lines below should do.
279 # Theoretically 3 lines below should do:
280 #
280
281 #auth_token = self.readauthtoken(base_url)
282 #if auth_token:
283 # user, pwd = auth.get('username'), auth.get('password')
284
281 # Unfortunately they do not work, readauthtoken always return
285 # Unfortunately they do not work, readauthtoken always return
282 # None. Why? Because ui (self.ui of passwordmgr) describes the
286 # None. Why? Because ui (self.ui of passwordmgr) describes the
283 # *remote* repository, so does *not* contain any option from
287 # *remote* repository, so does *not* contain any option from
284 # local .hg/hgrc.
288 # local .hg/hgrc.
285
289
286 #auth_token = self.readauthtoken(base_url)
287 #if auth_token:
288 # user, pwd = auth.get('username'), auth.get('password')
289
290 # Workaround: we recreate the repository object
290 # Workaround: we recreate the repository object
291 repo_root = ui.config("bundle", "mainreporoot")
291 repo_root = ui.config("bundle", "mainreporoot")
292 if repo_root:
292 if repo_root:
293 from mercurial.ui import ui as _ui
293 from mercurial.ui import ui as _ui
294 import os
294 import os
295 local_ui = _ui(ui)
295 local_ui = _ui(ui)
296 local_ui.readconfig(os.path.join(repo_root, ".hg", "hgrc"))
296 local_ui.readconfig(os.path.join(repo_root, ".hg", "hgrc"))
297 local_passwordmgr = passwordmgr(local_ui)
297 local_passwordmgr = passwordmgr(local_ui)
298 auth_token = local_passwordmgr.readauthtoken(base_url)
298 auth_token = local_passwordmgr.readauthtoken(base_url)
299 if auth_token:
299 if auth_token:
300 return auth_token.get('username'), auth_token.get('password')
300 return auth_token.get('username'), auth_token.get('password')
301 return None, None
301 return None, None
302
302
303 def canonical_url(self, authuri):
303 def canonical_url(self, authuri):
@@ -326,7 +326,7 b' def find_user_password(self, realm, auth'
326 """
326 """
327 # Extend object attributes
327 # Extend object attributes
328 if not hasattr(self, '_pwd_handler'):
328 if not hasattr(self, '_pwd_handler'):
329 self._pwd_handler = PasswordHandler()
329 self._pwd_handler = PasswordHandler()
330
330
331 return self._pwd_handler.find_auth(self, realm, authuri)
331 return self._pwd_handler.find_auth(self, realm, authuri)
332
332
General Comments 0
You need to be logged in to leave comments. Login now