當前位置: 首頁>>代碼示例>>Python>>正文


Python resource.IResource方法代碼示例

本文整理匯總了Python中twisted.web.resource.IResource方法的典型用法代碼示例。如果您正苦於以下問題:Python resource.IResource方法的具體用法?Python resource.IResource怎麽用?Python resource.IResource使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在twisted.web.resource的用法示例。


在下文中一共展示了resource.IResource方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _authorizedResource

# 需要導入模塊: from twisted.web import resource [as 別名]
# 或者: from twisted.web.resource import IResource [as 別名]
def _authorizedResource(self, request):
        """
        Get the L{IResource} which the given request is authorized to receive.
        If the proper authorization headers are present, the resource will be
        requested from the portal.  If not, an anonymous login attempt will be
        made.
        """
        authheader = request.getHeader(b'authorization')
        if not authheader:
            return util.DeferredResource(self._login(Anonymous()))

        factory, respString = self._selectParseHeader(authheader)
        if factory is None:
            return UnauthorizedResource(self._credentialFactories)
        try:
            credentials = factory.decode(respString, request)
        except error.LoginFailed:
            return UnauthorizedResource(self._credentialFactories)
        except:
            log.err(None, "Unexpected failure from credentials factory")
            return ErrorPage(500, None, None)
        else:
            return util.DeferredResource(self._login(credentials)) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:25,代碼來源:wrapper.py

示例2: test_getChildWithDefaultAuthorized

# 需要導入模塊: from twisted.web import resource [as 別名]
# 或者: from twisted.web.resource import IResource [as 別名]
def test_getChildWithDefaultAuthorized(self):
        """
        Resource traversal which encounters an L{HTTPAuthSessionWrapper}
        results in an L{IResource} which renders the L{IResource} avatar
        retrieved from the portal when the request has a valid I{Authorization}
        header.
        """
        self.credentialFactories.append(BasicCredentialFactory('example.com'))
        request = self.makeRequest([self.childName])
        child = self._authorizedBasicLogin(request)
        d = request.notifyFinish()
        def cbFinished(ignored):
            self.assertEqual(request.written, [self.childContent])
        d.addCallback(cbFinished)
        request.render(child)
        return d 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:18,代碼來源:test_httpauth.py

示例3: _authorizedResource

# 需要導入模塊: from twisted.web import resource [as 別名]
# 或者: from twisted.web.resource import IResource [as 別名]
def _authorizedResource(self, request):
        """
        Get the L{IResource} which the given request is authorized to receive.
        If the proper authorization headers are present, the resource will be
        requested from the portal.  If not, an anonymous login attempt will be
        made.
        """
        authheader = request.getHeader(b'authorization')
        if not authheader:
            return util.DeferredResource(self._login(Anonymous()))

        factory, respString = self._selectParseHeader(authheader)
        if factory is None:
            return UnauthorizedResource(self._credentialFactories)
        try:
            credentials = factory.decode(respString, request)
        except error.LoginFailed:
            return UnauthorizedResource(self._credentialFactories)
        except:
            self._log.failure("Unexpected failure from credentials factory")
            return ErrorPage(500, None, None)
        else:
            return util.DeferredResource(self._login(credentials)) 
開發者ID:wistbean,項目名稱:learn_python3_spider,代碼行數:25,代碼來源:wrapper.py

示例4: test_renderAuthorized

# 需要導入模塊: from twisted.web import resource [as 別名]
# 或者: from twisted.web.resource import IResource [as 別名]
def test_renderAuthorized(self):
        """
        Resource traversal which terminates at an L{HTTPAuthSessionWrapper}
        and includes correct authentication headers results in the
        L{IResource} avatar (not one of its children) retrieved from the
        portal being rendered.
        """
        self.credentialFactories.append(BasicCredentialFactory('example.com'))
        # Request it exactly, not any of its children.
        request = self.makeRequest([])
        child = self._authorizedBasicLogin(request)
        d = request.notifyFinish()
        def cbFinished(ignored):
            self.assertEqual(request.written, [self.avatarContent])
        d.addCallback(cbFinished)
        request.render(child)
        return d 
