You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by ee...@apache.org on 2010/11/12 20:32:43 UTC
svn commit: r1034534 - /cassandra/trunk/drivers/py/cql/__init__.py
Author: eevans
Date: Fri Nov 12 19:32:43 2010
New Revision: 1034534
URL: http://svn.apache.org/viewvc?rev=1034534&view=rev
Log:
wrap AvroRemoteExceptions in CQLExcpetions
Patch by eevans
Modified:
cassandra/trunk/drivers/py/cql/__init__.py
Modified: cassandra/trunk/drivers/py/cql/__init__.py
URL: http://svn.apache.org/viewvc/cassandra/trunk/drivers/py/cql/__init__.py?rev=1034534&r1=1034533&r2=1034534&view=diff
==============================================================================
--- cassandra/trunk/drivers/py/cql/__init__.py (original)
+++ cassandra/trunk/drivers/py/cql/__init__.py Fri Nov 12 19:32:43 2010
@@ -1,5 +1,5 @@
-from avro.ipc import HTTPTransceiver, Requestor
+from avro.ipc import HTTPTransceiver, Requestor, AvroRemoteException
import avro.protocol, zlib, socket
from os.path import exists, abspath, dirname, join
@@ -43,7 +43,11 @@ class Connection(object):
compressed_query = Connection.compress_query(query, compress)
request_params = dict(query=compressed_query, compression=compress)
- response = self.requestor.request('execute_cql_query', request_params)
+
+ try:
+ response = self.requestor.request('execute_cql_query', request_params)
+ except AvroRemoteException, are:
+ raise CQLException(are)
if response['type'] == 'ROWS':
return response['rows']
@@ -57,6 +61,17 @@ class Connection(object):
class InvalidCompressionScheme(Exception): pass
+class CQLException(Exception):
+ def __init__(self, arg):
+ if isinstance(arg, AvroRemoteException):
+ if arg.args and isinstance(arg.args[0], dict) and arg.args[0].has_key('why'):
+ message = arg.args[0]['why']
+ else:
+ message = str(arg)
+ Exception.__init__(self, message)
+ else:
+ Exception.__init__(self, arg)
+
if __name__ == '__main__':
dbconn = Connection('localhost', 9160)
query = 'USE Keyspace1;'