Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small fixup to recent agent changes #108

Merged
merged 1 commit into from Jul 30, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions docs/howto.rst
Expand Up @@ -105,13 +105,13 @@ Full example: :download:`using_cookies.py <examples/using_cookies.py>`
Agent Customization
-------------------

`treq` creates its own `twisted.web.client.Agent` with reasonable defaults, but
you may want to provide your own custom agent. A custom agent can be passed
to the various `treq` request methods using the ``agent`` keyword argument.
treq creates its own `twisted.web.client.Agent
<https://twistedmatrix.com/documents/current/api/twisted.web.client.Agent.html>`_
with reasonable defaults, but you may want to provide your own custom agent.
A custom agent can be passed to the various treq request methods using the
``agent`` keyword argument.

.. code-block:: python

custom_agent = create_custom_agent(trusted_certs, timeout)
custom_agent = Agent(reactor, connectTimeout=42)
treq.get(url, agent=custom_agent)


6 changes: 2 additions & 4 deletions treq/api.py
Expand Up @@ -106,10 +106,8 @@ def request(method, url, **kwargs):
#

def _client(*args, **kwargs):
agent = kwargs.get('agent', None)
if agent is not None:
del kwargs['agent']
else:
agent = kwargs.get('agent')
if agent is None:
reactor = default_reactor(kwargs.get('reactor'))
pool = default_pool(reactor,
kwargs.get('pool'),
Expand Down
4 changes: 3 additions & 1 deletion treq/test/test_api.py
Expand Up @@ -45,7 +45,9 @@ def test_cached_pool(self):
self.Agent.assert_called_with(mock.ANY, pool=pool)

def test_custom_agent(self):
"""
A custom Agent is used if specified.
"""
custom_agent = mock.Mock()
treq.get('https://www.example.org/', agent=custom_agent)
self.HTTPClient.assertCalledWith(custom_agent)