Skip to content
Merged
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
65 changes: 48 additions & 17 deletions hazelcast/protocol/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@ def __init__(self, error_code, class_name, message, stack_trace_elements):
self.stack_trace_elements = stack_trace_elements

def __eq__(self, other):
return isinstance(other, ErrorHolder) and self.error_code == other.error_code \
and self.class_name == other.class_name and self.message == other.message \
and self.stack_trace_elements == other.stack_trace_elements
return (
isinstance(other, ErrorHolder)
and self.error_code == other.error_code
and self.class_name == other.class_name
and self.message == other.message
and self.stack_trace_elements == other.stack_trace_elements
)

def __ne__(self, other):
return not self.__eq__(other)
Expand All @@ -29,9 +33,13 @@ def __init__(self, class_name, method_name, file_name, line_number):
self.line_number = line_number

def __eq__(self, other):
return isinstance(other, StackTraceElement) and self.class_name == other.class_name \
and self.method_name == other.method_name and self.file_name == other.file_name \
and self.line_number == other.line_number
return (
isinstance(other, StackTraceElement)
and self.class_name == other.class_name
and self.method_name == other.method_name
and self.file_name == other.file_name
and self.line_number == other.line_number
)

def __ne__(self, other):
return not self.__eq__(other)
Expand All @@ -53,10 +61,12 @@ def __init__(self, name, seed, group_id):
self.id = group_id

def __eq__(self, other):
return isinstance(other, RaftGroupId) \
and self.name == other.name \
and self.seed == other.seed \
and self.id == other.id
return (
isinstance(other, RaftGroupId)
and self.name == other.name
and self.seed == other.seed
and self.id == other.id
)

def __ne__(self, other):
return not self.__eq__(other)
Expand Down Expand Up @@ -90,11 +100,25 @@ def as_anchor_list(self, to_object):

class PagingPredicateHolder(object):
__slots__ = (
"anchor_data_list_holder", "predicate_data", "comparator_data", "page_size", "page", "iteration_type_id",
"partition_key_data")

def __init__(self, anchor_data_list_holder, predicate_data, comparator_data, page_size, page, iteration_type_id,
partition_key_data):
"anchor_data_list_holder",
"predicate_data",
"comparator_data",
"page_size",
"page",
"iteration_type_id",
"partition_key_data",
)

def __init__(
self,
anchor_data_list_holder,
predicate_data,
comparator_data,
page_size,
page,
iteration_type_id,
partition_key_data,
):
self.anchor_data_list_holder = anchor_data_list_holder
self.predicate_data = predicate_data
self.comparator_data = comparator_data
Expand All @@ -120,5 +144,12 @@ def of(predicate, to_data):
comparator_data = to_data(predicate.comparator)
iteration_type = predicate.iteration_type

return PagingPredicateHolder(anchor_data_list_holder, predicate_data, comparator_data, predicate.page_size,
predicate.page, iteration_type, None)
return PagingPredicateHolder(
anchor_data_list_holder,
predicate_data,
comparator_data,
predicate.page_size,
predicate.page,
iteration_type,
None,
)
48 changes: 38 additions & 10 deletions hazelcast/protocol/builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,28 @@

from hazelcast import six
from hazelcast.six.moves import range
from hazelcast.protocol.client_message import NULL_FRAME_BUF, BEGIN_FRAME_BUF, END_FRAME_BUF, \
SIZE_OF_FRAME_LENGTH_AND_FLAGS, _IS_FINAL_FLAG, NULL_FINAL_FRAME_BUF, END_FINAL_FRAME_BUF
from hazelcast.serialization import LONG_SIZE_IN_BYTES, UUID_SIZE_IN_BYTES, LE_INT, LE_LONG, BOOLEAN_SIZE_IN_BYTES, \
INT_SIZE_IN_BYTES, LE_ULONG, LE_UINT16, LE_INT8, UUID_MSB_SHIFT, UUID_LSB_MASK
from hazelcast.protocol.client_message import (
NULL_FRAME_BUF,
BEGIN_FRAME_BUF,
END_FRAME_BUF,
SIZE_OF_FRAME_LENGTH_AND_FLAGS,
_IS_FINAL_FLAG,
NULL_FINAL_FRAME_BUF,
END_FINAL_FRAME_BUF,
)
from hazelcast.serialization import (
LONG_SIZE_IN_BYTES,
UUID_SIZE_IN_BYTES,
LE_INT,
LE_LONG,
BOOLEAN_SIZE_IN_BYTES,
INT_SIZE_IN_BYTES,
LE_ULONG,
LE_UINT16,
LE_INT8,
UUID_MSB_SHIFT,
UUID_LSB_MASK,
)
from hazelcast.serialization.data import Data


Expand Down Expand Up @@ -145,7 +163,6 @@ def decode_nullable(msg, key_decoder, value_decoder):


class EntryListUUIDLongCodec(object):

@staticmethod
def encode(buf, entries, is_final=False):
n = len(entries)
Expand Down Expand Up @@ -251,7 +268,10 @@ def decode_uuid(buf, offset):

