Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Lib/test/test_urlparse.py

    r2 r391  
    77RFC1808_BASE = "http://a/b/c/d;p?q#f"
    88RFC2396_BASE = "http://a/b/c/d;p?q"
    9 RFC3986_BASE = "http://a/b/c/d;p?q"
    10 
    11 # A list of test cases.  Each test case is a a two-tuple that contains
     9RFC3986_BASE = 'http://a/b/c/d;p?q'
     10SIMPLE_BASE  = 'http://a/b/c/d'
     11
     12# A list of test cases.  Each test case is a two-tuple that contains
    1213# a string with the query and a dictionary with the expected result.
    1314
     
    8283        for orig, expect in parse_qsl_test_cases:
    8384            result = urlparse.parse_qsl(orig, keep_blank_values=True)
    84             self.assertEqual(result, expect, "Error parsing %s" % repr(orig))
     85            self.assertEqual(result, expect, "Error parsing %r" % orig)
     86            expect_without_blanks = [v for v in expect if len(v[1])]
     87            result = urlparse.parse_qsl(orig, keep_blank_values=False)
     88            self.assertEqual(result, expect_without_blanks,
     89                    "Error parsing %r" % orig)
     90
    8591
    8692    def test_roundtrips(self):
     
    97103             ('mms', 'wms.sys.hinet.net', '/cts/Drama/09006251100.asf',
    98104              '', '')),
     105            ('nfs://server/path/to/file.txt',
     106             ('nfs', 'server', '/path/to/file.txt',  '', '', ''),
     107             ('nfs', 'server', '/path/to/file.txt', '', '')),
    99108            ('svn+ssh://svn.zope.org/repos/main/ZConfig/trunk/',
    100109             ('svn+ssh', 'svn.zope.org', '/repos/main/ZConfig/trunk/',
    101110              '', '', ''),
    102111             ('svn+ssh', 'svn.zope.org', '/repos/main/ZConfig/trunk/',
    103               '', ''))
     112              '', '')),
     113            ('git+ssh://git@github.com/user/project.git',
     114            ('git+ssh', 'git@github.com','/user/project.git',
     115             '','',''),
     116            ('git+ssh', 'git@github.com','/user/project.git',
     117             '', ''))
    104118            ]
    105119        for url, parsed, split in testcases:
     
    139153
    140154    def test_unparse_parse(self):
    141         for u in ['Python', './Python','x-newscheme://foo.com/stuff']:
     155        for u in ['Python', './Python','x-newscheme://foo.com/stuff','x://y','x:/y','x:/','/',]:
    142156            self.assertEqual(urlparse.urlunsplit(urlparse.urlsplit(u)), u)
    143157            self.assertEqual(urlparse.urlunparse(urlparse.urlparse(u)), u)
     
    188202        #self.checkJoin(RFC1808_BASE, 'http:', 'http:')
    189203
     204    def test_RFC2368(self):
     205        # Issue 11467: path that starts with a number is not parsed correctly
     206        self.assertEqual(urlparse.urlparse('mailto:1337@example.org'),
     207                ('mailto', '', '1337@example.org', '', '', ''))
     208
    190209    def test_RFC2396(self):
    191210        # cases from RFC 2396
    192 
    193 
    194211        self.checkJoin(RFC2396_BASE, 'g:h', 'g:h')
    195212        self.checkJoin(RFC2396_BASE, 'g', 'http://a/b/c/g')
     
    232249        self.checkJoin(RFC2396_BASE, 'g#s/../x', 'http://a/b/c/g#s/../x')
    233250
    234         #The following scenarios have been updated in RFC3986
    235         #self.checkJoin(RFC2396_BASE, '?y', 'http://a/b/c/?y')
    236         #self.checkJoin(RFC2396_BASE, ';x', 'http://a/b/c/;x')
    237 
    238251    def test_RFC3986(self):
     252        # Test cases from RFC3986
    239253        self.checkJoin(RFC3986_BASE, '?y','http://a/b/c/d;p?y')
    240254        self.checkJoin(RFC2396_BASE, ';x', 'http://a/b/c/;x')
     255        self.checkJoin(RFC3986_BASE, 'g:h','g:h')
     256        self.checkJoin(RFC3986_BASE, 'g','http://a/b/c/g')
     257        self.checkJoin(RFC3986_BASE, './g','http://a/b/c/g')
     258        self.checkJoin(RFC3986_BASE, 'g/','http://a/b/c/g/')
     259        self.checkJoin(RFC3986_BASE, '/g','http://a/g')
     260        self.checkJoin(RFC3986_BASE, '//g','http://g')
     261        self.checkJoin(RFC3986_BASE, '?y','http://a/b/c/d;p?y')
     262        self.checkJoin(RFC3986_BASE, 'g?y','http://a/b/c/g?y')
     263        self.checkJoin(RFC3986_BASE, '#s','http://a/b/c/d;p?q#s')
     264        self.checkJoin(RFC3986_BASE, 'g#s','http://a/b/c/g#s')
     265        self.checkJoin(RFC3986_BASE, 'g?y#s','http://a/b/c/g?y#s')
     266        self.checkJoin(RFC3986_BASE, ';x','http://a/b/c/;x')
     267        self.checkJoin(RFC3986_BASE, 'g;x','http://a/b/c/g;x')
     268        self.checkJoin(RFC3986_BASE, 'g;x?y#s','http://a/b/c/g;x?y#s')
     269        self.checkJoin(RFC3986_BASE, '','http://a/b/c/d;p?q')
     270        self.checkJoin(RFC3986_BASE, '.','http://a/b/c/')
     271        self.checkJoin(RFC3986_BASE, './','http://a/b/c/')
     272        self.checkJoin(RFC3986_BASE, '..','http://a/b/')
     273        self.checkJoin(RFC3986_BASE, '../','http://a/b/')
     274        self.checkJoin(RFC3986_BASE, '../g','http://a/b/g')
     275        self.checkJoin(RFC3986_BASE, '../..','http://a/')
     276        self.checkJoin(RFC3986_BASE, '../../','http://a/')
     277        self.checkJoin(RFC3986_BASE, '../../g','http://a/g')
     278
     279        #Abnormal Examples
     280
     281        # The 'abnormal scenarios' are incompatible with RFC2986 parsing
     282        # Tests are here for reference.
     283
     284        #self.checkJoin(RFC3986_BASE, '../../../g','http://a/g')
     285        #self.checkJoin(RFC3986_BASE, '../../../../g','http://a/g')
     286        #self.checkJoin(RFC3986_BASE, '/./g','http://a/g')
     287        #self.checkJoin(RFC3986_BASE, '/../g','http://a/g')
     288
     289        self.checkJoin(RFC3986_BASE, 'g.','http://a/b/c/g.')
     290        self.checkJoin(RFC3986_BASE, '.g','http://a/b/c/.g')
     291        self.checkJoin(RFC3986_BASE, 'g..','http://a/b/c/g..')
     292        self.checkJoin(RFC3986_BASE, '..g','http://a/b/c/..g')
     293        self.checkJoin(RFC3986_BASE, './../g','http://a/b/g')
     294        self.checkJoin(RFC3986_BASE, './g/.','http://a/b/c/g/')
     295        self.checkJoin(RFC3986_BASE, 'g/./h','http://a/b/c/g/h')
     296        self.checkJoin(RFC3986_BASE, 'g/../h','http://a/b/c/h')
     297        self.checkJoin(RFC3986_BASE, 'g;x=1/./y','http://a/b/c/g;x=1/y')
     298        self.checkJoin(RFC3986_BASE, 'g;x=1/../y','http://a/b/c/y')
     299        self.checkJoin(RFC3986_BASE, 'g?y/./x','http://a/b/c/g?y/./x')
     300        self.checkJoin(RFC3986_BASE, 'g?y/../x','http://a/b/c/g?y/../x')
     301        self.checkJoin(RFC3986_BASE, 'g#s/./x','http://a/b/c/g#s/./x')
     302        self.checkJoin(RFC3986_BASE, 'g#s/../x','http://a/b/c/g#s/../x')
     303        #self.checkJoin(RFC3986_BASE, 'http:g','http:g') # strict parser
     304        self.checkJoin(RFC3986_BASE, 'http:g','http://a/b/c/g') # relaxed parser
     305
     306        # Test for issue9721
     307        self.checkJoin('http://a/b/c/de', ';x','http://a/b/c/;x')
     308
     309    def test_urljoins(self):
     310        self.checkJoin(SIMPLE_BASE, 'g:h','g:h')
     311        self.checkJoin(SIMPLE_BASE, 'http:g','http://a/b/c/g')
     312        self.checkJoin(SIMPLE_BASE, 'http:','http://a/b/c/d')
     313        self.checkJoin(SIMPLE_BASE, 'g','http://a/b/c/g')
     314        self.checkJoin(SIMPLE_BASE, './g','http://a/b/c/g')
     315        self.checkJoin(SIMPLE_BASE, 'g/','http://a/b/c/g/')
     316        self.checkJoin(SIMPLE_BASE, '/g','http://a/g')
     317        self.checkJoin(SIMPLE_BASE, '//g','http://g')
     318        self.checkJoin(SIMPLE_BASE, '?y','http://a/b/c/d?y')
     319        self.checkJoin(SIMPLE_BASE, 'g?y','http://a/b/c/g?y')
     320        self.checkJoin(SIMPLE_BASE, 'g?y/./x','http://a/b/c/g?y/./x')
     321        self.checkJoin(SIMPLE_BASE, '.','http://a/b/c/')
     322        self.checkJoin(SIMPLE_BASE, './','http://a/b/c/')
     323        self.checkJoin(SIMPLE_BASE, '..','http://a/b/')
     324        self.checkJoin(SIMPLE_BASE, '../','http://a/b/')
     325        self.checkJoin(SIMPLE_BASE, '../g','http://a/b/g')
     326        self.checkJoin(SIMPLE_BASE, '../..','http://a/')
     327        self.checkJoin(SIMPLE_BASE, '../../g','http://a/g')
     328        self.checkJoin(SIMPLE_BASE, '../../../g','http://a/../g')
     329        self.checkJoin(SIMPLE_BASE, './../g','http://a/b/g')
     330        self.checkJoin(SIMPLE_BASE, './g/.','http://a/b/c/g/')
     331        self.checkJoin(SIMPLE_BASE, '/./g','http://a/./g')
     332        self.checkJoin(SIMPLE_BASE, 'g/./h','http://a/b/c/g/h')
     333        self.checkJoin(SIMPLE_BASE, 'g/../h','http://a/b/c/h')
     334        self.checkJoin(SIMPLE_BASE, 'http:g','http://a/b/c/g')
     335        self.checkJoin(SIMPLE_BASE, 'http:','http://a/b/c/d')
     336        self.checkJoin(SIMPLE_BASE, 'http:?y','http://a/b/c/d?y')
     337        self.checkJoin(SIMPLE_BASE, 'http:g?y','http://a/b/c/g?y')
     338        self.checkJoin(SIMPLE_BASE, 'http:g?y/./x','http://a/b/c/g?y/./x')
     339        self.checkJoin('http:///', '..','http:///')
     340        self.checkJoin('', 'http://a/b/c/g?y/./x','http://a/b/c/g?y/./x')
     341        self.checkJoin('', 'http://a/./g', 'http://a/./g')
     342        self.checkJoin('svn://pathtorepo/dir1','dir2','svn://pathtorepo/dir2')
     343        self.checkJoin('svn+ssh://pathtorepo/dir1','dir2','svn+ssh://pathtorepo/dir2')
     344
     345    def test_RFC2732(self):
     346        for url, hostname, port in [
     347            ('http://Test.python.org:5432/foo/', 'test.python.org', 5432),
     348            ('http://12.34.56.78:5432/foo/', '12.34.56.78', 5432),
     349            ('http://[::1]:5432/foo/', '::1', 5432),
     350            ('http://[dead:beef::1]:5432/foo/', 'dead:beef::1', 5432),
     351            ('http://[dead:beef::]:5432/foo/', 'dead:beef::', 5432),
     352            ('http://[dead:beef:cafe:5417:affe:8FA3:deaf:feed]:5432/foo/',
     353             'dead:beef:cafe:5417:affe:8fa3:deaf:feed', 5432),
     354            ('http://[::12.34.56.78]:5432/foo/', '::12.34.56.78', 5432),
     355            ('http://[::ffff:12.34.56.78]:5432/foo/',
     356             '::ffff:12.34.56.78', 5432),
     357            ('http://Test.python.org/foo/', 'test.python.org', None),
     358            ('http://12.34.56.78/foo/', '12.34.56.78', None),
     359            ('http://[::1]/foo/', '::1', None),
     360            ('http://[dead:beef::1]/foo/', 'dead:beef::1', None),
     361            ('http://[dead:beef::]/foo/', 'dead:beef::', None),
     362            ('http://[dead:beef:cafe:5417:affe:8FA3:deaf:feed]/foo/',
     363             'dead:beef:cafe:5417:affe:8fa3:deaf:feed', None),
     364            ('http://[::12.34.56.78]/foo/', '::12.34.56.78', None),
     365            ('http://[::ffff:12.34.56.78]/foo/',
     366             '::ffff:12.34.56.78', None),
     367            ]:
     368            urlparsed = urlparse.urlparse(url)
     369            self.assertEqual((urlparsed.hostname, urlparsed.port) , (hostname, port))
     370
     371        for invalid_url in [
     372                'http://::12.34.56.78]/',
     373                'http://[::1/foo/',
     374                'ftp://[::1/foo/bad]/bad',
     375                'http://[::1/foo/bad]/bad',
     376                'http://[::ffff:12.34.56.78']:
     377            self.assertRaises(ValueError, urlparse.urlparse, invalid_url)
    241378
    242379    def test_urldefrag(self):
     
    301438        self.assertEqual(p.geturl(), url)
    302439
     440        # Verify an illegal port of value greater than 65535 is set as None
     441        url = "http://www.python.org:65536"
     442        p = urlparse.urlsplit(url)
     443        self.assertEqual(p.port, None)
     444
     445    def test_issue14072(self):
     446        p1 = urlparse.urlsplit('tel:+31-641044153')
     447        self.assertEqual(p1.scheme, 'tel')
     448        self.assertEqual(p1.path, '+31-641044153')
     449
     450        p2 = urlparse.urlsplit('tel:+31641044153')
     451        self.assertEqual(p2.scheme, 'tel')
     452        self.assertEqual(p2.path, '+31641044153')
     453
     454        # Assert for urlparse
     455        p1 = urlparse.urlparse('tel:+31-641044153')
     456        self.assertEqual(p1.scheme, 'tel')
     457        self.assertEqual(p1.path, '+31-641044153')
     458
     459        p2 = urlparse.urlparse('tel:+31641044153')
     460        self.assertEqual(p2.scheme, 'tel')
     461        self.assertEqual(p2.path, '+31641044153')
     462
     463
     464    def test_telurl_params(self):
     465        p1 = urlparse.urlparse('tel:123-4;phone-context=+1-650-516')
     466        self.assertEqual(p1.scheme, 'tel')
     467        self.assertEqual(p1.path, '123-4')
     468        self.assertEqual(p1.params, 'phone-context=+1-650-516')
     469
     470        p1 = urlparse.urlparse('tel:+1-201-555-0123')
     471        self.assertEqual(p1.scheme, 'tel')
     472        self.assertEqual(p1.path, '+1-201-555-0123')
     473        self.assertEqual(p1.params, '')
     474
     475        p1 = urlparse.urlparse('tel:7042;phone-context=example.com')
     476        self.assertEqual(p1.scheme, 'tel')
     477        self.assertEqual(p1.path, '7042')
     478        self.assertEqual(p1.params, 'phone-context=example.com')
     479
     480        p1 = urlparse.urlparse('tel:863-1234;phone-context=+1-914-555')
     481        self.assertEqual(p1.scheme, 'tel')
     482        self.assertEqual(p1.path, '863-1234')
     483        self.assertEqual(p1.params, 'phone-context=+1-914-555')
     484
    303485
    304486    def test_attributes_bad_port(self):
     
    357539        self.assertEqual(urlparse.urlparse("x-newscheme://foo.com/stuff"),
    358540                         ('x-newscheme','foo.com','/stuff','','',''))
    359 
    360 
     541        self.assertEqual(urlparse.urlparse("x-newscheme://foo.com/stuff?query#fragment"),
     542                         ('x-newscheme','foo.com','/stuff','','query','fragment'))
     543        self.assertEqual(urlparse.urlparse("x-newscheme://foo.com/stuff?query"),
     544                         ('x-newscheme','foo.com','/stuff','','query',''))
     545
     546    def test_withoutscheme(self):
     547        # Test urlparse without scheme
     548        # Issue 754016: urlparse goes wrong with IP:port without scheme
     549        # RFC 1808 specifies that netloc should start with //, urlparse expects
     550        # the same, otherwise it classifies the portion of url as path.
     551        self.assertEqual(urlparse.urlparse("path"),
     552                ('','','path','','',''))
     553        self.assertEqual(urlparse.urlparse("//www.python.org:80"),
     554                ('','www.python.org:80','','','',''))
     555        self.assertEqual(urlparse.urlparse("http://www.python.org:80"),
     556                ('http','www.python.org:80','','','',''))
     557
     558    def test_portseparator(self):
     559        # Issue 754016 makes changes for port separator ':' from scheme separator
     560        self.assertEqual(urlparse.urlparse("path:80"),
     561                ('','','path:80','','',''))
     562        self.assertEqual(urlparse.urlparse("http:"),('http','','','','',''))
     563        self.assertEqual(urlparse.urlparse("https:"),('https','','','','',''))
     564        self.assertEqual(urlparse.urlparse("http://www.python.org:80"),
     565                ('http','www.python.org:80','','','',''))
    361566
    362567def test_main():
Note: See TracChangeset for help on using the changeset viewer.