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


Python http.FOUND属性代码示例

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


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

示例1: test_headersAndCode

# 需要导入模块: from twisted.web import http [as 别名]
# 或者: from twisted.web.http import FOUND [as 别名]
def test_headersAndCode(self):
        """
        L{redirectTo} will set the C{Location} and C{Content-Type} headers on
        its request, and set the response code to C{FOUND}, so the browser will
        be redirected.
        """
        request = Request(DummyChannel(), True)
        request.method = b'GET'
        targetURL = b"http://target.example.com/4321"
        redirectTo(targetURL, request)
        self.assertEqual(request.code, FOUND)
        self.assertEqual(
            request.responseHeaders.getRawHeaders(b'location'), [targetURL])
        self.assertEqual(
            request.responseHeaders.getRawHeaders(b'content-type'),
            [b'text/html; charset=utf-8']) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:18,代码来源:test_util.py

示例2: outReceived

# 需要导入模块: from twisted.web import http [as 别名]
# 或者: from twisted.web.http import FOUND [as 别名]
def outReceived(self, output):
        """
        Handle a chunk of input
        """
        # First, make sure that the headers from the script are sorted
        # out (we'll want to do some parsing on these later.)
        if self.handling_headers:
            text = self.headertext + output
            headerEnds = []
            for delimiter in '\n\n','\r\n\r\n','\r\r', '\n\r\n':
                headerend = text.find(delimiter)
                if headerend != -1:
                    headerEnds.append((headerend, delimiter))
            if headerEnds:
                # The script is entirely in control of response headers; disable the
                # default Content-Type value normally provided by
                # twisted.web.server.Request.
                self.request.defaultContentType = None

                headerEnds.sort()
                headerend, delimiter = headerEnds[0]
                self.headertext = text[:headerend]
                # This is a final version of the header text.
                linebreak = delimiter[:len(delimiter)//2]
                headers = self.headertext.split(linebreak)
                for header in headers:
                    br = header.find(': ')
                    if br == -1:
                        log.msg(
                            format='ignoring malformed CGI header: %(header)r',
                            header=header)
                    else:
                        headerName = header[:br].lower()
                        headerText = header[br+2:]
                        if headerName == 'location':
                            self.request.setResponseCode(http.FOUND)
                        if headerName == 'status':
                            try:
                                statusNum = int(headerText[:3]) #"XXX <description>" sometimes happens.
                            except:
                                log.msg( "malformed status header" )
                            else:
                                self.request.setResponseCode(statusNum)
                        else:
                            # Don't allow the application to control these required headers.
                            if headerName.lower() not in ('server', 'date'):
                                self.request.responseHeaders.addRawHeader(headerName, headerText)
                output = text[headerend+len(delimiter):]
                self.handling_headers = 0
            if self.handling_headers:
                self.headertext = text
        if not self.handling_headers:
            self.request.write(output) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:55,代码来源:twcgi.py

示例3: outReceived

# 需要导入模块: from twisted.web import http [as 别名]
# 或者: from twisted.web.http import FOUND [as 别名]
def outReceived(self, output):
        """
        Handle a chunk of input
        """
        # First, make sure that the headers from the script are sorted
        # out (we'll want to do some parsing on these later.)
        if self.handling_headers:
            text = self.headertext + output
            headerEnds = []
            for delimiter in b'\n\n', b'\r\n\r\n', b'\r\r', b'\n\r\n':
                headerend = text.find(delimiter)
                if headerend != -1:
                    headerEnds.append((headerend, delimiter))
            if headerEnds:
                # The script is entirely in control of response headers;
                # disable the default Content-Type value normally provided by
                # twisted.web.server.Request.
                self.request.defaultContentType = None

                headerEnds.sort()
                headerend, delimiter = headerEnds[0]
                self.headertext = text[:headerend]
                # This is a final version of the header text.
                linebreak = delimiter[:len(delimiter)//2]
                headers = self.headertext.split(linebreak)
                for header in headers:
                    br = header.find(b': ')
                    if br == -1:
                        self._log.error(
                            'ignoring malformed CGI header: {header!r}',
                            header=header)
                    else:
                        headerName = header[:br].lower()
                        headerText = header[br+2:]
                        if headerName == b'location':
                            self.request.setResponseCode(http.FOUND)
                        if headerName == b'status':
                            try:
                                # "XXX <description>" sometimes happens.
                                statusNum = int(headerText[:3])
                            except:
                                self._log.error("malformed status header")
                            else:
                                self.request.setResponseCode(statusNum)
                        else:
                            # Don't allow the application to control
                            # these required headers.
                            if headerName.lower() not in (b'server', b'date'):
                                self.request.responseHeaders.addRawHeader(
                                    headerName, headerText)
                output = text[headerend+len(delimiter):]
                self.handling_headers = 0
            if self.handling_headers:
                self.headertext = text
        if not self.handling_headers:
            self.request.write(output) 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:58,代码来源:twcgi.py

示例4: outReceived

# 需要导入模块: from twisted.web import http [as 别名]
# 或者: from twisted.web.http import FOUND [as 别名]
def outReceived(self, output):
        """
        Handle a chunk of input
        """
        # First, make sure that the headers from the script are sorted
        # out (we'll want to do some parsing on these later.)
        if self.handling_headers:
            text = self.headertext + output
            headerEnds = []
            for delimiter in '\n\n','\r\n\r\n','\r\r', '\n\r\n':
                headerend = string.find(text,delimiter)
                if headerend != -1:
                    headerEnds.append((headerend, delimiter))
            if headerEnds:
                headerEnds.sort()
                headerend, delimiter = headerEnds[0]
                self.headertext = text[:headerend]
                # This is a final version of the header text.
                linebreak = delimiter[:len(delimiter)/2]
                headers = string.split(self.headertext, linebreak)
                for header in headers:
                    br = string.find(header,': ')
                    if br == -1:
                        log.msg( 'ignoring malformed CGI header: %s' % header )
                    else:
                        headerName = string.lower(header[:br])
                        headerText = header[br+2:]
                        if headerName == 'location':
                            self.request.setResponseCode(http.FOUND)
                        if headerName == 'status':
                            try:
                                statusNum = int(headerText[:3]) #"XXX <description>" sometimes happens.
                            except:
                                log.msg( "malformed status header" )
                            else:
                                self.request.setResponseCode(statusNum)
                        else:
                            # Don't allow the application to control these required headers.
                            if headerName.lower() not in ('server', 'date'):
                                self.request.responseHeaders.addRawHeader(headerName, headerText)
                output = text[headerend+len(delimiter):]
                self.handling_headers = 0
            if self.handling_headers:
                self.headertext = text
        if not self.handling_headers:
            self.request.write(output) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:48,代码来源:twcgi.py

示例5: outReceived

# 需要导入模块: from twisted.web import http [as 别名]
# 或者: from twisted.web.http import FOUND [as 别名]
def outReceived(self, output):
        """
        Handle a chunk of input
        """
        # First, make sure that the headers from the script are sorted
        # out (we'll want to do some parsing on these later.)
        if self.handling_headers:
            text = self.headertext + output
            headerEnds = []
            for delimiter in '\n\n','\r\n\r\n','\r\r', '\n\r\n':
                headerend = string.find(text,delimiter)
                if headerend != -1:
                    headerEnds.append((headerend, delimiter))
            if headerEnds:
                headerEnds.sort()
                headerend, delimiter = headerEnds[0]
                self.headertext = text[:headerend]
                # This is a final version of the header text.
                linebreak = delimiter[:len(delimiter)/2]
                headers = string.split(self.headertext, linebreak)
                for header in headers:
                    br = string.find(header,': ')
                    if br == -1:
                        log.msg( 'ignoring malformed CGI header: %s' % header )
                    else:
                        headerName = string.lower(header[:br])
                        headerText = header[br+2:]
                        if headerName == 'location':
                            self.request.setResponseCode(http.FOUND)
                        if headerName == 'status':
                            try:
                                statusNum = int(headerText[:3]) #"XXX <description>" sometimes happens.
                            except:
                                log.msg( "malformed status header" )
                            else:
                                self.request.setResponseCode(statusNum)
                        else:
                            self.request.setHeader(headerName,headerText)
                output = text[headerend+len(delimiter):]
                self.handling_headers = 0
            if self.handling_headers:
                self.headertext = text
        if not self.handling_headers:
            self.request.write(output) 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:46,代码来源:twcgi.py


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