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


Python File.getChild方法代码示例

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


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

示例1: getChild

# 需要导入模块: from twisted.web.static import File [as 别名]
# 或者: from twisted.web.static.File import getChild [as 别名]
 def getChild(self, path, request):
    resource = File.getChild(self, path, request)
    for pat, repl in self._virtualLinks.iteritems():
       newPath = pat.sub(repl, path)
       if newPath != path:
          resource = File.getChild(self, newPath, request)
          break
    return resource
开发者ID:istobran,项目名称:eaEmu,代码行数:10,代码来源:webServices.py

示例2: SubdirectoryContexts

# 需要导入模块: from twisted.web.static import File [as 别名]
# 或者: from twisted.web.static.File import getChild [as 别名]
class SubdirectoryContexts(Resource):
    def __init__(self, dbrootdir="db", webdir="www/command", landingdir="www/landing"):
        self.dbrootdir = dbrootdir
        self.webdir = webdir

        self.file_resource = File(landingdir)

        Resource.__init__(self)

    def getChild(self, name, request):

        if request.method == "GET":
            # Let's assume that all file are either empty (-> index.html) or have a period in them.
            if len(name) == 0 or "." in name:
                return self.file_resource.getChild(name, request)

            else:
                print 'making db', name

                dbdir = os.path.join(self.dbrootdir, name)

                subdir_resources = {}

                dbfactory = CommandDatabase(dbdir, subdir_resources)
                dbfactory.protocol = minidb.DBProtocol
                dbws_resource = WebSocketResource(dbfactory)
                subdir_resources['db'] = dbfactory

                factory = AudioConferenceFactory(subdir_resources, dbdir, dbfactory)
                factory.protocol = AudioConferenceProtocol
                ws_resource = WebSocketResource(factory)
                subdir_resources['factory'] = factory

                attachdir = os.path.join(dbdir, "_attachments")
                attach = TranscodingAttachFactory(factory, dbfactory, attachdir=attachdir)
                attach.protocol = attachments.AttachProtocol
                subdir_resources['attach'] = attach

                attachhttp = File(attachdir)
                attws_resource = WebSocketResource(attach)

                zipper = DBZipper(dbfactory)

                root = File(self.webdir)
                dbhttp = File(dbdir)                
                root.putChild('_ws', ws_resource)
                root.putChild('_db', dbws_resource)
                root.putChild('_attach', attws_resource)
                root.putChild('db', dbhttp)
                root.putChild('attachments', attachhttp)
                root.putChild('download.zip', zipper)

                self.putChild(name, root)
                return root

        return Resource.getChild(self, name, request)
开发者ID:lowerquality,项目名称:earmark,代码行数:58,代码来源:serve.py

示例3: getChild

# 需要导入模块: from twisted.web.static import File [as 别名]
# 或者: from twisted.web.static.File import getChild [as 别名]
 def getChild(self, name, request):
     versionString = 'phoenix/%s' % self.core.VERSION
     request.setHeader('Server', versionString)
     if request.method == 'POST' and request.path == '/':
         return self
     else:
         docroot = os.path.join(self.core.basedir, 'www')
         root = File(self.core.config.get('web', 'root', str, docroot))
         root.processors = {'.rpy': script.ResourceScript}
         return root.getChild(name, request)
开发者ID:BlackhatEspeed,项目名称:phoenix,代码行数:12,代码来源:PhoenixRPC.py

示例4: PirateBelt

# 需要导入模块: from twisted.web.static import File [as 别名]
# 或者: from twisted.web.static.File import getChild [as 别名]
class PirateBelt(Seatbelt):
    # Piratepad-style Seatbelt variant

    # make /links go to the _rewrite url of a database that's created
    # & populated on-demand
    def __init__(self, dbdir, landing_path, ddoc_path, otherddocs=None):
        self.ddoc_path = ddoc_path
        self.otherddocs = otherddocs or []
        self.ddoc_name = "_design/%s" % (ddoc_path.split("/")[-1])
        self.file_resource = File(landing_path)
        Seatbelt.__init__(self, dbdir)

    def _serve_db(self, dbname):
        # Add the _rewrite root, instead of the db root
        self.dbs[dbname] = PARTS_BIN["Database"](self, os.path.join(self.datadir, dbname))
        # Link the ddocs
        ddoc = linkddocs(self.dbs[dbname], self.ddoc_path)
        self.putChild(dbname, ddoc.rewrite_resource)

        for odd in self.otherddocs:
            o_ddoc = linkddocs(self.dbs[dbname], odd)
            ddoc.rewrite_resource.putChild(odd.split("/")[-1], o_ddoc.rewrite_resource)

    def on_db_create(self, db):
        pass

    def getChild(self, name, request):
        _cors(request)

        if request.method == "GET":
            # Let's assume that all file are either empty (-> index.html) or have a period in them.
            if len(name) == 0 or "." in name:
                return self.file_resource.getChild(name, request)
            elif "_" in name:
                # Why *not* allow some of the db tracking APIs...
                return self
            else:
                # get_or_create db?
                db = self.create_db(name)

                self.on_db_create(db)

                # Return new ddoc _rewrite
                return db.docs[self.ddoc_name].rewrite_resource
        else:
            # Error? 
            return Resource.getChild(self, name, request)
开发者ID:lowerquality,项目名称:seatbelt,代码行数:49,代码来源:seatbelt.py

示例5: getChild

