From aeabd47a79b50a74c57f1cb9e8c5b361408ea483 Mon Sep 17 00:00:00 2001 From: evilkost Date: Fri, 15 Apr 2011 16:00:27 +0400 Subject: [PATCH] cleanup --- brukva/client.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/brukva/client.py b/brukva/client.py index dd73e99..c494702 100644 --- a/brukva/client.py +++ b/brukva/client.py @@ -45,6 +45,17 @@ def enable(self): self.is_active = True def forward_error(callbacks): + """ + Syntax sugar. + If some error occurred inside with block, + it will be suppressed and forwarded to callbacks. + + Error handling can be disabled using context.disable(), + and re enabled again using context.enable(). + + @type callbacks: callable or iterator over callables + @rtype: context + """ return ForwardErrorManager(callbacks) class Message(object): @@ -134,7 +145,7 @@ def write(self, data, try_left=None): try: #print('try to write: %s'% data) self._stream.write(data) - except IOError, e: + except IOError: self.disconnect() self.write(data, try_left - 1) else: @@ -322,7 +333,6 @@ def on_connect(self): self.select(self.selected_db) def on_disconnect(self, callbacks): - self.pipeline().discard() raise ConnectionError("Socket closed on remote end") #### @@ -363,7 +373,7 @@ def call_callbacks(self, callbacks, *args, **kwargs): @process def execute_command(self, cmd, callbacks, *args, **kwargs): result = None - with forward_error(callbacks) as forward: + with forward_error(callbacks): if callbacks is None: callbacks = [] elif not hasattr(callbacks, '__iter__'):