From de71292821e4f11565b16e7a32c0f370c5ba43d2 Mon Sep 17 00:00:00 2001 From: Konstantin Stepanov Date: Tue, 21 Dec 2010 11:20:18 +0200 Subject: [PATCH] support \uXXXX as well as \xXX in args field --- dbuscron/parser.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/dbuscron/parser.py b/dbuscron/parser.py index 2365423..6937e14 100644 --- a/dbuscron/parser.py +++ b/dbuscron/parser.py @@ -3,12 +3,22 @@ from __future__ import with_statement import re from dbuscron.bus import DbusBus -def unescape(value): - if not value or r'\x' not in value: - return value - - r = re.compile(r'\\x([0-9A-Fa-f]{2})') - return r.sub(lambda m: chr(int(m.group(1), 16)), value) +def unescape_(): + h = '[0-9A-Fa-f]' + r = re.compile(r'\\x('+h+r'{2})|\\u('+h+'{4})') + def unescape(value): + if not (value and \ + (r'\x' in value or r'\u' in value)): + return value + + return r.sub(\ + lambda m: chr(int(m.group(1), 16)) \ + if m.group(1) is not None else \ + unichr(int(m.group(2), 16))\ + .encode('utf-8'),\ + value) + return unescape +unescape = unescape_() def product(*args): if args: -- 1.7.9.5