Hi UBI,
 Would you please add some description with one example to let us how to 
use it for saving Tiddlywiki

--Mohammad

On Saturday, December 28, 2019 at 8:22:43 PM UTC+3:30, UBi wrote:
>
> Hello,
>
> I had some spare time recently, so I tried to re-implement the Ruby Server 
> in Python:
>
> #!/usr/bin/python3
>
> from http.server import SimpleHTTPRequestHandler, HTTPServer
> import datetime, shutil, os
>
> def makebackup(src):
>     (srcpath, srcfile) = os.path.split(src)
>     tstamp=datetime.datetime.now().strftime("%Y%m%d%H%M%S")
>     dstpath = os.path.join(srcpath,'twBackups')
>     if not os.path.exists(dstpath):
>         os.mkdir(dstpath)
>     shutil.copyfile(src, os.path.join(dstpath, srcfile+'.'+tstamp))
>
> class ExtendedHandler(SimpleHTTPRequestHandler):
>     def do_OPTIONS(self):
>         self.send_response(200, 'OK')
>         self.send_header('allow',
> 'GET,HEAD,POST,OPTIONS,CONNECT,PUT,DAV,dav')
>         self.send_header('x-api-access-type','file')
>         self.send_header('dav','tw5/put')
>         self.end_headers()
>     def do_PUT(self):
>         length = int(self.headers['Content-Length'])
>         path = self.translate_path(self.path)
>         makebackup(path)
>         with open(path, "wb") as dst:
>             dst.write(self.rfile.read(length))
>         self.send_response(200, 'OK')
>         self.send_header('Content-Type', 'text/html')
>         self.end_headers()
>
> os.chdir(os.path.dirname(os.path.abspath(__file__)))
> HTTPServer(('localhost',8080),ExtendedHandler).serve_forever()
>
> It works for me :-)
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/58903513-abeb-458c-8006-7a4896b07fdd%40googlegroups.com.

Reply via email to