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