# Path: pyinstrument/vendor/decorator.py
# def decorator(caller, _func=None):
#     """decorator(caller) converts a caller function into a decorator"""
#     if _func is not None:  # return a decorated function
#         # this is obsolete behavior; you should use decorate instead
#         return decorate(_func, caller)
#     # else return a decorator function
#     defaultargs, defaults = '', ()
#     if inspect.isclass(caller):
#         name = caller.__name__.lower()
#         doc = 'decorator(%s) converts functions/generators into ' \
#             'factories of %s objects' % (caller.__name__, caller.__name__)
#     elif inspect.isfunction(caller):
#         if caller.__name__ == '<lambda>':
#             name = '_lambda_'
#         else:
#             name = caller.__name__
#         doc = caller.__doc__
#         nargs = caller.__code__.co_argcount
#         ndefs = len(caller.__defaults__ or ())
#         defaultargs = ', '.join(caller.__code__.co_varnames[nargs-ndefs:nargs])
#         if defaultargs:
#             defaultargs += ','
#         defaults = caller.__defaults__
#     else:  # assume caller is an object with a __call__ method
#         name = caller.__class__.__name__.lower()
#         doc = caller.__call__.__doc__
#     evaldict = dict(_call=caller, _decorate_=decorate)
#     dec = FunctionMaker.create(
#         '%s(%s func)' % (name, defaultargs),
#         'if func is None: return lambda func:  _decorate_(func, _call, (%s))\n'
#         'return _decorate_(func, _call, (%s))' % (defaultargs, defaultargs),
#         evaldict, doc=doc, module=caller.__module__, __wrapped__=caller)
#     if defaults:
#         dec.__defaults__ = defaults + (None,)
#     return dec


import codecs
import importlib
import os
import sys
import warnings
from typing import IO
from pyinstrument.vendor.decorator import decorator
def truncate(string: str, max_length: int):
    if len(string) > max_length:
        return string[0 : max_length - 3] + "..."
    return string


@decorator
def deprecated(func, *args, **kwargs):
    """ Marks a function as deprecated. """
    warnings.warn(
        f"{func} is deprecated and should no longer be used.",
        DeprecationWarning,
        stacklevel=3,
    )
    return func(*args, **kwargs)


def deprecated_option(option_name, message=""):
    """ Marks an option as deprecated. """

    def caller(func, *args, **kwargs):
        if option_name in kwargs:
            warnings.warn(
                f"{option_name} is deprecated. {message}",
                DeprecationWarning,
                stacklevel=3,
            )

        return func(*args, **kwargs)


# Path: pyinstrument/vendor/decorator.py
# def decorator(caller, _func=None):
#     """decorator(caller) converts a caller function into a decorator"""
#     if _func is not None:  # return a decorated function
#         # this is obsolete behavior; you should use decorate instead
#         return decorate(_func, caller)
#     # else return a decorator function
#     defaultargs, defaults = '', ()
#     if inspect.isclass(caller):
#         name = caller.__name__.lower()
#         doc = 'decorator(%s) converts functions/generators into ' \
#             'factories of %s objects' % (caller.__name__, caller.__name__)
#     elif inspect.isfunction(caller):
#         if caller.__name__ == '<lambda>':
#             name = '_lambda_'
#         else:
#             name = caller.__name__
#         doc = caller.__doc__
#         nargs = caller.__code__.co_argcount
#         ndefs = len(caller.__defaults__ or ())
#         defaultargs = ', '.join(caller.__code__.co_varnames[nargs-ndefs:nargs])
#         if defaultargs:
#             defaultargs += ','
#         defaults = caller.__defaults__
#     else:  # assume caller is an object with a __call__ method
#         name = caller.__class__.__name__.lower()
#         doc = caller.__call__.__doc__
#     evaldict = dict(_call=caller, _decorate_=decorate)
#     dec = FunctionMaker.create(
#         '%s(%s func)' % (name, defaultargs),
#         'if func is None: return lambda func:  _decorate_(func, _call, (%s))\n'
#         'return _decorate_(func, _call, (%s))' % (defaultargs, defaultargs),
#         evaldict, doc=doc, module=caller.__module__, __wrapped__=caller)
#     if defaults:
#         dec.__defaults__ = defaults + (None,)
#     return dec


# Path: pyinstrument/util.py
import codecs
import importlib
import os
import sys
import warnings
from typing import IO
from pyinstrument.vendor.decorator import decorator

def truncate(string: str, max_length: int):
    if len(string) > max_length:
        return string[0 : max_length - 3] + "..."
    return string


@decorator
def deprecated(func, *args, **kwargs):
    """ Marks a function as deprecated. """
    warnings.warn(
        f"{func} is deprecated and should no longer be used.",
        DeprecationWarning,
        stacklevel=3,
    )
    return func(*args, **kwargs)


def deprecated_option(option_name, message=""):
    """ Marks an option as deprecated. """

    def caller(func, *args, **kwargs):
        if option_name in kwargs:
            warnings.warn(
                f"{option_name} is deprecated. {message}",
                DeprecationWarning,
                stacklevel=3,
            )

        return func(*args, **kwargs)


    return decorator(caller)