cleanup: '%s' -> %r

This commit is contained in:
Thomas Nagy 2016-04-26 19:35:46 +02:00
parent ba1932ebc2
commit 8b32d93ec3
No known key found for this signature in database
GPG Key ID: 67A565EDFDF90E64
3 changed files with 31 additions and 30 deletions

View File

@ -237,7 +237,7 @@ def get_num(lst):
:return: a pair containing the number and the rest of the list :return: a pair containing the number and the rest of the list
:rtype: tuple(value, list) :rtype: tuple(value, list)
""" """
if not lst: raise PreprocError("empty list for get_num") if not lst: raise PreprocError('empty list for get_num')
(p, v) = lst[0] (p, v) = lst[0]
if p == OP: if p == OP:
if v == '(': if v == '(':
@ -255,7 +255,7 @@ def get_num(lst):
count_par += 1 count_par += 1
i += 1 i += 1
else: else:
raise PreprocError("rparen expected %r" % lst) raise PreprocError('rparen expected %r' % lst)
(num, _) = get_term(lst[1:i]) (num, _) = get_term(lst[1:i])
return (num, lst[i+1:]) return (num, lst[i+1:])
@ -272,14 +272,14 @@ def get_num(lst):
num, lst = get_num(lst[1:]) num, lst = get_num(lst[1:])
return (~ int(num), lst) return (~ int(num), lst)
else: else:
raise PreprocError("Invalid op token %r for get_num" % lst) raise PreprocError('Invalid op token %r for get_num' % lst)
elif p == NUM: elif p == NUM:
return v, lst[1:] return v, lst[1:]
elif p == IDENT: elif p == IDENT:
# all macros should have been replaced, remaining identifiers eval to 0 # all macros should have been replaced, remaining identifiers eval to 0
return 0, lst[1:] return 0, lst[1:]
else: else:
raise PreprocError("Invalid token %r for get_num" % lst) raise PreprocError('Invalid token %r for get_num' % lst)
def get_term(lst): def get_term(lst):
""" """
@ -293,7 +293,7 @@ def get_term(lst):
:rtype: value, list :rtype: value, list
""" """
if not lst: raise PreprocError("empty list for get_term") if not lst: raise PreprocError('empty list for get_term')
num, lst = get_num(lst) num, lst = get_num(lst)
if not lst: if not lst:
return (num, []) return (num, [])
@ -318,7 +318,7 @@ def get_term(lst):
break break
i += 1 i += 1
else: else:
raise PreprocError("rparen expected %r" % lst) raise PreprocError('rparen expected %r' % lst)
if int(num): if int(num):
return get_term(lst[1:i]) return get_term(lst[1:i])
@ -336,7 +336,7 @@ def get_term(lst):
# operator precedence # operator precedence
p2, v2 = lst[0] p2, v2 = lst[0]
if p2 != OP: if p2 != OP:
raise PreprocError("op expected %r" % lst) raise PreprocError('op expected %r' % lst)
if prec[v2] >= prec[v]: if prec[v2] >= prec[v]:
num2 = reduce_nums(num, num2, v) num2 = reduce_nums(num, num2, v)
@ -347,7 +347,7 @@ def get_term(lst):
return get_term([(NUM, num), (p, v), (NUM, num3)] + lst) return get_term([(NUM, num), (p, v), (NUM, num3)] + lst)
raise PreprocError("cannot reduce %r" % lst) raise PreprocError('cannot reduce %r' % lst)
def reduce_eval(lst): def reduce_eval(lst):
""" """
@ -432,7 +432,7 @@ def reduce_tokens(lst, defs, ban=[]):
else: else:
lst[i] = (NUM, 0) lst[i] = (NUM, 0)
else: else:
raise PreprocError("Invalid define expression %r" % lst) raise PreprocError('Invalid define expression %r' % lst)
elif p == IDENT and v in defs: elif p == IDENT and v in defs:
@ -457,11 +457,11 @@ def reduce_tokens(lst, defs, ban=[]):
del lst[i] del lst[i]
if i >= len(lst): if i >= len(lst):
raise PreprocError("expected '(' after %r (got nothing)" % v) raise PreprocError('expected ( after %r (got nothing)' % v)
(p2, v2) = lst[i] (p2, v2) = lst[i]
if p2 != OP or v2 != '(': if p2 != OP or v2 != '(':
raise PreprocError("expected '(' after %r" % v) raise PreprocError('expected ( after %r' % v)
del lst[i] del lst[i]
@ -479,7 +479,7 @@ def reduce_tokens(lst, defs, ban=[]):
if one_param: args.append(one_param) if one_param: args.append(one_param)
break break
elif v2 == ',': elif v2 == ',':
if not one_param: raise PreprocError("empty param in funcall %s" % v) if not one_param: raise PreprocError('empty param in funcall %r' % v)
args.append(one_param) args.append(one_param)
one_param = [] one_param = []
else: else:
@ -580,7 +580,7 @@ def eval_macro(lst, defs):
:rtype: int :rtype: int
""" """
reduce_tokens(lst, defs, []) reduce_tokens(lst, defs, [])
if not lst: raise PreprocError("missing tokens to evaluate") if not lst: raise PreprocError('missing tokens to evaluate')
(p, v) = reduce_eval(lst) (p, v) = reduce_eval(lst)
return int(v) != 0 return int(v) != 0
@ -601,7 +601,7 @@ def extract_macro(txt):
p, name = t[0] p, name = t[0]
p, v = t[1] p, v = t[1]
if p != OP: raise PreprocError("expected open parenthesis") if p != OP: raise PreprocError('expected (')
i = 1 i = 1
pindex = 0 pindex = 0
@ -620,27 +620,27 @@ def extract_macro(txt):
elif p == OP and v == ')': elif p == OP and v == ')':
break break
else: else:
raise PreprocError("unexpected token (3)") raise PreprocError('unexpected token (3)')
elif prev == IDENT: elif prev == IDENT:
if p == OP and v == ',': if p == OP and v == ',':
prev = v prev = v
elif p == OP and v == ')': elif p == OP and v == ')':
break break
else: else:
raise PreprocError("comma or ... expected") raise PreprocError('comma or ... expected')
elif prev == ',': elif prev == ',':
if p == IDENT: if p == IDENT:
params[v] = pindex params[v] = pindex
pindex += 1 pindex += 1
prev = p prev = p
elif p == OP and v == '...': elif p == OP and v == '...':
raise PreprocError("not implemented (1)") raise PreprocError('not implemented (1)')
else: else:
raise PreprocError("comma or ... expected (2)") raise PreprocError('comma or ... expected (2)')
elif prev == '...': elif prev == '...':
raise PreprocError("not implemented (2)") raise PreprocError('not implemented (2)')
else: else:
raise PreprocError("unexpected else") raise PreprocError('unexpected else')
#~ print (name, [params, t[i+1:]]) #~ print (name, [params, t[i+1:]])
return (name, [params, t[i+1:]]) return (name, [params, t[i+1:]])
@ -676,7 +676,7 @@ def extract_include(txt, defs):
reduce_tokens(toks, defs, ['waf_include']) reduce_tokens(toks, defs, ['waf_include'])
if not toks: if not toks:
raise PreprocError("could not parse include %s" % txt) raise PreprocError('could not parse include %r' % txt)
if len(toks) == 1: if len(toks) == 1:
if toks[0][0] == STR: if toks[0][0] == STR:
@ -686,7 +686,7 @@ def extract_include(txt, defs):
ret = '<', stringize(toks).lstrip('<').rstrip('>') ret = '<', stringize(toks).lstrip('<').rstrip('>')
return ret return ret
raise PreprocError("could not parse include %s." % txt) raise PreprocError('could not parse include %r' % txt)
def parse_char(txt): def parse_char(txt):
""" """
@ -698,7 +698,8 @@ def parse_char(txt):
:rtype: string :rtype: string
""" """
if not txt: raise PreprocError("attempted to parse a null char") if not txt:
raise PreprocError('attempted to parse a null char')
if txt[0] != '\\': if txt[0] != '\\':
return ord(txt) return ord(txt)
c = txt[1] c = txt[1]
@ -712,7 +713,7 @@ def parse_char(txt):
return (1+i, int(txt[1:1+i], 8)) return (1+i, int(txt[1:1+i], 8))
else: else:
try: return chr_esc[c] try: return chr_esc[c]
except KeyError: raise PreprocError("could not parse char literal '%s'" % txt) except KeyError: raise PreprocError('could not parse char literal %r' % txt)
def tokenize(s): def tokenize(s):
""" """
@ -902,14 +903,14 @@ class c_parser(object):
self.count_files += 1 self.count_files += 1
if self.count_files > recursion_limit: if self.count_files > recursion_limit:
# issue #812 # issue #812
raise PreprocError("recursion limit exceeded") raise PreprocError('recursion limit exceeded')
if Logs.verbose: if Logs.verbose:
debug('preproc: reading file %r', node) debug('preproc: reading file %r', node)
try: try:
lines = self.parse_lines(node) lines = self.parse_lines(node)
except EnvironmentError: except EnvironmentError:
raise PreprocError("could not read the file %r" % node) raise PreprocError('could not read the file %r' % node)
except Exception: except Exception:
if Logs.verbose > 0: if Logs.verbose > 0:
error("parsing %r failed" % node) error("parsing %r failed" % node)
@ -993,7 +994,7 @@ class c_parser(object):
try: try:
self.defs[self.define_name(line)] = line self.defs[self.define_name(line)] = line
except AttributeError: except AttributeError:
raise PreprocError("Invalid define line %s" % line) raise PreprocError('Invalid define line %r' % line)
elif token == 'undef': elif token == 'undef':
m = re_mac.match(line) m = re_mac.match(line)
if m and m.group() in self.defs: if m and m.group() in self.defs:

