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


Python Site.log方法代码示例

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


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

示例1: _create_web_factory

# 需要导入模块: from twisted.web.server import Site [as 别名]
# 或者: from twisted.web.server.Site import log [as 别名]
    def _create_web_factory(self, config):

        options = config.get('options', {})

        # create Twisted Web root resource
        if '/' in config['paths']:
            root_config = config['paths']['/']
            root = self._create_resource(root_config, nested=False)
        else:
            root = Resource404(self._templates, b'')

        # create Twisted Web resources on all non-root paths configured
        self._add_paths(root, config.get('paths', {}))

        # create the actual transport factory
        transport_factory = Site(root)
        transport_factory.noisy = False

        # Web access logging
        if not options.get('access_log', False):
            transport_factory.log = lambda _: None

        # Traceback rendering
        transport_factory.displayTracebacks = options.get('display_tracebacks', False)

        # HSTS
        if options.get('hsts', False):
            if 'tls' in config['endpoint']:
                hsts_max_age = int(options.get('hsts_max_age', 31536000))
                transport_factory.requestFactory = createHSTSRequestFactory(transport_factory.requestFactory, hsts_max_age)
            else:
                self.log.warn("Warning: HSTS requested, but running on non-TLS - skipping HSTS")

        return transport_factory
开发者ID:david-e,项目名称:crossbar,代码行数:36,代码来源:router.py

示例2: master

# 需要导入模块: from twisted.web.server import Site [as 别名]
# 或者: from twisted.web.server.Site import log [as 别名]
def master(options):
   """
   Start of the master process.
   """
   if not options.silence:
      print "Master started on PID %s" % os.getpid()

   ## start embedded Web server if asked for (this only runs on master)
   ##
   if options.port:
      webdir = File(".")
      web = Site(webdir)
      web.log = lambda _: None # disable annoyingly verbose request logging
      reactor.listenTCP(options.port, web)

   ## we just need some factory like thing .. it won't be used on master anyway
   ## for actual socket accept
   ##
   factory = Factory()

   ## create socket, bind and listen ..
   port = reactor.listenTCP(options.wsport, factory, backlog = options.backlog)

   ## .. but immediately stop reading: we only want to accept on workers, not master
   port.stopReading()

   ## fire off background workers
   ##
   for i in range(options.workers):

      args = [executable, "-u", __file__, "--fd", str(port.fileno()), "--cpuid", str(i)]

      ## pass on cmd line args to worker ..
      args.extend(sys.argv[1:])

      reactor.spawnProcess(
         None, executable, args,
         childFDs = {0: 0, 1: 1, 2: 2, port.fileno(): port.fileno()},
         env = os.environ)

   reactor.run()
开发者ID:EricSchles,项目名称:AutobahnPython,代码行数:43,代码来源:server.py

示例3: print

# 需要导入模块: from twisted.web.server import Site [as 别名]
# 或者: from twisted.web.server.Site import log [as 别名]
        WebSocketServerFactory.__init__(self, url)

        # map of cookies
        self._cookies = {}


if __name__ == '__main__':

    log.startLogging(sys.stdout)

    print("Running Autobahn|Python {}".format(autobahn.version))

    # our WebSocket server factory
    factory = PersonaServerFactory(u"ws://127.0.0.1:8080")

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

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

    # run both under one Twisted Web Site
    site = Site(root)
    site.log = lambda _: None  # disable any logging

    reactor.listenTCP(8080, site)

    reactor.run()
开发者ID:Anggi-Permana-Harianja,项目名称:autobahn-python,代码行数:32,代码来源:server.py

示例4: main

