当前位置: 首页>>代码示例>>Python>>正文


Python File.putChild方法代码示例

本文整理汇总了Python中twisted.web.static.File.putChild方法的典型用法代码示例。如果您正苦于以下问题:Python File.putChild方法的具体用法?Python File.putChild怎么用?Python File.putChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在twisted.web.static.File的用法示例。


在下文中一共展示了File.putChild方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: startService

# 需要导入模块: from twisted.web.static import File [as 别名]
# 或者: from twisted.web.static.File import putChild [as 别名]
    def startService(self):

        factory = WebSocketServerFactory(u"ws://127.0.0.1:%d" % self.port)
        factory.protocol = EchoServerProtocol

        # FIXME: Site.start/stopFactory should start/stop factories wrapped as Resources
        factory.startFactory()

        resource = WebSocketResource(factory)

        # we server static files under "/" ..
        webdir = os.path.abspath(pkg_resources.resource_filename("echows", "web"))
        root = File(webdir)

        # and our WebSocket server under "/ws" (note that Twisted uses
        # bytes for URIs)
        root.putChild(b"ws", resource)

        # both under one Twisted Web Site
        site = Site(root)

        self.site = site
        self.factory = factory

        self.listener = reactor.listenTCP(self.port, site)
开发者ID:Anggi-Permana-Harianja,项目名称:autobahn-python,代码行数:27,代码来源:echoservice.py

示例2: makeService

# 需要导入模块: from twisted.web.static import File [as 别名]
# 或者: from twisted.web.static.File import putChild [as 别名]
    def makeService(self, options):
        if not options['noisy-logging']:
            protocol.Factory.noisy = False
            
        endpoint = twitterEndpoint(options['endpoint'])
        tickeryService = service.MultiService()
        cache = TickeryCache(
            options['cache-dir'], options['restore-add-queue'],
            int(options['queue-width']), endpoint)
        cache.setServiceParent(tickeryService)
        
        root = File('www/output')
        root.putChild('tickery', RegularService(cache, endpoint))
        root.putChild(defaults.TICKERY_CALLBACK_CHILD, callback.Callback(cache))
        
        adminRoot = File('admin/output')
        adminRoot.putChild('tickery', AdminService(cache))
        root.putChild('admin', adminRoot)

        root.putChild('api', API(cache))
        
        factory = server.Site(root)
        if options['promiscuous']:
            kw = {}
        else:
            kw = { 'interface' : 'localhost' }
        tickeryServer = internet.TCPServer(int(options['port']), factory, **kw)
        tickeryServer.setServiceParent(tickeryService)
        
        return tickeryService
开发者ID:jdunck,项目名称:Tickery,代码行数:32,代码来源:tickery_service.py

示例3: start

# 需要导入模块: from twisted.web.static import File [as 别名]
# 或者: from twisted.web.static.File import putChild [as 别名]
    def start(self):
        """ start websocket server """
        logger.info('start websocket server at %s', self._url)
        self._factory = MyWebSocketServerFactory(
            self._url,
            debug=self._debug
        )

        self._factory.protocol = MyWebSocketServerProtocol
        self._factory.setProtocolOptions(allowHixie76=True)

        self._resource = WebSocketResource(self._factory)

        # we server static files under "/" ..
        root = File('.')

        # and our WebSocket server under "/websocket"
        root.putChild('websocket', self._resource)

        # both under one Twisted Web Site
        site = Site(root)
        site.protocol = HTTPChannelHixie76Aware
        reactor.listenTCP(self._port, site)
        self._thread = threading.Thread(target=reactor.run, args=(False,))
        self._thread.start()
开发者ID:chikuta,项目名称:autobahn_websocketserver_sample,代码行数:27,代码来源:websocket_server_sample.py

示例4: start_web

# 需要导入模块: from twisted.web.static import File [as 别名]
# 或者: from twisted.web.static.File import putChild [as 别名]
def start_web(port=8080):
    root = File('./enocean_site')
    root.putChild('radio', RadioResource())
    site = Site(root)
    reactor.listenTCP(port, site)
    logging.info('HTTP server running on port '+str(port))
    return site
开发者ID:jachor,项目名称:enocean-ui,代码行数:9,代码来源:web.py

示例5: startService

# 需要导入模块: from twisted.web.static import File [as 别名]
# 或者: from twisted.web.static.File import putChild [as 别名]
    def startService(self):

        factory = WebSocketServerFactory(u"ws://127.0.0.1:%d" % self.port, debug=self.debug)
        factory.protocol = DispatcherProtocol
        factory.protocol.core = self._core

        # FIXME: Site.start/stopFactory should start/stop factories wrapped as Resources
        factory.startFactory()

        resource = WebSocketResource(factory)

        # we server static files under "/" ..
        webdir = os.path.abspath(pkg_resources.resource_filename("leap.bitmask_core", "web"))
        root = File(webdir)

        # and our WebSocket server under "/ws"
        root.putChild(u"bitmask", resource)

        # both under one Twisted Web Site
        site = Site(root)

        self.site = site
        self.factory = factory

        self.listener = reactor.listenTCP(self.port, site)
