From: Ivan Frade Date: Thu, 20 Aug 2009 22:46:59 +0000 (+0300) Subject: Common code to a utils file X-Git-Tag: mussorgsky-0.2-1~16 X-Git-Url: http://vcs.maemo.org/git/?a=commitdiff_plain;h=4c3295473a8efac4bbe6790ad5fc4ad6760d14dc;p=mussorgsky Common code to a utils file escape_html function is needed when printing in markup --- diff --git a/setup.py b/setup.py index 7bb3298..6f05f3b 100644 --- a/setup.py +++ b/setup.py @@ -17,7 +17,8 @@ DATA = [('share/applications/hildon', ['data/mussorgsky.desktop']), 'src/mussorgsky.py', 'src/mutagen_backend.py', 'src/player_backend.py', - 'src/tracker_backend.py'])] + 'src/tracker_backend.py', + 'src/utils.py'])] setup(name = 'mussorgsky', version = '0.1', diff --git a/src/utils.py b/src/utils.py new file mode 100644 index 0000000..ed01048 --- /dev/null +++ b/src/utils.py @@ -0,0 +1,8 @@ +def escape_html (text, max_length=40): + if (len (text) > max_length): + cutpoint = text.find (' ', max_length-10) + if (cutpoint == -1 or cutpoint > max_length): + cutpoint = max_length + text = text [0:cutpoint] + "..." + return text.replace ("&","&").replace ("<", "<").replace (">", ">").replace ("\"", """) +