View File

@ -239,7 +239,7 @@ def add_settings_enums(self, namespace, filename_list):
:type filename_list: file list :type filename_list: file list
""" """
if hasattr(self, 'settings_enum_namespace'): if hasattr(self, 'settings_enum_namespace'):
raise Errors.WafError("Tried to add gsettings enums to '%s' more than once" % self.name) raise Errors.WafError("Tried to add gsettings enums to %r more than once" % self.name)
self.settings_enum_namespace = namespace self.settings_enum_namespace = namespace
if type(filename_list) != 'list': if type(filename_list) != 'list':
@ -288,7 +288,7 @@ def process_settings(self):
schema_node = self.path.find_resource(schema) schema_node = self.path.find_resource(schema)
if not schema_node: if not schema_node:
raise Errors.WafError("Cannot find the schema file '%s'" % schema) raise Errors.WafError("Cannot find the schema file %r" % schema)
install_files.append(schema_node) install_files.append(schema_node)
source_list = enums_tgt_node + [schema_node] source_list = enums_tgt_node + [schema_node]

View File

@ -541,7 +541,7 @@ def check_python_module(conf, module_name, condition=''):
:param module_name: module :param module_name: module
:type module_name: string :type module_name: string
""" """
msg = "Checking for python module '%s'" % module_name msg = "Checking for python module %r" % module_name
if condition: if condition:
msg = '%s (%s)' % (msg, condition) msg = '%s (%s)' % (msg, condition)
conf.start_msg(msg) conf.start_msg(msg)