本文整理汇总了Python中httplib.HTTPResponse.msg['content-encoding']方法的典型用法代码示例。如果您正苦于以下问题:Python HTTPResponse.msg['content-encoding']方法的具体用法?Python HTTPResponse.msg['content-encoding']怎么用?Python HTTPResponse.msg['content-encoding']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类httplib.HTTPResponse
的用法示例。
在下文中一共展示了HTTPResponse.msg['content-encoding']方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: send_and_recv
# 需要导入模块: from httplib import HTTPResponse [as 别名]
# 或者: from httplib.HTTPResponse import msg['content-encoding'] [as 别名]
def send_and_recv(self):
try:
# because www.dream-pro.info is tlanslated to 127.0.0.1 using hosts' entry,
# send message to www.dream-pro.info with socket.socket to make
# http connection
sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
sock.connect((WWW_DREAM_PRO_INFO,80))
sock.sendall(str(self))
except:
print 'SocketError'
return
res = HTTPResponse(sock)
res.begin()
res_body = res.read()
res.close()
if 'transfer-encoding' in res.msg:
# httplib.HTTPResponse automatically concatenate chunked response
# but do not delete 'transfer-encoding' header
# so the header must be deleted
res.msg.__delitem__('transfer-encoding')
compmeth = res.msg.getheader('content-encoding','').lower()
if compmeth and compmeth.find('identity') != 0 :
# response body is compressed with some method
offset = 0
if compmeth.find('gzip') != -1:
# if body is gziped, header offset value is 47
# if not, offset value is 0
# this server does not support sdch...
offset += 47
res_body = decompress(res_body,offset)
res.msg['content-encoding'] = 'identity'
return res, res_body