comparison mercurial/ui.py @ 35940:72de5c504833

py3: factor out helpers to apply string conversion recursively
author Yuya Nishihara <yuya@tcha.org>
date Sat, 27 Jan 2018 13:33:31 +0900
parents 4b1c04082cdc
children 704095e27c5c
comparison
equal deleted inserted replaced
35939:d5457d94e1c9 35940:72de5c504833
146 # churn = 146 # churn =
147 """, 147 """,
148 } 148 }
149 149
150 def _maybestrurl(maybebytes): 150 def _maybestrurl(maybebytes):
151 if maybebytes is None: 151 return util.rapply(pycompat.strurl, maybebytes)
152 return None
153 return pycompat.strurl(maybebytes)
154 152
155 def _maybebytesurl(maybestr): 153 def _maybebytesurl(maybestr):
156 if maybestr is None: 154 return util.rapply(pycompat.bytesurl, maybestr)
157 return None
158 return pycompat.bytesurl(maybestr)
159 155
160 class httppasswordmgrdbproxy(object): 156 class httppasswordmgrdbproxy(object):
161 """Delays loading urllib2 until it's needed.""" 157 """Delays loading urllib2 until it's needed."""
162 def __init__(self): 158 def __init__(self):
163 self._mgr = None 159 self._mgr = None
166 if self._mgr is None: 162 if self._mgr is None:
167 self._mgr = urlreq.httppasswordmgrwithdefaultrealm() 163 self._mgr = urlreq.httppasswordmgrwithdefaultrealm()
168 return self._mgr 164 return self._mgr
169 165
170 def add_password(self, realm, uris, user, passwd): 166 def add_password(self, realm, uris, user, passwd):
171 if isinstance(uris, tuple):
172 uris = tuple(_maybestrurl(u) for u in uris)
173 else:
174 uris = _maybestrurl(uris)
175 return self._get_mgr().add_password( 167 return self._get_mgr().add_password(
176 _maybestrurl(realm), uris, 168 _maybestrurl(realm), _maybestrurl(uris),
177 _maybestrurl(user), _maybestrurl(passwd)) 169 _maybestrurl(user), _maybestrurl(passwd))
178 170
179 def find_user_password(self, realm, uri): 171 def find_user_password(self, realm, uri):
180 return tuple(_maybebytesurl(v) for v in 172 mgr = self._get_mgr()
181 self._get_mgr().find_user_password(_maybestrurl(realm), 173 return _maybebytesurl(mgr.find_user_password(_maybestrurl(realm),
182 _maybestrurl(uri))) 174 _maybestrurl(uri)))
183 175
184 def _catchterm(*args): 176 def _catchterm(*args):
185 raise error.SignalInterrupt 177 raise error.SignalInterrupt
186 178
187 # unique object used to detect no default value has been provided when 179 # unique object used to detect no default value has been provided when