##// END OF EJS Templates
Various py3 incompatibilities
Marcin Kasperski -
r272:4e2d69f2 default
parent child Browse files
Show More
@@ -224,7 +224,7 b' class PasswordStore(object):'
224 224 err)
225 225 return ''
226 226 # Reverse recoding from next routine
227 if isinstance(password, unicode):
227 if isinstance(password, meu.pycompat.unicode):
228 228 return encoding.tolocal(password.encode('utf-8'))
229 229 return password
230 230
@@ -251,11 +251,6 b' password_store = PasswordStore()'
251 251 # Various utils
252 252 ############################################################
253 253
254 def _debug(ui, msg):
255 """Generic debug message"""
256 ui.debug("keyring: " + msg + "\n")
257
258
259 254 class PwdCache(object):
260 255 """Short term cache, used to preserve passwords
261 256 if they are used twice during a command"""
@@ -328,9 +323,9 b' class HTTPPasswordHandler(object):'
328 323 ui = pwmgr.ui
329 324
330 325 parsed_url, url_user, url_passwd = self.unpack_url(authuri)
331 base_url = str(parsed_url)
332 ui.debug(_('keyring: base url: %s, url user: %s, url pwd: %s\n') %
333 (base_url, url_user or '', url_passwd and '******' or ''))
326 base_url = bytes(parsed_url)
327 ui.debug(b'keyring: base url: %s, url user: %s, url pwd: %s\n' %
328 (base_url, url_user or b'', url_passwd and b'******' or b''))
334 329
335 330 # Extract username (or password) stored directly in url
336 331 if url_user and url_passwd:
@@ -371,7 +366,7 b' class HTTPPasswordHandler(object):'
371 366
372 367 # Load from keyring.
373 368 if actual_user:
374 ui.debug(_("keyring: looking for password (user %s, url %s)\n") %
369 ui.debug(b"keyring: looking for password (user %s, url %s)\n" %
375 370 (actual_user, keyring_url))
376 371 keyring_pwd = password_store.get_http_password(keyring_url, actual_user)
377 372 if keyring_pwd:
@@ -389,10 +384,10 b' class HTTPPasswordHandler(object):'
389 384 ui.status(_("keyring: username not specified in hgrc (or in url). Password will not be saved.\n"))
390 385
391 386 ui.write(_("http authorization required\n"))
392 ui.status(_("realm: %s\n") % realm)
387 ui.status(_("realm: %s\n") % meu.pycompat.bytestr(realm))
393 388 ui.status(_("url: %s\n") % url)
394 389 if user:
395 ui.write(_("user: %s (fixed in hgrc or url)\n", user))
390 ui.write(_("user: %s (fixed in hgrc or url)\n") % user)
396 391 else:
397 392 user = ui.prompt(_("user:"), default=None)
398 393 pwd = ui.getpass(_("password: "))
@@ -415,7 +410,7 b' class HTTPPasswordHandler(object):'
415 410 if src != self.SRC_MEMCACHE:
416 411 self.pwd_cache.store(realm, final_url, user, pwd)
417 412 self._note_last_reply(realm, authuri, user, req)
418 _debug(ui, _("Password found in " + src))
413 ui.debug("keyring: Password found in %s\n" % src)
419 414 return user, pwd
420 415
421 416 # Last resort: interactive prompt
@@ -426,7 +421,7 b' class HTTPPasswordHandler(object):'
426 421 # It is done only if username is permanently set.
427 422 # Otherwise we won't be able to find the password so it
428 423 # does not make much sense to preserve it
429 _debug(ui, _("Saving password for %s to keyring"), user)
424 ui.debug("keyring: Saving password for %s to keyring\n" % user)
430 425 try:
431 426 password_store.set_http_password(final_url, user, pwd)
432 427 except Exception as e:
@@ -440,7 +435,7 b' class HTTPPasswordHandler(object):'
440 435 # Saving password to the memory cache
441 436 self.pwd_cache.store(realm, final_url, user, pwd)
442 437 self._note_last_reply(realm, authuri, user, req)
443 _debug(ui, _("Manually entered password"))
438 ui.debug("keyring: Manually entered password\n")
444 439 return user, pwd
445 440
446 441 def get_url_config(self, ui, parsed_url, user):
@@ -452,10 +447,10 b' class HTTPPasswordHandler(object):'
452 447 found. username and password can be None (if unset), if prefix
453 448 is not found, url itself is returned.
454 449 """
455 base_url = str(parsed_url)
450 base_url = bytes(parsed_url)
456 451
457 452 from mercurial.httpconnection import readauthforuri
458 _debug(ui, _("Checking for hgrc info about url %s, user %s") % (base_url, user))
453 ui.debug(b"keyring: checking for hgrc info about url %s, user %s\n" % (base_url, user))
459 454 res = readauthforuri(ui, base_url, user)
460 455 # If it user-less version not work, let's try with added username to handle
461 456 # both config conventions
@@ -479,8 +474,8 b' class HTTPPasswordHandler(object):'
479 474
480 475 password_url = self.password_url(base_url, prefix)
481 476
482 _debug(ui, _("Password url: %s, user: %s, password: %s (prefix: %s)") % (
483 password_url, username, '********' if password else '', prefix))
477 ui.debug(b"keyring: Password url: %s, user: %s, password: %s (prefix: %s)\n" % (
478 password_url, username or b'', b'********' if password else b'', prefix or b''))
484 479
485 480 return username, password, password_url
486 481
@@ -505,7 +500,8 b' class HTTPPasswordHandler(object):'
505 500 if (self.last_reply['realm'] == realm) \
506 501 and (self.last_reply['authuri'] == authuri) \
507 502 and (self.last_reply['req'] == req):
508 _debug(ui, _("Working after bad authentication, cached passwords not used %s") % str(self.last_reply))
503 ui.debug("keyring: Working after bad authentication, cached passwords not used %s\n" %
504 str(self.last_reply))
509 505 return True
510 506 return False
511 507
@@ -542,11 +538,12 b' class HTTPPasswordHandler(object):'
542 538 where url is mercurial.util.url object already stripped of all those
543 539 params.
544 540 """
545 import pdb; pdb.set_trace()
541 # In case of py3, util.url expects bytes
542 authuri = meu.pycompat.bytestr(authuri)
546 543
547 544 # mercurial.util.url, rather handy url parser
548 545 parsed_url = util.url(authuri)
549 parsed_url.query = ''
546 parsed_url.query = b''
550 547 parsed_url.fragment = None
551 548 # Strip arguments to get actual remote repository url.
552 549 # base_url = "%s://%s%s" % (parsed_url.scheme, parsed_url.netloc,
General Comments 0
You need to be logged in to leave comments. Login now