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


Python File.childNotFound方法代码示例

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


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

示例1: __init__

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

示例2: File

# 需要导入模块: from twisted.web.static import File [as 别名]
# 或者: from twisted.web.static.File import childNotFound [as 别名]
import os
import sys

from twisted.web.server import Site
from twisted.web.static import File
from twisted.internet import reactor

sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "lib", "python") )

from twistedfun.add20 import Add20Controller
from twistedfun.add20json import Add20JSONController

PORT = 8888

if __name__ == "__main__":
    root = File(os.path.join(os.path.dirname(os.path.realpath(__file__)), "..","public"), defaultType='text/html; charset=utf-8')
    root.childNotFound = File(os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "public", "404.html"))
    root.putChild('add20', Add20Controller())
    root.putChild('add20json', Add20JSONController())

    factory = Site(root)
    reactor.listenTCP(PORT, factory)
    reactor.run()
开发者ID:aawilson,项目名称:twistedfun,代码行数:25,代码来源:twistedfun-server.py

示例3: start_router_transport

# 需要导入模块: from twisted.web.static import File [as 别名]
# 或者: from twisted.web.static.File import childNotFound [as 别名]

#.........这里部分代码省略.........
                     root_dir = os.path.abspath(pkg_resources.resource_filename(root_config['package'], root_config['resource']))
                  except Exception as e:
                     emsg = "ERROR: could not import resource '{}' from package '{}' - {}".format(root_config['resource'], root_config['package'], e)
                     log.msg(emsg)
                     raise ApplicationError("crossbar.error.invalid_configuration", emsg)
                  else:
                     mod_version = getattr(mod, '__version__', '?.?.?')
                     log.msg("Loaded static Web resource '{}' from package '{} {}' (filesystem path {})".format(root_config['resource'], root_config['package'], mod_version, root_dir))

            else:
               raise ApplicationError("crossbar.error.invalid_configuration", "missing web spec")

            root_dir = root_dir.encode('ascii', 'ignore') # http://stackoverflow.com/a/20433918/884770
            if self.debug:
               log.msg("Starting Web service at root directory {}".format(root_dir))


            ## create resource for file system hierarchy
            ##
            if root_options.get('enable_directory_listing', False):
               root = File(root_dir)
            else:
               root = FileNoListing(root_dir)

            ## set extra MIME types
            ##
            root.contentTypes.update(EXTRA_MIME_TYPES)
            if 'mime_types' in root_options:
               root.contentTypes.update(root_options['mime_types'])
            patchFileContentTypes(root)

            ## render 404 page on any concrete path not found
            ##
            root.childNotFound = Resource404(self._templates, root_dir)


         ## WSGI root resource
         ##
         elif root_type == 'wsgi':

            if not _HAS_WSGI:
               raise ApplicationError("crossbar.error.invalid_configuration", "WSGI unsupported")

            wsgi_options = root_config.get('options', {})

            if not 'module' in root_config:
               raise ApplicationError("crossbar.error.invalid_configuration", "missing module")

            if not 'object' in root_config:
               raise ApplicationError("crossbar.error.invalid_configuration", "missing object")

            try:
               mod = importlib.import_module(root_config['module'])
            except ImportError:
               raise ApplicationError("crossbar.error.invalid_configuration", "module import failed")
            else:
               if not root_config['object'] in mod.__dict__:
                  raise ApplicationError("crossbar.error.invalid_configuration", "object not in module")
               else:
                  app = getattr(mod, root_config['object'])

            ## create a Twisted Web WSGI resource from the user's WSGI application object
            try:
               wsgi_resource = WSGIResource(reactor, reactor.getThreadPool(), app)
            except Exception as e:
               raise ApplicationError("crossbar.error.invalid_configuration", "could not instantiate WSGI resource: {}".format(e))
开发者ID:Inspire2Innovate,项目名称:crossbar,代码行数:70,代码来源:router.py

示例4: getChild

# 需要导入模块: from twisted.web.static import File [as 别名]
# 或者: from twisted.web.static.File import childNotFound [as 别名]
        request.setHeader(b"content-type", b"text/html; charset=utf-8")
        return self.page

    def getChild(self, chnam, request):
        return self


class NoResource(ErrorResource):
    def __init__(self):
        ErrorResource.__init__(self, NOT_FOUND)


application = Application("static-server")

plainSite = Site(RedirectResource())
plainSite.displayTracebacks = False
plainService6 = TCPServer(INSECURE_PORT, plainSite, interface='::')
plainService6.setServiceParent(application)

files = File(DOCUMENTS.path)
files.childNotFound = NoResource()

