def writeError(self, *args, **options): """ Display an error with its backtrace. Usage: self.writeError(context, err) or self.writeError(err) """ if not isinstance(args[0], (Failure, Exception)): # logger.writeError(context, err, ...): have a context context = args[0] error = args[1] args = args[2:] else: # logger.writeError(err, ...): no context context = None error = args[0] args = args[1:] if isinstance(error, Failure): options['traceback'] = error.getBriefTraceback() error = error.value if context and (not context.component): logger = self._with_context logger.context = context try: logger.writeError(error, *args, **options) finally: logger.context = None else: CommonLogger.writeError(self, error, *args, **options)
def __init__(self, gui, client): dict.__init__(self) Logger.__init__(self) self.client = client self.gui = gui self.getConfig() self.update_callbacks = [] # def callback(config): ...
def __init__(self, client): Logger.__init__(self, "async_client") QThread.__init__(self) self._run_mutex = QMutex() self._stop_mutex = QMutex() self._queue_mutex = QMutex() self._queue_event = Event() self._run_event = Event() self.client = client self.queue = set() self.cache = {}
def __init__(self, deserialize_fn, cfg_name, set_fn_name, parent=None): QObject.__init__(self, parent) #name of a model -> model self.models = {} if isinstance(parent, Logger): self.logger = parent else: self.logger = Logger(cfg_name) self.cfg = None self.validation_callbacks = [] self.passed_args = [] self.effective_callbacks = [] self.__forgettables = {} self.backup = None cls = self.__class__ setattr( cls, cfg_name, property(fget=cls.getCfg, fset=cls.setCfg) ) setattr( self, set_fn_name, self.setCfg ) setattr( self.__class__, 'deserialize', staticmethod(deserialize_fn) )
def __init__(self): ClientSSLConfig.__init__(self) self.logger = Logger("ssl") self.temp_ignored_errors = defaultdict(set) self.loadOptions()
class QtSSLConfig(ClientSSLConfig): def __init__(self): ClientSSLConfig.__init__(self) self.logger = Logger("ssl") self.temp_ignored_errors = defaultdict(set) self.loadOptions() # FIXME: call self.check() def _setUnicode(self, settings, key, value): if value is None: value = u'' settings.setUnicode(key, value) def saveOptions(self): settings = UserSettings(SETTINGS_APP_NAME) settings.setInt('fqdn_check', self.fqdn_check) settings.setInt('check_peer', self.check) settings.setInt('send_cert', self.send_cert) ## option 'check' removed in 4.1.0 : disable ssl authentication and ssl checks # when it's disabled for backward compatibily # settings.setInt('check', self.enable_ssl_checks) settings.setInt('check', True) self._setUnicode(settings, 'cert', self.cert) self._setUnicode(settings, 'key', self.key) self._setUnicode(settings, 'ca', self.ca) self._setUnicode(settings, 'crl', self.crl) errors = self.generateIgnoredErrors(self.ignored_errors) if errors: settings.setStringList('ignored_errors', errors) def loadOptions(self): settings = UserSettings(SETTINGS_APP_NAME) self.check = settings.getInt('check_peer', self.check) self.fqdn_check = settings.getInt('fqdn_check', self.fqdn_check) self.send_cert = settings.getInt('send_cert', self.send_cert) ## option 'check' removed in 4.1.0 : disable ssl authentication and ssl checks # when it's disabled for backward compatibily # self.enable_ssl_checks = settings.getInt('check', self.enable_ssl_checks) if settings.getInt('check', True) == False: self.send_cert = False self.check = False for name in ('cert', 'key', 'ca', 'crl'): value = getattr(self, name) new_value = settings.getUnicode(name, value) if new_value: if exists(new_value): setattr(self, name, new_value) else: self.logger.info("Ignore %s=%s (missing file)" % (name, new_value)) else: setattr(self, name, u'') self.ignored_errors = self.parseIgnoredErrors(settings.getStringList('ignored_errors')) def parseIgnoredErrors(self, lst): # Parse a list of errors to ignore during verification # The list is alist of fingerprint followed by the error to ignore: # lst = [ fingerprint 1, error ignored for fingerprint 1, fingerprint 1, other error ... ] ignored_errors = defaultdict(set) if lst is None: return ignored_errors while len(lst) > 1: fingerprint = lst[0] err_no = int(lst[1]) ignored_errors[fingerprint].add(err_no) del lst[0:2] return ignored_errors def generateIgnoredErrors(self, ignored_errors): lst = [] for fingerprint in ignored_errors: for err_no in ignored_errors[fingerprint]: lst.append(fingerprint) lst.append(str(err_no)) return lst def _user_verify(self, error): # temporary implementation using a QMessageBox # XXX in the future, we should create a dedicated UI # Check wether we should ignore this error err_no = error.number fingerprint = error.getFingerprint() if (fingerprint in self.ignored_errors) \ and (err_no in self.ignored_errors[fingerprint]): return 1 if (fingerprint in self.temp_ignored_errors) \ and (err_no in self.temp_ignored_errors[fingerprint]): return 1 msgBox = QMessageBox() msgBox.setIcon(QMessageBox.Critical) msgBox.setTextFormat(Qt.RichText) message = u"<b>%s!</b>" % error.getMessage() msgBox.setText( tr('The "%s" certificate is invalid: %s') % (error.getSubject(), message)) msgBox.setInformativeText( tr("Do you want to accept the following certificate?") ) msgBox.setDetailedText(error.getCertText()) msgBox.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel) msgBox.addButton( tr("For this session only"), QMessageBox.AcceptRole ) msgBox.setDefaultButton(QMessageBox.Cancel) ret = msgBox.exec_() if ret == QMessageBox.Ok: self.ignored_errors[fingerprint].add(err_no) self.saveOptions() elif ret == QMessageBox.AcceptRole: self.temp_ignored_errors[fingerprint].add(err_no) if ret in (QMessageBox.Ok, QMessageBox.AcceptRole): return 1 else: return 0 def user_verify(self, error): try: return self._user_verify(error) except Exception, err: self.logger.writeError(err, tr("Certificate validation error")) return 0
class QConfigObject(QObject): """ Singleton object. Holds a *cfg, and notices you with a 'modified' SIGNAL The reason of this object is that it is difficult to find a frontend module, listen for its modifications and react accordingly. The singleton reflects the user seing a unique data set, and this can be refactored later of we need several ufwi_conf interfaces talking to several edenwalls. """ _instance = None def __init__(self, deserialize_fn, cfg_name, set_fn_name, parent=None): QObject.__init__(self, parent) #name of a model -> model self.models = {} if isinstance(parent, Logger): self.logger = parent else: self.logger = Logger(cfg_name) self.cfg = None self.validation_callbacks = [] self.passed_args = [] self.effective_callbacks = [] self.__forgettables = {} self.backup = None cls = self.__class__ setattr( cls, cfg_name, property(fget=cls.getCfg, fset=cls.setCfg) ) setattr( self, set_fn_name, self.setCfg ) setattr( self.__class__, 'deserialize', staticmethod(deserialize_fn) ) def resetModels(self): """ A method that should be subclassed """ pass def hasConfig(self): """ return if object have a config """ return self.cfg != None @classmethod def getInstance(cls): if cls._instance is None: cls._instance = cls() return cls._instance def registerCallbacks(self, canHandleModification, handleModification, attach=None): self.validation_callbacks.append(canHandleModification) self.effective_callbacks.append(handleModification) if attach is not None: self.connect(attach, SIGNAL('destroyed(QObject)'), self.forget) self.__forgettables[attach] = canHandleModification, handleModification def forget(self, qobject): callbacks = self.__forgettables.get(qobject) if callbacks is None: return canHandleModification, handleModification = callbacks del self.__forgettables[qobject] self.validation_callbacks.remove(canHandleModification) self.effective_callbacks.remove(handleModification) def pre_modify(self): self.backup = self.cfg.serialize() def revert(self): assert self.backup is not None, 'Did you call pre_modify() before?' self._importSerialized(self.backup) def post_modify(self): assert self.cfg is not None, \ "Do not call this function unless you really modified cfg. I which case you should have done a setCfg(cfg) once before" self.resetModels() if self._modificationAuthorized(): self._propagate() # self.pre_modify() valid = True else: self.revert() self.emit(SIGNAL('cancelled')) valid = False self.passed_args = [] return valid def _importSerialized(self, serialized): try: self.cfg = self.deserialize(serialized) except Exception, err: self.logger.writeError(err) self.resetModels()
def __init__(self, *args, **kw): CommonLogger.__init__(self, *args, **kw) self._with_context = ContextLoggerChild(None, self)
def __init__(self): ClientSSLConfig.__init__(self) Logger.__init__(self, "ssl")