-
Notifications
You must be signed in to change notification settings - Fork 8
/
utilities.py
47 lines (38 loc) · 984 Bytes
/
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
"""Utility variables and functions for the TS3 API"""
# FROM OLD API
# Don't change the order in this map, otherwise it might break!
_ESCAPE_MAP = [
("\\", r"\\"),
("/", r"\/"),
(" ", r"\s"),
("|", r"\p"),
("\a", r"\a"),
("\b", r"\b"),
("\f", r"\f"),
("\n", r"\n"),
("\r", r"\r"),
("\t", r"\t"),
("\v", r"\v"),
]
def escape(raw):
"""
Escapes characters that need escaping according to _ESCAPE_MAP
"""
for char, replacement in _ESCAPE_MAP:
raw = raw.replace(char, replacement)
return raw
def unescape(raw):
"""
Undo escaping of characters according to _ESCAPE_MAP
"""
for replacement, char in reversed(_ESCAPE_MAP):
raw = raw.replace(char, replacement)
return raw
class TS3Exception(Exception):
"""
Basic Exception for all Teamspeak3 Exceptions.
"""
class TS3ConnectionClosedException(Exception):
"""
Exception that signalizes a closed connection.
"""