本文整理匯總了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'])
示例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)
示例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)
示例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)
示例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)