comparison mercurial/ui.py @ 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 ae2fcf7af409
children 63c19b7fa100
comparison
equal deleted inserted replaced
34480:cbda631c1dde 34482:75de5d456b60
133 # blackbox = 133 # blackbox =
134 # churn = 134 # churn =
135 """, 135 """,
136 } 136 }
137 137
138 def _maybestrurl(maybebytes):
139 if maybebytes is None:
140 return None
141 return pycompat.strurl(maybebytes)
142
143 def _maybebytesurl(maybestr):
144 if maybestr is None:
145 return None
146 return pycompat.bytesurl(maybestr)
138 147
139 class httppasswordmgrdbproxy(object): 148 class httppasswordmgrdbproxy(object):
140 """Delays loading urllib2 until it's needed.""" 149 """Delays loading urllib2 until it's needed."""
141 def __init__(self): 150 def __init__(self):
142 self._mgr = None 151 self._mgr = None
145 if self._mgr is None: 154 if self._mgr is None:
146 self._mgr = urlreq.httppasswordmgrwithdefaultrealm() 155 self._mgr = urlreq.httppasswordmgrwithdefaultrealm()
147 return self._mgr 156 return self._mgr
148 157
149 def add_password(self, realm, uris, user, passwd): 158 def add_password(self, realm, uris, user, passwd):
150 return self._get_mgr().add_password(realm, uris, user, passwd) 159 if isinstance(uris, tuple):
160 uris = tuple(_maybestrurl(u) for u in uris)
161 else:
162 uris = _maybestrurl(uris)
163 return self._get_mgr().add_password(
164 _maybestrurl(realm), uris,
165 _maybestrurl(user), _maybestrurl(passwd))
151 166
152 def find_user_password(self, realm, uri): 167 def find_user_password(self, realm, uri):
153 return self._get_mgr().find_user_password(realm, uri) 168 return tuple(_maybebytesurl(v) for v in
169 self._get_mgr().find_user_password(_maybestrurl(realm),
170 _maybestrurl(uri)))
154 171
155 def _catchterm(*args): 172 def _catchterm(*args):
156 raise error.SignalInterrupt 173 raise error.SignalInterrupt
157 174
158 # unique object used to detect no default value has been provided when 175 # unique object used to detect no default value has been provided when