From cc3beb1b3469c99fdaf9335e3c7b262a34605f72 Mon Sep 17 00:00:00 2001 From: Julio Biason Date: Sat, 9 Jan 2010 17:33:28 -0200 Subject: [PATCH] network layer now have asserts --- mitterlib/network/__init__.py | 10 ++++++++-- mitterlib/network/twitter.py | 6 ++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/mitterlib/network/__init__.py b/mitterlib/network/__init__.py index 5ae18a3..fe79727 100644 --- a/mitterlib/network/__init__.py +++ b/mitterlib/network/__init__.py @@ -172,16 +172,19 @@ class Networks(object): def reply_prefix(self, message): """Return the prefix to be used in the reply for that message.""" + assert(isinstance(message, NetworkData)) return self.networks[message.network].reply_prefix(message) def repost(self, message): """Repost a message in the user's timeline. The network used is the same in the message.""" + assert(isinstance(message, NetworkData)) self.networks[message.network].repost(message) return def favourite(self, message): """Change the favourite status of the message.""" + assert(isinstance(message, NetworkData)) self.networks[message.network].favourite(message) return @@ -208,6 +211,7 @@ class Networks(object): def link(self, message): """Returns a link directly to the message.""" + assert(isinstance(message, NetworkData)) return self.networks[message.network].link(message) def replies(self, network=None): @@ -231,21 +235,23 @@ class Networks(object): def can_delete(self, message): """Return True if the message can be deleted; False otherwise.""" + assert(isinstance(message, NetworkData)) return self.networks[message.network].can_delete(message) def can_reply(self, message): """Return True if the message can be replied; False otherwise.""" + assert(isinstance(message, NetworkData)) return self.networks[message.network].can_reply(message) def can_repost(self, message): """Return True if the message can be resposted; False otherwise.""" + assert(isinstance(message, NetworkData)) return self.networks[message.network].can_repost(message) def can_favourite(self, message): """Return True if the message can be favourited/unfavourited; False otherwise.""" + assert(isinstance(message, NetworkData)) return self.networks[message.network].can_favourite(message) # TODO: Function to return a regexp for usernames - # TODO: Function to return a pre-message for replies (how to handle - # dynamic content, like usernames?) diff --git a/mitterlib/network/twitter.py b/mitterlib/network/twitter.py index ed14989..f9784d7 100644 --- a/mitterlib/network/twitter.py +++ b/mitterlib/network/twitter.py @@ -431,11 +431,13 @@ class Connection(NetworkBase): def link(self, message): """Return a link directly to the message.""" + assert(isinstance(message, NetworkData)) return 'http://twitter.com/%s/status/%s' % (message.username, message.id) def reply_prefix(self, message): """Returns the prefix needed for a reply.""" + assert(isinstance(message, NetworkData)) return '@' + message.username + ' ' def replies(self): @@ -492,6 +494,7 @@ class Connection(NetworkBase): def repost(self, message): """Repost a message.""" + assert(isinstance(message, NetworkData)) body = urllib.urlencode({'id': message.id}) resource = '/statuses/retweet/%d.json' % (message.id) data = self._request(resource, body=body) @@ -499,6 +502,7 @@ class Connection(NetworkBase): def favourite(self, message): """Mark a message as favourite.""" + assert(isinstance(message, NetworkData)) body = urllib.urlencode({'id': message.id}) if not message.favourite: resource = '/favorites/create/%d.json' % (message.id) @@ -522,6 +526,7 @@ class Connection(NetworkBase): def can_delete(self, message): """Check if the message belongs to the user. If so, returns True; False otherwise.""" + assert(isinstance(message, NetworkData)) return (message.username == self._options[self.NAMESPACE]['username']) def can_reply(self, message): @@ -531,6 +536,7 @@ class Connection(NetworkBase): def can_repost(self, message): """Twitter ignores retweets from the user.""" + assert(isinstance(message, NetworkData)) return not (message.username == self._options[self.NAMESPACE]['username'])