Use the provided calls to shutdown server instead of rewriting it

This commit is contained in:
Darshit Shah 2013-09-10 12:22:13 +05:30
parent 99659f3295
commit e84192a8d3
3 changed files with 16 additions and 19 deletions

View File

@ -1,3 +1,14 @@
2013-09-10 Darshit Shah <darnir@gmail.com>
* WgetTest.py (HTTPTest.stop_HTTP_server): With the threaded servers,
we can simply use the socketserver.shutdown() method to close the
server instead of sending a QUIT command
* HTTPServer.py (StoppabelHTTPServer.serve_forever): Delete method. No
need to override this method anymore.
(WgetHTTPRequestHandler.do_QUIT): No longer required
(HTTPd): Rename self.server to self.server_inst to reduce ambiguity
when referenced from WgetTest
2013-09-08 Darshit Shah <darnir@gmail.com> 2013-09-08 Darshit Shah <darnir@gmail.com>
* README (File Structure): Add explanation about various variables * README (File Structure): Add explanation about various variables

View File

@ -3,7 +3,6 @@ from base64 import b64encode
from random import random from random import random
from hashlib import md5 from hashlib import md5
import threading import threading
import os
import re import re
@ -29,11 +28,6 @@ class StoppableHTTPServer (HTTPServer):
self.server_configs = conf_dict self.server_configs = conf_dict
self.fileSys = filelist self.fileSys = filelist
def serve_forever (self):
self.stop = False
while not self.stop:
self.handle_request ()
class WgetHTTPRequestHandler (BaseHTTPRequestHandler): class WgetHTTPRequestHandler (BaseHTTPRequestHandler):
@ -43,11 +37,6 @@ class WgetHTTPRequestHandler (BaseHTTPRequestHandler):
r_list = self.rules.get (name) if name in self.rules else None r_list = self.rules.get (name) if name in self.rules else None
return r_list return r_list
def do_QUIT (self):
self.send_response (200)
self.end_headers ()
self.server.stop = True
class _Handler (WgetHTTPRequestHandler): class _Handler (WgetHTTPRequestHandler):
@ -394,13 +383,13 @@ class HTTPd (threading.Thread):
threading.Thread.__init__ (self) threading.Thread.__init__ (self)
if addr is None: if addr is None:
addr = ('localhost', 0) addr = ('localhost', 0)
self.server = self.server_class (addr, self.handler) self.server_inst = self.server_class (addr, self.handler)
self.server_address = self.server.socket.getsockname()[:2] self.server_address = self.server_inst.socket.getsockname()[:2]
def run (self): def run (self):
self.server.serve_forever () self.server_inst.serve_forever ()
def server_conf (self, file_list, server_rules): def server_conf (self, file_list, server_rules):
self.server.server_conf (file_list, server_rules) self.server_inst.server_conf (file_list, server_rules)
# vim: set ts=8 sts=4 sw=3 tw=0 et : # vim: set ts=8 sts=4 sw=3 tw=0 et :

View File

@ -4,7 +4,6 @@ import shlex
import sys import sys
import traceback import traceback
import HTTPServer import HTTPServer
import http.client
import re import re
from subprocess import call from subprocess import call
from ColourTerm import printer from ColourTerm import printer
@ -254,9 +253,7 @@ class HTTPTest (CommonMethods):
return server return server
def stop_HTTP_Server (self): def stop_HTTP_Server (self):
conn = http.client.HTTPConnection (self.domain.strip ('/')) self.server.server_inst.shutdown ()
conn.request ("QUIT", "/")
conn.getresponse ()
""" WgetFile is a File Data Container object """ """ WgetFile is a File Data Container object """