def open_session(self, app, request): try: sid = request.cookies.get(app.session_cookie_name) if sid: stored_session = self.store.find_one({'sid': sid}) if stored_session: if stored_session.get('expiration') > datetime.utcnow(): return MongoSession(initial=stored_session['data'], sid=stored_session['sid']) sid = str(uuid4()) return MongoSession(sid=sid) except: logger(format_exc())
def save_session(self, app, session, response): try: domain = self.get_cookie_domain(app) if not session: response.delete_cookie(app.session_cookie_name, domain=domain) return if self.get_expiration_time(app, session): expiration = self.get_expiration_time(app, session) else: expiration = datetime.utcnow() + timedelta(hours=1) self.store.update({'sid': session.sid}, {'sid': session.sid, 'data': session, 'expiration': expiration}, True) response.set_cookie(app.session_cookie_name, session.sid, expires=self.get_expiration_time(app, session), httponly=True, domain=domain) except: logger( format_exc())
""" IO Module This module defines the inout/output interfaces """ from Utils import Error,logger,NotYet,WrongDataType _logger=logger().getLogger('IO') class Input: """ Base Class for input """ def __init__(self): self.input = None self.name = None def getObject(self): """ Returns the input object """ return self.input def __str__(self): try: return 'Input: %s'%self.name except: return 'Input: %s'%self.name def __call__(self): raise BaseClass() class FileInput(Input): """ Read input from File.
from Utils import Error,logger _logger=logger().getLogger('Interface') class Result: UNDEFINED = "UNDEFINED" FAILED = "FAILED" NOTPASSED = "NOTPASSED" SUCCESS = "SUCCESS" class Output: """ Class representing the result of a test """ def __init__(self,name,failedThreshold=0.05,passedThreshold=0.90): """ Create an output class, with thresholds for failed and passed. """ self.name = name self.low = failedThreshold self.high= passedThreshold self.result = Result.UNDEFINED self.value = None def checkResult(self,result): """ Check result against thresholds: result < failedThreshold -> FAILED result >= passedThreshold -> SUCCESS else -> NOTPASSED """ self.value = result if result < self.low:
""" IO Module This module defines the inout/output interfaces """ from Utils import Error, logger, NotYet, WrongDataType _logger = logger().getLogger('IO') class Input: """ Base Class for input """ def __init__(self): self.input = None self.name = None def getObject(self): """ Returns the input object """ return self.input def __str__(self): try: return 'Input: %s' % self.name except: return 'Input: %s' % self.name def __call__(self): raise BaseClass()