From 713c9bb02b9bab9956f8e5439a0d47e7dedfaf24 Mon Sep 17 00:00:00 2001 From: keis Date: Sat, 15 Jan 2011 22:16:42 +0100 Subject: grok quoted strings in a select places in the em --- examples/data/plugins/config.py | 10 +++++++++- examples/data/plugins/cookies.py | 11 +++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) (limited to 'examples/data/plugins') diff --git a/examples/data/plugins/config.py b/examples/data/plugins/config.py index ed2d761..dde4ae1 100644 --- a/examples/data/plugins/config.py +++ b/examples/data/plugins/config.py @@ -2,8 +2,16 @@ 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': unicode} +types = {'int': int, 'float': float, 'str': unquote} escape = lambda s: unicode(s).replace('\n', '\\n') class Config(DictMixin): diff --git a/examples/data/plugins/cookies.py b/examples/data/plugins/cookies.py index 6ee8798..05a8901 100644 --- a/examples/data/plugins/cookies.py +++ b/examples/data/plugins/cookies.py @@ -7,9 +7,16 @@ import os, re # these are symbolic names for the components of the cookie tuple symbolic = {'domain': 0, 'path':1, 'name':2, 'value':3, 'scheme':4, 'expires':5} -_splitquoted = re.compile("( |\\\".*?\\\"|'.*?')") +_unquote = re.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') + +_splitquoted = re.compile("( |\"(?:\\\\.|[^\"])*?\"|'(?:\\\\.|[^'])*?')") def splitquoted(text): - return [str(p.strip('\'"')) for p in _splitquoted.split(text) if p.strip()] + return [unquote(p) for p in _splitquoted.split(text) if p.strip()] # allows for partial cookies # ? allow wildcard in key -- cgit v1.2.3