Skip to content

Commit

Permalink
rearrange new module structure a bit
Browse files Browse the repository at this point in the history
to avoid using "from X import *" where easy to do so, and to combine the
translate and cassandra.constants modules, since they accomplished
nearly the same purpose.

removed extraneous __all__ declarations.

clarify name of per-cassandra-version constants.
  • Loading branch information
paul cannon committed Apr 26, 2011
1 parent 81f1892 commit ff57817
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 22 deletions.
7 changes: 0 additions & 7 deletions telephus/cassandra/constants.py

This file was deleted.

4 changes: 2 additions & 2 deletions telephus/pool.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@
InvalidThriftRequest) InvalidThriftRequest)
from telephus.cassandra.c08 import Cassandra as Cassandra08 from telephus.cassandra.c08 import Cassandra as Cassandra08
from telephus.cassandra.ttypes import * from telephus.cassandra.ttypes import *
from telephus.cassandra.constants import *
from telephus.client import CassandraClient from telephus.client import CassandraClient
from translate import * from telephus.translate import (getAPIVersion, translateArgs,
postProcess)


noop = lambda *a, **kw: None noop = lambda *a, **kw: None


Expand Down
5 changes: 2 additions & 3 deletions telephus/protocol.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
from twisted.internet import defer, reactor from twisted.internet import defer, reactor
from twisted.internet.error import UserError from twisted.internet.error import UserError
from twisted.python import failure from twisted.python import failure
from telephus import translate
from telephus.cassandra.ttypes import * from telephus.cassandra.ttypes import *
from telephus.cassandra.constants import * from telephus.cassandra.c08 import Cassandra
import telephus.cassandra.c08.Cassandra as Cassandra
import telephus.translate as translate
from sys import exc_info from sys import exc_info


class ClientBusy(Exception): class ClientBusy(Exception):
Expand Down
16 changes: 10 additions & 6 deletions telephus/translate.py
Original file line number Original file line Diff line number Diff line change
@@ -1,6 +1,10 @@
from telephus.cassandra.constants import * from telephus.cassandra.c07.constants import VERSION as CASSANDRA_07_VERSION
from telephus.cassandra.c08.constants import VERSION as CASSANDRA_08_VERSION


__all__ = ['APIMismatch', 'getAPIVersion', 'translateArgs', 'postProcess'] supported_versions = (
('0.7', CASSANDRA_07_VERSION),
('0.8', CASSANDRA_08_VERSION),
)


class APIMismatch(Exception): class APIMismatch(Exception):
pass pass
Expand All @@ -14,18 +18,18 @@ def getAPIVersion(remoteversion):
number should not affect anything noticeable. number should not affect anything noticeable.
""" """
r_major, r_minor, r_patch = map(int, remoteversion.split('.')) r_major, r_minor, r_patch = map(int, remoteversion.split('.'))
for version in [CASSANDRA_08, CASSANDRA_07]: for cassversion, thriftversion in supported_versions:
o_major, o_minor, o_patch = map(int, version.split('.')) o_major, o_minor, o_patch = map(int, thriftversion.split('.'))
if (r_major == o_major) and (r_minor >= o_minor): if (r_major == o_major) and (r_minor >= o_minor):
return version return thriftversion
msg = 'Cassandra API version %s is not compatible with telephus' % ver msg = 'Cassandra API version %s is not compatible with telephus' % ver
raise APIMismatch(msg) raise APIMismatch(msg)


def translateArgs(request, api_version): def translateArgs(request, api_version):
args = request.args args = request.args
if request.method == 'system_add_keyspace' or \ if request.method == 'system_add_keyspace' or \
request.method == 'system_update_keyspace': request.method == 'system_update_keyspace':
if api_version == CASSANDRA_07: if api_version == CASSANDRA_07_VERSION:
args = (args[0].to07(),) args = (args[0].to07(),)
else: else:
args = (args[0].to08(),) args = (args[0].to08(),)
Expand Down
4 changes: 2 additions & 2 deletions test/test_cassandraclient.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from twisted.internet import defer, reactor, error from twisted.internet import defer, reactor, error
from telephus.protocol import ManagedCassandraClientFactory, APIMismatch from telephus.protocol import ManagedCassandraClientFactory, APIMismatch
from telephus.client import CassandraClient from telephus.client import CassandraClient
from telephus.cassandra import constants from telephus import translate
from telephus.cassandra.ttypes import * from telephus.cassandra.ttypes import *
import os import os


Expand Down Expand Up @@ -346,7 +346,7 @@ def test_initial_connection_failure(self):


@defer.inlineCallbacks @defer.inlineCallbacks
def test_api_match(self): def test_api_match(self):
for version in [constants.CASSANDRA_07, constants.CASSANDRA_08, None]: for version in [translate.CASSANDRA_07_VERSION, translate.CASSANDRA_08_VERSION, None]:
cmanager = ManagedCassandraClientFactory(api_version=version) cmanager = ManagedCassandraClientFactory(api_version=version)
client = CassandraClient(cmanager) client = CassandraClient(cmanager)
d = cmanager.deferred d = cmanager.deferred
Expand Down
4 changes: 2 additions & 2 deletions test/test_cassandraclusterpool.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from twisted.python import log from twisted.python import log
from telephus.pool import (CassandraClusterPool, CassandraPoolReconnectorFactory, from telephus.pool import (CassandraClusterPool, CassandraPoolReconnectorFactory,
CassandraPoolParticipantClient, TTransport) CassandraPoolParticipantClient, TTransport)
from telephus.cassandra import constants from telephus import translate
from telephus.cassandra.c08 import Cassandra from telephus.cassandra.c08 import Cassandra
from telephus.cassandra.ttypes import * from telephus.cassandra.ttypes import *


Expand Down Expand Up @@ -811,7 +811,7 @@ def work_o_tron(optime, numops, n):


starttime = time() starttime = time()
with self.cluster_and_pool(pool_size=1, num_nodes=num_nodes, with self.cluster_and_pool(pool_size=1, num_nodes=num_nodes,
api_version=constants.CASSANDRA_08): api_version=translate.CASSANDRA_08_VERSION):
yield self.make_standard_cfs(ksname) yield self.make_standard_cfs(ksname)
yield self.insert_dumb_rows(ksname, numkeys=num_keys) yield self.insert_dumb_rows(ksname, numkeys=num_keys)


Expand Down

0 comments on commit ff57817

Please sign in to comment.