Statistics
| Revision:

gvsig-scripting / org.gvsig.scripting / trunk / org.gvsig.scripting / org.gvsig.scripting.app / org.gvsig.scripting.app.mainplugin / src / main / resources-plugin / scripting / lib / requests_oauthlib / compliance_fixes / mailchimp.py @ 564

History | View | Annotate | Download (756 Bytes)

1
import json
2

    
3
from oauthlib.common import to_unicode
4

    
5
def mailchimp_compliance_fix(session):
6
    def _null_scope(r):
7
        token = json.loads(r.text)
8
        if 'scope' in token and token['scope'] is None:
9
            token.pop('scope')
10
        r._content = to_unicode(json.dumps(token)).encode('utf-8')
11
        return r
12

    
13
    def _non_zero_expiration(r):
14
        token = json.loads(r.text)
15
        if 'expires_in' in token and token['expires_in'] == 0:
16
            token['expires_in'] = 3600
17
        r._content = to_unicode(json.dumps(token)).encode('utf-8')
18
        return r
19

    
20
    session.register_compliance_hook('access_token_response', _null_scope)
21
    session.register_compliance_hook('access_token_response', _non_zero_expiration)
22
    return session