Skip to content

Commit

Permalink
simplify binding declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
petersilva committed Aug 7, 2024
1 parent 490fb1b commit 07d4892
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions sarracenia/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1337,10 +1337,18 @@ def _resolve_exchange(self):
if hasattr(self, 'exchangeSuffix'):
self.exchange += '_%s' % self.exchangeSuffix

if hasattr(self, 'exchangeSplit') and hasattr(
self, 'no') and (self.no > 0):
if hasattr(self, 'exchangeSplit') and hasattr(self, 'no') and (self.no > 0):
self.exchange += "%02d" % self.no

def _empty_binding(self) -> dict:
new_binding={}
for i in [ 'auto_delete', 'broker', 'durable', 'exchange', 'expire', 'message_ttl', 'prefetch', \
'qos', 'queueBind', 'queueDeclare', 'queueName', 'topicPrefix' ]:
new_binding[i] = getattr(self,i)
return new_binding



def _parse_binding(self, subtopic_string):
"""
FIXME: see original parse, with substitions for url encoding.
Expand All @@ -1365,10 +1373,7 @@ def _parse_binding(self, subtopic_string):
subtopic = subtopic_string.split('/')

if hasattr(self, 'exchange') and hasattr(self, 'topicPrefix'):
new_binding={}
for i in [ 'auto_delete', 'broker', 'durable', 'exchange', 'expire', 'message_ttl', 'prefetch', \
'qos', 'queueBind', 'queueDeclare', 'queueName', 'topicPrefix' ]:
new_binding[i] = getattr(self,i)
new_binding=self._empty_binding()
new_binding['subtopic'] = subtopic

self.bindings.append(new_binding)
Expand Down Expand Up @@ -2445,8 +2450,11 @@ def __call__(self, parser, namespace, values, option_string):
else:
topicPrefix = namespace.topicPrefix.split('/')

namespace.bindings.append(
{'broker':namespace.broker, 'exchange':namespace.exchange, 'topicPrefix':topicPrefix, 'subtopic':values})
new_binding = namespace._empty_binding()
new_binding['topicPrefix'] = topicPrefix
new_binding['subtopic'] = values

namespace.bindings.append( new_binding )

def parse_args(self, isPost=False):
"""
Expand Down

0 comments on commit 07d4892

Please sign in to comment.