7 t
= imp
.find_module('test_zlib')
14 # test the chucksums (hex so the test doesn't break on 64-bit machines)
15 print hex(zlib
.crc32('penguin')), hex(zlib
.crc32('penguin', 1))
16 print hex(zlib
.adler32('penguin')), hex(zlib
.adler32('penguin', 1))
18 # make sure we generate some expected errors
20 zlib
.compress('ERROR', zlib
.MAX_WBITS
+ 1)
21 except zlib
.error
, msg
:
22 print "expecting", msg
24 zlib
.compressobj(1, 8, 0)
25 except ValueError, msg
:
26 print "expecting", msg
29 except ValueError, msg
:
30 print "expecting", msg
32 x
= zlib
.compress(buf
)
33 y
= zlib
.decompress(x
)
35 print "normal compression/decompression failed"
37 print "normal compression/decompression succeeded"
41 co
= zlib
.compressobj(8, 8, -15)
46 dc
= zlib
.decompressobj(-15)
51 print "compress/decompression obj failed"
53 print "compress/decompression obj succeeded"
55 co
= zlib
.compressobj(2, 8, -12, 9, 1)
57 for i
in range(0, len(buf
), 256):
58 bufs
.append(co
.compress(buf
[i
:i
+256]))
59 bufs
.append(co
.flush())
60 combuf
= string
.join(bufs
, '')
62 decomp1
= zlib
.decompress(combuf
, -12, -5)
64 print "decompress with init options failed"
66 print "decompress with init options succeeded"
68 deco
= zlib
.decompressobj(-12)
70 for i
in range(0, len(combuf
), 128):
71 bufs
.append(deco
.decompress(combuf
[i
:i
+128]))
72 bufs
.append(deco
.flush())
73 decomp2
= string
.join(buf
, '')
75 print "decompressobj with init options failed"
77 print "decompressobj with init options succeeded"
80 """An empty function with a big string.
82 Make the compression algorithm work a little harder.
89 I stay too long: but here my father comes.
93 A double blessing is a double grace,
94 Occasion smiles upon a second leave.
98 Yet here, Laertes! aboard, aboard, for shame!
99 The wind sits in the shoulder of your sail,
100 And you are stay'd for. There; my blessing with thee!
101 And these few precepts in thy memory
102 See thou character. Give thy thoughts no tongue,
103 Nor any unproportioned thought his act.
104 Be thou familiar, but by no means vulgar.
105 Those friends thou hast, and their adoption tried,
106 Grapple them to thy soul with hoops of steel;
107 But do not dull thy palm with entertainment
108 Of each new-hatch'd, unfledged comrade. Beware
109 Of entrance to a quarrel, but being in,
110 Bear't that the opposed may beware of thee.
111 Give every man thy ear, but few thy voice;
112 Take each man's censure, but reserve thy judgment.
113 Costly thy habit as thy purse can buy,
114 But not express'd in fancy; rich, not gaudy;
115 For the apparel oft proclaims the man,
116 And they in France of the best rank and station
117 Are of a most select and generous chief in that.
118 Neither a borrower nor a lender be;
119 For loan oft loses both itself and friend,
120 And borrowing dulls the edge of husbandry.
121 This above all: to thine ownself be true,
122 And it must follow, as the night the day,
123 Thou canst not then be false to any man.
124 Farewell: my blessing season this in thee!
128 Most humbly do I take my leave, my lord.
132 The time invites you; go; your servants tend.
136 Farewell, Ophelia; and remember well
137 What I have said to you.
141 'Tis in my memory lock'd,
142 And you yourself shall keep the key of it.