Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #38759

Re: Generate 16+MAX_WBITS decompressable data

Path csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!cs.uu.nl!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'argument': 0.04; 'chunk': 0.07; 'data:': 0.07; 'does,': 0.09; 'exception:': 0.09; 'here?': 0.09; 'incorrect': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'terry': 0.09; 'explicitly.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'skip:z 30': 0.16; 'subject:Generate': 0.16; 'zlib': 0.16; 'wrote:': 0.17; 'jan': 0.18; 'memory': 0.18; 'code.': 0.20; 'versions': 0.20; 'trying': 0.21; 'import': 0.21; '"",': 0.22; 'default,': 0.22; "skip:' 40": 0.22; 'absolute': 0.23; "i've": 0.23; 'second': 0.24; 'header': 0.24; 'header:In- Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'fit': 0.26; '(most': 0.27; 'am,': 0.27; 'subject:skip:d 10': 0.27; 'header:X -Complaints-To:1': 0.28; 'run': 0.28; '>>>>': 0.29; 'once,': 0.29; 'piece': 0.29; "i'm": 0.29; "skip:' 10": 0.30; 'error': 0.30; 'code': 0.31; 'point': 0.31; 'file': 0.32; 'getting': 0.33; 'asked': 0.33; 'subject:data': 0.33; 'traceback': 0.33; 'to:addr :python-list': 0.33; 'skip:d 20': 0.34; "can't": 0.34; 'project': 0.34; 'largest': 0.35; 'ahead': 0.35; 'there': 0.35; 'received:org': 0.36; 'really': 0.36; 'but': 0.36; 'should': 0.36; 'passed': 0.37; 'skip:z 10': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'most': 0.61; 'remove': 0.61; 'between': 0.63; 'received:fios.verizon.net': 0.84; 'yusuf': 0.84; 'subject:+': 0.93
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Terry Reedy <tjreedy@udel.edu>
Subject Re: Generate 16+MAX_WBITS decompressable data
Date Tue, 12 Feb 2013 10:27:39 -0500
References <kfddp5$fho$1@ger.gmane.org>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host pool-173-75-251-66.phlapa.fios.verizon.net
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130107 Thunderbird/17.0.2
In-Reply-To <kfddp5$fho$1@ger.gmane.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1705.1360682882.2939.python-list@python.org> (permalink)
Lines 35
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1360682882 news.xs4all.nl 6850 [2001:888:2000:d::a6]:35611
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:38759

Show key headers only | View raw


On 2/12/2013 7:47 AM, Fayaz Yusuf Khan wrote:
> I'm trying write unit-tests for some of my old code and have run into this
> piece of code.
>
> dcomp = zlib.decompressobj(16+zlib.MAX_WBITS)

Since zlib.MAX_WBITS is the largest value that should be passed (15), 
adding 16 makes no sense. Since it is also the default, there is also no 
point in providing it explicitly. "Its absolute value should be between 
8 and 15 for the most recent versions of the zlib library".

> chunk = ''.join(f.chunks())
> received_data =  dcomp.decompress(chunk)

Since decompressobj is intended for data that will not all fit in memory 
at once, and since chunk does, just use zlib.decompress(chunk)

> How do I generate the chunk here? From what I've been trying I'm getting
> this exception:
>>>> import zlib
>>>> zlib.compress('hello')
> 'x\x9c\xcbH\xcd\xc9\xc9\x07\x00\x06,\x02\x15'
>>>> zlib.decompress(_, 16+zlib.MAX_WBITS)
> Traceback (most recent call last):
>    File "<stdin>", line 1, in <module>
> zlib.error: Error -3 while decompressing data: incorrect header check

You asked for an internal buffer of 2**31 = 2 gigabytes.

> zlib.decompress without the second argument works, but I can't really go
> ahead into my project file and remove it.

-- 
Terry Jan Reedy

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: Generate 16+MAX_WBITS decompressable data Terry Reedy <tjreedy@udel.edu> - 2013-02-12 10:27 -0500
  Re: Generate 16+MAX_WBITS decompressable data Marc Christiansen <usenet@solar-empire.de> - 2013-02-12 21:39 +0100
    Re: Generate 16+MAX_WBITS decompressable data Fayaz Yusuf Khan <fayaz@dexetra.com> - 2013-02-13 10:48 +0530
    Re: Generate 16+MAX_WBITS decompressable data Terry Reedy <tjreedy@udel.edu> - 2013-02-13 01:30 -0500

csiph-web