diff options
author | Florian Bruhin <me@the-compiler.org> | 2020-12-22 12:38:06 +0100 |
---|---|---|
committer | Florian Bruhin <me@the-compiler.org> | 2020-12-22 12:38:06 +0100 |
commit | b7d1c4079d2e9d7f63830dd2bd760054839a9f50 (patch) | |
tree | 0dc49e904529efff456ab0a00a40975abbb05e28 | |
parent | ae8d6e0800a6ea343f982f123be61873699391e4 (diff) | |
download | qutebrowser-b7d1c4079d2e9d7f63830dd2bd760054839a9f50.tar.gz qutebrowser-b7d1c4079d2e9d7f63830dd2bd760054839a9f50.zip |
Simplify and fix lint
-rwxr-xr-x | misc/userscripts/qute-lastpass | 17 | ||||
-rw-r--r-- | tests/unit/misc/userscripts/test_qute_lastpass.py | 3 |
2 files changed, 10 insertions, 10 deletions
diff --git a/misc/userscripts/qute-lastpass b/misc/userscripts/qute-lastpass index e71630792..c92505600 100755 --- a/misc/userscripts/qute-lastpass +++ b/misc/userscripts/qute-lastpass @@ -102,15 +102,14 @@ def dmenu(items, invocation, encoding): def fake_key_raw(text): - sequence = '' - - for character in text: - # Escape all characters by default, space, '<' and '>' requires special handling - sequence += ('" "' if character == ' ' else - '<less>' if character == '<' else - '<greater>' if character == '>' else - '\\{}'.format(character)) - qute_command('fake-key {}'.format(sequence)) + # Escape all characters by default, space, '<' and '>' requires special handling + special_escapes = { + ' ': '" "', + '<': '<less>', + '>': '<greater>', + } + sequence = ''.join([special_escapes.get(c, '\\{}'.format(c)) for c in text]) + qute_command(f'fake-key {sequence}') def main(arguments): diff --git a/tests/unit/misc/userscripts/test_qute_lastpass.py b/tests/unit/misc/userscripts/test_qute_lastpass.py index 7b5f35ace..229fcf09e 100644 --- a/tests/unit/misc/userscripts/test_qute_lastpass.py +++ b/tests/unit/misc/userscripts/test_qute_lastpass.py @@ -85,7 +85,8 @@ class TestQuteLastPassComponents: qute_lastpass.fake_key_raw('john.<<doe>>@example.com ') qutecommand_mock.assert_called_once_with( - 'fake-key \\j\\o\\h\\n\\.<less><less>\\d\\o\\e<greater><greater>\\@\\e\\x\\a\\m\\p\\l\\e\\.\\c\\o\\m" "' + 'fake-key \\j\\o\\h\\n\\.<less><less>\\d\\o\\e<greater><greater>\\@' + '\\e\\x\\a\\m\\p\\l\\e\\.\\c\\o\\m" "' ) def test_dmenu(self, subprocess_mock): |