From 5fab9b5f81ff0d7eeebbd1bf07f4b945e1454165 Mon Sep 17 00:00:00 2001 From: Mason Larobina Date: Wed, 23 Dec 2009 21:15:18 +0800 Subject: Added the escaped and quoted %r replace for on_event and bind args. --- examples/data/uzbl/plugins/bind.py | 10 ++++++++++ examples/data/uzbl/plugins/on_event.py | 11 +++++++++++ 2 files changed, 21 insertions(+) (limited to 'examples') diff --git a/examples/data/uzbl/plugins/bind.py b/examples/data/uzbl/plugins/bind.py index 1cba7b2..668b595 100644 --- a/examples/data/uzbl/plugins/bind.py +++ b/examples/data/uzbl/plugins/bind.py @@ -306,9 +306,19 @@ class Bind(object): def expand(cmd, args): '''Replaces "%s %1 %2 %3..." with " ...".''' + # Direct string replace. if '%s' in cmd: cmd = cmd.replace('%s', ' '.join(map(unicode, args))) + # Escaped and quoted string replace. + if '%r' in cmd: + joined = ('%r' % ' '.join(map(unicode, args)))[1:] + for char in ['\\', '@']: + joined = joined.replace(char, '\\'+char) + + cmd = cmd.replace('%r', joined) + + # Arg index string replace. for (index, arg) in enumerate(args): index += 1 if '%%%d' % index in cmd: diff --git a/examples/data/uzbl/plugins/on_event.py b/examples/data/uzbl/plugins/on_event.py index afee4e6..9d2525b 100644 --- a/examples/data/uzbl/plugins/on_event.py +++ b/examples/data/uzbl/plugins/on_event.py @@ -2,6 +2,7 @@ Formatting options: %s = space separated string of the arguments + %r = escaped and quoted version of %s %1 = argument 1 %2 = argument 2 %n = argument n @@ -47,9 +48,19 @@ def get_on_events(uzbl): def expand(cmd, args): '''Replaces "%s %1 %2 %3..." with " ...".''' + # Direct string replace. if '%s' in cmd: cmd = cmd.replace('%s', ' '.join(map(unicode, args))) + # Escaped and quoted string replace. + if '%r' in cmd: + joined = ('%r' % ' '.join(map(unicode, args)))[1:] + for char in ['\\', '@']: + joined = joined.replace(char, '\\'+char) + + cmd = cmd.replace('%r', joined) + + # Arg index string replace. for (index, arg) in enumerate(args): index += 1 if '%%%d' % index in cmd: -- cgit v1.2.3