How to use the wrapt.function_wrapper function in wrapt

To help you get started, we’ve selected a few wrapt examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ionelmc / python-lazy-object-proxy / tests / test_monkey_patching.py View on Github external
            @wrapt.function_wrapper
            def __call__(self, wrapped, instance, args, kwargs):
                _self.assertEqual(type(self), wrapper)
                called.append((args, kwargs))
                _self.assertEqual(instance, None)
                _self.assertEqual(args, _args)
                _self.assertEqual(kwargs, _kwargs)
                return wrapped(*args, **kwargs)
github ionelmc / python-lazy-object-proxy / tests / test_monkey_patching.py View on Github external
        @wrapt.function_wrapper
        def wrapper(wrapped, instance, args, kwargs):
            called.append((args, kwargs))
            self.assertEqual(instance, _instance)
            self.assertEqual(args, _args)
            self.assertEqual(kwargs, _kwargs)
            return wrapped(*args, **kwargs)
github openworm / owmeta / owmeta / import_override.py View on Github external
        @wrapt.function_wrapper
        def import_wrapper(orig__import__, __, args, kwargs):
            m = [None, None]

            module_name, caller = module_name_from_import_args(args)

            def cb():
                if len(args) >= 3:
                    importer_locals = args[2]
                    if importer_locals is not None:
                        splits = module_name.split('.', 1)
                        if len(splits) == 2:
                            first, rest = splits
                            local = importer_locals.get(first, None)
                            if isinstance(local, ImportContextualizer):
                                new_args = list(args)
                                new_args[0] = rest