#NEWLINE# def _process_content( content , encoding ) : #NEWLINE# #INDENT# 'Decode the content taking into consideration the encoding.' #NEWLINE# result = content #NEWLINE# if ( six . PY3 and ( not isinstance ( result , six . binary_type ) ) ) : #NEWLINE# #INDENT# result = result . encode ( ) #NEWLINE# #UNINDENT# steps = _decode_steps ( encoding ) #NEWLINE# if ( not steps ) : #NEWLINE# #INDENT# LOG . error ( 'Unknown encoding, doing nothing.' ) #NEWLINE# return result #NEWLINE# #UNINDENT# for mime_type in _decode_steps ( encoding ) : #NEWLINE# #INDENT# if ( mime_type == GZIP_MIME ) : #NEWLINE# #INDENT# bufferio = io . BytesIO ( result ) #NEWLINE# with gzip . GzipFile ( fileobj = bufferio , mode = 'rb' ) as file_handle : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# result = file_handle . read ( ) #NEWLINE# #UNINDENT# except ( IOError , ValueError ) : #NEWLINE# #INDENT# LOG . exception ( 'Fail to decompress gzip content.' ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( mime_type == BASE64_MIME ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# result = base64 . b64decode ( result ) #NEWLINE# #UNINDENT# except ( ValueError , TypeError ) : #NEWLINE# #INDENT# LOG . exception ( 'Fail to decode base64 content.' ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# return result