diff --git a/cassandra/__init__.py b/cassandra/__init__.py index e69de29b..a79680f5 100644 --- a/cassandra/__init__.py +++ b/cassandra/__init__.py @@ -0,0 +1,36 @@ +__version__ = '0.0.1-alpha' +__version_info__ = (0, 0, 1) + + +class ConsistencyLevel(object): + + ANY = 0 + ONE = 1 + TWO = 2 + THREE = 3 + QUORUM = 4 + ALL = 5 + LOCAL_QUORUM = 6 + EACH_QUORUM = 7 + +ConsistencyLevel.value_to_name = { + ConsistencyLevel.ANY: 'ANY', + ConsistencyLevel.ONE: 'ONE', + ConsistencyLevel.TWO: 'TWO', + ConsistencyLevel.THREE: 'THREE', + ConsistencyLevel.QUORUM: 'QUORUM', + ConsistencyLevel.ALL: 'ALL', + ConsistencyLevel.LOCAL_QUORUM: 'LOCAL_QUORUM', + ConsistencyLevel.EACH_QUORUM: 'EACH_QUORUM' +} + +ConsistencyLevel.name_to_value = { + 'ANY': ConsistencyLevel.ANY, + 'ONE': ConsistencyLevel.ONE, + 'TWO': ConsistencyLevel.TWO, + 'THREE': ConsistencyLevel.THREE, + 'QUORUM': ConsistencyLevel.QUORUM, + 'ALL': ConsistencyLevel.ALL, + 'LOCAL_QUORUM': ConsistencyLevel.LOCAL_QUORUM, + 'EACH_QUORUM': ConsistencyLevel.EACH_QUORUM +} diff --git a/cassandra/cluster.py b/cassandra/cluster.py index 32cab35e..9bbb2908 100644 --- a/cassandra/cluster.py +++ b/cassandra/cluster.py @@ -6,8 +6,9 @@ import Queue import weakref from functools import partial +from cassandra import ConsistencyLevel from cassandra.connection import Connection, ConnectionException -from cassandra.decoder import (ConsistencyLevel, QueryMessage, ResultMessage, +from cassandra.decoder import (QueryMessage, ResultMessage, ErrorMessage, ReadTimeoutErrorMessage, WriteTimeoutErrorMessage, UnavailableErrorMessage, diff --git a/cassandra/connection.py b/cassandra/connection.py index 78237f8a..6d86a4ab 100644 --- a/cassandra/connection.py +++ b/cassandra/connection.py @@ -8,12 +8,11 @@ import socket from threading import RLock, Event, Lock, Thread import traceback - +from cassandra import ConsistencyLevel from cassandra.marshal import (int8_unpack, int32_unpack) from cassandra.decoder import (OptionsMessage, ReadyMessage, AuthenticateMessage, StartupMessage, ErrorMessage, CredentialsMessage, - QueryMessage, ResultMessage, ConsistencyLevel, - decode_response) + QueryMessage, ResultMessage, decode_response) log = logging.getLogger(__name__) diff --git a/cassandra/decoder.py b/cassandra/decoder.py index 8b8c9191..4d4cb8d3 100644 --- a/cassandra/decoder.py +++ b/cassandra/decoder.py @@ -20,6 +20,7 @@ try: except ImportError: from StringIO import StringIO # ignore flake8 warning: # NOQA +from cassandra import ConsistencyLevel from cassandra.marshal import (int32_pack, int32_unpack, uint16_pack, uint16_unpack, int8_pack, int8_unpack) from cassandra.types import lookup_cqltype @@ -45,40 +46,6 @@ def warn(msg): print msg -class ConsistencyLevel(object): - - ANY = 0 - ONE = 1 - TWO = 2 - THREE = 3 - QUORUM = 4 - ALL = 5 - LOCAL_QUORUM = 6 - EACH_QUORUM = 7 - -ConsistencyLevel.value_to_name = { - ConsistencyLevel.ANY: 'ANY', - ConsistencyLevel.ONE: 'ONE', - ConsistencyLevel.TWO: 'TWO', - ConsistencyLevel.THREE: 'THREE', - ConsistencyLevel.QUORUM: 'QUORUM', - ConsistencyLevel.ALL: 'ALL', - ConsistencyLevel.LOCAL_QUORUM: 'LOCAL_QUORUM', - ConsistencyLevel.EACH_QUORUM: 'EACH_QUORUM' -} - -ConsistencyLevel.name_to_value = { - 'ANY': ConsistencyLevel.ANY, - 'ONE': ConsistencyLevel.ONE, - 'TWO': ConsistencyLevel.TWO, - 'THREE': ConsistencyLevel.THREE, - 'QUORUM': ConsistencyLevel.QUORUM, - 'ALL': ConsistencyLevel.ALL, - 'LOCAL_QUORUM': ConsistencyLevel.LOCAL_QUORUM, - 'EACH_QUORUM': ConsistencyLevel.EACH_QUORUM -} - - class PreparedResult: def __init__(self, queryid, param_metadata): self.queryid = queryid diff --git a/cassandra/marshal.py b/cassandra/marshal.py index b2758a41..51010891 100644 --- a/cassandra/marshal.py +++ b/cassandra/marshal.py @@ -1,19 +1,3 @@ -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - import struct def _make_packer(format_string): diff --git a/cassandra/policies.py b/cassandra/policies.py index fab6d8c6..77eb448f 100644 --- a/cassandra/policies.py +++ b/cassandra/policies.py @@ -2,7 +2,7 @@ from itertools import islice, cycle, groupby, repeat from random import randint from threading import RLock -from decoder import ConsistencyLevel +from cassandra import ConsistencyLevel class HostDistance(object): diff --git a/cassandra/query.py b/cassandra/query.py index 0da16759..9ef8ddb5 100644 --- a/cassandra/query.py +++ b/cassandra/query.py @@ -1,6 +1,6 @@ import struct -from decoder import ConsistencyLevel +from cassandra import ConsistencyLevel class Query(object): diff --git a/tests/test_cluster.py b/tests/test_cluster.py index cd6ee784..9abd6cf1 100644 --- a/tests/test_cluster.py +++ b/tests/test_cluster.py @@ -1,11 +1,12 @@ import unittest from mock import Mock, ANY +from cassandra import ConsistencyLevel from cassandra.cluster import Cluster, Session, ResponseFuture, NoHostAvailable from cassandra.connection import ConnectionException from cassandra.decoder import (ReadTimeoutErrorMessage, WriteTimeoutErrorMessage, UnavailableErrorMessage, ResultMessage, QueryMessage, - OverloadedErrorMessage, ConsistencyLevel) + OverloadedErrorMessage) from cassandra.policies import RetryPolicy from cassandra.pool import NoConnectionsAvailable from cassandra.query import SimpleStatement diff --git a/tests/test_connection.py b/tests/test_connection.py index 9b068a50..e533c4e8 100644 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -2,7 +2,8 @@ import unittest from functools import partial from threading import Thread, Event -from cassandra.decoder import QueryMessage, ConsistencyLevel +from cassandra import ConsistencyLevel +from cassandra.decoder import QueryMessage from cassandra.connection import Connection class ConnectionTest(unittest.TestCase): diff --git a/tests/test_control_connection.py b/tests/test_control_connection.py index 834b31e8..27853e5f 100644 --- a/tests/test_control_connection.py +++ b/tests/test_control_connection.py @@ -1,7 +1,7 @@ import unittest from cassandra.decoder import ResultMessage -from cassandra.cluster import _ControlConnection, Cluster +from cassandra.cluster import ControlConnection, Cluster from cassandra.pool import Host from cassandra.policies import SimpleConvictionPolicy @@ -109,7 +109,7 @@ class ControlConnectionTest(unittest.TestCase): self.connection = MockConnection() self.time = FakeTime() - self.control_connection = _ControlConnection(self.cluster) + self.control_connection = ControlConnection(self.cluster) self.control_connection._connection = self.connection self.control_connection._time = self.time diff --git a/tests/test_policies.py b/tests/test_policies.py index e146f6f1..7a6c29fe 100644 --- a/tests/test_policies.py +++ b/tests/test_policies.py @@ -1,7 +1,7 @@ import unittest from threading import Thread -from cassandra.decoder import ConsistencyLevel +from cassandra import ConsistencyLevel from cassandra.policies import (RoundRobinPolicy, DCAwareRoundRobinPolicy, SimpleConvictionPolicy, HostDistance, ExponentialReconnectionPolicy, RetryPolicy,