forked from binaryage/firelogger.py
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
47 lines (32 loc) · 939 Bytes
/
utils.py
File metadata and controls
47 lines (32 loc) · 939 Bytes
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
37
38
39
40
41
42
43
44
45
46
47
# -*- mode: python; coding: utf-8 -*-
import sys
from firepython import __api_version__
import firepython._const as CONST
__all__ = [
'json_encode',
'get_version_header',
'get_auth_token',
'get_auth_header',
]
try:
import json
except ImportError:
try:
import simplejson as json
except ImportError:
from django.utils import simplejson as json
try:
from hashlib import md5
except ImportError:
from md5 import md5
class TolerantJSONEncoder(json.JSONEncoder):
def default(self, o):
return str(o)
def json_encode(data):
return json.dumps(data, cls=TolerantJSONEncoder)
def get_version_header(version=__api_version__):
return (CONST.FIRELOGGER_VERSION_HEADER, version)
def get_auth_token(password):
return md5(CONST.AUTHTOK_FORMAT % password).hexdigest()
def get_auth_header(password):
return (CONST.FIRELOGGER_AUTH_HEADER, get_auth_token(password))