X-Git-Url: https://vcs.maemo.org/git/?a=blobdiff_plain;f=dbuscron%2Fparser.py;h=6937e149273551c1e70eee0b1c2a08e97d0dd2fe;hb=4801eafb397f98ed34b37324f31d706bd95d06e4;hp=8610f795f854725d671099868171d04530d29c79;hpb=67e562e2f387334d24fac85e2d2141e02bf59820;p=dbuscron diff --git a/dbuscron/parser.py b/dbuscron/parser.py index 8610f79..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: @@ -107,7 +117,7 @@ class CrontabParser(object): ruled = dict() for i, f in enumerate(self.__fields): - if self.__fields_chk[f]: + if r[i] is not None and self.__fields_chk[f]: if isinstance(self.__fields_chk[f], tuple): if r[i] not in self.__fields_chk[f]: raise CrontabParserError('Unexpected %s value' % (f.strip('_')), lineno,