def _ApplySudsJurkoSendPatch(self):
    """Appends a Monkey Patch to the suds.transport.http module.

    This allows the suds library to decompress the SOAP body when compression is
    enabled. For more details on SOAP Compression, see:
    https://developers.google.com/adwords/api/docs/guides/bestpractices?hl=en#use_compression
    """
    def GetInflateStream(msg):
      stream = io.BytesIO()
      stream.write(msg)
      stream.flush()
      stream.seek(0)
      return gzip.GzipFile(fileobj=stream, mode='rb')

    def PatchedHttpTransportSend(self, request):
      """Patch for HttpTransport.send to enable gzip compression."""
      msg = request.message
      http_transport = suds.transport.http.HttpTransport
      url = http_transport._HttpTransport__get_request_url(request)
      headers = request.headers
      u2request = urllib2.Request(url, msg, headers)
      self.addcookies(u2request)
      self.proxy = self.options.proxy
      request.headers.update(u2request.headers)
      suds.transport.http.log.debug('sending:\n%s', request)
      try:
        fp = self.u2open(u2request)
      except urllib2.HTTPError, e:
        if e.code in (202, 204):
          return None
        else:
          if e.headers.get('content-encoding') == 'gzip':
            # If gzip encoding is used, decompress here.
            # Need to read and recreate a stream because urllib result objects
            # don't fully implement the file-like API
            e.fp = GetInflateStream(e.fp.read())

          raise suds.transport.TransportError(e.msg, e.code, e.fp)

      self.getcookies(fp, u2request)
      # Note: Python 2 returns httplib.HTTPMessage, and Python 3 returns
      # http.client.HTTPMessage, which differ slightly.
      headers = (fp.headers.dict if sys.version_info < (3, 0) else fp.headers)
      result = suds.transport.Reply(200, headers, fp.read())

      if result.headers.get('content-encoding') == 'gzip':
        # If gzip encoding is used, decompress here.
        result.message = GetInflateStream(result.message).read()

      suds.transport.http.log.debug('received:\n%s', result)
      return result

    suds.transport.http.HttpTransport.send = PatchedHttpTransportSend
def _ApplySudsJurkoSendPatch ( self ) : def GetInflateStream ( msg ) : stream = io . BytesIO ( ) stream . write ( msg ) stream . flush ( ) stream . seek ( 0 ) return gzip . GzipFile ( fileobj = stream , mode = 'rb' ) def PatchedHttpTransportSend ( self , request ) : msg = request . message http_transport = suds . transport . http . HttpTransport url = http_transport . _HttpTransport__get_request_url ( request ) headers = request . headers u2request = urllib2 . Request ( url , msg , headers ) self . addcookies ( u2request ) self . proxy = self . options . proxy request . headers . update ( u2request . headers ) suds . transport . http . log . debug ( 'sending:\n%s' , request ) try : fp = self . u2open ( u2request ) except urllib2 . HTTPError , e : if e . code in ( 202 , 204 ) : return None else : if e . headers . get ( 'content-encoding' ) == 'gzip' : e . fp = GetInflateStream ( e . fp . read ( ) ) raise suds . transport . TransportError ( e . msg , e . code , e . fp ) self . getcookies ( fp , u2request ) headers = ( fp . headers . dict if sys . version_info < ( 3 , 0 ) else fp . headers ) result = suds . transport . Reply ( 200 , headers , fp . read ( ) ) if result . headers . get ( 'content-encoding' ) == 'gzip' : result . message = GetInflateStream ( result . message ) . read ( ) suds . transport . http . log . debug ( 'received:\n%s' , result ) return result suds . transport . http . HttpTransport . send = PatchedHttpTransportSend
Appends a Monkey Patch to the suds.transport.http module.

    This allows the suds library to decompress the SOAP body when compression is
    enabled. For more details on SOAP Compression, see:
    https://developers.google.com/adwords/api/docs/guides/bestpractices?hl=en#use_compression