File size: 747 Bytes
703e6fc
 
458f0bb
703e6fc
d1c021a
458f0bb
d1c021a
 
458f0bb
703e6fc
 
 
458f0bb
703e6fc
 
458f0bb
703e6fc
 
 
 
458f0bb
703e6fc
 
 
d1c021a
458f0bb
d1c021a
 
 
458f0bb
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import json


def extract(hf_token):
    """
    Extract token, user, redirect, source, and info from input hf_token.
    If hf_token is simple, it is the token itself.
    """
    info = {}  # a copy of hf_token in json format
    try:
        info = json.loads(hf_token)
    except json.decoder.JSONDecodeError:
        return hf_token, None, None, None, None

    try:
        token = info["token"]
    except KeyError:
        token = None

    try:
        user = info["user"]
    except KeyError:
        user = None

    try:
        redirect = info["redirect"]
    except KeyError:
        redirect = None

    try:
        source = info["source"]
    except KeyError:
        source = None

    return token, user, redirect, source, info