annotate tests/test-url.py @ 28801:441491aba8c3

test-ctxmanager: stop direct symbol import of mercurial.util
author Yuya Nishihara <yuya@tcha.org>
date Tue, 05 Apr 2016 23:13:52 +0900
parents 2903558a6991
children 63fe5ddb8715
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
28677
2903558a6991 py3: make test-url use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 26421
diff changeset
1 from __future__ import print_function
15398
474279be5add tests: fix readline escape characters in heredoctest.py/test-url.py
Brodie Rao <brodie@bitheap.org>
parents: 15018
diff changeset
2 import os
12592
f2937d6492c5 url: verify correctness of https server certificates (issue2407)
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
3
f2937d6492c5 url: verify correctness of https server certificates (issue2407)
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
4 def check(a, b):
f2937d6492c5 url: verify correctness of https server certificates (issue2407)
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
5 if a != b:
28677
2903558a6991 py3: make test-url use print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents: 26421
diff changeset
6 print((a, b))
12592
f2937d6492c5 url: verify correctness of https server certificates (issue2407)
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
7
12606
5c8353692123 test-url: refactor with shorter lines
Martin Geisler <mg@aragost.com>
parents: 12592
diff changeset
8 def cert(cn):
20685
56b1f39dd0c1 test-url: move from dict() construction to {} literals
Augie Fackler <raf@durin42.com>
parents: 15611
diff changeset
9 return {'subject': ((('commonName', cn),),)}
12606
5c8353692123 test-url: refactor with shorter lines
Martin Geisler <mg@aragost.com>
parents: 12592
diff changeset
10
14204
5fa21960b2f4 sslutil: extracted ssl methods from httpsconnection in url.py
Augie Fackler <durin42@gmail.com>
parents: 14076
diff changeset
11 from mercurial.sslutil import _verifycert
12592
f2937d6492c5 url: verify correctness of https server certificates (issue2407)
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
12
12724
66e7ba85585b test-url: remove trailing whitespace
Augie Fackler <durin42@gmail.com>
parents: 12606
diff changeset
13 # Test non-wildcard certificates
12606
5c8353692123 test-url: refactor with shorter lines
Martin Geisler <mg@aragost.com>
parents: 12592
diff changeset
14 check(_verifycert(cert('example.com'), 'example.com'),
5c8353692123 test-url: refactor with shorter lines
Martin Geisler <mg@aragost.com>
parents: 12592
diff changeset
15 None)
5c8353692123 test-url: refactor with shorter lines
Martin Geisler <mg@aragost.com>
parents: 12592
diff changeset
16 check(_verifycert(cert('example.com'), 'www.example.com'),
5c8353692123 test-url: refactor with shorter lines
Martin Geisler <mg@aragost.com>
parents: 12592
diff changeset
17 'certificate is for example.com')
5c8353692123 test-url: refactor with shorter lines
Martin Geisler <mg@aragost.com>
parents: 12592
diff changeset
18 check(_verifycert(cert('www.example.com'), 'example.com'),
5c8353692123 test-url: refactor with shorter lines
Martin Geisler <mg@aragost.com>
parents: 12592
diff changeset
19 'certificate is for www.example.com')
12592
f2937d6492c5 url: verify correctness of https server certificates (issue2407)
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
20
f2937d6492c5 url: verify correctness of https server certificates (issue2407)
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
21 # Test wildcard certificates
12606
5c8353692123 test-url: refactor with shorter lines
Martin Geisler <mg@aragost.com>
parents: 12592
diff changeset
22 check(_verifycert(cert('*.example.com'), 'www.example.com'),
5c8353692123 test-url: refactor with shorter lines
Martin Geisler <mg@aragost.com>
parents: 12592
diff changeset
23 None)
5c8353692123 test-url: refactor with shorter lines
Martin Geisler <mg@aragost.com>
parents: 12592
diff changeset
24 check(_verifycert(cert('*.example.com'), 'example.com'),
5c8353692123 test-url: refactor with shorter lines
Martin Geisler <mg@aragost.com>
parents: 12592
diff changeset
25 'certificate is for *.example.com')
5c8353692123 test-url: refactor with shorter lines
Martin Geisler <mg@aragost.com>
parents: 12592
diff changeset
26 check(_verifycert(cert('*.example.com'), 'w.w.example.com'),
5c8353692123 test-url: refactor with shorter lines
Martin Geisler <mg@aragost.com>
parents: 12592
diff changeset
27 'certificate is for *.example.com')
12592
f2937d6492c5 url: verify correctness of https server certificates (issue2407)
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
28
13249
75d0c38a0bca url: check subjectAltName when verifying ssl certificate
Yuya Nishihara <yuya@tcha.org>
parents: 13248
diff changeset
29 # Test subjectAltName
75d0c38a0bca url: check subjectAltName when verifying ssl certificate
Yuya Nishihara <yuya@tcha.org>
parents: 13248
diff changeset
30 san_cert = {'subject': ((('commonName', 'example.com'),),),
75d0c38a0bca url: check subjectAltName when verifying ssl certificate
Yuya Nishihara <yuya@tcha.org>
parents: 13248
diff changeset
31 'subjectAltName': (('DNS', '*.example.net'),
75d0c38a0bca url: check subjectAltName when verifying ssl certificate
Yuya Nishihara <yuya@tcha.org>
parents: 13248
diff changeset
32 ('DNS', 'example.net'))}
75d0c38a0bca url: check subjectAltName when verifying ssl certificate
Yuya Nishihara <yuya@tcha.org>
parents: 13248
diff changeset
33 check(_verifycert(san_cert, 'example.net'),
75d0c38a0bca url: check subjectAltName when verifying ssl certificate
Yuya Nishihara <yuya@tcha.org>
parents: 13248
diff changeset
34 None)
75d0c38a0bca url: check subjectAltName when verifying ssl certificate
Yuya Nishihara <yuya@tcha.org>
parents: 13248
diff changeset
35 check(_verifycert(san_cert, 'foo.example.net'),
75d0c38a0bca url: check subjectAltName when verifying ssl certificate
Yuya Nishihara <yuya@tcha.org>
parents: 13248
diff changeset
36 None)
14666
27b080aa880a sslutil: fall back to commonName when no dNSName in subjectAltName (issue2798)
Nicolas Bareil <nico@chdir.org>
parents: 14313
diff changeset
37 # no fallback to subject commonName when subjectAltName has DNS
13249
75d0c38a0bca url: check subjectAltName when verifying ssl certificate
Yuya Nishihara <yuya@tcha.org>
parents: 13248
diff changeset
38 check(_verifycert(san_cert, 'example.com'),
75d0c38a0bca url: check subjectAltName when verifying ssl certificate
Yuya Nishihara <yuya@tcha.org>
parents: 13248
diff changeset
39 'certificate is for *.example.net, example.net')
14666
27b080aa880a sslutil: fall back to commonName when no dNSName in subjectAltName (issue2798)
Nicolas Bareil <nico@chdir.org>
parents: 14313
diff changeset
40 # fallback to subject commonName when no DNS in subjectAltName
27b080aa880a sslutil: fall back to commonName when no dNSName in subjectAltName (issue2798)
Nicolas Bareil <nico@chdir.org>
parents: 14313
diff changeset
41 san_cert = {'subject': ((('commonName', 'example.com'),),),
27b080aa880a sslutil: fall back to commonName when no dNSName in subjectAltName (issue2798)
Nicolas Bareil <nico@chdir.org>
parents: 14313
diff changeset
42 'subjectAltName': (('IP Address', '8.8.8.8'),)}
27b080aa880a sslutil: fall back to commonName when no dNSName in subjectAltName (issue2798)
Nicolas Bareil <nico@chdir.org>
parents: 14313
diff changeset
43 check(_verifycert(san_cert, 'example.com'), None)
13249
75d0c38a0bca url: check subjectAltName when verifying ssl certificate
Yuya Nishihara <yuya@tcha.org>
parents: 13248
diff changeset
44
12592
f2937d6492c5 url: verify correctness of https server certificates (issue2407)
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
45 # Avoid some pitfalls
12606
5c8353692123 test-url: refactor with shorter lines
Martin Geisler <mg@aragost.com>
parents: 12592
diff changeset
46 check(_verifycert(cert('*.foo'), 'foo'),
5c8353692123 test-url: refactor with shorter lines
Martin Geisler <mg@aragost.com>
parents: 12592
diff changeset
47 'certificate is for *.foo')
5c8353692123 test-url: refactor with shorter lines
Martin Geisler <mg@aragost.com>
parents: 12592
diff changeset
48 check(_verifycert(cert('*o'), 'foo'),
5c8353692123 test-url: refactor with shorter lines
Martin Geisler <mg@aragost.com>
parents: 12592
diff changeset
49 'certificate is for *o')
12592
f2937d6492c5 url: verify correctness of https server certificates (issue2407)
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
50
12742
6ab4a7d3c179 url: validity (notBefore/notAfter) is checked by OpenSSL (issue2407)
Mads Kiilerich <mads@kiilerich.com>
parents: 12738
diff changeset
51 check(_verifycert({'subject': ()},
12606
5c8353692123 test-url: refactor with shorter lines
Martin Geisler <mg@aragost.com>
parents: 12592
diff changeset
52 'example.com'),
13249
75d0c38a0bca url: check subjectAltName when verifying ssl certificate
Yuya Nishihara <yuya@tcha.org>
parents: 13248
diff changeset
53 'no commonName or subjectAltName found in certificate')
12592
f2937d6492c5 url: verify correctness of https server certificates (issue2407)
Mads Kiilerich <mads@kiilerich.com>
parents:
diff changeset
54 check(_verifycert(None, 'example.com'),
12606
5c8353692123 test-url: refactor with shorter lines
Martin Geisler <mg@aragost.com>
parents: 12592
diff changeset
55 'no certificate received')
13248
00411a4fa1bb url: fix UnicodeDecodeError on certificate verification error
Yuya Nishihara <yuya@tcha.org>
parents: 12865
diff changeset
56
14666
27b080aa880a sslutil: fall back to commonName when no dNSName in subjectAltName (issue2798)
Nicolas Bareil <nico@chdir.org>
parents: 14313
diff changeset
57 # Unicode (IDN) certname isn't supported
27b080aa880a sslutil: fall back to commonName when no dNSName in subjectAltName (issue2798)
Nicolas Bareil <nico@chdir.org>
parents: 14313
diff changeset
58 check(_verifycert(cert(u'\u4f8b.jp'), 'example.jp'),
27b080aa880a sslutil: fall back to commonName when no dNSName in subjectAltName (issue2798)
Nicolas Bareil <nico@chdir.org>
parents: 14313
diff changeset
59 'IDN in certificate not supported')
27b080aa880a sslutil: fall back to commonName when no dNSName in subjectAltName (issue2798)
Nicolas Bareil <nico@chdir.org>
parents: 14313
diff changeset
60
13770
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
61 import doctest
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
62
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
63 def test_url():
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
64 """
14076
924c82157d46 url: move URL parsing functions into util to improve startup time
Brodie Rao <brodie@bitheap.org>
parents: 13848
diff changeset
65 >>> from mercurial.util import url
13770
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
66
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
67 This tests for edge cases in url.URL's parsing algorithm. Most of
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
68 these aren't useful for documentation purposes, so they aren't
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
69 part of the class's doc tests.
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
70
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
71 Query strings and fragments:
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
72
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
73 >>> url('http://host/a?b#c')
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
74 <url scheme: 'http', host: 'host', path: 'a', query: 'b', fragment: 'c'>
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
75 >>> url('http://host/a?')
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
76 <url scheme: 'http', host: 'host', path: 'a'>
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
77 >>> url('http://host/a#b#c')
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
78 <url scheme: 'http', host: 'host', path: 'a', fragment: 'b#c'>
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
79 >>> url('http://host/a#b?c')
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
80 <url scheme: 'http', host: 'host', path: 'a', fragment: 'b?c'>
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
81 >>> url('http://host/?a#b')
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
82 <url scheme: 'http', host: 'host', path: '', query: 'a', fragment: 'b'>
13827
f1823b9f073b url: nuke some newly-introduced underbars in identifiers
Matt Mackall <mpm@selenic.com>
parents: 13817
diff changeset
83 >>> url('http://host/?a#b', parsequery=False)
13770
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
84 <url scheme: 'http', host: 'host', path: '?a', fragment: 'b'>
13827
f1823b9f073b url: nuke some newly-introduced underbars in identifiers
Matt Mackall <mpm@selenic.com>
parents: 13817
diff changeset
85 >>> url('http://host/?a#b', parsefragment=False)
13770
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
86 <url scheme: 'http', host: 'host', path: '', query: 'a#b'>
13827
f1823b9f073b url: nuke some newly-introduced underbars in identifiers
Matt Mackall <mpm@selenic.com>
parents: 13817
diff changeset
87 >>> url('http://host/?a#b', parsequery=False, parsefragment=False)
13770
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
88 <url scheme: 'http', host: 'host', path: '?a#b'>
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
89
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
90 IPv6 addresses:
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
91
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
92 >>> url('ldap://[2001:db8::7]/c=GB?objectClass?one')
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
93 <url scheme: 'ldap', host: '[2001:db8::7]', path: 'c=GB',
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
94 query: 'objectClass?one'>
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
95 >>> url('ldap://joe:xxx@[2001:db8::7]:80/c=GB?objectClass?one')
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
96 <url scheme: 'ldap', user: 'joe', passwd: 'xxx', host: '[2001:db8::7]',
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
97 port: '80', path: 'c=GB', query: 'objectClass?one'>
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
98
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
99 Missing scheme, host, etc.:
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
100
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
101 >>> url('://192.0.2.16:80/')
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
102 <url path: '://192.0.2.16:80/'>
26421
4b0fc75f9403 urls: bulk-change primary website URLs
Matt Mackall <mpm@selenic.com>
parents: 20685
diff changeset
103 >>> url('https://mercurial-scm.org')
4b0fc75f9403 urls: bulk-change primary website URLs
Matt Mackall <mpm@selenic.com>
parents: 20685
diff changeset
104 <url scheme: 'https', host: 'mercurial-scm.org'>
13770
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
105 >>> url('/foo')
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
106 <url path: '/foo'>
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
107 >>> url('bundle:/foo')
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
108 <url scheme: 'bundle', path: '/foo'>
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
109 >>> url('a?b#c')
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
110 <url path: 'a?b', fragment: 'c'>
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
111 >>> url('http://x.com?arg=/foo')
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
112 <url scheme: 'http', host: 'x.com', query: 'arg=/foo'>
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
113 >>> url('http://joe:xxx@/foo')
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
114 <url scheme: 'http', user: 'joe', passwd: 'xxx', path: 'foo'>
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
115
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
116 Just a scheme and a path:
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
117
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
118 >>> url('mailto:John.Doe@example.com')
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
119 <url scheme: 'mailto', path: 'John.Doe@example.com'>
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
120 >>> url('a:b:c:d')
13808
58b86b9149f1 url: fix tests
Matt Mackall <mpm@selenic.com>
parents: 13770
diff changeset
121 <url path: 'a:b:c:d'>
58b86b9149f1 url: fix tests
Matt Mackall <mpm@selenic.com>
parents: 13770
diff changeset
122 >>> url('aa:bb:cc:dd')
58b86b9149f1 url: fix tests
Matt Mackall <mpm@selenic.com>
parents: 13770
diff changeset
123 <url scheme: 'aa', path: 'bb:cc:dd'>
13770
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
124
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
125 SSH examples:
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
126
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
127 >>> url('ssh://joe@host//home/joe')
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
128 <url scheme: 'ssh', user: 'joe', host: 'host', path: '/home/joe'>
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
129 >>> url('ssh://joe:xxx@host/src')
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
130 <url scheme: 'ssh', user: 'joe', passwd: 'xxx', host: 'host', path: 'src'>
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
131 >>> url('ssh://joe:xxx@host')
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
132 <url scheme: 'ssh', user: 'joe', passwd: 'xxx', host: 'host'>
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
133 >>> url('ssh://joe@host')
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
134 <url scheme: 'ssh', user: 'joe', host: 'host'>
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
135 >>> url('ssh://host')
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
136 <url scheme: 'ssh', host: 'host'>
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
137 >>> url('ssh://')
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
138 <url scheme: 'ssh'>
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
139 >>> url('ssh:')
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
140 <url scheme: 'ssh'>
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
141
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
142 Non-numeric port:
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
143
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
144 >>> url('http://example.com:dd')
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
145 <url scheme: 'http', host: 'example.com', port: 'dd'>
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
146 >>> url('ssh://joe:xxx@host:ssh/foo')
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
147 <url scheme: 'ssh', user: 'joe', passwd: 'xxx', host: 'host', port: 'ssh',
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
148 path: 'foo'>
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
149
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
150 Bad authentication credentials:
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
151
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
152 >>> url('http://joe@joeville:123@4:@host/a?b#c')
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
153 <url scheme: 'http', user: 'joe@joeville', passwd: '123@4:',
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
154 host: 'host', path: 'a', query: 'b', fragment: 'c'>
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
155 >>> url('http://!*#?/@!*#?/:@host/a?b#c')
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
156 <url scheme: 'http', host: '!*', fragment: '?/@!*#?/:@host/a?b#c'>
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
157 >>> url('http://!*#?@!*#?:@host/a?b#c')
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
158 <url scheme: 'http', host: '!*', fragment: '?@!*#?:@host/a?b#c'>
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
159 >>> url('http://!*@:!*@@host/a?b#c')
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
160 <url scheme: 'http', user: '!*@', passwd: '!*@', host: 'host',
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
161 path: 'a', query: 'b', fragment: 'c'>
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
162
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
163 File paths:
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
164
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
165 >>> url('a/b/c/d.g.f')
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
166 <url path: 'a/b/c/d.g.f'>
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
167 >>> url('/x///z/y/')
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
168 <url path: '/x///z/y/'>
13848
b2798c1defff url: be stricter about detecting schemes
Brodie Rao <brodie@bitheap.org>
parents: 13827
diff changeset
169 >>> url('/foo:bar')
b2798c1defff url: be stricter about detecting schemes
Brodie Rao <brodie@bitheap.org>
parents: 13827
diff changeset
170 <url path: '/foo:bar'>
b2798c1defff url: be stricter about detecting schemes
Brodie Rao <brodie@bitheap.org>
parents: 13827
diff changeset
171 >>> url('\\\\foo:bar')
b2798c1defff url: be stricter about detecting schemes
Brodie Rao <brodie@bitheap.org>
parents: 13827
diff changeset
172 <url path: '\\\\foo:bar'>
b2798c1defff url: be stricter about detecting schemes
Brodie Rao <brodie@bitheap.org>
parents: 13827
diff changeset
173 >>> url('./foo:bar')
b2798c1defff url: be stricter about detecting schemes
Brodie Rao <brodie@bitheap.org>
parents: 13827
diff changeset
174 <url path: './foo:bar'>
13770
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
175
13817
7f18bab2c0b0 url: abort on file:// URLs with non-localhost hosts
Brodie Rao <brodie@bitheap.org>
parents: 13808
diff changeset
176 Non-localhost file URL:
7f18bab2c0b0 url: abort on file:// URLs with non-localhost hosts
Brodie Rao <brodie@bitheap.org>
parents: 13808
diff changeset
177
26421
4b0fc75f9403 urls: bulk-change primary website URLs
Matt Mackall <mpm@selenic.com>
parents: 20685
diff changeset
178 >>> u = url('file://mercurial-scm.org/foo')
13817
7f18bab2c0b0 url: abort on file:// URLs with non-localhost hosts
Brodie Rao <brodie@bitheap.org>
parents: 13808
diff changeset
179 Traceback (most recent call last):
7f18bab2c0b0 url: abort on file:// URLs with non-localhost hosts
Brodie Rao <brodie@bitheap.org>
parents: 13808
diff changeset
180 File "<stdin>", line 1, in ?
7f18bab2c0b0 url: abort on file:// URLs with non-localhost hosts
Brodie Rao <brodie@bitheap.org>
parents: 13808
diff changeset
181 Abort: file:// URLs can only refer to localhost
7f18bab2c0b0 url: abort on file:// URLs with non-localhost hosts
Brodie Rao <brodie@bitheap.org>
parents: 13808
diff changeset
182
13770
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
183 Empty URL:
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
184
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
185 >>> u = url('')
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
186 >>> u
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
187 <url path: ''>
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
188 >>> str(u)
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
189 ''
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
190
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
191 Empty path with query string:
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
192
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
193 >>> str(url('http://foo/?bar'))
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
194 'http://foo/?bar'
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
195
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
196 Invalid path:
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
197
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
198 >>> u = url('http://foo/bar')
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
199 >>> u.path = 'bar'
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
200 >>> str(u)
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
201 'http://foo/bar'
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
202
14313
a389dd285282 util: make str(url) return file:/// for abs paths again
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14204
diff changeset
203 >>> u = url('file:/foo/bar/baz')
a389dd285282 util: make str(url) return file:/// for abs paths again
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14204
diff changeset
204 >>> u
a389dd285282 util: make str(url) return file:/// for abs paths again
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14204
diff changeset
205 <url scheme: 'file', path: '/foo/bar/baz'>
a389dd285282 util: make str(url) return file:/// for abs paths again
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14204
diff changeset
206 >>> str(u)
a389dd285282 util: make str(url) return file:/// for abs paths again
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14204
diff changeset
207 'file:///foo/bar/baz'
15018
e89f62dcd723 url: really handle urls of the form file:///c:/foo/bar/ correctly
Mads Kiilerich <mads@kiilerich.com>
parents: 14666
diff changeset
208 >>> u.localpath()
e89f62dcd723 url: really handle urls of the form file:///c:/foo/bar/ correctly
Mads Kiilerich <mads@kiilerich.com>
parents: 14666
diff changeset
209 '/foo/bar/baz'
14313
a389dd285282 util: make str(url) return file:/// for abs paths again
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14204
diff changeset
210
13770
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
211 >>> u = url('file:///foo/bar/baz')
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
212 >>> u
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
213 <url scheme: 'file', path: '/foo/bar/baz'>
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
214 >>> str(u)
14313
a389dd285282 util: make str(url) return file:/// for abs paths again
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14204
diff changeset
215 'file:///foo/bar/baz'
15018
e89f62dcd723 url: really handle urls of the form file:///c:/foo/bar/ correctly
Mads Kiilerich <mads@kiilerich.com>
parents: 14666
diff changeset
216 >>> u.localpath()
e89f62dcd723 url: really handle urls of the form file:///c:/foo/bar/ correctly
Mads Kiilerich <mads@kiilerich.com>
parents: 14666
diff changeset
217 '/foo/bar/baz'
e89f62dcd723 url: really handle urls of the form file:///c:/foo/bar/ correctly
Mads Kiilerich <mads@kiilerich.com>
parents: 14666
diff changeset
218
e89f62dcd723 url: really handle urls of the form file:///c:/foo/bar/ correctly
Mads Kiilerich <mads@kiilerich.com>
parents: 14666
diff changeset
219 >>> u = url('file:///f:oo/bar/baz')
e89f62dcd723 url: really handle urls of the form file:///c:/foo/bar/ correctly
Mads Kiilerich <mads@kiilerich.com>
parents: 14666
diff changeset
220 >>> u
e89f62dcd723 url: really handle urls of the form file:///c:/foo/bar/ correctly
Mads Kiilerich <mads@kiilerich.com>
parents: 14666
diff changeset
221 <url scheme: 'file', path: 'f:oo/bar/baz'>
e89f62dcd723 url: really handle urls of the form file:///c:/foo/bar/ correctly
Mads Kiilerich <mads@kiilerich.com>
parents: 14666
diff changeset
222 >>> str(u)
15611
ec8a49c46d7e merge with stable
Matt Mackall <mpm@selenic.com>
parents: 15513 15609
diff changeset
223 'file:///f:oo/bar/baz'
15018
e89f62dcd723 url: really handle urls of the form file:///c:/foo/bar/ correctly
Mads Kiilerich <mads@kiilerich.com>
parents: 14666
diff changeset
224 >>> u.localpath()
e89f62dcd723 url: really handle urls of the form file:///c:/foo/bar/ correctly
Mads Kiilerich <mads@kiilerich.com>
parents: 14666
diff changeset
225 'f:oo/bar/baz'
14313
a389dd285282 util: make str(url) return file:/// for abs paths again
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14204
diff changeset
226
15496
396e83d635a6 url: handle file://localhost/c:/foo "correctly"
Mads Kiilerich <mads@kiilerich.com>
parents: 15398
diff changeset
227 >>> u = url('file://localhost/f:oo/bar/baz')
396e83d635a6 url: handle file://localhost/c:/foo "correctly"
Mads Kiilerich <mads@kiilerich.com>
parents: 15398
diff changeset
228 >>> u
396e83d635a6 url: handle file://localhost/c:/foo "correctly"
Mads Kiilerich <mads@kiilerich.com>
parents: 15398
diff changeset
229 <url scheme: 'file', host: 'localhost', path: 'f:oo/bar/baz'>
396e83d635a6 url: handle file://localhost/c:/foo "correctly"
Mads Kiilerich <mads@kiilerich.com>
parents: 15398
diff changeset
230 >>> str(u)
15513
646759147717 merge with stable
Matt Mackall <mpm@selenic.com>
parents: 15452 15496
diff changeset
231 'file://localhost/f:oo/bar/baz'
15496
396e83d635a6 url: handle file://localhost/c:/foo "correctly"
Mads Kiilerich <mads@kiilerich.com>
parents: 15398
diff changeset
232 >>> u.localpath()
396e83d635a6 url: handle file://localhost/c:/foo "correctly"
Mads Kiilerich <mads@kiilerich.com>
parents: 15398
diff changeset
233 'f:oo/bar/baz'
396e83d635a6 url: handle file://localhost/c:/foo "correctly"
Mads Kiilerich <mads@kiilerich.com>
parents: 15398
diff changeset
234
14313
a389dd285282 util: make str(url) return file:/// for abs paths again
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14204
diff changeset
235 >>> u = url('file:foo/bar/baz')
a389dd285282 util: make str(url) return file:/// for abs paths again
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14204
diff changeset
236 >>> u
a389dd285282 util: make str(url) return file:/// for abs paths again
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14204
diff changeset
237 <url scheme: 'file', path: 'foo/bar/baz'>
a389dd285282 util: make str(url) return file:/// for abs paths again
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14204
diff changeset
238 >>> str(u)
a389dd285282 util: make str(url) return file:/// for abs paths again
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 14204
diff changeset
239 'file:foo/bar/baz'
15018
e89f62dcd723 url: really handle urls of the form file:///c:/foo/bar/ correctly
Mads Kiilerich <mads@kiilerich.com>
parents: 14666
diff changeset
240 >>> u.localpath()
e89f62dcd723 url: really handle urls of the form file:///c:/foo/bar/ correctly
Mads Kiilerich <mads@kiilerich.com>
parents: 14666
diff changeset
241 'foo/bar/baz'
13770
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
242 """
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
243
15398
474279be5add tests: fix readline escape characters in heredoctest.py/test-url.py
Brodie Rao <brodie@bitheap.org>
parents: 15018
diff changeset
244 if 'TERM' in os.environ:
474279be5add tests: fix readline escape characters in heredoctest.py/test-url.py
Brodie Rao <brodie@bitheap.org>
parents: 15018
diff changeset
245 del os.environ['TERM']
474279be5add tests: fix readline escape characters in heredoctest.py/test-url.py
Brodie Rao <brodie@bitheap.org>
parents: 15018
diff changeset
246
13770
4e8f2310f310 url: provide url object
Brodie Rao <brodie@bitheap.org>
parents: 13249
diff changeset
247 doctest.testmod(optionflags=doctest.NORMALIZE_WHITESPACE)