本文整理汇总了Python中zlib.error方法的典型用法代码示例。如果您正苦于以下问题:Python zlib.error方法的具体用法?Python zlib.error怎么用?Python zlib.error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类zlib
的用法示例。
在下文中一共展示了zlib.error方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: decompress
# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import error [as 别名]
def decompress(self, data):
if not data:
return data
if not self._first_try:
return self._obj.decompress(data)
self._data += data
try:
return self._obj.decompress(data)
except zlib.error:
self._first_try = False
self._obj = zlib.decompressobj(-zlib.MAX_WBITS)
try:
return self.decompress(self._data)
finally:
self._data = None
示例2: _decode
# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import error [as 别名]
def _decode(self, data, decode_content, flush_decoder):
"""
Decode the data passed in and potentially flush the decoder.
"""
try:
if decode_content and self._decoder:
data = self._decoder.decompress(data)
except (IOError, zlib.error) as e:
content_encoding = self.headers.get('content-encoding', '').lower()
raise DecodeError(
"Received response with content-encoding: %s, but "
"failed to decode it." % content_encoding, e)
if flush_decoder and decode_content and self._decoder:
buf = self._decoder.decompress(binary_type())
data += buf + self._decoder.flush()
return data
示例3: decompress
# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import error [as 别名]
def decompress(self, data):
if not data:
return data
if not self._first_try:
return self._obj.decompress(data)
self._data += data
try:
decompressed = self._obj.decompress(data)
if decompressed:
self._first_try = False
self._data = None
return decompressed
except zlib.error:
self._first_try = False
self._obj = zlib.decompressobj(-zlib.MAX_WBITS)
try:
return self.decompress(self._data)
finally:
self._data = None
示例4: _decode
# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import error [as 别名]
def _decode(self, data, decode_content, flush_decoder):
"""
Decode the data passed in and potentially flush the decoder.
"""
try:
if decode_content and self._decoder:
data = self._decoder.decompress(data)
except (IOError, zlib.error) as e:
content_encoding = self.headers.get('content-encoding', '').lower()
raise DecodeError(
"Received response with content-encoding: %s, but "
"failed to decode it." % content_encoding, e)
if flush_decoder and decode_content:
data += self._flush_decoder()
return data
示例5: getStorJSONObj
# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import error [as 别名]
def getStorJSONObj(app, key, bucket=None):
""" Get object identified by key and read as JSON
"""
client = _getStorageClient(app)
if not bucket:
bucket = app['bucket_name']
if key[0] == '/':
key = key[1:] # no leading slash
log.info(f"getStorJSONObj({bucket})/{key}")
data = await client.get_object(key, bucket=bucket)
try:
json_dict = json.loads(data.decode('utf8'))
except UnicodeDecodeError:
log.error(f"Error loading JSON at key: {key}")
raise HTTPInternalServerError()
log.debug(f"storage key {key} returned: {json_dict}")
return json_dict
示例6: getStorObjStats
# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import error [as 别名]
def getStorObjStats(app, key, bucket=None):
""" Return etag, size, and last modified time for given object
"""
# TBD - will need to be refactored to handle azure responses
client = _getStorageClient(app)
if not bucket:
bucket = app['bucket_name']
stats = {}
if key[0] == '/':
#key = key[1:] # no leading slash
msg = f"key with leading slash: {key}"
log.error(msg)
raise KeyError(msg)
log.info(f"getStorObjStats({key}, bucket={bucket})")
stats = await client.get_key_stats(key, bucket=bucket)
return stats
示例7: getStorJSONObj
# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import error [as 别名]
def getStorJSONObj(app, key, bucket=None):
""" Get object identified by key and read as JSON
"""
client = _getStorageClient(app)
if not bucket:
bucket = app['bucket_name']
if key[0] == '/':
key = key[1:] # no leading slash
log.info(f"getStorJSONObj({bucket})/{key}")
data = client.get_object(key, bucket=bucket)
try:
json_dict = json.loads(data.decode('utf8'))
except UnicodeDecodeError:
log.error(f"Error loading JSON at key: {key}")
raise KeyError()
log.debug(f"storage key {key} returned: {json_dict}")
return json_dict
示例8: send_request
# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import error [as 别名]
def send_request(self, http_request):
"""
Send a request and get response
"""
self.request_object = http_request
self.build_socket()
self.build_request()
try:
self.sock.send(self.request)
except socket.error as err:
raise errors.TestError(
'We were unable to send the request to the socket',
{
'msg': err,
'function': 'http.HttpUA.send_request'
})
self.get_response()
示例9: _decompressContent
# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import error [as 别名]
def _decompressContent(response, new_content):
content = new_content
try:
encoding = response.get("content-encoding", None)
if encoding in ["gzip", "deflate"]:
if encoding == "gzip":
content = gzip.GzipFile(fileobj=io.BytesIO(new_content)).read()
if encoding == "deflate":
content = zlib.decompress(content, -zlib.MAX_WBITS)
response["content-length"] = str(len(content))
# Record the historical presence of the encoding in a way the won't interfere.
response["-content-encoding"] = response["content-encoding"]
del response["content-encoding"]
except (IOError, zlib.error):
content = ""
raise FailedToDecompressContent(
_("Content purported to be compressed with %s but failed to decompress.")
% response.get("content-encoding"),
response,
content,
)
return content
示例10: _decompressContent
# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import error [as 别名]
def _decompressContent(response, new_content):
content = new_content
try:
encoding = response.get("content-encoding", None)
if encoding in ["gzip", "deflate"]:
if encoding == "gzip":
content = gzip.GzipFile(fileobj=StringIO.StringIO(new_content)).read()
if encoding == "deflate":
content = zlib.decompress(content, -zlib.MAX_WBITS)
response["content-length"] = str(len(content))
# Record the historical presence of the encoding in a way the won't interfere.
response["-content-encoding"] = response["content-encoding"]
del response["content-encoding"]
except (IOError, zlib.error):
content = ""
raise FailedToDecompressContent(
_("Content purported to be compressed with %s but failed to decompress.")
% response.get("content-encoding"),
response,
content,
)
return content