Commit 1ed3a160 authored by Jason R. Coombs's avatar Jason R. Coombs

Cleaned up simulated index server, expanding documentation.

--HG--
branch : distribute
extra : rebase_source : b479cf805b766fa35c8e76c30c7725e93f56e6a2
parent 83a86217
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
""" """
import urllib2 import urllib2
import sys import sys
from threading import Thread import threading
from BaseHTTPServer import HTTPServer from BaseHTTPServer import HTTPServer
from SimpleHTTPServer import SimpleHTTPRequestHandler from SimpleHTTPServer import SimpleHTTPRequestHandler
...@@ -17,29 +17,36 @@ class IndexServer(HTTPServer): ...@@ -17,29 +17,36 @@ class IndexServer(HTTPServer):
# The index files should be located in setuptools/tests/indexes # The index files should be located in setuptools/tests/indexes
s.stop() s.stop()
""" """
def __init__(self): def __init__(self, server_address=('', 0),
HTTPServer.__init__(self, ('', 0), SimpleHTTPRequestHandler) RequestHandlerClass=SimpleHTTPRequestHandler,
bind_and_activate=True):
HTTPServer.__init__(self, server_address, RequestHandlerClass,
bind_and_activate)
self._run = True self._run = True
def serve(self): def serve(self):
while True: while self._run:
self.handle_request() self.handle_request()
if not self._run: break
def start(self): def start(self):
self.thread = Thread(target=self.serve) self.thread = threading.Thread(target=self.serve)
self.thread.start() self.thread.start()
def stop(self): def stop(self):
"""self.shutdown is not supported on python < 2.6""" "Stop the server"
# self.shutdown is not supported on python < 2.6, so just
# set _run to false, and make a request, causing it to
# terminate.
self._run = False self._run = False
url = 'http://127.0.0.1:%(server_port)s/' % vars(self)
try: try:
if sys.version > '2.6': if sys.version_info >= (2, 6):
urllib2.urlopen('http://127.0.0.1:%s/' % self.server_port, urllib2.urlopen(url, timeout=5)
None, 5)
else: else:
urllib2.urlopen('http://127.0.0.1:%s/' % self.server_port) urllib2.urlopen(url)
except urllib2.URLError: except urllib2.URLError:
# ignore any errors; all that's important is the request
pass pass
self.thread.join() self.thread.join()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment