Ejemplo n.º 1
0
    def __init__(self):
        self.mongo = MongoBackend()

        # Set in the test suite
        #  os.environ['AMON_ENV'] = 'test'
        if getenv('AMON_ENV', None) == 'test':
            self.mongo.database = 'amon_test'
Ejemplo n.º 2
0
Archivo: views.py Proyecto: see0/amon
    def initialize(self):
        self.mongo = MongoBackend()
        self.now = datetime.now()

        self.unread_col = self.mongo.get_collection("unread")
        self.unread_values = self.unread_col.find_one()

        super(Base, self).initialize()
Ejemplo n.º 3
0
Archivo: views.py Proyecto: see0/amon
class Base(tornado.web.RequestHandler):
    def initialize(self):
        self.mongo = MongoBackend()
        self.now = datetime.now()

        self.unread_col = self.mongo.get_collection("unread")
        self.unread_values = self.unread_col.find_one()

        super(Base, self).initialize()

    def write_error(self, status_code, **kwargs):
        error_trace = None

        if "exc_info" in kwargs:
            import traceback

            error_trace = ""
            for line in traceback.format_exception(*kwargs["exc_info"]):
                error_trace += line

        _template = render(template="error.html", status_code=status_code, error_trace=error_trace, unread_values=None)

        self.write(_template)
Ejemplo n.º 4
0
            'duration': self.duration,
            'expires': self.expires,
            'ip_address': self.ip_address,
            'user_agent': self.user_agent,
            'security_model': self.security_model,
            'regeneration_interval': self.regeneration_interval,
            'next_regeneration': self.next_regeneration
        }
        return base64.encodestring(pickle.dumps(dump))

    @staticmethod
    def deserialize(datastring):
        return pickle.loads(base64.decodestring(datastring))


mongo_backend = MongoBackend()
mongo = mongo_backend.get_collection('sessions')


class MongoDBSession(BaseSession):
    """Class implementing the MongoDB based session storage.
	All sessions are stored in a collection "sessions" in the db
	you specify in the session_storage setting.

	The session document structure is following:
	'session_id': session ID
	'data': serialized session object
	'expires': a timestamp of when the session expires, in sec since epoch
	'user_agent': self-explanatory
	An index on session_id is created automatically, on application's init.
Ejemplo n.º 5
0
                'data': self.data,
                'duration': self.duration,
                'expires': self.expires,
                'ip_address': self.ip_address,
                'user_agent': self.user_agent,
                'security_model': self.security_model,
                'regeneration_interval': self.regeneration_interval,
                'next_regeneration': self.next_regeneration}
        return base64.encodestring(pickle.dumps(dump))

    @staticmethod
    def deserialize(datastring):
        return pickle.loads(base64.decodestring(datastring))


mongo_backend = MongoBackend()
mongo = mongo_backend.get_collection('sessions') 

class MongoDBSession(BaseSession):
    """Class implementing the MongoDB based session storage.
    All sessions are stored in a collection "sessions" in the db
    you specify in the session_storage setting.

    The session document structure is following:
    'session_id': session ID
    'data': serialized session object
    'expires': a timestamp of when the session expires, in sec since epoch
    'user_agent': self-explanatory
    An index on session_id is created automatically, on application's init.

    The end_request() is called after every operation (save, load, delete),