Skip to content

Commit

Permalink
Escape special chars before strip plus tags. Do not recompile regex e…
Browse files Browse the repository at this point in the history
…very time remove method is used
  • Loading branch information
Jose Rostagno committed Jul 26, 2011
1 parent e2face9 commit a8bc40a
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions emesene/gui/base/Plus.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@

open_tag_re = re.compile('''(.*?)\[\$?(/?)(\w+)(\=(\#?[0-9a-f]+))?\]''', re.IGNORECASE)

#regex used to remove plus markup
tag_plus_strip_re = re.compile('(\[\w(\=\d+)?\])|(\[\w\=\w+\])|(\[\/\w+(\=\d+)?\])')
tag_plus_old_strip_re = re.compile('\·(\&|\@|\#|0)|\·\$(\d+|\#\w+)?(\,(\d+|\#\w+))?')

def parse_emotes(markup):
'''search for emotes on markup and return a list of items with chunks of
test and Emote instances'''
Expand Down Expand Up @@ -293,12 +297,21 @@ def msnplus_strip(msnplus, useless_arg=None):
@param useless_arg This is actually useless, and is mantained just for
compatibility with msnplus
'''
tag_re = re.compile('(\[\w(\=\d+)?\])|(\[\w\=\w+\])|(\[\/\w+(\=\d+)?\])')
tag_plus_old = re.compile('\·(\&|\@|\#|0)|\·\$(\d+|\#\w+)?(\,(\d+|\#\w+))?')
res = tag_re.sub('', msnplus)
res = tag_plus_old.sub('', res)
res = res.replace("no-more-color",'')
return res
#escape special chars
msnplus = msnplus.replace ('\xc2\xb7&','\xc2\xb7&')
msnplus = msnplus.replace('\xc2\xb7"','\xc2\xb7"')
msnplus = msnplus.replace('\xc2\xb7'','\xc2\xb7\'')

msnplus = tag_plus_strip_re.sub('', msnplus)
msnplus = tag_plus_old_strip_re.sub('', msnplus)
msnplus = msnplus.replace("no-more-color",'')

#unescape special chars
msnplus = msnplus.replace('\xc2\xb7&','\xc2\xb7&')
msnplus = msnplus.replace('\xc2\xb7"','\xc2\xb7"')
msnplus = msnplus.replace('\xc2\xb7\'','\xc2\xb7'')

return msnplus

################################################################################
# WARNING: Good ol' emesene1 code from mohrtutchy, roger et. al.
Expand Down

0 comments on commit a8bc40a

Please sign in to comment.