From 9a5bc1d0011740dce72e848fb741e5205ac1f1de Mon Sep 17 00:00:00 2001 From: Senthil Kumaran Date: Wed, 14 Jul 2010 10:39:35 +0000 Subject: [PATCH] Merged revisions 82881 via svnmerge from svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r82881 | senthil.kumaran | 2010-07-14 15:51:22 +0530 (Wed, 14 Jul 2010) | 3 lines Fix Issue5842 - Moving the tests out of urllib.parse module ........ --- Lib/test/test_urlparse.py | 32 ++++++++++++++++++ Lib/urlparse.py | 69 --------------------------------------- 2 files changed, 32 insertions(+), 69 deletions(-) diff --git a/Lib/test/test_urlparse.py b/Lib/test/test_urlparse.py index 07256a2a1ec..80e4d91193d 100644 --- a/Lib/test/test_urlparse.py +++ b/Lib/test/test_urlparse.py @@ -7,6 +7,7 @@ import urlparse RFC1808_BASE = "http://a/b/c/d;p?q#f" RFC2396_BASE = "http://a/b/c/d;p?q" RFC3986_BASE = 'http://a/b/c/d;p?q' +SIMPLE_BASE = 'http://a/b/c/d' # A list of test cases. Each test case is a a two-tuple that contains # a string with the query and a dictionary with the expected result. @@ -294,6 +295,37 @@ class UrlParseTestCase(unittest.TestCase): #self.checkJoin(RFC3986_BASE, 'http:g','http:g') # strict parser self.checkJoin(RFC3986_BASE, 'http:g','http://a/b/c/g') # relaxed parser + def test_urljoins(self): + self.checkJoin(SIMPLE_BASE, 'g:h','g:h') + self.checkJoin(SIMPLE_BASE, 'http:g','http://a/b/c/g') + self.checkJoin(SIMPLE_BASE, 'http:','http://a/b/c/d') + self.checkJoin(SIMPLE_BASE, 'g','http://a/b/c/g') + self.checkJoin(SIMPLE_BASE, './g','http://a/b/c/g') + self.checkJoin(SIMPLE_BASE, 'g/','http://a/b/c/g/') + self.checkJoin(SIMPLE_BASE, '/g','http://a/g') + self.checkJoin(SIMPLE_BASE, '//g','http://g') + self.checkJoin(SIMPLE_BASE, '?y','http://a/b/c/d?y') + self.checkJoin(SIMPLE_BASE, 'g?y','http://a/b/c/g?y') + self.checkJoin(SIMPLE_BASE, 'g?y/./x','http://a/b/c/g?y/./x') + self.checkJoin(SIMPLE_BASE, '.','http://a/b/c/') + self.checkJoin(SIMPLE_BASE, './','http://a/b/c/') + self.checkJoin(SIMPLE_BASE, '..','http://a/b/') + self.checkJoin(SIMPLE_BASE, '../','http://a/b/') + self.checkJoin(SIMPLE_BASE, '../g','http://a/b/g') + self.checkJoin(SIMPLE_BASE, '../..','http://a/') + self.checkJoin(SIMPLE_BASE, '../../g','http://a/g') + self.checkJoin(SIMPLE_BASE, '../../../g','http://a/../g') + self.checkJoin(SIMPLE_BASE, './../g','http://a/b/g') + self.checkJoin(SIMPLE_BASE, './g/.','http://a/b/c/g/') + self.checkJoin(SIMPLE_BASE, '/./g','http://a/./g') + self.checkJoin(SIMPLE_BASE, 'g/./h','http://a/b/c/g/h') + self.checkJoin(SIMPLE_BASE, 'g/../h','http://a/b/c/h') + self.checkJoin(SIMPLE_BASE, 'http:g','http://a/b/c/g') + self.checkJoin(SIMPLE_BASE, 'http:','http://a/b/c/d') + self.checkJoin(SIMPLE_BASE, 'http:?y','http://a/b/c/d?y') + self.checkJoin(SIMPLE_BASE, 'http:g?y','http://a/b/c/g?y') + self.checkJoin(SIMPLE_BASE, 'http:g?y/./x','http://a/b/c/g?y/./x') + def test_RFC2732(self): for url, hostname, port in [ ('http://Test.python.org:5432/foo/', 'test.python.org', 5432), diff --git a/Lib/urlparse.py b/Lib/urlparse.py index e134770644f..6261b24e78e 100644 --- a/Lib/urlparse.py +++ b/Lib/urlparse.py @@ -395,72 +395,3 @@ def parse_qsl(qs, keep_blank_values=0, strict_parsing=0): r.append((name, value)) return r - - -test_input = """ - http://a/b/c/d - - g:h = - http:g = - http: = - g = - ./g = - g/ = - /g = - //g = - ?y = - g?y = - g?y/./x = - . = - ./ = - .. = - ../ = - ../g = - ../.. = - ../../g = - ../../../g = - ./../g = - ./g/. = - /./g = - g/./h = - g/../h = - http:g = - http: = - http:?y = - http:g?y = - http:g?y/./x = -""" - -def test(): - import sys - base = '' - if sys.argv[1:]: - fn = sys.argv[1] - if fn == '-': - fp = sys.stdin - else: - fp = open(fn) - else: - try: - from cStringIO import StringIO - except ImportError: - from StringIO import StringIO - fp = StringIO(test_input) - for line in fp: - words = line.split() - if not words: - continue - url = words[0] - parts = urlparse(url) - print '%-10s : %s' % (url, parts) - abs = urljoin(base, url) - if not base: - base = abs - wrapped = '' % abs - print '%-10s = %s' % (url, wrapped) - if len(words) == 3 and words[1] == '=': - if wrapped != words[2]: - print 'EXPECTED', words[2], '!!!!!!!!!!' - -if __name__ == '__main__': - test()