SILENT KILLERPanel

Current Path: > > opt > cloudlinux > venv > lib64 > python3.11 > site-packages > testfixtures


Operation   : Linux premium131.web-hosting.com 4.18.0-553.44.1.lve.el8.x86_64 #1 SMP Thu Mar 13 14:29:12 UTC 2025 x86_64
Software     : Apache
Server IP    : 162.0.232.56 | Your IP: 216.73.216.111
Domains      : 1034 Domain(s)
Permission   : [ 0755 ]

Files and Folders in: //opt/cloudlinux/venv/lib64/python3.11/site-packages/testfixtures

NameTypeSizeLast ModifiedActions
__pycache__ Directory - -
tests Directory - -
__init__.py File 1223 bytes April 17 2025 13:10:58.
comparison.py File 40081 bytes April 17 2025 13:10:58.
compat.py File 224 bytes April 17 2025 13:10:58.
components.py File 1337 bytes April 17 2025 13:10:58.
datetime.py File 25009 bytes April 17 2025 13:10:58.
django.py File 2954 bytes April 17 2025 13:10:58.
logcapture.py File 11013 bytes April 17 2025 13:10:58.
mock.py File 1234 bytes April 17 2025 13:10:58.
outputcapture.py File 4801 bytes April 17 2025 13:10:58.
popen.py File 10124 bytes April 17 2025 13:10:58.
replace.py File 12441 bytes April 17 2025 13:10:58.
resolve.py File 2103 bytes April 17 2025 13:10:58.
rmtree.py File 2584 bytes April 17 2025 13:10:58.
shouldraise.py File 3664 bytes April 17 2025 13:10:58.
shouldwarn.py File 2266 bytes April 17 2025 13:10:58.
sybil.py File 2334 bytes April 17 2025 13:10:58.
tempdirectory.py File 13196 bytes April 17 2025 13:10:58.
twisted.py File 4915 bytes April 17 2025 13:10:58.
utils.py File 2803 bytes April 17 2025 13:10:58.
version.txt File 6 bytes April 17 2025 13:10:58.

Reading File: //opt/cloudlinux/venv/lib64/python3.11/site-packages/testfixtures/utils.py

import sys
from functools import wraps
from textwrap import dedent

from inspect import getfullargspec
from typing import Callable, Sequence, Any

from . import singleton

DEFAULT = singleton('DEFAULT')
defaults = [DEFAULT]


try:
    from .mock import DEFAULT
except ImportError:  # pragma: no cover
    pass
else:
    defaults.append(DEFAULT)


def generator(*args):
    """
    A utility function for creating a generator that will yield the
    supplied arguments.
    """
    for i in args:
        yield i


class Wrapping:

    attribute_name = None
    new = DEFAULT

    def __init__(self, before: Callable[[], None], after: Callable[[], None]):
        self.before, self.after = before, after

    def __enter__(self):
        return self.before()

    def __exit__(self, exc_type=None, exc_val=None, exc_tb=None):
        if self.after is not None:
            self.after()


def wrap(before: Callable[[], Any], after: Callable[[], Any] = None):
    """
    A decorator that causes the supplied callables to be called before
    or after the wrapped callable, as appropriate.
    """

    wrapping = Wrapping(before, after)

    def wrapper(func):
        if hasattr(func, 'patchings'):
            func.patchings.append(wrapping)
            return func

        @wraps(func)
        def patched(*args, **keywargs):
            extra_args = []
            entered_patchers = []

            to_add = len(getfullargspec(func).args[len(args):])
            added = 0

            exc_info = (None, None, None)
            try:
                for patching in patched.patchings:
                    arg = patching.__enter__()
                    entered_patchers.append(patching)
                    if patching.attribute_name is not None:
                        keywargs.update(arg)
                    elif patching.new in defaults and added < to_add:
                        extra_args.append(arg)
                        added += 1

                args += tuple(extra_args)
                return func(*args, **keywargs)
            except:
                # Pass the exception to __exit__
                exc_info = sys.exc_info()
                # re-raise the exception
                raise
            finally:
                for patching in reversed(entered_patchers):
                    patching.__exit__(*exc_info)

        patched.patchings = [wrapping]
        return patched

    return wrapper


def extend_docstring(docstring: str, objs: Sequence):
    for obj in objs:
        obj.__doc__ = dedent(obj.__doc__) + docstring


def indent(text: str, indent_size: int = 2):
    indented = []
    for do_indent, line in enumerate(text.splitlines(True)):
        if do_indent:
            line = ' '*indent_size + line
        indented.append(line)
    return ''.join(indented)

SILENT KILLER Tool