示例#1
0
class decompressobj:
    # all jython uses wbits for is deciding whether to skip the header if it's negative
    def __init__(self, wbits=MAX_WBITS):
        if abs(wbits) > MAX_WBITS or abs(wbits) < 8:
            raise ValueError, "Invalid initialization option"
        self.inflater = Inflater(wbits < 0)
        self.unused_data = ""
        self._ended = False

    def decompress(self, string, max_length=0):
        if self._ended:
            raise error("decompressobj may not be used after flush()")

        # unused_data is always "" until inflation is finished; then it is
        # the unused bytes of the input;
        # unconsumed_tail is whatever input was not used because max_length
        # was exceeded before inflation finished.
        # Thus, at most one of {unused_data, unconsumed_tail} may be non-empty.
        self.unused_data = ""
        self.unconsumed_tail = ""

        if max_length < 0:
            raise ValueError("max_length must be a positive integer")

        string = _to_input(string)
        self.inflater.setInput(string)
        inflated = _get_inflate_data(self.inflater, max_length)

        r = self.inflater.getRemaining()
        if r:
            if max_length:
                self.unconsumed_tail = string[-r:]
            else:
                self.unused_data = string[-r:]

        return inflated

    def flush(self, length=None):
        if self._ended:
            raise error("decompressobj may not be used after flush()")
        if length is None:
            length = 0
        elif length <= 0:
            raise ValueError('length must be greater than zero')
        last = _get_inflate_data(self.inflater, length)
        self.inflater.end()
        return last
示例#2
0
文件: zlib.py 项目: loy2000/Ghidra
    def __init__(self, wbits=MAX_WBITS):

        # Jython only uses wbits to determine to skip the header if it's negative;
        # but apparently there are some tests around this that we do some bogus
        # param checking

        if abs(wbits) < 8:
            raise ValueError, "Invalid initialization option"
        if abs(wbits) > 16:  # NOTE apparently this also implies being negative in CPython/zlib
            wbits = -1

        self.inflater = Inflater(wbits < 0)
        self._ended = False
        self.unused_data = ""
        self.unconsumed_tail = ""
        self.gzip = wbits < 0
        self.gzip_header_skipped = False
示例#3
0
文件: zlib.py 项目: loy2000/Ghidra
def decompress(string, wbits=0, bufsize=16384):
    inflater = Inflater(wbits < 0)
    try:
        inflater.setInput(_to_input(string))
        data = _get_inflate_data(inflater)
        if not inflater.finished():
            raise error, "Error -5 while decompressing data: incomplete or truncated stream"
        return data
    finally:
        inflater.end()
示例#4
0
def decompress(string, wbits=0, bufsize=16384):
    inflater = Inflater(wbits < 0)
    try:
        inflater.setInput(_to_input(string))
        return _get_inflate_data(inflater)
    finally:
        inflater.end()
示例#5
0
 def __init__(self, wbits=MAX_WBITS):
     if abs(wbits) > MAX_WBITS or abs(wbits) < 8:
         raise ValueError, "Invalid initialization option"
     self.inflater = Inflater(wbits < 0)
     self.unused_data = ""
     self._ended = False
示例#6
0
def decompress(string, wbits=0, bufsize=16384):
    inflater = Inflater(wbits < 0)
    inflater.setInput(string)

    return _get_inflate_data(inflater)