msb_offset = offset + BOOLEAN_SIZE_IN_BYTES
lsb_offset = msb_offset + LONG_SIZE_IN_BYTES
b = buf[lsb_offset - 1:msb_offset - 1:-1] + buf[lsb_offset + LONG_SIZE_IN_BYTES - 1:lsb_offset - 1:-1]
b = (
buf[lsb_offset - 1 : msb_offset - 1 : -1]
+ buf[lsb_offset + LONG_SIZE_IN_BYTES - 1 : lsb_offset - 1 : -1]
)
return uuid.UUID(bytes=bytes(b))


Expand All @@ -265,7 +285,9 @@ def encode(buf, arr, is_final=False):
if is_final:
LE_UINT16.pack_into(b, INT_SIZE_IN_BYTES, _IS_FINAL_FLAG)
for i in range(n):
FixSizedTypesCodec.encode_int(b, SIZE_OF_FRAME_LENGTH_AND_FLAGS + i * INT_SIZE_IN_BYTES, arr[i])
FixSizedTypesCodec.encode_int(
b, SIZE_OF_FRAME_LENGTH_AND_FLAGS + i * INT_SIZE_IN_BYTES, arr[i]
)
buf.extend(b)

@staticmethod
Expand All @@ -288,7 +310,9 @@ def encode(buf, arr, is_final=False):
if is_final:
LE_UINT16.pack_into(b, INT_SIZE_IN_BYTES, _IS_FINAL_FLAG)
for i in range(n):
FixSizedTypesCodec.encode_long(b, SIZE_OF_FRAME_LENGTH_AND_FLAGS + i * LONG_SIZE_IN_BYTES, arr[i])
FixSizedTypesCodec.encode_long(
b, SIZE_OF_FRAME_LENGTH_AND_FLAGS + i * LONG_SIZE_IN_BYTES, arr[i]
)
buf.extend(b)

@staticmethod
Expand Down Expand Up @@ -376,7 +400,9 @@ def encode(buf, arr, is_final=False):
if is_final:
LE_UINT16.pack_into(b, INT_SIZE_IN_BYTES, _IS_FINAL_FLAG)
for i in range(n):
FixSizedTypesCodec.encode_uuid(b, SIZE_OF_FRAME_LENGTH_AND_FLAGS + i * UUID_SIZE_IN_BYTES, arr[i])
FixSizedTypesCodec.encode_uuid(
b, SIZE_OF_FRAME_LENGTH_AND_FLAGS + i * UUID_SIZE_IN_BYTES, arr[i]
)
buf.extend(b)

@staticmethod
Expand All @@ -399,7 +425,9 @@ def encode(buf, arr, is_final=False):
if is_final:
LE_UINT16.pack_into(b, INT_SIZE_IN_BYTES, _IS_FINAL_FLAG)
for i in range(n):
FixSizedTypesCodec.encode_long(b, SIZE_OF_FRAME_LENGTH_AND_FLAGS + i * LONG_SIZE_IN_BYTES, arr[i])
FixSizedTypesCodec.encode_long(
b, SIZE_OF_FRAME_LENGTH_AND_FLAGS + i * LONG_SIZE_IN_BYTES, arr[i]
)
buf.extend(b)

@staticmethod
Expand Down
11 changes: 8 additions & 3 deletions hazelcast/protocol/client_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,11 @@ def set_backup_aware_flag(self):
def __repr__(self):
message_type = LE_INT.unpack_from(self.buf, _OUTBOUND_MESSAGE_MESSAGE_TYPE_OFFSET)[0]
correlation_id = self.get_correlation_id()
return "OutboundMessage(message_type=%s, correlation_id=%s, retryable=%s)" \
% (message_type, correlation_id, self.retryable)
return "OutboundMessage(message_type=%s, correlation_id=%s, retryable=%s)" % (
message_type,
correlation_id,
self.retryable,
)


class Frame(object):
Expand Down Expand Up @@ -213,7 +216,9 @@ def __repr__(self):
# Has END_DATA_STRUCTURE and IS_FINAL flags
END_FINAL_FRAME_BUF = bytearray(SIZE_OF_FRAME_LENGTH_AND_FLAGS)
LE_INT.pack_into(END_FINAL_FRAME_BUF, 0, SIZE_OF_FRAME_LENGTH_AND_FLAGS)
LE_UINT16.pack_into(END_FINAL_FRAME_BUF, INT_SIZE_IN_BYTES, _END_DATA_STRUCTURE_FLAG | _IS_FINAL_FLAG)
LE_UINT16.pack_into(
END_FINAL_FRAME_BUF, INT_SIZE_IN_BYTES, _END_DATA_STRUCTURE_FLAG | _IS_FINAL_FLAG
)


class ClientMessageBuilder(object):
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ exclude = '''
| dist

| benchmarks
| hazelcast/protocol
| hazelcast/protocol/codec
| hazelcast/proxy
| hazelcast/serialization
| tests
)/
| /hazelcast/(?!(__init__)\.py).+
| /hazelcast/(?!(__init__))\w+\.py
)
'''