Basic URI Parser according to STD66 aka RFC3986

       >>> urisplit("scheme://authority/path?query#fragment")
       ('scheme', 'authority', 'path', 'query', 'fragment')

def urisplit(uri):
    """
       Basic URI Parser according to STD66 aka RFC3986

       >>> urisplit("scheme://authority/path?query#fragment")
       ('scheme', 'authority', 'path', 'query', 'fragment')

    """
    inner_part = re.compile(r'\(\(.*?\)\)')
    m = inner_part.search(uri)
    inner_value = ''
    if m is not None:
        inner_value = uri[m.start():m.end()]
        uri = uri[:m.start()]+'__inner_part__'+uri[m.end():]
    # regex straight from STD 66 section B
    regex = '^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?'
    p = re.match(regex, uri).groups()
    scheme, authority, path, query, fragment = p[1], p[3], p[4], p[6], p[8]
    #if not path: path = None
    authority = authority.replace('__inner_part__', inner_value)
    if authority == '.':
        path = ''.join([authority, path])
        authority = None
    # bugfix: '#' might be a legal character in a file name
    # it only has special meaning in urls
    if scheme not in ['http', 'https']:
        if fragment:
            path = '#'.join([path, fragment])
            fragment = ''
    return (scheme, authority, path, query, fragment)