Beginning of URI decoder -- !!! NOT YET FULLY IMPLEMENTED !!!
This commit is contained in:
1
python/obitools3/uri/__init__.py
Normal file
1
python/obitools3/uri/__init__.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
|
66
python/obitools3/uri/decode.pyx
Normal file
66
python/obitools3/uri/decode.pyx
Normal file
@ -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" :
|
||||||
|
|
||||||
|
|
Reference in New Issue
Block a user