Show More
@@ -1594,7 +1594,7 b' def showmarker(fm, marker, index=None):' | |||
|
1594 | 1594 | fm.write('date', '(%s) ', fm.formatdate(marker.date())) |
|
1595 | 1595 | meta = marker.metadata().copy() |
|
1596 | 1596 | meta.pop('date', None) |
|
1597 | smeta = {_maybebytestr(k): _maybebytestr(v) for k, v in meta.iteritems()} | |
|
1597 | smeta = util.rapply(_maybebytestr, meta) | |
|
1598 | 1598 | fm.write('metadata', '{%s}', fm.formatdict(smeta, fmt='%r: %r', sep=', ')) |
|
1599 | 1599 | fm.plain('\n') |
|
1600 | 1600 |
@@ -148,14 +148,10 b' b"""# example system-wide hg config (see' | |||
|
148 | 148 | } |
|
149 | 149 | |
|
150 | 150 | def _maybestrurl(maybebytes): |
|
151 | if maybebytes is None: | |
|
152 | return None | |
|
153 | return pycompat.strurl(maybebytes) | |
|
151 | return util.rapply(pycompat.strurl, maybebytes) | |
|
154 | 152 | |
|
155 | 153 | def _maybebytesurl(maybestr): |
|
156 | if maybestr is None: | |
|
157 | return None | |
|
158 | return pycompat.bytesurl(maybestr) | |
|
154 | return util.rapply(pycompat.bytesurl, maybestr) | |
|
159 | 155 | |
|
160 | 156 | class httppasswordmgrdbproxy(object): |
|
161 | 157 | """Delays loading urllib2 until it's needed.""" |
@@ -168,18 +164,14 b' class httppasswordmgrdbproxy(object):' | |||
|
168 | 164 | return self._mgr |
|
169 | 165 | |
|
170 | 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 | 167 | return self._get_mgr().add_password( |
|
176 | _maybestrurl(realm), uris, | |
|
168 | _maybestrurl(realm), _maybestrurl(uris), | |
|
177 | 169 | _maybestrurl(user), _maybestrurl(passwd)) |
|
178 | 170 | |
|
179 | 171 | def find_user_password(self, realm, uri): |
|
180 | return tuple(_maybebytesurl(v) for v in | |
|
181 |
|
|
|
182 |
|
|
|
172 | mgr = self._get_mgr() | |
|
173 | return _maybebytesurl(mgr.find_user_password(_maybestrurl(realm), | |
|
174 | _maybestrurl(uri))) | |
|
183 | 175 | |
|
184 | 176 | def _catchterm(*args): |
|
185 | 177 | raise error.SignalInterrupt |
@@ -183,6 +183,39 b' os.stat_float_times(False)' | |||
|
183 | 183 | def safehasattr(thing, attr): |
|
184 | 184 | return getattr(thing, attr, _notset) is not _notset |
|
185 | 185 | |
|
186 | def _rapply(f, xs): | |
|
187 | if xs is None: | |
|
188 | # assume None means non-value of optional data | |
|
189 | return xs | |
|
190 | if isinstance(xs, (list, set, tuple)): | |
|
191 | return type(xs)(_rapply(f, x) for x in xs) | |
|
192 | if isinstance(xs, dict): | |
|
193 | return type(xs)((_rapply(f, k), _rapply(f, v)) for k, v in xs.items()) | |
|
194 | return f(xs) | |
|
195 | ||
|
196 | def rapply(f, xs): | |
|
197 | """Apply function recursively to every item preserving the data structure | |
|
198 | ||
|
199 | >>> def f(x): | |
|
200 | ... return 'f(%s)' % x | |
|
201 | >>> rapply(f, None) is None | |
|
202 | True | |
|
203 | >>> rapply(f, 'a') | |
|
204 | 'f(a)' | |
|
205 | >>> rapply(f, {'a'}) == {'f(a)'} | |
|
206 | True | |
|
207 | >>> rapply(f, ['a', 'b', None, {'c': 'd'}, []]) | |
|
208 | ['f(a)', 'f(b)', None, {'f(c)': 'f(d)'}, []] | |
|
209 | ||
|
210 | >>> xs = [object()] | |
|
211 | >>> rapply(pycompat.identity, xs) is xs | |
|
212 | True | |
|
213 | """ | |
|
214 | if f is pycompat.identity: | |
|
215 | # fast path mainly for py2 | |
|
216 | return xs | |
|
217 | return _rapply(f, xs) | |
|
218 | ||
|
186 | 219 | def bytesinput(fin, fout, *args, **kwargs): |
|
187 | 220 | sin, sout = sys.stdin, sys.stdout |
|
188 | 221 | try: |
@@ -123,10 +123,7 b' class webproto(abstractserverproto):' | |||
|
123 | 123 | return [data[k] for k in keys] |
|
124 | 124 | |
|
125 | 125 | def _args(self): |
|
126 | args = self._req.form.copy() | |
|
127 | if pycompat.ispy3: | |
|
128 | args = {k.encode('ascii'): [v.encode('ascii') for v in vs] | |
|
129 | for k, vs in args.items()} | |
|
126 | args = util.rapply(pycompat.bytesurl, self._req.form.copy()) | |
|
130 | 127 | postlen = int(self._req.env.get(r'HTTP_X_HGARGS_POST', 0)) |
|
131 | 128 | if postlen: |
|
132 | 129 | args.update(cgi.parse_qs( |
General Comments 0
You need to be logged in to leave comments.
Login now