Merge lp:~3v1n0/gwibber/failing-messages-loading-fix into lp:gwibber

Proposed by Marco Trevisan (Treviño)
Status: Merged
Merged at revision: 937
Proposed branch: lp:~3v1n0/gwibber/failing-messages-loading-fix
Merge into: lp:gwibber
Diff against target: 116 lines (+40/-37)
2 files modified
gwibber/microblog/dispatcher.py (+34/-31)
gwibber/microblog/plugins/twitter/__init__.py (+6/-6)
To merge this branch: bzr merge lp:~3v1n0/gwibber/failing-messages-loading-fix
Reviewer Review Type Date Requested Status
Ken VanDine Approve
Review via email: mp+43128@code.launchpad.net

Description of the change

Fix bug #645512 (which causes Twitter not to load any message if just one, or a small subset, is failing) plus it includes a fix for not throwing exceptions for a plugin when just one message fails.

To post a comment you must log in.
Revision history for this message
Ken VanDine (ken-vandine) wrote :

Thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'gwibber/microblog/dispatcher.py'
2--- gwibber/microblog/dispatcher.py 2010-11-16 19:02:53 +0000
3+++ gwibber/microblog/dispatcher.py 2010-12-08 20:02:53 +0000
4@@ -56,37 +56,40 @@
5
6 if message_data is not None:
7 for m in message_data:
8- if isinstance(m, dict) and m.has_key("mid"):
9- m["id"] = uuid.uuid1().hex
10- m["operation"] = opname
11- m["stream"] = stream
12- m["transient"] = transient
13- m["rtl"] = util.isRTL(re.sub(text_cleaner, "", m["text"].decode('utf-8')))
14-
15- log.logger.debug("%s Adding record", logtext)
16-
17- new_messages.insert(0, (
18- m["id"],
19- m["mid"],
20- m["account"],
21- account["service"],
22- opname,
23- transient,
24- stream,
25- m["time"],
26- m["text"],
27- m.get("sender", {}).get("is_me", None),
28- m.get("to_me", None),
29- m.get("sender", {}).get("nick", None),
30- m.get("reply", {}).get("nick", None),
31- json.dumps(m)
32- ))
33- elif isinstance(m, dict) and m.has_key("error"):
34- new_messages.insert(0, (
35- "error",
36- json.dumps(m)
37- ))
38-
39+ try:
40+ if isinstance(m, dict) and m.has_key("mid"):
41+ m["id"] = uuid.uuid1().hex
42+ m["operation"] = opname
43+ m["stream"] = stream
44+ m["transient"] = transient
45+ m["rtl"] = util.isRTL(re.sub(text_cleaner, "", m["text"].decode('utf-8')))
46+
47+ log.logger.debug("%s Adding record", logtext)
48+
49+ new_messages.insert(0, (
50+ m["id"],
51+ m["mid"],
52+ m["account"],
53+ account["service"],
54+ opname,
55+ transient,
56+ stream,
57+ m["time"],
58+ m["text"],
59+ m.get("sender", {}).get("is_me", None),
60+ m.get("to_me", None),
61+ m.get("sender", {}).get("nick", None),
62+ m.get("reply", {}).get("nick", None),
63+ json.dumps(m)
64+ ))
65+ elif isinstance(m, dict) and m.has_key("error"):
66+ new_messages.insert(0, (
67+ "error",
68+ json.dumps(m)
69+ ))
70+ except Exception as e:
71+ if not "logtext" in locals(): logtext = "<UNKNOWN>"
72+ log.logger.error("%s Operation failed", logtext)
73
74 log.logger.debug("%s Finished operation", logtext)
75 return ("Success", new_messages)
76
77=== modified file 'gwibber/microblog/plugins/twitter/__init__.py'
78--- gwibber/microblog/plugins/twitter/__init__.py 2010-10-27 20:02:23 +0000
79+++ gwibber/microblog/plugins/twitter/__init__.py 2010-12-08 20:02:53 +0000
80@@ -1,5 +1,6 @@
81 from gwibber.microblog import network, util
82-import htmllib, re
83+from htmlentitydefs import name2codepoint
84+import re
85 import gnomekeyring
86 from oauth import oauth
87 from gwibber.microblog.util import log, exceptions
88@@ -54,10 +55,8 @@
89 API_PREFIX = "https://api.twitter.com/1"
90
91 def unescape(s):
92- p = htmllib.HTMLParser(None)
93- p.save_bgn()
94- p.feed(s)
95- return p.save_end()
96+ return re.sub('&(%s);' % '|'.join(name2codepoint),
97+ lambda m: unichr(name2codepoint[m.group(1)]), s)
98
99 class Client:
100 def __init__(self, acct):
101@@ -73,7 +72,7 @@
102 self.token = oauth.OAuthToken(acct["access_token"], acct["secret_token"])
103
104 def _common(self, data):
105- m = {};
106+ m = {};
107 try:
108 m["mid"] = str(data["id"])
109 m["service"] = "twitter"
110@@ -95,6 +94,7 @@
111 m["images"] = images
112 except:
113 log.logger.error("%s failure - %s", PROTOCOL_INFO["name"], data)
114+ return {}
115
116 return m
117