escape

This module contains classes and functions used to build valid query strings and to unescape responses.

class ts3.escape.TS3Escape[source]

Bases: object

Provides methods to escape a string properly and to build query strings.

classmethod escape(raw)[source]

Escapes the value of raw.

>>> TS3Escape.escape(None)
''
>>> TS3Escape.escape(2)
'2'
>>> TS3Escape.escape(True)
'1'
>>> TS3Escape.escape('Hello World')
'Hello\sWorld'
Parameters:raw (None, str, bool, int or RawParameter) – The value to escape.
Returns:The escaped value of raw
Return type:string
Raises:TypeError – If raw has an unsupported type.
classmethod unescape(txt)[source]

Unescapes the str txt.

>>> TS3Escape.unescape('Hello\sWorld')
'Hello World'
Parameters:txt (string) – The string to escape.
Raises:TypeError – If txt is not a string.
classmethod escape_parameters(parameters)[source]

Escapes the parameters of a TS3 query and encodes it as a part of a valid ts3 query string.

>>> # None
>>> TS3Escape.escape_parameters(None)
''        
>>> # key -> str
>>> TS3Escape.escape_parameters({'virtualserver_name': 'foo bar'})
'virtualserver_name=foo\\sbar'
>>> # key -> None
>>> TS3Escape.escape_parameters({"permsid": None})
''
>>> # Of course, you can mix them:
>>> TS3Escape.escape_parameters(
...     {'virtualserver_name': 'foo bar',
...      'permsid': None}
...     )
'virtualserver_name=foo\\sbar'
Parameters:parameters (dictionary) – The dictionary with the key value pairs.
classmethod escape_parameterlist(parameterslist)[source]

Escapes each parameter dictionary in the parameterslist and encodes the list as a part of a valid ts3 query string.

>>> TS3Escape.escape_parameterlist(None)
''
>>> TS3Escape.escape_parameterlist(
...     [{"permid": 17276, "permvalue": 50, "permskip": 1},
...      {"permid": 21415, "permvalue": 20, "permskip": 0}]
...     )
'permid=17276 permvalue=50 permskip=1|permid=21415 permvalue=20 permskip=0'

Note, that the order of the parameters might change, when you use the built-in dictionary, that does not care about the order.

Parameters:parameterslist (None or a list of dictionaries) – A list of parameters.
classmethod escape_properties(properties)[source]

Escapes each property and encodes the list as a part of a valid ts3 query string.

>>> TS3Escape.escape_properties(None)
''
>>> TS3Escape.escape_properties(
...     ["client_channel_group_id","client_servergroups"]
...     )
'client_channel_group_id client_servergroups'

Note, that the order of the parameters might change, when you use the list, that does not care about the order.

Parameters:properties (None or a list) – A list of parameters.
classmethod escape_options(options)[source]

Escapes the items in the options list and prepends a ‘-‘ if necessairy. If options is None, the empty string will be returned.

>>> TS3Escape.options_to_str(None)
''
>>> TS3Escape.options_to_str([None, 'permsid', '-virtual'])
'-permsid -virtual'
Parameters:options (None or a list of strings.) – A list with the options.