簡単な Python WebDAVサーバー用のより良いコード スニペットを持っている人はいますか? 以下のコード (いくつかの Google 検索結果からまとめたもの) は Python 2.6 で動作するように見えますが、誰かが以前に使用したことのある、もう少しテスト済みで完全なものを持っているのではないかと思います。サードパーティのパッケージよりも stdlib のみのスニペットを使用したいと思います。一部のテストコードがヒットするためのものであるため、生産に値する必要はありません。
import httplib
import BaseHTTPServer
class WebDAV(BaseHTTPServer.BaseHTTPRequestHandler):
"""
Ultra-simplistic WebDAV server.
"""
def do_PUT(self):
path = os.path.normpath(self.path)
if os.path.isabs(path):
path = path[1:] # safe assumption due to normpath above
directory = os.path.dirname(path)
if not os.path.isdir(directory):
os.makedirs(directory)
content_length = int(self.headers['Content-Length'])
with open(path, "w") as f:
f.write(self.rfile.read(content_length))
self.send_response(httplib.OK)
def server_main(server_class=BaseHTTPServer.HTTPServer,
handler_class=WebDAV):
server_class(('', 9231), handler_class).serve_forever()