Change "add_callback" functions to "subscribe" functions
This commit is contained in:
parent
f366a02758
commit
04f7c9c781
2 changed files with 11 additions and 11 deletions
|
|
@ -200,27 +200,27 @@ class Connection():
|
||||||
|
|
||||||
return str(self._send_id)
|
return str(self._send_id)
|
||||||
|
|
||||||
def add_callback(self, ptype, callback, *args, **kwargs):
|
def subscribe(self, ptype, callback, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
add_callback(ptype, callback, *args, **kwargs) -> None
|
subscribe(ptype, callback, *args, **kwargs) -> None
|
||||||
|
|
||||||
Add a function to be called when a packet of type ptype is received.
|
Add a function to be called when a packet of type ptype is received.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
self._callbacks.add(ptype, callback, *args, **kwargs)
|
self._callbacks.add(ptype, callback, *args, **kwargs)
|
||||||
|
|
||||||
def add_id_callback(self, pid, callback, *args, **kwargs):
|
def subscribe_to_id(self, pid, callback, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
add_id_callback(pid, callback, *args, **kwargs) -> None
|
subscribe_to_id(pid, callback, *args, **kwargs) -> None
|
||||||
|
|
||||||
Add a function to be called when a packet with id pid is received.
|
Add a function to be called when a packet with id pid is received.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
self._id_callbacks.add(pid, callback, *args, **kwargs)
|
self._id_callbacks.add(pid, callback, *args, **kwargs)
|
||||||
|
|
||||||
def add_next_callback(self, callback, *args, **kwargs):
|
def subscribe_to_next(self, callback, *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
add_next_callback(callback, *args, **kwargs) -> None
|
subscribe_to_next(callback, *args, **kwargs) -> None
|
||||||
|
|
||||||
Add a function to be called when the answer to the next message sent is received.
|
Add a function to be called when the answer to the next message sent is received.
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -31,9 +31,9 @@ class Session():
|
||||||
|
|
||||||
def __init__(self, room, password=None):
|
def __init__(self, room, password=None):
|
||||||
self._connection = Connection(room)
|
self._connection = Connection(room)
|
||||||
self._connection.add_callback("disconnect", self._on_disconnect)
|
self._connection.subscribe("disconnect", self._on_disconnect)
|
||||||
self._connection.add_callback("bounce-event", self.handle_bounce_event)
|
self._connection.subscribe("bounce-event", self.handle_bounce_event)
|
||||||
self._connection.add_callback("ping-event", self.handle_ping_event)
|
self._connection.subscribe("ping-event", self.handle_ping_event)
|
||||||
|
|
||||||
self._callbacks = Callbacks()
|
self._callbacks = Callbacks()
|
||||||
self._hello_event_completed = False
|
self._hello_event_completed = False
|
||||||
|
|
@ -60,7 +60,7 @@ class Session():
|
||||||
def name(self, new_name):
|
def name(self, new_name):
|
||||||
with self._connection as conn:
|
with self._connection as conn:
|
||||||
logger.debug("setting name to {!r}".format(new_name))
|
logger.debug("setting name to {!r}".format(new_name))
|
||||||
conn.add_next_callback(self.handle_nick_reply)
|
conn.subscribe_to_next(self.handle_nick_reply)
|
||||||
conn.send_packet("nick", name=new_name)
|
conn.send_packet("nick", name=new_name)
|
||||||
|
|
||||||
def _on_disconnect(self):
|
def _on_disconnect(self):
|
||||||
|
|
@ -74,7 +74,7 @@ class Session():
|
||||||
if data.get("reason") == "authentication required":
|
if data.get("reason") == "authentication required":
|
||||||
if self.password:
|
if self.password:
|
||||||
with self._connection as conn:
|
with self._connection as conn:
|
||||||
conn.add_next_callback(self.handle_auth_reply)
|
conn.subscribe_to_next(self.handle_auth_reply)
|
||||||
conn.send_packet("auth", type="passcode", passcode=self.password)
|
conn.send_packet("auth", type="passcode", passcode=self.password)
|
||||||
else:
|
else:
|
||||||
logger.warn("Could not access &{}: No password.".format(self._connection.room))
|
logger.warn("Could not access &{}: No password.".format(self._connection.room))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue