diff --git a/hazelcast/protocol/__init__.py b/hazelcast/protocol/__init__.py index cafd66f1e5..ce2c6d2325 100644 --- a/hazelcast/protocol/__init__.py +++ b/hazelcast/protocol/__init__.py @@ -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) @@ -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) @@ -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) @@ -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 @@ -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, + ) diff --git a/hazelcast/protocol/builtin.py b/hazelcast/protocol/builtin.py index d99ede5082..e28c5fb7a3 100644 --- a/hazelcast/protocol/builtin.py +++ b/hazelcast/protocol/builtin.py @@ -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 @@ -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) @@ -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)) @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/hazelcast/protocol/client_message.py b/hazelcast/protocol/client_message.py index cb1bfe84cf..45010ab0d7 100644 --- a/hazelcast/protocol/client_message.py +++ b/hazelcast/protocol/client_message.py @@ -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): @@ -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): diff --git a/pyproject.toml b/pyproject.toml index a1a1160df1..506eceba31 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,11 +15,11 @@ exclude = ''' | dist | benchmarks - | hazelcast/protocol + | hazelcast/protocol/codec | hazelcast/proxy | hazelcast/serialization | tests )/ - | /hazelcast/(?!(__init__)\.py).+ + | /hazelcast/(?!(__init__))\w+\.py ) '''