def application(config): app = Application("Scrapyd") http_port = int(environ.get('PORT', config.getint('http_port', 6800))) config.cp.set('scrapyd', 'database_url', environ.get('DATABASE_URL')) poller = Psycopg2QueuePoller(config) eggstorage = FilesystemEggStorage(config) scheduler = Psycopg2SpiderScheduler(config) environment = Environment(config) app.setComponent(IPoller, poller) app.setComponent(IEggStorage, eggstorage) app.setComponent(ISpiderScheduler, scheduler) app.setComponent(IEnvironment, environment) launcher = Launcher(config, app) timer = TimerService(5, poller.poll) webservice = TCPServer(http_port, server.Site(Root(config, app))) log.msg("Scrapyd web console available at http://localhost:%s/ (HEROKU)" % http_port) launcher.setServiceParent(app) timer.setServiceParent(app) webservice.setServiceParent(app) return app
def application(config): app = Application("Scrapyd") http_port = config.getint('http_port', 6800) bind_address = config.get('bind_address', '0.0.0.0') poller = QueuePoller(config) eggstorage = FilesystemEggStorage(config) scheduler = SpiderScheduler(config) environment = Environment(config) app.setComponent(IPoller, poller) app.setComponent(IEggStorage, eggstorage) app.setComponent(ISpiderScheduler, scheduler) app.setComponent(IEnvironment, environment) launcher = Launcher(config, app) timer = TimerService(5, poller.poll) webservice = TCPServer(http_port, server.Site(Root(config, app)), interface=bind_address) log.msg("Scrapyd web console available at http://%s:%s/" % (bind_address, http_port)) launcher.setServiceParent(app) timer.setServiceParent(app) webservice.setServiceParent(app) return app
def test_nonAsciiLog(self): """ Make sure that the file based error log can write non ascii data """ logpath = self.mktemp() service = ErrorLoggingMultiService( True, logpath, 10000, 10, False, ) app = Application("non-ascii") service.setServiceParent(app) observer = app.getComponent(ILogObserver, None) self.assertTrue(observer is not None) log = Logger(observer=observer) log.error(u"Couldn\u2019t be wrong") with open(logpath) as f: logentry = f.read() self.assertIn("Couldn\xe2\x80\x99t be wrong", logentry)
def application(config): app = Application("Scrapyd") http_port = config.getint('http_port', 6800) bind_address = config.get('bind_address', '0.0.0.0') poll_interval = config.getfloat('poll_interval', 5) poller = QueuePoller(config) eggstorage = FilesystemEggStorage(config) scheduler = SpiderScheduler(config) environment = Environment(config) app.setComponent(IPoller, poller) app.setComponent(IEggStorage, eggstorage) app.setComponent(ISpiderScheduler, scheduler) app.setComponent(IEnvironment, environment) laupath = config.get('launcher', 'scrapyd.launcher.Launcher') laucls = load_object(laupath) launcher = laucls(config, app) timer = TimerService(poll_interval, poller.poll) webservice = TCPServer(http_port, server.Site(Root(config, app)), interface=bind_address) log.msg( format= "Scrapyd web console available at http://%(bind_address)s:%(http_port)s/", bind_address=bind_address, http_port=http_port) launcher.setServiceParent(app) timer.setServiceParent(app) webservice.setServiceParent(app) return app
def application(config, components=interfaces): app = Application("Scrapyd") http_port = config.getint('http_port', 6800) bind_address = config.get('bind_address', '0.0.0.0') for interface, key in interfaces: path = config.get(key) cls = load_object(path) component = cls(config) app.setComponent(interface, component) poller = component laupath = config.get('launcher', 'scrapyd.launcher.Launcher') laucls = load_object(laupath) launcher = laucls(config, app) poll_every = config.getint("poll_every", 5) timer = TimerService(poll_every, poller.poll) webservice = TCPServer(http_port, server.Site(Root(config, app)), interface=bind_address) log.msg(format="Scrapyd web console available at http://%(bind_address)s:%(http_port)s/", bind_address=bind_address, http_port=http_port) launcher.setServiceParent(app) timer.setServiceParent(app) webservice.setServiceParent(app) return app
def application(config): app = Application("Scrapyd") http_port = config.getint('http_port', 6800) portal = Portal(PublicHTMLRealm(config, app), [FilePasswordDB(str(config.get('passwd', '')))]) credentialFactory = DigestCredentialFactory("md5", "Go away") poller = QueuePoller(config) eggstorage = FilesystemEggStorage(config) scheduler = SpiderScheduler(config) environment = Environment(config) app.setComponent(IPoller, poller) app.setComponent(IEggStorage, eggstorage) app.setComponent(ISpiderScheduler, scheduler) app.setComponent(IEnvironment, environment) launcher = Launcher(config, app) timer = TimerService(5, poller.poll) webservice = TCPServer(http_port, server.Site(HTTPAuthSessionWrapper(portal, [credentialFactory]))) log.msg("Scrapyd web console available at http://localhost:%s/" % http_port) launcher.setServiceParent(app) timer.setServiceParent(app) webservice.setServiceParent(app) return app
def application(config): app = Application("Scrapyd") http_port = config.getint('http_port', 6800) poller = QueuePoller(config) eggstorage = FilesystemEggStorage(config) scheduler = SpiderScheduler(config) environment = Environment(config) app.setComponent(IPoller, poller) app.setComponent(IEggStorage, eggstorage) app.setComponent(ISpiderScheduler, scheduler) app.setComponent(IEnvironment, environment) launcher = Launcher(config, app) timer = TimerService(5, poller.poll) root = Root(config, app) root = configRoot(root, config) webservice = TCPServer(http_port, server.Site(root)) log.msg("Scrapyd web console available at http://localhost:%s/" % http_port) launcher.setServiceParent(app) timer.setServiceParent(app) webservice.setServiceParent(app) return app
def get_application(config): app = Application('Scrapyd') http_port = config.getint('http_port', 6800) bind_address = config.get('bind_address', '0.0.0.0') poll_interval = config.getfloat('poll_interval', 5) poller = QueuePoller(config) eggstorage = FilesystemEggStorage(config) scheduler = SpiderScheduler(config) environment = Environment(config) app.setComponent(IPoller, poller) app.setComponent(IEggStorage, eggstorage) app.setComponent(ISpiderScheduler, scheduler) app.setComponent(IEnvironment, environment) laupath = config.get('launcher', 'scrapyd_mongodb.launcher.Launcher') laucls = load_object(laupath) launcher = laucls(config, app) timer = TimerService(poll_interval, poller.poll) webservice = TCPServer( http_port, server.Site(Root(config, app)), interface=bind_address) log.msg('http://%(bind_address)s:%(http_port)s/' % {'bind_address':bind_address, 'http_port':http_port}) launcher.setServiceParent(app) timer.setServiceParent(app) webservice.setServiceParent(app) return app
def application(config): app = Application("Scrapyd") http_port = config.getint('http_port', 6800) bind_address = config.get('bind_address', '0.0.0.0') poller = QueuePoller(config) eggstorage = FilesystemEggStorage(config) scheduler = SpiderScheduler(config) environment = Environment(config) app.setComponent(IPoller, poller) app.setComponent(IEggStorage, eggstorage) app.setComponent(ISpiderScheduler, scheduler) app.setComponent(IEnvironment, environment) laupath = config.get('launcher', 'scrapyd.launcher.Launcher') laucls = load_object(laupath) launcher = laucls(config, app) timer = TimerService(5, poller.poll) webservice = TCPServer(http_port, server.Site(Root(config, app)), interface=bind_address) log.msg("Scrapyd web console available at http://%s:%s/" % (bind_address, http_port)) launcher.setServiceParent(app) timer.setServiceParent(app) webservice.setServiceParent(app) return app
def application(config): app = Application("Scrapyd") http_port = config.getint('http_port', 6800) bind_address = config.get('bind_address', '127.0.0.1') poll_interval = config.getfloat('poll_interval', 5) poller = QueuePoller(config) eggstorage = FilesystemEggStorage(config) scheduler = SpiderScheduler(config) environment = Environment(config) app.setComponent(IPoller, poller) app.setComponent(IEggStorage, eggstorage) app.setComponent(ISpiderScheduler, scheduler) app.setComponent(IEnvironment, environment) laupath = config.get('launcher', 'scrapyd.launcher.Launcher') laucls = load_object(laupath) launcher = laucls(config, app) webpath = config.get('webroot', 'scrapyd.website.Root') webcls = load_object(webpath) timer = TimerService(poll_interval, poller.poll) webservice = TCPServer(http_port, server.Site(webcls(config, app)), interface=bind_address) log.msg( format= "Scrapyd web console available at http://%(bind_address)s:%(http_port)s/", bind_address=bind_address, http_port=http_port) launcher.setServiceParent(app) timer.setServiceParent(app) webservice.setServiceParent(app) host = get_host_ip(config) redis_host = config.get('redis_host', 'localhost') redis_port = config.get('redis_port', 6379) redis_db = config.get('redis_db', 0) redis_pool = redis.ConnectionPool(host=redis_host, port=redis_port, db=redis_db) register_to_redis(config, redis_pool) log.msg('Registering scrapyd [{}] to redis {}:{} at db {}'.format( host, redis_host, redis_port, redis_db)) # log.msg('2018-11-03 10:10 am') redis_interval = config.getfloat('redis_interval', 5) register_timer = TimerService(redis_interval, register_to_redis, config, redis_pool) register_timer.setServiceParent(app) return app
def _get_application(): """ Factory function that returns an Application object. If the object does not exist then it creates a new Application object. (Internal use only). """ global _application if _application is not None: return _application _application = Application(consts.APP_NAME) logfile = WaderLogFile(consts.LOG_NAME, consts.LOG_DIR, maxRotatedFiles=consts.LOG_NUMBER) _application.setComponent(ILogObserver, FileLogObserver(logfile).emit) return _application
def application(config): app = Application("Scrapyd") http_port = config.getint('http_port', 6800) bind_address = config.get('bind_address', '127.0.0.1') poll_interval = config.getfloat('poll_interval', 5) poller = QueuePoller(config) eggstorage = FilesystemEggStorage(config) scheduler = SpiderScheduler(config) environment = Environment(config) app.setComponent(IPoller, poller) app.setComponent(IEggStorage, eggstorage) app.setComponent(ISpiderScheduler, scheduler) app.setComponent(IEnvironment, environment) laupath = config.get('launcher', 'scrapyd.launcher.Launcher') laucls = load_object(laupath) launcher = laucls(config, app) timer = TimerService(poll_interval, poller.poll) webpath = config.get('webroot', 'scrapyd.website.Root') webcls = load_object(webpath) username = config.get('username', '') password = config.get('password', '') if username and password: if ':' in username: sys.exit("The `username` option contains illegal character ':', " "check and update the configuration file of Scrapyd") portal = Portal(PublicHTMLRealm(webcls(config, app)), [StringCredentialsChecker(username, password)]) credential_factory = BasicCredentialFactory("Auth") resource = HTTPAuthSessionWrapper(portal, [credential_factory]) log.msg("Basic authentication enabled") else: resource = webcls(config, app) log.msg("Basic authentication disabled as either `username` or `password` is unset") webservice = TCPServer(http_port, server.Site(resource), interface=bind_address) log.msg(format="Scrapyd web console available at http://%(bind_address)s:%(http_port)s/", bind_address=bind_address, http_port=http_port) launcher.setServiceParent(app) timer.setServiceParent(app) webservice.setServiceParent(app) return app
def get_application(arguments): ServiceRoot = load_object(settings.SERVICE_ROOT) site = Site(ServiceRoot()) application = Application('scrapyrt') server = TCPServer(arguments.port, site, interface=arguments.ip) server.setServiceParent(application) return application
def make_application(ini_file): from harold.plugins import database from harold.plugins import deploy from harold.plugins import github from harold.plugins import http from harold.plugins import httpchat from harold.plugins import salons from harold.plugins import slack application = Application("Harold") parser = RawConfigParser() with open(ini_file) as fp: parser.readfp(fp) # TODO: ditch the separate config sections next def plugin_config(name): return dict(parser.items("harold:plugin:" + name)) http_plugin = http.make_plugin(application, plugin_config("http")) slack_plugin = slack.make_plugin(application, plugin_config("slack")) db_plugin = database.make_plugin(plugin_config("database")) salons_plugin = salons.make_plugin(db_plugin) github.make_plugin(http_plugin, slack_plugin, salons_plugin, db_plugin) deploy.make_plugin(plugin_config("deploy"), http_plugin, slack_plugin, salons_plugin) httpchat.make_plugin(http_plugin, slack_plugin) return application
def setupApplication(options): """Setup the API service. @param options: A parsed L{APIServiceOptions} instance. @return: A C{(port, site, application)} 3-tuple. """ config = setupOptions(options) setConfig(config) setupStore(config) setupCache(config) facade = setupFacade(config) root = setupRootResource(facade, development=bool(options.get('development'))) site = Site(root) application = Application('fluidinfo-api') setupManhole(application, config) if options.get('nodaemon') and not options.get('logfile'): setupLogging(stream=sys.stdout, level=INFO) else: logPath = options.get('logfile', 'fluidinfo-api.log') setupLogging(path=logPath, level=INFO) setupTwistedLogging(application) return int(config.get('service', 'port')), site, application
def application(config): app = Application("Flowder") app_id = config.get('app_id', 'fw0') logfile = config.get('logfile', '/var/log/flowder.log') loglevel = config.get('loglevel', 'info') db_file = config.get('db_file', 'flowder') rest_port = config.getint('rest_port', 4000) rest_bind = config.get('rest_bind', '0.0.0.0') poll_interval = config.getfloat('poll_interval', 1) poll_size = config.getint("poll_size", 5) signalmanager = SignalManager() app.setComponent(ISignalManager, signalmanager) fetcher = FetcherService(config) fetcher.setServiceParent(app) poller = QueuePoller(app, poll_size) poller.setServiceParent(app) db_file = '%s.db' % db_file task_storage = FileDownloaderTaskStorage(app, db_file) task_storage.setServiceParent(app) timer = TimerService(poll_interval, poller.poll) timer.setServiceParent(app) scheduler = TaskScheduler(config, app) scheduler.setServiceParent(app) laupath = config.get('launcher', 'flowder.launcher.Launcher') laucls = load_object(laupath) launcher = laucls(app, config) launcher.setServiceParent(app) restService = TCPServer(rest_port, server.Site(Root(app, config)), interface=rest_bind) restService.setServiceParent(app) amqp_publisher = AmqpService(app, config) amqp_publisher.setServiceParent(app) log.msg("Starting Flowder services (;-)") return app
def create_application(application_name, urwid_mind_factory, port, *args, **kw): """Convenience to create an application suitable for tac file """ application = Application(application_name) svc = create_service(urwid_mind_factory, 6022) svc.setServiceParent(application) return application
def test_applicationComponentsArePersistable(self): """ L{twisted.application.service.Application} implements L{IPersistable}. """ app = Application('app-name') from twisted.persisted.sob import IPersistable self.assertTrue(verifyObject(IPersistable, IPersistable(app)))
def application(config): """ 提供http服务并启动应用 :param config: :return: """ app = Application("engine") http_port = config.getint('http_port', 6800) bind_address = config.get('bind_address', '127.0.0.1') poll_interval = config.getfloat('poll_interval', 5) poller = QueuePoller(config) eggstorage = FilesystemEggStorage(config) scheduler = SpiderScheduler(config) environment = Environment(config) # metrics = MetricsReporter(config) app.setComponent(IPoller, poller) app.setComponent(IEggStorage, eggstorage) app.setComponent(ISpiderScheduler, scheduler) app.setComponent(IEnvironment, environment) # app.setComponent(IMetrics, metrics) laupath = config.get('launcher', 'engine.launcher.Launcher') laucls = load_object(laupath) launcher = laucls(config, app) webpath = config.get('webroot', 'engine.website.Root') webcls = load_object(webpath) timer = TimerService(poll_interval, poller.poll) webservice = TCPServer(http_port, server.Site(webcls(config, app)), interface=bind_address) log.msg( format="DtCrawlEngine 访问地址 at http://%(bind_address)s:%(http_port)s/", bind_address=bind_address, http_port=http_port) launcher.setServiceParent(app) timer.setServiceParent(app) webservice.setServiceParent(app) return app
def test_applicationComponents(self): """ Check L{twisted.application.service.Application} instantiation. """ app = Application("app-name") self.assertTrue(verifyObject(IService, IService(app))) self.assertTrue(verifyObject(IServiceCollection, IServiceCollection(app))) self.assertTrue(verifyObject(IProcess, IProcess(app))) self.assertTrue(verifyObject(IPersistable, IPersistable(app)))
def application(settings): app = Application("Scraperd") poller = QueuePoller(settings) environment = Environment(settings) app.setComponent(IPoller, poller) app.setComponent(IEnvironment, environment) laupath = settings.get('DAEMON_LAUNCHER', 'scraper.daemon.launcher.Launcher') laucls = load_object(laupath) launcher = laucls(settings, app) poll_interval = settings.getfloat('DAEMON_POLL_INTERVAL', 5) timer = TimerService(poll_interval, poller.poll) launcher.setServiceParent(app) timer.setServiceParent(app) return app
def main(): f = Factory() f.protocol = Fibonacci f.a, f.b = 1, 1 application = Application("Fibonacci") application.listenTCP(8888, f) application.save()
def __init__(self, cfg=None): """ Constructor """ self.cfg = cfg or dict() self.logger = logging.getLogger("app") self.reactor = reactor self.root_service = MultiService() self.service = MHubService(self.cfg, self.reactor, self) self.application = Application("mhub") self.root_service.setServiceParent(self.application)
def _prepare_svc(self): self.app = Application('test') self.workerm = workermanager.WorkerManager() self.sched = FIFOScheduler(self.workerm) self.taskm = taskmanager.TaskManager(self.db_path, self.workerm, self.sched) # HACK: tests needs clear twisted's reactor, so we're mocking # method that creates additional deferreds. self.taskm.database.start_periodic_sync = lambda: None for tid, env in self.SAVED_TASKS: self.taskm.database.update(tid, env) return self.taskm.startService()
def makeService(self, options): """ called by 'python -m twisted -no game-server', via twisted.plugins.game_server_plugin """ # config = ConfigParser() # config.read([options['config']]) application = Application(settings.SERVER_NAME) main = service.MultiService() game_service = GameService() game_service.setName(settings.SERVER_NAME + '-game-service') game_service.setServiceParent(main) main.setServiceParent(application) return main
def main(): """To daemonize as a twistd plugin! Except this doesn't work and these""" from twisted.application.internet import TCPServer, SSLServer from twisted.application.service import Application from twisted.internet import ssl rpc = TriggerXMLRPCServer() xmlrpc.addIntrospection(rpc) server_factory = server.Site(rpc) application = Application('trigger_xmlrpc') #xmlrpc_service = TCPServer(8000, server_factory) ctx = ssl.DefaultOpenSSLContextFactory('server.key', 'cacert.pem') xmlrpc_service = SSLServer(8000, server_factory, ctx) xmlrpc_service.setServiceParent(application) return application
def application(config): app = Application("Scrapyd") http_port = config.getint("http_port", 6800) bind_address = config.get("bind_address", "0.0.0.0") poll_interval = config.getfloat("poll_interval", 5) poller = QueuePoller(config) eggstorage = FilesystemEggStorage(config) scheduler = SpiderScheduler(config) environment = Environment(config) app.setComponent(IPoller, poller) app.setComponent(IEggStorage, eggstorage) app.setComponent(ISpiderScheduler, scheduler) app.setComponent(IEnvironment, environment) laupath = config.get("launcher", "scrapyd.launcher.Launcher") laucls = load_object(laupath) launcher = laucls(config, app) webpath = config.get("webroot", "scrapyd.website.Root") webcls = load_object(webpath) timer = TimerService(poll_interval, poller.poll) webservice = TCPServer(http_port, server.Site(webcls(config, app)), interface=bind_address) log.msg( format="Scrapyd web console available at http://%(bind_address)s:%(http_port)s/", bind_address=bind_address, http_port=http_port, ) launcher.setServiceParent(app) timer.setServiceParent(app) webservice.setServiceParent(app) return app
def application(): app = Application("Scrapyd") config = Config() http_port = config.getint('http_port', 6800) poller = QueuePoller(config) eggstorage = FilesystemEggStorage(config) scheduler = SpiderScheduler(config) environment = Environment(config) app.setComponent(IPoller, poller) app.setComponent(IEggStorage, eggstorage) app.setComponent(ISpiderScheduler, scheduler) app.setComponent(IEnvironment, environment) launcher = Launcher(config, app) timer = TimerService(5, poller.poll) webservice = TCPServer(http_port, server.Site(Root(config, app))) launcher.setServiceParent(app) timer.setServiceParent(app) webservice.setServiceParent(app) return app
def run(args=sys.argv, reactor=None): """Start the watchdog. This is the topmost function that kicks off the Landscape client. It cleans up the environment, loads the configuration, and starts the reactor. @param args: Command line arguments, including the program name as the first element. @param reactor: The reactor to use. If none is specified, the global reactor is used. @raise SystemExit: if command line arguments are bad, or when landscape- client is not running as 'root' or 'landscape'. """ clean_environment() config = WatchDogConfiguration() config.load(args) try: landscape_uid = pwd.getpwnam("landscape").pw_uid except KeyError: sys.exit("The 'landscape' user doesn't exist!") if os.getuid() not in (0, landscape_uid): sys.exit("landscape-client can only be run as 'root' or 'landscape'.") init_logging(config, "watchdog") application = Application("landscape-client") watchdog_service = WatchDogService(config) watchdog_service.setServiceParent(application) if reactor is None: from twisted.internet import reactor # We add a small delay to work around a Twisted bug: this method should # only be called when the reactor is running, but we still get a # PotentialZombieWarning. reactor.callLater(0, startApplication, application, False) reactor.run() return watchdog_service.exit_code
def setUp(self): self.config = { 'MEMCACHE_SERVERS': { 'c0': { 'host': 'localhost' }, 'c1': { 'host': 'localhost' }, 'c2': { 'host': 'localhost' }, }, } self.config_id = conf.settings.add_config(self.config) self.app = Application(__name__) self.memcache = app.build_memcache(self.app) IService(self.app).startService() yield timed.sleep(1)
def make_application(remoteHost, remotePort, listenPort, bindAddress): from twisted.application.internet import TCPServer from twisted.application.service import Application from twisted.internet import reactor applicationName = 'xoauth2relay' application = Application(applicationName) from .oauth2 import CredentialsStore from .oauth2 import OAuth2AuthenticatorRefreshingOnly from .xoauth2 import XOAUTH2TokenAcquirer from .xoauth2 import XOAUTH2MailerFactory credentialsStore = CredentialsStore.create(applicationName) oauth2authenticator = OAuth2AuthenticatorRefreshingOnly( credentialsStore, ) tokenAcquirer = XOAUTH2TokenAcquirer( oauth2authenticator=oauth2authenticator, ) mailerFactory = XOAUTH2MailerFactory( reactor, remoteHost, remotePort, tokenAcquirer, None, ) smtpDeliveryFactory = MessageDeliveryFactory(mailerFactory=mailerFactory) smtpServerProtoFactory = SMTPServerProtocolFactory( deliveryFactory=smtpDeliveryFactory, ) smtpServer = TCPServer( listenPort, smtpServerProtoFactory, interface=bindAddress ) smtpServer.setServiceParent(application) return application
def application(config): app = Application("Scrapyd") poll_interval = config.getfloat('poll_interval', 5) poller = QueuePoller(config, app) taskpoller = TaskPoller(config, app) # app.setComponent(IPoller, poller) app.setComponent(IPoller, taskpoller) # timer = TimerService(poll_interval, poller.poll) tasktimer = TimerService(poll_interval, taskpoller.poll) # timer.setServiceParent(app) tasktimer.setServiceParent(app) # http_port = config.getint('http_port', 9090) bind_address = config.get('bind_address', '127.0.0.1') log.msg(format="Scrapyd web console available at http://%(bind_address)s:%(http_port)s/", bind_address=bind_address, http_port=http_port) webservice = TCPServer(http_port, server.Site(Root(config, app)), interface=bind_address) webservice.setServiceParent(app) return app
# coding:utf-8 ''' @author = super_fazai @File : basic_server.py @connect : [email protected] ''' """ 设置监听amp服务器 AMP运行在面向流的基于连接的协议上,例如TCP或SSL。在使用AMP协议的任何功能之前,您需要连接。用于建立AMP连接的协议类是AMP。连接设置与Twisted中几乎所有协议的工作方式相同。 """ from twisted.protocols.amp import AMP from twisted.internet import reactor from twisted.internet.protocol import Factory from twisted.internet.endpoints import TCP4ServerEndpoint from twisted.application.service import Application from twisted.application.internet import StreamServerEndpointService application = Application("basic AMP server") endpoint = TCP4ServerEndpoint(reactor, 8751) factory = Factory() factory.protocol = AMP service = StreamServerEndpointService(endpoint, factory) service.setServiceParent(application)
mortal = Bot("Mortal", Room.get(name__icontains = "mortals")) GarenaRSFactory(mortal, Account.get(login = "******"), write_only = False) GarenaRSFactory(mortal, Account.get(login = "******"), send_kicks = True) GarenaRSFactory(mortal, Account.get(login = "******")) GarenaRSFactory(mortal, Account.get(login = "******")) #god = Bot("God", Room.get(pk = 196880)) #GarenaRSFactory(god, Account.get(login = "******"), # write_only = False, send_kicks = True) from twisted.application.service import Application application = Application("OSPL|Bot") from twisted.python.log import ILogObserver, FileLogObserver from twisted.python.logfile import LogFile logfile = LogFile("twisted.log", "tmp/", maxRotatedFiles = 5) application.setComponent(ILogObserver, FileLogObserver(logfile).emit) if __name__ == '__main__': reactor.run()
""" from pprint import pprint from twisted.application import internet from twisted.application.service import Application from twisted.web.resource import Resource from twisted.web.server import Site class FormPage(Resource): def render_GET(self, request): return 'form' def render_POST(self, request): pprint(request.__dict__) newdata = request.content.getvalue() print newdata return '' class HelloPage(Resource): def render_GET(self, request): return "hello" root = Resource() root.putChild("form", FormPage()) root.putChild("hello", HelloPage()) application = Application("My Web Service") internet.TCPServer(10000, Site(root, timeout=60 * 15)).setServiceParent(application)
return self def render_POST(self, request): return self.render_GET(request) def render_GET(self, _): status, text, action = None, None, None if self.api.exClient.factory.running: status, text, action = "Running", "Stop", "stop" else: status, text, action = "Stopped", "Start", "start" return """ <HTML> <HEAD> <META http-equiv="refresh" content="15" /> <TITLE>Touch Point Monitor Application</TITLE> </HEAD> <BODY> <H1>{}</H1> <FORM method="post"> <BUTTON type="submit" name="action" value="{}" >{}</BUTTON> </FORM> </BODY> </HTML> """.format(status, action, text) application = Application("UR TCP Transfer Application") TCPServer(80, Site(WebUI())).setServiceParent(application)
real_name, ips, dns.Record_A)).addErrback(self._got_error) return d elif query.type == dns.AAAA: # Kubernetes can't do IPv6, and if we return empty result OS X # gives up (Happy Eyeballs algorithm, maybe?), so never return # anything IPv6y. Instead return A records to pacify OS X. print("AAAA query, sending back A instead: {}".format( query.name.name)) query.type = dns.A return self.query(query, timeout=timeout, real_name=real_name) else: print("{} query:".format(query.type, query.name.name)) return self.fallback.query(query, timeout=timeout) def listen(): reactor.listenTCP(9050, socks.SOCKSv5Factory()) factory = server.DNSServerFactory(clients=[LocalResolver()]) protocol = dns.DNSDatagramProtocol(controller=factory) reactor.listenUDP(9053, protocol) with open("/var/run/secrets/kubernetes.io/serviceaccount/namespace") as f: NAMESPACE = f.read() NOLOOP = os.environ.get("TELEPRESENCE_NAMESERVER") is not None reactor.suggestThreadPoolSize(50) print("Listening...") listen() application = Application("go")
def setUp(self): self.app = Application('test_cron') self.tick = lambda: None
def lineReceived(self, line): if 'findService' in line: self.sendLine('Find that service!') line = line.split() service_name = line[1] result = networkserviceapi.findService(self.node, service_name) elif 'postService' in line: self.sendLine('Post that service!') line = line.split() service = networkserviceapi.Service(line[1],"description", line[2], line[3]) result = networkserviceapi.postService(self.node, service) elif line == 'printContacts': self.node.printContacts() result = "" elif 'launchApp' in line: self.sendLine('Launch that app!') line = line.split() app_name = line [1] # Create the application application = Application(app_name) # add calling node to the pool of nodes for that app application.addNode(self.node) # launch it application.launchApp(self.node) result = application elif 'joinApp' in line: self.sendLine('Join that app!') line = line.split() app_name = line [1] # find the applicaiton obejct in the DHT. result = findApplication(self.node, app_name) # if found add node. result.addCallback(joinApplication, self.node) # then reprint showing you have joined this app result.addCallback(print_result, app_name) self.transport.write('>>> ') return result
# do all the necessary high level wiring to make everything work together. # Specifically we create the cyclone web.Application from the API specification, # we create a TCPServer for it and setup logging. # We also set to kill the threadpool (the one used by Storm) when the # application shuts down. from twisted.application.service import Application from twisted.application import internet from cyclone import web from globaleaks.utils.utility import randbits from globaleaks.settings import GLSetting from globaleaks.rest import api from globaleaks.handlers.base import GLHTTPServer application = Application('GLBackend') settings = dict(cookie_secret=randbits(128), xsrf_cookies=True, debug=GLSetting.http_log) # Initialize the web API event listener, handling all the synchronous operations GLBackendAPIFactory = web.Application(api.spec, **settings) GLBackendAPIFactory.protocol = GLHTTPServer for ip in GLSetting.bind_addresses: GLBackendAPI = internet.TCPServer(GLSetting.bind_port, GLBackendAPIFactory, interface=ip) GLBackendAPI.setServiceParent(application) # define exit behaviour
def application(config): app = Application("Scrapyd") http_port = config.getint('http_port', 6800) bind_address = config.get('bind_address', '0.0.0.0') poll_interval = config.getfloat('poll_interval', 5) poller = QueuePoller(config) eggstorage = FilesystemEggStorage(config) schedpath = config.get('scheduler', 'scrapyd.scheduler.SpiderScheduler') schedCls = load_object(schedpath) scheduler = schedCls(config, app) environment = Environment(config) pubsub_path = config.get('pubsub', 'scrapyd.pubsub.BasePubSub') pubsubCls = load_object(pubsub_path) pubsub = pubsubCls(config, app) app.setComponent(IPoller, poller) app.setComponent(IEggStorage, eggstorage) app.setComponent(ISpiderScheduler, scheduler) app.setComponent(IEnvironment, environment) app.setComponent(IPubSub, pubsub) laupath = config.get('launcher', 'scrapyd.launcher.Launcher') laucls = load_object(laupath) launcher = laucls(config, app) timer = TimerService(poll_interval, poller.poll) webservice = TCPServer(http_port, server.Site(Root(config, app)), interface=bind_address) log.msg(format="Scrapyd web console available at http://%(bind_address)s:%(http_port)s/", bind_address=bind_address, http_port=http_port) launcher.setServiceParent(app) timer.setServiceParent(app) webservice.setServiceParent(app) return app
def render_GET(self, request): return '' def render_POST(self, request): contents = request.content.read() json_dict = json.loads(contents) print json_dict.keys() for key, value in json_dict.items() : decoded = base64.b64decode(value) img = open("image.jpg", "wb") img.write(decoded) img.close() print "first 50 chars" print value[:50] ''' json_dict = json.loads(newdata) # Parse json dict if json_dict.has_key("img_raw") : img = open("img.jpg", "wb") img.write(base64.b64decode(json_dict["img_raw"])) img.close() ''' return '<html><body>success-striing</body></html>' root = Resource() root.putChild("form", FormPage()) application = Application("Http Enpoint for App") TCPServer(PORT, Site(root)).setServiceParent(application)