From abe6245751b10404b71dab0bb5542b5e59cad55b Mon Sep 17 00:00:00 2001 From: Dan Vanderkam Date: Tue, 22 Sep 2015 10:30:53 -0400 Subject: [PATCH] Revert "Python3 compatibility" --- .travis.yml | 1 - RangeHTTPServer.py | 24 +++++------------------- tests/RangeHTTPServer_test.py | 24 ++++++++++++------------ tests/server_test.py | 5 +---- 4 files changed, 18 insertions(+), 36 deletions(-) diff --git a/.travis.yml b/.travis.yml index b5827cf..be4e658 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,6 @@ sudo: false # use container-based infrastructure language: python python: - "2.7" - - "3.4" install: "pip install -r requirements.txt" script: nosetests --with-coverage --cover-tests diff --git a/RangeHTTPServer.py b/RangeHTTPServer.py index bb17760..81c3d24 100755 --- a/RangeHTTPServer.py +++ b/RangeHTTPServer.py @@ -1,10 +1,10 @@ #!/usr/bin/python ''' -Use this in the same way as Python's http.server / SimpleHTTPServer: +Use this in the same way as Python's SimpleHTTPServer: python -m RangeHTTPServer [port] -The only difference from http.server / SimpleHTTPServer is that RangeHTTPServer supports +The only difference from SimpleHTTPServer is that RangeHTTPServer supports 'Range:' headers to load portions of files. This is helpful for doing local web development with genomic data files, which tend to be to large to load into the browser all at once. @@ -13,13 +13,8 @@ import os import re import sys -import argparse -try: - from http.server import SimpleHTTPRequestHandler - import http.server as http_server -except ImportError: - from SimpleHTTPServer import SimpleHTTPRequestHandler - import SimpleHTTPServer as http_server +from SimpleHTTPServer import SimpleHTTPRequestHandler +import SimpleHTTPServer def copy_byte_range(infile, outfile, start=None, stop=None, bufsize=16*1024): @@ -115,13 +110,4 @@ def copyfile(self, source, outputfile): if __name__ == '__main__': - parser = argparse.ArgumentParser() - parser.add_argument('--bind', '-b', default='', metavar='ADDRESS', - help='Specify alternate bind address ' - '[default: all interfaces]') - parser.add_argument('port', action='store', - default=8000, type=int, - nargs='?', - help='Specify alternate port [default: 8000]') - args = parser.parse_args() - http_server.test(HandlerClass=RangeRequestHandler, port=args.port, bind=args.bind) + SimpleHTTPServer.test(HandlerClass=RangeRequestHandler) diff --git a/tests/RangeHTTPServer_test.py b/tests/RangeHTTPServer_test.py index cd8cfb3..f65fe38 100644 --- a/tests/RangeHTTPServer_test.py +++ b/tests/RangeHTTPServer_test.py @@ -4,7 +4,7 @@ import RangeHTTPServer from nose.tools import * -from io import BytesIO +from StringIO import StringIO def test_parse_byte_range(): @@ -22,25 +22,25 @@ def test_parse_byte_range(): def test_copy_byte_range(): - inbuffer = BytesIO(b'0123456789abcdefghijklmnopqrstuvwxyz') - outbuffer = BytesIO() + inbuffer = StringIO('0123456789abcdefghijklmnopqrstuvwxyz') + outbuffer = StringIO() RangeHTTPServer.copy_byte_range(inbuffer, outbuffer, 4, 10) - eq_(b'456789a', outbuffer.getvalue()) + eq_('456789a', outbuffer.getvalue()) - outbuffer = BytesIO() + outbuffer = StringIO() RangeHTTPServer.copy_byte_range(inbuffer, outbuffer, 0, 4) - eq_(b'01234', outbuffer.getvalue()) + eq_('01234', outbuffer.getvalue()) - outbuffer = BytesIO() + outbuffer = StringIO() RangeHTTPServer.copy_byte_range(inbuffer, outbuffer, 26) - eq_(b'qrstuvwxyz', outbuffer.getvalue()) + eq_('qrstuvwxyz', outbuffer.getvalue()) - outbuffer = BytesIO() + outbuffer = StringIO() RangeHTTPServer.copy_byte_range(inbuffer, outbuffer, 0, 9, 10) - eq_(b'0123456789', outbuffer.getvalue()) + eq_('0123456789', outbuffer.getvalue()) inbuffer.seek(0) - outbuffer = BytesIO() + outbuffer = StringIO() RangeHTTPServer.copy_byte_range(inbuffer, outbuffer) - eq_(b'0123456789abcdefghijklmnopqrstuvwxyz', outbuffer.getvalue()) + eq_('0123456789abcdefghijklmnopqrstuvwxyz', outbuffer.getvalue()) diff --git a/tests/server_test.py b/tests/server_test.py index ed3ba2d..968c9c9 100644 --- a/tests/server_test.py +++ b/tests/server_test.py @@ -6,10 +6,7 @@ from nose.tools import * -try: - from http.server import HTTPServer -except ImportError: - from BaseHTTPServer import HTTPServer +from BaseHTTPServer import HTTPServer import requests import threading import time