Support programatically setting Handler class variables

This commit is contained in:
Darshit Shah 2013-12-29 16:37:28 +05:30 committed by Giuseppe Scrivano
parent 7e1f4c1abc
commit 7effa90359
3 changed files with 30 additions and 3 deletions

View File

@ -1,3 +1,12 @@
2013-12-27 Darshit Shah <darnir@gmail.com>
* WgetTest.py: Add modeline
(CommonMethods.ServerConf): New pre-test hook that sets
BaseHTTPRequestHandler class variables in all available servers
* HTTPServer.py (HTTPd.ServerConf): Call the respective method in the Server
to set the class variables
(StoppableHTTPServer.server_sett): Set the handler class variables
2013-12-26 Darshit Shah <darnir@gmail.com>
* WgetTest.py (HTTPTest.call_test): Correct the call to stop_HTTP_Server.

View File

@ -31,6 +31,10 @@ class StoppableHTTPServer (HTTPServer):
self.server_configs = conf_dict
self.fileSys = filelist
def server_sett (self, settings):
for settings_key in settings:
setattr (self.RequestHandlerClass, settings_key, settings[settings_key])
def get_req_headers (self):
return self.request_headers
@ -264,8 +268,13 @@ class _Handler (WgetHTTPRequestHandler):
auth_type = auth_header.split(' ')[0] if auth_header else required_auth
else:
auth_type = required_auth
assert hasattr (self, "authorize_" + auth_type)
is_auth = getattr (self, "authorize_" + auth_type) (auth_header, auth_rule)
try:
assert hasattr (self, "authorize_" + auth_type)
is_auth = getattr (self, "authorize_" + auth_type) (auth_header, auth_rule)
except AssertionError:
raise ServerError ("Authentication Mechanism " + auth_rule + " not supported")
except AttributeError as ae:
raise ServerError (ae.__str__())
if is_auth is False:
raise ServerError ("Unable to Authenticate")
@ -427,4 +436,7 @@ class HTTPd (threading.Thread):
def server_conf (self, file_list, server_rules):
self.server_inst.server_conf (file_list, server_rules)
# vim: set ts=8 sts=4 sw=3 tw=0 et :
def server_sett (self, settings):
self.server_inst.server_sett (settings)
# vim: set ts=4 sts=4 sw=4 tw=80 et :

View File

@ -178,6 +178,10 @@ class CommonMethods:
file_handler.write (file_obj.content)
file_handler.close ()
def ServerConf (self, server_settings):
for i in range (0, self.servers):
self.server_list[i].server_sett (server_settings)
""" Test Option Function Calls """
def WgetCommands (self, command_list):
@ -316,3 +320,5 @@ class WgetFile:
self.content = content
self.timestamp = timestamp
self.rules = rules
# vim: set ts=4 sts=4 sw=4 tw=80 et :