packages.urllib3._collections

Module Contents

Classes

RLock()
RecentlyUsedContainer(self,maxsize=10,dispose_func=None) Provides a thread-safe dict-like container which maintains up to
HTTPHeaderDict(self,headers=None,**kwargs)
param headers:
class RLock
__enter__()
__exit__(exc_type, exc_value, traceback)
class RecentlyUsedContainer(maxsize=10, dispose_func=None)

Provides a thread-safe dict-like container which maintains up to maxsize keys while throwing away the least-recently-used keys beyond maxsize.

Parameters:
  • maxsize – Maximum number of recent elements to retain.
  • dispose_func – Every time an item is evicted from the container, dispose_func(value) is called. Callback which will get called
__init__(maxsize=10, dispose_func=None)
__getitem__(key)
__setitem__(key, value)
__delitem__(key)
__len__()
__iter__()
clear()
keys()
class HTTPHeaderDict(headers=None, **kwargs)
Parameters:
  • headers – An iterable of field-value pairs. Must not contain multiple field names when compared case-insensitively.
  • kwargs – Additional field-value pairs to pass in to dict.update.

A dict like container for storing HTTP Headers.

Field names are stored and compared case-insensitively in compliance with RFC 7230. Iteration provides the first case-sensitive key seen for each case-insensitive pair.

Using __setitem__ syntax overwrites fields that compare equal case-insensitively in order to maintain dict’s api. For fields that compare equal, instead create a new HTTPHeaderDict and use .add in a loop.

If multiple fields that are equal case-insensitively are passed to the constructor or .update, the behavior is undefined and some will be lost.

>>> headers = HTTPHeaderDict()
>>> headers.add('Set-Cookie', 'foo=bar')
>>> headers.add('set-cookie', 'baz=quxx')
>>> headers['content-length'] = '7'
>>> headers['SET-cookie']
'foo=bar, baz=quxx'
>>> headers['Content-Length']
'7'
__init__(headers=None, **kwargs)
__setitem__(key, val)
__getitem__(key)
__delitem__(key)
__contains__(key)
__eq__(other)
__ne__(other)
__len__()
__iter__()
pop(key, default=__marker)

D.pop(k[,d]) -> v, remove specified key and return the corresponding value. If key is not found, d is returned if given, otherwise KeyError is raised.

discard(key)
add(key, val)

Adds a (name, value) pair, doesn’t overwrite the value if it already exists.

>>> headers = HTTPHeaderDict(foo='bar')
>>> headers.add('Foo', 'baz')
>>> headers['foo']
'bar, baz'
extend(*args, **kwargs)

Generic import function for any type of header-like object. Adapted version of MutableMapping.update in order to insert items with self.add instead of self.__setitem__

getlist(key)

Returns a list of all the values for the named field. Returns an empty list if the key doesn’t exist.

__repr__()
_copy_from(other)
copy()
iteritems()

Iterate over all header lines, including duplicate ones.

itermerged()

Iterate over all headers, merging duplicate ones together.

items()
from_httplib(message)

Read headers from a Python 2 httplib message object.