Changeset 55

Show
Ignore:
Timestamp:
12/14/06 20:22:07 (2 years ago)
Author:
verbosus
Message:

Removed htmlescape in favor of cgi.escape (thanks, C8E)

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • hacks/trunk/statusbot/statusbot.py

    r54 r55  
    55 
    66import re 
     7from cgi import escape 
    78import time, sys, codecs 
    89import jabberbot 
     
    1112__svnid__ = "$Id$" 
    1213 
    13 def htmlescape(input): 
    14     return input.replace('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;') 
    15  
    1614def extract_link(input): 
    1715    link_r = re.compile(r'(?P<desc>.*?): (?P<uri>(http://.*)+)') 
     
    1917    if results: 
    2018        return u'<a href="%s">%s</a>' % \ 
    21             (results.group('uri'), htmlescape(results.group('desc'))) 
     19            (results.group('uri'), escape(results.group('desc'))) 
    2220    else: 
    23         return htmlescape(input) 
     21        return escape(input) 
    2422 
    2523def save_status(status): 
    2624    """Write status (a unicode string) to filename (as UTF-8)""" 
    27     template = codecs.open( 
    28         '/path/to/template.html', 'r', 'utf-8') 
     25    template = codecs.open('/path/to/template.html', 'r', 'utf-8') 
    2926    t = template.read() 
    30     f = codecs.open( 
    31         '/path/to/output.html', 'w', 'utf-8') 
     27    f = codecs.open('/path/to/output.html', 'w', 'utf-8') 
    3228    status = extract_link(status) 
    3329    f.write(t.replace(u'{{ status }}', status))