fixed transparent background of popups

fixed popup border image location
fixed charset encoding issues
This commit is contained in:
lars 2011-03-09 00:01:15 +00:00
parent 38b7268e27
commit 039c5947a5
3 changed files with 41 additions and 38 deletions

View file

@ -83,7 +83,6 @@ ICON_SIZES = {
}
# used for "html_escape" below
HTML_ESCAPE_TABLE = {
"&": "&",
'"': """,
@ -104,17 +103,12 @@ TIME_OFFSET_HOURS = {
}
def htmlentitydecode(s):
# convert html enitities to unicode (taken from: http://wiki.python.org/moin/EscapingHtml)
return re.sub('&(%s);' % '|'.join(htmlentitydefs.name2codepoint),
lambda m: unichr(htmlentitydefs.name2codepoint[m.group(1)]), s)
def htmlentityencode(s):
# convert unicode to html enitities (taken from: http://wiki.python.org/moin/EscapingHtml)
def html_escape(s):
result = []
for char in s:
if ord(char) > 127:
if char in HTML_ESCAPE_TABLE:
result.append(HTML_ESCAPE_TABLE[char])
elif ord(char) > 127:
result.append("&#%d;" % ord(char))
else:
result.append(char)
@ -202,7 +196,7 @@ class EventParser(HTMLParser.HTMLParser, object):
pass
elif self.current_attribute == COLUMNS['title']:
# maybe the title is splitted by an ampersand entity
event['title'] = event.get('title', '') + htmlentityencode(data)
event['title'] = event.get('title', '') + html_escape(data)
elif self.current_attribute == COLUMNS['time']:
if event.has_key("time"):
# the first "time" field is the start
@ -223,13 +217,13 @@ class EventParser(HTMLParser.HTMLParser, object):
elif self.current_attribute == COLUMNS['category']:
event['category'] = data.strip()
elif self.current_attribute == COLUMNS['place']:
event['place'] = event.get('place', '') + htmlentityencode(data)
event['place'] = event.get('place', '') + html_escape(data)
elif self.current_attribute == COLUMNS['latitude']:
event['latitude'] = data.strip()
elif self.current_attribute == COLUMNS['longitude']:
event['longitude'] = data.strip()
elif self.current_attribute == COLUMNS['organizer']:
event['organizer'] = event.get('organizer', '') + htmlentityencode(data)
event['organizer'] = event.get('organizer', '') + html_escape(data)
else:
sys.stderr.write("UNKNOWN ATTRIBUTE: %d (%s)\n" % (self.current_attribute, data.encode(INPUT_ENCODING)))
@ -268,15 +262,7 @@ def get_date_string(timestamp):
sys.stderr.write("Locales (%s) not found: %s\n" % (LOCALE, err_msg) \
+ " Maybe you should run 'aptitude install locales-all' on debian.\n")
localtime = time.localtime(timestamp)
return htmlentityencode(time.strftime(locale.nl_langinfo(locale.D_T_FMT), localtime))
def html_escape(text):
"""Produce entities within text."""
chars = []
for c in text:
chars.append(HTML_ESCAPE_TABLE.get(c, c))
return "".join(chars)
return html_escape(time.strftime(locale.nl_langinfo(locale.D_T_FMT), localtime))
def get_data_from_html(html):
@ -353,10 +339,6 @@ def get_gml_from_data(data):
for place in group_sorted_events_by_location(data):
result.append([])
event = place[0]
# escape some html entities
for item in ["title", "place", "organizer"]:
if event.has_key(item):
event[item] = html_escape(event[item])
items = result[-1]
# the 'point'
items.append('%(latitude)s,%(longitude)s' % event)
@ -381,8 +363,8 @@ def get_gml_from_data(data):
description += '<li style="list-style-image:url(%s)">' \
% get_icon_url(other_event["category"], None)
description += '%s: <a href="%s" title="Details" target="_blank">%s</a></li>' \
% (html_escape(get_date_string(other_event["time"]).decode(DATE_ENCODING)),
other_event["event_url"], html_escape(other_event["title"]))
% (get_date_string(other_event["time"]).decode(DATE_ENCODING),
other_event["event_url"], other_event["title"])
description += '</ul></li>'
description += '</ul>'
items.append(description)