Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 3 additions & 14 deletions cassandra/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,7 @@
from cassandra.application_info import ApplicationInfoBase
from cassandra.driver_config import DriverConfigReporter

try:
from weakref import WeakSet
except ImportError:
from cassandra.util import WeakSet # NOQA
from weakref import WeakSet

def _try_libev_import():
try:
Expand Down Expand Up @@ -134,12 +131,6 @@ def _connection_reduce_fn(val,import_fn):
raise DependencyException("Exception loading connection class dependencies", excs)
DefaultConnection = conn_class

# Forces load of utf8 encoding module to avoid deadlock that occurs
# if code that is being imported tries to import the module in a seperate
# thread.
# See http://bugs.python.org/issue10923
"".encode('utf8')

log = logging.getLogger(__name__)

_GRAPH_PAGING_MIN_DSE_VERSION = Version('6.8.0')
Expand Down Expand Up @@ -5309,7 +5300,7 @@ def _set_result(self, host, connection, pool, response):
except KeyError:
if not self.prepared_statement:
log.error("Tried to execute unknown prepared statement: id=%s",
query_id.encode('hex'))
query_id.hex())
self._set_final_exception(response)
return
else:
Expand Down Expand Up @@ -5898,11 +5889,9 @@ def __getitem__(self, i):
self._enter_list_mode("index operator")
return self._current_rows[i]

def __nonzero__(self):
def __bool__(self):
return bool(self._current_rows)

__bool__ = __nonzero__

def get_query_trace(self, max_wait_sec=None):
"""
Gets the last query trace from the associated future.
Expand Down
3 changes: 0 additions & 3 deletions cassandra/cqlengine/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,3 @@ class CQLEngineException(Exception):
class ValidationError(CQLEngineException):
pass


class UnicodeMixin(object):
__str__ = lambda x: x.__unicode__()
8 changes: 4 additions & 4 deletions cassandra/cqlengine/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@

from datetime import datetime

from cassandra.cqlengine import UnicodeMixin, ValidationError
from cassandra.cqlengine import ValidationError

def get_total_seconds(td):
return td.total_seconds()

class QueryValue(UnicodeMixin):
class QueryValue:
"""
Base class for query filter values. Subclasses of these classes can
be passed into .filter() keyword args
Expand All @@ -31,7 +31,7 @@ def __init__(self, value):
self.value = value
self.context_id = None

def __unicode__(self):
def __str__(self):
return self.format_string.format(self.context_id)

def set_context_id(self, ctx_id):
Expand Down Expand Up @@ -109,7 +109,7 @@ def set_columns(self, columns):
def get_context_size(self):
return len(self.value)

def __unicode__(self):
def __str__(self):
token_args = ', '.join('%({0})s'.format(self.context_id + i) for i in range(self.get_context_size()))
return "token({0})".format(token_args)

Expand Down
2 changes: 1 addition & 1 deletion cassandra/cqlengine/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ class ColumnQueryEvaluator(query.AbstractQueryableColumn):
def __init__(self, column):
self.column = column

def __unicode__(self):
def __str__(self):
return self.column.db_field_name

def _get_column(self):
Expand Down
2 changes: 1 addition & 1 deletion cassandra/cqlengine/named.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class NamedColumn(AbstractQueryableColumn):
def __init__(self, name):
self.name = name

def __unicode__(self):
def __str__(self):
return self.name

def _get_column(self):
Expand Down
5 changes: 2 additions & 3 deletions cassandra/cqlengine/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,21 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from cassandra.cqlengine import UnicodeMixin


class QueryOperatorException(Exception):
pass


class BaseQueryOperator(UnicodeMixin):
class BaseQueryOperator:
# The symbol that identifies this operator in kwargs
# ie: colname__<symbol>
symbol = None

# The comparator symbol this operator uses in cql
cql_symbol = None

def __unicode__(self):
def __str__(self):
if self.cql_symbol is None:
raise QueryOperatorException("cql symbol is None")
return self.cql_symbol
Expand Down
11 changes: 4 additions & 7 deletions cassandra/cqlengine/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from warnings import warn

