mirror of
https://github.com/codex-storage/deluge.git
synced 2025-01-12 20:44:50 +00:00
xml escape notifications sent via libnotify (Closes: #1185)
This commit is contained in:
parent
d6b7917350
commit
412b96ba55
@ -550,6 +550,40 @@ def path_join(*parts):
|
|||||||
path += '/' + part
|
path += '/' + part
|
||||||
return path
|
return path
|
||||||
|
|
||||||
|
XML_ESCAPES = (
|
||||||
|
('&', '&'),
|
||||||
|
('<', '<'),
|
||||||
|
('>', '>'),
|
||||||
|
('"', '"'),
|
||||||
|
("'", ''')
|
||||||
|
)
|
||||||
|
|
||||||
|
def xml_decode(string):
|
||||||
|
"""
|
||||||
|
Unescape a string that was previously encoded for use within xml.
|
||||||
|
|
||||||
|
:param string: The string to escape
|
||||||
|
:type string: string
|
||||||
|
:returns: The unescaped version of the string.
|
||||||
|
:rtype: string
|
||||||
|
"""
|
||||||
|
for char, escape in XML_ESCAPES:
|
||||||
|
string = string.replace(escape, char)
|
||||||
|
return string
|
||||||
|
|
||||||
|
def xml_encode(string):
|
||||||
|
"""
|
||||||
|
Escape a string for use within an xml element or attribute.
|
||||||
|
|
||||||
|
:param string: The string to escape
|
||||||
|
:type string: string
|
||||||
|
:returns: An escaped version of the string.
|
||||||
|
:rtype: string
|
||||||
|
"""
|
||||||
|
for char, escape in XML_ESCAPES:
|
||||||
|
string = string.replace(char, escape)
|
||||||
|
return string
|
||||||
|
|
||||||
class VersionSplit(object):
|
class VersionSplit(object):
|
||||||
"""
|
"""
|
||||||
Used for comparing version numbers.
|
Used for comparing version numbers.
|
||||||
|
@ -74,12 +74,14 @@ class Notification:
|
|||||||
except:
|
except:
|
||||||
log.warning("pynotify is not installed")
|
log.warning("pynotify is not installed")
|
||||||
else:
|
else:
|
||||||
if pynotify.init("Deluge"):
|
if not pynotify.init("Deluge"):
|
||||||
self.note = pynotify.Notification(_("Torrent complete"),
|
return
|
||||||
status["name"] + "\n" + _("Including %i files" % status["num_files"]))
|
title = deluge.common.xml_encode(_("Torrent complete"))
|
||||||
self.note.set_icon_from_pixbuf(common.get_logo(48))
|
message = deluge.common.xml_encode(status["name"] + "\n" + _("Including %i files" % status["num_files"]))
|
||||||
if not self.note.show():
|
self.note = pynotify.Notification(title, message)
|
||||||
log.warning("pynotify failed to show notification")
|
self.note.set_icon_from_pixbuf(common.get_logo(48))
|
||||||
|
if not self.note.show():
|
||||||
|
log.warning("pynotify failed to show notification")
|
||||||
|
|
||||||
def sound(self):
|
def sound(self):
|
||||||
"""plays a sound when a torrent finishes"""
|
"""plays a sound when a torrent finishes"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user