from functools import wraps
from inspect import ismethod


EXTRACTS = "_extracts"
BINDS = "_binds"


def to_function(callable_object):
    """
    In python, we can't use setattr on a method
    We can instead wrap the method in a function.
    This function will wrap only methods.

    """
    if not ismethod(callable_object):
        return callable_object

    @wraps(callable_object)
    def decorated_method(*args, **kwargs):
        return callable_object(*args, **kwargs)
    return decorated_method


def extracts(*extract):
    """
    On resolving this function with get_from_context decorator -
    updates the context based on the function return value.

    Note: The decorator just marks the function and don't change the return value.
    :param *args: key/s of the return value

    """
    def decorate(func):
        function = to_function(func)
        setattr(function, EXTRACTS, extract)
        return function
    return decorate


def binds(**binds):
    """
    On resolving this function with temporarily_replace_context_keys decorator -
    temporarily updates the context keys.

    Note: The decorator just marks the function.
    :param **binds: (old_context_key, new_context_key) - context keys to rename

    """
    def decorate(func):
        function = to_function(func)
        setattr(function, BINDS, binds)
        return function
    return decorate

e3109e9eb6fcd33d3a48e2996271a541db41c3d4
<mask token>


def to_function(callable_object):
    """
    In python, we can't use setattr on a method
    We can instead wrap the method in a function.
    This function will wrap only methods.

    """
    if not ismethod(callable_object):
        return callable_object

    @wraps(callable_object)
    def decorated_method(*args, **kwargs):
        return callable_object(*args, **kwargs)
    return decorated_method


<mask token>


def binds(**binds):
    """
    On resolving this function with temporarily_replace_context_keys decorator -
    temporarily updates the context keys.

    Note: The decorator just marks the function.
    :param **binds: (old_context_key, new_context_key) - context keys to rename

    """

    def decorate(func):
        function = to_function(func)
        setattr(function, BINDS, binds)
        return function
    return decorate

<mask token>


def to_function(callable_object):
    """
    In python, we can't use setattr on a method
    We can instead wrap the method in a function.
    This function will wrap only methods.

    """
    if not ismethod(callable_object):
        return callable_object

    @wraps(callable_object)
    def decorated_method(*args, **kwargs):
        return callable_object(*args, **kwargs)
    return decorated_method


def extracts(*extract):
    """
    On resolving this function with get_from_context decorator -
    updates the context based on the function return value.

    Note: The decorator just marks the function and don't change the return value.
    :param *args: key/s of the return value

    """

    def decorate(func):
        function = to_function(func)
        setattr(function, EXTRACTS, extract)
        return function
    return decorate


def binds(**binds):
    """
    On resolving this function with temporarily_replace_context_keys decorator -
    temporarily updates the context keys.

    Note: The decorator just marks the function.
    :param **binds: (old_context_key, new_context_key) - context keys to rename

    """

    def decorate(func):
        function = to_function(func)
        setattr(function, BINDS, binds)
        return function
    return decorate

<mask token>
EXTRACTS = '_extracts'
BINDS = '_binds'


def to_function(callable_object):
    """
    In python, we can't use setattr on a method
    We can instead wrap the method in a function.
    This function will wrap only methods.

    """
    if not ismethod(callable_object):
        return callable_object

    @wraps(callable_object)
    def decorated_method(*args, **kwargs):
        return callable_object(*args, **kwargs)
    return decorated_method


def extracts(*extract):
    """
    On resolving this function with get_from_context decorator -
    updates the context based on the function return value.

    Note: The decorator just marks the function and don't change the return value.
    :param *args: key/s of the return value

    """

    def decorate(func):
        function = to_function(func)
        setattr(function, EXTRACTS, extract)
        return function
    return decorate


def binds(**binds):
    """
    On resolving this function with temporarily_replace_context_keys decorator -
    temporarily updates the context keys.

    Note: The decorator just marks the function.
    :param **binds: (old_context_key, new_context_key) - context keys to rename

    """

    def decorate(func):
        function = to_function(func)
        setattr(function, BINDS, binds)
        return function
    return decorate

from functools import wraps
from inspect import ismethod
EXTRACTS = '_extracts'
BINDS = '_binds'


def to_function(callable_object):
    """
    In python, we can't use setattr on a method
    We can instead wrap the method in a function.
    This function will wrap only methods.

    """
    if not ismethod(callable_object):
        return callable_object

    @wraps(callable_object)
    def decorated_method(*args, **kwargs):
        return callable_object(*args, **kwargs)
    return decorated_method


def extracts(*extract):
    """
    On resolving this function with get_from_context decorator -
    updates the context based on the function return value.

    Note: The decorator just marks the function and don't change the return value.
    :param *args: key/s of the return value

    """

    def decorate(func):
        function = to_function(func)
        setattr(function, EXTRACTS, extract)
        return function
    return decorate


def binds(**binds):
    """
    On resolving this function with temporarily_replace_context_keys decorator -
    temporarily updates the context keys.

    Note: The decorator just marks the function.
    :param **binds: (old_context_key, new_context_key) - context keys to rename

    """

    def decorate(func):
        function = to_function(func)
        setattr(function, BINDS, binds)
        return function
    return decorate

from functools import wraps
from inspect import ismethod


EXTRACTS = "_extracts"
BINDS = "_binds"


def to_function(callable_object):
    """
    In python, we can't use setattr on a method
    We can instead wrap the method in a function.
    This function will wrap only methods.

    """
    if not ismethod(callable_object):
        return callable_object

    @wraps(callable_object)
    def decorated_method(*args, **kwargs):
        return callable_object(*args, **kwargs)
    return decorated_method


def extracts(*extract):
    """
    On resolving this function with get_from_context decorator -
    updates the context based on the function return value.

    Note: The decorator just marks the function and don't change the return value.
    :param *args: key/s of the return value

    """
    def decorate(func):
        function = to_function(func)
        setattr(function, EXTRACTS, extract)
        return function
    return decorate


def binds(**binds):
    """
    On resolving this function with temporarily_replace_context_keys decorator -
    temporarily updates the context keys.

    Note: The decorator just marks the function.
    :param **binds: (old_context_key, new_context_key) - context keys to rename

    """
    def decorate(func):
        function = to_function(func)
        setattr(function, BINDS, binds)
        return function
    return decorate
