-
Notifications
You must be signed in to change notification settings - Fork 0
/
zigutils.py
executable file
·51 lines (44 loc) · 1.32 KB
/
zigutils.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
#!/usr/bin/python
import re
import inspect
# num is a string which may or may not be in hex
def parseNumber(num) :
hexmap = { '0' : 0, '1':1,'2':2,'3':3,'4':4,'5':5,'6':6,'7':7,'8':8,'9':9,
'A':10,'B':11,'C':12,'D':13,'E':14,'F':15 }
m = re.match(r'0x[0-9A-F]',num)
if m :
# convert from hex
retval = hexmap[num[2]]
for i in num[3:] :
retval = retval*16 + hexmap[i]
return retval
# not hex, assume decimal
return int(num)
def makeString(*args) :
return ''.join([str(s) for s in args])
def nuvoEscape(s) :
retval = []
for ch in s.encode("ISO-8859-1") :
if ord(ch) >= 128 :
retval.append('_')
elif ch == '*' :
#if ch == '*' :
retval.append(r'\*')
elif ch == '"' :
retval.append(r'\"')
else :
retval.append(ch)
return ''.join(retval)
def Func(base_level=0) :
"""returns function name that called this; can pass in a count of how far up stack
to go"""
level = base_level + 1
# first check if we have an object to print out the class name
args, varargs, varkw, defaults = inspect.getargvalues(inspect.stack()[level][0])
prefix = ""
if defaults.has_key('self') :
prefix = defaults['self'].__class__.__name__ + "."
return prefix + inspect.stack()[level][3] + "()"
def FileLine() :
"returns filename and line number that called this"
return inspect.stack()[1][1] + " " + inspect.stack()[1][2]