开发者ID:ivanalejandro0,项目名称:bitmask_core,代码行数:27,代码来源:websocket.py

示例6: serve

# 需要导入模块: from twisted.web.static import File [as 别名]
# 或者: from twisted.web.static.File import putChild [as 别名]
def serve(port=8765, interface='0.0.0.0', installSignalHandlers=0, data_dir=get_datadir('webdata')):
    logging.info("SERVE %d, %s, %d", port, interface, installSignalHandlers)
    
    if not os.path.exists(data_dir):
        os.makedirs(data_dir)

    zip_dir = os.path.join(data_dir, 'zip')
    if not os.path.exists(zip_dir):
        os.makedirs(zip_dir)
    
    f = File(data_dir)

    f.putChild('', File(get_resource('www/index.html')))
    f.putChild('status.html', File(get_resource('www/status.html')))
    f.putChild('preloader.gif', File(get_resource('www/preloader.gif')))

    trans = Transcriber(data_dir)
    trans_ctrl = TranscriptionsController(trans)
    f.putChild('transcriptions', trans_ctrl)

    trans_zippr = TranscriptionZipper(zip_dir, trans)
    f.putChild('zip', trans_zippr)
    
    s = Site(f)
    logging.info("about to listen")
    default_reactor.listenTCP(port, s, interface=interface)
    logging.info("listening")

    default_reactor.run(installSignalHandlers=installSignalHandlers)
开发者ID:saisus,项目名称:gentle,代码行数:31,代码来源:serve.py

示例7: setUp

# 需要导入模块: from twisted.web.static import File [as 别名]
# 或者: from twisted.web.static.File import putChild [as 别名]
    def setUp(self):
        from twisted.python import threadpool
        reactor.threadpool = threadpool.ThreadPool(0, 10)
        reactor.threadpool.start()

        class Hello(resource.Resource):
            isLeaf = True

            def render_GET(self, request):
                return "<html>Hello, world!</html>"

        self.src_path = tempfile.mkdtemp(suffix=".src")
        self.cache_path = tempfile.mkdtemp(suffix=".cache")
        self._resource = None

        self.createSrcFile("a", "content of a")

        src = File(self.src_path)
        src.putChild("hello", Hello())
        factory = Site(src)
        self.httpserver = reactor.listenTCP(0, factory)
        p = self.httpserver.getHost().port

        plugProps = {"properties": {"cache-size": CACHE_SIZE,
                                    "cache-dir": self.cache_path,
                                    "virtual-hostname": "localhost",
                                    "virtual-port": p}}

        self.plug = \
            file_provider.FileProviderHTTPCachedPlug(plugProps)

        self.stats = DummyStats()
        self.plug.startStatsUpdates(self.stats)

        return self.plug.start(None)
开发者ID:ApsOps,项目名称:flumotion-orig,代码行数:37,代码来源:test_component_httpserver_httpcached_stats.py

示例8: startup

# 需要导入模块: from twisted.web.static import File [as 别名]
# 或者: from twisted.web.static.File import putChild [as 别名]
def startup():
	if not os.path.exists('data/firmware'):
		os.makedirs('data/firmware')
	if not os.path.exists('data/static'):
		os.makedirs('data/static')
	if not os.path.exists('data/cert'):
		os.makedirs('data/cert')
	# Check the certificate file
	host = getHost()
	validateCertHost('data/cert/key.pem', 'data/cert/cert.pem', 'data/static/thumb.txt', host)
	
	# Start up the HTTPS server
	web_port = 443
	root_handler = File('./data/static/')	
	firmware_handler = FirmwareHandler('data/firmware/')
	root_handler.putChild('firmware', firmware_handler)
	site = Site(root_handler)
	site.protocol = MyHttpChannel
	reactor.listenTCP(web_port, site)
	
	# Start up the HTTP server
	root_handler_http = File("./data/static/")
	config_handler = File("./config.html")
	root_handler_http.putChild('config.html', config_handler)
	site_http = Site(root_handler_http)
	reactor.listenTCP(8080, site_http)

	reactor.suggestThreadPoolSize(50)

	printStatus("Startup complete, running main loop...")

	# Run the main loop, this never returns:
	reactor.run()
开发者ID:jldeon,项目名称:OakSoftAP,代码行数:35,代码来源:oakupsrv.py

示例9: main