開發者ID:wistbean,項目名稱:learn_python3_spider,代碼行數:19,代碼來源:test_httpauth.py

示例5: _authorizedResource

# 需要導入模塊: from twisted.web import resource [as 別名]
# 或者: from twisted.web.resource import IResource [as 別名]
def _authorizedResource(self, request):
        """
        Get the L{IResource} which the given request is authorized to receive.
        If the proper authorization headers are present, the resource will be
        requested from the portal.  If not, an anonymous login attempt will be
        made.
        """
        authheader = request.getHeader('authorization')
        if not authheader:
            return util.DeferredResource(self._login(Anonymous()))

        factory, respString = self._selectParseHeader(authheader)
        if factory is None:
            return UnauthorizedResource(self._credentialFactories)
        try:
            credentials = factory.decode(respString, request)
        except error.LoginFailed:
            return UnauthorizedResource(self._credentialFactories)
        except:
            log.err(None, "Unexpected failure from credentials factory")
            return ErrorPage(500, None, None)
        else:
            return util.DeferredResource(self._login(credentials)) 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:25,代碼來源:wrapper.py

示例6: test_getChildWithDefaultAuthorized

# 需要導入模塊: from twisted.web import resource [as 別名]
# 或者: from twisted.web.resource import IResource [as 別名]
def test_getChildWithDefaultAuthorized(self):
        """
        Resource traversal which encounters an L{HTTPAuthSessionWrapper}
        results in an L{IResource} which renders the L{IResource} avatar
        retrieved from the portal when the request has a valid I{Authorization}
        header.
        """
        self.credentialFactories.append(BasicCredentialFactory('example.com'))
        request = self.makeRequest([self.childName])
        child = self._authorizedBasicLogin(request)
        d = request.notifyFinish()
        def cbFinished(ignored):
            self.assertEquals(request.written, [self.childContent])
        d.addCallback(cbFinished)
        request.render(child)
        return d 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:18,代碼來源:test_httpauth.py

示例7: test_renderAuthorized

# 需要導入模塊: from twisted.web import resource [as 別名]
# 或者: from twisted.web.resource import IResource [as 別名]
def test_renderAuthorized(self):
        """
        Resource traversal which terminates at an L{HTTPAuthSessionWrapper}
        and includes correct authentication headers results in the
        L{IResource} avatar (not one of its children) retrieved from the
        portal being rendered.
        """
        self.credentialFactories.append(BasicCredentialFactory('example.com'))
        # Request it exactly, not any of its children.
        request = self.makeRequest([])
        child = self._authorizedBasicLogin(request)
        d = request.notifyFinish()
        def cbFinished(ignored):
            self.assertEquals(request.written, [self.avatarContent])
        d.addCallback(cbFinished)
        request.render(child)
        return d 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:19,代碼來源:test_httpauth.py

示例8: _login

# 需要導入模塊: from twisted.web import resource [as 別名]
# 或者: from twisted.web.resource import IResource [as 別名]
def _login(self, credentials, request):
        pattern = re.compile("^/sandbox/")

        def loginSucceeded(args):
            interface, avatar, logout = args
            if avatar == checkers.ANONYMOUS and not pattern.match(request.path):
                return self._anonymous_resource
            else:
                return self._root_resource

        def loginFailed(result):
            if result.check(error.Unauthorized, error.LoginFailed):
                return UnauthorizedResource(self._credentialFactories)
            else:
                log.err(
                    result,
                    "HTTPAuthSessionWrapper.getChildWithDefault encountered "
                    "unexpected error")
                return ErrorPage(500, None, None)

        d = self._portal.login(credentials, None, IResource)
        d.addCallbacks(loginSucceeded, loginFailed)
        return d 
開發者ID:pixelated,項目名稱:pixelated-user-agent,代碼行數:25,代碼來源:auth.py

示例9: requestAvatar

