Message159492
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? |
|
Date |
User |
Action |
Args |
2012-04-27 20:49:10 | Sam.Rushing | set | recipients:
+ Sam.Rushing |
2012-04-27 20:49:09 | Sam.Rushing | set | messageid: <1335559749.94.0.188559298614.issue14684@psf.upfronthosting.co.za> |
2012-04-27 20:49:09 | Sam.Rushing | link | issue14684 messages |
2012-04-27 20:49:09 | Sam.Rushing | create | |
|