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


Python Site.getResourceFor方法代码示例

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


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

示例1: getResourceFor

# 需要导入模块: from twisted.web.server import Site [as 别名]
# 或者: from twisted.web.server.Site import getResourceFor [as 别名]
 def getResourceFor(self, request):
     "Fetch a resource and measure the time until it's finished writing."
     resource = Site.getResourceFor(self, request)
     now = time.time()
     request.requestHeaders.addRawHeader('X-Request-Started-At', '%0.8f' % now)
     request.notifyFinish().addBoth(self._recordRequestTime, now, request)
     self._activeRequests.add(request)
     return resource
开发者ID:charmander,项目名称:weasyl,代码行数:10,代码来源:polecat.py

示例2: getResourceFor

# 需要导入模块: from twisted.web.server import Site [as 别名]
# 或者: from twisted.web.server.Site import getResourceFor [as 别名]
	def getResourceFor(self, request):
		userpass = self.check_userpass_auth(self, request)
		if userpass == AUTH_SUCCESS:
			return PurgeAuthCredentials()

		cookie = self.check_cookie_auth(self, request)
		if cookie == AUTH_SUCCESS:
			return Site.getResourceFor(self, request)

		return RequestAuthenticationResource()
开发者ID:sporkexec,项目名称:confluence,代码行数:12,代码来源:auth.py

示例3: getResourceFor

# 需要导入模块: from twisted.web.server import Site [as 别名]
# 或者: from twisted.web.server.Site import getResourceFor [as 别名]
 def getResourceFor(self, request):
     "Fetch a resource and measure the time until it's finished writing."
     resource = Site.getResourceFor(self, request)
     if self.endpointFunc is None:
         endpoint = None
     else:
         endpoint, _ = self.endpointFunc(request.path)
     request.notifyFinish().addBoth(
         self._recordRequestTime, time.time(), endpoint, request)
     self._activeRequests.add(request)
     return resource
开发者ID:habnabit,项目名称:polecat,代码行数:13,代码来源:polecat.py

示例4: getResourceFor

# 需要导入模块: from twisted.web.server import Site [as 别名]
# 或者: from twisted.web.server.Site import getResourceFor [as 别名]
 def getResourceFor(self, request):
     # Scan well-known search paths first
     search_paths = ["build-out", "build-gen"]
     for search_path in search_paths:
         resource = self.resource
         prepath = copy.copy(request.prepath)
         postpath = copy.copy(request.postpath)
         postpath.insert(0, search_path)
         while postpath and not resource.isLeaf:
             path_element = postpath.pop(0)
             prepath.append(path_element)
             resource = resource.getChildWithDefault(path_element, request)
         if resource and not isinstance(resource, NoResource):
             return resource
     # Fallback to normal handling
     return Site.getResourceFor(self, request)
开发者ID:sushanthpy,项目名称:anvil-build,代码行数:18,代码来源:serve_command.py

示例5: getResourceFor

# 需要导入模块: from twisted.web.server import Site [as 别名]
# 或者: from twisted.web.server.Site import getResourceFor [as 别名]
    def getResourceFor(self, request):
        "Override Site so we can track active requests"
        if request.requestHeaders.hasHeader('user-agent'):
            ua = ' '.join(request.requestHeaders.getRawHeaders('user-agent'))
            print('{}: Serving request to User-Agent "{}".'.format(time.asctime(), ua))
        else:
            print('{}: Serving request with no incoming User-Agent header.'.format(time.asctime()))

        # track requsts currently being serviced, so we can nicely
        # shut them off
        self.active_requests.add(request)
        request.notifyFinish().addBoth(self._forget_request, request)

        # see if we've reached the maximum requests
        self._request_count += 1
        if self._max_requests is not None:
            if self._request_count >= self._max_requests:
                d = self.gracefully_stop()
                d.addBoth(lambda x: reactor.stop())

        # call through to parent
        return Site.getResourceFor(self, request)
开发者ID:david415,项目名称:carml,代码行数:24,代码来源:pastebin.py

示例6: getResourceFor

# 需要导入模块: from twisted.web.server import Site [as 别名]
# 或者: from twisted.web.server.Site import getResourceFor [as 别名]
 def getResourceFor(self, request):
     request.setHeader('Server', SERVER_HEADER)
     return Site.getResourceFor(self, request)
开发者ID:kevinburke,项目名称:hamms,代码行数:5,代码来源:__init__.py

示例7: getResourceFor

# 需要导入模块: from twisted.web.server import Site [as 别名]
# 或者: from twisted.web.server.Site import getResourceFor [as 别名]
 def getResourceFor(self, request):
     request.setHeader('Server', 'MUDSling/%s' % mudsling.version)
     return Site.getResourceFor(self, request)
