blob: 2366d0268d129916829f8ab768ad2c148e0dda68 [file] [log] [blame]
Guido van Rossum9a744a91999-04-08 20:27:54 +00001
2import sys, os
3import gzip, tempfile
4
5filename = tempfile.mktemp()
6
7data1 = """ int length=DEFAULTALLOC, err = Z_OK;
8 PyObject *RetVal;
9 int flushmode = Z_FINISH;
10 unsigned long start_total_out;
11
12"""
13
14data2 = """/* zlibmodule.c -- gzip-compatible data compression */
15/* See http://www.cdrom.com/pub/infozip/zlib/ */
16/* See http://www.winimage.com/zLibDll for Windows */
17"""
18
Guido van Rossum8d691c82000-09-01 19:25:51 +000019f = gzip.GzipFile(filename, 'wb') ; f.write(data1 * 50) ; f.close()
Guido van Rossum9a744a91999-04-08 20:27:54 +000020
21f = gzip.GzipFile(filename, 'rb') ; d = f.read() ; f.close()
Guido van Rossum8d691c82000-09-01 19:25:51 +000022assert d == data1*50
Guido van Rossum9a744a91999-04-08 20:27:54 +000023
24# Append to the previous file
Guido van Rossum8d691c82000-09-01 19:25:51 +000025f = gzip.GzipFile(filename, 'ab') ; f.write(data2 * 15) ; f.close()
Guido van Rossum9a744a91999-04-08 20:27:54 +000026
27f = gzip.GzipFile(filename, 'rb') ; d = f.read() ; f.close()
Guido van Rossum8d691c82000-09-01 19:25:51 +000028assert d == (data1*50) + (data2*15)
29
30# Try .readline() with varying line lengths
31
32f = gzip.GzipFile(filename, 'rb')
33line_length = 0
34while 1:
35 L = f.readline( line_length )
36 if L == "" and line_length != 0: break
37 assert len(L) <= line_length
38 line_length = (line_length + 1) % 50
39f.close()
40
41# Try .readlines()
42
43f = gzip.GzipFile(filename, 'rb')
44L = f.readlines()
45f.close()
46
47f = gzip.GzipFile(filename, 'rb')
48while 1:
49 L = f.readlines(150)
50 if L == []: break
51f.close()
52
Guido van Rossum9a744a91999-04-08 20:27:54 +000053
54os.unlink( filename )