Skip to content

Commit

Permalink
Revert "Python3 compatibility"
Browse files Browse the repository at this point in the history
  • Loading branch information
danvk committed Sep 22, 2015
1 parent ebb5c5d commit abe6245
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 36 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Expand Up @@ -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

Expand Down
24 changes: 5 additions & 19 deletions 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.
Expand All @@ -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):
Expand Down Expand Up @@ -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)
24 changes: 12 additions & 12 deletions tests/RangeHTTPServer_test.py
Expand Up @@ -4,7 +4,7 @@
import RangeHTTPServer

from nose.tools import *
from io import BytesIO
from StringIO import StringIO


def test_parse_byte_range():
Expand All @@ -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())
5 changes: 1 addition & 4 deletions tests/server_test.py
Expand Up @@ -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
Expand Down

0 comments on commit abe6245

Please sign in to comment.