# 需要導入模塊: from twisted.web import resource [as 別名]
# 或者: from twisted.web.resource import IResource [as 別名]
def requestAvatar(self, user, mind, *interfaces):
        # the resource is passed on regardless of user
        if IResource in interfaces:
            return (IResource, self.resource, lambda: None)
        raise NotImplementedError() 
開發者ID:leapcode,項目名稱:bitmask-dev,代碼行數:7,代碼來源:_auth.py

示例10: getChildWithDefault

# 需要導入模塊: from twisted.web import resource [as 別名]
# 或者: from twisted.web.resource import IResource [as 別名]
def getChildWithDefault(self, name, request):
        """
        Reject attempts to retrieve a child resource.  All path segments beyond
        the one which refers to this resource are handled by the WSGI
        application object.
        """
        raise RuntimeError("Cannot get IResource children from WSGIResource") 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:9,代碼來源:wsgi.py

示例11: putChild

# 需要導入模塊: from twisted.web import resource [as 別名]
# 或者: from twisted.web.resource import IResource [as 別名]
def putChild(self, path, child):
        """
        Reject attempts to add a child resource to this resource.  The WSGI
        application object handles all path segments beneath this resource, so
        L{IResource} children can never be found.
        """
        raise RuntimeError("Cannot put IResource children under WSGIResource") 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:9,代碼來源:wsgi.py

示例12: render

# 需要導入模塊: from twisted.web import resource [as 別名]
# 或者: from twisted.web.resource import IResource [as 別名]
def render(self, request):
        """
        Find the L{IResource} avatar suitable for the given request, if
        possible, and render it.  Otherwise, perhaps render an error page
        requiring authorization or describing an internal server failure.
        """
        return self._authorizedResource(request).render(request) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:9,代碼來源:wrapper.py

示例13: _login

# 需要導入模塊: from twisted.web import resource [as 別名]
# 或者: from twisted.web.resource import IResource [as 別名]
def _login(self, credentials):
        """
        Get the L{IResource} avatar for the given credentials.

        @return: A L{Deferred} which will be called back with an L{IResource}
            avatar or which will errback if authentication fails.
        """
        d = self._portal.login(credentials, None, IResource)
        d.addCallbacks(self._loginSucceeded, self._loginFailed)
        return d 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:12,代碼來源:wrapper.py

示例14: getChild

# 需要導入模塊: from twisted.web import resource [as 別名]
# 或者: from twisted.web.resource import IResource [as 別名]
def getChild(self, path, request):
        """
        If this L{File}'s path refers to a directory, return a L{File}
        referring to the file named C{path} in that directory.

        If C{path} is the empty string, return a L{DirectoryLister} instead.
        """
        self.restat(reraise=False)

        if not self.isdir():
            return self.childNotFound

        if path:
            try:
                fpath = self.child(path)
            except filepath.InsecurePath:
                return self.childNotFound
        else:
            fpath = self.childSearchPreauth(*self.indexNames)
            if fpath is None:
                return self.directoryListing()

        if not fpath.exists():
            fpath = fpath.siblingExtensionSearch(*self.ignoredExts)
            if fpath is None:
                return self.childNotFound

        if platformType == "win32":
            # don't want .RPY to be different than .rpy, since that would allow
            # source disclosure.
            processor = InsensitiveDict(self.processors).get(fpath.splitext()[1])
        else:
            processor = self.processors.get(fpath.splitext()[1])
        if processor:
            return resource.IResource(processor(fpath.path, self.registry))
        return self.createSimilarFile(fpath.path)


    # methods to allow subclasses to e.g. decrypt files on the fly: 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:41,代碼來源:static.py

示例15: test_interface

# 需要導入模塊: from twisted.web import resource [as 別名]
# 或者: from twisted.web.resource import IResource [as 別名]
def test_interface(self):
        """
        L{UserDirectory} instances provide L{resource.IResource}.
        """
        self.assertTrue(verifyObject(resource.IResource, self.directory)) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:7,代碼來源:test_distrib.py


注:本文中的twisted.web.resource.IResource方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。