##// END OF EJS Templates
Fixes toward py3.0 support
Marcin Kasperski -
r274:7f65d6c0 default
parent child Browse files
Show More
@@ -220,8 +220,8 b' class PasswordStore(object):'
220 220 password = keyring.get_password(KEYRING_SERVICE, pwdkey)
221 221 except Exception as err:
222 222 ui = uimod.ui()
223 ui.warn(_("keyring: keyring backend doesn't seem to work, password can not be restored. Falling back to prompts. Error details: %s\n") %
224 err)
223 ui.warn(meu.ui_string("keyring: keyring backend doesn't seem to work, password can not be restored. Falling back to prompts. Error details: %s\n",
224 err))
225 225 return ''
226 226 # Reverse recoding from next routine
227 227 if isinstance(password, meu.pycompat.unicode):
@@ -240,8 +240,9 b' class PasswordStore(object):'
240 240 KEYRING_SERVICE, pwdkey, password)
241 241 except Exception as err:
242 242 ui = uimod.ui()
243 ui.warn(_("keyring: keyring backend doesn't seem to work, password was not saved. Error details: %s\n") %
244 err)
243 ui.warn(meu.ui_string(
244 "keyring: keyring backend doesn't seem to work, password was not saved. Error details: %s\n",
245 err))
245 246
246 247
247 248 password_store = PasswordStore()
@@ -324,8 +325,8 b' class HTTPPasswordHandler(object):'
324 325
325 326 parsed_url, url_user, url_passwd = self.unpack_url(authuri)
326 327 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''))
328 ui.debug(meu.ui_string('keyring: base url: %s, url user: %s, url pwd: %s\n',
329 base_url, url_user, url_passwd and b'******' or b''))
329 330
330 331 # Extract username (or password) stored directly in url
331 332 if url_user and url_passwd:
@@ -366,8 +367,8 b' class HTTPPasswordHandler(object):'
366 367
367 368 # Load from keyring.
368 369 if actual_user:
369 ui.debug(b"keyring: looking for password (user %s, url %s)\n" %
370 (actual_user, keyring_url))
370 ui.debug(meu.ui_string("keyring: looking for password (user %s, url %s)\n",
371 actual_user, keyring_url))
371 372 keyring_pwd = password_store.get_http_password(keyring_url, actual_user)
372 373 if keyring_pwd:
373 374 return actual_user, keyring_pwd, self.SRC_KEYRING, keyring_url
@@ -381,16 +382,20 b' class HTTPPasswordHandler(object):'
381 382 raise error.Abort(_('keyring: http authorization required but program used in non-interactive mode'))
382 383
383 384 if not user:
384 ui.status(_("keyring: username not specified in hgrc (or in url). Password will not be saved.\n"))
385 ui.status(meu.ui_string("keyring: username not specified in hgrc (or in url). Password will not be saved.\n"))
385 386
386 ui.write(_("http authorization required\n"))
387 ui.status(_("realm: %s\n") % meu.pycompat.bytestr(realm))
388 ui.status(_("url: %s\n") % url)
387 ui.write(meu.ui_string("http authorization required\n"))
388 ui.status(meu.ui_string("realm: %s\n",
389 realm))
390 ui.status(meu.ui_string("url: %s\n",
391 url))
389 392 if user:
390 ui.write(_("user: %s (fixed in hgrc or url)\n") % user)
393 ui.write(meu.ui_string("user: %s (fixed in hgrc or url)\n",
394 user))
391 395 else:
392 user = ui.prompt(_("user:"), default=None)
393 pwd = ui.getpass(_("password: "))
396 user = ui.prompt(meu.ui_string("user:"),
397 default=None)
398 pwd = ui.getpass(meu.ui_string("password: "))
394 399 return user, pwd
395 400
396 401 def find_auth(self, pwmgr, realm, authuri, req):
@@ -410,7 +415,8 b' class HTTPPasswordHandler(object):'
410 415 if src != self.SRC_MEMCACHE:
411 416 self.pwd_cache.store(realm, final_url, user, pwd)
412 417 self._note_last_reply(realm, authuri, user, req)
413 ui.debug("keyring: Password found in %s\n" % src)
418 ui.debug(meu.ui_string("keyring: Password found in %s\n",
419 src))
414 420 return user, pwd
415 421
416 422 # Last resort: interactive prompt
@@ -421,21 +427,22 b' class HTTPPasswordHandler(object):'
421 427 # It is done only if username is permanently set.
422 428 # Otherwise we won't be able to find the password so it
423 429 # does not make much sense to preserve it
424 ui.debug("keyring: Saving password for %s to keyring\n" % user)
430 ui.debug(meu.ui_string("keyring: Saving password for %s to keyring\n",
431 user))
425 432 try:
426 433 password_store.set_http_password(final_url, user, pwd)
427 434 except Exception as e:
428 435 keyring = import_keyring()
429 436 if isinstance(e, keyring.errors.PasswordSetError):
430 437 ui.traceback()
431 ui.warn(_("warning: failed to save password in keyring\n"))
438 ui.warn(meu.ui_string("warning: failed to save password in keyring\n"))
432 439 else:
433 440 raise e
434 441
435 442 # Saving password to the memory cache
436 443 self.pwd_cache.store(realm, final_url, user, pwd)
437 444 self._note_last_reply(realm, authuri, user, req)
438 ui.debug("keyring: Manually entered password\n")
445 ui.debug(meu.ui_string("keyring: Manually entered password\n"))
439 446 return user, pwd
440 447
441 448 def get_url_config(self, ui, parsed_url, user):
@@ -448,7 +455,8 b' class HTTPPasswordHandler(object):'
448 455 is not found, url itself is returned.
449 456 """
450 457 from mercurial.httpconnection import readauthforuri
451 ui.debug(b"keyring: checking for hgrc info about url %s, user %s\n" % (parsed_url, user))
458 ui.debug(meu.ui_string("keyring: checking for hgrc info about url %s, user %s\n",
459 parsed_url, user))
452 460 res = readauthforuri(ui, str(parsed_url), user)
453 461 # If it user-less version not work, let's try with added username to handle
454 462 # both config conventions
@@ -472,8 +480,10 b' class HTTPPasswordHandler(object):'
472 480
473 481 password_url = self.password_url(str(parsed_url), prefix)
474 482
475 ui.debug(b"keyring: Password url: %s, user: %s, password: %s (prefix: %s)\n" % (
476 password_url, username or b'', b'********' if password else b'', prefix or b''))
483 ui.debug(meu.ui_string("keyring: Password url: %s, user: %s, password: %s (prefix: %s)\n",
484 password_url, username,
485 b'********' if password else b'',
486 prefix))
477 487
478 488 return username, password, password_url
479 489
@@ -498,8 +508,9 b' class HTTPPasswordHandler(object):'
498 508 if (self.last_reply['realm'] == realm) \
499 509 and (self.last_reply['authuri'] == authuri) \
500 510 and (self.last_reply['req'] == req):
501 ui.debug("keyring: Working after bad authentication, cached passwords not used %s\n" %
502 str(self.last_reply))
511 ui.debug(meu.ui_string(
512 "keyring: Working after bad authentication, cached passwords not used %s\n",
513 str(self.last_reply)))
503 514 return True
504 515 return False
505 516
@@ -632,8 +643,8 b' def try_smtp_login(ui, smtp_obj, usernam'
632 643 return True
633 644 except smtplib.SMTPException as inst:
634 645 if inst.smtp_code == 535:
635 ui.status(_("SMTP login failed: %s\n\n") %
636 inst.smtp_error)
646 ui.status(meu.ui_string("SMTP login failed: %s\n\n",
647 inst.smtp_error))
637 648 return False
638 649 else:
639 650 raise error.Abort(inst)
@@ -784,34 +795,37 b' def cmd_keyring_check(ui, repo, *path_ar'
784 795 for path_arg in path_args]
785 796 else:
786 797 if not repo:
787 ui.status(_("Url to check not specified. Either run ``hg keyring_check https://...``, or run the command inside some repository (to test all defined paths).\n"))
798 ui.status(meu.ui_string("Url to check not specified. Either run ``hg keyring_check https://...``, or run the command inside some repository (to test all defined paths).\n"))
788 799 return
789 800 paths = [(name, url) for name, url in defined_paths]
790 801
791 802 if not paths:
792 ui.status(_("keyring_check: no paths defined\n"))
803 ui.status(meu.ui_string("keyring_check: no paths defined\n"))
793 804 return
794 805
795 806 handler = HTTPPasswordHandler()
796 807
797 ui.status(_("keyring password save status:\n"))
808 ui.status(meu.ui_string("keyring password save status:\n"))
798 809 for name, url in paths:
799 810 if not is_http_path(url):
800 811 if path_args:
801 ui.status(_(" %s: non-http path (%s)\n") %
802 (name, url))
812 ui.status(meu.ui_string(" %s: non-http path (%s)\n",
813 name, url))
803 814 continue
804 815 user, pwd, source, final_url = handler.get_credentials(
805 816 make_passwordmgr(ui), name, url)
806 817 if pwd:
807 ui.status(_(" %s: password available, source: %s, bound to user %s, url %s\n") %
808 (name, source, user, final_url))
818 ui.status(meu.ui_string(
819 " %s: password available, source: %s, bound to user %s, url %s\n",
820 name, source, user, final_url))
809 821 elif user:
810 ui.status(_(" %s: password not available, once entered, will be bound to user %s, url %s\n") %
811 (name, user, final_url))
822 ui.status(meu.ui_string(
823 " %s: password not available, once entered, will be bound to user %s, url %s\n",
824 name, user, final_url))
812 825 else:
813 ui.status(_(" %s: password not available, user unknown, url %s\n") %
814 (name, final_url))
826 ui.status(meu.ui_string(
827 " %s: password not available, user unknown, url %s\n",
828 name, final_url))
815 829
816 830
817 831 @command(b'keyring_clear',
@@ -831,8 +845,9 b' def cmd_keyring_clear(ui, repo, path, **'
831 845 path_url = url
832 846 break
833 847 if not is_http_path(path_url):
834 ui.status(_("%s is not a http path (and %s can't be resolved as path alias)\n") %
835 (path, path_url))
848 ui.status(meu.ui_string(
849 "%s is not a http path (and %s can't be resolved as path alias)\n",
850 path, path_url))
836 851 return
837 852
838 853 handler = HTTPPasswordHandler()
@@ -840,21 +855,21 b' def cmd_keyring_clear(ui, repo, path, **'
840 855 user, pwd, source, final_url = handler.get_credentials(
841 856 make_passwordmgr(ui), path, path_url)
842 857 if not user:
843 ui.status(_("Username not configured for url %s\n") %
844 final_url)
858 ui.status(meu.ui_string("Username not configured for url %s\n",
859 final_url))
845 860 return
846 861 if not pwd:
847 ui.status(_("No password is saved for user %s, url %s\n") %
848 (user, final_url))
862 ui.status(meu.ui_string("No password is saved for user %s, url %s\n",
863 user, final_url))
849 864 return
850 865
851 866 if source != handler.SRC_KEYRING:
852 ui.status(_("Password for user %s, url %s is saved in %s, not in keyring\n") %
853 (user, final_url, source))
867 ui.status(meu.ui_string("Password for user %s, url %s is saved in %s, not in keyring\n",
868 user, final_url, source))
854 869
855 870 password_store.clear_http_password(final_url, user)
856 ui.status(_("Password removed for user %s, url %s\n") %
857 (user, final_url))
871 ui.status(meu.ui_string("Password removed for user %s, url %s\n",
872 user, final_url))
858 873
859 874
860 875 buglink = 'https://bitbucket.org/Mekk/mercurial_keyring/issues'
General Comments 0
You need to be logged in to leave comments. Login now