From d4cfcd4919e7c1927acc74b06d01e0f63429a1ad Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Thu, 14 Jun 2018 14:00:13 -0400 Subject: [PATCH] Wrap bytes in a StringIO Python httplib was making a copy of the data passed as bytes, completely foiling the memory reduction attempt. Change to StringIO to avoid bulk copies and have python httplib itreate a bit at a time. Change-Id: I923d8bac290f628ee10dd8a33e528a32f3d52a23 --- pyghmi/util/webclient.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pyghmi/util/webclient.py b/pyghmi/util/webclient.py index 81c0030f..74150dad 100644 --- a/pyghmi/util/webclient.py +++ b/pyghmi/util/webclient.py @@ -24,9 +24,11 @@ import ssl try: import Cookie import httplib + import StringIO except ImportError: import http.client as httplib import http.cookies as Cookie + import io as StringIO __author__ = 'jjohnson2' @@ -146,9 +148,11 @@ class SecureHTTPConnection(httplib.HTTPConnection, object): """ if data is None: data = open(filename, 'rb') - form = get_upload_form(filename, data, formname, otherfields) + form = StringIO.StringIO(get_upload_form(filename, data, formname, + otherfields)) ulheaders = self.stdheaders.copy() ulheaders['Content-Type'] = 'multipart/form-data; boundary=' + BND + ulheaders['Content-Length'] = len(uploadforms[filename]) webclient = self.dupe() webclient.request('POST', url, form, ulheaders) rsp = webclient.getresponse()