comparison venv/lib/python2.7/site-packages/requests_toolbelt/adapters/source.py @ 0:d67268158946 draft

planemo upload commit a3f181f5f126803c654b3a66dd4e83a48f7e203b
author bcclaywell
date Mon, 12 Oct 2015 17:43:33 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:d67268158946
1 # -*- coding: utf-8 -*-
2 """
3 requests_toolbelt.source_adapter
4 ================================
5
6 This file contains an implementation of the SourceAddressAdapter originally
7 demonstrated on the Requests GitHub page.
8 """
9 from requests.adapters import HTTPAdapter
10 from requests.packages.urllib3.poolmanager import PoolManager
11
12
13 class SourceAddressAdapter(HTTPAdapter):
14 """
15 A Source Address Adapter for Python Requests that enables you to choose the
16 local address to bind to. This allows you to send your HTTP requests from a
17 specific interface and IP address.
18
19 Example usage:
20
21 .. code-block:: python
22
23 import requests
24 from requests_toolbelt.adapters.source import SourceAddressAdapter
25
26 s = requests.Session()
27 s.mount('http://', SourceAddressAdapter('10.10.10.10'))
28 """
29 def __init__(self, source_address, **kwargs):
30 self.source_address = source_address
31
32 super(SourceAddressAdapter, self).__init__(**kwargs)
33
34 def init_poolmanager(self, connections, maxsize, block=False):
35 self.poolmanager = PoolManager(num_pools=connections,
36 maxsize=maxsize,
37 block=block,
38 source_address=self.source_address)