How to use the funcy.decorator function in funcy

To help you get started, we’ve selected a few funcy 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 idrdex / star-django / djapi / auth.py View on Github external
    @decorator
    def deco(call):
        try:
            attempt_auth(call.request)
        except PermissionDenied as e:
            return json(status, detail=str(e))
        # Check test
        if test(call.request.user):
            return call()
        else:
            return json(status, detail=message)
github robotcaresystems / RoboticsLanguage / RoboticsLanguage / Base / Utilities.py View on Github external
@decorator
def name_all_calls(function):
  print('function name:' + function._func.__name__)
  return function()
github idrdex / star-django / djapi / __init__.py View on Github external
@decorator
def validate(call, form=None):
    # request.content_type is new in Django 1.10
    if hasattr(call.request, 'content_type'):
        content_type = call.request.content_type
    else:
        content_type, _ = cgi.parse_header(call.request.META.get('CONTENT_TYPE', ''))
    # Parse JSON or fallback to urlencoded
    if content_type == 'application/json':
        try:
            data = _json.loads(call.request.body)
        except ValueError:
            return json(400, detail="Failed parsing JSON")
    else:
        data = call.request.POST

    aform = form(data)
github Suor / aioscrape / aioscrape / __init__.py View on Github external
@decorator
def configurable_middleware(call):
    prefix = call._func.__name__ + '__'
    overwrites = {cut_prefix(name, prefix): value
                  for name, value in SETTINGS.get().items() if name.startswith(prefix)}
    return call(**overwrites)
github iterative / dvc / dvc / remote / gdrive.py View on Github external
@decorator
def _wrap_pydrive_retriable(call):
    from apiclient import errors
    from pydrive.files import ApiRequestError

    try:
        result = call()
    except (ApiRequestError, errors.HttpError) as exception:
        retry_codes = ["403", "500", "502", "503", "504"]
        if any(
            "HttpError {}".format(code) in str(exception)
            for code in retry_codes
        ):
            raise GDriveRetriableError(msg="Google API request failed")
        raise
    return result
github mozilla / dxr / dxr / plugins / clang / condense.py View on Github external
@decorator
def without(call, *keys):
    """Return dictionary without the given keys"""
    return select_keys(lambda k: k not in keys, call())
github idrdex / star-django / legacy / management / commands / fill_probes.py View on Github external
@decorator
def ftp_retry(call):
    tries = 50
    for attempt in range(tries):
        try:
            try:
                return call()
            except ftplib.all_errors:
                # Connection could be in inconsistent state, close and forget
                shared.conn.close()
                del shared.conn
                raise
        except (ftplib.Error, socket.error, EOFError) as e:
            if error_persistent(e):
                raise
            # Reraise error on last attempt
            elif attempt + 1 == tries:
github robotcaresystems / RoboticsLanguage / RoboticsLanguage / Base / Utilities.py View on Github external
@decorator
def cache_in_disk(function):
  cache_path = '/.rol/cache/'

  # create a name based on the module and function name
  name = __name__ + '.' + function._func.__name__

  # create a the path name for the file to cache
  path = os.path.expanduser("~") + cache_path + name + '.cache'

  if os.path.isfile(path):
    # if file exists just load it
    return dill.load(open(path, "rb"))
  else:
    # otherwise run function
    data = function()
github Suor / aioscrape / aioscrape / __init__.py View on Github external
@decorator
def adhoc_session(call):
    return with_session(call())
github Suor / django-cacheops / cacheops / transaction.py View on Github external
@decorator
def queue_when_in_transaction(call):
    if transaction_states[call.using]:
        transaction_states[call.using].push((call, (), {}))
    else:
        return call()