Browse Source

network layer now have asserts

master
Julio Biason 15 years ago
parent
commit
cc3beb1b34
  1. 10
      mitterlib/network/__init__.py
  2. 6
      mitterlib/network/twitter.py

10
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?)

6
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'])

Loading…
Cancel
Save