summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWouter Bolsterlee <uws@xs4all.nl>2016-03-27 21:46:42 +0200
committerWouter Bolsterlee <uws@xs4all.nl>2016-03-27 21:46:42 +0200
commit9212da0fd4997e462a95f20a8c26182ce51be55e (patch)
tree7157e2b855fdccfdd5df8b2e6729fd2cfa8081a9
parent1ded319c92c3861b2ebbc455f6763d812fc13e55 (diff)
downloadhappybase-9212da0fd4997e462a95f20a8c26182ce51be55e.tar.gz
Port to thriftpy
-rw-r--r--happybase/__init__.py5
-rw-r--r--happybase/batch.py2
-rw-r--r--happybase/connection.py27
-rw-r--r--happybase/pool.py2
-rw-r--r--happybase/table.py3
-rw-r--r--happybase/util.py2
-rw-r--r--requirements.txt2
-rw-r--r--tests/test_api.py6
8 files changed, 25 insertions, 24 deletions
diff --git a/happybase/__init__.py b/happybase/__init__.py
index 11e350d..6f91799 100644
--- a/happybase/__init__.py
+++ b/happybase/__init__.py
@@ -3,11 +3,12 @@ HappyBase, a developer-friendly Python library to interact with Apache
HBase.
"""
+import thriftpy as _thriftpy
+_thriftpy.install_import_hook()
+
from ._version import __version__
from .connection import DEFAULT_HOST, DEFAULT_PORT, Connection
from .table import Table
from .batch import Batch
from .pool import ConnectionPool, NoConnectionsAvailable
-
-# TODO: properly handle errors defined in Thrift specification
diff --git a/happybase/batch.py b/happybase/batch.py
index 5e51410..a8162e9 100644
--- a/happybase/batch.py
+++ b/happybase/batch.py
@@ -6,7 +6,7 @@ from collections import defaultdict
import logging
from numbers import Integral
-from .hbase.ttypes import BatchMutation, Mutation
+from .Hbase_thrift import BatchMutation, Mutation
logger = logging.getLogger(__name__)
diff --git a/happybase/connection.py b/happybase/connection.py
index e52d256..3c1627c 100644
--- a/happybase/connection.py
+++ b/happybase/connection.py
@@ -6,12 +6,11 @@ HappyBase connection module.
import logging
-from thrift.transport.TSocket import TSocket
-from thrift.transport.TTransport import TBufferedTransport, TFramedTransport
-from thrift.protocol import TBinaryProtocol, TCompactProtocol
+from thriftpy.thrift import TClient
+from thriftpy.transport import TBufferedTransport, TFramedTransport, TSocket
+from thriftpy.protocol import TBinaryProtocol, TCompactProtocol
-from .hbase import Hbase
-from .hbase.ttypes import ColumnDescriptor
+from .Hbase_thrift import Hbase, ColumnDescriptor
from .table import Table
from .util import pep8_to_camel_case
@@ -23,8 +22,8 @@ THRIFT_TRANSPORTS = dict(
framed=TFramedTransport,
)
THRIFT_PROTOCOLS = dict(
- binary=TBinaryProtocol.TBinaryProtocolAccelerated,
- compact=TCompactProtocol.TCompactProtocol,
+ binary=TBinaryProtocol,
+ compact=TCompactProtocol,
)
DEFAULT_HOST = 'localhost'
@@ -78,8 +77,8 @@ class Connection(object):
since otherwise you might see non-obvious connection errors or
program hangs when making a connection. ``TCompactProtocol`` is
a more compact binary format that is typically more efficient to
- process as well. ``TBinaryAccelerated`` is the default protocol that
- happybase uses.
+ process as well. ``TBinaryProtocol`` is the default protocol that
+ Happybase uses.
.. versionadded:: 0.9
`protocol` argument
@@ -148,11 +147,11 @@ class Connection(object):
"""Refresh the Thrift socket, transport, and client."""
socket = TSocket(self.host, self.port)
if self.timeout is not None:
- socket.setTimeout(self.timeout)
+ socket.set_timeout(self.timeout)
self.transport = self._transport_class(socket)
- protocol = self._protocol_class(self.transport)
- self.client = Hbase.Client(protocol)
+ protocol = self._protocol_class(self.transport, decode_response=False)
+ self.client = TClient(Hbase, protocol)
def _table_name(self, name):
"""Construct a table name by optionally adding a table name prefix."""
@@ -166,7 +165,7 @@ class Connection(object):
This method opens the underlying Thrift transport (TCP connection).
"""
- if self.transport.isOpen():
+ if self.transport.is_open():
return
logger.debug("Opening Thrift transport to %s:%d", self.host, self.port)
@@ -177,7 +176,7 @@ class Connection(object):
This method closes the underlying Thrift transport (TCP connection).
"""
- if not self.transport.isOpen():
+ if not self.transport.is_open():
return
if logger is not None:
diff --git a/happybase/pool.py b/happybase/pool.py
index 9cc9f69..aa0da99 100644
--- a/happybase/pool.py
+++ b/happybase/pool.py
@@ -8,7 +8,7 @@ import Queue
import socket
import threading
-from thrift.Thrift import TException
+from thriftpy.thrift import TException
from .connection import Connection
diff --git a/happybase/table.py b/happybase/table.py
index 3cb26b7..87be2f6 100644
--- a/happybase/table.py
+++ b/happybase/table.py
@@ -7,7 +7,8 @@ from numbers import Integral
from operator import attrgetter
from struct import Struct
-from .hbase.ttypes import TScan
+from .Hbase_thrift import TScan
+
from .util import thrift_type_to_dict, str_increment, OrderedDict
from .batch import Batch
diff --git a/happybase/util.py b/happybase/util.py
index 355e864..09a4c61 100644
--- a/happybase/util.py
+++ b/happybase/util.py
@@ -45,7 +45,7 @@ def pep8_to_camel_case(name, initial=False):
def thrift_attrs(obj_or_cls):
"""Obtain Thrift data type attribute names for an instance or class."""
- return [v[2] for v in obj_or_cls.thrift_spec[1:]]
+ return [v[1] for v in obj_or_cls.thrift_spec.values()]
def thrift_type_to_dict(obj):
diff --git a/requirements.txt b/requirements.txt
index 85cebac..dee2304 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1 +1 @@
-thrift>=0.8.0
+thriftpy>=0.3.7
diff --git a/tests/test_api.py b/tests/test_api.py
index 292ee3f..cbfdbd0 100644
--- a/tests/test_api.py
+++ b/tests/test_api.py
@@ -490,7 +490,7 @@ def test_connection_pool_construction():
def test_connection_pool():
- from thrift.transport.TTransport import TTransportException
+ from thriftpy.thrift import TException
def run():
name = threading.current_thread().name
@@ -505,7 +505,7 @@ def test_connection_pool():
if random.random() < .25:
print "Introducing random failure"
connection.transport.close()
- raise TTransportException("Fake transport exception")
+ raise TException("Fake transport exception")
for i in xrange(50):
with pool.connection() as connection:
@@ -513,7 +513,7 @@ def test_connection_pool():
try:
inner_function()
- except TTransportException:
+ except TException:
# This error should have been picked up by the
# connection pool, and the connection should have
# been replaced by a fresh one