本文整理匯總了Python中paste.response.HeaderDict.pop方法的典型用法代碼示例。如果您正苦於以下問題:Python HeaderDict.pop方法的具體用法?Python HeaderDict.pop怎麽用?Python HeaderDict.pop使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類paste.response.HeaderDict
的用法示例。
在下文中一共展示了HeaderDict.pop方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: WSGIResponse
# 需要導入模塊: from paste.response import HeaderDict [as 別名]
# 或者: from paste.response.HeaderDict import pop [as 別名]
#.........這裏部分代碼省略.........
Return this WSGIResponse as a tuple of WSGI formatted data, including:
(status, headers, iterable)
"""
status_text = STATUS_CODE_TEXT[self.status_code]
status = '%s %s' % (self.status_code, status_text)
response_headers = self.headers.headeritems()
for c in self.cookies.values():
response_headers.append(('Set-Cookie', c.output(header='')))
return status, response_headers, self.get_content()
# The remaining methods partially implement the file-like object interface.
# See http://docs.python.org/lib/bltin-file-objects.html
def write(self, content):
if not self._is_str_iter:
raise IOError, "This %s instance's content is not writable: (content " \
'is an iterator)' % self.__class__.__name__
self.content.append(content)
def flush(self):
pass
def tell(self):
if not self._is_str_iter:
raise IOError, 'This %s instance cannot tell its position: (content ' \
'is an iterator)' % self.__class__.__name__
return sum([len(chunk) for chunk in self._iter])
########################################
## Content-type and charset
def charset__get(self):
"""
Get/set the charset (in the Content-Type)
"""
header = self.headers.get('content-type')
if not header:
return None
match = _CHARSET_RE.search(header)
if match:
return match.group(1)
return None
def charset__set(self, charset):
if charset is None:
del self.charset
return
try:
header = self.headers.pop('content-type')
except KeyError:
raise AttributeError(
"You cannot set the charset when no content-type is defined")
match = _CHARSET_RE.search(header)
if match:
header = header[:match.start()] + header[match.end():]
header += '; charset=%s' % charset
self.headers['content-type'] = header
def charset__del(self):
try:
header = self.headers.pop('content-type')
except KeyError:
# Don't need to remove anything
return
match = _CHARSET_RE.search(header)
if match:
header = header[:match.start()] + header[match.end():]
self.headers['content-type'] = header
charset = property(charset__get, charset__set, charset__del, doc=charset__get.__doc__)
def content_type__get(self):
"""
Get/set the Content-Type header (or None), *without* the
charset or any parameters.
If you include parameters (or ``;`` at all) when setting the
content_type, any existing parameters will be deleted;
otherwise they will be preserved.
"""
header = self.headers.get('content-type')
if not header:
return None
return header.split(';', 1)[0]
def content_type__set(self, value):
if ';' not in value:
header = self.headers.get('content-type', '')
if ';' in header:
params = header.split(';', 1)[1]
value += ';' + params
self.headers['content-type'] = value
def content_type__del(self):
try:
del self.headers['content-type']
except KeyError:
pass
content_type = property(content_type__get, content_type__set,
content_type__del, doc=content_type__get.__doc__)