forked from lnishan/SQLGitHub
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutilities.py
50 lines (45 loc) · 1.04 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
"""Utilities for general operations."""
def PrintResult(table, output):
if output == "str":
print(table)
elif output == "csv":
print(table.InCsv())
elif output == "html":
print(table.InHtml())
def IsNumeric(num_str):
try:
val = int(num_str)
except ValueError:
return False
else:
return True
def GuaranteeUnicode(obj):
if type(obj) == unicode:
return obj
elif type(obj) == str:
return unicode(obj, "utf-8")
else:
return unicode(str(obj), "utf-8")
def Unescape(ch):
if ch == "0":
return chr(0)
elif ch == "\'":
return "\'"
elif ch == "\"":
return "\""
elif ch == "b":
return "\b"
elif ch == "n":
return "\n"
elif ch == "r":
return "\r"
elif ch == "t":
return "\t"
elif ch == "Z":
return chr(26)
elif ch == "\\":
return "\\"
elif ch == "%": # keep escape: like <literal string>
return "\\%"
elif ch == "_":
return "\\_"