def __init__(self, id_, data, debug=False): UserDict.__init__(self) self.id = id_ self.update(data) self.status = Session.SESSION_STATUS_INITED if not debug: self.sm_request_manager = SMRequestManager() self.sm_request_manager.initialize();
class Session(UserDict): SESSION_STATUS_UNKNOWN = "unknown" SESSION_STATUS_ERROR = "error" SESSION_STATUS_INITED = "ready" SESSION_STATUS_ACTIVE = "logged" SESSION_STATUS_INACTIVE = "disconnected" SESSION_STATUS_WAIT_DESTROY = "wait_destroy" SESSION_STATUS_DESTROYED = "destroyed" MODE_DESKTOP = "desktop" MODE_APPLICATIONS = "applications" def __init__(self, id_, data, debug=False): UserDict.__init__(self) self.id = id_ self.update(data) self.status = Session.SESSION_STATUS_INITED if not debug: self.sm_request_manager = SMRequestManager() self.sm_request_manager.initialize(); def switch_status(self, status_): self.status = status_ self.send_server_status() def credentials(self): return { 'USE_CURRENT_USER_LOGIN': self.get('USER_LOGIN', ''), 'USE_CURRENT_USER_PASSWD': self.get('USER_PASSWD', ''), } def send_server_status(self): doc = None; try: doc = Document() rootNode = doc.createElement('session') rootNode.setAttribute("id", self.id) rootNode.setAttribute("status", self.status) rootNode.setAttribute("role", "webapps") doc.appendChild(rootNode) except Exception, e: Logger.warn("WebappsServer: unable to format session status xml: %s"(str(e))) if not hasattr(self, "sm_request_manager"): return response = self.sm_request_manager.send_packet("/session/status", doc) Logger.debug2("WebappsServer: send_session_status: %s"%(response)) if response is False: Logger.warn("WebappsServer: unable to send session status") else: response.close() response = None