summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWouter Bolsterlee <uws@xs4all.nl>2013-05-03 23:17:12 +0200
committerWouter Bolsterlee <uws@xs4all.nl>2013-05-03 23:17:12 +0200
commitd4078a44cb3ba1b5af13d6bfd6d830d79e74754a (patch)
tree974b0c7ed14b20f2973fb2175baed3bb71e7e462
parent9b21ff2e2c54a3fb43547d6d569fd41d8f1adeaa (diff)
downloadhappybase-d4078a44cb3ba1b5af13d6bfd6d830d79e74754a.tar.gz
Move Thrift object creation to helper method
-rw-r--r--happybase/connection.py20
1 files changed, 12 insertions, 8 deletions
diff --git a/happybase/connection.py b/happybase/connection.py
index 6bd045a..abc2f72 100644
--- a/happybase/connection.py
+++ b/happybase/connection.py
@@ -101,20 +101,24 @@ class Connection(object):
self.table_prefix_separator = table_prefix_separator
self.compat = compat
- socket = TSocket(self.host, self.port)
-
- if timeout is not None:
- socket.setTimeout(timeout)
-
- self.transport = THRIFT_TRANSPORTS[transport](socket)
- protocol = TBinaryProtocol.TBinaryProtocolAccelerated(self.transport)
- self.client = Hbase.Client(protocol)
+ self._transport_class = THRIFT_TRANSPORTS[transport]
+ self._refresh_thrift_client()
if autoconnect:
self.open()
self._initialized = True
+ def _refresh_thrift_client(self):
+ """Refresh the Thrift socket, transport, and client."""
+ socket = TSocket(self.host, self.port)
+ if self.timeout is not None:
+ socket.setTimeout(self.timeout)
+
+ self.transport = self._transport_class(socket)
+ protocol = TBinaryProtocol.TBinaryProtocolAccelerated(self.transport)
+ self.client = Hbase.Client(protocol)
+
def _table_name(self, name):
"""Construct a table name by optionally adding a table name prefix."""
if self.table_prefix is None: