1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-06-28 01:35:32 +00:00
elinks/test/cgi/chunked_gzip.py
Witold Filipczyk a27e9b168c [python3] adjust code to Python3 in test scripts. Refs #38
I don't know how to fix big_file.cgi
If you know how to get equivalent of this script in Python3, tell me.
2020-01-01 16:07:14 +01:00

27 lines
736 B
Python
Executable File

#!/usr/bin/env python3
import gzip, os, time, six
output = six.BytesIO()
data1 = b'<html><body>Two lines should be visible.<br/>The second line.</body></html>'
f1 = gzip.GzipFile("/tmp/1.gz", mode = "wb", fileobj=output)
f1.write(data1)
f1.close()
cd1 = output.getvalue()
output.close()
length = len(cd1)
next_chunk = hex(length - 10)[2:]
os.write(1, b"Date: Sun, 20 Jan 2008 15:24:00 GMT\r\nServer: ddd\r\nTransfer-Encoding: chunked\r\nContent-Encoding: gzip\r\nConnection: close\r\nContent-Type: text/html; charset=ISO-8859-1\r\n")
os.write(1, b"\r\na\r\n")
os.write(1, cd1[:10])
time.sleep(2)
os.write(1, b"\r\n")
os.write(1, bytes(next_chunk, 'iso8859-1'))
os.write(1, b"\r\n")
os.write(1, cd1[10:])
os.write(1, b"\r\n0\r\n")