Skip to content

Commit

Permalink
allow to work in 2.7
Browse files Browse the repository at this point in the history
  • Loading branch information
iscai-msft committed Oct 26, 2021
1 parent b518af8 commit b208403
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions sdk/core/azure-core/azure/core/pipeline/policies/_universal.py
Original file line number Diff line number Diff line change
Expand Up @@ -618,11 +618,18 @@ def deserialize_from_http_generics(
mime_type = "application/json"

# Rely on transport implementation to give me "text()" decoded correctly
if hasattr(response, "read") and not inspect.iscoroutinefunction(response.read):
# since users can call deserialize_from_http_generics by themselves
# we want to make sure our new responses are read before we try to
# deserialize. Only read sync responses since we're in a sync function
response.read()
if hasattr(response, "read"):
try:
# since users can call deserialize_from_http_generics by themselves
# we want to make sure our new responses are read before we try to
# deserialize. Only read sync responses since we're in a sync function
if not inspect.iscoroutinefunction(response.read):
response.read()
except AttributeError:
# raises an AttributeError in 2.7 bc inspect.iscoroutinefunction was added in 3.5
# Entering here means it's 2.7 and that the response has a read method, so we read
# bc it will be sync.
response.read()
return cls.deserialize_from_text(response.text(encoding), mime_type, response=response)

def on_request(self, request):
Expand Down

0 comments on commit b208403

Please sign in to comment.