from cassandra.query import SimpleStatement, BatchType as CBatchType
from cassandra.cqlengine import columns, CQLEngineException, ValidationError, UnicodeMixin
from cassandra.cqlengine import columns, CQLEngineException, ValidationError
from cassandra.cqlengine import connection as conn
from cassandra.cqlengine.functions import Token, BaseQueryFunction, QueryValue
from cassandra.cqlengine.operators import (InOperator, EqualsOperator, GreaterThanOperator,
Expand Down Expand Up @@ -78,7 +78,7 @@ def check_applied(result):
raise LWTException(result.one())


class AbstractQueryableColumn(UnicodeMixin):
class AbstractQueryableColumn:
"""
exposes cql query operators through pythons
builtin comparator symbols
Expand All @@ -87,7 +87,7 @@ class AbstractQueryableColumn(UnicodeMixin):
def _get_column(self):
raise NotImplementedError

def __unicode__(self):
def __str__(self):
raise NotImplementedError

def _to_database(self, val):
Expand Down Expand Up @@ -405,11 +405,8 @@ def _execute(self, statement):
check_applied(result)
return result

def __unicode__(self):
return str(self._select_query())

def __str__(self):
return str(self.__unicode__())
return str(self._select_query())

def __call__(self, *args, **kwargs):
return self.filter(*args, **kwargs)
Expand Down
53 changes: 26 additions & 27 deletions cassandra/cqlengine/statements.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

from cassandra.query import FETCH_SIZE_UNSET
from cassandra.cqlengine import columns
from cassandra.cqlengine import UnicodeMixin
from cassandra.cqlengine.functions import QueryValue
from cassandra.cqlengine.operators import BaseWhereOperator, InOperator, EqualsOperator, IsNotNullOperator

Expand All @@ -26,12 +25,12 @@ class StatementException(Exception):
pass


class ValueQuoter(UnicodeMixin):
class ValueQuoter:

def __init__(self, value):
self.value = value

def __unicode__(self):
def __str__(self):
from cassandra.encoder import cql_quote
if isinstance(self.value, (list, tuple)):
return '[' + ', '.join([cql_quote(v) for v in self.value]) + ']'
Expand All @@ -49,19 +48,19 @@ def __eq__(self, other):

class InQuoter(ValueQuoter):

def __unicode__(self):
def __str__(self):
from cassandra.encoder import cql_quote
return '(' + ', '.join([cql_quote(v) for v in self.value]) + ')'


class BaseClause(UnicodeMixin):
class BaseClause:

def __init__(self, field, value):
self.field = field
self.value = value
self.context_id = None

def __unicode__(self):
def __str__(self):
raise NotImplementedError

def __hash__(self):
Expand Down Expand Up @@ -110,9 +109,9 @@ def __init__(self, field, operator, value, quote_field=True):
self.query_value = self.value if isinstance(self.value, QueryValue) else QueryValue(self.value)
self.quote_field = quote_field

def __unicode__(self):
def __str__(self):
field = ('"{0}"' if self.quote_field else '{0}').format(self.field)
return u'{0} {1} {2}'.format(field, self.operator, str(self.query_value))
return '{0} {1} {2}'.format(field, self.operator, str(self.query_value))

def __hash__(self):
return super(WhereClause, self).__hash__() ^ hash(self.operator)
Expand Down Expand Up @@ -140,9 +139,9 @@ class IsNotNullClause(WhereClause):
def __init__(self, field):
super(IsNotNullClause, self).__init__(field, IsNotNullOperator(), '')

def __unicode__(self):
def __str__(self):
field = ('"{0}"' if self.quote_field else '{0}').format(self.field)
return u'{0} {1}'.format(field, self.operator)
return '{0} {1}'.format(field, self.operator)

def update_context(self, ctx):
pass
Expand All @@ -157,8 +156,8 @@ def get_context_size(self):
class AssignmentClause(BaseClause):
""" a single variable st statement """

def __unicode__(self):
return u'"{0}" = %({1})s'.format(self.field, self.context_id)
def __str__(self):
return '"{0}" = %({1})s'.format(self.field, self.context_id)

def insert_tuple(self):
return self.field, self.context_id
Expand All @@ -167,8 +166,8 @@ def insert_tuple(self):
class ConditionalClause(BaseClause):
""" A single variable iff statement """

def __unicode__(self):
return u'"{0}" = %({1})s'.format(self.field, self.context_id)
def __str__(self):
return '"{0}" = %({1})s'.format(self.field, self.context_id)

def insert_tuple(self):
return self.field, self.context_id
Expand Down Expand Up @@ -211,7 +210,7 @@ class SetUpdateClause(ContainerUpdateClause):
_additions = None
_removals = None

def __unicode__(self):
def __str__(self):
qs = []
ctx_id = self.context_id
if (self.previous is None and
Expand Down Expand Up @@ -283,7 +282,7 @@ class ListUpdateClause(ContainerUpdateClause):
_append = None
_prepend = None

def __unicode__(self):
def __str__(self):
if not self._analyzed:
self._analyze()
qs = []
Expand Down Expand Up @@ -412,7 +411,7 @@ def is_assignment(self):
self._analyze()
return self.previous is None and not self._updates and not self._removals

def __unicode__(self):
def __str__(self):
qs = []

ctx_id = self.context_id
Expand Down Expand Up @@ -443,7 +442,7 @@ def get_context_size(self):
def update_context(self, ctx):
ctx[str(self.context_id)] = abs(self.value - self.previous)

def __unicode__(self):
def __str__(self):
delta = self.value - self.previous
sign = '-' if delta < 0 else '+'
return '"{0}" = "{0}" {1} %({2})s'.format(self.field, sign, self.context_id)
Expand All @@ -459,7 +458,7 @@ class FieldDeleteClause(BaseDeleteClause):
def __init__(self, field):
super(FieldDeleteClause, self).__init__(field, None)

def __unicode__(self):
def __str__(self):
return '"{0}"'.format(self.field)

def update_context(self, ctx):
Expand Down Expand Up @@ -494,13 +493,13 @@ def get_context_size(self):
self._analyze()
return len(self._removals)

def __unicode__(self):
def __str__(self):
if not self._analyzed:
self._analyze()
return ', '.join(['"{0}"[%({1})s]'.format(self.field, self.context_id + i) for i in range(len(self._removals))])


class BaseCQLStatement(UnicodeMixin):
class BaseCQLStatement:
""" The base cql statement class """

def __init__(self, table, timestamp=None, where=None, fetch_size=None, conditionals=None):
Expand Down Expand Up @@ -591,11 +590,11 @@ def timestamp_normalized(self):

return int(time.mktime(tmp.timetuple()) * 1e+6 + tmp.microsecond)

def __unicode__(self):
def __str__(self):
raise NotImplementedError

def __repr__(self):
return self.__unicode__()
return self.__str__()

@property
def _where(self):
Expand Down Expand Up @@ -633,7 +632,7 @@ def __init__(self,
self.limit = limit
self.allow_filtering = allow_filtering

def __unicode__(self):
def __str__(self):
qs = ['SELECT']
if self.distinct_fields:
if self.count:
Expand Down Expand Up @@ -734,7 +733,7 @@ def __init__(self,

self.if_not_exists = if_not_exists

def __unicode__(self):
def __str__(self):
qs = ['INSERT INTO {0}'.format(self.table)]

# get column names and context placeholders
Expand Down Expand Up @@ -780,7 +779,7 @@ def __init__(self,

self.if_exists = if_exists

def __unicode__(self):
def __str__(self):
qs = ['UPDATE', self.table]

using_options = []
Expand Down Expand Up @@ -881,7 +880,7 @@ def add_field(self, field):
self.context_counter += field.get_context_size()
self.fields.append(field)

def __unicode__(self):
def __str__(self):
qs = ['DELETE']
if self.fields:
qs += [', '.join(['{0}'.format(f) for f in self.fields])]
Expand Down
Loading
Loading