Patchwork D886: ui: convert to/from Optional[bytes] to Optional[str] in password manager

login
register
mail settings
Submitter phabricator
Date Oct. 4, 2017, 4:26 p.m.
Message ID <4abe62f48039a93f1cbf9688169356fd@localhost.localdomain>
Download mbox | patch
Permalink /patch/24504/
State Not Applicable
Headers show

Comments

phabricator - Oct. 4, 2017, 4:26 p.m.
durin42 updated this revision to Diff 2421.
durin42 marked 3 inline comments as done.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D886?vs=2298&id=2421

REVISION DETAIL
  https://phab.mercurial-scm.org/D886

AFFECTED FILES
  mercurial/ui.py

CHANGE DETAILS




To: durin42, #hg-reviewers, yuja
Cc: yuja, mercurial-devel

Patch

diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -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