示例#1
0
 def __call__(self, environ, start_response):
     rtree = environ["psid.rtree"] = self.rtree
     
     # debugging
     def error_callback(exc_info):
         pass
     def ok_callback():
         pass
     return catch_errors(self.app, environ, start_response,
                         error_callback, ok_callback)
示例#2
0
    def __call__(self, environ, start_response):
        dm = self._init_datamanager(environ)
        rindex = self.rindex_handler(environ, key=self.rindex_key)
        environ["psid.rtree"] = RtreeProxy(dm, environ['psid.rtree_raw'], rindex)

        # do any cleanup here
        def error_callback(exc_info):
            self.dm = None
        def ok_callback():
            self.dm = None
        return catch_errors(self.app, environ, start_response,
                            error_callback, ok_callback)
 def wrapped(environ, start_response):
     log = logging.getLogger('loggerhead')
     url = construct_url(environ)
     log.info("Starting to process %s", url)
     start_time = time.time()
     def request_done_ok():
         log.info("Processed ok %s [%0.3f seconds]", url, time.time() -
                 start_time)
     def request_done_err(exc_info):
         log.info("Processed err %s [%0.3f seconds]: %s", url, time.time() -
                 start_time, traceback.format_exception_only(*exc_info[:2]))
     return catch_errors(app, environ, start_response, request_done_err,
             request_done_ok)
示例#4
0
    def __call__(self, environ, start_response):
        conn = [self.conn]
        if self.use_transaction:
            conn[0] = conn[0].transaction()
        any_errors = []
        use_transaction = [self.use_transaction]
        self.hub.threadConnection = conn[0]

        def abort():
            assert use_transaction[0], (
                "You cannot abort, because a transaction is not being used")
            any_errors.append(None)

        def begin():
            if use_transaction[0]:
                if any_errors:
                    conn[0].rollback()
                else:
                    conn[0].commit()
            any_errors[:] = []
            use_transaction[0] = True
            conn[0] = self.conn.transaction()
            self.hub.threadConnection = conn[0]

        def error(exc_info=None):
            any_errors.append(None)
            ok()

        def ok():
            if use_transaction[0]:
                if any_errors:
                    conn[0].rollback()
                else:
                    conn[0].commit(close=True)
            self.hub.threadConnection = None

        def in_transaction():
            return use_transaction[0]

        def get_connection():
            return conn[0]

        environ['sqlobject.get_connection'] = get_connection
        environ['sqlobject.abort'] = abort
        environ['sqlobject.begin'] = begin
        environ['sqlobject.in_transaction'] = in_transaction
        return catch_errors(self.app,
                            environ,
                            start_response,
                            error_callback=error,
                            ok_callback=ok)
示例#5
0
 def __call__(self, environ, start_response):
     dm = self._init_datamanager(environ)
     
     # our add and delete hooks
     environ["psid.rtree.add"] = dm.add
     environ["psid.rtree.add"] = dm.delete
     
     # for debugging remove
     def error_callback(exc_info):
         pass
     def ok_callback():
         pass
     return catch_errors(self.app, environ, start_response,
                         error_callback, ok_callback)
示例#6
0
 def __call__(self, environ, start_response):
     length = environ.get('CONTENT_LENGTH', 0)
     if length and int(length) > self.threshold:
         # replace input file object
         self.monitor.append(environ)
         environ[ENVIRON_RECEIVED] = 0
         environ[REQUEST_STARTED] = time.time()
         environ[REQUEST_FINISHED] = None
         environ['wsgi.input'] = \
             _ProgressFile(environ, environ['wsgi.input'])
         def finalizer(exc_info=None):
             environ[REQUEST_FINISHED] = time.time()
         return catch_errors(self.application, environ,
                    start_response, finalizer, finalizer)
     return self.application(environ, start_response)
示例#7
0
    def __call__(self, environ, start_response):
        conn = [self.conn]
        if self.use_transaction:
            conn[0] = conn[0].transaction()
        any_errors = []
        use_transaction = [self.use_transaction]
        self.hub.threadConnection = conn[0]

        def abort():
            assert use_transaction[0], (
                "You cannot abort, because a transaction is not being used")
            any_errors.append(None)

        def begin():
            if use_transaction[0]:
                if any_errors:
                    conn[0].rollback()
                else:
                    conn[0].commit()
            any_errors[:] = []
            use_transaction[0] = True
            conn[0] = self.conn.transaction()
            self.hub.threadConnection = conn[0]

        def error(exc_info=None):
            any_errors.append(None)
            ok()

        def ok():
            if use_transaction[0]:
                if any_errors:
                    conn[0].rollback()
                else:
                    conn[0].commit(close=True)
            self.hub.threadConnection = None

        def in_transaction():
            return use_transaction[0]

        def get_connection():
            return conn[0]

        environ['sqlobject.get_connection'] = get_connection
        environ['sqlobject.abort'] = abort
        environ['sqlobject.begin'] = begin
        environ['sqlobject.in_transaction'] = in_transaction
        return catch_errors(self.app, environ, start_response,
                            error_callback=error, ok_callback=ok)
示例#8
0
    def wrapped(environ, start_response):
        url = construct_url(environ)
        log.info("Starting to process %s", url)
        start_time = time.time()

        def request_done_ok():
            log.info("Processed ok %s [%0.3f seconds]", url,
                     time.time() - start_time)

        def request_done_err(exc_info):
            log.info("Processed err %s [%0.3f seconds]: %s", url,
                     time.time() - start_time,
                     traceback.format_exception_only(*exc_info[:2]))

        return catch_errors(app, environ, start_response, request_done_err,
                            request_done_ok)
示例#9
0
    def __call__(self, environ, start_response):
        length = environ.get('CONTENT_LENGTH', 0)
        if length and int(length) > self.threshold:
            # replace input file object
            self.monitor.append(environ)
            environ[ENVIRON_RECEIVED] = 0
            environ[REQUEST_STARTED] = time.time()
            environ[REQUEST_FINISHED] = None
            environ['wsgi.input'] = \
                _ProgressFile(environ, environ['wsgi.input'])

            def finalizer(exc_info=None):
                environ[REQUEST_FINISHED] = time.time()

            return catch_errors(self.application, environ, start_response,
                                finalizer, finalizer)
        return self.application(environ, start_response)