Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
evilkost committed Apr 15, 2011
1 parent eb5a055 commit aeabd47
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions brukva/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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")
####

Expand Down Expand Up @@ -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__'):
Expand Down

0 comments on commit aeabd47

Please sign in to comment.