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


Python Site.requestFactory方法代码示例

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


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

示例1: _create_web_factory

# 需要导入模块: from twisted.web.server import Site [as 别名]
# 或者: from twisted.web.server.Site import requestFactory [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: get_site

# 需要导入模块: from twisted.web.server import Site [as 别名]
# 或者: from twisted.web.server.Site import requestFactory [as 别名]
def get_site(resource, logging=False):
    """
    :param resource: A :class:`twisted.web.resource.Resource` object.
    :return: a :class:`Site` that can be run
    """
    site = Site(resource)
    site.displayTracebacks = False
    site.requestFactory = MimicLoggingRequest if logging else MimicRequest
    return site
开发者ID:derwolfe,项目名称:mimic,代码行数:11,代码来源:resource.py

示例3: secureSite

# 需要导入模块: from twisted.web.server import Site [as 别名]
# 或者: from twisted.web.server.Site import requestFactory [as 别名]
def secureSite(_environ=environ):
    """Builds the secure (HTTPS, port 443) site.

    """
    root = File(_environ["STATIC_PATH"])
    root.putChild("subscribe", SubscribeResource("[email protected]"))

    site = Site(root)
    site.displayTracebacks = False
    site.requestFactory = _withHSTS(site.requestFactory)
    return site
开发者ID:crypto101,项目名称:website,代码行数:13,代码来源:web.py

示例4: int

# 需要导入模块: from twisted.web.server import Site [as 别名]
# 或者: from twisted.web.server.Site import requestFactory [as 别名]
            ## 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")

            ## enable Hixie-76 on Twisted Web
            ##
            if options.get("hixie76_aware", False):
                transport_factory.protocol = HTTPChannelHixie76Aware  # needed if Hixie76 is to be supported

        else:
            raise Exception("logic error")

        ## create transport endpoint / listening port from transport factory
        ##
        if True:
开发者ID:rogererens,项目名称:crossbar,代码行数:33,代码来源:router.py

示例5: User

# 需要导入模块: from twisted.web.server import Site [as 别名]
# 或者: from twisted.web.server.Site import requestFactory [as 别名]
        return self.session_uid_to_user[session_uid]

class User():
    """
    any relevant user information
    """
    def __init__(self, session_uid):
        self.session_uid = session_uid
        self.uid = User.uid
        User.uid += 1

    def getid(self):
        return self.uid

User.uid = 0
users = Users()

index = Index()
index.putChild('e', EventScheduler())

site = Site(index)
site.requestFactory = RequestBootstrap # hook in our request

reactor.listenTCP(8080, site) # HTTP listener

osc_writer = OscWriter(reactor, 16666) # UDP(OSC) sender/receiver

reactor.run()

开发者ID:clownpie,项目名称:http2osc,代码行数:30,代码来源:bootstrap.py

示例6: FormPage

# 需要导入模块: from twisted.web.server import Site [as 别名]
# 或者: from twisted.web.server.Site import requestFactory [as 别名]
import cgi

class FormPage(Resource):
    def render_GET(self, request):
        return """
<html>
<body>
<form method="POST" enctype="multipart/form-data">
<input name="the-file" type="file" />
<input type="submit" />
</form>
</body>
</html>
"""

    def render_POST(self, request):
        return '<html><body>You submitted file: %s<pre>%s</pre></body></html>' % (
            # filename always placed in fieldname_filename
            request.args["the-file_filename"][0],
            # remember to treat the args as files/tempfiles now!
            cgi.escape(request.args["the-file"][0].read())
            )

root = Resource()
root.putChild("form", FormPage())
factory = Site(root)
## change to LargeRequest
factory.requestFactory = LargeRequest
reactor.listenTCP(8880, factory)
reactor.run()
开发者ID:myukselen,项目名称:twisted-largerequest,代码行数:32,代码来源:example.py


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