Add decorator for register_packet_listener()

This commit is contained in:
Zachy 2018-08-13 01:57:16 +01:00 committed by GitHub
parent f6f6511788
commit 6d6a592f07
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 0 deletions

View File

@ -187,6 +187,15 @@ class Connection(object):
else:
self._outgoing_packet_queue.append(packet)
def listener(self, *packet_types, **kwds):
"""
Shorthand decorator to register a function as a packet listener.
"""
def _method_func(method):
self.register_packet_listener(method, *packet_types, **kwds)
return _method_func
def register_packet_listener(self, method, *packet_types, **kwds):
"""
Registers a listener method which will be notified when a packet of