def __init__(self, options, session, auth_config=None): """ Ctor. :param options: Options for path service from configuration. :type options: dict :param session: Instance of `ApplicationSession` to be used for forwarding events. :type session: obj """ Resource.__init__(self) self._options = options self._session = session self.log = make_logger() self._key = None if 'key' in options: self._key = options['key'].encode('utf8') self._secret = None if 'secret' in options: self._secret = options['secret'].encode('utf8') self._post_body_limit = int(options.get('post_body_limit', 0)) self._timestamp_delta_limit = int(options.get('timestamp_delta_limit', 300)) self._require_ip = None if 'require_ip' in options: self._require_ip = [ip_network(net) for net in options['require_ip']] self._require_tls = options.get('require_tls', None) self._auth_config = auth_config or {} self._pending_auth = None
def __init__(self, rsrc, cookieKey=None): Resource.__init__(self) self.resource = rsrc if cookieKey is None: cookieKey = "woven_session_" + _sessionCookie() self.cookieKey = cookieKey self.sessions = {}
def __init__(self, host, port, path, path_rewrite=None, reactor=reactor, tls=False, headers={}): """ @param host: the host of the web server to proxy. @type host: C{str} @param port: the port of the web server to proxy. @type port: C{port} @param path: the base path to fetch data from. Note that you shouldn't put any trailing slashes in it, it will be added automatically in request. For example, if you put B{/foo}, a request on B{/bar} will be proxied to B{/foo/bar}. Any required encoding of special characters (such as " " or "/") should have been done already. @param path_rewrite: list of lists with two regexp strings used for rewriting the path. @param tls: use tls or not @type path: C{str} """ Resource.__init__(self) self.host = host self.port = port self.path = path self.path_rewrite = path_rewrite self.tls = tls self.reactor = reactor self.headers = headers
def __init__(self, parent): """ :param parent: The Web parent resource for the WAMP session. :type parent: Instance of :class:`autobahn.twisted.longpoll.WampLongPollResourceSession`. """ Resource.__init__(self) self._parent = parent self._debug = self._parent._parent._debug self.reactor = self._parent._parent.reactor self._queue = deque() self._request = None self._killed = False if self._debug: def logqueue(): if not self._killed: log.msg( "WampLongPoll: transport '{0}' - currently polled {1}, pending messages {2}".format( self._parent._transport_id, self._request is not None, len(self._queue) ) ) self.reactor.callLater(1, logqueue) logqueue()
def __init__(self, hs, media_repo): Resource.__init__(self) self.auth = hs.get_auth() self.clock = hs.get_clock() self.version_string = hs.version_string self.filepaths = media_repo.filepaths self.max_spider_size = hs.config.max_spider_size self.server_name = hs.hostname self.store = hs.get_datastore() self.client = SpiderHttpClient(hs) self.media_repo = media_repo self.url_preview_url_blacklist = hs.config.url_preview_url_blacklist # simple memory cache mapping urls to OG metadata self.cache = ExpiringCache( cache_name="url_previews", clock=self.clock, # don't spider URLs more often than once an hour expiry_ms=60 * 60 * 1000, ) self.cache.start() self.downloads = {}
def __init__(self, out=None, *a, **kw): Resource.__init__(self, *a, **kw) self._log = logging.getLogger(self.__class__.__name__) self._log.debug('Initialized.') if out is None: out = sys.stdout self.out = out
def __init__(self, hs): self.hs = hs self.version_string = hs.version_string self.response_body = encode_canonical_json( self.response_json_object(hs.config) ) Resource.__init__(self)
def __init__(self, ws, static_path=None): self._ws = ws if static_path is None: static_path = os.path.join(os.path.dirname(__file__), 'static') self._static_path = static_path Resource.__init__(self)
def __init__(self): Resource.__init__(self) self.putChild("status", Status()) self.putChild("follow", Follow()) self.putChild("delay", Delay()) self.putChild("partial", Partial()) self.putChild("drop", Drop())
def __init__(self, parent): """ Initialize """ parent.putChild(self.name, self) Renderable.__init__(self, parent) Resource.__init__(self)
def __init__(self): Resource.__init__(self) self.__path = [''] self.__controllers = {} self.__mapper = routes.Mapper()
def __init__(self, debug=False, signing_key=None, signing_id=None, event_handler=GenericEventHandler): Resource.__init__(self) self.signing_key = signing_key self.signing_id = signing_id self.debug = debug # This class acts as a 'factory', debug is used by Protocol self.event_handler = event_handler
def __init__(self, get_data_callback, clear_data_callback): """ """ self.get_data_callback = get_data_callback self.clear_data_callback = clear_data_callback Resource.__init__(self)
def __init__(self, logDirResource, allowedChannels=None): Resource.__init__(self) self.logDirResource = logDirResource allowed = allowedChannels if allowed is not None: allowed = set(unprefixedChannel(channel) for channel in allowedChannels) self.allowed = allowed
def __init__(self, source): """ @param source: The NotificationSource to fetch notifications from. """ Resource.__init__(self) self.source = source self._finished = {}
def __init__(self, cashier): """ :param cashier: The cashier we talk to """ Resource.__init__(self) self.cashier = cashier self.compropago = cashier.compropago
def __init__(self, app, chunked=False, max_content_length=2 * 1024 * 1024, block_length=8 * 1024): Resource.__init__(self) self.http_transport = TwistedHttpTransport(app, chunked, max_content_length, block_length) self._wsdl = None
def __init__(self, client): self.upload = Queue() self.client = client Resource.__init__(self) t = UploadThread(self) t.setDaemon(True) t.start()
def __init__(self, parent): """ """ Resource.__init__(self) self._parent = parent self._debug = self._parent._debug self.reactor = self._parent.reactor
def __init__(self, parent): """ :param parent: The Web parent resource for the WAMP session. :type parent: Instance of :class:`autobahn.twisted.longpoll.WampLongPollResourceSession`. """ Resource.__init__(self) self._parent = parent self.reactor = self._parent._parent.reactor self._queue = deque() self._request = None self._killed = False # FIXME: can we read the loglevel from self.log currently set? if False: def logqueue(): if not self._killed: self.log.debug( "WampLongPoll: transport '{tid}' - currently polled" " {is_polled}, pending messages {pending}", tid=self._parent._transport_id, is_polled=self._request is not None, pending=len(self._queue), ) self.reactor.callLater(1, logqueue) logqueue()
def __init__(self, test, method, content, expect_content=None, status=200): Resource.__init__(self) self._test = test self._method = method self._content = content self._expect_content = expect_content self._status = status
def __init__(self): self.lastsearchresult = None self.presence=[] self.last_search_id=0 loopingCall = task.LoopingCall(self.__update_search) loopingCall.start(20, False) Resource.__init__(self)
def __init__(self, appleId): allowed_ids = os.environ.get('ALLOWED_APPLEIDS', None) if allowed_ids and not str(appleId) in allowed_ids.split(' '): print 'AppleID Forbidden: ' + appleId raise Exception('Forbidden: ' + appleId) Resource.__init__(self) self.appleId = appleId
def __init__(self, session, host='', port=0, path='', reactor=reactor): Resource.__init__(self) self.session = session self.host = host self.port = port self.path = path self.reactor = reactor
def __init__(self): log.msg("Setting up the API...") Resource.__init__(self) self.putChild("history", HistoryList()) self.putChild("groupmessage", GroupChat()) self.putChild("auth", Retriever())
def __init__(self, response): """ @param response: A C{bytes} object giving the value to return from C{render_GET}. """ Resource.__init__(self) self._response = response
def __init__(self, seatbelt, dbpath): Resource.__init__(self) self.seatbelt = seatbelt self._all_docs = {} self.dbpath = dbpath self.dbname = os.path.basename(dbpath) self.change_resource = PARTS_BIN["DbChanges"](self) self.putChild("_changes", self.change_resource) # defaults -- potentially overwritten in `self._load_from_disk()' call self.docs = {} # docid -> Document self._db_info = {"db_name": self.dbname, "update_seq": 0} self._changes = {} # seqno -> [doc] self._load_from_disk() self.all_docs_resource = GetAllJSON(self._all_docs) # We need to use an intermediate object for the Designer # because _design/<name> is interpreted by twisted as two # levels deep. self.designer_resource = PARTS_BIN["Designer"](self) self.putChild("_design", self.designer_resource) self._serve_docs() self.putChild("_all_docs", self.all_docs_resource) #self._changesink = AsynchronousFileSink(os.path.join(self.dbpath, "_changes")) self._changesink = SynchronousFileSink(os.path.join(self.dbpath, "_changes")) self._change_waiters = {} # request -> timeout_callback
def __init__(self): Resource.__init__(self) #twisted will handle static content for me self.putChild('bootstrap', File('./bootstrap')) self.putChild('js', File('./js')) #make the correspondance between the path and the object to call self.page_handler = {'/' : Index, '/graphs': GraphView, '/get_rules': GenWhitelist, '/map': WootMap}
def __init__(self, RouterPB, SMPPClientManagerPB, config, interceptor=None): Resource.__init__(self) # Setup stats collector stats = HttpAPIStatsCollector().get() stats.set('created_at', datetime.now()) # Set up a dedicated logger log = logging.getLogger(LOG_CATEGORY) if len(log.handlers) != 1: log.setLevel(config.log_level) handler = TimedRotatingFileHandler(filename=config.log_file, when=config.log_rotate) formatter = logging.Formatter(config.log_format, config.log_date_format) handler.setFormatter(formatter) log.addHandler(handler) log.propagate = False # Set http url routings log.debug("Setting http url routing for /send") self.putChild('send', Send(config, RouterPB, SMPPClientManagerPB, stats, log, interceptor)) log.debug("Setting http url routing for /rate") self.putChild('rate', Rate(config, RouterPB, stats, log, interceptor)) log.debug("Setting http url routing for /balance") self.putChild('balance', Balance(RouterPB, stats, log)) log.debug("Setting http url routing for /ping") self.putChild('ping', Ping(log))
def __init__(self, dbpool, services): Resource.__init__(self) self.dbpool = dbpool self.services = services logdir = self.services["config"].get("log-dir") ## create log dir when not there if not os.path.isdir(logdir): os.mkdir(logdir) ## create/open log files self.dispatch_log_file = open(os.path.join(logdir, "dispatch.log"), "ab") self.error_log_file = open(os.path.join(logdir, "error.log"), "ab") ## in-memory log queues self.dispatch_log = deque() self.error_log = deque() ## current statistics self.stats = { "uri": None, "publish-allowed": 0, "publish-denied": 0, "dispatch-success": 0, "dispatch-failed": 0, } self.statsChanged = False ## the config is not yet load at this point # self.writeLog() reactor.callLater(10, self.writeLog) self.publishStats()
def __init__(self, cachedir, transcriber): self.cachedir = cachedir self.transcriber = transcriber Resource.__init__(self)
def __init__(self, tracResource, htdocs, attachments): Resource.__init__(self) self.tracResource = tracResource self.htdocs = htdocs self.attachments = attachments
def __init__(self, wcommon, title): Resource.__init__(self) self.__element = _RadioIndexHtmlElement(wcommon, title)
def __init__(self, controller): Resource.__init__(self)
def __init__(self, controller): Resource.__init__(self) self.controller = controller self.is_remote_ip = False
def __init__(self, controller): Resource.__init__(self) self.delayed_requests = [] self.controller = controller
def __init__(self, hs): Resource.__init__(self) self._well_known_builder = WellKnownBuilder(hs)
def __init__(self, transcriber): Resource.__init__(self) self.transcriber = transcriber
def __init__(self, s3, bucket, path=""): Resource.__init__(self) self.s3 = s3 self.bucket = bucket self.path = path
def __init__(self, status_dict): self.status_dict = status_dict Resource.__init__(self)
def __init__(self, ldfs, root, path=""): Resource.__init__(self) self.ldfs = ldfs self.root = root self.path = path
def __init__(self, fs): Resource.__init__(self) self.fs = fs self.fs.install_renderer(self.resource_render)
def __init__(self, mail_service): Resource.__init__(self) self.mail_service = mail_service
def __init__(self, prod): Resource.__init__(self) self.prod = prod
def __init__(self): Resource.__init__(self)
def __init__(self, parent, path): Resource.__init__(self); self.parent = parent; self.children = {}; self.path = path;
def __init__(self, hs): self.config = hs.config self.clock = hs.get_clock() self.update_response_body(self.clock.time_msec()) Resource.__init__(self)
def __init__(self, mail_service, attachment_id): Resource.__init__(self) self.attachment_id = attachment_id self.mail_service = mail_service
def __init__(self, templates, realm, schemas=None): Resource.__init__(self) self._templates = templates self._realm = realm self._schemas = schemas or {}
def __init__(self, proposer): Resource.__init__(self) self.proposer = proposer
def __init__(self, templates, directory): Resource.__init__(self) self._page = templates.get_template('cb_web_404.html') self._directory = nativeString(directory)
def __init__(self, irc_factory, conf): self.irc_factory = irc_factory self.conf = conf Resource.__init__(self)
def __init__(self, handler): Resource.__init__(self) self.handler = handler
def __init__(self, redirect_url): Resource.__init__(self) self._redirect_url = redirect_url
def __init__(self, service): Resource.__init__(self) self.service = service
def __init__(self, state): Resource.__init__(self) self.state = state
def __init__(self, dispatcher): Resource.__init__(self) self.dispatcher = dispatcher
def __init__(self, service, name): Resource.__init__(self) self.service = service self.name = name
def __init__(self, pool, max_timeout, is_proxy_request=False): Resource.__init__(self) self.pool = pool self.js_profiles_path = self.pool.js_profiles_path self.is_proxy_request = is_proxy_request self.max_timeout = max_timeout
def __init__(self, main): Resource.__init__(self) self.main = main