# 需要导入模块: from twisted.web.server import Site [as 别名]
# 或者: from twisted.web.server.Site import log [as 别名]
def main(pm):
    from sputnik.webserver.router.twisted.wamp import RouterFactory
    router_factory = RouterFactory()
    router_factory.router = SputnikRouter

    router_factory.authz_plugins = \
            pm.services.get("sputnik.webserver.plugins.authz", [])
    router_factory.schema_plugins = \
            pm.services.get("sputnik.webserver.plugins.schema", [])

    from sputnik.webserver.router.twisted.wamp import RouterSessionFactory
    session_factory = RouterSessionFactory(router_factory)
    session_factory.session = SputnikRouterSession

    authn_stack = [("ip.IPFilter", "requisite"),
                   ("anonymous.AnonymousLogin", "sufficient"),
                   ("cookie.CookieLogin", "sufficient"),
                   ("wampcra.WAMPCRALogin", "requisite"),
                   ("totp.TOTPVerification", "requisite")]
    session_factory.plugins = []
    for plugin_name, flag in authn_stack:
        path = "sputnik.webserver.plugins.authn." + plugin_name
        session_factory.plugins.append((pm.plugins[path], flag))

    rpc_plugins = pm.services.get("sputnik.webserver.plugins.rpc", [])
    feeds_plugins = pm.services.get("sputnik.webserver.plugins.feeds", [])
    svc_plugins = rpc_plugins + feeds_plugins
    for plugin in svc_plugins:
        component_session = plugin
        component_session.config.realm = u"sputnik"
        session_factory.add(component_session,
                plugin.plugin_path.decode("ascii"), u"trusted")

    uri = "ws://"
    if config.getboolean("webserver", "ssl"):
        uri = "wss://"

    address = config.get("webserver", "ws_address")
    port = config.getint("webserver", "ws_port")
    uri += "%s:%s/" % (address, port)

    from autobahn.twisted.websocket import WampWebSocketServerFactory
    transport_factory = WampWebSocketServerFactory(session_factory,
            uri, debug = False, debug_wamp = False)
    transport_factory.setProtocolOptions(failByDrop = False)
    watchdog(config.get("watchdog", "webserver"))

    from twisted.web.server import Site
    from autobahn.twisted.resource import WebSocketResource

    root = Root()
    ws_resource = WebSocketResource(transport_factory)
    rest_resource = pm.plugins['sputnik.webserver.rest.RESTProxy']
    root.putChild("ws", ws_resource)
    root.putChild("api", rest_resource)
    site = Site(root)
    site.noisy = False
    site.log = lambda _: None

    from twisted.internet.endpoints import serverFromString, quoteStringArgument
    if config.getboolean("webserver", "ssl"):
        key = config.get("webserver", "ssl_key")
        cert = config.get("webserver", "ssl_cert")
        cert_chain = config.get("webserver", "ssl_cert_chain")
        # TODO: Add dhparameters
        # See https://twistedmatrix.com/documents/14.0.0/core/howto/endpoints.html
        server = serverFromString(reactor, b"ssl:%d:privateKey=%s:certKey=%s:extraCertChain=%s:sslmethod=TLSv1_METHOD"
                                  % (port,
                                     quoteStringArgument(key),
                                     quoteStringArgument(cert),
                                     quoteStringArgument(cert_chain)))
    else:
        server = serverFromString(reactor, b"tcp:%d" % port)

    server.listen(site)
开发者ID:Mrkebubun,项目名称:sputnik,代码行数:77,代码来源:launch.py

示例5: JsonSerializer

# 需要导入模块: from twisted.web.server import Site [as 别名]
# 或者: from twisted.web.server.Site import log [as 别名]
      ws_factory.setProtocolOptions(failByDrop = False)
      serializers = [MsgPackSerializer(), JsonSerializer()]

      resource = WampHttpResource(serializers, debug=True, timeout=100, killAfter=120)
      resource.factory = ws_factory
      root = File("longpoll")

      root.putChild("ws", WebSocketResource(ws_factory))
      root.putChild("longpoll", resource)
      if args.static_dir:
          #root.putChild("web", File("/Users/arno/Documents/PycharmProjects/AutobahnJS/test/"))
          #root.putChild("autobahn.js", File("/Users/arno/Documents/PycharmProjects/AutobahnJS/build/autobahn.js"))
          #root.putChild("lib", File("/Users/arno/Documents/PycharmProjects/AutobahnJS/package/lib/"))
          root.putChild("static", File(args.static_dir))
      transport_factory = Site(root)
      transport_factory.log = lambda _: None # disable any logging


   elif args.transport in ['rawsocket-json', 'rawsocket-msgpack']:

      ## create a WAMP-over-RawSocket transport server factory
      ##
      if args.transport == 'rawsocket-msgpack':
         from autobahn.wamp.serializer import MsgPackSerializer
         serializer = MsgPackSerializer()
      elif args.transport == 'rawsocket-json':
         from autobahn.wamp.serializer import JsonSerializer
         serializer = JsonSerializer()
      else:
         raise Exception("should not arrive here")