开发者ID:joshbenner,项目名称:mudsling-restserver,代码行数:5,代码来源:plugin.py

示例8: getResourceFor

# 需要导入模块: from twisted.web.server import Site [as 别名]
# 或者: from twisted.web.server.Site import getResourceFor [as 别名]
 def getResourceFor(self, request):
     """
     Remove the server header from the response.
     """
     request.responseHeaders.removeHeader('server')
     return Site.getResourceFor(self, request)
开发者ID:Mainchains,项目名称:sawtooth-validator,代码行数:8,代码来源:web_api.py

示例9: TestClient

# 需要导入模块: from twisted.web.server import Site [as 别名]
# 或者: from twisted.web.server.Site import getResourceFor [as 别名]
class TestClient(object):
    def __init__(self, resource):
        self.site = Site(resource)

    def get(self, path_with_params, status=None):
        return self.request(path_with_params, method='GET', status=status)

    def post(self, path_with_params, content=None, content_type=None, status=None):
        return self.request(path_with_params, method='POST', content=content,
                content_type=content_type, status=status)

    def delete(self, path_with_params, status=None):
        return self.request(path_with_params, method='DELETE', status=status)

    def patch(self, path_with_params, content=None, content_type=None, status=None):
        return self.request(path_with_params, method='PATCH', content=content,
                content_type=content_type, status=None)

    def put(self, path_with_params, content=None, content_type=None, status=None):
        return self.request(path_with_params, method='PUT', content=content,
                content_type=content_type, status=status)

    def head(self, path_with_params, status=None):
        return self.request(path_with_params, method='HEAD', status=status)

    def options(self, path_with_params, status=None):
        return self.request(path_with_params, method='OPTIONS', status=status)

    @defer.inlineCallbacks
    def request(self, req_or_path_with_params, status=None, **request_kwargs):
        if isinstance(req_or_path_with_params, TestRequest):
            req = req_or_path_with_params
        else:
            path, params = self.parse_url(req_or_path_with_params)
            req = TestRequest(path, params=params, **request_kwargs)

        resp = yield self._handle_request(req)
        if status is not None:
            assert resp.status_code == status, resp.status_code
        defer.returnValue(resp)

    def _handle_request(self, request):
        ''' Resolves a test request. '''
        finished = request.notifyFinish()

        def extract_response(none):
            return TestResponse(request.responseCode or 200, request.responseHeaders,
                    ''.join(request.written))

        def _render(resource):
            result = resource.render(request)
            if isinstance(result, str):
                request.write(result)
                request.finish()
                return finished
            elif result is NOT_DONE_YET:
                return finished
            else:
                raise ValueError("Unexpected return value: %r" % (result,))

        resource_handler = self.site.getResourceFor(request)
        d = _render(resource_handler)
        d.addCallback(extract_response)
        return d

    def parse_url(self, path_with_params):
        parts = path_with_params.split('?')
        if len(parts) == 2:
            path, param_str = parts
            params = parse_qs(param_str)
        else:
            path, = parts
            params = {}
        return path, params
开发者ID:wrapp,项目名称:txwebtest,代码行数:76,代码来源:txwebtest.py

示例10: getResourceFor

# 需要导入模块: from twisted.web.server import Site [as 别名]
# 或者: from twisted.web.server.Site import getResourceFor [as 别名]
 def getResourceFor(self, request):
     request.setHeader('X-Frame-Options', 'DENY')
     request.setHeader('X-XSS-Protection', '1')
     request.setHeader('X-Content-Type-Options','nosniff')
     request.setHeader('Server', 'None')
     return Site.getResourceFor(self, request)
开发者ID:daniellowtw,项目名称:Pico,代码行数:8,代码来源:server.py

示例11: getResourceFor

# 需要导入模块: from twisted.web.server import Site [as 别名]
# 或者: from twisted.web.server.Site import getResourceFor [as 别名]
 def getResourceFor(self, request):
     request.setHeader('server',  'PYPDDemo/1.0')
     request.setHeader('cache-control: ',  'cache-control: private, max-age=0, no-cache')
     return Site.getResourceFor(self, request)
开发者ID:mlockett42,项目名称:pypddemo,代码行数:6,代码来源:pypddemo.py

示例12: getResourceFor

# 需要导入模块: from twisted.web.server import Site [as 别名]
# 或者: from twisted.web.server.Site import getResourceFor [as 别名]
 def getResourceFor(self, request):
    self.cnt += 1
    return Site.getResourceFor(self, request)
开发者ID:luodaobin,项目名称:scratchbox,代码行数:5,代码来源:server.py


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