Exemple #1
0
    def prefetch_object(self, this, f, objid, *args, **kwds):
        import tornado.web

        # validate objid format
        # objid = kwds.get(OBJID_REGEX_GROUP_NAME)
        objid = str(objid)[:40]

        o = self.registry.get(objid)
        if o is None:
            raise tornado.web.HTTPError(404, 'No such Object')
        else:
            setattr(self.get_context(), OBJECT_ATTR, o)

        val = f(this, objid, *args, **kwds)

        # release ref to object, to allow weakrefs
        # to be reaped
        setattr(self.get_context(), OBJECT_ATTR, None)
        # should have been put there by ExhibitionitRequestHandler
        # if Init was called

        from exhibitionist.log import getLogger
        if not hasattr(this,SUPER_CANARY):
            if not self.in_test:

                getLogger(__name__).error("RequestHandler did not call super().__init__ ")
        else:
            delattr(this,SUPER_CANARY)


        return val
Exemple #2
0
# -*- coding: utf-8 -*-
from __future__ import print_function

import logging
from functools import wraps
import threading

from exhibitionist.log import getLogger

logger = getLogger("decorator")

# These are the attribute name used to store
# the decorator supplied values on the class
VIEW_NAME_ATTR = "view_name" # key in dict under self.STORE_UNDER_ATTR
ROUTE_ATTR = "view_route" # key in dict under self.STORE_UNDER_ATTR
OBJECT_ATTR = 'object'
AUTO_OBJ_ATTR = 'auto_obj'
KWDS_ATTR = 'kwds'

# the name of the group/argument used to capture the objid
OBJID_REGEX_GROUP_NAME = 'objid'
# the pat placeholder to be replaced by objid regx
OBJID_PLACEHOLDER = '{{%s}}' % OBJID_REGEX_GROUP_NAME
MIN_OBJID_LEN = 8
OBJID_REGEX = '(?P<{obj_group_name}>[a-z\d]{{{min_len},40}})'.format(
    min_len=MIN_OBJID_LEN,
    obj_group_name=OBJID_REGEX_GROUP_NAME)

GET_REG_OBJ_ATTR = "get_obj_from_registry"
GET_VIEW_ATTR = "get_view_url"
PUBSUB_ATTR = "pubsub"