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


Python error.PageRedirect方法代码示例

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


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

示例1: _testPageRedirectFailure

# 需要导入模块: from twisted.web import error [as 别名]
# 或者: from twisted.web.error import PageRedirect [as 别名]
def _testPageRedirectFailure(self, code, method):
        """
        When getting a redirect on an unsupported request method,
        L{client.RedirectAgent} fails with a L{ResponseFailed} error wrapping
        a L{error.PageRedirect} exception.

        @param code: HTTP status code.

        @param method: HTTP request method.
        """
        deferred = self.agent.request(method, b'http://example.com/foo')

        req, res = self.protocol.requests.pop()

        headers = http_headers.Headers()
        response = Response((b'HTTP', 1, 1), code, b'OK', headers, None)
        res.callback(response)

        fail = self.failureResultOf(deferred, client.ResponseFailed)
        fail.value.reasons[0].trap(error.PageRedirect)
        self.assertEqual(b'http://example.com/foo',
                         fail.value.reasons[0].value.location)
        self.assertEqual(code, fail.value.response.code) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:25,代码来源:test_agent.py

示例2: handleStatus_301

# 需要导入模块: from twisted.web import error [as 别名]
# 或者: from twisted.web.error import PageRedirect [as 别名]
def handleStatus_301(self):
        l = self.headers.get(b'location')
        if not l:
            self.handleStatusDefault()
            return
        url = l[0]
        if self.followRedirect:
            self.factory._redirectCount += 1
            if self.factory._redirectCount >= self.factory.redirectLimit:
                err = error.InfiniteRedirection(
                    self.status,
                    b'Infinite redirection detected',
                    location=url)
                self.factory.noPage(Failure(err))
                self.quietLoss = True
                self.transport.loseConnection()
                return

            self._completelyDone = False
            self.factory.setURL(url)

            if self.factory.scheme == b'https':
                from twisted.internet import ssl
                contextFactory = ssl.ClientContextFactory()
                reactor.connectSSL(nativeString(self.factory.host),
                                   self.factory.port,
                                   self.factory, contextFactory)
            else:
                reactor.connectTCP(nativeString(self.factory.host),
                                   self.factory.port,
                                   self.factory)
        else:
            self.handleStatusDefault()
            self.factory.noPage(
                Failure(
                    error.PageRedirect(
                        self.status, self.message, location = url)))
        self.quietLoss = True
        self.transport.loseConnection() 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:41,代码来源:client.py

示例3: _handleResponse

# 需要导入模块: from twisted.web import error [as 别名]
# 或者: from twisted.web.error import PageRedirect [as 别名]
def _handleResponse(self, response, method, uri, headers, redirectCount):
        """
        Handle the response, making another request if it indicates a redirect.
        """
        if response.code in self._redirectResponses:
            if method not in (b'GET', b'HEAD'):
                err = error.PageRedirect(response.code, location=uri)
                raise ResponseFailed([Failure(err)], response)
            return self._handleRedirect(response, method, uri, headers,
                                        redirectCount)
        elif response.code in self._seeOtherResponses:
            return self._handleRedirect(response, b'GET', uri, headers,
                                        redirectCount)
        return response 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:16,代码来源:client.py

示例4: test_noMessageValidStatus

# 需要导入模块: from twisted.web import error [as 别名]
# 或者: from twisted.web.error import PageRedirect [as 别名]
def test_noMessageValidStatus(self):
        """
        If no C{message} argument is passed to the L{PageRedirect} constructor
        and the C{code} argument is a valid HTTP status code, C{code} is mapped
        to a descriptive string to which C{message} is assigned.
        """
        e = error.PageRedirect(b"200", location=b"/foo")
        self.assertEqual(e.message, b"OK to /foo") 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:10,代码来源:test_error.py

示例5: test_noMessageValidStatusNoLocation

# 需要导入模块: from twisted.web import error [as 别名]
# 或者: from twisted.web.error import PageRedirect [as 别名]
def test_noMessageValidStatusNoLocation(self):
        """
        If no C{message} argument is passed to the L{PageRedirect} constructor
        and C{location} is also empty and the C{code} argument is a valid HTTP
        status code, C{code} is mapped to a descriptive string to which
        C{message} is assigned without trying to include an empty location.
        """
        e = error.PageRedirect(b"200")
        self.assertEqual(e.message, b"OK") 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:11,代码来源:test_error.py

示例6: test_noMessageInvalidStatusLocationExists

# 需要导入模块: from twisted.web import error [as 别名]
# 或者: from twisted.web.error import PageRedirect [as 别名]
def test_noMessageInvalidStatusLocationExists(self):
        """
        If no C{message} argument is passed to the L{PageRedirect} constructor
        and C{code} isn't a valid HTTP status code, C{message} stays L{None}.
        """
        e = error.PageRedirect(b"InvalidCode", location=b"/foo")
        self.assertEqual(e.message, None) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:9,代码来源:test_error.py

示例7: test_messageExistsNoLocation

# 需要导入模块: from twisted.web import error [as 别名]
# 或者: from twisted.web.error import PageRedirect [as 别名]
def test_messageExistsNoLocation(self):
        """
        If a C{message} argument is passed to the L{PageRedirect} constructor
        and no location is provided, C{message} doesn't try to include the
        empty location.
        """
        e = error.PageRedirect(b"200", b"My own message")
        self.assertEqual(e.message, b"My own message") 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:10,代码来源:test_error.py