开发者ID:arnoschn,项目名称:AutobahnPython,代码行数:32,代码来源:server.py

示例6: startService

# 需要导入模块: from twisted.web.server import Site [as 别名]
# 或者: from twisted.web.server.Site import log [as 别名]
   def startService(self):
      log.msg("Starting %s service ..." % self.SERVICENAME)

      issecure = self.services["config"]["hub-websocket-tls"]
      port = self.services["config"]["hub-websocket-port"]
      acceptqueue = self.services["config"]["ws-accept-queue-size"]

      if issecure:
         contextFactory = TlsContextFactory(self.services["config"]["hub-websocket-tlskey-pem"],
                                            self.services["config"]["hub-websocket-tlscert-pem"],
                                            dhParamFilename = self.services['master'].dhParamFilename)

         uri = "wss://localhost:%d" % port
      else:
         contextFactory = None

         uri = "ws://localhost:%d" % port

      self.wsfactory = HubWebSocketFactory(uri, self.dbpool, self.services)
      #self.wsfactory.trackTimings = True

      self.enableAppWeb = self.services["config"]["service-enable-appweb"]

      if self.enableAppWeb:
         ## FIXME: Site.start/stopFactory should start/stop factories wrapped as Resources
         self.wsfactory.startFactory()
         resource = WebSocketResource(self.wsfactory)
         appwebDir = self.services["master"].webdata
         root = File(appwebDir)
         root.putChild(self.services["config"]["ws-websocket-path"], resource)

         ## CGI
         ##
         cgienable = self.services["config"]["appweb-cgi-enable"]
         cgipath = self.services["config"]["appweb-cgi-path"]
         cgiprocessor = self.services["config"]["appweb-cgi-processor"]
         if cgienable and cgipath is not None and cgipath.strip() != "" and cgiprocessor is not None and cgiprocessor.strip() != "":
            cgipath = cgipath.strip()
            cgidir = os.path.join(appwebDir, cgipath)
            cgiprocessor = cgiprocessor.strip()
            cgiresource = CgiDirectory(cgidir, cgiprocessor)
            root.putChild(cgipath, cgiresource)
            log.msg("CGI configured on path '%s' using processor '%s'" % (cgipath, cgiprocessor))
         else:
            log.msg("No CGI configured")

         factory = Site(root)
         factory.log = lambda _: None # disable any logging
         factory.protocol = HTTPChannelHixie76Aware # needed if Hixie76 is to be supported

         ## REST interface to get config values
         ##
         configPath = self.services["config"]["ws-websocket-path"] + "config"
         addPortConfigResource(self.services["config"], root, configPath)
      else:
         factory = self.wsfactory

      self.factory = factory

      if issecure:
         self.listener = reactor.listenSSL(port, factory, contextFactory, backlog = acceptqueue)
      else:
         self.listener = reactor.listenTCP(port, factory, backlog = acceptqueue)

      self.isRunning = True
开发者ID:jamjr,项目名称:crossbar,代码行数:67,代码来源:hubwebsocket.py

示例7: WampWebSocketServerFactory

# 需要导入模块: from twisted.web.server import Site [as 别名]
# 或者: from twisted.web.server.Site import log [as 别名]
   transport_factory = WampWebSocketServerFactory(session_factory, args.wsurl, debug = False, debug_wamp = args.debug)
   transport_factory.setProtocolOptions(failByDrop = False)


   from twisted.web.server import Site
   from twisted.web.static import File
   from autobahn.twisted.resource import WebSocketResource

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

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

   ## run both under one Twisted Web Site
   site = Site(root)
   site.noisy = False
   site.log = lambda _: None


   ## start the WebSocket server from an endpoint
   ##
   server = serverFromString(reactor, args.websocket)
   server.listen(site)


   ## now enter the Twisted reactor loop
   ##
   reactor.run()
