Skip to content

Conversation

@jmoldow
Copy link
Contributor

@jmoldow jmoldow commented Sep 22, 2016

Move response logging to a new LoggingNetworkResponse class.
This allows us to decide whether to log the response body, based
on whether the caller reads or streams the content. This fixes a
bug introduced by Pull Request #166, where the LoggingNetwork
would always omit logging the response body.

Add a network_response_constructor property to
DefaultNetwork, to make it easier for subclasses to return
their own NetworkResponse subclasses. Use this in
LoggingNetwork, to return LoggingNetworkResponse instances.
Also add it as an optional property on the Network interface
class.

In network_interface.py, switch some usages of
@abc.abstractmethod to @abc.abstractproperty. This doesn't
matter on recent versions of Python 3, but there is a difference
between the two on Python 2, plus it makes the interface
clearer. This is a backwards-compatible change, because the SDK
uses these as properties, so any custom implementations would've
needed to implement these with property anyway.

Update the logging format strings in LoggingNetwork, to make
them more informative and also easier to override (by using
keyword format placeholders instead of positional ones). This is
a breaking change for clients that were overriding these class
attributes.

Add logging for request exceptions in LoggingNetwork.

Use the LoggingNetwork during functional tests.

Switch some stateful mock fixtures from session scope to
function scope.

Move response logging to a new `LoggingNetworkResponse` class.
This allows us to decide whether to log the response body, based
on whether the caller reads or streams the content. This fixes a
bug introduced by Pull Request #166, where the `LoggingNetwork`
would always omit logging the response body.

Add a `network_response_constructor` property to
`DefaultNetwork`, to make it easier for subclasses to return
their own `NetworkResponse` subclasses. Use this in
`LoggingNetwork`, to return `LoggingNetworkResponse` instances.
Also add it as an optional property on the `Network` interface
class.

In `network_interface.py`, switch some usages of
`@abc.abstractmethod` to `@abc.abstractproperty`. This doesn't
matter on recent versions of Python 3, but there is a difference
between the two on Python 2, plus it makes the interface
clearer. This is a backwards-compatible change, because the SDK
uses these as properties, so any custom implementations would've
needed to implement these with `property` anyway.

Update the logging format strings in `LoggingNetwork`, to make
them more informative and also easier to override (by using
keyword format placeholders instead of positional ones). This is
a breaking change for clients that were overriding these class
attributes.

Add logging for request exceptions in `LoggingNetwork`.

Use the `LoggingNetwork` during functional tests.

Switch some stateful mock fixtures from session scope to
function scope.
@jmoldow jmoldow added this to the v2.0.0 Major version bump milestone Sep 22, 2016
@boxcla
Copy link

boxcla commented Sep 22, 2016

Verified that @jmoldow has signed the CLA. Thanks for the pull request!

:param exc_info: The exception info returned from `sys.exc_info()`.
"""
if response.ok:
if response.request_response.raw is not None:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

response.request_response.raw is always set (both for stream=True and stream=False, so this code path was always being followed. cc @Jeff-Meadows

@Jeff-Meadows
Copy link
Contributor

👍

@jmoldow jmoldow merged commit cc49214 into master Nov 9, 2016
@jmoldow jmoldow deleted the logging branch November 9, 2016 23:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants