Browse Source

sorting fixes; proper escaping of HTML (finally)

master
Julio Biason 16 years ago
parent
commit
285695ac96
  1. 15
      mitterlib/__init__.py
  2. 15
      mitterlib/network/twitter.py
  3. 14
      mitterlib/ui/ui_pygtk.py

15
mitterlib/__init__.py

@ -19,6 +19,7 @@
import os.path
import glob
import htmlentitydefs
def module_search(source, ignore):
"""Search for modules in the source directory. Ignore any modules
@ -37,3 +38,17 @@ def module_search(source, ignore):
# TODO: Maybe this is a good place to test if the module is
# "importable"
yield module_name
def htmlize(text):
"""Convert accented characters to their HTML entities."""
new = []
# XXX: This is not very effective, but Twitter only accepts 140 chars,
# so it won't be a big pain.
for char in text:
if ord(char) in htmlentitydefs.codepoint2name:
new.append('&%s;' % (htmlentitydefs.codepoint2name[ord(char)]))
else:
new.append(char)
return ''.join(new)

15
mitterlib/network/twitter.py

@ -73,19 +73,6 @@ def _unhtml(text):
return result
def _htmlize(text):
"""Convert accented characters to their HTML entities."""
new = []
# XXX: This is not very effective, but Twitter only accepts 140 chars,
# so it won't be a big pain.
for char in text:
if ord(char) in htmlentitydefs.codepoint2name:
new.append('&%s;' % (htmlentitydefs.codepoint2name[ord(char)]))
else:
new.append(char)
return ''.join(new)
def _to_datetime(server_str):
"""Convert a date send by the server to a datetime object.
Ex:
@ -375,7 +362,7 @@ class Connection(NetworkBase):
# accents to HTML entities, so everything falls into ASCII.
body = {
'status': _htmlize(status),
'status': htmlize(status),
'source': 'mitter'}
if reply_to:

14
mitterlib/ui/ui_pygtk.py

@ -29,6 +29,7 @@ import re
import urllib2
from mitterlib.ui.helpers.image_helpers import find_image
from mitterlib import htmlize
from mitterlib.constants import gpl_3, version
#from mitterlib.ui.helpers.utils import str_len
@ -254,7 +255,7 @@ class Interface(object):
# Store NetworkData objects only
grid_store = gtk.ListStore(object)
grid_store.set_sort_column_id(0, gtk.SORT_ASCENDING)
grid_store.set_default_sort_func(self._order_datetime)
grid_store.set_sort_func(0, self._order_datetime)
self._grid = gtk.TreeView(grid_store)
self._grid.set_property('headers-visible', False)
@ -493,10 +494,13 @@ class Interface(object):
message = data.message
username = data.username
#_log.debug('Rendering message: %s', message)
time = timesince.timesince(data.message_time)
# unescape escaped entities that pango is okay with
#message = re.sub(r'&(?!(amp;|gt;|lt;|quot;|apos;))', r'&', message)
# unescape escaped entities that pango is not okay with
message = htmlize(message)
# highlight URLs
mask = r'<span foreground="%s">\1</span>' % (
@ -612,12 +616,12 @@ class Interface(object):
if (not message1) or \
(not message1.message_time) or \
(message1.message_time > message2.message_time):
return 1
return -1
if (not message2) or \
(not message2.message_time) or \
(message2.message_time > message1.message_time):
return -1
return 1
return 0
# ------------------------------------------------------------

Loading…
Cancel
Save