Permalink
Browse files

gives the ability to pass arguments to the backend stream

  • Loading branch information...
1 parent 6e68f0d commit 49ad1ab661e26e564def37017aa4777d9559db00 @ahassany ahassany committed Jan 31, 2012
@@ -17,7 +17,7 @@
import glib
class Glib2Stream(object):
- def __init__(self, socket):
+ def __init__(self, socket, **kwargs):
self.__socket = socket
self.__close_id = None
self.__read_id = None
@@ -81,5 +81,5 @@ def __new__(cls, *args, **kwargs):
cls, *args, **kwargs)
return cls._instance
- def register_stream(self, socket):
- return Glib2Stream(socket)
+ def register_stream(self, socket, **kwargs):
+ return Glib2Stream(socket, **kwargs)
@@ -17,7 +17,7 @@
from gi.repository import GObject
class Glib3Stream(object):
- def __init__(self, socket):
+ def __init__(self, socket, **kwargs):
self.__socket = socket
self.__close_id = None
self.__read_id = None
@@ -81,5 +81,5 @@ def __new__(cls, *args, **kwargs):
cls, *args, **kwargs)
return cls._instance
- def register_stream(self, socket):
- return Glib3Stream(socket)
+ def register_stream(self, socket, **kwargs):
+ return Glib3Stream(socket, **kwargs)
@@ -17,8 +17,16 @@
import tornado.iostream
class TornadoStream(object):
- def __init__(self, socket):
- self.__stream = tornado.iostream.IOStream(socket)
+ def __init__(self, socket, **kwargs):
+ """
+ :Parameters:
+ - `socket`: TCP socket
+ - `**kwargs`: passed to `tornado.iostream.IOStream`
+ - `io_loop` (optional): Tornado IOLoop instance.
+ - `max_buffer_size` (optional):
+ - `read_chunk_size` (optional):
+ """
+ self.__stream = tornado.iostream.IOStream(socket, **kwargs)
def write(self, data):
self.__stream.write(data)
@@ -41,6 +49,13 @@ def __new__(cls, *args, **kwargs):
cls, *args, **kwargs)
return cls._instance
- def register_stream(self, socket):
- return TornadoStream(socket)
-
+ def register_stream(self, socket, **kwargs):
+ """
+ :Parameters:
+ - `socket`: TCP socket
+ - `**kwargs`: passed to `tornado.iostream.IOStream`
+ - `io_loop` (optional): Tornado IOLoop instance.
+ - `max_buffer_size` (optional):
+ - `read_chunk_size` (optional):
+ """
+ return TornadoStream(socket, **kwargs)
@@ -40,15 +40,17 @@ class Connection(object):
- `dbuser`: db user to connect with
- `dbpass`: db password
- `autoreconnect` (optional): auto reconnect on interface errors
+ - `**kwargs`: passed to `backends.AsyncBackend.register_stream`
"""
def __init__(self, host, port, dbuser=None, dbpass=None, autoreconnect=True, pool=None,
- backend="tornado"):
+ backend="tornado", **kwargs):
assert isinstance(host, (str, unicode))
assert isinstance(port, int)
assert isinstance(autoreconnect, bool)
assert isinstance(dbuser, (str, unicode, None.__class__))
assert isinstance(dbpass, (str, unicode, None.__class__))
+ assert isinstance(kwargs, (dict, None.__class__))
assert pool
self.__host = host
self.__port = port
@@ -62,6 +64,7 @@ def __init__(self, host, port, dbuser=None, dbpass=None, autoreconnect=True, poo
self.__pool = pool
self.__deferred_message = None
self.__deferred_callback = None
+ self.__kwargs = kwargs
self.__backend = self.__load_backend(backend)
self.usage_count = 0
self.__connect()
@@ -76,7 +79,7 @@ def __connect(self):
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
s.connect((self.__host, self.__port))
- self.__stream = self.__backend.register_stream(s)
+ self.__stream = self.__backend.register_stream(s, **self.__kwargs)
self.__stream.set_close_callback(self._socket_close)
self.__alive = True
except socket.error, error:
@@ -238,5 +241,3 @@ def _get_nonce(self, callback):
SON({'getnonce' : 1}),
SON({})
))
-
-

0 comments on commit 49ad1ab

Please sign in to comment.