Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@wrapt.decorator
def deprecated_wrapper(wrapped, instance, args, kwargs):
if is_init_or_classmethod(wrapped):
deprecated_thing = wrapped.__self__.__class__
warnings.warn('DEPRECATED: %s. %s' % (deprecated_thing.__class__, message), DeprecationWarning, stacklevel=2)
else:
deprecated_thing = wrapped
warnings.warn('DEPRECATED: %s. %s' % (deprecated_thing, message), DeprecationWarning, stacklevel=2)
return wrapped(*args, **kwargs)
@wrapt.decorator
def valid_combined_production_activity(wrapped, instance, args, kwargs):
"""Check to make sure the activity meets the assumptions for combined production allocation.
Each refernce product exchange must be a variable name, so that the amount of inputs can vary depending on whether that reference product is chosen in subdivision.
"""
dataset = kwargs.get('dataset') or args[0]
for exc in dataset['exchanges']:
if (exc['type'] == 'reference product'
and exc['amount']
and not exc.get('variable')):
message = ("Ref. product exchange in combined production must have"
" variable name:\n{}\nIn dataset:\n{}")
raise InvalidExchange(message.format(pformat(exc), pformat(dataset)))
return wrapped(*args, **kwargs)
@wrapt.decorator
def wrapper(wrapped, instance, args, kwargs):
if not set(wrapped.__dict__) & set(func_dict):
wrapped.__dict__.update(func_dict)
return wrapped(*args, **kwargs)
return wrapper
@wrapt.decorator
def wrapped_render(wrapped, instance, args, kwargs):
tracked_request = TrackedRequest.instance()
span = tracked_request.start_span(operation="Template/Render")
span.tag("name", instance.name)
try:
return wrapped(*args, **kwargs)
finally:
tracked_request.stop_span()
@wrapt.decorator
def check_contracts(wrapped, instance, args, kwargs):
"""A decorator for automatically checking preconditions and type contracts for a function."""
try:
if instance and inspect.isclass(instance):
# This is a class method, so there is no instance.
return _check_function_contracts(wrapped, None, args, kwargs)
else:
return _check_function_contracts(wrapped, instance, args, kwargs)
except AssertionError as e:
raise AssertionError(str(e)) from None
@wrapt.decorator
def type_check_wrapper(method, instance, args, kwargs):
"""Wraps a method so that it is type-checked.
:param method: The method to wrap
:type method: (T) -> U
:return: The result of calling the method with the given parameters
:rtype: U
"""
if instance is not None:
raise Exception("Instance shouldn't be set.")
parameter_names = inspect.getargspec(method).args # pylint: disable=deprecated-method
defaults = inspect.getargspec(method).defaults # pylint: disable=deprecated-method
parameters = self._collect_parameters(parameter_names, args, kwargs, defaults)
parameter_checker.check_types(parameters, parameter_types, self._strict_floats)
@wrapt.decorator
def _to_yaml_tags(wrapped, instance, args, kwargs):
"""
New in v17
public decorator for yaml generator
"""
return wrapped(*args, **kwargs)
@_decorator
def system_entry_point(wrapped, instance, args, kwargs):
"""
Decorator for wrapping functions that enter a system context. This should decorate every method a user might
call. This will allow us to add differentiation between what is a user error and what is a system failure.
Furthermore, we will clean the exception trace so as to make more sense to the user--allowing them to know if they
should take action themselves or pass on to the platform owners. We will dispatch metrics and such appropriately.
"""
try:
_CONTEXT_STACK.append(_SYSTEM_CONTEXT)
if _is_base_context():
try:
return wrapped(*args, **kwargs)
except FlyteScopedException as ex:
_reraise(ex.type, ex.value, ex.traceback)
else:
try:
@wrapt.decorator
def constrain_landmarks(wrapped, instance, args, kwargs):
def _execute(image, *args, **kwargs):
feature = wrapped(image, *args, **kwargs)
# after calculation, constrain the landmarks to the bounds
feature.constrain_landmarks_to_bounds()
return feature
return _execute(*args, **kwargs)
@wrapt.decorator
def __call__(self, wrapped, instance, args, kwargs):
"""Implement __call__ function for decorator.
Args:
wrapped (callable): The wrapped function which in turns
needs to be called by your wrapper function.
instance (App): The object to which the wrapped
function was bound when it was called.
args (list): The list of positional arguments supplied
when the decorated function was called.
kwargs (dict): The dictionary of keyword arguments
supplied when the decorated function was called.
Returns:
function: The custom decorator function.
"""