208 assert callable(func) |
208 assert callable(func) |
209 def closure(*a, **kw): |
209 def closure(*a, **kw): |
210 return func(*(args + a), **kw) |
210 return func(*(args + a), **kw) |
211 return closure |
211 return closure |
212 |
212 |
213 def _updatewrapper(wrap, origfn): |
213 def _updatewrapper(wrap, origfn, unboundwrapper): |
214 '''Copy attributes to wrapper function''' |
214 '''Copy and add some useful attributes to wrapper''' |
215 wrap.__module__ = getattr(origfn, '__module__') |
215 wrap.__module__ = getattr(origfn, '__module__') |
216 wrap.__doc__ = getattr(origfn, '__doc__') |
216 wrap.__doc__ = getattr(origfn, '__doc__') |
217 wrap.__dict__.update(getattr(origfn, '__dict__', {})) |
217 wrap.__dict__.update(getattr(origfn, '__dict__', {})) |
|
218 wrap._origfunc = origfn |
|
219 wrap._unboundwrapper = unboundwrapper |
218 |
220 |
219 def wrapcommand(table, command, wrapper, synopsis=None, docstring=None): |
221 def wrapcommand(table, command, wrapper, synopsis=None, docstring=None): |
220 '''Wrap the command named `command' in table |
222 '''Wrap the command named `command' in table |
221 |
223 |
222 Replace command in the command table with wrapper. The wrapped command will |
224 Replace command in the command table with wrapper. The wrapped command will |
252 key = alias |
254 key = alias |
253 break |
255 break |
254 |
256 |
255 origfn = entry[0] |
257 origfn = entry[0] |
256 wrap = bind(util.checksignature(wrapper), util.checksignature(origfn)) |
258 wrap = bind(util.checksignature(wrapper), util.checksignature(origfn)) |
257 _updatewrapper(wrap, origfn) |
259 _updatewrapper(wrap, origfn, wrapper) |
258 if docstring is not None: |
260 if docstring is not None: |
259 wrap.__doc__ += docstring |
261 wrap.__doc__ += docstring |
260 |
262 |
261 newentry = list(entry) |
263 newentry = list(entry) |
262 newentry[0] = wrap |
264 newentry[0] = wrap |
301 assert callable(wrapper) |
303 assert callable(wrapper) |
302 |
304 |
303 origfn = getattr(container, funcname) |
305 origfn = getattr(container, funcname) |
304 assert callable(origfn) |
306 assert callable(origfn) |
305 wrap = bind(wrapper, origfn) |
307 wrap = bind(wrapper, origfn) |
306 _updatewrapper(wrap, origfn) |
308 _updatewrapper(wrap, origfn, wrapper) |
307 setattr(container, funcname, wrap) |
309 setattr(container, funcname, wrap) |
308 return origfn |
310 return origfn |
309 |
311 |
310 def _disabledpaths(strip_init=False): |
312 def _disabledpaths(strip_init=False): |
311 '''find paths of disabled extensions. returns a dict of {name: path} |
313 '''find paths of disabled extensions. returns a dict of {name: path} |