mirror of
https://github.com/moparisthebest/wget
synced 2024-07-03 16:38:41 -04:00
Minor optimizations of Python tests
This commit is contained in:
parent
7cd528a4e9
commit
796da8da3a
@ -1,3 +1,18 @@
|
|||||||
|
2014-10-01 Darshit Shah <darnir@gmail.com>
|
||||||
|
|
||||||
|
* Makefile.am: Run the tests in Python's Optimizedmode
|
||||||
|
* conf/__init__.py (gen_hook): Use try..except instead of if..else
|
||||||
|
* misc/color_terminal.py: System and check will not change while a test is
|
||||||
|
run. Do not test for them on every invokation of printer()
|
||||||
|
* server/http/http_server.py: The ssl and re modules are required by
|
||||||
|
specific functions. Load them lazily
|
||||||
|
(HTTPSServer.__init__): Lazy load ssl module here
|
||||||
|
(_handler.parse_range_header): Lazy load re module here
|
||||||
|
(_Handler.get_rule_list): get() can return a default value. Use it
|
||||||
|
(_Handler.guess_type): Same
|
||||||
|
(_Handler.is_authorized): Unused function artefact. Remove
|
||||||
|
(_Handler.reject_headers): Unused function artefact. Remove
|
||||||
|
|
||||||
2014-10-08 Darshit Shah <darnir@gmail.com>
|
2014-10-08 Darshit Shah <darnir@gmail.com>
|
||||||
|
|
||||||
* Makefile.am: Fix EXTRA_DIST variable for make distcheck
|
* Makefile.am: Fix EXTRA_DIST variable for make distcheck
|
||||||
|
@ -3,7 +3,6 @@ import os
|
|||||||
# this file implements the mechanism of conf class auto-registration,
|
# this file implements the mechanism of conf class auto-registration,
|
||||||
# don't modify this file if you have no idea what you're doing
|
# don't modify this file if you have no idea what you're doing
|
||||||
|
|
||||||
|
|
||||||
def gen_hook():
|
def gen_hook():
|
||||||
hook_table = {}
|
hook_table = {}
|
||||||
|
|
||||||
@ -24,9 +23,9 @@ def gen_hook():
|
|||||||
return cls
|
return cls
|
||||||
|
|
||||||
def find_hook(name):
|
def find_hook(name):
|
||||||
if name in hook_table:
|
try:
|
||||||
return hook_table[name]
|
return hook_table[name]
|
||||||
else:
|
except:
|
||||||
raise AttributeError
|
raise AttributeError
|
||||||
|
|
||||||
return Wrapper, find_hook
|
return Wrapper, find_hook
|
||||||
|
@ -25,14 +25,12 @@ T_COLORS = {
|
|||||||
'ENDC' : '\033[0m'
|
'ENDC' : '\033[0m'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
system = True if platform.system() == 'Linux' else False
|
||||||
|
check = False if getenv("MAKE_CHECK") == 'True' else True
|
||||||
|
|
||||||
def printer (color, string):
|
def printer (color, string):
|
||||||
if platform.system () == 'Linux':
|
if system and check:
|
||||||
if getenv ("MAKE_CHECK", "False") == "True":
|
|
||||||
print (string)
|
|
||||||
else:
|
|
||||||
print (T_COLORS.get (color) + string + T_COLORS.get ('ENDC'))
|
print (T_COLORS.get (color) + string + T_COLORS.get ('ENDC'))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print (string)
|
print (string)
|
||||||
|
|
||||||
|
@ -7,10 +7,9 @@ from random import random
|
|||||||
from hashlib import md5
|
from hashlib import md5
|
||||||
import threading
|
import threading
|
||||||
import socket
|
import socket
|
||||||
import re
|
|
||||||
import ssl
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
|
||||||
class StoppableHTTPServer (HTTPServer):
|
class StoppableHTTPServer (HTTPServer):
|
||||||
""" This class extends the HTTPServer class from default http.server library
|
""" This class extends the HTTPServer class from default http.server library
|
||||||
in Python 3. The StoppableHTTPServer class is capable of starting an HTTP
|
in Python 3. The StoppableHTTPServer class is capable of starting an HTTP
|
||||||
@ -36,6 +35,7 @@ class HTTPSServer (StoppableHTTPServer):
|
|||||||
additional support for secure connections through SSL. """
|
additional support for secure connections through SSL. """
|
||||||
|
|
||||||
def __init__ (self, address, handler):
|
def __init__ (self, address, handler):
|
||||||
|
import ssl
|
||||||
BaseServer.__init__ (self, address, handler)
|
BaseServer.__init__ (self, address, handler)
|
||||||
# step one up because test suite change directory away from $srcdir (don't do that !!!)
|
# step one up because test suite change directory away from $srcdir (don't do that !!!)
|
||||||
CERTFILE = os.path.abspath(os.path.join('..', os.getenv('srcdir', '.'), 'certs', 'wget-cert.pem'))
|
CERTFILE = os.path.abspath(os.path.join('..', os.getenv('srcdir', '.'), 'certs', 'wget-cert.pem'))
|
||||||
@ -60,8 +60,7 @@ class _Handler (BaseHTTPRequestHandler):
|
|||||||
requests. """
|
requests. """
|
||||||
|
|
||||||
def get_rule_list (self, name):
|
def get_rule_list (self, name):
|
||||||
r_list = self.rules.get (name) if name in self.rules else None
|
return self.rules.get(name)
|
||||||
return r_list
|
|
||||||
|
|
||||||
# The defailt protocol version of the server we run is HTTP/1.1 not
|
# The defailt protocol version of the server we run is HTTP/1.1 not
|
||||||
# HTTP/1.0 which is the default with the http.server module.
|
# HTTP/1.0 which is the default with the http.server module.
|
||||||
@ -134,6 +133,7 @@ class _Handler (BaseHTTPRequestHandler):
|
|||||||
""" Helper functions for the Handlers. """
|
""" Helper functions for the Handlers. """
|
||||||
|
|
||||||
def parse_range_header (self, header_line, length):
|
def parse_range_header (self, header_line, length):
|
||||||
|
import re
|
||||||
if header_line is None:
|
if header_line is None:
|
||||||
return None
|
return None
|
||||||
if not header_line.startswith ("bytes="):
|
if not header_line.startswith ("bytes="):
|
||||||
@ -315,23 +315,6 @@ class _Handler (BaseHTTPRequestHandler):
|
|||||||
if is_auth is False:
|
if is_auth is False:
|
||||||
raise ServerError ("Unable to Authenticate")
|
raise ServerError ("Unable to Authenticate")
|
||||||
|
|
||||||
def is_authorized (self):
|
|
||||||
is_auth = True
|
|
||||||
auth_rule = self.get_rule_list ('Authentication')
|
|
||||||
if auth_rule:
|
|
||||||
auth_header = self.headers.get ("Authorization")
|
|
||||||
req_auth = auth_rule.auth_type
|
|
||||||
if req_auth == "Both" or req_auth == "Both_inline":
|
|
||||||
auth_type = auth_header.split(' ')[0] if auth_header else req_auth
|
|
||||||
else:
|
|
||||||
auth_type = req_auth
|
|
||||||
assert hasattr (self, "authorize_" + auth_type)
|
|
||||||
is_auth = getattr (self, "authorize_" + auth_type) (auth_header, auth_rule)
|
|
||||||
if is_auth is False:
|
|
||||||
self.send_response (401)
|
|
||||||
self.send_challenge (auth_type)
|
|
||||||
self.finish_headers ()
|
|
||||||
return is_auth
|
|
||||||
|
|
||||||
def ExpectHeader (self, header_obj):
|
def ExpectHeader (self, header_obj):
|
||||||
exp_headers = header_obj.headers
|
exp_headers = header_obj.headers
|
||||||
@ -342,6 +325,7 @@ class _Handler (BaseHTTPRequestHandler):
|
|||||||
self.finish_headers ()
|
self.finish_headers ()
|
||||||
raise ServerError ("Header " + header_line + " not found")
|
raise ServerError ("Header " + header_line + " not found")
|
||||||
|
|
||||||
|
|
||||||
def RejectHeader (self, header_obj):
|
def RejectHeader (self, header_obj):
|
||||||
rej_headers = header_obj.headers
|
rej_headers = header_obj.headers
|
||||||
for header_line in rej_headers:
|
for header_line in rej_headers:
|
||||||
@ -351,18 +335,6 @@ class _Handler (BaseHTTPRequestHandler):
|
|||||||
self.finish_headers ()
|
self.finish_headers ()
|
||||||
raise ServerError ("Header " + header_line + ' received')
|
raise ServerError ("Header " + header_line + ' received')
|
||||||
|
|
||||||
def reject_headers (self):
|
|
||||||
rej_headers = self.get_rule_list ("RejectHeader")
|
|
||||||
if rej_headers:
|
|
||||||
rej_headers = rej_headers.headers
|
|
||||||
for header_line in rej_headers:
|
|
||||||
header_re = self.headers.get (header_line)
|
|
||||||
if header_re is not None and header_re == rej_headers[header_line]:
|
|
||||||
self.send_error (400, 'Blacklisted Header was Sent')
|
|
||||||
self.end_headers ()
|
|
||||||
return False
|
|
||||||
return True
|
|
||||||
|
|
||||||
def __log_request (self, method):
|
def __log_request (self, method):
|
||||||
req = method + " " + self.path
|
req = method + " " + self.path
|
||||||
self.server.request_headers.append (req)
|
self.server.request_headers.append (req)
|
||||||
@ -438,11 +410,7 @@ class _Handler (BaseHTTPRequestHandler):
|
|||||||
".css" : "text/css",
|
".css" : "text/css",
|
||||||
".html" : "text/html"
|
".html" : "text/html"
|
||||||
}
|
}
|
||||||
if ext in extension_map:
|
return extension_map.get(ext, "text/plain")
|
||||||
return extension_map[ext]
|
|
||||||
else:
|
|
||||||
return "text/plain"
|
|
||||||
|
|
||||||
|
|
||||||
class HTTPd (threading.Thread):
|
class HTTPd (threading.Thread):
|
||||||
server_class = StoppableHTTPServer
|
server_class = StoppableHTTPServer
|
||||||
|
@ -116,9 +116,8 @@ class BaseTest:
|
|||||||
# 1 a
|
# 1 a
|
||||||
# 5 e
|
# 5 e
|
||||||
# 3 c
|
# 3 c
|
||||||
protocol = protocol.lower()
|
|
||||||
for url in urls:
|
for url in urls:
|
||||||
cmd_line += '%s://%s/%s ' % (protocol, domain, url)
|
cmd_line += '%s://%s/%s ' % (protocol.lower(), domain, url)
|
||||||
|
|
||||||
print(cmd_line)
|
print(cmd_line)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user