diff options
author | keis <keijser@gmail.com> | 2011-01-23 21:57:16 +0100 |
---|---|---|
committer | keis <keijser@gmail.com> | 2011-02-15 21:17:16 +0100 |
commit | 3594f35e565ebf210b583bcc3c4df042e0dc4191 (patch) | |
tree | 614eab8b78bc09cc16a642783064ae119ee573c9 /examples/data/plugins/config.py | |
parent | bed2433630f6d0d78e8b829c46b00c3ab301b512 (diff) |
move common function related to escaping to Plugin
Diffstat (limited to 'examples/data/plugins/config.py')
-rw-r--r-- | examples/data/plugins/config.py | 14 |
1 files changed, 3 insertions, 11 deletions
diff --git a/examples/data/plugins/config.py b/examples/data/plugins/config.py index dde4ae1..b7ecf42 100644 --- a/examples/data/plugins/config.py +++ b/examples/data/plugins/config.py @@ -2,17 +2,7 @@ from re import compile from types import BooleanType from UserDict import DictMixin -_unquote = compile("'(.*?)'|\"(.*?)\"") -def unquote(s): - m = _unquote.match(s) - if m is not None: - return unicode(m.group(1)).decode('string_escape') - return unicode(s).decode('string_escape') - - valid_key = compile('^[A-Za-z0-9_\.]+$').match -types = {'int': int, 'float': float, 'str': unquote} -escape = lambda s: unicode(s).replace('\n', '\\n') class Config(DictMixin): def __init__(self, uzbl): @@ -57,7 +47,7 @@ class Config(DictMixin): value = int(value) else: - value = escape(value) + value = value.encode('unicode_escape') if not force and key in self and self[key] == value: return @@ -90,6 +80,8 @@ def parse_set_event(uzbl, args): # plugin init hook def init(uzbl): + global types + types = {'int': int, 'float': float, 'str': unquote} export(uzbl, 'config', Config(uzbl)) connect(uzbl, 'VARIABLE_SET', parse_set_event) |