Example #1
0
    def visit_for_key(self, visit_key):
        '''
        Return the visit for this key or None if the visit doesn't exist or has
        expired.
        '''
        log.debug('JsonFasVisitManager.visit_for_key: enter')
        # Hit any URL in fas2 with the visit_key set.  That will call the
        # new_visit method in fas2
        # We only need to get the session cookie from this request
        request_data = self.fas.refresh_session(visit_key)
        session_id = request_data[0]

        # Knowing what happens in turbogears/visit/api.py when this is called,
        # we can shortcircuit this step and avoid a round trip to the FAS
        # server.
        # if visit_key != session_id:
        #     # visit has expired
        #     return None
        # # Hitting FAS has already updated the visit.
        # return Visit(visit_key, False)
        log.debug('JsonFasVisitManager.visit_for_key: exit')
        if visit_key != session_id:
            return Visit(session_id, True)
        else:
            return Visit(visit_key, False)
Example #2
0
 def new_visit_with_key(self, visit_key):
     log.debug("new_visit_with_key(%s)" % visit_key)
     created = datetime.now()
     visit = Visit(visit_key, True)
     visit.visit_key = visit_key
     visit.created = created
     visit.expiry = created + self.timeout
     self.visits[visit_key] =  visit
     log.debug("returning %s" % visit)
     return visit
Example #3
0
 def new_visit_with_key(self, visit_key):
     log.debug("new_visit_with_key(%s)" % visit_key)
     created = datetime.now()
     visit = Visit(visit_key, True)
     visit.visit_key = visit_key
     visit.created = created
     visit.expiry = created + self.timeout
     self.visits[visit_key] = visit
     log.debug("returning %s" % visit)
     return visit
Example #4
0
 def new_visit_with_key(self, visit_key):
     hub.begin()
     visit = visit_class(visit_key=visit_key,
                         expiry=datetime.now() + self.timeout)
     hub.commit()
     hub.end()
     return Visit(visit_key, True)
Example #5
0
 def new_visit_with_key(self, visit_key):
     created = datetime.now()
     visit = visit_class()
     visit.visit_key = visit_key
     visit.created = created
     visit.expiry = created + self.timeout
     session.flush()
     return Visit(visit_key, True)
Example #6
0
 def new_visit_with_key(self, visit_key):
     box = hub.getConnection()
     box.start(isolation=turbogears.database.READ_COMMITTED)
     now = datetime.datetime.now()
     visit = visit_class(visit_key=visit_key,
                         expiry=now + self.timeout,
                         created=now)
     box.memorize(visit)
     box.flush_all()
     return Visit(visit_key, True)
Example #7
0
 def visit_for_key(self, visit_key):
     box = hub.getConnection()
     box.start(isolation=turbogears.database.READ_COMMITTED)
     visit = box.unit(visit_class, visit_key=visit_key)
     box.flush_all()
     now = datetime.datetime.now()
     if not visit or visit.expiry < now:
         return None
     # Visit hasn't expired, extend it
     self.update_visit(visit_key, now + self.timeout)
     return Visit(visit_key, False)
Example #8
0
 def new_visit_with_key(self, visit_key):
     '''
     Return a new Visit object with the given key.
     '''
     log.debug('JsonFasVisitManager.new_visit_with_key: enter')
     # Hit any URL in fas2 with the visit_key set.  That will call the
     # new_visit method in fas2
     # We only need to get the session cookie from this request
     request_data = self.fas.refresh_session(visit_key)
     session_id = request_data[0]
     log.debug('JsonFasVisitManager.new_visit_with_key: exit')
     return Visit(session_id, True)
Example #9
0
    def visit_for_key(self, visit_key):
        '''
        Return the visit for this key or None if the visit doesn't exist or has
        expired.
        '''
        self.log.debug('JsonFasVisitManager.visit_for_key: enter')
        # Hit any URL in fas2 with the visit_key set.  That will call the
        # new_visit method in fas2
        # We only need to get the session cookie from this request
        try:
            request_data = self.fas.refresh_session(visit_key)
        except Exception:
            # HACK -- if we get an error from calling FAS, we still need to
            # return something to the application
            try:
                JsonFasVisitManager.error_session_id_lock.acquire()
                session_id = str(JsonFasVisitManager.error_session_id)
                JsonFasVisitManager.error_session_id += 1
            finally:
                JsonFasVisitManager.error_session_id_lock.release()
        else:
            session_id = request_data[0]

        # Knowing what happens in turbogears/visit/api.py when this is called,
        # we can shortcircuit this step and avoid a round trip to the FAS
        # server.
        # if visit_key != session_id:
        #     # visit has expired
        #     return None
        # # Hitting FAS has already updated the visit.
        # return Visit(visit_key, False)
        self.log.debug('JsonFasVisitManager.visit_for_key: exit')
        if visit_key != session_id:
            return Visit(session_id, True)
        else:
            return Visit(visit_key, False)
Example #10
0
    def visit_for_key(self, visit_key):
        """Return the visit for this key.

        Returns None if the visit doesn't exist or has expired.

        """
        try:
            expiry = self.queue[visit_key]
        except KeyError:
            visit = visit_class.lookup_visit(visit_key)
            if not visit:
                return None
            expiry = visit.expiry
        now = datetime.now(expiry.tzinfo)
        if expiry < now:
            return None
        # Visit hasn't expired, extend it
        self.update_visit(visit_key, now + self.timeout)
        return Visit(visit_key, False)
Example #11
0
 def new_visit_with_key(self, visit_key):
     '''
     Return a new Visit object with the given key.
     '''
     self.log.debug('JsonFasVisitManager.new_visit_with_key: enter')
     # Hit any URL in fas2 with the visit_key set.  That will call the
     # new_visit method in fas2
     # We only need to get the session cookie from this request
     try:
         request_data = self.fas.refresh_session(visit_key)
     except Exception:
         # HACK -- if we get an error from calling FAS, we still need to
         # return something to the application
         try:
             JsonFasVisitManager.error_session_id_lock.acquire()
             session_id = str(JsonFasVisitManager.error_session_id)
             JsonFasVisitManager.error_session_id += 1
         finally:
             JsonFasVisitManager.error_session_id_lock.release()
     else:
         session_id = request_data[0]
     self.log.debug('JsonFasVisitManager.new_visit_with_key: exit')
     return Visit(session_id, True)
Example #12
0
 def lookup_visit(cls, visit_key):
     return Visit.get(visit_key)
Example #13
0
 def lookup_visit(cls, visit_key):
     return Visit.get(visit_key)