1 from test_support
import verify
5 filename
= tempfile
.mktemp()
7 data1
= """ int length=DEFAULTALLOC, err = Z_OK;
9 int flushmode = Z_FINISH;
10 unsigned long start_total_out;
14 data2
= """/* zlibmodule.c -- gzip-compatible data compression */
15 /* See http://www.cdrom.com/pub/infozip/zlib/ */
16 /* See http://www.winimage.com/zLibDll for Windows */
19 f
= gzip
.GzipFile(filename
, 'wb') ; f
.write(data1
* 50) ; f
.close()
21 f
= gzip
.GzipFile(filename
, 'r') ; d
= f
.read() ; f
.close()
24 # Append to the previous file
25 f
= gzip
.GzipFile(filename
, 'ab') ; f
.write(data2
* 15) ; f
.close()
27 f
= gzip
.GzipFile(filename
, 'rb') ; d
= f
.read() ; f
.close()
28 verify(d
== (data1
*50) + (data2
*15))
30 # Try .readline() with varying line lengths
32 f
= gzip
.GzipFile(filename
, 'rb')
35 L
= f
.readline(line_length
)
36 if L
== "" and line_length
!= 0: break
37 verify(len(L
) <= line_length
)
38 line_length
= (line_length
+ 1) % 50
43 f
= gzip
.GzipFile(filename
, 'rb')
47 f
= gzip
.GzipFile(filename
, 'rb')
55 f
= gzip
.GzipFile(filename
)
61 f
.seek(oldpos
) # negative seek
66 line2
= f
.read(amount
)
67 verify(line1
[:amount
] == line2
)
68 f
.seek(newpos
) # positive seek
71 # Try seek, write test
72 f
= gzip
.GzipFile(filename
, 'w')
73 for pos
in range(0, 256, 16):
78 f
= gzip
.GzipFile(filename
, 'r')
79 verify(f
.myfileobj
.mode
== 'rb')