mirror of https://github.com/caronc/apprise
CLI --interpret-escapes works without --title specified (#471)
parent
245e57cca9
commit
9b5815ef6e
|
@ -558,22 +558,24 @@ class Apprise(object):
|
||||||
logger.error('Failed to escape message body')
|
logger.error('Failed to escape message body')
|
||||||
raise TypeError
|
raise TypeError
|
||||||
|
|
||||||
try:
|
if title:
|
||||||
# Added overhead required due to Python 3 Encoding Bug
|
try:
|
||||||
# identified here: https://bugs.python.org/issue21331
|
# Added overhead required due to Python 3 Encoding Bug
|
||||||
title = title\
|
# identified here: https://bugs.python.org/issue21331
|
||||||
.encode('ascii', 'backslashreplace')\
|
title = title\
|
||||||
.decode('unicode-escape')
|
.encode('ascii', 'backslashreplace')\
|
||||||
|
.decode('unicode-escape')
|
||||||
|
|
||||||
except UnicodeDecodeError: # pragma: no cover
|
except UnicodeDecodeError: # pragma: no cover
|
||||||
# This occurs using a very old verion of Python 2.7 such
|
# This occurs using a very old verion of Python 2.7
|
||||||
# as the one that ships with CentOS/RedHat 7.x (v2.7.5).
|
# such as the one that ships with CentOS/RedHat 7.x
|
||||||
title = title.decode('string_escape')
|
# (v2.7.5).
|
||||||
|
title = title.decode('string_escape')
|
||||||
|
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
# Must be of string type
|
# Must be of string type
|
||||||
logger.error('Failed to escape message title')
|
logger.error('Failed to escape message title')
|
||||||
raise TypeError
|
raise TypeError
|
||||||
|
|
||||||
yield handler(
|
yield handler(
|
||||||
server,
|
server,
|
||||||
|
|
|
@ -576,6 +576,23 @@ def test_apprise_cli_nux_env(tmpdir):
|
||||||
])
|
])
|
||||||
assert result.exit_code == 1
|
assert result.exit_code == 1
|
||||||
|
|
||||||
|
# Test Escaping:
|
||||||
|
result = runner.invoke(cli.main, [
|
||||||
|
'-e',
|
||||||
|
'-t', 'test\ntitle',
|
||||||
|
'-b', 'test\nbody',
|
||||||
|
'good://localhost',
|
||||||
|
])
|
||||||
|
assert result.exit_code == 0
|
||||||
|
|
||||||
|
# Test Escaping (without title)
|
||||||
|
result = runner.invoke(cli.main, [
|
||||||
|
'--interpret-escapes',
|
||||||
|
'-b', 'test\nbody',
|
||||||
|
'good://localhost',
|
||||||
|
])
|
||||||
|
assert result.exit_code == 0
|
||||||
|
|
||||||
|
|
||||||
@mock.patch('platform.system')
|
@mock.patch('platform.system')
|
||||||
def test_apprise_cli_windows_env(mock_system):
|
def test_apprise_cli_windows_env(mock_system):
|
||||||
|
|
|
@ -191,13 +191,13 @@ def test_apprise_escaping_py3(mock_post):
|
||||||
# the body only. Now we run similar tests but only make the title
|
# the body only. Now we run similar tests but only make the title
|
||||||
# bad and always mark the body good
|
# bad and always mark the body good
|
||||||
assert a.notify(
|
assert a.notify(
|
||||||
title=None, body="valid", interpret_escapes=True) is False
|
title=None, body="valid", interpret_escapes=True) is True
|
||||||
assert a.notify(
|
assert a.notify(
|
||||||
title=4, body="valid", interpret_escapes=True) is False
|
title=4, body="valid", interpret_escapes=True) is False
|
||||||
assert a.notify(
|
assert a.notify(
|
||||||
title=object(), body="valid", interpret_escapes=True) is False
|
title=object(), body="valid", interpret_escapes=True) is False
|
||||||
assert a.notify(
|
assert a.notify(
|
||||||
title=False, body="valid", interpret_escapes=True) is False
|
title=False, body="valid", interpret_escapes=True) is True
|
||||||
assert a.notify(
|
assert a.notify(
|
||||||
title=b'byte title', body="valid", interpret_escapes=True) is False
|
title=b'byte title', body="valid", interpret_escapes=True) is False
|
||||||
|
|
||||||
|
@ -320,10 +320,10 @@ def test_apprise_escaping_py2(mock_post):
|
||||||
# the body only. Now we run similar tests but only make the title
|
# the body only. Now we run similar tests but only make the title
|
||||||
# bad and always mark the body good
|
# bad and always mark the body good
|
||||||
assert a.notify(
|
assert a.notify(
|
||||||
title=None, body="valid", interpret_escapes=True) is False
|
title=None, body="valid", interpret_escapes=True) is True
|
||||||
assert a.notify(
|
assert a.notify(
|
||||||
title=4, body="valid", interpret_escapes=True) is False
|
title=4, body="valid", interpret_escapes=True) is False
|
||||||
assert a.notify(
|
assert a.notify(
|
||||||
title=object(), body="valid", interpret_escapes=True) is False
|
title=object(), body="valid", interpret_escapes=True) is False
|
||||||
assert a.notify(
|
assert a.notify(
|
||||||
title=False, body="valid", interpret_escapes=True) is False
|
title=False, body="valid", interpret_escapes=True) is True
|
||||||
|
|
Loading…
Reference in New Issue