Skip to content

Commit 01f183f

Browse files
committed
Modified version of
#47 from Justin Bradfield. 1. Use urlopen() as a context manager 2. Immediately read() response 3. Set object 'pan_body' attribute to read() result
1 parent 6e5ee53 commit 01f183f

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

AUTHORS.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ Patches and Suggestions
1010
- Darlene Wong
1111
- Michael Richardson
1212
- Garfield Freeman
13+
- Justin Bradfield

lib/pan/xapi.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ def __get_header(self, response, name):
201201
return types
202202

203203
def __set_response(self, response):
204-
message_body = response.read()
204+
message_body = response.pan_body
205205

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

517517
try:
518-
response = urlopen(**kwargs)
518+
with urlopen(**kwargs) as response:
519+
response.pan_body = response.read()
519520

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

535536
self._log(DEBUG2, 'HTTP response headers:')
536537
self._log(DEBUG2, '%s', response.info())
538+
self._log(DEBUG2, 'stream closed %s', response.closed)
537539

538540
return response
539541

0 commit comments

Comments
 (0)