How to use the requests3.structures.CaseInsensitiveDict function in requests3

To help you get started, we’ve selected a few requests3 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github psf / requests / tests / test_requests.py View on Github external
            CaseInsensitiveDict(FOO='foo', BAr='bar'),
        ),
    )
    def test_init(self, cid):
        assert len(cid) == 2
        assert 'foo' in cid
        assert 'bar' in cid
github psf / requests / tests / test_requests.py View on Github external
def test_update_retains_unchanged(self):
        cid = CaseInsensitiveDict({'foo': 'foo', 'bar': 'bar'})
        cid.update({'foo': 'newfoo'})
        assert cid['bar'] == 'bar'
github psf / requests / tests / test_requests.py View on Github external
def test_preserve_key_case(self):
        cid = CaseInsensitiveDict(
            {'Accept': 'application/json', 'user-Agent': 'requests'}
        )
        keyset = frozenset(['Accept', 'user-Agent'])
        assert frozenset(i[0] for i in cid.items()) == keyset
        assert frozenset(cid.keys()) == keyset
        assert frozenset(cid) == keyset
github psf / requests / tests / test_requests.py View on Github external
def test_setdefault(self):
        cid = CaseInsensitiveDict({'Spam': 'blueval'})
        assert cid.setdefault('spam', 'notblueval') == 'blueval'
        assert cid.setdefault('notspam', 'notblueval') == 'notblueval'
github psf / requests / tests / test_requests.py View on Github external
def test_update(self):
        cid = CaseInsensitiveDict()
        cid['spam'] = 'blueval'
        cid.update({'sPam': 'notblueval'})
        assert cid['spam'] == 'notblueval'
        cid = CaseInsensitiveDict({'Foo': 'foo', 'BAr': 'bar'})
        cid.update({'fOO': 'anotherfoo', 'bAR': 'anotherbar'})
        assert len(cid) == 2
        assert cid['foo'] == 'anotherfoo'
        assert cid['bar'] == 'anotherbar'
github psf / requests / tests / test_requests.py View on Github external
def test_fixes_649(self):
        """__setitem__ should behave case-insensitively."""
        cid = CaseInsensitiveDict()
        cid['spam'] = 'oneval'
        cid['Spam'] = 'twoval'
        cid['sPAM'] = 'redval'
        cid['SPAM'] = 'blueval'
        assert cid['spam'] == 'blueval'
        assert cid['SPAM'] == 'blueval'
        assert list(cid.keys()) == ['SPAM']
github psf / requests / tests / test_requests.py View on Github external
def test_contains(self):
        cid = CaseInsensitiveDict()
        cid['Spam'] = 'someval'
        assert 'Spam' in cid
        assert 'spam' in cid
        assert 'SPAM' in cid
        assert 'sPam' in cid
        assert 'notspam' not in cid
github psf / requests / tests / test_requests.py View on Github external
def test_preserve_last_key_case(self):
        cid = CaseInsensitiveDict(
            {'Accept': 'application/json', 'user-Agent': 'requests'}
        )
        cid.update({'ACCEPT': 'application/json'})
        cid['USER-AGENT'] = 'requests'
        keyset = frozenset(['ACCEPT', 'USER-AGENT'])
        assert frozenset(i[0] for i in cid.items()) == keyset
        assert frozenset(cid.keys()) == keyset
        assert frozenset(cid) == keyset
github psf / requests / requests3 / models.py View on Github external
def __init__(self):
        self._content = False
        self._content_consumed = False
        self._next = None
        # : Integer Code of responded HTTP Status, e.g. 404 or 200.
        self.status_code = None
        # : Case-insensitive Dictionary of Response Headers.
        #: For example, ``headers['content-encoding']`` will return the
        #: value of a ``'Content-Encoding'`` response header.
        self.headers = CaseInsensitiveDict()
        # : File-like object representation of response (for advanced usage).
        #: Use of ``raw`` requires that ``stream=True`` be set on the request.
        # This requirement does not apply for use internally to Requests.
        self.raw = None
        # : Final URL location of Response.
        self.url = None
        # : Encoding to decode with when accessing r.text or
        #: r.iter_content(decode_unicode=True)
        self.encoding = None
        # : A list of :class:`Response ` objects from
        #: the history of the Request. Any redirect responses will end
        #: up here. The list is sorted from the oldest to the most recent request.
        self.history = []
        # : Textual reason of responded HTTP Status, e.g. "Not Found" or "OK".
        self.reason = None
        # : A CookieJar of Cookies the server sent back.
github psf / requests / requests3 / models.py View on Github external
def prepare_headers(self, headers):
        """Prepares the given HTTP headers."""
        self.headers = CaseInsensitiveDict()
        if headers:
            for header in headers.items():
                # Raise exception on invalid header value.
                check_header_validity(header)
                name, value = header
                self.headers[to_native_string(name)] = value