예제 #1
0
파일: block.py 프로젝트: astrofrog/pyasdf
 def get_external_uri(self, uri, index):
     """
     Given a main URI and an index number, return a new URI for
     saving an external block.
     """
     if uri is None:
         uri = ''
     parts = list(urlparse.urlparse(uri))
     path = parts[2]
     dirname, filename = os.path.split(path)
     filename = self.get_external_filename(filename, index)
     path = os.path.join(dirname, filename)
     parts[2] = path
     return urlparse.urlunparse(parts)
예제 #2
0
파일: block.py 프로젝트: nden/pyasdf
 def get_external_uri(self, uri, index):
     """
     Given a main URI and an index number, return a new URI for
     saving an external block.
     """
     if uri is None:
         uri = ''
     parts = list(urlparse.urlparse(uri))
     path = parts[2]
     dirname, filename = os.path.split(path)
     filename = self.get_external_filename(filename, index)
     path = os.path.join(dirname, filename)
     parts[2] = path
     return urlparse.urlunparse(parts)
예제 #3
0
def relative_uri(source, target):
    """
    Make a relative URI from source to target.
    """
    su = urlparse.urlparse(source)
    tu = urlparse.urlparse(target)
    extra = list(tu[3:])
    relative = None
    if tu[0] == '' and tu[1] == '':
        if tu[2] == su[2]:
            relative = ''
        elif not tu[2].startswith('/'):
            relative = tu[2]
    elif su[0:2] != tu[0:2]:
        return target

    if relative is None:
        relative = os.path.relpath(tu[2], os.path.dirname(su[2]))
    if relative == '.':
        relative = ''
    relative = urlparse.urlunparse(["", "", relative] + extra)
    return relative
예제 #4
0
파일: generic_io.py 프로젝트: nden/pyasdf
def relative_uri(source, target):
    """
    Make a relative URI from source to target.
    """
    su = urlparse.urlparse(source)
    tu = urlparse.urlparse(target)
    extra = list(tu[3:])
    relative = None
    if tu[0] == '' and tu[1] == '':
        if tu[2] == su[2]:
            relative = ''
        elif not tu[2].startswith('/'):
            relative = tu[2]
    elif su[0:2] != tu[0:2]:
        return target

    if relative is None:
        relative = os.path.relpath(tu[2], su[2])
    if relative == '.':
        relative = ''
    relative = urlparse.urlunparse(["", "", relative] + extra)
    return relative
예제 #5
0
파일: util.py 프로젝트: nden/pyasdf
def get_base_uri(uri):
    """
    For a given URI, return the part without any fragment.
    """
    parts = urlparse.urlparse(uri)
    return urlparse.urlunparse(list(parts[:5]) + [''])
예제 #6
0
def get_base_uri(uri):
    """
    For a given URI, return the part without any fragment.
    """
    parts = urlparse.urlparse(uri)
    return urlparse.urlunparse(list(parts[:5]) + [''])