Jeremy Hylton | 6eb4b6a | 1997-08-15 15:59:43 +0000 | [diff] [blame] | 1 | import zlib |
| 2 | import sys |
Guido van Rossum | c95a6c1 | 1997-08-15 16:23:32 +0000 | [diff] [blame^] | 3 | import imp |
Jeremy Hylton | 6eb4b6a | 1997-08-15 15:59:43 +0000 | [diff] [blame] | 4 | |
Guido van Rossum | c95a6c1 | 1997-08-15 16:23:32 +0000 | [diff] [blame^] | 5 | t = imp.find_module('test_zlib') |
| 6 | file = t[0] |
| 7 | buf = file.read() * 8 |
| 8 | file.close() |
Jeremy Hylton | 6eb4b6a | 1997-08-15 15:59:43 +0000 | [diff] [blame] | 9 | |
| 10 | x = zlib.compress(buf) |
| 11 | y = zlib.decompress(x) |
| 12 | if buf != y: |
| 13 | print "normal compression/decompression failed" |
| 14 | |
| 15 | buf = buf * 16 |
| 16 | |
| 17 | co = zlib.compressobj(8, 8, -15) |
| 18 | x1 = co.compress(buf) |
| 19 | x2 = co.flush() |
| 20 | x = x1 + x2 |
| 21 | |
| 22 | dc = zlib.decompressobj(-15) |
| 23 | y1 = dc.decompress(x) |
| 24 | y2 = dc.flush() |
| 25 | y = y1 + y2 |
| 26 | if buf != y: |
| 27 | print "compress/decompression obj failed" |
| 28 | |
| 29 | def ignore(): |
| 30 | """An empty function with a big string. |
| 31 | |
| 32 | Make the compression algorithm work a little harder. |
| 33 | """ |
| 34 | |
| 35 | """ |
| 36 | LAERTES |
| 37 | |
| 38 | O, fear me not. |
| 39 | I stay too long: but here my father comes. |
| 40 | |
| 41 | Enter POLONIUS |
| 42 | |
| 43 | A double blessing is a double grace, |
| 44 | Occasion smiles upon a second leave. |
| 45 | |
| 46 | LORD POLONIUS |
| 47 | |
| 48 | Yet here, Laertes! aboard, aboard, for shame! |
| 49 | The wind sits in the shoulder of your sail, |
| 50 | And you are stay'd for. There; my blessing with thee! |
| 51 | And these few precepts in thy memory |
| 52 | See thou character. Give thy thoughts no tongue, |
| 53 | Nor any unproportioned thought his act. |
| 54 | Be thou familiar, but by no means vulgar. |
| 55 | Those friends thou hast, and their adoption tried, |
| 56 | Grapple them to thy soul with hoops of steel; |
| 57 | But do not dull thy palm with entertainment |
| 58 | Of each new-hatch'd, unfledged comrade. Beware |
| 59 | Of entrance to a quarrel, but being in, |
| 60 | Bear't that the opposed may beware of thee. |
| 61 | Give every man thy ear, but few thy voice; |
| 62 | Take each man's censure, but reserve thy judgment. |
| 63 | Costly thy habit as thy purse can buy, |
| 64 | But not express'd in fancy; rich, not gaudy; |
| 65 | For the apparel oft proclaims the man, |
| 66 | And they in France of the best rank and station |
| 67 | Are of a most select and generous chief in that. |
| 68 | Neither a borrower nor a lender be; |
| 69 | For loan oft loses both itself and friend, |
| 70 | And borrowing dulls the edge of husbandry. |
| 71 | This above all: to thine ownself be true, |
| 72 | And it must follow, as the night the day, |
| 73 | Thou canst not then be false to any man. |
| 74 | Farewell: my blessing season this in thee! |
| 75 | |
| 76 | LAERTES |
| 77 | |
| 78 | Most humbly do I take my leave, my lord. |
| 79 | |
| 80 | LORD POLONIUS |
| 81 | |
| 82 | The time invites you; go; your servants tend. |
| 83 | |
| 84 | LAERTES |
| 85 | |
| 86 | Farewell, Ophelia; and remember well |
| 87 | What I have said to you. |
| 88 | |
| 89 | OPHELIA |
| 90 | |
| 91 | 'Tis in my memory lock'd, |
| 92 | And you yourself shall keep the key of it. |
| 93 | |
| 94 | LAERTES |
| 95 | |
| 96 | Farewell. |
| 97 | """ |
| 98 | |