Last active
September 18, 2019 22:23
-
-
Save Zsailer/1de7f236e896398a0cc135b30e4c74bc to your computer and use it in GitHub Desktop.
wsgidav, webdav-client3, and tornado
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from tornado import web, wsgi, httpserver, ioloop | |
from wsgidav.wsgidav_app import WsgiDAVApp | |
from webdav3.client import Client | |
host = '127.0.0.1' | |
port = 8081 | |
path = os.path.join(os.getcwd(), 'hubshare') | |
config = { | |
"host": host, | |
"port": port, | |
"provider_mapping": {"/dav": path}, | |
"verbose": 1, | |
"simple_dc": {"user_mapping": {"*": True} } #{"*": {"zach": {"password": "test"}}}} | |
} | |
webdav_app = WsgiDAVApp(config) | |
webdav_tornado_app = wsgi.WSGIContainer(webdav_app) | |
client_config = { | |
"webdav_hostname": "http://{}:{}/dav".format(host, port), | |
} | |
webdav_client = Client(client_config) | |
class MainHandler(web.RequestHandler): | |
@property | |
def webdav_client(self): | |
return self.settings.get('webdav_client') | |
async def get(self): | |
import requests | |
r = await requests.get('http://localhost:8081/dav') | |
print(r.text) | |
#print(self.webdav_client.list()) | |
class WebDavHandler(web.FallbackHandler): | |
SUPPORTED_METHODS = ( | |
'COPY', | |
'LOCK', | |
'MKCOL', | |
'MOVE', | |
'PROPFIND', | |
'PROPPATCH', | |
'UNLOCK', | |
) | |
handlers = [] | |
handlers.append(('/test', MainHandler)) | |
handlers.append(( | |
'/dav/.*', | |
WebDavHandler, | |
{'fallback':webdav_tornado_app} | |
)) | |
tornado_app = web.Application(handlers, webdav_client=webdav_client) | |
server = httpserver.HTTPServer(tornado_app) | |
server.listen(port, address=host) | |
ioloop.IOLoop.current().start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment