changeset 34482:75de5d456b60

ui: convert to/from Optional[bytes] to Optional[str] in password manager This password manager proxy is roughly the right-looking layer to convert between strings and bytes. Many of these arguments can be None, so we have a helper method to make the conversion preserve Nones without exploding. Differential Revision: https://phab.mercurial-scm.org/D886
author Augie Fackler <augie@google.com>
date Sun, 01 Oct 2017 12:10:48 -0400
parents cbda631c1dde
children a6d95a8b7243
files mercurial/ui.py
diffstat 1 files changed, 19 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/ui.py	Fri Jun 30 03:37:05 2017 +0200
+++ b/mercurial/ui.py	Sun Oct 01 12:10:48 2017 -0400
@@ -135,6 +135,15 @@
 """,
 }
 
+def _maybestrurl(maybebytes):
+    if maybebytes is None:
+        return None
+    return pycompat.strurl(maybebytes)
+
+def _maybebytesurl(maybestr):
+    if maybestr is None:
+        return None
+    return pycompat.bytesurl(maybestr)
 
 class httppasswordmgrdbproxy(object):
     """Delays loading urllib2 until it's needed."""
@@ -147,10 +156,18 @@
         return self._mgr
 
     def add_password(self, realm, uris, user, passwd):
-        return self._get_mgr().add_password(realm, uris, user, passwd)
+        if isinstance(uris, tuple):
+            uris = tuple(_maybestrurl(u) for u in uris)
+        else:
+            uris = _maybestrurl(uris)
+        return self._get_mgr().add_password(
+            _maybestrurl(realm), uris,
+            _maybestrurl(user), _maybestrurl(passwd))
 
     def find_user_password(self, realm, uri):
-        return self._get_mgr().find_user_password(realm, uri)
+        return tuple(_maybebytesurl(v) for v in
+                     self._get_mgr().find_user_password(_maybestrurl(realm),
+                                                        _maybestrurl(uri)))
 
 def _catchterm(*args):
     raise error.SignalInterrupt