refactoring
This commit is contained in:
parent
f8672bdd6d
commit
97a357ae00
@ -58,7 +58,7 @@ class SyncClientProtocol(CommandProtocol):
|
|||||||
def handle_connected_state(self, args):
|
def handle_connected_state(self, args):
|
||||||
args = self.__parseState(args)
|
args = self.__parseState(args)
|
||||||
if not args:
|
if not args:
|
||||||
self.drop_with_error('Malformed state attributes')
|
self.dropWithError('Malformed state attributes')
|
||||||
return
|
return
|
||||||
|
|
||||||
counter, ctime, paused, position, name = args
|
counter, ctime, paused, position, name = args
|
||||||
@ -72,7 +72,7 @@ class SyncClientProtocol(CommandProtocol):
|
|||||||
ctime = int(ctime)
|
ctime = int(ctime)
|
||||||
position = int(position)
|
position = int(position)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
self.drop_with_error('Invalid arguments')
|
self.dropWithError('Invalid arguments')
|
||||||
|
|
||||||
ctime /= 1000.0
|
ctime /= 1000.0
|
||||||
position /= 1000.0
|
position /= 1000.0
|
||||||
|
|||||||
@ -42,7 +42,7 @@ class CommandProtocol(LineReceiver):
|
|||||||
|
|
||||||
args = ArgumentParser.splitArguments(line)
|
args = ArgumentParser.splitArguments(line)
|
||||||
if not args:
|
if not args:
|
||||||
self.drop_with_error('Malformed line')
|
self.dropWithError('Malformed line')
|
||||||
return
|
return
|
||||||
command = args.pop(0)
|
command = args.pop(0)
|
||||||
#if command not in ['ping', 'pong']:
|
#if command not in ['ping', 'pong']:
|
||||||
@ -56,7 +56,7 @@ class CommandProtocol(LineReceiver):
|
|||||||
if handler:
|
if handler:
|
||||||
handler = getattr(self, handler, None)
|
handler = getattr(self, handler, None)
|
||||||
if not handler:
|
if not handler:
|
||||||
self.drop_with_error('Unknown command: `%s`' % command)
|
self.dropWithError('Unknown command: `%s`' % command)
|
||||||
return # TODO log it too
|
return # TODO log it too
|
||||||
handler(args)
|
handler(args)
|
||||||
|
|
||||||
@ -77,7 +77,7 @@ class CommandProtocol(LineReceiver):
|
|||||||
def drop(self):
|
def drop(self):
|
||||||
self.transport.loseConnection()
|
self.transport.loseConnection()
|
||||||
|
|
||||||
def drop_with_error(self, error):
|
def dropWithError(self, error):
|
||||||
self.send_message('error', error)
|
self.send_message('error', error)
|
||||||
self.drop()
|
self.drop()
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user