Skip to content

Commit

Permalink
fixed linter and added some more data checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Geary-Layne committed Dec 6, 2024
1 parent 4dc1e34 commit e698e9d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
27 changes: 17 additions & 10 deletions python/idsse_common/idsse/common/path_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,18 +387,25 @@ def _get_parsed_arg_parts(self, path: str, fmt_str: str) -> dict:
parsed_arg_parts = {}
for path_part, fmt_part in zip(path_parts, fmt_parts):
expected_len, lookup_info = self._lookup_dict[fmt_part]
if len(path_part) != expected_len:
raise ValueError('Some part of the path is not expected length. Passed part '
if (part_len := len(path_part)) != expected_len:
raise ValueError('Path is not expected length. Passed path part '
f"'{path_part}' doesn't match format '{fmt_part}'")
for lookup in lookup_info:
match lookup.type:
case self.INT:
parsed_arg_parts[lookup.key] = int(path_part[lookup.start:lookup.end])
case self.FLOAT:
parsed_arg_parts[lookup.key] = float(path_part[lookup.start:lookup.end])
case self.STR:
parsed_arg_parts[lookup.key] = path_part[lookup.start:lookup.end]

if not (0 <= lookup.start <= part_len and 0 <= lookup.end <= part_len):
raise ValueError('Parse indices are out of range for path')
try:
match lookup.type:
case self.INT:
parsed_arg_parts[lookup.key] = int(path_part[lookup.start:lookup.end])
case self.FLOAT:
parsed_arg_parts[lookup.key] = float(path_part[lookup.start:lookup.end])
case self.STR:
parsed_arg_parts[lookup.key] = path_part[lookup.start:lookup.end]
except ValueError:
arg_str = path_part[lookup.start:lookup.end]
error_str = {self.INT: f"int('{arg_str}')",
self.FLOAT: f"float('{arg_str}')"}[lookup.type]
raise ValueError(f'Unable to apply formatting: {error_str}')
return parsed_arg_parts

def _apply_format(self, fmt_str: str, **kwargs) -> str:
Expand Down
10 changes: 4 additions & 6 deletions python/idsse_common/idsse/common/rabbitmq_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def __init__(
self._consumer_tags.append(
self.channel.basic_consume(queue.name,
partial(self._on_message, func=func),
# RMQ requires auto_ack=True to consume from Direct Reply-to
# RMQ requires auto_ack=True for Direct Reply-to
auto_ack=queue.name == DIRECT_REPLY_QUEUE)
)

Expand Down Expand Up @@ -221,7 +221,7 @@ def __init__(
'x-message-ttl': 10 * 1000})

_setup_exch_and_queue(self.channel, self._exch, self._queue)
elif self._exch.name != '': # if using default exchange, skip declaring (not allowed by RMQ)
elif self._exch.name != '': # if using default exchange, skip declare (not allowed by RMQ)
_setup_exch(self.channel, self._exch)

if self._exch.delivery_conf:
Expand Down Expand Up @@ -560,8 +560,6 @@ def threadsafe_nack(
threadsafe_call(channel, lambda: channel.basic_nack(delivery_tag, requeue=requeue))




def _initialize_exchange_and_queue(channel: Channel, params: RabbitMqParams) -> str:
"""Declare and bind RabbitMQ exchange and queue using the provided channel.
Expand Down Expand Up @@ -634,7 +632,7 @@ def _setup_exch_and_queue(channel: Channel, exch: Exch, queue: Queue):
queue.arguments['x-queue-type'] == 'quorum' and queue.auto_delete:
raise ValueError('Quorum queues can not be configured to auto delete')

if exch.name != '': # if using default exchange, skip declaring (not allowed by RMQ)
if exch.name != '': # if using default exchange, skip declaring (not allowed by RMQ)
_setup_exch(channel, exch)

if queue.name == DIRECT_REPLY_QUEUE:
Expand All @@ -652,7 +650,7 @@ def _setup_exch_and_queue(channel: Channel, exch: Exch, queue: Queue):
queue_name = result.method.queue
logger.debug('Declared queue: %s', queue_name)

if exch.name != '': # if using default exchange, skip binding queues (not allowed by RMQ)
if exch.name != '': # if using default exchange, skip binding queues (not allowed by RMQ)
if isinstance(queue.route_key, list):
for route_key in queue.route_key:
channel.queue_bind(
Expand Down

0 comments on commit e698e9d

Please sign in to comment.