~ubuntu-branches/ubuntu/oneiric/gwibber/oneiric

« back to all changes in this revision

Viewing changes to gwibber/microblog/plugins/twitter/__init__.py

  • Committer: Bazaar Package Importer
  • Author(s): Ken VanDine
  • Date: 2011-08-23 11:49:50 UTC
  • mfrom: (1.1.58 upstream)
  • Revision ID: james.westby@ubuntu.com-20110823114950-b4pnf3dlihf3okfk
Tags: 3.1.5.1-0ubuntu1
* New upstream release
  - tile sizing fixes, getting rid of wasted space
  - revert back to python-wnck, we can't mix GIR and static 
    bindings (LP: #829186)
  - use subprocess instead of Gio for handling gsettings.  We can't mix GIR 
    and static bindings (LP: #829186)
  - Fixes escaping of html elements properly (LP: #825204)
  - Fixed data type checks that were causing failures (LP: #830839)
  - Make sure we get time from the right json object
  - Lots of json warnings and criticals cleaned up
  - Don't crash the service if notifications fail (LP: #727568)
* debian/control
  - Depend on python-wnck instead of gir1.2-wnck-1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
from gwibber.microblog import network, util
2
 
from htmlentitydefs import name2codepoint
3
2
import re
4
3
import gnomekeyring
5
4
from oauth import oauth
58
57
URL_PREFIX = "https://twitter.com"
59
58
API_PREFIX = "https://api.twitter.com/1"
60
59
 
61
 
def unescape(s):
62
 
  return re.sub('&(%s);' % '|'.join(name2codepoint), 
63
 
    lambda m: unichr(name2codepoint[m.group(1)]), s)
64
 
 
65
60
class Client:
66
61
  def __init__(self, acct):
67
62
    self.service = util.getbus("Service")
84
79
      m["account"] = self.account["id"]
85
80
      if data.has_key("created_at"):
86
81
        m["time"] = util.parsetime(data["created_at"])
87
 
      m["text"] = unescape(data["text"])
 
82
      m["text"] = util.unescape(data["text"])
88
83
      m["to_me"] = ("@%s" % self.account["username"]) in data["text"]
89
84
 
90
 
      m["html"] = util.linkify(data["text"],
 
85
      m["html"] = util.linkify(m["text"],
91
86
        ((util.PARSE_HASH, '#<a class="hash" href="%s#search?q=\\1">\\1</a>' % URL_PREFIX),
92
 
        (util.PARSE_NICK, '@<a class="nick" href="%s/\\1">\\1</a>' % URL_PREFIX)), escape=True)
 
87
        (util.PARSE_NICK, '@<a class="nick" href="%s/\\1">\\1</a>' % URL_PREFIX)), escape=False)
93
88
 
94
 
      m["content"] = util.linkify(data["text"],
95
 
        ((util.PARSE_HASH, '#<a class="hash" href="gwibber:/tag?acct=%s&query=\\1">\\1</a>' % m["account"]),
96
 
        (util.PARSE_NICK, '@<a class="nick" href="gwibber:/user?acct=%s&name=\\1">\\1</a>' % m["account"])), escape=True)
 
89
      m["content"] = util.linkify(m["text"],
 
90
        ((util.PARSE_HASH, '#<a href="gwibber:/tag?acct=%s&query=\\1">\\1</a>' % m["account"]),
 
91
        (util.PARSE_NICK, '@<a href="gwibber:/user?acct=%s&name=\\1">\\1</a>' % m["account"])), escape=True)
97
92
 
98
93
      m["favorited"] = data.get("favorited", False)
99
94
 
126
121
    }
127
122
    
128
123
  def _message(self, data):
129
 
    if type(data) == type(None):
130
 
      return []
 
124
    if type(data) != dict:
 
125
      log.logger.error("Cannot parse message data: %s", str(data))
 
126
      return {}
131
127
 
132
128
    n = {}
133
129
    if data.has_key("retweeted_status"):
300
296
    data = network.Download("http://search.twitter.com/search.json", util.compact(args))
301
297
    data = data.get_json()["results"]
302
298
 
 
299
    if type(data) != list:
 
300
      log.logger.error("Cannot parse search data: %s", str(data))
 
301
      return []
 
302
 
303
303
    return [self._result(m) for m in data]
304
304
 
305
305
  def __call__(self, opname, **args):