Skip to content

Commit

Permalink
Modified version of
Browse files Browse the repository at this point in the history
#47
from Justin Bradfield.

1. Use urlopen() as a context manager
2. Immediately read() response
3. Set object 'pan_body' attribute to read() result
  • Loading branch information
kevinsteves committed Jan 13, 2023
1 parent 6e5ee53 commit 01f183f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ Patches and Suggestions
- Darlene Wong
- Michael Richardson
- Garfield Freeman
- Justin Bradfield
6 changes: 4 additions & 2 deletions lib/pan/xapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def __get_header(self, response, name):
return types

def __set_response(self, response):
message_body = response.read()
message_body = response.pan_body

content_type = self.__get_header(response, 'content-type')
if not content_type:
Expand Down Expand Up @@ -515,7 +515,8 @@ def __api_request(self, query):
kwargs['timeout'] = self.timeout

try:
response = urlopen(**kwargs)
with urlopen(**kwargs) as response:
response.pan_body = response.read()

# XXX handle httplib.BadStatusLine when http to port 443
except ssl.CertificateError as e:
Expand All @@ -534,6 +535,7 @@ def __api_request(self, query):

self._log(DEBUG2, 'HTTP response headers:')
self._log(DEBUG2, '%s', response.info())
self._log(DEBUG2, 'stream closed %s', response.closed)

return response

Expand Down

0 comments on commit 01f183f

Please sign in to comment.