aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJauhien Piatlicki (jauhien) <piatlicki@gmail.com>2013-09-16 00:38:06 +0200
committerJauhien Piatlicki (jauhien) <piatlicki@gmail.com>2013-09-16 00:38:06 +0200
commitfe0840ffb8a3991164bb9aa68bf0a370e1b1e132 (patch)
tree5a3318148b8d6112ea41ce077ff58226d89078a0 /tests
parentadd tests for FileJSON with serialization (diff)
downloadg-sorcery-fe0840ffb8a3991164bb9aa68bf0a370e1b1e132.tar.gz
g-sorcery-fe0840ffb8a3991164bb9aa68bf0a370e1b1e132.tar.bz2
g-sorcery-fe0840ffb8a3991164bb9aa68bf0a370e1b1e132.zip
tests/server: serve files from a given directory
Diffstat (limited to 'tests')
-rw-r--r--tests/server.py19
1 files changed, 17 insertions, 2 deletions
diff --git a/tests/server.py b/tests/server.py
index 41767fc..6cb16e6 100644
--- a/tests/server.py
+++ b/tests/server.py
@@ -11,6 +11,7 @@
:license: GPL-2, see LICENSE for more details.
"""
+import os
import threading
from g_sorcery.compatibility import py2k
@@ -22,12 +23,26 @@ else:
from http.server import HTTPServer
from http.server import SimpleHTTPRequestHandler
+def HTTPRequestHandlerGenerator(direct):
+
+ class HTTPRequestHandler(SimpleHTTPRequestHandler):
+ directory = direct
+
+ def __init__(self, request, client_address, server):
+ super(HTTPRequestHandler, self).__init__(request, client_address, server)
+
+ def translate_path(self, path):
+ return os.path.join(self.directory, path[1:])
+
+ return HTTPRequestHandler
+
+
class Server(threading.Thread):
- def __init__(self):
+ def __init__(self, directory):
super(Server, self).__init__()
HTTPServer.allow_reuse_address = True
server_address = ('127.0.0.1', 8080)
- self.httpd = HTTPServer(server_address, SimpleHTTPRequestHandler)
+ self.httpd = HTTPServer(server_address, HTTPRequestHandlerGenerator(directory))
def run(self):
self.httpd.serve_forever()