Exemplo n.º 1
0
	def test_copy(self):
		test = types.CaseInsensitiveDict(TEST)
		copy = test.copy()
		assert test == copy
		
		copy["hi"] = "hello!"
		assert test != copy
Exemplo n.º 2
0
	def test_getitem(self):
		test = types.CaseInsensitiveDict(TEST)
		assert test["HI"] == "hello"
		
		with pytest.raises(KeyError):
			test["hello"]
		with pytest.raises(TypeError):
			test[b"HI"]
Exemplo n.º 3
0
	def test_setitem(self):
		test = types.CaseInsensitiveDict(TEST)
		test["hi"] = "hello!"
		test["hey"] = "hi"
		assert test == {"hi": "hello!", "hey": "hi", "test": "TEST"}
		
		with pytest.raises(TypeError):
			test[0] = "hi"
		with pytest.raises(TypeError):
			test[b"hi"] = "hi"
Exemplo n.º 4
0
	def test_pop(self):
		test = types.CaseInsensitiveDict(TEST)
		assert test.pop("hI") == "hello"
		assert "hI" not in test
		
		with pytest.raises(KeyError):
			test.pop("hI")
		
		assert test.pop("hI", None) is None
		assert test.pop("hI", 1) == 1
Exemplo n.º 5
0
	def test_setdefault(self):
		test = types.CaseInsensitiveDict(TEST)
		assert test.setdefault("hi", "hey") == "hello"
		assert test == TEST
		
		assert test.setdefault("hey", "hi") == "hi"
		assert test == {"hi": "hello", "test": "TEST", "hey": "hi"}
		
		assert test.setdefault("hey") == "hi"
		assert test == {"hi": "hello", "test": "TEST", "hey": "hi"}
		
		assert test.setdefault("hello") is None
		assert test == {"hi": "hello", "test": "TEST", "hey": "hi", "hello": None}
Exemplo n.º 6
0
    def __init__(self):
        self.version = "HTTP/1.1"

        self.headers = types.CaseInsensitiveDict()
        self.body = b""

        self.text = None

        self.files = {}
        self.form = {}
        self.plainform = {}
        self.json = {}
        self.xml = None

        self.boundary = "--------BOUNDARY--------"
Exemplo n.º 7
0
async def get(url, headers={}, context=None):
    if "://" in url:
        scheme, url = url.split("://", 1)
        if scheme == "http":
            context = None
        elif scheme == "https":
            if context is None:
                context = tls.TLSContext()
                context.load_default_authorities()
        else:
            raise ValueError("Invalid HTTP url scheme: %s" % scheme)

    if "/" in url:
        host, path = url.split("/", 1)
    else:
        host = url
        path = "/"

    req = HTTPRequest.get("/" + path)
    req.headers = types.CaseInsensitiveDict(headers)
    req.headers["Host"] = host
    return await request(req, context)
Exemplo n.º 8
0
	def test_popitem(self):
		test = types.CaseInsensitiveDict(TEST)
		assert test.popitem() == ("Test", "TEST")
		assert test == {"hi": "hello"}
Exemplo n.º 9
0
	def test_delitem(self):
		test = types.CaseInsensitiveDict(TEST)
		del test["hI"]
		assert test == {"test": "TEST"}
Exemplo n.º 10
0
	def test_clear(self):
		test = types.CaseInsensitiveDict(TEST)
		test.clear()
		assert test == {}
Exemplo n.º 11
0
	def test_keys(self):
		test = types.CaseInsensitiveDict(TEST)
		assert list(test.keys()) == ["Hi", "Test"]
Exemplo n.º 12
0
	def test_init_empty(self):
		test = types.CaseInsensitiveDict()
		assert test == {}
Exemplo n.º 13
0
	def test_update_empty(self):
		test = types.CaseInsensitiveDict(TEST)
		test.update()
		assert test == TEST
Exemplo n.º 14
0
	def test_contains(self):
		test = types.CaseInsensitiveDict(TEST)
		assert "Hi" in test
		assert "tEsT" in test
		assert "hello" not in test
Exemplo n.º 15
0
	def test_iter(self):
		test = types.CaseInsensitiveDict(TEST)
		for i, item in enumerate(test):
			assert item == ["Hi", "Test"][i]
Exemplo n.º 16
0
	def test_len(self):
		test = types.CaseInsensitiveDict(TEST)
		assert len(test) == 2
Exemplo n.º 17
0
	def test_values(self):
		test = types.CaseInsensitiveDict(TEST)
		assert list(test.values()) == ["hello", "TEST"]
Exemplo n.º 18
0
	def test_standard_dict(self):
		test = types.CaseInsensitiveDict(TEST)
		assert test.standard_dict() == TEST
Exemplo n.º 19
0
	def test_init_dict(self):
		test = types.CaseInsensitiveDict(TEST, HI = "hey")
		assert test == {"hI": "hey", "test": "TEST"}
Exemplo n.º 20
0
	def test_update_items(self):
		test = types.CaseInsensitiveDict(TEST)
		test.update([("hi", "hey"), ("hey", "hi")], HEY="hello")
		assert test == {"hi": "hey", "hey": "hello", "test": "TEST"}
Exemplo n.º 21
0
	def test_update_dict(self):
		test = types.CaseInsensitiveDict(TEST)
		test.update({"hi": "hey", "hey": "hi"})
		assert test == {"hi": "hey", "hey": "hi", "test": "TEST"}
Exemplo n.º 22
0
	def test_get(self):
		test = types.CaseInsensitiveDict(TEST)
		assert test.get("hi") == "hello"
		assert test.get("hi", 1) == "hello"
		assert test.get("hey") is None
		assert test.get("hey", 1) == 1
Exemplo n.º 23
0
	def test_bool(self):
		test = types.CaseInsensitiveDict()
		assert not test
	
		test = types.CaseInsensitiveDict(TEST)
		assert test
Exemplo n.º 24
0
	def test_init_items(self):
		test = types.CaseInsensitiveDict([("Hi", "hello"), ("Test", "TEST")], HI = "hey")
		assert test == {"hI": "hey", "test": "TEST"}
Exemplo n.º 25
0
	def test_items(self):
		test = types.CaseInsensitiveDict(TEST)
		assert list(test.items()) == [("Hi", "hello"), ("Test", "TEST")]