Skip to content

Commit

Permalink
fixes in hub.py
Browse files Browse the repository at this point in the history
  • Loading branch information
semiversus committed Jun 8, 2018
1 parent b80c96f commit 3ca15b1
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions broqer/hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def assign(self, topic_str: str, publisher: Publisher,
topic._subject = publisher

if len(topic._subscriptions):
topic._subject.subscribe(topic)
publisher.subscribe(topic)

if meta:
topic.meta = meta
Expand All @@ -212,8 +212,9 @@ def assign(self, topic_str: str, publisher: Publisher,

return topic


class SubHub:
def __init__(self, hub: Hub, prefix: str):
def __init__(self, hub: Hub, prefix: str) -> None:
self._hub = hub
assert not prefix.endswith('.'), 'Prefix should not end with \'.\''
assert prefix, 'Prefix should not be empty'
Expand All @@ -226,24 +227,25 @@ def __contains__(self, topic: str) -> bool:
return self._prefix + topic in self._hub

def __iter__(self):
l = len(self._prefix)
return (t[l:] for t in self._hub if t.startswith(self._prefix))
length = len(self._prefix)
return (t[length:] for t in self._hub if t.startswith(self._prefix))

@property
def topics(self):
l = len(self._prefix)
topics = ((n[l:], t) for (n, t) in self._hub.topics.items()
length = len(self._prefix)
topics = ((n[length:], t) for (n, t) in self._hub.topics.items()
if n.startswith(self._prefix))
return MappingProxyType(OrderedDict(topics))

@property
def unassigned_topics(self):
l = len(self._prefix)
topics = ((n[l:], t) for (n, t) in self._hub.unassigned_topics.items()
length = len(self._prefix)
topics = ((n[length:], t) for (n, t)
in self._hub.unassigned_topics.items()
if n.startswith(self._prefix))
return MappingProxyType(OrderedDict(topics))

def assign(self, topic_str: str, publisher: Publisher,
meta: Optional[dict]=None) -> Topic:

return self._hub.assign(self._prefix + topic_str, publisher, meta)
return self._hub.assign(self._prefix + topic_str, publisher, meta)

0 comments on commit 3ca15b1

Please sign in to comment.