secureSite = Site(HSTSResource(files))
secureSite.displayTracebacks = False
secureService6 = SSLServer(SECURE_PORT,
                           secureSite,
                           ctxFactory,
                           interface='::')

secureService6.setServiceParent(application)
开发者ID:derwolfe,项目名称:calrissian,代码行数:32,代码来源:server.py

示例5: start_transport

# 需要导入模块: from twisted.web.static import File [as 别名]
# 或者: from twisted.web.static.File import childNotFound [as 别名]
    def start_transport(self, router_index, config):
        """
      Start a transport on this router module.
      """
        if not router_index in self._routers:
            raise ApplicationError("crossbar.error.no_such_router", router_index)

        router = self._routers[router_index]

        if self.debug:
            log.msg("Worker {}: starting '{}' transport on router module.".format(config["type"], self._pid))

        ## check for valid transport type
        ##
        if not config["type"] in ["websocket", "websocket.testee", "web", "rawsocket"]:
            raise ApplicationError(
                "crossbar.error.invalid_transport", "Unknown transport type '{}'".format(config["type"])
            )

        ## standalone WAMP-RawSocket transport
        ##
        if config["type"] == "rawsocket":

            transport_factory = CrossbarWampRawSocketServerFactory(router.session_factory, config)

        ## standalone WAMP-WebSocket transport
        ##
        elif config["type"] == "websocket":

            transport_factory = CrossbarWampWebSocketServerFactory(router.session_factory, config, self._templates)

        ## standalone WebSocket testee transport
        ##
        elif config["type"] == "websocket.testee":

            transport_factory = TesteeServerFactory(config, self._templates)

        ## Twisted Web transport
        ##
        elif config["type"] == "web":

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

            ## create Twisted Web root resource
            ##
            root_config = config["paths"]["/"]
            root_type = root_config["type"]

            ## Static file hierarchy root resource
            ##
            if root_type == "static":

                if "directory" in root_config:

                    root_dir = os.path.abspath(os.path.join(self._cbdir, root_config["directory"]))

                elif "module" in root_config:
                    if not "resource" in root_config:
                        raise ApplicationError("crossbar.error.invalid_configuration", "missing module")

                    try:
                        mod = importlib.import_module(root_config["module"])
                    except ImportError:
                        raise ApplicationError("crossbar.error.invalid_configuration", "module import failed")
                    else:
                        try:
                            root_dir = os.path.abspath(
                                pkg_resources.resource_filename(root_config["module"], root_config["resource"])
                            )
                        except Exception, e:
                            raise ApplicationError("crossbar.error.invalid_configuration", str(e))
                        else:
                            mod_version = getattr(mod, "__version__", "?.?.?")
                            log.msg(
                                "Loaded static Web resource '{}' from module '{} {}' (filesystem path {})".format(
                                    root_config["resource"], root_config["module"], mod_version, root_dir
                                )
                            )

                else:
                    raise ApplicationError("crossbar.error.invalid_configuration", "missing web spec")

                root_dir = root_dir.encode("ascii", "ignore")  # http://stackoverflow.com/a/20433918/884770
                if self.debug:
                    log.msg("Starting Web service at root directory {}".format(root_dir))

                ## create resource for file system hierarchy
                ##
                if options.get("enable_directory_listing", False):
                    root = File(root_dir)
                else:
                    root = FileNoListing(root_dir)

                ## render 404 page on any concrete path not found
                ##
                root.childNotFound = Resource404(self._templates, root_dir)
开发者ID:rogererens,项目名称:crossbar,代码行数:98,代码来源:router.py

示例6: ApplicationError

# 需要导入模块: from twisted.web.static import File [as 别名]
# 或者: from twisted.web.static.File import childNotFound [as 别名]
                        else:

                            raise ApplicationError("crossbar.error.invalid_configuration", "missing web spec")

                        static_dir = static_dir.encode("ascii", "ignore")  # http://stackoverflow.com/a/20433918/884770

                        ## create resource for file system hierarchy
                        ##
                        if static_options.get("enable_directory_listing", False):
                            static_resource = File(static_dir)
                        else:
                            static_resource = FileNoListing(static_dir)

                        ## render 404 page on any concrete path not found
                        ##
                        static_resource.childNotFound = Resource404(self._templates, static_dir)

                        root.putChild(path, static_resource)

                    ## WSGI resource
                    ##
                    elif path_config["type"] == "wsgi":

                        wsgi_options = path_config.get("options", {})

                        if not "module" in path_config:
                            raise ApplicationError("crossbar.error.invalid_configuration", "missing module")

                        if not "object" in path_config:
                            raise ApplicationError("crossbar.error.invalid_configuration", "missing object")
开发者ID:rogererens,项目名称:crossbar,代码行数:32,代码来源:router.py


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