# 需要导入模块: from twisted.web.static import File [as 别名]
# 或者: from twisted.web.static.File import putChild [as 别名]
def main(argv):
    from twisted.python import log
    from twisted.web.server import Site
    from twisted.web.static import File
    from twisted.internet import reactor
    from twisted.python import log

    observer = log.PythonLoggingObserver('twisted')
    log.startLoggingWithObserver(observer.emit, setStdout=False)

    static_dir = os.path.abspath('.')
    logging.info("registering static folder %r on /" % static_dir)
    root = File(static_dir)

    wr = TwistedWebResource(soap11_application)
    logging.info("registering %r on /%s" % (wr, url))
    root.putChild(url, wr)

    site = Site(root)

    if port[0] == 0:
        port[0] = get_open_port()
    reactor.listenTCP(port[0], site)
    logging.info("listening on: %s:%d" % (host,port))

    return reactor.run()
开发者ID:plq,项目名称:spyne,代码行数:28,代码来源:soap_http_static.py

示例10: startService

# 需要导入模块: from twisted.web.static import File [as 别名]
# 或者: from twisted.web.static.File import putChild [as 别名]
    def startService(self):

        factory = WebSocketServerFactory("ws://localhost:%d" % self.port, debug=self.debug)

        factory.protocol = EchoServerProtocol
        factory.setProtocolOptions(allowHixie76=True)  # needed if Hixie76 is to be supported

        # FIXME: Site.start/stopFactory should start/stop factories wrapped as Resources
        factory.startFactory()

        resource = WebSocketResource(factory)

        # we server static files under "/" ..
        webdir = os.path.abspath(pkg_resources.resource_filename("echows", "web"))
        root = File(webdir)

        # and our WebSocket server under "/ws"
        root.putChild("ws", resource)

        # both under one Twisted Web Site
        site = Site(root)
        site.protocol = HTTPChannelHixie76Aware  # needed if Hixie76 is to be supported

        self.site = site
        self.factory = factory

        self.listener = reactor.listenTCP(self.port, site)
开发者ID:Avnerus,项目名称:AutobahnPython,代码行数:29,代码来源:echoservice.py

示例11: __init__

# 需要导入模块: from twisted.web.static import File [as 别名]
# 或者: from twisted.web.static.File import putChild [as 别名]
 def __init__(self, feederName, lockCamera, lockSensor):
     threading.Thread.__init__(self)
     feederName = feederName
     res = File('/home/pi/PiFeed/src/')
     res.putChild('', res)
     factory = Site(res)
     reactor.listenTCP(8000, factory)
     print('%s: twisted web server started' % (feederName))
开发者ID:zergler,项目名称:pifeed,代码行数:10,代码来源:infoServer.py

示例12: setup

# 需要导入模块: from twisted.web.static import File [as 别名]
# 或者: from twisted.web.static.File import putChild [as 别名]
def setup(scope, port=21000):
    MainHandler.scope = scope
    MainHandler.setup()
    global root
    root = File(".")
    root.putChild('_pyreg',File(os.path.dirname(__file__)+'/_pyreg'))
    site = WebSocketSite(root)
    site.addHandler("/ws/websocket", MainHandler)
    reactor.listenTCP(port, site)
开发者ID:amiller,项目名称:pyreg,代码行数:11,代码来源:browser.py

示例13: getChild

# 需要导入模块: from twisted.web.static import File [as 别名]
# 或者: from twisted.web.static.File import putChild [as 别名]
    def getChild(self, uid, req):
        out_dir = self.transcriber.out_dir(uid)
        trans_ctrl = File(out_dir)

        # Add a Status endpoint to the file
        trans_status = TranscriptionStatus(self.transcriber.get_status(uid))
        trans_ctrl.putChild("status.json", trans_status)
        
        return trans_ctrl
开发者ID:saisus,项目名称:gentle,代码行数:11,代码来源:serve.py

示例14: __init__

# 需要导入模块: from twisted.web.static import File [as 别名]
# 或者: from twisted.web.static.File import putChild [as 别名]
 def __init__(self, service):
     pagedir = os.getcwd() + "/www"
     timeout = 60*60*12
     root = File(pagedir)
     dbres = Uploader()
     root.putChild("upload", dbres)
     root.childNotFound = File(pagedir+"/404.html")
     server.Site.__init__(self, root, logPath=None, timeout=timeout)
     self.service = service
开发者ID:hatmer,项目名称:TwistedHTTPS,代码行数:11,代码来源:serve.py

示例15: runatomix

# 需要导入模块: from twisted.web.static import File [as 别名]
# 或者: from twisted.web.static.File import putChild [as 别名]
def runatomix():
    log.startLogging(stdout)
    factory  = WebSocketServerFactory(u"ws://127.0.0.1:8080")
    factory.protocol = WebServerProtocol
    resource = WebSocketResource(factory)
    root = File(".")
    root.putChild(u"ws", resource)
    site = Site(root)
    reactor.listenTCP(8080, site)
    reactor.run()
开发者ID:Izeka,项目名称:atomix,代码行数:12,代码来源:atomix.py


注:本文中的twisted.web.static.File.putChild方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。