Skip to content

Commit

Permalink
tests_website: remove six, bump version, update open script
Browse files Browse the repository at this point in the history
* tests_website: remove six usage from server.py
* tests_website: bump version
* tests_website: update open_test_page.py for Python 3
  • Loading branch information
Greg Guthe committed Aug 3, 2021
1 parent e96c8d7 commit ae196a3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions tests_website/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html>
<head>
<meta charset="UTF-8">
<title>Python Bleach 3.3.0</title>
<title>Python Bleach 4.0.0</title>
<style>
textarea, iframe {
width: 95%;
Expand All @@ -20,7 +20,7 @@
</style>
</head>
<body>
<h2>Python Bleach 3.3.0</h2>
<h2>Python Bleach 4.0.0</h2>
<p>
<a href="http://badge.fury.io/py/bleach"><img style="max-width:100%;" alt="pypi version" src="https://badge.fury.io/py/bleach.svg"></a>
<a href="https://github.com/mozilla/bleach/actions?query=workflow%3ATest"><img style="max-width:100%;" alt="Build Status" src="https://github.com/mozilla/bleach/workflows/Test/badge.svg"></a>
Expand Down
9 changes: 6 additions & 3 deletions tests_website/open_test_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@
# 'chromium',
# 'chromium-browser',
}
REGISTERED_BROWSERS = set(webbrowser._browsers.keys())


if __name__ == "__main__":
for b in TEST_BROWSERS & REGISTERED_BROWSERS:
webbrowser.get(b).open_new_tab("http://localhost:8080")
for browser_name in TEST_BROWSERS:
try:
browser = webbrowser.get(browser_name)
browser.open_new_tab("http://localhost:8080")
except Exception as error:
print("error getting test browser %s: %s" % (browser_name, error))
25 changes: 11 additions & 14 deletions tests_website/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,26 @@
"""

import six
import http.server
import socketserver

import bleach


PORT = 8080


class BleachCleanHandler(six.moves.SimpleHTTPServer.SimpleHTTPRequestHandler):
class BleachCleanHandler(http.server.SimpleHTTPRequestHandler):

# Prevent 'cannot bind to address' errors on restart
allow_reuse_address = True

def do_POST(self):
if six.PY2:
content_len = int(self.headers.getheader("content-length", 0))
else:
content_len = int(self.headers.get("content-length", 0))
content_len = int(self.headers.get("content-length", 0))
body = self.rfile.read(content_len)
print("read %s bytes: %s" % (content_len, body))

if six.PY3:
body = body.decode("utf-8")
body = body.decode("utf-8")
print("input: %r" % body)
cleaned = bleach.clean(body)

Expand All @@ -37,16 +38,12 @@ def do_POST(self):
self.send_header("Content-Type", "text/plain;charset=UTF-8")
self.end_headers()

if six.PY3:
cleaned = bytes(cleaned, encoding="utf-8")
cleaned = bytes(cleaned, encoding="utf-8")
print("cleaned: %r" % cleaned)
self.wfile.write(cleaned)


if __name__ == "__main__":
# Prevent 'cannot bind to address' errors on restart
six.moves.socketserver.TCPServer.allow_reuse_address = True

httpd = six.moves.socketserver.TCPServer(("127.0.0.1", PORT), BleachCleanHandler)
httpd = socketserver.TCPServer(("127.0.0.1", PORT), BleachCleanHandler)
print("listening on localhost port %d" % PORT)
httpd.serve_forever()

0 comments on commit ae196a3

Please sign in to comment.