From 08fbe6f1118455bc44d05db30b83bdf81feda2a0 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Tue, 31 May 2016 17:16:31 +1200 Subject: Start cleaning up netlib.utils - Remove http2 functions, move to http2.frame - Remove Serializable, move to netlib.basetypes --- test/netlib/test_utils.py | 27 --------------------------- 1 file changed, 27 deletions(-) (limited to 'test/netlib/test_utils.py') diff --git a/test/netlib/test_utils.py b/test/netlib/test_utils.py index e4c81a48..cd629d77 100644 --- a/test/netlib/test_utils.py +++ b/test/netlib/test_utils.py @@ -144,33 +144,6 @@ def test_parse_content_type(): assert v == ('text', 'html', {'charset': 'UTF-8'}) -class SerializableDummy(utils.Serializable): - def __init__(self, i): - self.i = i - - def get_state(self): - return self.i - - def set_state(self, i): - self.i = i - - def from_state(self, state): - return type(self)(state) - - -class TestSerializable: - - def test_copy(self): - a = SerializableDummy(42) - assert a.i == 42 - b = a.copy() - assert b.i == 42 - - a.set_state(1) - assert a.i == 1 - assert b.i == 42 - - def test_safe_subn(): assert utils.safe_subn("foo", u"bar", "\xc2foo") -- cgit v1.2.3 From 4e6c9c4e935458d23add259dc63c5e0a85fba9c8 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Tue, 31 May 2016 18:42:56 +1200 Subject: Extract url functions from netlib.utils and move to netlib.http.url --- test/netlib/test_utils.py | 64 ----------------------------------------------- 1 file changed, 64 deletions(-) (limited to 'test/netlib/test_utils.py') diff --git a/test/netlib/test_utils.py b/test/netlib/test_utils.py index cd629d77..f9315667 100644 --- a/test/netlib/test_utils.py +++ b/test/netlib/test_utils.py @@ -38,70 +38,6 @@ def test_pretty_size(): assert utils.pretty_size(1024 * 1024) == "1MB" -def test_parse_url(): - with tutils.raises(ValueError): - utils.parse_url("") - - s, h, po, pa = utils.parse_url(b"http://foo.com:8888/test") - assert s == b"http" - assert h == b"foo.com" - assert po == 8888 - assert pa == b"/test" - - s, h, po, pa = utils.parse_url("http://foo/bar") - assert s == b"http" - assert h == b"foo" - assert po == 80 - assert pa == b"/bar" - - s, h, po, pa = utils.parse_url(b"http://user:pass@foo/bar") - assert s == b"http" - assert h == b"foo" - assert po == 80 - assert pa == b"/bar" - - s, h, po, pa = utils.parse_url(b"http://foo") - assert pa == b"/" - - s, h, po, pa = utils.parse_url(b"https://foo") - assert po == 443 - - with tutils.raises(ValueError): - utils.parse_url(b"https://foo:bar") - - # Invalid IDNA - with tutils.raises(ValueError): - utils.parse_url("http://\xfafoo") - # Invalid PATH - with tutils.raises(ValueError): - utils.parse_url("http:/\xc6/localhost:56121") - # Null byte in host - with tutils.raises(ValueError): - utils.parse_url("http://foo\0") - # Port out of range - _, _, port, _ = utils.parse_url("http://foo:999999") - assert port == 80 - # Invalid IPv6 URL - see http://www.ietf.org/rfc/rfc2732.txt - with tutils.raises(ValueError): - utils.parse_url('http://lo[calhost') - - -def test_unparse_url(): - assert utils.unparse_url("http", "foo.com", 99, "") == "http://foo.com:99" - assert utils.unparse_url("http", "foo.com", 80, "/bar") == "http://foo.com/bar" - assert utils.unparse_url("https", "foo.com", 80, "") == "https://foo.com:80" - assert utils.unparse_url("https", "foo.com", 443, "") == "https://foo.com" - - -def test_urlencode(): - assert utils.urlencode([('foo', 'bar')]) - - -def test_urldecode(): - s = "one=two&three=four" - assert len(utils.urldecode(s)) == 2 - - def test_get_header_tokens(): headers = Headers() assert utils.get_header_tokens(headers, "foo") == [] -- cgit v1.2.3 From 15b2374ef9d6a8cbafdff7c79694921387836ff3 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Tue, 31 May 2016 18:54:42 +1200 Subject: netlib.utils.get_header_tokens -> netlib.http1.read.get_header_tokens Placing this next to its only use. --- test/netlib/test_utils.py | 11 ----------- 1 file changed, 11 deletions(-) (limited to 'test/netlib/test_utils.py') diff --git a/test/netlib/test_utils.py b/test/netlib/test_utils.py index f9315667..c4ee3c10 100644 --- a/test/netlib/test_utils.py +++ b/test/netlib/test_utils.py @@ -38,17 +38,6 @@ def test_pretty_size(): assert utils.pretty_size(1024 * 1024) == "1MB" -def test_get_header_tokens(): - headers = Headers() - assert utils.get_header_tokens(headers, "foo") == [] - headers["foo"] = "bar" - assert utils.get_header_tokens(headers, "foo") == ["bar"] - headers["foo"] = "bar, voing" - assert utils.get_header_tokens(headers, "foo") == ["bar", "voing"] - headers.set_all("foo", ["bar, voing", "oink"]) - assert utils.get_header_tokens(headers, "foo") == ["bar", "voing", "oink"] - - def test_multipartdecode(): boundary = 'somefancyboundary' headers = Headers( -- cgit v1.2.3 From ec34cae6181d6af0150ac730d70b96104a07e9d5 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Tue, 31 May 2016 19:07:55 +1200 Subject: utils.multipartdecode -> http.multipart.decode also utils.parse_content_type -> http.headers.parse_content_type --- test/netlib/test_utils.py | 32 -------------------------------- 1 file changed, 32 deletions(-) (limited to 'test/netlib/test_utils.py') diff --git a/test/netlib/test_utils.py b/test/netlib/test_utils.py index c4ee3c10..b3cc9a0b 100644 --- a/test/netlib/test_utils.py +++ b/test/netlib/test_utils.py @@ -1,7 +1,6 @@ # coding=utf-8 from netlib import utils, tutils -from netlib.http import Headers def test_bidi(): @@ -38,37 +37,6 @@ def test_pretty_size(): assert utils.pretty_size(1024 * 1024) == "1MB" -def test_multipartdecode(): - boundary = 'somefancyboundary' - headers = Headers( - content_type='multipart/form-data; boundary=' + boundary - ) - content = ( - "--{0}\n" - "Content-Disposition: form-data; name=\"field1\"\n\n" - "value1\n" - "--{0}\n" - "Content-Disposition: form-data; name=\"field2\"\n\n" - "value2\n" - "--{0}--".format(boundary).encode() - ) - - form = utils.multipartdecode(headers, content) - - assert len(form) == 2 - assert form[0] == (b"field1", b"value1") - assert form[1] == (b"field2", b"value2") - - -def test_parse_content_type(): - p = utils.parse_content_type - assert p("text/html") == ("text", "html", {}) - assert p("text") is None - - v = p("text/html; charset=UTF-8") - assert v == ('text', 'html', {'charset': 'UTF-8'}) - - def test_safe_subn(): assert utils.safe_subn("foo", u"bar", "\xc2foo") -- cgit v1.2.3 From b2f63458fcda7878d5cf674c2f1e9ca7db5bf3ce Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Tue, 31 May 2016 19:32:08 +1200 Subject: Move human-friendly format functions to netlib.human, remove redundant implementations --- test/netlib/test_utils.py | 7 ------- 1 file changed, 7 deletions(-) (limited to 'test/netlib/test_utils.py') diff --git a/test/netlib/test_utils.py b/test/netlib/test_utils.py index b3cc9a0b..e13029cb 100644 --- a/test/netlib/test_utils.py +++ b/test/netlib/test_utils.py @@ -30,13 +30,6 @@ def test_clean_bin(): assert utils.clean_bin(u"\u2605") == u"\u2605" -def test_pretty_size(): - assert utils.pretty_size(100) == "100B" - assert utils.pretty_size(1024) == "1kB" - assert utils.pretty_size(1024 + (1024 / 2.0)) == "1.5kB" - assert utils.pretty_size(1024 * 1024) == "1MB" - - def test_safe_subn(): assert utils.safe_subn("foo", u"bar", "\xc2foo") -- cgit v1.2.3