This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Sam.Rushing
Recipients Sam.Rushing
Date 2012-04-27.20:49:08
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1335559749.94.0.188559298614.issue14684@psf.upfronthosting.co.za>
In-reply-to
Content
Google's SPDY protocol requires the use of a pre-defined compression dictionary.  The current zlib module doesn't expose the two functions for setting the dictionary.

This patch is minimal in the sense that it only exposes the two functions, but unfortunately the sequence of zlib calls required is clumsy: a call to inflate() must fail first (with an error of Z_NEED_DICT):


import zlib
zdict = b"thequickbrownfoxjumped\x00"
c = zlib.compressobj()
c.set_dictionary (zdict)
cd = c.compress (b"the quick brown fox jumped over the candlestick")
cd += c.flush()
d = zlib.decompressobj()
try:
    print (d.decompress (cd))
except zlib.error as what:
    if what.args[0].startswith ('Error 2 '):
        d.set_dictionary (zdict)
        print (d.flush())

Obviously a better way to catch/match Z_NEED_DICT would be nice.
A much nicer solution would allow you to associate the dictionary at creation time, rather than having to wait for an error condition.  I can only guess that the zlib authors designed it that way for a reason?
History
Date User Action Args
2012-04-27 20:49:10Sam.Rushingsetrecipients: + Sam.Rushing
2012-04-27 20:49:09Sam.Rushingsetmessageid: <1335559749.94.0.188559298614.issue14684@psf.upfronthosting.co.za>
2012-04-27 20:49:09Sam.Rushinglinkissue14684 messages
2012-04-27 20:49:09Sam.Rushingcreate