IPv6 support.
This commit is contained in:
parent
02b51b082e
commit
8c2f99951f
5
http.py
5
http.py
@ -19,15 +19,14 @@ class HTTP:
|
|||||||
query = re1.group(7)
|
query = re1.group(7)
|
||||||
fragment = re1.group(9)
|
fragment = re1.group(9)
|
||||||
|
|
||||||
# TODO: Not IPv6 ready!!!
|
re2 = re.match('^(([^:]+)(:([^@]*))?@)?((\[.+\])|[^:]+)(:(\d+))?$', hostpart)
|
||||||
re2 = re.match('^(([^:]+)(:([^@]*))?@)?([^:]+)(:(\d+))?$', hostpart)
|
|
||||||
#for i in range(0, 10):
|
#for i in range(0, 10):
|
||||||
# print(str(i) + ': ' + re2.group(i))
|
# print(str(i) + ': ' + re2.group(i))
|
||||||
|
|
||||||
username = re2.group(2) or None
|
username = re2.group(2) or None
|
||||||
password = re2.group(4) or None
|
password = re2.group(4) or None
|
||||||
hostname = re2.group(5) or None
|
hostname = re2.group(5) or None
|
||||||
port = re2.group(7) or None
|
port = re2.group(8) or None
|
||||||
if port:
|
if port:
|
||||||
port = int(port)
|
port = int(port)
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ class TestHttp(unittest.TestCase):
|
|||||||
import http
|
import http
|
||||||
self.http = http.HTTP()
|
self.http = http.HTTP()
|
||||||
|
|
||||||
def test_parse_url(self):
|
def test_parse_url1(self):
|
||||||
urlparts = self.http.parse_url('https://user:passwd@example.org:1234/test?x=3&y=4#fragme')
|
urlparts = self.http.parse_url('https://user:passwd@example.org:1234/test?x=3&y=4#fragme')
|
||||||
self.assertEqual(urlparts.scheme, 'https')
|
self.assertEqual(urlparts.scheme, 'https')
|
||||||
self.assertEqual(urlparts.hostname, 'example.org')
|
self.assertEqual(urlparts.hostname, 'example.org')
|
||||||
@ -54,6 +54,19 @@ class TestHttp(unittest.TestCase):
|
|||||||
self.assertEqual(urlparts.password, None)
|
self.assertEqual(urlparts.password, None)
|
||||||
self.assertEqual(urlparts.port, 1234)
|
self.assertEqual(urlparts.port, 1234)
|
||||||
|
|
||||||
|
def test_parse_ipv6_1(self):
|
||||||
|
urlparts = self.http.parse_url('http://[fedc:ba98::3210]/test')
|
||||||
|
self.assertEqual(urlparts.hostname, '[fedc:ba98::3210]')
|
||||||
|
|
||||||
|
def test_parse_ipv6_2(self):
|
||||||
|
urlparts = self.http.parse_url('http://[fedc:ba98::3210]:1234/test')
|
||||||
|
self.assertEqual(urlparts.hostname, '[fedc:ba98::3210]')
|
||||||
|
self.assertEqual(urlparts.port, 1234)
|
||||||
|
|
||||||
|
def test_parse_ipv6_3(self):
|
||||||
|
urlparts = self.http.parse_url('http://[::FFFF:129.144.52.38]:5678/blah')
|
||||||
|
self.assertEqual(urlparts.hostname, '[::FFFF:129.144.52.38]')
|
||||||
|
self.assertEqual(urlparts.port, 5678)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user