# 需要导入模块: from twisted.web.static import File [as 别名]
# 或者: from twisted.web.static.File import getChild [as 别名]
  def getChild(self, name, request):
    print(request.getClientIP() +" : in getChild : "+ str(name) +" : "+ str(request))
    # print(dir(request))
    print(str(request.getClientIP()) +" : "+ str(request.URLPath()))


    if(re.search('^/REGISTER',request.uri)):
      # p = multiprocessing.Process(target=self.saveUserDetails, args=(request,))
      # p.start()
      self.saveUserDetails(request)
      return(Registered())
    elif(re.search('^/PLAY',request.uri)):
      if(str(request.getClientIP()) in clientsAllowed.values()):
        self.savePlayDetails(request)
        return(RegisterForPlay())
      else:
        return(NotRegisterForPlay())
    elif(re.search('^/ALIVE',request.uri)):
      return(iAmAlive())
    else:
      if(str(request.getClientIP()) in clientsAllowed.values()):
        return(File.getChild(self,name,request))
      else:
        return(NotRegistered())
开发者ID:shrinidhi666,项目名称:wtfBox,代码行数:26,代码来源:webServer.py

示例6: getChild

# 需要导入模块: from twisted.web.static import File [as 别名]
# 或者: from twisted.web.static.File import getChild [as 别名]
 def getChild(self, path, request):
     child = File.getChild(self, path, request)
     return EncodingResourceWrapper(child, [GzipEncoderFactory()])
开发者ID:howethomas,项目名称:synapse,代码行数:5,代码来源:homeserver.py

示例7: getChild

# 需要导入模块: from twisted.web.static import File [as 别名]
# 或者: from twisted.web.static.File import getChild [as 别名]
 def getChild(self, name, request):
     _cors(request)
     return File.getChild(self, name, request)
开发者ID:lowerquality,项目名称:seatbelt,代码行数:5,代码来源:seatbelt.py

示例8: unsubscribe

# 需要导入模块: from twisted.web.static import File [as 别名]
# 或者: from twisted.web.static.File import getChild [as 别名]
    
    def unsubscribe(self, p, channel):
        if channel in self.channels:
            self.channels[channel].remove(p)
            if not self.channels[channel]:
                del self.channels[channel]
    
    def publish(self, channel, message, error=False):
        if channel in self.channels:
            for p in self.channels[channel]:
                if error:
                    p.errorReceived(channel, message)
                else:
                    p.messageReceived(channel, message)

# Start the party
shutil.rmtree("./tmp")
os.mkdir("./tmp")

index_page = File("index.html")
index_page.putChild("sockjs", SockJSResource(TumblrServer()))
index_page.putChild("archives", File("archives"))

from functools import partial
def bypass(self, path, request):
    return self
index_page.getChild = partial(bypass, index_page)

def resource():
    return index_page
开发者ID:Fugiman,项目名称:Tumblr-Backup,代码行数:32,代码来源:server.py

示例9: RootPage

# 需要导入模块: from twisted.web.static import File [as 别名]
# 或者: from twisted.web.static.File import getChild [as 别名]
class RootPage(Resource):
    isLeaf = True

    def __init__(self, validator):
        Resource.__init__(self)
        self.Ledger = validator.Ledger
        self.Validator = validator
        self.ps = PlatformStats()

        self.GetPageMap = {
            'block': self._handle_blk_request,
            'statistics': self._handle_stat_request,
            'store': self._handle_store_request,
            'transaction': self._handle_txn_request,
            'status': self._hdl_status_request,
        }

        self.PostPageMap = {
            'default': self._msg_forward,
            'forward': self._msg_forward,
            'initiate': self._msg_initiate,
            'command': self._do_command,
            'echo': self._msg_echo
        }

        static_dir = os.path.join(
            os.path.dirname(os.path.abspath(__file__)), "static_content")
        self.static_content = File(static_dir)

    def error_response(self, request, response, *msgargs):
        """
        Generate a common error response for broken requests
        """
        request.setResponseCode(response)

        msg = msgargs[0].format(*msgargs[1:])
        if response > 400:
            logger.warn(msg)
        elif response > 300:
            logger.debug(msg)

        return "" if request.method == 'HEAD' else (msg + '\n')

    def errback(self, failure, request):
        failure.printTraceback()
        request.processingFailed(failure)
        return None

    def do_get(self, request):
        """
        Handle a GET request on the HTTP interface. Three paths are accepted:
            /store[/<storename>[/<key>|*]]
            /block[/<blockid>]
            /transaction[/<txnid>]
        """
        # pylint: disable=invalid-name

        # split the request path removing leading duplicate slashes
        components = request.path.split('/')
        while components and components[0] == '':
            components.pop(0)

        prefix = components.pop(0) if components else 'error'

        if prefix not in self.GetPageMap:
            # attempt to serve static content if present.
            resource = self.static_content.getChild(request.path[1:], request)
            return resource.render(request)

        test_only = (request.method == 'HEAD')

        try:
            response = self.GetPageMap[prefix](components, request.args,
                                               test_only)
            if test_only:
                return ''

            cbor = (request.getHeader('Accept') == 'application/cbor')

            if cbor:
                request.responseHeaders.addRawHeader(b"content-type",
                                                     b"application/cbor")
                return dict2cbor(response)

            request.responseHeaders.addRawHeader(b"content-type",
                                                 b"application/json")

            pretty = 'p' in request.args
            if pretty:
                result = pretty_print_dict(response) + '\n'
            else:
                result = dict2json(response)

            return result

        except Error as e:
            return self.error_response(
                request, int(e.status),
                'exception while processing http request {0}; {1}',
                request.path, str(e))
#.........这里部分代码省略.........
开发者ID:hopkinwang,项目名称:sawtooth-validator,代码行数:103,代码来源:web_api.py

示例10: getChild

# 需要导入模块: from twisted.web.static import File [as 别名]
# 或者: from twisted.web.static.File import getChild [as 别名]
 def getChild(self, path, request):
     return File.getChild(self, path, request)
开发者ID:aircable,项目名称:AIRi,代码行数:4,代码来源:jinja.py


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