开发者ID:BanzaiMan,项目名称:AutobahnPython,代码行数:32,代码来源:server.py

示例8: log

# 需要导入模块: from twisted.web.server import Site [as 别名]
# 或者: from twisted.web.server.Site import log [as 别名]
 def log(self, request):
     if getattr(request, 'do_not_log', None):
         return
     return Site.log(self, request)
开发者ID:Nagato23,项目名称:vumi,代码行数:6,代码来源:utils.py

示例9: UploadDatabaseDump

# 需要导入模块: from twisted.web.server import Site [as 别名]
# 或者: from twisted.web.server.Site import log [as 别名]
      root.putChild(str(self.services["config"].get("export-url")), dbexp)

      ## Database Import
      ##
      dbimp = UploadDatabaseDump(str(self.services["config"].get("import-dir")))
      root.putChild(str(self.services["config"].get("import-url")), dbimp)

      ## Activate
      ##
      root.putChild("doactivate", Activate(self.dbpool, self.services))


      ## create twisted.web Site
      ##
      factory = Site(root)
      factory.log = lambda _: None # disable any logging

      cfg = self.services["config"]

      port = cfg["admin-web-port"]
      if cfg["admin-web-tls"]:
         contextFactory = TlsContextFactory(cfg["admin-web-tlskey-pem"],
                                            cfg["admin-web-tlscert-pem"],
                                            dhParamFilename = self.services['master'].dhParamFilename)
         self.listener = self.reactor.listenSSL(port, factory, contextFactory)
      else:
         self.listener = self.reactor.listenTCP(port, factory)

      self.isRunning = True

开发者ID:Inspire2Innovate,项目名称:crossbar,代码行数:31,代码来源:adminwebresource.py

示例10: Site

# 需要导入模块: from twisted.web.server import Site [as 别名]
# 或者: from twisted.web.server.Site import log [as 别名]
   from twisted.web.server import Site
   from twisted.web.static import File
   from twisted.internet.endpoints import serverFromString

   mimetypes.add_type('image/svg+xml', '.svg')
   mimetypes.add_type('text/javascript', '.jgz')

   parser = argparse.ArgumentParser()

   parser.add_argument("--root", type = str, default = ".",
                       help = 'Web document root directory')

   parser.add_argument("--endpoint", type = str, default = "tcp:8080",
                       help = 'Twisted server endpoint descriptor, e.g. "tcp:8080" or "unix:/tmp/mywebsocket".')

   parser.add_argument("-s", "--silence", action = "store_true",
                       help = "Disable access logging.")

   args = parser.parse_args()
   log.startLogging(sys.stdout)

   factory = Site(File(args.root))
   if args.silence:
      factory.log = lambda _: None
      factory.noisy = False

   server = serverFromString(reactor, args.endpoint)
   server.listen(factory)

   reactor.run()
开发者ID:AdrianBajdiuk,项目名称:AutobahnPython,代码行数:32,代码来源:serve.py

示例11: ApplicationError

# 需要导入模块: from twisted.web.server import Site [as 别名]
# 或者: from twisted.web.server.Site import log [as 别名]
                        log.msg("Web path type 'longpoll' not implemented")

                    else:
                        raise ApplicationError(
                            "crossbar.error.invalid_configuration",
                            "invalid Web path type '{}'".format(path_config["type"]),
                        )

            ## create the actual transport factory
            ##
            transport_factory = Site(root)

            ## Web access logging
            ##
            if not options.get("access_log", False):
                transport_factory.log = lambda _: None

            ## Traceback rendering
            ##
            transport_factory.displayTracebacks = options.get("display_tracebacks", False)

            ## HSTS
            ##
            if options.get("hsts", False):
                if "tls" in config["endpoint"]:
                    hsts_max_age = int(options.get("hsts_max_age", 31536000))
                    transport_factory.requestFactory = createHSTSRequestFactory(
                        transport_factory.requestFactory, hsts_max_age
                    )
                else:
                    log.msg("Warning: HSTS requested, but running on non-TLS - skipping HSTS")
开发者ID:rogererens,项目名称:crossbar,代码行数:33,代码来源:router.py


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