Ejemplo n.º 1
0
def make_lazy_object(func, *args, **kwargs):
    """ SimpleLazyOjbect 扩展(默认仅接受无参数的函数) """
    partial_func = functools.partial(func, *args, **kwargs)
    return functional.SimpleLazyObject(partial_func)
 def process_request(self, request):
     request.service_is_readonly = functional.SimpleLazyObject(
         self.is_service_read_only)
Ejemplo n.º 3
0
from django.utils.module_loading import import_string
from django.conf import settings
from django.utils import functional


def get_user_management():
    return import_string(settings.USER_MGMT_BACKEND)()


user_mgtm_backend = functional.SimpleLazyObject(get_user_management)
Ejemplo n.º 4
0

def get_s3():
    return boto3.client("s3", endpoint_url=settings.AWS_ENDPOINT_URL)


def get_sqs():
    return boto3.client(
        "sqs",
        endpoint_url=settings.AWS_ENDPOINT_URL,
        aws_access_key_id=settings.AWS_ACCESS_KEY_ID,
        aws_secret_access_key=settings.AWS_SECRET_ACCESS_KEY,
    )


s3 = functional.SimpleLazyObject(get_s3)
sqs = functional.SimpleLazyObject(get_sqs)


def local_lambda_invoke(payload):
    data = {
        "Records": [{
            "messageId": "059f36b4-87a3-44ab-83d2-661975830a7d",
            "receiptHandle": "AQEBwJnKyrHigUMZj6rYigCgxlaS3SLy0a...",
            "body": json.dumps(payload),
            "attributes": {
                "ApproximateReceiveCount": "1",
                "SentTimestamp": "1545082649183",
                "SenderId": "AIDAIENQZJOLO23YVJ4VO",
                "ApproximateFirstReceiveTimestamp": "1545082649185",
            },
Ejemplo n.º 5
0
def get_lazy_queryset(alias):
    """ Queryset(lazy)
    """
    return functional.SimpleLazyObject(partial(get_queryset, alias))
Ejemplo n.º 6
0
def get_lazy_dao(alias, dao_class_or_namespace=None):
    """ Manager(lazy)
    """
    return functional.SimpleLazyObject(
        partial(get_dao, alias, dao_class_or_namespace=dao_class_or_namespace))
Ejemplo n.º 7
0
def get_lazy_model(alias):
    """ Model(lazy)
    """
    return functional.SimpleLazyObject(partial(get_model, alias))