From fa6a2cce6ea64fe57b0acee12c130c7e8f975f0e Mon Sep 17 00:00:00 2001 From: Constantine Peresypkin Date: Tue, 25 Mar 2014 14:44:58 +0200 Subject: [PATCH] moved static macros definition from func to module RE_ILLEGAL was redefined each time on has_control_chars() execution there is no need for that --- zerocloud/common.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/zerocloud/common.py b/zerocloud/common.py index bb56478..7d4a5ec 100644 --- a/zerocloud/common.py +++ b/zerocloud/common.py @@ -95,6 +95,13 @@ REPORT_CDR = 4 REPORT_STATUS = 5 +RE_ILLEGAL = u'([\u0000-\u0008\u000b-\u000c\u000e-\u001f\ufffe-\uffff])' + \ + u'|' + \ + u'([%s-%s][^%s-%s])|([^%s-%s][%s-%s])|([%s-%s]$)|(^[%s-%s])' % \ + (unichr(0xd800), unichr(0xdbff), unichr(0xdc00), unichr(0xdfff), + unichr(0xd800), unichr(0xdbff), unichr(0xdc00), unichr(0xdfff), + unichr(0xd800), unichr(0xdbff), unichr(0xdc00), unichr(0xdfff),) + def merge_headers(current, new): if hasattr(new, 'keys'): @@ -113,12 +120,6 @@ def merge_headers(current, new): def has_control_chars(line): if line: - RE_ILLEGAL = u'([\u0000-\u0008\u000b-\u000c\u000e-\u001f\ufffe-\uffff])' + \ - u'|' + \ - u'([%s-%s][^%s-%s])|([^%s-%s][%s-%s])|([%s-%s]$)|(^[%s-%s])' % \ - (unichr(0xd800), unichr(0xdbff), unichr(0xdc00), unichr(0xdfff), - unichr(0xd800), unichr(0xdbff), unichr(0xdc00), unichr(0xdfff), - unichr(0xd800), unichr(0xdbff), unichr(0xdc00), unichr(0xdfff),) if re.search(RE_ILLEGAL, line): return True if re.search(r"[\x01-\x1F\x7F]", line):