Reorganize exceptions, centralize UnicodeMixin
This commit is contained in:
@@ -12,6 +12,9 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import six
|
||||
|
||||
|
||||
# compaction
|
||||
SizeTieredCompactionStrategy = "SizeTieredCompactionStrategy"
|
||||
LeveledCompactionStrategy = "LeveledCompactionStrategy"
|
||||
@@ -21,3 +24,18 @@ CACHING_ALL = "ALL"
|
||||
CACHING_KEYS_ONLY = "KEYS_ONLY"
|
||||
CACHING_ROWS_ONLY = "ROWS_ONLY"
|
||||
CACHING_NONE = "NONE"
|
||||
|
||||
|
||||
class CQLEngineException(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class ValidationError(CQLEngineException):
|
||||
pass
|
||||
|
||||
|
||||
class UnicodeMixin(object):
|
||||
if six.PY3:
|
||||
__str__ = lambda x: x.__unicode__()
|
||||
else:
|
||||
__str__ = lambda x: six.text_type(x).encode('utf-8')
|
||||
|
||||
@@ -17,24 +17,16 @@ from datetime import date, datetime
|
||||
import logging
|
||||
import re
|
||||
import six
|
||||
import sys
|
||||
import warnings
|
||||
|
||||
from cassandra.cqltypes import DateType
|
||||
from cassandra.encoder import cql_quote
|
||||
from cassandra.cqlengine.exceptions import ValidationError
|
||||
|
||||
from cassandra.cqlengine import ValidationError
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
# move to central spot
|
||||
class UnicodeMixin(object):
|
||||
if sys.version_info > (3, 0):
|
||||
__str__ = lambda x: x.__unicode__()
|
||||
else:
|
||||
__str__ = lambda x: six.text_type(x).encode('utf-8')
|
||||
|
||||
|
||||
class BaseValueManager(object):
|
||||
|
||||
def __init__(self, instance, column, value):
|
||||
|
||||
@@ -19,7 +19,8 @@ import six
|
||||
from cassandra import ConsistencyLevel
|
||||
from cassandra.cluster import Cluster, _NOT_SET, NoHostAvailable
|
||||
from cassandra.query import SimpleStatement, Statement, dict_factory
|
||||
from cassandra.cqlengine.exceptions import CQLEngineException, UndefinedKeyspaceException
|
||||
|
||||
from cassandra.cqlengine import CQLEngineException
|
||||
from cassandra.cqlengine.statements import BaseCQLStatement
|
||||
|
||||
|
||||
@@ -27,10 +28,6 @@ log = logging.getLogger(__name__)
|
||||
|
||||
NOT_SET = _NOT_SET # required for passing timeout to Session.execute
|
||||
|
||||
|
||||
class CQLConnectionError(CQLEngineException):
|
||||
pass
|
||||
|
||||
Host = namedtuple('Host', ['name', 'port'])
|
||||
|
||||
cluster = None
|
||||
@@ -39,6 +36,10 @@ lazy_connect_args = None
|
||||
default_consistency_level = ConsistencyLevel.ONE
|
||||
|
||||
|
||||
class UndefinedKeyspaceException(CQLEngineException):
|
||||
pass
|
||||
|
||||
|
||||
def default():
|
||||
"""
|
||||
Configures the global mapper connection to localhost, using the driver defaults
|
||||
|
||||
@@ -12,26 +12,12 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import logging
|
||||
import warnings
|
||||
|
||||
class CQLEngineException(Exception):
|
||||
pass
|
||||
import cassandra.cqlengine
|
||||
|
||||
|
||||
class ModelException(CQLEngineException):
|
||||
pass
|
||||
CQLEngineException = cassandra.cqlengine.CQLEngineException
|
||||
|
||||
|
||||
class ValidationError(CQLEngineException):
|
||||
pass
|
||||
|
||||
|
||||
class UndefinedKeyspaceException(CQLEngineException):
|
||||
pass
|
||||
|
||||
|
||||
class LWTException(CQLEngineException):
|
||||
pass
|
||||
|
||||
|
||||
class IfNotExistsWithCounterColumn(CQLEngineException):
|
||||
pass
|
||||
ValidationError = cassandra.cqlengine.ValidationError
|
||||
|
||||
@@ -13,18 +13,8 @@
|
||||
# limitations under the License.
|
||||
|
||||
from datetime import datetime
|
||||
import six
|
||||
import sys
|
||||
|
||||
from cassandra.cqlengine.exceptions import ValidationError
|
||||
# move to central spot
|
||||
|
||||
|
||||
class UnicodeMixin(object):
|
||||
if sys.version_info > (3, 0):
|
||||
__str__ = lambda x: x.__unicode__()
|
||||
else:
|
||||
__str__ = lambda x: six.text_type(x).encode('utf-8')
|
||||
from cassandra.cqlengine import UnicodeMixin, ValidationError
|
||||
|
||||
|
||||
class QueryValue(UnicodeMixin):
|
||||
|
||||
@@ -19,9 +19,8 @@ import six
|
||||
import warnings
|
||||
|
||||
from cassandra.metadata import KeyspaceMetadata
|
||||
from cassandra.cqlengine import SizeTieredCompactionStrategy, LeveledCompactionStrategy
|
||||
from cassandra.cqlengine import CQLEngineException, SizeTieredCompactionStrategy, LeveledCompactionStrategy
|
||||
from cassandra.cqlengine.connection import execute, get_cluster
|
||||
from cassandra.cqlengine.exceptions import CQLEngineException
|
||||
from cassandra.cqlengine.models import Model
|
||||
from cassandra.cqlengine.named import NamedTable
|
||||
|
||||
|
||||
@@ -17,8 +17,8 @@ import re
|
||||
import six
|
||||
import warnings
|
||||
|
||||
from cassandra.cqlengine import CQLEngineException, ValidationError
|
||||
from cassandra.cqlengine import columns
|
||||
from cassandra.cqlengine.exceptions import ModelException, CQLEngineException, ValidationError
|
||||
from cassandra.cqlengine.query import ModelQuerySet, DMLQuery, AbstractQueryableColumn, NOT_SET
|
||||
from cassandra.cqlengine.query import DoesNotExist as _DoesNotExist
|
||||
from cassandra.cqlengine.query import MultipleObjectsReturned as _MultipleObjectsReturned
|
||||
@@ -27,11 +27,15 @@ from cassandra.util import OrderedDict
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ModelException(CQLEngineException):
|
||||
pass
|
||||
|
||||
|
||||
class ModelDefinitionException(ModelException):
|
||||
pass
|
||||
|
||||
|
||||
class PolyMorphicModelException(ModelException):
|
||||
class PolymorphicModelException(ModelException):
|
||||
pass
|
||||
|
||||
|
||||
@@ -411,7 +415,7 @@ class BaseModel(object):
|
||||
disc_key = field_dict.get(cls._discriminator_column_name)
|
||||
|
||||
if disc_key is None:
|
||||
raise PolyMorphicModelException('discriminator value was not found in values')
|
||||
raise PolymorphicModelException('discriminator value was not found in values')
|
||||
|
||||
poly_base = cls if cls._is_polymorphic_base else cls._polymorphic_base
|
||||
|
||||
@@ -420,12 +424,12 @@ class BaseModel(object):
|
||||
poly_base._discover_polymorphic_submodels()
|
||||
klass = poly_base._get_model_by_discriminator_value(disc_key)
|
||||
if klass is None:
|
||||
raise PolyMorphicModelException(
|
||||
raise PolymorphicModelException(
|
||||
'unrecognized discriminator column {} for class {}'.format(disc_key, poly_base.__name__)
|
||||
)
|
||||
|
||||
if not issubclass(klass, cls):
|
||||
raise PolyMorphicModelException(
|
||||
raise PolymorphicModelException(
|
||||
'{} is not a subclass of {}'.format(klass.__name__, cls.__name__)
|
||||
)
|
||||
|
||||
@@ -643,7 +647,7 @@ class BaseModel(object):
|
||||
# handle polymorphic models
|
||||
if self._is_polymorphic:
|
||||
if self._is_polymorphic_base:
|
||||
raise PolyMorphicModelException('cannot save polymorphic base model')
|
||||
raise PolymorphicModelException('cannot save polymorphic base model')
|
||||
else:
|
||||
setattr(self, self._discriminator_column_name, self.__discriminator_value__)
|
||||
|
||||
@@ -693,7 +697,7 @@ class BaseModel(object):
|
||||
# handle polymorphic models
|
||||
if self._is_polymorphic:
|
||||
if self._is_polymorphic_base:
|
||||
raise PolyMorphicModelException('cannot update polymorphic base model')
|
||||
raise PolymorphicModelException('cannot update polymorphic base model')
|
||||
else:
|
||||
setattr(self, self._discriminator_column_name, self.__disciminator_value__)
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from cassandra.cqlengine.exceptions import CQLEngineException
|
||||
from cassandra.cqlengine import CQLEngineException
|
||||
from cassandra.cqlengine.query import AbstractQueryableColumn, SimpleQuerySet
|
||||
from cassandra.cqlengine.query import DoesNotExist as _DoesNotExist
|
||||
from cassandra.cqlengine.query import MultipleObjectsReturned as _MultipleObjectsReturned
|
||||
|
||||
@@ -12,22 +12,13 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import six
|
||||
import sys
|
||||
from cassandra.cqlengine import UnicodeMixin
|
||||
|
||||
|
||||
class QueryOperatorException(Exception):
|
||||
pass
|
||||
|
||||
|
||||
# move to central spot
|
||||
class UnicodeMixin(object):
|
||||
if sys.version_info > (3, 0):
|
||||
__str__ = lambda x: x.__unicode__()
|
||||
else:
|
||||
__str__ = lambda x: six.text_type(x).encode('utf-8')
|
||||
|
||||
|
||||
class BaseQueryOperator(UnicodeMixin):
|
||||
# The symbol that identifies this operator in kwargs
|
||||
# ie: colname__<symbol>
|
||||
|
||||
@@ -17,10 +17,9 @@ from datetime import datetime, timedelta
|
||||
import time
|
||||
import six
|
||||
|
||||
from cassandra.cqlengine import columns
|
||||
from cassandra.cqlengine import columns, CQLEngineException, ValidationError, UnicodeMixin
|
||||
from cassandra.cqlengine.connection import execute, NOT_SET
|
||||
from cassandra.cqlengine.exceptions import CQLEngineException, ValidationError, LWTException, IfNotExistsWithCounterColumn
|
||||
from cassandra.cqlengine.functions import Token, BaseQueryFunction, QueryValue, UnicodeMixin
|
||||
from cassandra.cqlengine.functions import Token, BaseQueryFunction, QueryValue
|
||||
from cassandra.cqlengine.operators import (InOperator, EqualsOperator, GreaterThanOperator,
|
||||
GreaterThanOrEqualOperator, LessThanOperator,
|
||||
LessThanOrEqualOperator, BaseWhereOperator)
|
||||
@@ -36,6 +35,14 @@ class QueryException(CQLEngineException):
|
||||
pass
|
||||
|
||||
|
||||
class IfNotExistsWithCounterColumn(CQLEngineException):
|
||||
pass
|
||||
|
||||
|
||||
class LWTException(CQLEngineException):
|
||||
pass
|
||||
|
||||
|
||||
class DoesNotExist(QueryException):
|
||||
pass
|
||||
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
from datetime import datetime, timedelta
|
||||
import time
|
||||
import six
|
||||
import sys
|
||||
|
||||
from cassandra.cqlengine import UnicodeMixin
|
||||
from cassandra.cqlengine.functions import QueryValue
|
||||
from cassandra.cqlengine.operators import BaseWhereOperator, InOperator
|
||||
|
||||
@@ -25,13 +25,6 @@ class StatementException(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class UnicodeMixin(object):
|
||||
if sys.version_info > (3, 0):
|
||||
__str__ = lambda x: x.__unicode__()
|
||||
else:
|
||||
__str__ = lambda x: six.text_type(x).encode('utf-8')
|
||||
|
||||
|
||||
class ValueQuoter(UnicodeMixin):
|
||||
|
||||
def __init__(self, value):
|
||||
|
||||
@@ -15,9 +15,8 @@
|
||||
from uuid import uuid4
|
||||
import warnings
|
||||
|
||||
from cassandra.cqlengine import columns
|
||||
from cassandra.cqlengine.exceptions import ModelException, CQLEngineException
|
||||
from cassandra.cqlengine.models import Model, ModelDefinitionException, ColumnQueryEvaluator
|
||||
from cassandra.cqlengine import columns, CQLEngineException
|
||||
from cassandra.cqlengine.models import Model, ModelException, ModelDefinitionException, ColumnQueryEvaluator
|
||||
from cassandra.cqlengine.query import ModelQuerySet, DMLQuery
|
||||
|
||||
from tests.integration.cqlengine.base import BaseCassEngTestCase
|
||||
|
||||
@@ -120,7 +120,7 @@ class TestPolymorphicModel(BaseCassEngTestCase):
|
||||
management.drop_table(Poly2)
|
||||
|
||||
def test_saving_base_model_fails(self):
|
||||
with self.assertRaises(models.PolyMorphicModelException):
|
||||
with self.assertRaises(models.PolymorphicModelException):
|
||||
PolyBase.create()
|
||||
|
||||
def test_saving_subclass_saves_poly_key(self):
|
||||
@@ -208,9 +208,9 @@ class TestUnindexedPolymorphicQuery(BaseCassEngTestCase):
|
||||
assert len(list(UnindexedPoly2.objects(partition=p1.partition, cluster__in=[p2.cluster, p3.cluster]))) == 2
|
||||
|
||||
def test_conflicting_type_results(self):
|
||||
with self.assertRaises(models.PolyMorphicModelException):
|
||||
with self.assertRaises(models.PolymorphicModelException):
|
||||
list(UnindexedPoly1.objects(partition=self.p1.partition))
|
||||
with self.assertRaises(models.PolyMorphicModelException):
|
||||
with self.assertRaises(models.PolymorphicModelException):
|
||||
list(UnindexedPoly2.objects(partition=self.p1.partition))
|
||||
|
||||
|
||||
|
||||
@@ -17,10 +17,9 @@ from uuid import uuid4
|
||||
|
||||
from tests.integration.cqlengine.base import BaseCassEngTestCase
|
||||
|
||||
from cassandra.cqlengine.exceptions import ModelException
|
||||
from cassandra.cqlengine.management import sync_table
|
||||
from cassandra.cqlengine.management import drop_table
|
||||
from cassandra.cqlengine.models import Model
|
||||
from cassandra.cqlengine.models import Model, ModelException
|
||||
from cassandra.cqlengine import columns
|
||||
from cassandra.cqlengine import query
|
||||
|
||||
|
||||
@@ -17,10 +17,9 @@ from unittest import skipUnless
|
||||
from uuid import uuid4
|
||||
|
||||
from cassandra.cqlengine import columns
|
||||
from cassandra.cqlengine.exceptions import LWTException, IfNotExistsWithCounterColumn
|
||||
from cassandra.cqlengine.management import sync_table, drop_table
|
||||
from cassandra.cqlengine.models import Model
|
||||
from cassandra.cqlengine.query import BatchQuery
|
||||
from cassandra.cqlengine.query import BatchQuery, LWTException, IfNotExistsWithCounterColumn
|
||||
|
||||
from tests.integration.cqlengine.base import BaseCassEngTestCase
|
||||
from tests.integration import PROTOCOL_VERSION
|
||||
|
||||
@@ -20,8 +20,7 @@ from uuid import uuid4
|
||||
from cassandra.cqlengine import columns
|
||||
from cassandra.cqlengine.management import sync_table, drop_table
|
||||
from cassandra.cqlengine.models import Model
|
||||
from cassandra.cqlengine.exceptions import LWTException
|
||||
from cassandra.cqlengine.query import BatchQuery
|
||||
from cassandra.cqlengine.query import BatchQuery, LWTException
|
||||
from cassandra.cqlengine.statements import TransactionClause
|
||||
|
||||
from tests.integration.cqlengine.base import BaseCassEngTestCase
|
||||
|
||||
Reference in New Issue
Block a user