forked from adharmad/profanity-filter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utilities.py
58 lines (43 loc) · 1.26 KB
/
utilities.py
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
54
55
56
57
# utilities
import string, json, os
def rot13(chars):
"Simple rot-13 encoder"
lalpha = 'abcdefghijklmnopqrstuvwxyz'
ualpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ret = []
for c in chars:
if c in lalpha:
ret.append(lalpha[(lalpha.find(c) + 13) % 26])
elif c in ualpha:
ret.append(ualpha[(ualpha.find(c) + 13) % 26])
else:
ret.append(c)
return "".join(ret)
def readPropertiesFile(fileName, valtype):
"""
Reads a properties file which has name - value properties in the
following format:
name1 : value1
name2 : value2
...
valtype can be 'list' or 'int', in which case the values will be
interpreted accordingly
Returns a dict
"""
props = {}
fileName = os.path.join(os.path.dirname(__file__), fileName)
f = open(fileName, 'r')
for line in f.readlines():
if line.startswith('#'):
pass
(val1, val2) = line.split(' : ')
if valtype == 'int':
props[val1] = int(val2)
elif valtype == 'list':
props[val1] = val2.split(',')
f.close()
return props
def prettyPrintDict(d):
"Pretty print a dict"
for k in d.keys():
print(k, " ==> ", d[k])