mirror of
https://github.com/rkd77/elinks.git
synced 2024-06-15 23:35:34 +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:
parent
df905c7481
commit
a27e9b168c
|
@ -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])
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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
|
||||
|
||||
|
@ -19,103 +19,103 @@ F_Hidden = 0
|
|||
F_TextArea = 1
|
||||
|
||||
def encode(ch, encoding):
|
||||
if ch == C_CRLF:
|
||||
return encode(C_CR, encoding) + encode(C_LF, encoding)
|
||||
if ch == C_CR:
|
||||
if encoding == E_Raw:
|
||||
return "\r"
|
||||
if encoding == E_JavaScript:
|
||||
return "\\r"
|
||||
if encoding == E_Entity:
|
||||
return "
"
|
||||
if ch == C_LF:
|
||||
if encoding == E_Raw:
|
||||
return "\n"
|
||||
if encoding == E_JavaScript:
|
||||
return "\\n"
|
||||
if encoding == E_Entity:
|
||||
return "
"
|
||||
if ch == C_CRLF:
|
||||
return encode(C_CR, encoding) + encode(C_LF, encoding)
|
||||
if ch == C_CR:
|
||||
if encoding == E_Raw:
|
||||
return "\r"
|
||||
if encoding == E_JavaScript:
|
||||
return "\\r"
|
||||
if encoding == E_Entity:
|
||||
return "
"
|
||||
if ch == C_LF:
|
||||
if encoding == E_Raw:
|
||||
return "\n"
|
||||
if encoding == E_JavaScript:
|
||||
return "\\n"
|
||||
if encoding == E_Entity:
|
||||
return "
"
|
||||
|
||||
def get_form(ch, encoding, field):
|
||||
text = "foo" + encode(ch, encoding) + "bar"
|
||||
if encoding == E_JavaScript:
|
||||
text_initial = ""
|
||||
else:
|
||||
text_initial = text
|
||||
text = "foo" + encode(ch, encoding) + "bar"
|
||||
if encoding == E_JavaScript:
|
||||
text_initial = ""
|
||||
else:
|
||||
text_initial = text
|
||||
|
||||
s = """<html>
|
||||
s = """<html>
|
||||
<head>
|
||||
<title>Form Test</title>
|
||||
</head>
|
||||
<body>
|
||||
<form id="form1" name="form1" action="http://127.0.0.1:8090/">
|
||||
"""
|
||||
if field == F_Hidden:
|
||||
s += '<input type="hidden" id="field1" name="field1" value="' + text_initial + '">'
|
||||
elif field == F_TextArea:
|
||||
s += '<textarea id="field1" name="field1">' + text_initial + '</textarea>'
|
||||
s += "\n</form>"
|
||||
if encoding == E_JavaScript:
|
||||
s += """
|
||||
if field == F_Hidden:
|
||||
s += '<input type="hidden" id="field1" name="field1" value="' + text_initial + '">'
|
||||
elif field == F_TextArea:
|
||||
s += '<textarea id="field1" name="field1">' + text_initial + '</textarea>'
|
||||
s += "\n</form>"
|
||||
if encoding == E_JavaScript:
|
||||
s += """
|
||||
<script>
|
||||
document.form1.field1.value = '%s';
|
||||
</script>""" % (text)
|
||||
|
||||
s += "</body></html>"
|
||||
return s
|
||||
s += "</body></html>"
|
||||
return s
|
||||
|
||||
class forwarder(BaseHTTPRequestHandler):
|
||||
def do_GET(self):
|
||||
w.write(self.path + "\n")
|
||||
w.flush()
|
||||
self.send_response(200)
|
||||
self.send_header("Content-Type", "text/plain")
|
||||
self.end_headers()
|
||||
self.wfile.write("Dummy response")
|
||||
def do_GET(self):
|
||||
w.write(self.path + "\n")
|
||||
w.flush()
|
||||
self.send_response(200)
|
||||
self.send_header("Content-Type", "text/plain")
|
||||
self.end_headers()
|
||||
self.wfile.write(b"Dummy response")
|
||||
|
||||
def runtest(r, *args):
|
||||
form = get_form(*args)
|
||||
form = get_form(*args)
|
||||
|
||||
tmpfile, tmpname = tempfile.mkstemp(".html")
|
||||
tmpfile = os.fdopen(tmpfile, 'w')
|
||||
tmpfile.write(form)
|
||||
tmpfile.close()
|
||||
tmpfile, tmpname = tempfile.mkstemp(".html")
|
||||
tmpfile = os.fdopen(tmpfile, 'w')
|
||||
tmpfile.write(form)
|
||||
tmpfile.close()
|
||||
|
||||
linkspid = os.spawnlp(os.P_NOWAIT, 'elinks', 'elinks',
|
||||
'-config-dir', os.getcwd(),
|
||||
'-config-file', 'crlf.conf',
|
||||
'-no-connect', '1',
|
||||
'-auto-submit', '1',
|
||||
tmpname)
|
||||
path = r.readline()
|
||||
os.kill(linkspid, signal.SIGINT)
|
||||
os.waitpid(linkspid, 0)
|
||||
linkspid = os.spawnlp(os.P_NOWAIT, 'elinks', 'elinks',
|
||||
'-config-dir', os.getcwd(),
|
||||
'-config-file', 'crlf.conf',
|
||||
'-no-connect', '1',
|
||||
'-auto-submit', '1',
|
||||
tmpname)
|
||||
path = r.readline()
|
||||
os.kill(linkspid, signal.SIGINT)
|
||||
os.waitpid(linkspid, 0)
|
||||
|
||||
os.unlink(tmpname)
|
||||
os.unlink(tmpname)
|
||||
|
||||
return path
|
||||
return path
|
||||
|
||||
pid = os.fork()
|
||||
|
||||
if pid:
|
||||
os.close(w)
|
||||
r = os.fdopen(r)
|
||||
os.close(w)
|
||||
r = os.fdopen(r)
|
||||
|
||||
paths = []
|
||||
paths = []
|
||||
|
||||
for c in [C_CR, C_LF, C_CRLF]:
|
||||
for e in [E_Raw, E_Entity, E_JavaScript]:
|
||||
for f in [F_Hidden, F_TextArea]:
|
||||
paths.append(("%d %d %d " % (c, e, f)) + runtest(r, c, e, f))
|
||||
for c in [C_CR, C_LF, C_CRLF]:
|
||||
for e in [E_Raw, E_Entity, E_JavaScript]:
|
||||
for f in [F_Hidden, F_TextArea]:
|
||||
paths.append(("%d %d %d " % (c, e, f)) + runtest(r, c, e, f))
|
||||
|
||||
for path in paths:
|
||||
print path,
|
||||
for path in paths:
|
||||
print(path, end=' ')
|
||||
|
||||
os.kill(pid, signal.SIGTERM)
|
||||
os.waitpid(pid, 0)
|
||||
os.kill(pid, signal.SIGTERM)
|
||||
os.waitpid(pid, 0)
|
||||
else:
|
||||
os.close(r)
|
||||
w = os.fdopen(w, 'w')
|
||||
server_address = ('127.0.0.1', 8090)
|
||||
httpd = HTTPServer(server_address, forwarder)
|
||||
httpd.serve_forever()
|
||||
os.close(r)
|
||||
w = os.fdopen(w, 'w')
|
||||
server_address = ('127.0.0.1', 8090)
|
||||
httpd = HTTPServer(server_address, forwarder)
|
||||
httpd.serve_forever()
|
||||
|
|
|
@ -1,32 +1,32 @@
|
|||
#!/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):
|
||||
def do_GET(self):
|
||||
self.send_response(200)
|
||||
self.send_header("Content-Type", "text/plain")
|
||||
self.send_header("Content-Encoding", "gzip")
|
||||
self.send_header("Connection", "close")
|
||||
self.end_headers()
|
||||
self.wfile.write(pocz)
|
||||
time.sleep(5)
|
||||
self.wfile.write(reszta)
|
||||
class obsluga(http.server.BaseHTTPRequestHandler):
|
||||
def do_GET(self):
|
||||
self.send_response(200)
|
||||
self.send_header("Content-Type", "text/plain")
|
||||
self.send_header("Content-Encoding", "gzip")
|
||||
self.send_header("Connection", "close")
|
||||
self.end_headers()
|
||||
self.wfile.write(pocz)
|
||||
time.sleep(5)
|
||||
self.wfile.write(reszta)
|
||||
|
||||
def run(port=8900):
|
||||
server_address = ('127.0.0.1', port)
|
||||
httpd = BaseHTTPServer.HTTPServer(server_address, obsluga)
|
||||
httpd.handle_request()
|
||||
server_address = ('127.0.0.1', port)
|
||||
httpd = http.server.HTTPServer(server_address, obsluga)
|
||||
httpd.handle_request()
|
||||
|
||||
if __name__ == "__main__":
|
||||
run()
|
||||
run()
|
||||
|
|
Loading…
Reference in New Issue
Block a user