def createReturnValue(data, parse): statusAndHeaders, body = _parseData(data) contentType = statusAndHeaders['Headers'].get('Content-Type') if parse: if not contentType is None: if 'html' in contentType: body = HTML(body, HTMLParser(recover=True)) elif 'xml' in contentType: body = XML(body) elif 'json' in contentType: try: body = loads(body.decode()) except JSONDecodeError: body = 'JSONDecodeError in: ' + body.decode() elif body.strip() != b'': try: body = XML(body) except: try: body = HTML(body, HTMLParser(recover=True)) except: print("Exception parsing:") print(body) raise return statusAndHeaders, body