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