Skip to content

Commit

Permalink
method to get a instance of feed if type is known
Browse files Browse the repository at this point in the history
  • Loading branch information
iuridiniz committed Jul 11, 2012
1 parent cbe0eac commit 32e2ceb
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions txthoonk/client.py
Expand Up @@ -102,6 +102,7 @@ class ThoonkPub(ThoonkBase):

def __init__(self, *args, **kwargs):
self.feed = self._get_feed_type(Feed, type_="feed")
self._types = dict(feed=self.feed)
super(ThoonkPub, self).__init__(*args, **kwargs)

def _get_feed_type(self, kls, type_):
Expand Down Expand Up @@ -136,6 +137,30 @@ def _exists(ret):

return _create_type

def _get_typed_feed(self, feed_name):
"""
Try to discovery a type of a feed and return it as an instance of the
discovered type.
@param feed_name: the name of feed
"""
def _got_error(f):
f.trap(FeedDoesNotExist)
return None

def _got_config(config):
feed_type = config.get("type")
feed_getter = self._types.get(feed_type)
if not feed_getter:
# unknown type
return None
return feed_getter(feed_name)

d = self.get_config(feed_name)
d.addCallback(_got_config)
d.addErrback(_got_error)
return d

def _publish_channel(self, channel, *args):
"""Calls self.publish_channel appending self._uuid at end"""
args = list(args) + [self._uuid]
Expand Down

0 comments on commit 32e2ceb

Please sign in to comment.