def __init__(self, tableName, database=None, deepCopy=True): self.__tableName = tableName self.__deepCopy = deepCopy self.__database = database setattr(self, tableName, {}) if not self.__class__.logger: self.__class__.logger = util.getLogger(self)
def load(cls, filename): if not cls.logger: cls.logger = util.getLogger(cls) jsonPath = cls._computeJsonFilename(filename) if cls.preferJson and os.path.exists(jsonPath): return cls._loadJson(jsonPath) else: return cls._loadPickle(filename)
def __init__(self, parent=None, root=None): resource.Resource.__init__(self) self.parent = parent self.root = root if not self.__class__.logger: self.__class__.logger = util.getLogger(self) self.contentTypeProducers = {"text/html": self.__getHtml, "application/xhtml+xml": self.__getHtml, "application/json": self.__getJson, "*/*": self.__getHtml} self.templateSearchPath = [ self.templatePath ] if not self.disableLibraryTemplates: self.templateSearchPath += [self._libraryTemplatePath, self._libraryPath]
def __init__(self, name): self._name = name self.__class__.logger = util.getLogger(self)
def __setstate__(self, state): self.__dict__.update(state) if not self.__class__.logger: self.__class__.logger = util.getLogger(self)
def __init__(self): if not self.__class__.logger: self.__class__.logger = util.getLogger(self)
def __init__(self, record=None): if not self.__class__.logger: self.__class__.logger = util.getLogger(self) if type(record) == dict: for k, v in record.iteritems(): setattr(self, k, v)
def __setstate__(self, state): if not self.__class__.logger: self.__class__.logger = util.getLogger(self) self.logger.debug("__setstate__(...)") self.__dict__.update(state)
def __init__(self, app): if not self.__class__.logger: self.__class__.logger = util.getLogger(self) self.logger.debug("__init__(%r)", app) self.app = app
def __init__(self, factory, commandMap={}): if not self.__class__.logger: self.__class__.logger = util.getLogger(self) self.logger.debug("__init__(%r)", factory) self.factory = factory self.commandMap = commandMap
import guernsey.util as util class DnsClient(object): logger = None def lookupService(self, name, timeouts=[2]): self.logger.debug("lookupService(name=%r, timeouts=%r)", name, timeouts) deferred = client.lookupService(name, timeouts) def cb(result): self.logger.debug("lookupService() cb(result=%r)", result) payload = result[0][0].payload port = payload.port name = payload.target.name return (name, port) def eb(failure): self.logger.warning("lookupService(name=%r, timeouts=%r) eb(failure=%r)", name, timeouts, failure) if isinstance(failure.type, Exception): util.logTwistedFailure(self.logger, failure, "lookupService(name=%r, timeouts=%r) threw exception", name, timeouts) self.logger.warning("failure.__dict__: %r", failure.__dict__) return (None, None) deferred.addCallbacks(cb, eb) return deferred DnsClient.logger = util.getLogger(DnsClient)
def __init__(self, appName=None, options=None, appId=None): self.__class__.logger = util.getLogger(self) self.__class__._instance = self self.appName = appName self.appId = appId args = None if not options: self.options, self.args = self.__parseArgs() else: self.options = options if not self.options.showDb: self.config = ConfigModel() self.config.addVariable(ConfigEnum("logLevel", self.options.logLevelFile.upper(), ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"], "Log Level")) self.config.addVariable(ConfigString("logFormat", "%(asctime)s %(levelname)s %(name)s: " "%(message)s", "Log Format String")) self.setupLogging() self.__shutdownHooks = [] reactor.addSystemEventTrigger("before", "shutdown", self.__beforeShutdownCallback) self.addShutdownHook(logging.shutdown) if self.appName: self.addShutdownHook(self.logger.info, "Stopped: %s", self.appName) # These events fire, but are not likely to complete. We # allow using them, but consider yourself warned. We'll # keep the call in case an update fixes it. # # Note: No logging calls allowed in these callbacks, as # the logging subsystem has already been shutdown. reactor.addSystemEventTrigger("during", "shutdown", self.__duringShutdownCallback) reactor.addSystemEventTrigger("after", "shutdown", self.__afterShutdownCallback) if self.appName: self.logger.warning("Starting: %s", self.appName) reactor.callWhenRunning(self.logger.info, "Started: %s", self.appName) Resource.templatePath = self.options.templatePath Resource.disableLibraryTemplates = self.options.disableLibraryTemplates if self.appName: Resource._appName = self.appName if hasattr(self.options, "corsAllowOrigins"): Resource.corsAllowOrigins = self.options.corsAllowOrigins if hasattr(self.options, "corsAllowMethods"): Resource.corsAllowMethods = map(lambda x: x.upper(), self.options.corsAllowMethods) \ + ["GET", "HEAD", "POST"] Resource.__init__(self) import twisted.web.static as static self.putChild("css", static.File(os.path.join(self.options.templatePath, "css"))) self.putChild("js", static.File(os.path.join(self.options.templatePath, "js"))) self.putChild("images", static.File(os.path.join(self.options.templatePath, "images"))) if self.options.enableAcme: self.putChild(".well-known", static.File(os.path.join(self.options.templatePath, ".well-known"))) if not self.disableLibraryTemplates: self.putChild("libcss", static.File(os.path.join(self._libraryTemplatePath, "css"))) self.putChild("libjs", static.File(os.path.join(self._libraryTemplatePath, "js"))) self.putChild("libimages", static.File(os.path.join(self._libraryTemplatePath, "images"))) self.putChild("config", ConfigResource(self)) self.putChild("issues", Issues(self)) if self.options.dbFile and os.path.exists(self.options.dbFile): self.logger.info("Loading database from file %s", self.options.dbFile) self.database = self.databaseClass.load(self.options.dbFile) if not self.database.__class__ is self.databaseClass: self.logger.warning("Database class is '%s.%s' instead of expected '%s.%s'", self.database.__class__.__module__, self.database.__class__.__name__, self.databaseClass.__module__, self.databaseClass.__name__) if self.options.showDb: print "Database: %r" % self.database sys.exit(0) else: if self.options.showDb: print "Database file '%s' not found!" % self.options.dbFile sys.exit(1) else: self.database = self.databaseClass() if self.options.dbFile: self.addShutdownHook(self._saveDatabase) if self.options.dbSaveInterval > 0: self.logger.info("Scheduling database save procedure every %s seconds", self.options.dbSaveInterval) from twisted.internet import task t = task.LoopingCall(self._saveDatabase) t.start(self.options.dbSaveInterval, now=False) if self.appName: self.addShutdownHook(self.logger.warning, "Stopping: %s", self.appName)
return self.request(url, "GET", data=None, getBody=getBody) def post(self, url, data, getBody=False): self.logger.info("post(%r, %r, %r)", url, data, getBody) return self.request(url, "POST", data, getBody=getBody) def put(self, url, data, getBody=False): self.logger.info("put(%r, %r, %r)", url, data, getBody) return self.request(url, "PUT", data, getBody=getBody) def delete(self, url, getBody=False): self.logger.info("delete(%r, %r)", url, getBody) return self.request(url, "DELETE", data=None, getBody=getBody) WebClient.logger = util.getLogger(WebClient) class BodyReceiver(protocol.Protocol): logger = None def __init__(self, finished): self.finished = finished self.body = "" def dataReceived(self, bytes): self.logger.debug("dataReceived(%r)", bytes) self.body += bytes def connectionLost(self, reason): self.logger.debug("connectionLost(%r)", reason)