예제 #1
0
	def test_copy(self):
		test = types.CaseInsensitiveDict(TEST)
		copy = test.copy()
		assert test == copy
		
		copy["hi"] = "hello!"
		assert test != copy
예제 #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"]
예제 #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"
예제 #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
예제 #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}
예제 #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--------"
예제 #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)
예제 #8
0
	def test_popitem(self):
		test = types.CaseInsensitiveDict(TEST)
		assert test.popitem() == ("Test", "TEST")
		assert test == {"hi": "hello"}
예제 #9
0
	def test_delitem(self):
		test = types.CaseInsensitiveDict(TEST)
		del test["hI"]
		assert test == {"test": "TEST"}
예제 #10
0
	def test_clear(self):
		test = types.CaseInsensitiveDict(TEST)
		test.clear()
		assert test == {}
예제 #11
0
	def test_keys(self):
		test = types.CaseInsensitiveDict(TEST)
		assert list(test.keys()) == ["Hi", "Test"]
예제 #12
0
	def test_init_empty(self):
		test = types.CaseInsensitiveDict()
		assert test == {}
예제 #13
0
	def test_update_empty(self):
		test = types.CaseInsensitiveDict(TEST)
		test.update()
		assert test == TEST
예제 #14
0
	def test_contains(self):
		test = types.CaseInsensitiveDict(TEST)
		assert "Hi" in test
		assert "tEsT" in test
		assert "hello" not in test
예제 #15
0
	def test_iter(self):
		test = types.CaseInsensitiveDict(TEST)
		for i, item in enumerate(test):
			assert item == ["Hi", "Test"][i]
예제 #16
0
	def test_len(self):
		test = types.CaseInsensitiveDict(TEST)
		assert len(test) == 2
예제 #17
0
	def test_values(self):
		test = types.CaseInsensitiveDict(TEST)
		assert list(test.values()) == ["hello", "TEST"]
예제 #18
0
	def test_standard_dict(self):
		test = types.CaseInsensitiveDict(TEST)
		assert test.standard_dict() == TEST
예제 #19
0
	def test_init_dict(self):
		test = types.CaseInsensitiveDict(TEST, HI = "hey")
		assert test == {"hI": "hey", "test": "TEST"}
예제 #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"}
예제 #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"}
예제 #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
예제 #23
0
	def test_bool(self):
		test = types.CaseInsensitiveDict()
		assert not test
	
		test = types.CaseInsensitiveDict(TEST)
		assert test
예제 #24
0
	def test_init_items(self):
		test = types.CaseInsensitiveDict([("Hi", "hello"), ("Test", "TEST")], HI = "hey")
		assert test == {"hI": "hey", "test": "TEST"}
예제 #25
0
	def test_items(self):
		test = types.CaseInsensitiveDict(TEST)
		assert list(test.items()) == [("Hi", "hello"), ("Test", "TEST")]