1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585
|
# -*- coding: iso-8859-1 -*-
# Copyright (C) 2004-2014 Bastian Kleineidam
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
"""
Test url routines.
"""
from . import need_network, need_posix, need_windows
import unittest
import os
import re
import linkcheck.url
# 'ftp://user:pass@ftp.foo.net/foo/bar':
# 'ftp://user:pass@ftp.foo.net/foo/bar',
# 'http://USER:pass@www.Example.COM/foo/bar':
# 'http://USER:pass@www.example.com/foo/bar',
# '-': '-',
# All portions of the URI must be utf-8 encoded NFC form Unicode strings
#valid: http://example.com/?q=%C3%87 (C-cedilla U+00C7)
#valid: http://example.com/?q=%E2%85%A0 (Roman numeral one U+2160)
#invalid: http://example.com/?q=%C7 (C-cedilla ISO-8859-1)
#invalid: http://example.com/?q=C%CC%A7
# (Latin capital letter C + Combining cedilla U+0327)
def url_norm (url, encoding=None):
return linkcheck.url.url_norm(url, encoding=encoding)[0]
class TestUrl (unittest.TestCase):
"""Test url norming and quoting."""
def urlnormtest (self, url, nurl, encoding=None):
self.assertFalse(linkcheck.url.url_needs_quoting(nurl),
"Result URL %r must not need quoting" % nurl)
nurl1 = url_norm(url, encoding=encoding)
self.assertFalse(linkcheck.url.url_needs_quoting(nurl1),
"Normed URL %r needs quoting" % nurl)
self.assertEqual(nurl1, nurl)
def test_pathattack (self):
# Windows winamp path attack prevention.
url = "http://server/..%5c..%5c..%5c..%5c..%5c..%5c..%5c.."\
"%5ccskin.zip"
nurl = "http://server/cskin.zip"
self.assertEqual(linkcheck.url.url_quote(url_norm(url)), nurl)
def test_safe_patterns (self):
is_safe_host = linkcheck.url.is_safe_host
safe_host_pattern = linkcheck.url.safe_host_pattern
self.assertTrue(is_safe_host("example.org"))
self.assertTrue(is_safe_host("example.org:80"))
self.assertTrue(not is_safe_host("example.org:21"))
pat = safe_host_pattern("example.org")
ro = re.compile(pat)
self.assertTrue(ro.match("http://example.org:80/"))
def test_url_quote (self):
url_quote = linkcheck.url.url_quote
url = "http://a:80/bcd"
self.assertEqual(url_quote(url), url)
url = "http://a:80/bcd?"
url2 = "http://a:80/bcd"
self.assertEqual(url_quote(url), url2)
url = "http://a:80/bcd?a=b"
url2 = "http://a:80/bcd?a=b"
self.assertEqual(url_quote(url), url2)
url = "a/b"
self.assertEqual(url_quote(url), url)
url = "bcd?"
url2 = "bcd"
self.assertEqual(url_quote(url), url2)
url = "bcd?a=b"
url2 = "bcd?a=b"
self.assertEqual(url_quote(url), url2)
def test_norm_quote (self):
# Test url norm quoting.
url = "http://groups.google.com/groups?hl=en&lr&ie=UTF-8&"\
"threadm=3845B54D.E546F9BD%40monmouth.com&rnum=2&"\
"prev=/groups%3Fq%3Dlogitech%2Bwingman%2Bextreme%2Bdigital"\
"%2B3d%26hl%3Den%26lr%3D%26ie%3DUTF-8%26selm%3D3845B54D.E5"\
"46F9BD%2540monmouth.com%26rnum%3D2"
self.urlnormtest(url, url)
url = "http://redirect.alexa.com/redirect?"\
"http://www.offeroptimizer.com"
self.urlnormtest(url, url)
url = "http://www.lesgensducinema.com/photo/Philippe%20Nahon.jpg"
self.urlnormtest(url, url)
# Only perform percent-encoding where it is essential.
url = "http://example.com/%7Ejane"
nurl = "http://example.com/~jane"
self.urlnormtest(url, nurl)
url = "http://example.com/%7ejane"
self.urlnormtest(url, nurl)
# Always use uppercase A-through-F characters when percent-encoding.
url = "http://example.com/?q=1%2a2"
nurl = "http://example.com/?q=1%2A2"
self.urlnormtest(url, nurl)
# the no-quote chars
url = "http://example.com/a*+-();b"
self.urlnormtest(url, url)
url = "http://linkchecker.git.sourceforge.net/git/gitweb.cgi?p=linkchecker/linkchecker;a=blob;f=doc/changelog.txt;hb=HEAD"
self.urlnormtest(url, url)
url = "http://www.company.com/path/doc.html?url=/path2/doc2.html?foo=bar"
self.urlnormtest(url, url)
url = "http://example.com/#a b"
nurl = "http://example.com/#a%20b"
self.urlnormtest(url, nurl)
url = "http://example.com/?u=http://example2.com?b=c "
nurl = "http://example.com/?u=http://example2.com?b=c%20"
self.urlnormtest(url, nurl)
url = "http://example.com/?u=http://example2.com?b="
nurl = "http://example.com/?u=http://example2.com?b="
self.urlnormtest(url, nurl)
url = "http://localhost:8001/?quoted="
nurl = "http://localhost:8001/?quoted=%FC"
self.urlnormtest(url, nurl, encoding="iso-8859-1")
url = "http://host/?a=b/c+d="
nurl = "http://host/?a=b/c%20d%3D"
self.urlnormtest(url, nurl)
def test_norm_case_sensitivity (self):
# Test url norm case sensitivity.
# Always provide the URI scheme in lowercase characters.
url = "HTTP://example.com/"
nurl = "http://example.com/"
self.urlnormtest(url, nurl)
# Always provide the host, if any, in lowercase characters.
url = "http://EXAMPLE.COM/"
nurl = "http://example.com/"
self.urlnormtest(url, nurl)
url = "http://EXAMPLE.COM:55/"
nurl = "http://example.com:55/"
self.urlnormtest(url, nurl)
def test_norm_defaultport (self):
# Test url norm default port recognition.
# For schemes that define a port, use an empty port if the default
# is desired
url = "http://example.com:80/"
nurl = "http://example.com/"
self.urlnormtest(url, nurl)
url = "http://example.com:8080/"
nurl = "http://example.com:8080/"
self.urlnormtest(url, nurl)
def test_norm_host_dot (self):
# Test url norm host dot removal.
url = "http://example.com./"
nurl = "http://example.com/"
self.urlnormtest(url, nurl)
url = "http://example.com.:81/"
nurl = "http://example.com:81/"
self.urlnormtest(url, nurl)
def test_norm_fragment (self):
# Test url norm fragment preserving.
# Empty fragment identifiers must be preserved:
url = "http://www.w3.org/2000/01/rdf-schema#"
nurl = url
self.urlnormtest(url, nurl)
url = "http://example.org/foo/ #a=1,2,3"
nurl = "http://example.org/foo/%20#a%3D1%2C2%2C3"
self.urlnormtest(url, nurl)
def test_norm_empty_path (self):
# Test url norm empty path handling.
# For schemes that define an empty path to be equivalent to a
# path of "/", use "/".
url = "http://example.com"
nurl = "http://example.com"
self.urlnormtest(url, nurl)
url = "http://example.com?a=b"
nurl = "http://example.com/?a=b"
self.urlnormtest(url, nurl)
url = "http://example.com#foo"
nurl = "http://example.com/#foo"
self.urlnormtest(url, nurl)
def test_norm_path_backslashes (self):
# Test url norm backslash path handling.
# note: this is not RFC conform (see url.py for more info)
url = r"http://example.com\test.html"
nurl = "http://example.com/test.html"
self.urlnormtest(url, nurl)
url = r"http://example.com/a\test.html"
nurl = "http://example.com/a/test.html"
self.urlnormtest(url, nurl)
url = r"http://example.com\a\test.html"
nurl = "http://example.com/a/test.html"
self.urlnormtest(url, nurl)
url = r"http://example.com\a/test.html"
nurl = "http://example.com/a/test.html"
self.urlnormtest(url, nurl)
def test_norm_path_slashes (self):
# Test url norm slashes in path handling.
# reduce duplicate slashes
url = "http://example.com//a/test.html"
nurl = "http://example.com/a/test.html"
self.urlnormtest(url, nurl)
url = "http://example.com//a/b/"
nurl = "http://example.com/a/b/"
self.urlnormtest(url, nurl)
def test_norm_path_dots (self):
# Test url norm dots in path handling.
# Prevent dot-segments appearing in non-relative URI paths.
url = "http://example.com/a/./b"
nurl = "http://example.com/a/b"
self.urlnormtest(url, nurl)
url = "http://example.com/a/../a/b"
self.urlnormtest(url, nurl)
url = "http://example.com/../a/b"
self.urlnormtest(url, nurl)
def test_norm_path_relative_dots (self):
# Test url norm relative path handling with dots.
# normalize redundant path segments
url = '/foo/bar/.'
nurl = '/foo/bar/'
self.urlnormtest(url, nurl)
url = '/foo/bar/./'
nurl = '/foo/bar/'
self.urlnormtest(url, nurl)
url = '/foo/bar/..'
nurl = '/foo/'
self.urlnormtest(url, nurl)
url = '/foo/bar/../'
nurl = '/foo/'
self.urlnormtest(url, nurl)
url = '/foo/bar/../baz'
nurl = '/foo/baz'
self.urlnormtest(url, nurl)
url = '/foo/bar/../..'
nurl = '/'
self.urlnormtest(url, nurl)
url = '/foo/bar/../../'
nurl = '/'
self.urlnormtest(url, nurl)
url = '/foo/bar/../../baz'
nurl = '/baz'
self.urlnormtest(url, nurl)
url = '/foo/bar/../../../baz'
nurl = '/baz'
self.urlnormtest(url, nurl)
url = '/foo/bar/../../../../baz'
nurl = '/baz'
self.urlnormtest(url, nurl)
url = '/./foo'
nurl = '/foo'
self.urlnormtest(url, nurl)
url = '/../foo'
nurl = '/foo'
self.urlnormtest(url, nurl)
url = '/foo.'
nurl = url
self.urlnormtest(url, nurl)
url = '/.foo'
nurl = url
self.urlnormtest(url, nurl)
url = '/foo..'
nurl = url
self.urlnormtest(url, nurl)
url = '/..foo'
nurl = url
self.urlnormtest(url, nurl)
url = '/./../foo'
nurl = '/foo'
self.urlnormtest(url, nurl)
url = '/./foo/.'
nurl = '/foo/'
self.urlnormtest(url, nurl)
url = '/foo/./bar'
nurl = '/foo/bar'
self.urlnormtest(url, nurl)
url = '/foo/../bar'
nurl = '/bar'
self.urlnormtest(url, nurl)
url = '../../../images/miniXmlButton.gif'
nurl = url
self.urlnormtest(url, nurl)
url = '/a..b/../images/miniXmlButton.gif'
nurl = '/images/miniXmlButton.gif'
self.urlnormtest(url, nurl)
url = '/.a.b/../foo/'
nurl = '/foo/'
self.urlnormtest(url, nurl)
url = '/..a.b/../foo/'
nurl = '/foo/'
self.urlnormtest(url, nurl)
url = 'b/../../foo/'
nurl = '../foo/'
self.urlnormtest(url, nurl)
url = './foo'
nurl = 'foo'
self.urlnormtest(url, nurl)
def test_norm_path_relative_slashes (self):
# Test url norm relative path handling with slashes.
url = '/foo//'
nurl = '/foo/'
self.urlnormtest(url, nurl)
url = '/foo///bar//'
nurl = '/foo/bar/'
self.urlnormtest(url, nurl)
def test_mail_url (self):
# Test mailto URLs.
# no netloc and no path
url = 'mailto:'
nurl = url
self.urlnormtest(url, nurl)
# standard email
url = 'mailto:user@www.example.org'
nurl = url
self.urlnormtest(url, nurl)
# emails with subject
url = 'mailto:user@www.example.org?subject=a_b'
nurl = url
self.urlnormtest(url, nurl)
url = 'mailto:business.inquiries@designingpatterns.com?subject=Business%20Inquiry'
nurl = url
self.urlnormtest(url, nurl)
def test_norm_other (self):
# Test norming of other schemes.
url = 'news:'
nurl = 'news:'
self.urlnormtest(url, nurl)
url = 'snews:'
nurl = 'snews://'
self.urlnormtest(url, nurl)
url = 'nntp:'
nurl = 'nntp://'
self.urlnormtest(url, nurl)
url = "news:!$%&/()="
nurl = 'news:!%24%25%26/()='
self.urlnormtest(url, nurl)
url = "news:comp.infosystems.www.servers.unix"
nurl = url
self.urlnormtest(url, nurl)
# javascript url
url = "javascript:loadthis()"
nurl = url
self.urlnormtest(url, nurl)
# ldap url # XXX failing on Travis build
#url = "ldap://[2001:db8::7]/c=GB?objectClass?one"
#nurl = "ldap://%5B2001:db8::7%5D/c=GB?objectClass?one"
#self.urlnormtest(url, nurl)
url = "tel:+1-816-555-1212"
nurl = url
self.urlnormtest(url, nurl)
url = "urn:oasis:names:specification:docbook:dtd:xml:4.1.2"
nurl = "urn:oasis%3Anames%3Aspecification%3Adocbook%3Adtd%3Axml%3A4.1.2"
self.urlnormtest(url, nurl)
def test_norm_with_auth (self):
# Test norming of URLs with authentication tokens.
url = "telnet://User@www.example.org"
nurl = url
self.urlnormtest(url, nurl)
url = "telnet://User:Pass@www.example.org"
nurl = url
self.urlnormtest(url, nurl)
url = "http://User:Pass@www.example.org/"
nurl = url
self.urlnormtest(url, nurl)
@need_posix
def test_norm_file1 (self):
url = "file:///a/b.txt"
nurl = url
self.urlnormtest(url, nurl)
@need_windows
def test_norm_file2 (self):
url = "file:///C|/a/b.txt"
nurl = url
self.urlnormtest(url, nurl)
@need_posix
def test_norm_file_unicode (self):
url = u"file:///a/b.txt"
nurl = url
self.urlnormtest(url, nurl)
url = u"file:///a/.txt"
nurl = u"file:///a/%E4.txt"
self.urlnormtest(url, nurl, encoding="iso-8859-1")
#url = u"file:///\u041c\u043e\u0448\u043a\u043e\u0432\u0430.bin"
#nurl = u"file:///a.bin" # XXX
#self.urlnormtest(url, nurl)
def test_norm_invalid (self):
url = u"?:"
nurl = u"%E4%F6%FC?:"
self.urlnormtest(url, nurl, encoding="iso-8859-1")
def test_fixing (self):
# Test url fix method.
url = "http//www.example.org"
nurl = "http://www.example.org"
self.assertEqual(linkcheck.url.url_fix_common_typos(url), nurl)
url = u"http//www.example.org"
nurl = u"http://www.example.org"
self.assertEqual(linkcheck.url.url_fix_common_typos(url), nurl)
url = u"https//www.example.org"
nurl = u"https://www.example.org"
self.assertEqual(linkcheck.url.url_fix_common_typos(url), nurl)
def test_valid (self):
# Test url validity functions.
u = "http://www.example.com"
self.assertTrue(linkcheck.url.is_safe_url(u), u)
u = "http://www.example.com/"
self.assertTrue(linkcheck.url.is_safe_url(u), u)
u = "http://www.example.com/~calvin"
self.assertTrue(linkcheck.url.is_safe_url(u), u)
u = "http://www.example.com/a,b"
self.assertTrue(linkcheck.url.is_safe_url(u), u)
u = "http://www.example.com#anchor55"
self.assertTrue(linkcheck.url.is_safe_url(u), u)
def test_needs_quoting (self):
# Test url quoting necessity.
url = "mailto:<calvin@example.org>?subject=Halli Hallo"
self.assertTrue(linkcheck.url.url_needs_quoting(url), repr(url))
url = " http://www.example.com/"
self.assertTrue(linkcheck.url.url_needs_quoting(url), repr(url))
url = "http://www.example.com/ "
self.assertTrue(linkcheck.url.url_needs_quoting(url), repr(url))
url = "http://www.example.com/\n"
self.assertTrue(linkcheck.url.url_needs_quoting(url), repr(url))
url = "\nhttp://www.example.com/"
self.assertTrue(linkcheck.url.url_needs_quoting(url), repr(url))
url = "http://www.example.com/#a!"
self.assertTrue(not linkcheck.url.url_needs_quoting(url), repr(url))
url = "http://www.example.com/#a b"
self.assertTrue(linkcheck.url.url_needs_quoting(url), repr(url))
def test_absolute_url (self):
url = "hutzli:"
self.assertTrue(linkcheck.url.url_is_absolute(url), repr(url))
url = "file:/"
self.assertTrue(linkcheck.url.url_is_absolute(url), repr(url))
url = ":"
self.assertTrue(not linkcheck.url.url_is_absolute(url), repr(url))
url = "/a/b?http://"
self.assertTrue(not linkcheck.url.url_is_absolute(url), repr(url))
def test_nopathquote_chars (self):
if os.name == 'nt':
url = "file:///c|/msys/"
nurl = url
self.assertEqual(url_norm(url), nurl)
self.assertTrue(not linkcheck.url.url_needs_quoting(url))
url = "http://hulla/a/b/!?c=d"
nurl = url
self.assertEqual(url_norm(url), nurl)
def test_idn_encoding (self):
# Test idna encoding.
url = u'www.ko.de'
idna_encode = linkcheck.url.idna_encode
encurl, is_idn = idna_encode(url)
self.assertTrue(is_idn)
self.assertTrue(encurl)
url = u''
encurl, is_idn = idna_encode(url)
self.assertFalse(is_idn)
self.assertFalse(encurl)
url = u".."
self.assertRaises(UnicodeError, idna_encode, url)
def test_match_host (self):
# Test host matching.
match_host = linkcheck.url.match_host
match_url = linkcheck.url.match_url
self.assertTrue(not match_host("", []))
self.assertTrue(not match_host("", [".localhost"]))
self.assertTrue(not match_host("localhost", []))
self.assertTrue(not match_host("localhost", [".localhost"]))
self.assertTrue(match_host("a.localhost", [".localhost"]))
self.assertTrue(match_host("localhost", ["localhost"]))
self.assertTrue(not match_url("", []))
self.assertTrue(not match_url("a", []))
self.assertTrue(match_url("http://example.org/hulla", ["example.org"]))
def test_splitparam (self):
# Path parameter split test.
p = [
("", ("", "")),
("/", ("/", "")),
("a", ("a", "")),
("a;", ("a", "")),
("a/b;c/d;e", ("a/b;c/d", "e")),
]
for x in p:
self._splitparam(x)
def _splitparam (self, x):
self.assertEqual(linkcheck.url.splitparams(x[0]), (x[1][0], x[1][1]))
def test_cgi_split (self):
# Test cgi parameter splitting.
u = "scid=kb;en-us;Q248840"
self.assertEqual(linkcheck.url.url_parse_query(u), u)
u = "scid=kb;en-us;Q248840&b=c;hulla=bulla"
self.assertEqual(linkcheck.url.url_parse_query(u), u)
def test_long_cgi (self):
u = "/test%s;" % ("?a="*1000)
self.assertEqual(linkcheck.url.url_parse_query(u), u)
def test_port (self):
is_numeric_port = linkcheck.url.is_numeric_port
self.assertTrue(is_numeric_port("80"))
self.assertTrue(is_numeric_port("1"))
self.assertFalse(is_numeric_port("0"))
self.assertFalse(is_numeric_port("66000"))
self.assertFalse(is_numeric_port("-1"))
self.assertFalse(is_numeric_port("a"))
def test_split (self):
url_split = linkcheck.url.url_split
url_unsplit = linkcheck.url.url_unsplit
url = "http://example.org/whoops"
self.assertEqual(url_unsplit(url_split(url)), url)
url = "http://example.org:123/whoops"
self.assertEqual(url_unsplit(url_split(url)), url)
def test_safe_domain (self):
is_safe_domain = linkcheck.url.is_safe_domain
self.assertFalse(is_safe_domain(u"a..example.com"))
self.assertFalse(is_safe_domain(u"a_b.example.com"))
self.assertTrue(is_safe_domain(u"a-b.example.com"))
self.assertTrue(is_safe_domain(u"x1.example.com"))
@need_network
def test_get_content (self):
linkcheck.url.get_content('http://www.debian.org/')
def test_duplicate_urls(self):
is_dup = linkcheck.url.is_duplicate_content_url
self.assertTrue(is_dup("http://example.org", "http://example.org"))
self.assertTrue(is_dup("http://example.org/", "http://example.org"))
self.assertTrue(is_dup("http://example.org", "http://example.org/"))
self.assertTrue(is_dup("http://example.org/index.html", "http://example.org"))
self.assertTrue(is_dup("http://example.org", "http://example.org/index.html"))
self.assertTrue(is_dup("http://example.org/index.htm", "http://example.org"))
self.assertTrue(is_dup("http://example.org", "http://example.org/index.htm"))
def test_splitport(self):
splitport = linkcheck.url.splitport
netloc = "hostname"
host, port = splitport(netloc, 99)
self.assertEqual(host, netloc)
self.assertEqual(port, 99)
netloc = "hostname:"
host, port = splitport(netloc, 99)
self.assertEqual(host, "hostname")
self.assertEqual(port, 99)
netloc = "hostname:42"
host, port = splitport(netloc, 99)
self.assertEqual(host, "hostname")
self.assertEqual(port, 42)
netloc = "hostname:foo"
host, port = splitport(netloc, 99)
self.assertEqual(host, netloc)
self.assertEqual(port, 99)
|