Merge lp:~raoul-snyman/openlp/biblefixes into lp:openlp

Proposed by Raoul Snyman
Status: Merged
Merged at revision: not available
Proposed branch: lp:~raoul-snyman/openlp/biblefixes
Merge into: lp:openlp
Diff against target: None lines
To merge this branch: bzr merge lp:~raoul-snyman/openlp/biblefixes
Reviewer Review Type Date Requested Status
Tim Bentley Approve
Review via email: mp+8345@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Raoul Snyman (raoul-snyman) wrote :

Fixes issues that some of us were having.

Revision history for this message
Tim Bentley (trb143) wrote :

Nice one. Looks much better now!

review: Approve
lp:~raoul-snyman/openlp/biblefixes updated
483. By Tim Bentley

Remove unused stuff
Add more bits to ImageSlideController bar
Clean up ThemeManager
Add OOS saving

484. By Raoul Snyman

Fixed up a few logging things, a few bits of indentation, and resolved some conflicts from the last update.

485. By Raoul Snyman

Merged changes to Bible plugin into trunk.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'openlp/plugins/bibles/lib/common.py'
2--- openlp/plugins/bibles/lib/common.py 2009-06-20 19:11:17 +0000
3+++ openlp/plugins/bibles/lib/common.py 2009-07-07 20:18:36 +0000
4@@ -19,93 +19,140 @@
5 import os.path
6 import sys
7 import urllib2
8-
9+import chardet
10 import logging
11
12 class SearchResults:
13+ """
14+ Encapsulate a set of search results. This is Bible-type independant.
15+ """
16 def __init__(self, book, chapter, verselist):
17+ """
18+ Create the search result object.
19+
20+ ``book``
21+ The book of the Bible.
22+
23+ ``chapter``
24+ The chapter of the book.
25+
26+ ``verselist``
27+ The list of verses for this reading
28+ """
29 self.book = book
30 self.chapter = chapter
31 self.verselist = verselist
32+
33 def get_verselist(self):
34+ """
35+ Returns the list of verses.
36+ """
37 return self.verselist
38+
39 def get_book(self):
40+ """
41+ Returns the book of the Bible.
42+ """
43 return self.book
44+
45 def get_chapter(self):
46+ """
47+ Returns the chapter of the book.
48+ """
49 return self.chapter
50+
51 def has_verselist(self):
52- if self.verselist == {}:
53- return False
54- else:
55- return True
56-
57-class BibleCommon:
58+ """
59+ Returns whether or not the verse list contains verses.
60+ """
61+ return len(self.verselist) > 0
62+
63+
64+class BibleCommon(object):
65+ """
66+ A common ancestor for bible download sites.
67+ """
68 global log
69 log = logging.getLogger(u'BibleCommon')
70 log.info(u'BibleCommon')
71+
72 def __init__(self):
73 """
74+ An empty constructor... not sure why I'm here.
75 """
76+ pass
77+
78 def _get_web_text(self, urlstring, proxyurl):
79+ """
80+ Get the HTML from the web page.
81+
82+ ``urlstring``
83+ The URL of the page to open.
84+
85+ ``proxyurl``
86+ The URL of a proxy server used to access the Internet.
87+ """
88 log.debug(u'get_web_text %s %s', proxyurl, urlstring)
89- if not proxyurl == None:
90- proxy_support = urllib2.ProxyHandler({'http': self.proxyurl})
91+ if proxyurl is not None:
92+ proxy_support = urllib2.ProxyHandler({'http': self.proxyurl})
93 http_support = urllib2.HTTPHandler()
94- opener= urllib2.build_opener(proxy_support, http_support)
95+ opener = urllib2.build_opener(proxy_support, http_support)
96 urllib2.install_opener(opener)
97 xml_string = u''
98 req = urllib2.Request(urlstring)
99- req.add_header(u'User-Agent', 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)')
100+ req.add_header('User-Agent', 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)')
101 try:
102 handle = urllib2.urlopen(req)
103- xml_string = unicode(handle.read())
104+ html = handle.read()
105+ details = chardet.detect(html)
106+ xml_string = unicode(html, details['encoding'])
107 except IOError, e:
108 if hasattr(e, u'reason'):
109- log.error(u'Reason : ')
110- log.error( e.reason)
111+ log.error(u'Reason : %s', e.reason)
112 return xml_string
113
114 def _clean_text(self, text):
115 """
116- Clean up text and remove extra characters
117- after been downloaded from web
118+ Clean up text and remove extra characters after been downloaded from
119+ the Internet.
120+
121+ ``text``
122+ The text from the web page that needs to be cleaned up.
123 """
124 #return text.rstrip()
125 # Remove Headings from the Text
126- i = text.find(u'<h')
127- while i > -1:
128- j=text.find(u'</h', i)
129- text = text[ : (i - 1)]+text[(j+4)]
130- i = text.find(u'<h')
131-
132+ start_tag = text.find(u'<h')
133+ while start_tag > -1:
134+ end_tag = text.find(u'</h', start_tag)
135+ text = text[:(start_tag - 1)] + text[(end_tag + 4)]
136+ start_tag = text.find(u'<h')
137 # Remove Support References from the Text
138- x = text.find(u'<sup>')
139- while x > -1:
140- y = text.find(u'</sup>')
141- text= text[:x] + text[y + 6:len(text)]
142- x = text.find(u'<sup>')
143-
144+ start_tag = text.find(u'<sup>')
145+ while start_tag > -1:
146+ end_tag = text.find(u'</sup>')
147+ text = text[:start_tag] + text[end_tag + 6:len(text)]
148+ start_tag = text.find(u'<sup>')
149 # Static Clean ups
150- text= text.replace(u'\n', u'')
151- text= text.replace(u'\r', u'')
152- text= text.replace(u'&nbsp;', u'')
153- text= text.replace(u'<P>', u'')
154- text= text.replace(u'<I>', u'')
155- text= text.replace(u'</I>', u'')
156- text= text.replace(u'<P />', u'')
157- text= text.replace(u'<p />', u'')
158- text= text.replace(u'</P>', u'')
159- text= text.replace(u'<BR>', u'')
160- text= text.replace(u'<BR />', u'')
161- #text= text.replace(chr(189), u'1/2');print "l"
162- text= text.replace(u'&quot;', "'")
163- text= text.replace(u'&apos;', "'")
164-
165- i = text.find(u'<')
166- while i > -1 :
167- j = text.find(u'>', i)
168- text= text[:i] + text[j+1:]
169- i = text.find(u'<')
170-
171- text= text.replace(u'>', u'')
172+ text = text.replace(u'\n', u'')
173+ text = text.replace(u'\r', u'')
174+ text = text.replace(u'&nbsp;', u'')
175+ text = text.replace(u'<P>', u'')
176+ text = text.replace(u'<I>', u'')
177+ text = text.replace(u'</I>', u'')
178+ text = text.replace(u'<P />', u'')
179+ text = text.replace(u'<p />', u'')
180+ text = text.replace(u'</P>', u'')
181+ text = text.replace(u'<BR>', u'')
182+ text = text.replace(u'<BR />', u'')
183+ #text = text.replace(chr(189), u'1/2');print "l"
184+ text = text.replace(u'&quot;', u'\"')
185+ text = text.replace(u'&apos;', u'\'')
186+ # Remove some other tags
187+ start_tag = text.find(u'<')
188+ while start_tag > -1 :
189+ end_tag = text.find(u'>', start_tag)
190+ text = text[:start_tag] + text[end_tag + 1:]
191+ start_tag = text.find(u'<')
192+ text = text.replace(u'>', u'')
193 return text.rstrip()
194+