當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。