From 28259cd88b75a51cf883f70023e266b303e809d6 Mon Sep 17 00:00:00 2001 From: Eric Coissac Date: Tue, 25 Jul 2017 13:05:58 +0200 Subject: [PATCH] Beginning of URI decoder -- !!! NOT YET FULLY IMPLEMENTED !!! --- python/obitools3/uri/__init__.py | 1 + python/obitools3/uri/decode.pyx | 66 ++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 python/obitools3/uri/__init__.py create mode 100644 python/obitools3/uri/decode.pyx diff --git a/python/obitools3/uri/__init__.py b/python/obitools3/uri/__init__.py new file mode 100644 index 0000000..991aa1a --- /dev/null +++ b/python/obitools3/uri/__init__.py @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/python/obitools3/uri/decode.pyx b/python/obitools3/uri/decode.pyx new file mode 100644 index 0000000..8c88270 --- /dev/null +++ b/python/obitools3/uri/decode.pyx @@ -0,0 +1,66 @@ +from urllib.parse import urlparse +from os.path import isdir, isfile, basename, join + +from obitools3.utils import tobytes +from obitools3.dms.dms import DMS + + + + +cdef findDMS(bytes path,create=False): + cdef int pos=1 + cdef bytes dmspath + cdef bytes dmsdirname + cdef bytes dmsname + + while(pos>0): + pos = path.find(b"/",pos) + if pos>0: + dirpath=path[0:pos] + else: + dirpath=path + if not isdir(dirpath): + dmsdirname=dmspath+b".obidms" + if isdir(dmsdirname): + dmsname=basename(dmspath) + if isfile(join(dmsdirname,dmsname+b"_infos")): + dms = DMS.open(dmspath) + if pos > 0: + return(dms,path[pos+1:]) + else: + return(dms,b'') + elif create: + dms=DMS.new(dmspath) + if pos > 0: + return(dms,path[pos+1:]) + else: + return(dms,b'') + + pos=pos+1 + return None + + + + +cpdef openURI(uri,defaultDMS=None,input=True): + cdef bytes urib = tobytes(uri) + cdef bytes scheme + + urip = urlparse(urib) + + scheme = urip.scheme + + if scheme==b"" : + if defaultDMS is not None: + + scheme=b'file' + dms = findDMS(urip.path) + if dms is not None: + scheme=b"dms" + + + if scheme==b"dms" : + + elif scheme==b"file" : + +