示例#7
0
class decompressobj(object):
    def __init__(self, wbits=MAX_WBITS):

        # Jython only uses wbits to determine to skip the header if it's negative;
        # but apparently there are some tests around this that we do some bogus
        # param checking

        if abs(wbits) < 8:
            raise ValueError, "Invalid initialization option"
        if abs(
                wbits
        ) > 16:  # NOTE apparently this also implies being negative in CPython/zlib
            wbits = -1

        self.inflater = Inflater(wbits < 0)
        self._ended = False
        self.unused_data = ""
        self.unconsumed_tail = ""
        self.gzip = wbits < 0
        self.gzip_header_skipped = False

    def decompress(self, string, max_length=0):
        if self._ended:
            raise error("decompressobj may not be used after flush()")

        # unused_data is always "" until inflation is finished; then it is
        # the unused bytes of the input;
        # unconsumed_tail is whatever input was not used because max_length
        # was exceeded before inflation finished.
        # Thus, at most one of {unused_data, unconsumed_tail} may be non-empty.
        self.unused_data = ""
        self.unconsumed_tail = ""

        if max_length < 0:
            raise ValueError("max_length must be a positive integer")

        # Suppress gzip header if present and wbits < 0
        if self.gzip and not self.gzip_header_skipped:
            string = _skip_gzip_header(string)
            self.gzip_header_skipped = True

        string = _to_input(string)

        self.inflater.setInput(string)
        inflated = _get_inflate_data(self.inflater, max_length)

        r = self.inflater.getRemaining()
        if r:
            if max_length:
                self.unconsumed_tail = string[-r:]
            else:
                self.unused_data = string[-r:]

        return inflated

    def flush(self, length=None):
        # FIXME close input streams if gzip
        if self._ended:
            raise error("decompressobj may not be used after flush()")
        if length is None:
            length = 0
        elif length <= 0:
            raise ValueError('length must be greater than zero')
        last = _get_inflate_data(self.inflater, length)
        self.inflater.end()
        return last
示例#8
0
文件: zlib.py 项目: babble/babble
def decompress(string, wbits=0, bufsize=16384):
    inflater = Inflater(wbits < 0)
    inflater.setInput(string)
    return _get_inflate_data(inflater)
示例#9
0
文件: zlib.py 项目: Stewori/jython
class decompressobj(object):

    def __init__(self, wbits=MAX_WBITS):

        # Jython only uses wbits to determine to skip the header if it's negative;
        # but apparently there are some tests around this that we do some bogus
        # param checking

        if abs(wbits) < 8:
            raise ValueError, "Invalid initialization option"
        if abs(wbits) > 16:  # NOTE apparently this also implies being negative in CPython/zlib
            wbits = -1

        self.inflater = Inflater(wbits < 0)
        self._ended = False
        self.unused_data = ""
        self.unconsumed_tail = ""
        self.gzip = wbits < 0
        self.gzip_header_skipped = False

    def decompress(self, string, max_length=0):
        if self._ended:
            raise error("decompressobj may not be used after flush()")

        # unused_data is always "" until inflation is finished; then it is
        # the unused bytes of the input;
        # unconsumed_tail is whatever input was not used because max_length
        # was exceeded before inflation finished.
        # Thus, at most one of {unused_data, unconsumed_tail} may be non-empty.

        self.unconsumed_tail = ""
        if not self.inflater.finished() and not (self.gzip and not self.gzip_header_skipped):
            self.unused_data = ""

        if max_length < 0:
            raise ValueError("max_length must be a positive integer")

        # Suppress gzip header if present and wbits < 0
        if self.gzip and not self.gzip_header_skipped:
            string = self.unused_data + string
            self.unused_data = ""
            try:
                string = _skip_gzip_header(string)
            except IndexError:
                # need more input!
                self.unused_data = string
                return ""
            self.gzip_header_skipped = True

        string = _to_input(string)

        self.inflater.setInput(string)
        inflated = _get_inflate_data(self.inflater, max_length)

        r = self.inflater.getRemaining()
        if r:
            if max_length and not self.inflater.finished():
                self.unconsumed_tail = string[-r:]
            else:
                self.unused_data += string[-r:]

        return inflated

    def flush(self, length=None):
        if self._ended:
            raise error("decompressobj may not be used after flush()")
        if length is None:
            length = 0
        elif length <= 0:
            raise ValueError('length must be greater than zero')
        last = _get_inflate_data(self.inflater, length)
        self.inflater.end()
        return last