From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id D096D138200 for ; Sun, 15 Sep 2013 22:38:28 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id C4593E09A4; Sun, 15 Sep 2013 22:38:26 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 5AF5CE09A4 for ; Sun, 15 Sep 2013 22:38:26 +0000 (UTC) Received: from hornbill.gentoo.org (hornbill.gentoo.org [94.100.119.163]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 60C7233EB95 for ; Sun, 15 Sep 2013 22:38:25 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id EB781E5467 for ; Sun, 15 Sep 2013 22:38:22 +0000 (UTC) From: "Jauhien Piatlicki" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Jauhien Piatlicki" Message-ID: <1379284686.fe0840ffb8a3991164bb9aa68bf0a370e1b1e132.jauhien@gentoo> Subject: [gentoo-commits] proj/g-sorcery:master commit in: tests/ X-VCS-Repository: proj/g-sorcery X-VCS-Files: tests/server.py X-VCS-Directories: tests/ X-VCS-Committer: jauhien X-VCS-Committer-Name: Jauhien Piatlicki X-VCS-Revision: fe0840ffb8a3991164bb9aa68bf0a370e1b1e132 X-VCS-Branch: master Date: Sun, 15 Sep 2013 22:38:22 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: bc1a312c-0fa8-43c2-af44-4f24a3c76bd0 X-Archives-Hash: 839cb70becde1d3fac6cb098ee5d68a8 commit: fe0840ffb8a3991164bb9aa68bf0a370e1b1e132 Author: Jauhien Piatlicki (jauhien) gmail com> AuthorDate: Sun Sep 15 22:38:06 2013 +0000 Commit: Jauhien Piatlicki gmail com> CommitDate: Sun Sep 15 22:38:06 2013 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/g-sorcery.git;a=commit;h=fe0840ff tests/server: serve files from a given directory --- tests/server.py | 19 +++++++++++++++++-- 1 file 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()