mirror of
https://github.com/nikdoof/python-ts3.git
synced 2025-12-17 11:59:27 +00:00
Fix output parsing to provide all row details instead of just the last
This commit is contained in:
61
ts3.py
61
ts3.py
@@ -60,19 +60,19 @@ class TS3Proto():
|
|||||||
cmd = self.construct_command(command, keys=keys, opts=opts)
|
cmd = self.construct_command(command, keys=keys, opts=opts)
|
||||||
self.send('%s\n' % cmd)
|
self.send('%s\n' % cmd)
|
||||||
|
|
||||||
ret = []
|
data = []
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
resp = self._sockfile.readline()
|
resp = self._sockfile.readline()
|
||||||
resp = self.parse_command(resp)
|
resp = self.parse_command(resp)
|
||||||
if not 'command' in resp:
|
if not 'command' in resp:
|
||||||
ret.append(resp['keys'])
|
data.extend(resp)
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
|
|
||||||
if resp['command'] == 'error':
|
if resp['command'] == 'error':
|
||||||
if ret and resp['keys']['id'] == '0':
|
if data and resp['keys']['id'] == '0':
|
||||||
return ret
|
return data
|
||||||
else:
|
else:
|
||||||
return resp['keys']['id']
|
return resp['keys']['id']
|
||||||
|
|
||||||
@@ -119,45 +119,34 @@ class TS3Proto():
|
|||||||
@type commandstr: string
|
@type commandstr: string
|
||||||
"""
|
"""
|
||||||
|
|
||||||
cmdlist = commandstr.strip().split(' ')
|
if len(commandstr.split('|')) > 1:
|
||||||
|
vals = []
|
||||||
|
for cmd in commandstr.split('|'):
|
||||||
|
vals.append(self.parse_command(cmd))
|
||||||
|
return vals
|
||||||
|
|
||||||
command = cmdlist[0]
|
cmdlist = commandstr.strip().split(' ')
|
||||||
|
command = None
|
||||||
keys = {}
|
keys = {}
|
||||||
opts = []
|
opts = []
|
||||||
|
|
||||||
start = 1
|
for key in cmdlist:
|
||||||
len(command.split('='))
|
v = key.strip().split('=')
|
||||||
if len(command.split('=')) > 1:
|
if len(v) > 1:
|
||||||
start = 0
|
# Key
|
||||||
command = ''
|
key, value = v
|
||||||
|
keys[key] = self._unescape_str(value)
|
||||||
|
elif v[0][0] == '-':
|
||||||
for key in cmdlist[start:]:
|
# Option
|
||||||
if len(key.split('|')) > 1:
|
opts.append(v[0][1:])
|
||||||
output = []
|
else:
|
||||||
# Nested Keys
|
command = v[0]
|
||||||
nkeys = key.split('|')
|
|
||||||
for nkey in nkeys:
|
|
||||||
nvalue = nkey.split('=')
|
|
||||||
okey = nvalue[0]
|
|
||||||
output.append(nvalue[1])
|
|
||||||
keys[okey] = output
|
|
||||||
continue
|
|
||||||
if len(key.split('=')) > 1:
|
|
||||||
# Key value
|
|
||||||
nvalue = key.split('=')
|
|
||||||
keys[nvalue[0]] = self._unescape_str(nvalue[1])
|
|
||||||
continue
|
|
||||||
elif key[0] == '-':
|
|
||||||
opts.append(key[1:])
|
|
||||||
continue
|
|
||||||
|
|
||||||
d = {'keys': keys, 'opts': opts}
|
d = {'keys': keys, 'opts': opts}
|
||||||
if command:
|
if command:
|
||||||
d['command'] = command
|
d['command'] = command
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _escape_str(value):
|
def _escape_str(value):
|
||||||
"""
|
"""
|
||||||
@@ -228,12 +217,10 @@ class TS3Server(TS3Proto):
|
|||||||
@type password: str
|
@type password: str
|
||||||
"""
|
"""
|
||||||
d = p.send_command('login', keys={'client_login_name': username, 'client_login_password': password })
|
d = p.send_command('login', keys={'client_login_name': username, 'client_login_password': password })
|
||||||
if d > 0:
|
if d == 0:
|
||||||
self._log.error('Error logging in')
|
|
||||||
return False
|
|
||||||
elif d == 0:
|
|
||||||
self._log.info('Login Successful')
|
self._log.info('Login Successful')
|
||||||
return True
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
def serverlist(self):
|
def serverlist(self):
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user