1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-06-24 00:56:14 +00:00

[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.
This commit is contained in:
Witold Filipczyk 2020-01-01 16:07:14 +01:00
parent df905c7481
commit a27e9b168c
7 changed files with 126 additions and 118 deletions

View File

@ -16,7 +16,7 @@ AC_CONFIG_AUX_DIR(config)
AC_CONFIG_MACRO_DIR([config/m4])
PACKAGE=elinks
VERSION=0.13.0
VERSION=0.14.GIT
AC_SUBST(PACKAGE)
AC_SUBST(VERSION)
AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [Package version])

View File

@ -1,16 +1,18 @@
#!/usr/bin/env python
#!/usr/bin/env python3
import bz2, os, time
data1 = '<html><body>Two lines should be visible.<br/>The second line.</body></html>'
data1 = b'<html><body>Two lines should be visible.<br/>The second line.</body></html>'
cd1 = bz2.compress(data1)
length = len(cd1)
next_chunk = hex(length - 10)[2:]
os.write(1, "Date: Sun, 20 Jan 2008 15:24:00 GMT\r\nServer: ddd\r\nTransfer-Encoding: chunked\r\nContent-Encoding: bzip2\r\nConnection: close\r\nContent-Type: text/html; charset=ISO-8859-1\r\n")
os.write(1, "\r\na\r\n")
os.write(1, b"Date: Sun, 20 Jan 2008 15:24:00 GMT\r\nServer: ddd\r\nTransfer-Encoding: chunked\r\nContent-Encoding: bzip2\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, "\r\n%s\r\n" % next_chunk)
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, "\r\n0\r\n")
os.write(1, b"\r\n0\r\n")

View File

@ -1,16 +1,18 @@
#!/usr/bin/env python
#!/usr/bin/env python3
import os, time, zlib
data1 = '<html><body>Two lines should be visible.<br/>The second line.</body></html>'
data1 = b'<html><body>Two lines should be visible.<br/>The second line.</body></html>'
cd1 = zlib.compress(data1)
length = len(cd1)
next_chunk = hex(length - 10)[2:]
os.write(1, "Date: Sun, 20 Jan 2008 15:24:00 GMT\r\nServer: ddd\r\nTransfer-Encoding: chunked\r\nContent-Encoding: deflate\r\nConnection: close\r\nContent-Type: text/html; charset=ISO-8859-1\r\n")
os.write(1, "\r\na\r\n")
os.write(1, b"Date: Sun, 20 Jan 2008 15:24:00 GMT\r\nServer: ddd\r\nTransfer-Encoding: chunked\r\nContent-Encoding: deflate\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, "\r\n%s\r\n" % next_chunk)
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, "\r\n0\r\n")
os.write(1, b"\r\n0\r\n")

View File

@ -1,9 +1,9 @@
#!/usr/bin/env python
import gzip, os, time, StringIO
#!/usr/bin/env python3
import gzip, os, time, six
output = StringIO.StringIO()
output = six.BytesIO()
data1 = '<html><body>Two lines should be visible.<br/>The second line.</body></html>'
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)
@ -15,10 +15,12 @@ output.close()
length = len(cd1)
next_chunk = hex(length - 10)[2:]
os.write(1, "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, "\r\na\r\n")
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, "\r\n%s\r\n" % next_chunk)
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, "\r\n0\r\n")
os.write(1, b"\r\n0\r\n")

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
import os, time
from zlib import *
@ -6,17 +6,19 @@ from zlib import *
# requires a ZLIB header. However, Microsoft-IIS/6.0 sends a raw
# DEFLATE stream instead. This CGI tests how ELinks handles that.
data1 = '<html><body>Two lines should be visible.<br/>The second line.</body></html>'
data1 = b'<html><body>Two lines should be visible.<br/>The second line.</body></html>'
ob = compressobj(Z_DEFAULT_COMPRESSION, DEFLATED, -MAX_WBITS)
cd1 = ob.compress(data1)
cd1 += ob.flush()
length = len(cd1)
next_chunk = hex(length - 10)[2:]
os.write(1, "Date: Sun, 20 Jan 2008 15:24:00 GMT\r\nServer: ddd\r\nTransfer-Encoding: chunked\r\nContent-Encoding: deflate\r\nConnection: close\r\nContent-Type: text/html; charset=ISO-8859-1\r\n")
os.write(1, "\r\na\r\n")
os.write(1, b"Date: Sun, 20 Jan 2008 15:24:00 GMT\r\nServer: ddd\r\nTransfer-Encoding: chunked\r\nContent-Encoding: deflate\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, "\r\n%s\r\n" % next_chunk)
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, "\r\n0\r\n")
os.write(1, b"\r\n0\r\n")

View File

@ -1,7 +1,7 @@
#!/usr/bin/env python
#!/usr/bin/env python3
import os
from BaseHTTPServer import *
from http.server import *
import tempfile
import signal
@ -71,7 +71,7 @@ class forwarder(BaseHTTPRequestHandler):
self.send_response(200)
self.send_header("Content-Type", "text/plain")
self.end_headers()
self.wfile.write("Dummy response")
self.wfile.write(b"Dummy response")
def runtest(r, *args):
form = get_form(*args)
@ -109,7 +109,7 @@ if pid:
paths.append(("%d %d %d " % (c, e, f)) + runtest(r, c, e, f))
for path in paths:
print path,
print(path, end=' ')
os.kill(pid, signal.SIGTERM)
os.waitpid(pid, 0)

View File

@ -1,18 +1,18 @@
#!/usr/bin/env python
import gzip, string, cStringIO, os, time, BaseHTTPServer
#!/usr/bin/env python3
import gzip, string, six, os, time, http.server
data = [str(i) for i in xrange(34000)]
data = [str(i) for i in range(34000)]
text = "\n".join(data)
s = cStringIO.StringIO()
s = six.BytesIO()
gz = gzip.GzipFile("1.gz", "wb", 9, s)
gz.write(text)
gz.write(bytes(text, 'iso8859-1'))
gz.close()
comp = s.getvalue()
s.close()
pocz = comp[:65536]
reszta = comp[65536:]
class obsluga(BaseHTTPServer.BaseHTTPRequestHandler):
class obsluga(http.server.BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.send_header("Content-Type", "text/plain")
@ -25,7 +25,7 @@ class obsluga(BaseHTTPServer.BaseHTTPRequestHandler):
def run(port=8900):
server_address = ('127.0.0.1', port)
httpd = BaseHTTPServer.HTTPServer(server_address, obsluga)
httpd = http.server.HTTPServer(server_address, obsluga)
httpd.handle_request()
if __name__ == "__main__":