@@ -0,0 +1,1852 @@
+# -*- coding: utf-8 -*-%0A'''%0Asalt:// URL utils%0A'''%0A%0A# Import salt libs%0Afrom salt.ext.six.moves.urllib.parse import urlparse, urlunparse  # pylint: disable=import-error,no-name-in-module%0Aimport salt.utils%0A%0A%0Adef parse(url):%0A    '''%0A    Parse a salt:// URL; return the path and a possible saltenv query.%0A    '''%0A    if not url.startswith('salt://'):%0A        return url, None%0A%0A    # urlparse will split on valid filename chars such as '?' and '&'%0A    resource = url.split('salt://', 1)%5B-1%5D%0A%0A    if '?env=' in resource:%0A        salt.utils.warn_until(%0A            'Boron',%0A            'Passing a salt environment should be done using %5C'saltenv%5C' '%0A            'not %5C'env%5C'. This functionality will be removed in Salt Boron.'%0A        )%0A        path, saltenv = resource.split('?env=', 1)%0A    elif '?saltenv=' in resource:%0A        path, saltenv = resource.split('?saltenv=', 1)%0A    else:%0A        path, saltenv = resource, None%0A%0A    if salt.utils.is_windows():%0A        path = salt.utils.sanitize_win_path_string(path)%0A%0A    return path, saltenv%0A%0A%0Adef create(path, saltenv=None):%0A    '''%0A    join %60path%60 and %60saltenv%60 into a 'salt://' URL.%0A    '''%0A    if salt.utils.is_windows():%0A        path = salt.utils.sanitize_win_path_string(path)%0A%0A    query = u'saltenv=%7B0%7D'.format(saltenv) if saltenv else ''%0A    url = urlunparse(('file', '', path, '', query, ''))%0A    return u'salt://%7B0%7D'.format(url%5Blen('file:///'):%5D)%0A%0A%0Adef add_env(url, saltenv):%0A    '''%0A    append %60saltenv%60 to %60url%60 as a query parameter to a 'salt://' url%0A    '''%0A    if not url.startswith('salt://'):%0A        return url%0A%0A    path, senv = parse(url)%0A    return create(path, saltenv)%0A%0A%0Adef split_env(url):%0A    '''%0A    remove the saltenv query parameter from a 'salt://' url%0A    '''%0A    if not url.startswith('salt://'):%0A        return url, None%0A%0A    path, senv = parse(url)%0A    return create(path), senv%0A

add salt:// URL utils