Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
plentymarkets.py28 linesDownload Raw Back to compliance_fixes
1from json import dumps, loads2import re3 4 5def plentymarkets_compliance_fix(session):6    def _to_snake_case(n):7        return re.sub("(.)([A-Z][a-z]+)", r"\1_\2", n).lower()8 9    def _compliance_fix(r):10        # Plenty returns the Token in CamelCase instead of _11        if (12            "application/json" in r.headers.get("content-type", {})13            and r.status_code == 20014        ):15            token = loads(r.text)16        else:17            return r18 19        fixed_token = {}20        for k, v in token.items():21            fixed_token[_to_snake_case(k)] = v22 23        r._content = dumps(fixed_token).encode()24        return r25 26    session.register_compliance_hook("access_token_response", _compliance_fix)27    return session28 
codekingpro/portable-devtools · Team Ai