# HG changeset patch # Parent 56f71f02206ebe3413caa53b614403617ac544ed Issue #18828: Allow urljoin() to work with arbitrary schemes diff -r 56f71f02206e -r 7b8e83c924f1 Lib/test/test_urlparse.py --- a/Lib/test/test_urlparse.py Tue Dec 16 18:17:18 2014 -0800 +++ b/Lib/test/test_urlparse.py Wed Dec 17 04:18:38 2014 +0000 @@ -375,6 +375,10 @@ self.checkJoin('', 'http://a/./g', 'http://a/./g') self.checkJoin('svn://pathtorepo/dir1', 'dir2', 'svn://pathtorepo/dir2') self.checkJoin('svn+ssh://pathtorepo/dir1', 'dir2', 'svn+ssh://pathtorepo/dir2') + self.checkJoin('x-arbitrary-scheme://netloc/a', '/b', + 'x-arbitrary-scheme://netloc/b') + self.checkJoin('x-arbitrary-scheme://netloc/path', '?query', + 'x-arbitrary-scheme://netloc/path?query') # XXX: The following tests are no longer compatible with RFC3986 # self.checkJoin(SIMPLE_BASE, '../../../g','http://a/../g') diff -r 56f71f02206e -r 7b8e83c924f1 Lib/urllib/parse.py --- a/Lib/urllib/parse.py Tue Dec 16 18:17:18 2014 -0800 +++ b/Lib/urllib/parse.py Wed Dec 17 04:18:38 2014 +0000 @@ -37,10 +37,6 @@ "unquote", "unquote_plus", "unquote_to_bytes"] # A classification of schemes ('' means apply by default) -uses_relative = ['ftp', 'http', 'gopher', 'nntp', 'imap', - 'wais', 'file', 'https', 'shttp', 'mms', - 'prospero', 'rtsp', 'rtspu', '', 'sftp', - 'svn', 'svn+ssh'] uses_netloc = ['ftp', 'http', 'gopher', 'nntp', 'telnet', 'imap', 'wais', 'file', 'mms', 'https', 'shttp', 'snews', 'prospero', 'rtsp', 'rtspu', 'rsync', '', @@ -416,13 +412,12 @@ scheme, netloc, path, params, query, fragment = \ urlparse(url, bscheme, allow_fragments) - if scheme != bscheme or scheme not in uses_relative: + if scheme != bscheme: return _coerce_result(url) - if scheme in uses_netloc: - if netloc: - return _coerce_result(urlunparse((scheme, netloc, path, - params, query, fragment))) - netloc = bnetloc + if netloc: + return _coerce_result(urlunparse((scheme, netloc, path, + params, query, fragment))) + netloc = bnetloc if not path and not params: path = bpath