MCPcopy
hub / github.com/USArmyResearchLab/Dshell / decompress_gzip_content

Method decompress_gzip_content

dshell/plugins/httpplugin.py:180–198  ·  view source on GitHub ↗

If this response has Content-Encoding set to something with "gzip", this function will decompress it and store it in the body.

(self)

Source from the content-addressed store, hash-verified

178 self.body = parse_body(self, data, self.headers)
179
180 def decompress_gzip_content(self):
181 """
182 If this response has Content-Encoding set to something with "gzip",
183 this function will decompress it and store it in the body.
184 """
185 if "gzip" in self.headers.get("content-encoding", ""):
186 try:
187 iobody = io.BytesIO(self.body)
188 except TypeError as e:
189 # TODO: Why would body ever not be bytes? If it's not bytes, then that means
190 # we have a bug somewhere in the code and therefore should just allow the
191 # original exception to be raised.
192 self.errors.append(dshell.core.DataError("Body was not a byte string ({!s}). Could not decompress.".format(type(self.body))))
193 return
194 try:
195 self.body = gzip.GzipFile(fileobj=iobody).read()
196 except OSError as e:
197 self.errors.append(OSError("Could not gunzip body. {!s}".format(e)))
198 return
199
200
201class HTTPPlugin(dshell.core.ConnectionPlugin):

Callers 1

connection_handlerMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected