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
48
49
50
51
52
53
|
import json
import hashlib
from .helper import qtqml
def jsonify(symbol):
""" returns json format for symbol """
try:
# all symbols have a toJson method, try it
return json.dumps(symbol.toJson(), indent=' ')
except AttributeError:
pass
return json.dumps(symbol, indent=' ')
def upper_first(s):
""" uppercase first letter """
s = str(s)
return s[0].upper() + s[1:]
def lower_first(s):
s = str(s)
return s[0].lower() + s[1:]
def hash(symbol, hash_type='sha1'):
""" create a hash code from symbol """
code = hashlib.new(hash_type)
code.update(str(symbol).encode('utf-8'))
return code.hexdigest()
def path(symbol):
""" replaces '.' with '/' """
return str(symbol).replace('.', '/')
def identifier(s):
return str(s).lower().replace('.', '_')
filters = {
'jsonify': jsonify,
'upper_first': upper_first,
'lower_first': lower_first,
'upperfirst': upper_first,
'lowerfirst': lower_first,
'hash': hash,
'path': path,
'identifier': identifier,
}
filters.update(qtqml.Filters.get_filters())
|