Someone's been misusing Python's re.match... O:)

This commit is contained in:
Sei Lisa 2016-06-26 22:33:10 +02:00
parent 893bcf177b
commit ee091c63a6
2 changed files with 18 additions and 18 deletions

View file

@ -381,7 +381,7 @@ def InternalTypecast(val, out, InList, f32):
if out == Key: return Key(val) if out == Key: return Key(val)
if out == float: if out == float:
# Clean up the string for Picky Python # Clean up the string for Picky Python
match = float_re.match(val) match = float_re.search(val)
if match is None: if match is None:
return 0.0 return 0.0
if match.group(1): if match.group(1):
@ -394,7 +394,7 @@ def InternalTypecast(val, out, InList, f32):
ret = 0.0 ret = 0.0
return ret return ret
if out == int: if out == int:
match = int_re.match(val) match = int_re.search(val)
if match is None: if match is None:
return 0 return 0
val = match.group(0) val = match.group(0)
@ -412,7 +412,7 @@ def InternalTypecast(val, out, InList, f32):
return Z return Z
val = val[1:] val = val[1:]
for _ in range(dim): for _ in range(dim):
match = vfloat_re.match(val) match = vfloat_re.search(val)
if match is None: if match is None:
return Z return Z
if match.group(1): if match.group(1):
@ -752,7 +752,7 @@ def cond(x):
if tx == Key: if tx == Key:
if x == NULL_KEY or len(x) != 36: if x == NULL_KEY or len(x) != 36:
return False return False
return bool(key_re.match(x)) return bool(key_re.search(x))
if tx == Vector: if tx == Vector:
return bool(compare(x, ZERO_VECTOR, Eq=False)) return bool(compare(x, ZERO_VECTOR, Eq=False))
if tx == Quaternion: if tx == Quaternion:
@ -880,7 +880,7 @@ def llBase64ToInteger(s):
assert isstring(s) assert isstring(s)
if len(s) > 8: if len(s) > 8:
return 0 return 0
s = b64_re.match(s).group() s = b64_re.search(s).group()
i = len(s) i = len(s)
s = b64decode(s + u'='*(-i & 3)) s = b64decode(s + u'='*(-i & 3))
if len(s) < 3: if len(s) < 3:
@ -892,7 +892,7 @@ def llBase64ToInteger(s):
def llBase64ToString(s): def llBase64ToString(s):
assert isstring(s) assert isstring(s)
s = b64_re.match(s).group(0) s = b64_re.search(s).group(0)
return InternalUTF8toString(b64decode(s + u'='*(-len(s)&3))) return InternalUTF8toString(b64decode(s + u'='*(-len(s)&3)))
def llCSV2List(s): def llCSV2List(s):
@ -1688,9 +1688,9 @@ def llXorBase64(s, xor):
if xor == u'': if xor == u'':
return s return s
s = b64_re.match(s).group(0) s = b64_re.search(s).group(0)
L1 = len(s) L1 = len(s)
xor = b64_re.match(xor).group(0) xor = b64_re.search(xor).group(0)
L2 = len(xor) L2 = len(xor)
if L2 == 0: if L2 == 0:
@ -1770,9 +1770,9 @@ def llXorBase64StringsCorrect(s, xor):
return s return s
s = b64_re.match(s).group(0) s = b64_re.search(s).group(0)
L1 = len(s) L1 = len(s)
xor = b64_re.match(xor).group(0) xor = b64_re.search(xor).group(0)
L2 = len(xor) L2 = len(xor)
if L2 == 0: if L2 == 0:

View file

@ -2494,7 +2494,7 @@ list lazy_list_set(list L, integer i, list v)
line = f.readline() line = f.readline()
if not line: break if not line: break
if line[-1] == '\n': line = line[:-1] if line[-1] == '\n': line = line[:-1]
match = parse_lin_re.match(line) match = parse_lin_re.search(line)
if not match: if not match:
warning('Syntax error in ' + builtins + ', line ' + line) warning('Syntax error in ' + builtins + ', line ' + line)
continue continue
@ -2514,12 +2514,12 @@ list lazy_list_set(list L, integer i, list v)
arglist = arglist.split(',') arglist = arglist.split(',')
bad = False bad = False
for arg in arglist: for arg in arglist:
argtyp = parse_arg_re.match(arg).group(1) argtyp = parse_arg_re.search(arg).group(1)
if argtyp not in self.types: if argtyp not in self.types:
warning('Invalid type in ' + builtins + ', line ' + line + ': ' + argtyp) warning('Invalid type in ' + builtins + ', line ' + line + ': ' + argtyp)
bad = True bad = True
break break
args.append(parse_arg_re.match(arg).group(1)) args.append(parse_arg_re.search(arg).group(1))
if bad: if bad:
continue continue
name = match.group(2) name = match.group(2)
@ -2555,7 +2555,7 @@ list lazy_list_set(list L, integer i, list v)
value = lslfuncs.F32(float(value)) value = lslfuncs.F32(float(value))
elif typ == 'string': elif typ == 'string':
value = value.decode('utf8') value = value.decode('utf8')
if parse_str_re.match(value): if parse_str_re.search(value):
esc = False esc = False
tmp = value[1:-1] tmp = value[1:-1]
value = u'' value = u''
@ -2586,22 +2586,22 @@ list lazy_list_set(list L, integer i, list v)
value = value[1:-1].split(',') value = value[1:-1].split(',')
if len(value) != (3 if typ == 'vector' else 4): if len(value) != (3 if typ == 'vector' else 4):
raise ValueError raise ValueError
num = parse_num_re.match(value[0]) num = parse_num_re.search(value[0])
if not num: if not num:
raise ValueError raise ValueError
value[0] = lslfuncs.F32(float(num.group(1))) value[0] = lslfuncs.F32(float(num.group(1)))
num = parse_num_re.match(value[1]) num = parse_num_re.search(value[1])
if not num: if not num:
raise ValueError raise ValueError
value[1] = lslfuncs.F32(float(num.group(1))) value[1] = lslfuncs.F32(float(num.group(1)))
num = parse_num_re.match(value[2]) num = parse_num_re.search(value[2])
if not num: if not num:
raise ValueError raise ValueError
value[2] = lslfuncs.F32(float(num.group(1))) value[2] = lslfuncs.F32(float(num.group(1)))
if typ == 'vector': if typ == 'vector':
value = Vector(value) value = Vector(value)
else: else:
num = parse_num_re.match(value[3]) num = parse_num_re.search(value[3])
if not num: if not num:
raise ValueError raise ValueError
value[3] = lslfuncs.F32(float(num.group(1))) value[3] = lslfuncs.F32(float(num.group(1)))