<commit_before>from __future__ import (division, unicode_literals)
from functools import wraps
from collections import defaultdict
import logging
import datetime

from django.conf import settings as global_settings

import rq.utils
from rq.compat import string_types
import django_rq
from django_rq.queues import get_queue
from rq.defaults import DEFAULT_RESULT_TTL
from rq.queue import Queue

from .serializer import default_secure_serializer as secure_serializer


logger = logging.getLogger(__name__)



def execute(method_name, *args, **kwargs):
    return rq.utils.import_attribute(method_name)(*args, **kwargs)


def secure_job_proxy(*args, **kwargs):
    """
    The is a proxy method, each method wanted to be stored securely, it will be directed to this method. With first
    argument is the encrypted original method name.
    :param args: Always three parameters, first is the encrypted method name, second is the encrypted actual args,
    third is the encrypted actual kwargs
    :return: actual method return value
    """
    actual_function_name = secure_serializer.loads(args[0])
    decrypted_args = secure_serializer.loads(args[1])
    kwargs = secure_serializer.loads(args[2])
    return execute(actual_function_name, *decrypted_args, **kwargs)


def rq_job(func_or_queue, connection=None, *args, **kwargs):
    class _rq_job(object):
        def __init__(self, queue, connection=None, timeout=None,
                     result_ttl=DEFAULT_RESULT_TTL, ttl=None):
            """A decorator that adds :
            ``delay`` method to the decorated function,
            which in turn creates a RQ job when called. Accepts a required
            ``queue`` argument that can be either a ``Queue`` instance or a string
            denoting the queue name.  For example:<commit_msg>move import scope to rq_job<commit_after>from __future__ import (division, unicode_literals)
from functools import wraps
from collections import defaultdict
import logging
import datetime

from django.conf import settings as global_settings

import rq.utils
from rq.compat import string_types
from rq.defaults import DEFAULT_RESULT_TTL
from rq.queue import Queue

from .serializer import default_secure_serializer as secure_serializer


logger = logging.getLogger(__name__)



def execute(method_name, *args, **kwargs):
    return rq.utils.import_attribute(method_name)(*args, **kwargs)


def secure_job_proxy(*args, **kwargs):
    """
    The is a proxy method, each method wanted to be stored securely, it will be directed to this method. With first
    argument is the encrypted original method name.
    :param args: Always three parameters, first is the encrypted method name, second is the encrypted actual args,
    third is the encrypted actual kwargs
    :return: actual method return value
    """
    actual_function_name = secure_serializer.loads(args[0])
    decrypted_args = secure_serializer.loads(args[1])
    kwargs = secure_serializer.loads(args[2])
    return execute(actual_function_name, *decrypted_args, **kwargs)


def rq_job(func_or_queue, connection=None, *args, **kwargs):
    import django_rq
    from django_rq.queues import get_queue
    class _rq_job(object):
        def __init__(self, queue, connection=None, timeout=None,
                     result_ttl=DEFAULT_RESULT_TTL, ttl=None):
            """A decorator that adds :
            ``delay`` method to the decorated function,
            which in turn creates a RQ job when called. Accepts a required
            ``queue`` argument that can be either a ``Queue`` instance or a string
            denoting the queue name.  For example:
{'fraction_non_alphanumeric': 0.0712707182320442, 'fraction_numerical': 0.0016574585635359116, 'mean_word_length': 3.9670781893004117, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7119425', 'n_tokens_mistral': 1000, 'n_tokens_neox': 979, 'n_words': 365}