當前位置: 首頁>>代碼示例>>Python>>正文


Python zlib.error方法代碼示例

本文整理匯總了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 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:19,代碼來源:response.py

示例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 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:20,代碼來源:response.py

示例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 
開發者ID:danielecook,項目名稱:gist-alfred,代碼行數:23,代碼來源:response.py

示例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 
開發者ID:danielecook,項目名稱:gist-alfred,代碼行數:19,代碼來源:response.py

示例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 
開發者ID:HDFGroup,項目名稱:hsds,代碼行數:23,代碼來源:storUtil.py

示例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 
開發者ID:HDFGroup,項目名稱:hsds,代碼行數:23,代碼來源:storUtil.py

示例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 
開發者ID:HDFGroup,項目名稱:hsds,代碼行數:23,代碼來源:storUtil.py

示例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() 
開發者ID:CRS-support,項目名稱:ftw,代碼行數:19,代碼來源:http.py

示例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 
開發者ID:remg427,項目名稱:misp42splunk,代碼行數:24,代碼來源:__init__.py

示例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 
開發者ID:remg427,項目名稱:misp42splunk,代碼行數:24,代碼來源:__init__.py


注:本文中的zlib.error方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。