示例8: test_307OnPost

# 需要导入模块: from twisted.web import error [as 别名]
# 或者: from twisted.web.error import PageRedirect [as 别名]
def test_307OnPost(self):
        """
        When getting a 307 redirect on a I{POST} request,
        L{client.RedirectAgent} fails with a L{ResponseFailed} error wrapping
        a L{error.PageRedirect} exception.
        """
        self._testPageRedirectFailure(307, b'POST') 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:9,代码来源:test_agent.py

示例9: test_301OnPost

# 需要导入模块: from twisted.web import error [as 别名]
# 或者: from twisted.web.error import PageRedirect [as 别名]
def test_301OnPost(self):
        """
        When getting a 301 redirect on a I{POST} request,
        L{client.RedirectAgent} fails with a L{ResponseFailed} error wrapping
        a L{error.PageRedirect} exception.
        """
        self._testPageRedirectFailure(301, b'POST') 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:9,代码来源:test_agent.py

示例10: test_302OnPost

# 需要导入模块: from twisted.web import error [as 别名]
# 或者: from twisted.web.error import PageRedirect [as 别名]
def test_302OnPost(self):
        """
        When getting a 302 redirect on a I{POST} request,
        L{client.RedirectAgent} fails with a L{ResponseFailed} error wrapping
        a L{error.PageRedirect} exception.
        """
        self._testPageRedirectFailure(302, b'POST') 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:9,代码来源:test_agent.py

示例11: test_isolatedFollowRedirect

# 需要导入模块: from twisted.web import error [as 别名]
# 或者: from twisted.web.error import PageRedirect [as 别名]
def test_isolatedFollowRedirect(self):
        """
        C{client.HTTPPagerGetter} instances each obey the C{followRedirect}
        value passed to the L{client.getPage} call which created them.
        """
        d1 = client.getPage(self.getURL('redirect'), followRedirect=True)
        d2 = client.getPage(self.getURL('redirect'), followRedirect=False)

        d = self.assertFailure(d2, error.PageRedirect
            ).addCallback(lambda dummy: d1)
        return d 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:13,代码来源:test_webclient.py

示例12: handleStatus_301

# 需要导入模块: from twisted.web import error [as 别名]
# 或者: from twisted.web.error import PageRedirect [as 别名]
def handleStatus_301(self):
        l = self.headers.get('location')
        if not l:
            self.handleStatusDefault()
            return
        url = l[0]
        if self.followRedirect:
            scheme, host, port, path = \
                _parse(url, defaultPort=self.transport.getPeer().port)

            self.factory._redirectCount += 1
            if self.factory._redirectCount >= self.factory.redirectLimit:
                err = error.InfiniteRedirection(
                    self.status,
                    'Infinite redirection detected',
                    location=url)
                self.factory.noPage(failure.Failure(err))
                self.quietLoss = True
                self.transport.loseConnection()
                return

            self.factory.setURL(url)

            if self.factory.scheme == 'https':
                from twisted.internet import ssl
                contextFactory = ssl.ClientContextFactory()
                reactor.connectSSL(self.factory.host, self.factory.port,
                                   self.factory, contextFactory)
            else:
                reactor.connectTCP(self.factory.host, self.factory.port,
                                   self.factory)
        else:
            self.handleStatusDefault()
            self.factory.noPage(
                failure.Failure(
                    error.PageRedirect(
                        self.status, self.message, location = url)))
        self.quietLoss = True
        self.transport.loseConnection() 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:41,代码来源:client.py

示例13: test_noMessageValidStatus

# 需要导入模块: from twisted.web import error [as 别名]
# 或者: from twisted.web.error import PageRedirect [as 别名]
def test_noMessageValidStatus(self):
        """
        If no C{message} argument is passed to the L{PageRedirect} constructor
        and the C{code} argument is a valid HTTP status code, C{code} is mapped
        to a descriptive string to which C{message} is assigned.
        """
        e = error.PageRedirect("200", location="/foo")
        self.assertEquals(e.message, "OK to /foo") 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:10,代码来源:test_error.py

示例14: test_noMessageValidStatusNoLocation

# 需要导入模块: from twisted.web import error [as 别名]
# 或者: from twisted.web.error import PageRedirect [as 别名]
def test_noMessageValidStatusNoLocation(self):
        """
        If no C{message} argument is passed to the L{PageRedirect} constructor
        and C{location} is also empty and the C{code} argument is a valid HTTP
        status code, C{code} is mapped to a descriptive string to which
        C{message} is assigned without trying to include an empty location.
        """
        e = error.PageRedirect("200")
        self.assertEquals(e.message, "OK") 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:11,代码来源:test_error.py

示例15: test_noMessageInvalidStatusLocationExists

# 需要导入模块: from twisted.web import error [as 别名]
# 或者: from twisted.web.error import PageRedirect [as 别名]
def test_noMessageInvalidStatusLocationExists(self):
        """
        If no C{message} argument is passed to the L{PageRedirect} constructor
        and C{code} isn't a valid HTTP status code, C{message} stays C{None}.
        """
        e = error.PageRedirect("InvalidCode", location="/foo")
        self.assertEquals(e.message, None) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:9,代码来源:test_error.py


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