Merge lp:~stefanor/ibid/url-memory-454768 into lp:~ibid-core/ibid/old-trunk-pack-0.92

Proposed by Stefano Rivera
Status: Merged
Approved by: Stefano Rivera
Approved revision: 762
Merged at revision: 762
Proposed branch: lp:~stefanor/ibid/url-memory-454768
Merge into: lp:~ibid-core/ibid/old-trunk-pack-0.92
Diff against target: 66 lines
2 files modified
ibid/plugins/url.py (+9/-3)
ibid/utils.py (+8/-0)
To merge this branch: bzr merge lp:~stefanor/ibid/url-memory-454768
Reviewer Review Type Date Requested Status
Michael Gorven Approve
Jonathan Hitchcock Approve
Review via email: mp+13539@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Michael Gorven (mgorven) wrote :

On Sunday 18 October 2009 18:55:20 Stefano Rivera wrote:
> +class ContetTypeException(Exception):

Er, is there a reason that's "contet" and not "content"?

lp:~stefanor/ibid/url-memory-454768 updated
762. By Stefano Rivera

Typo

Revision history for this message
Stefano Rivera (stefanor) wrote :

> Er, is there a reason that's "contet" and not "content"?

Twice?! Grrr.

Fixed

Revision history for this message
Jonathan Hitchcock (vhata) :
review: Approve
Revision history for this message
Michael Gorven (mgorven) wrote :

 review approve

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ibid/plugins/url.py'
2--- ibid/plugins/url.py 2009-09-02 06:43:05 +0000
3+++ ibid/plugins/url.py 2009-10-19 08:24:13 +0000
4@@ -1,7 +1,8 @@
5 from datetime import datetime
6 from httplib import BadStatusLine
7 from urllib import urlencode
8-from urllib2 import urlopen, HTTPRedirectHandler, build_opener, HTTPError, HTTPBasicAuthHandler, install_opener
9+from urllib2 import urlopen, HTTPRedirectHandler, build_opener, HTTPError, \
10+ HTTPBasicAuthHandler, install_opener
11 import logging
12 import re
13
14@@ -44,7 +45,10 @@
15 "Posts a URL to delicious.com"
16
17 date = datetime.utcnow()
18- title = self._get_title(url)
19+ try:
20+ title = self._get_title(url)
21+ except HTTPError:
22+ return
23
24 con_re = re.compile(r'!n=|!')
25 connection_body = con_re.split(event.sender['connection'])
26@@ -74,7 +78,7 @@
27 'extended' : event.message['raw'],
28 }
29
30- self._set_auth(username,password)
31+ self._set_auth(username, password)
32 posturl = 'https://api.del.icio.us/v1/posts/add?' + urlencode(data, 'utf-8')
33
34 try:
35@@ -94,6 +98,8 @@
36 etree = get_html_parse_tree(url, None, headers, 'etree')
37 title = etree.findtext('head/title')
38 return title
39+ except HTTPError, e:
40+ raise
41 except Exception, e:
42 log.debug(u"Error determining title for %s: %s", url, unicode(e))
43 return url
44
45=== modified file 'ibid/utils.py'
46--- ibid/utils.py 2009-10-16 16:31:34 +0000
47+++ ibid/utils.py 2009-10-19 08:24:13 +0000
48@@ -166,11 +166,19 @@
49
50 return unicode(timestamp.strftime(format.encode('utf8')), 'utf8')
51
52+class ContentTypeException(Exception):
53+ pass
54+
55 def get_html_parse_tree(url, data=None, headers={}, treetype='beautifulsoup'):
56 "Request a URL, parse with html5lib, and return a parse tree from it"
57
58 req = urllib2.Request(url, data, headers)
59 f = urllib2.urlopen(req)
60+
61+ if f.info().gettype() not in ('text/html', 'application/xhtml+xml'):
62+ f.close()
63+ raise ContentTypeException("Content type isn't HTML, but " + f.info().gettype())
64+
65 data = f.read()
66 f.close()
67

Subscribers

People subscribed via source and target branches