79def _default_key_normalizer(key_class, request_context):
80 """
81 Create a pool key out of a request context dictionary.
82
83 According to RFC 3986, both the scheme and host are case-insensitive.
84 Therefore, this function normalizes both before constructing the pool
85 key for an HTTPS request. If you wish to change this behaviour, provide
86 alternate callables to ``key_fn_by_scheme``.
87
88 :param key_class:
89 The class to use when constructing the key. This should be a namedtuple
90 with the ``scheme`` and ``host`` keys at a minimum.
91 :type key_class: namedtuple
92 :param request_context:
93 A dictionary-like object that contain the context for a request.
94 :type request_context: dict
95
96 :return: A namedtuple that can be used as a connection pool key.
97 :rtype: PoolKey
98 """
99
101 context[
"scheme"] = context[
"scheme"].
lower()
102 context[
"host"] = context[
"host"].
lower()
103
104
105 for key in ("headers", "_proxy_headers", "_socks_options"):
106 if key in context and context[key] is not None:
107 context[key] =
frozenset(context[key].items())
108
109
110
112 if socket_opts is not None:
113 context["socket_options"] = tuple(socket_opts)
114
115
116
119
120
122 if field not in context:
123 context[field] = None
124
126
127
128
129
130
131