Separated out proxy_manager_for to fix #2048

Basically identical to @sigmavirus24's suggested code - thanks for that pointer. Just added docstring.

There aren't tests for particular Adapter implementations, and I've not added any at this stage.
I have tested it with the following (which achieves what I want):

```
class SourceAddressAdapter(requests.adapters.HTTPAdapter):
    """
    A Requests HTTP adapter to add source address specification for proxies
    """
    def __init__(self, *o, **k):
        self.source_address = k.pop('source_address', None)
        super(SourceAddressAdapter, self).__init__(*o, **k)

    def proxy_manager_for(self, proxy):
        conn_params = {}
        if self.source_address is not None:
            conn_params['source_address'] = (self.source_address, 0)

        if not proxy in self.proxy_manager:
            proxy_headers = self.proxy_headers(proxy)
            self.proxy_manager[proxy] = requests.adapters.proxy_from_url(
                proxy,
                proxy_headers=proxy_headers,
                num_pools=self._pool_connections,
                maxsize=self._pool_maxsize,
                block=self._pool_block,
                **conn_params)

        return self.proxy_manager[proxy]
```


LGTM. @codedstructure you should checkout [the toolbelt](https://gitlab.com/sigmavirus24/toolbelt). We just moved the `SourceAddressAdapter` there so people can use it without having to maintain their own version.


This looks great @codedstructure, but I want to bikeshed here for a moment. I'm wondering whether the right API is actually for `proxy_manager_for` to take an arbitrary keyword argument dict that it passes to `proxy_from_url`. This saves several lines from the `SourceAddressAdapter` because it can now do:

``` python
class SourceAddressAdapter(requests.adapters.HTTPAdapter):
    """
    A Requests HTTP adapter to add source address specification for proxies
    """
    def __init__(self, *o, **k):
        self.source_address = k.pop('source_address', None)
        super(SourceAddressAdapter, self).__init__(*o, **k)

    def proxy_manager_for(self, proxy, **proxy_kwargs):
        if self.source_address is not None:
            proxy_kwargs['source_address'] = (self.source_address, 0)

        return super(SourceAddressAdapter, self).proxy_manager_for(proxy, **proxy_kwargs)
```

Thoughts?


@Lukasa that sounds like a good idea. The revised PR would look like this then?

``` python
    def proxy_manager_for(self, proxy, **proxy_kwargs):
        """Return urllib3 ProxyManager for the given proxy.

        This method should not be called from user code, and is only
        exposed for use when subclassing the
        :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.

        :param proxy: The proxy to return a urllib3 ProxyManager for.
        :param proxy_kwargs: Extra keyword arguments used to configure the Proxy Manager.
        :returns: ProxyManager
        """
        if not proxy in self.proxy_manager:
            proxy_headers = self.proxy_headers(proxy)
            self.proxy_manager[proxy] = proxy_from_url(
                                            proxy,
                                            proxy_headers=proxy_headers,
                                            num_pools=self._pool_connections,
                                            maxsize=self._pool_maxsize,
                                            block=self._pool_block,
                                            **proxy_kwargs)

        return self.proxy_manager[proxy]
```


Thanks both, I'm 100% in favour of anything which makes adapters easier to write. The PR code now looks like @sigmavirus24' code above.

Although while we're at it / (& for consistency), should `init_poolmanager` also have a similar kwargs parameter `pool_kwargs`?


Consistency is the hobgoblin of the foolish mind. That aside, I'm in favor of consistency. I just like keeping PRs narrowly focused to one topic. If you're going to make that change, _I_ would prefer it in a separate PR, but @Lukasa should feel free to disagree. 


Been presumptuous and implemented the above on the branch; makes SourceAddressAdapter potentially less dependent on changes to `init_poolmanager` and removes the requirement to import the urllib3 PoolManager.


Understand, I can revert if required.


Sorry this took me so long to get to. One small code review markup and then we can pass it to Kenneth.


Improved indentation as requested, cheers.


Looking forward to it!


@kennethreitz I think we're good to go at this stage. =)


:sparkles: :cake: :sparkles:


Sorry for the delay :)


Thanks all, appreciate the encouraging community here.