test-url.py
462 lines
| 13.9 KiB
| text/x-python
|
PythonLexer
/ tests / test-url.py
Gregory Szorc
|
r29451 | # coding=utf-8 | ||
Pulkit Goyal
|
r28914 | |||
import doctest | ||||
Brodie Rao
|
r15398 | import os | ||
Mads Kiilerich
|
r12592 | |||
Augie Fackler
|
r43346 | |||
Mads Kiilerich
|
r12592 | def check(a, b): | ||
if a != b: | ||||
Pulkit Goyal
|
r28677 | print((a, b)) | ||
Mads Kiilerich
|
r12592 | |||
Augie Fackler
|
r43346 | |||
Martin Geisler
|
r12606 | def cert(cn): | ||
Augie Fackler
|
r20685 | return {'subject': ((('commonName', cn),),)} | ||
Martin Geisler
|
r12606 | |||
Augie Fackler
|
r43346 | |||
from mercurial import sslutil | ||||
Mads Kiilerich
|
r12592 | |||
Pulkit Goyal
|
r28914 | _verifycert = sslutil._verifycert | ||
Augie Fackler
|
r12724 | # Test non-wildcard certificates | ||
Augie Fackler
|
r43346 | check(_verifycert(cert('example.com'), 'example.com'), None) | ||
check( | ||||
_verifycert(cert('example.com'), 'www.example.com'), | ||||
b'certificate is for example.com', | ||||
) | ||||
check( | ||||
_verifycert(cert('www.example.com'), 'example.com'), | ||||
b'certificate is for www.example.com', | ||||
) | ||||
Mads Kiilerich
|
r12592 | |||
# Test wildcard certificates | ||||
Augie Fackler
|
r43346 | check(_verifycert(cert('*.example.com'), 'www.example.com'), None) | ||
check( | ||||
_verifycert(cert('*.example.com'), 'example.com'), | ||||
b'certificate is for *.example.com', | ||||
) | ||||
check( | ||||
_verifycert(cert('*.example.com'), 'w.w.example.com'), | ||||
b'certificate is for *.example.com', | ||||
) | ||||
Mads Kiilerich
|
r12592 | |||
Yuya Nishihara
|
r13249 | # Test subjectAltName | ||
Augie Fackler
|
r43346 | san_cert = { | ||
'subject': ((('commonName', 'example.com'),),), | ||||
'subjectAltName': (('DNS', '*.example.net'), ('DNS', 'example.net')), | ||||
} | ||||
check(_verifycert(san_cert, 'example.net'), None) | ||||
check(_verifycert(san_cert, 'foo.example.net'), None) | ||||
Nicolas Bareil
|
r14666 | # no fallback to subject commonName when subjectAltName has DNS | ||
Augie Fackler
|
r43346 | check( | ||
_verifycert(san_cert, 'example.com'), | ||||
b'certificate is for *.example.net, example.net', | ||||
) | ||||
Nicolas Bareil
|
r14666 | # fallback to subject commonName when no DNS in subjectAltName | ||
Augie Fackler
|
r43346 | san_cert = { | ||
'subject': ((('commonName', 'example.com'),),), | ||||
'subjectAltName': (('IP Address', '8.8.8.8'),), | ||||
} | ||||
Nicolas Bareil
|
r14666 | check(_verifycert(san_cert, 'example.com'), None) | ||
Yuya Nishihara
|
r13249 | |||
Mads Kiilerich
|
r12592 | # Avoid some pitfalls | ||
Augie Fackler
|
r43346 | check(_verifycert(cert('*.foo'), 'foo'), b'certificate is for *.foo') | ||
Gregory Szorc
|
r29452 | check(_verifycert(cert('*o'), 'foo'), None) | ||
Mads Kiilerich
|
r12592 | |||
Augie Fackler
|
r43346 | check( | ||
_verifycert({'subject': ()}, 'example.com'), | ||||
b'no commonName or subjectAltName found in certificate', | ||||
) | ||||
check(_verifycert(None, 'example.com'), b'no certificate received') | ||||
Yuya Nishihara
|
r13248 | |||
Nicolas Bareil
|
r14666 | # Unicode (IDN) certname isn't supported | ||
Augie Fackler
|
r43346 | check( | ||
_verifycert(cert(u'\u4f8b.jp'), 'example.jp'), | ||||
b'IDN in certificate not supported', | ||||
) | ||||
Nicolas Bareil
|
r14666 | |||
Gregory Szorc
|
r29451 | # The following tests are from CPython's test_ssl.py. | ||
check(_verifycert(cert('example.com'), 'example.com'), None) | ||||
check(_verifycert(cert('example.com'), 'ExAmple.cOm'), None) | ||||
Augie Fackler
|
r43346 | check( | ||
_verifycert(cert('example.com'), 'www.example.com'), | ||||
b'certificate is for example.com', | ||||
) | ||||
check( | ||||
_verifycert(cert('example.com'), '.example.com'), | ||||
b'certificate is for example.com', | ||||
) | ||||
check( | ||||
_verifycert(cert('example.com'), 'example.org'), | ||||
b'certificate is for example.com', | ||||
) | ||||
check( | ||||
_verifycert(cert('example.com'), 'exampleXcom'), | ||||
b'certificate is for example.com', | ||||
) | ||||
Gregory Szorc
|
r29451 | check(_verifycert(cert('*.a.com'), 'foo.a.com'), None) | ||
Augie Fackler
|
r43346 | check( | ||
_verifycert(cert('*.a.com'), 'bar.foo.a.com'), b'certificate is for *.a.com' | ||||
) | ||||
check(_verifycert(cert('*.a.com'), 'a.com'), b'certificate is for *.a.com') | ||||
check(_verifycert(cert('*.a.com'), 'Xa.com'), b'certificate is for *.a.com') | ||||
check(_verifycert(cert('*.a.com'), '.a.com'), b'certificate is for *.a.com') | ||||
Gregory Szorc
|
r29451 | |||
# only match one left-most wildcard | ||||
Gregory Szorc
|
r29452 | check(_verifycert(cert('f*.com'), 'foo.com'), None) | ||
check(_verifycert(cert('f*.com'), 'f.com'), None) | ||||
Augie Fackler
|
r43346 | check(_verifycert(cert('f*.com'), 'bar.com'), b'certificate is for f*.com') | ||
check(_verifycert(cert('f*.com'), 'foo.a.com'), b'certificate is for f*.com') | ||||
check(_verifycert(cert('f*.com'), 'bar.foo.com'), b'certificate is for f*.com') | ||||
Gregory Szorc
|
r29451 | |||
# NULL bytes are bad, CVE-2013-4073 | ||||
Augie Fackler
|
r43346 | check( | ||
_verifycert( | ||||
cert('null.python.org\x00example.org'), 'null.python.org\x00example.org' | ||||
), | ||||
None, | ||||
) | ||||
check( | ||||
_verifycert(cert('null.python.org\x00example.org'), 'example.org'), | ||||
b'certificate is for null.python.org\x00example.org', | ||||
) | ||||
check( | ||||
_verifycert(cert('null.python.org\x00example.org'), 'null.python.org'), | ||||
b'certificate is for null.python.org\x00example.org', | ||||
) | ||||
Gregory Szorc
|
r29451 | |||
# error cases with wildcards | ||||
Augie Fackler
|
r43346 | check( | ||
_verifycert(cert('*.*.a.com'), 'bar.foo.a.com'), | ||||
b'certificate is for *.*.a.com', | ||||
) | ||||
check(_verifycert(cert('*.*.a.com'), 'a.com'), b'certificate is for *.*.a.com') | ||||
check(_verifycert(cert('*.*.a.com'), 'Xa.com'), b'certificate is for *.*.a.com') | ||||
check(_verifycert(cert('*.*.a.com'), '.a.com'), b'certificate is for *.*.a.com') | ||||
Gregory Szorc
|
r29451 | |||
Augie Fackler
|
r43346 | check(_verifycert(cert('a.*.com'), 'a.foo.com'), b'certificate is for a.*.com') | ||
check(_verifycert(cert('a.*.com'), 'a..com'), b'certificate is for a.*.com') | ||||
check(_verifycert(cert('a.*.com'), 'a.com'), b'certificate is for a.*.com') | ||||
Gregory Szorc
|
r29451 | |||
# wildcard doesn't match IDNA prefix 'xn--' | ||||
idna = u'püthon.python.org'.encode('idna').decode('ascii') | ||||
check(_verifycert(cert(idna), idna), None) | ||||
Augie Fackler
|
r43346 | check( | ||
_verifycert(cert('x*.python.org'), idna), | ||||
b'certificate is for x*.python.org', | ||||
) | ||||
check( | ||||
_verifycert(cert('xn--p*.python.org'), idna), | ||||
b'certificate is for xn--p*.python.org', | ||||
) | ||||
Gregory Szorc
|
r29451 | |||
# wildcard in first fragment and IDNA A-labels in sequent fragments | ||||
# are supported. | ||||
idna = u'www*.pythön.org'.encode('idna').decode('ascii') | ||||
Augie Fackler
|
r43346 | check( | ||
_verifycert(cert(idna), u'www.pythön.org'.encode('idna').decode('ascii')), | ||||
None, | ||||
) | ||||
check( | ||||
_verifycert(cert(idna), u'www1.pythön.org'.encode('idna').decode('ascii')), | ||||
None, | ||||
) | ||||
check( | ||||
_verifycert(cert(idna), u'ftp.pythön.org'.encode('idna').decode('ascii')), | ||||
b'certificate is for www*.xn--pythn-mua.org', | ||||
) | ||||
check( | ||||
_verifycert(cert(idna), u'pythön.org'.encode('idna').decode('ascii')), | ||||
b'certificate is for www*.xn--pythn-mua.org', | ||||
) | ||||
Gregory Szorc
|
r29451 | |||
c = { | ||||
'notAfter': 'Jun 26 21:41:46 2011 GMT', | ||||
'subject': (((u'commonName', u'linuxfrz.org'),),), | ||||
'subjectAltName': ( | ||||
('DNS', 'linuxfr.org'), | ||||
('DNS', 'linuxfr.com'), | ||||
('othername', '<unsupported>'), | ||||
Augie Fackler
|
r43346 | ), | ||
Gregory Szorc
|
r29451 | } | ||
check(_verifycert(c, 'linuxfr.org'), None) | ||||
check(_verifycert(c, 'linuxfr.com'), None) | ||||
# Not a "DNS" entry | ||||
Augie Fackler
|
r43346 | check( | ||
_verifycert(c, '<unsupported>'), | ||||
b'certificate is for linuxfr.org, linuxfr.com', | ||||
) | ||||
Gregory Szorc
|
r29451 | # When there is a subjectAltName, commonName isn't used | ||
Augie Fackler
|
r43346 | check( | ||
_verifycert(c, 'linuxfrz.org'), | ||||
b'certificate is for linuxfr.org, linuxfr.com', | ||||
) | ||||
Gregory Szorc
|
r29451 | |||
# A pristine real-world example | ||||
c = { | ||||
'notAfter': 'Dec 18 23:59:59 2011 GMT', | ||||
'subject': ( | ||||
((u'countryName', u'US'),), | ||||
((u'stateOrProvinceName', u'California'),), | ||||
((u'localityName', u'Mountain View'),), | ||||
((u'organizationName', u'Google Inc'),), | ||||
((u'commonName', u'mail.google.com'),), | ||||
), | ||||
} | ||||
check(_verifycert(c, 'mail.google.com'), None) | ||||
Augie Fackler
|
r37892 | check(_verifycert(c, 'gmail.com'), b'certificate is for mail.google.com') | ||
Gregory Szorc
|
r29451 | |||
# Only commonName is considered | ||||
Augie Fackler
|
r37892 | check(_verifycert(c, 'California'), b'certificate is for mail.google.com') | ||
Gregory Szorc
|
r29451 | |||
# Neither commonName nor subjectAltName | ||||
c = { | ||||
'notAfter': 'Dec 18 23:59:59 2011 GMT', | ||||
'subject': ( | ||||
((u'countryName', u'US'),), | ||||
((u'stateOrProvinceName', u'California'),), | ||||
((u'localityName', u'Mountain View'),), | ||||
((u'organizationName', u'Google Inc'),), | ||||
), | ||||
} | ||||
Augie Fackler
|
r43346 | check( | ||
_verifycert(c, 'mail.google.com'), | ||||
b'no commonName or subjectAltName found in certificate', | ||||
) | ||||
Gregory Szorc
|
r29451 | |||
# No DNS entry in subjectAltName but a commonName | ||||
c = { | ||||
'notAfter': 'Dec 18 23:59:59 2099 GMT', | ||||
'subject': ( | ||||
((u'countryName', u'US'),), | ||||
((u'stateOrProvinceName', u'California'),), | ||||
((u'localityName', u'Mountain View'),), | ||||
((u'commonName', u'mail.google.com'),), | ||||
), | ||||
'subjectAltName': (('othername', 'blabla'),), | ||||
} | ||||
check(_verifycert(c, 'mail.google.com'), None) | ||||
# No DNS entry subjectAltName and no commonName | ||||
c = { | ||||
'notAfter': 'Dec 18 23:59:59 2099 GMT', | ||||
'subject': ( | ||||
((u'countryName', u'US'),), | ||||
((u'stateOrProvinceName', u'California'),), | ||||
((u'localityName', u'Mountain View'),), | ||||
((u'organizationName', u'Google Inc'),), | ||||
), | ||||
'subjectAltName': (('othername', 'blabla'),), | ||||
} | ||||
Augie Fackler
|
r43346 | check( | ||
_verifycert(c, 'google.com'), | ||||
b'no commonName or subjectAltName found in certificate', | ||||
) | ||||
Gregory Szorc
|
r29451 | |||
# Empty cert / no cert | ||||
Augie Fackler
|
r37892 | check(_verifycert(None, 'example.com'), b'no certificate received') | ||
check(_verifycert({}, 'example.com'), b'no certificate received') | ||||
Gregory Szorc
|
r29451 | |||
# avoid denials of service by refusing more than one | ||||
# wildcard per fragment. | ||||
Augie Fackler
|
r43346 | check( | ||
_verifycert({'subject': (((u'commonName', u'a*b.com'),),)}, 'axxb.com'), | ||||
None, | ||||
) | ||||
check( | ||||
_verifycert({'subject': (((u'commonName', u'a*b.co*'),),)}, 'axxb.com'), | ||||
b'certificate is for a*b.co*', | ||||
) | ||||
check( | ||||
_verifycert({'subject': (((u'commonName', u'a*b*.com'),),)}, 'axxbxxc.com'), | ||||
b'too many wildcards in certificate DNS name: a*b*.com', | ||||
) | ||||
Gregory Szorc
|
r29451 | |||
Brodie Rao
|
r13770 | def test_url(): | ||
""" | ||||
Augie Fackler
|
r37891 | >>> from mercurial import error, pycompat | ||
r47669 | >>> from mercurial.utils.urlutil import url | |||
Augie Fackler
|
r37974 | >>> from mercurial.utils.stringutil import forcebytestr | ||
Brodie Rao
|
r13770 | |||
This tests for edge cases in url.URL's parsing algorithm. Most of | ||||
these aren't useful for documentation purposes, so they aren't | ||||
part of the class's doc tests. | ||||
Query strings and fragments: | ||||
Augie Fackler
|
r37892 | >>> url(b'http://host/a?b#c') | ||
Brodie Rao
|
r13770 | <url scheme: 'http', host: 'host', path: 'a', query: 'b', fragment: 'c'> | ||
Augie Fackler
|
r37892 | >>> url(b'http://host/a?') | ||
Brodie Rao
|
r13770 | <url scheme: 'http', host: 'host', path: 'a'> | ||
Augie Fackler
|
r37892 | >>> url(b'http://host/a#b#c') | ||
Brodie Rao
|
r13770 | <url scheme: 'http', host: 'host', path: 'a', fragment: 'b#c'> | ||
Augie Fackler
|
r37892 | >>> url(b'http://host/a#b?c') | ||
Brodie Rao
|
r13770 | <url scheme: 'http', host: 'host', path: 'a', fragment: 'b?c'> | ||
Augie Fackler
|
r37892 | >>> url(b'http://host/?a#b') | ||
Brodie Rao
|
r13770 | <url scheme: 'http', host: 'host', path: '', query: 'a', fragment: 'b'> | ||
Augie Fackler
|
r37892 | >>> url(b'http://host/?a#b', parsequery=False) | ||
Brodie Rao
|
r13770 | <url scheme: 'http', host: 'host', path: '?a', fragment: 'b'> | ||
Augie Fackler
|
r37892 | >>> url(b'http://host/?a#b', parsefragment=False) | ||
Brodie Rao
|
r13770 | <url scheme: 'http', host: 'host', path: '', query: 'a#b'> | ||
Augie Fackler
|
r37892 | >>> url(b'http://host/?a#b', parsequery=False, parsefragment=False) | ||
Brodie Rao
|
r13770 | <url scheme: 'http', host: 'host', path: '?a#b'> | ||
IPv6 addresses: | ||||
Augie Fackler
|
r37892 | >>> url(b'ldap://[2001:db8::7]/c=GB?objectClass?one') | ||
Brodie Rao
|
r13770 | <url scheme: 'ldap', host: '[2001:db8::7]', path: 'c=GB', | ||
query: 'objectClass?one'> | ||||
Augie Fackler
|
r37892 | >>> url(b'ldap://joe:xxx@[2001:db8::7]:80/c=GB?objectClass?one') | ||
Brodie Rao
|
r13770 | <url scheme: 'ldap', user: 'joe', passwd: 'xxx', host: '[2001:db8::7]', | ||
port: '80', path: 'c=GB', query: 'objectClass?one'> | ||||
Missing scheme, host, etc.: | ||||
Augie Fackler
|
r37892 | >>> url(b'://192.0.2.16:80/') | ||
Brodie Rao
|
r13770 | <url path: '://192.0.2.16:80/'> | ||
Augie Fackler
|
r37892 | >>> url(b'https://mercurial-scm.org') | ||
Matt Mackall
|
r26421 | <url scheme: 'https', host: 'mercurial-scm.org'> | ||
Augie Fackler
|
r37892 | >>> url(b'/foo') | ||
Brodie Rao
|
r13770 | <url path: '/foo'> | ||
Augie Fackler
|
r37892 | >>> url(b'bundle:/foo') | ||
Brodie Rao
|
r13770 | <url scheme: 'bundle', path: '/foo'> | ||
Augie Fackler
|
r37892 | >>> url(b'a?b#c') | ||
Brodie Rao
|
r13770 | <url path: 'a?b', fragment: 'c'> | ||
Augie Fackler
|
r37892 | >>> url(b'http://x.com?arg=/foo') | ||
Brodie Rao
|
r13770 | <url scheme: 'http', host: 'x.com', query: 'arg=/foo'> | ||
Augie Fackler
|
r37892 | >>> url(b'http://joe:xxx@/foo') | ||
Brodie Rao
|
r13770 | <url scheme: 'http', user: 'joe', passwd: 'xxx', path: 'foo'> | ||
Just a scheme and a path: | ||||
Augie Fackler
|
r37892 | >>> url(b'mailto:John.Doe@example.com') | ||
Brodie Rao
|
r13770 | <url scheme: 'mailto', path: 'John.Doe@example.com'> | ||
Augie Fackler
|
r37892 | >>> url(b'a:b:c:d') | ||
Matt Mackall
|
r13808 | <url path: 'a:b:c:d'> | ||
Augie Fackler
|
r37892 | >>> url(b'aa:bb:cc:dd') | ||
Matt Mackall
|
r13808 | <url scheme: 'aa', path: 'bb:cc:dd'> | ||
Brodie Rao
|
r13770 | |||
SSH examples: | ||||
Augie Fackler
|
r37892 | >>> url(b'ssh://joe@host//home/joe') | ||
Brodie Rao
|
r13770 | <url scheme: 'ssh', user: 'joe', host: 'host', path: '/home/joe'> | ||
Augie Fackler
|
r37892 | >>> url(b'ssh://joe:xxx@host/src') | ||
Brodie Rao
|
r13770 | <url scheme: 'ssh', user: 'joe', passwd: 'xxx', host: 'host', path: 'src'> | ||
Augie Fackler
|
r37892 | >>> url(b'ssh://joe:xxx@host') | ||
Brodie Rao
|
r13770 | <url scheme: 'ssh', user: 'joe', passwd: 'xxx', host: 'host'> | ||
Augie Fackler
|
r37892 | >>> url(b'ssh://joe@host') | ||
Brodie Rao
|
r13770 | <url scheme: 'ssh', user: 'joe', host: 'host'> | ||
Augie Fackler
|
r37892 | >>> url(b'ssh://host') | ||
Brodie Rao
|
r13770 | <url scheme: 'ssh', host: 'host'> | ||
Augie Fackler
|
r37892 | >>> url(b'ssh://') | ||
Brodie Rao
|
r13770 | <url scheme: 'ssh'> | ||
Augie Fackler
|
r37892 | >>> url(b'ssh:') | ||
Brodie Rao
|
r13770 | <url scheme: 'ssh'> | ||
Non-numeric port: | ||||
Augie Fackler
|
r37892 | >>> url(b'http://example.com:dd') | ||
Brodie Rao
|
r13770 | <url scheme: 'http', host: 'example.com', port: 'dd'> | ||
Augie Fackler
|
r37892 | >>> url(b'ssh://joe:xxx@host:ssh/foo') | ||
Brodie Rao
|
r13770 | <url scheme: 'ssh', user: 'joe', passwd: 'xxx', host: 'host', port: 'ssh', | ||
path: 'foo'> | ||||
Bad authentication credentials: | ||||
Augie Fackler
|
r37892 | >>> url(b'http://joe@joeville:123@4:@host/a?b#c') | ||
Brodie Rao
|
r13770 | <url scheme: 'http', user: 'joe@joeville', passwd: '123@4:', | ||
host: 'host', path: 'a', query: 'b', fragment: 'c'> | ||||
Augie Fackler
|
r37892 | >>> url(b'http://!*#?/@!*#?/:@host/a?b#c') | ||
Brodie Rao
|
r13770 | <url scheme: 'http', host: '!*', fragment: '?/@!*#?/:@host/a?b#c'> | ||
Augie Fackler
|
r37892 | >>> url(b'http://!*#?@!*#?:@host/a?b#c') | ||
Brodie Rao
|
r13770 | <url scheme: 'http', host: '!*', fragment: '?@!*#?:@host/a?b#c'> | ||
Augie Fackler
|
r37892 | >>> url(b'http://!*@:!*@@host/a?b#c') | ||
Brodie Rao
|
r13770 | <url scheme: 'http', user: '!*@', passwd: '!*@', host: 'host', | ||
path: 'a', query: 'b', fragment: 'c'> | ||||
File paths: | ||||
Augie Fackler
|
r37892 | >>> url(b'a/b/c/d.g.f') | ||
Brodie Rao
|
r13770 | <url path: 'a/b/c/d.g.f'> | ||
Augie Fackler
|
r37892 | >>> url(b'/x///z/y/') | ||
Brodie Rao
|
r13770 | <url path: '/x///z/y/'> | ||
Augie Fackler
|
r37892 | >>> url(b'/foo:bar') | ||
Brodie Rao
|
r13848 | <url path: '/foo:bar'> | ||
Augie Fackler
|
r37892 | >>> url(b'\\\\foo:bar') | ||
Brodie Rao
|
r13848 | <url path: '\\\\foo:bar'> | ||
Augie Fackler
|
r37892 | >>> url(b'./foo:bar') | ||
Brodie Rao
|
r13848 | <url path: './foo:bar'> | ||
Brodie Rao
|
r13770 | |||
Brodie Rao
|
r13817 | Non-localhost file URL: | ||
Augie Fackler
|
r37891 | >>> try: | ||
... u = url(b'file://mercurial-scm.org/foo') | ||||
... except error.Abort as e: | ||||
Martin von Zweigbergk
|
r46279 | ... pycompat.bytestr(e.message) | ||
Augie Fackler
|
r37891 | 'file:// URLs can only refer to localhost' | ||
Brodie Rao
|
r13817 | |||
Brodie Rao
|
r13770 | Empty URL: | ||
Augie Fackler
|
r37892 | >>> u = url(b'') | ||
Brodie Rao
|
r13770 | >>> u | ||
<url path: ''> | ||||
>>> str(u) | ||||
'' | ||||
Empty path with query string: | ||||
Augie Fackler
|
r37892 | >>> str(url(b'http://foo/?bar')) | ||
Brodie Rao
|
r13770 | 'http://foo/?bar' | ||
Invalid path: | ||||
Augie Fackler
|
r37892 | >>> u = url(b'http://foo/bar') | ||
>>> u.path = b'bar' | ||||
Brodie Rao
|
r13770 | >>> str(u) | ||
'http://foo/bar' | ||||
Augie Fackler
|
r37892 | >>> u = url(b'file:/foo/bar/baz') | ||
Peter Arrenbrecht
|
r14313 | >>> u | ||
<url scheme: 'file', path: '/foo/bar/baz'> | ||||
>>> str(u) | ||||
'file:///foo/bar/baz' | ||||
Augie Fackler
|
r37892 | >>> pycompat.bytestr(u.localpath()) | ||
Mads Kiilerich
|
r15018 | '/foo/bar/baz' | ||
Peter Arrenbrecht
|
r14313 | |||
Augie Fackler
|
r37892 | >>> u = url(b'file:///foo/bar/baz') | ||
Brodie Rao
|
r13770 | >>> u | ||
<url scheme: 'file', path: '/foo/bar/baz'> | ||||
>>> str(u) | ||||
Peter Arrenbrecht
|
r14313 | 'file:///foo/bar/baz' | ||
Augie Fackler
|
r37892 | >>> pycompat.bytestr(u.localpath()) | ||
Mads Kiilerich
|
r15018 | '/foo/bar/baz' | ||
Augie Fackler
|
r37892 | >>> u = url(b'file:///f:oo/bar/baz') | ||
Mads Kiilerich
|
r15018 | >>> u | ||
<url scheme: 'file', path: 'f:oo/bar/baz'> | ||||
>>> str(u) | ||||
Matt Mackall
|
r15611 | 'file:///f:oo/bar/baz' | ||
Augie Fackler
|
r37892 | >>> pycompat.bytestr(u.localpath()) | ||
Mads Kiilerich
|
r15018 | 'f:oo/bar/baz' | ||
Peter Arrenbrecht
|
r14313 | |||
Augie Fackler
|
r37892 | >>> u = url(b'file://localhost/f:oo/bar/baz') | ||
Mads Kiilerich
|
r15496 | >>> u | ||
<url scheme: 'file', host: 'localhost', path: 'f:oo/bar/baz'> | ||||
>>> str(u) | ||||
Matt Mackall
|
r15513 | 'file://localhost/f:oo/bar/baz' | ||
Augie Fackler
|
r37892 | >>> pycompat.bytestr(u.localpath()) | ||
Mads Kiilerich
|
r15496 | 'f:oo/bar/baz' | ||
Augie Fackler
|
r37892 | >>> u = url(b'file:foo/bar/baz') | ||
Peter Arrenbrecht
|
r14313 | >>> u | ||
<url scheme: 'file', path: 'foo/bar/baz'> | ||||
>>> str(u) | ||||
'file:foo/bar/baz' | ||||
Augie Fackler
|
r37892 | >>> pycompat.bytestr(u.localpath()) | ||
Mads Kiilerich
|
r15018 | 'foo/bar/baz' | ||
Brodie Rao
|
r13770 | """ | ||
Augie Fackler
|
r43346 | |||
Brodie Rao
|
r15398 | if 'TERM' in os.environ: | ||
del os.environ['TERM'] | ||||
Brodie Rao
|
r13770 | doctest.testmod(optionflags=doctest.NORMALIZE_WHITESPACE) | ||