Merge lp:~coalwater/lernid/fix-925702 into lp:lernid

Proposed by Mohammad AbuShady
Status: Merged
Merged at revision: 231
Proposed branch: lp:~coalwater/lernid/fix-925702
Merge into: lp:lernid
Diff against target: 32 lines (+11/-10)
1 file modified
lernid/widgets/IrcWidget.py (+11/-10)
To merge this branch: bzr merge lp:~coalwater/lernid/fix-925702
Reviewer Review Type Date Requested Status
John S. Gruber Approve
Review via email: mp+91364@code.launchpad.net

Description of the change

After fixing the bug i also found another bug about the unicode conversion, that's why i added the type test before conversion

To post a comment you must log in.
Revision history for this message
Mohammad AbuShady (coalwater) wrote :

When i think about it i'm not sure if these changes broke the other checks or not

                if self._nick in text and sender != self._nick:
                    self._buffer.insert_with_tags_by_name(iend, text, 'highlight')
                elif self._on_faculty(sender):
                    self._buffer.insert_with_tags_by_name(iend, text, 'highlight')
                elif sender.lower() in self._classbotnames:
                    self._buffer.insert_with_tags_by_name(iend, text, 'italicize')

i think i should test them first

Revision history for this message
John S. Gruber (jsjgruber) wrote :

Yes, please. Testing those would be a good idea.

Can you tell me about the unicode conversion problem you found? Is it worth a bug report?

Revision history for this message
Mohammad AbuShady (coalwater) wrote :

This is the old line of the url matching
for url in re.finditer(r"https?://\S+", unicode(text, 'utf-8')):

in the NativeClassroom.py line 181
http://bazaar.launchpad.net/~lernid-devs/lernid/trunk/view/head:/lernid/widgets/NativeChatroom.py#L181
self._append_to_buffer(_('IRC commands are not yet supported.'))
for some reason lernid sees this text as unicode and when trying to apply the unicode part [unicode(text,'utf-8')] it throws an error, you can easily simulate this error in python console by doing this
  >>> unicode(u'aaa','utf-8')
  Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
  TypeError: decoding Unicode is not supported

when i added a test in the file before the unicode, [print type(text)] it always returned str but in this single case ( the irc command exception message ) it returned type unicode so i simple added the type check to avoid this.

Revision history for this message
John S. Gruber (jsjgruber) wrote :

Looks good to me. Thanks again.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lernid/widgets/IrcWidget.py'
2--- lernid/widgets/IrcWidget.py 2011-08-13 02:05:14 +0000
3+++ lernid/widgets/IrcWidget.py 2012-02-02 22:13:18 +0000
4@@ -77,17 +77,18 @@
5 else:
6 if sender:
7 self._buffer.insert_with_tags_by_name(iend, '<%s> ' % sender, 'gray')
8- start_pos = iend.get_offset()
9- if self._nick in text and sender != self._nick:
10- self._buffer.insert_with_tags_by_name(iend, text, 'highlight')
11- elif self._on_faculty(sender):
12- self._buffer.insert_with_tags_by_name(iend, text, 'highlight')
13- elif sender.lower() in self._classbotnames:
14- self._buffer.insert_with_tags_by_name(iend, text, 'italicize')
15- else:
16- self._buffer.insert(iend, text)
17+ start_pos = iend.get_offset()
18+ if self._nick in text and sender != self._nick:
19+ self._buffer.insert_with_tags_by_name(iend, text, 'highlight')
20+ elif self._on_faculty(sender):
21+ self._buffer.insert_with_tags_by_name(iend, text, 'highlight')
22+ elif sender.lower() in self._classbotnames:
23+ self._buffer.insert_with_tags_by_name(iend, text, 'italicize')
24+ self._buffer.insert(iend, text)
25
26- for url in re.finditer(r"https?://\S+", unicode(text, 'utf-8')):
27+ if type(text)!=unicode:
28+ text=unicode(text, 'utf-8')
29+ for url in re.finditer(r"https?://\S+", text):
30 self._buffer.apply_tag_by_name('hyperlink',
31 self._buffer.get_iter_at_offset(start_pos + url.start()),
32 self._buffer.get_iter_at_offset(start_pos + url.end()))

Subscribers

People subscribed via source and target branches