|
@@ -1021,7 +1021,7 @@ class Tracker(dict):
|
1021
|
1021
|
cw.writerow(argset)
|
1022
|
1022
|
|
1023
|
1023
|
|
1024
|
|
-def dataMatch(pattern, data, rmax=10, _r=0):
|
|
1024
|
+def dataMatch(pattern, data):
|
1025
|
1025
|
"""Check if data structure matches a pattern data structure.
|
1026
|
1026
|
|
1027
|
1027
|
Supports lists, dictionaries and scalars (int, float, string).
|
|
@@ -1036,7 +1036,7 @@ def dataMatch(pattern, data, rmax=10, _r=0):
|
1036
|
1036
|
assert all([hasattr(o, 'append') for o in [pattern, data]])
|
1037
|
1037
|
results = []
|
1038
|
1038
|
for pv in pattern:
|
1039
|
|
- if any([dataMatch(pv, dv, _r=_r+1) for dv in data]):
|
|
1039
|
+ if any([dataMatch(pv, dv) for dv in data]):
|
1040
|
1040
|
results.append(True)
|
1041
|
1041
|
else:
|
1042
|
1042
|
results.append(False)
|
|
@@ -1048,14 +1048,11 @@ def dataMatch(pattern, data, rmax=10, _r=0):
|
1048
|
1048
|
results = []
|
1049
|
1049
|
try:
|
1050
|
1050
|
for pk, pv in pattern.items():
|
1051
|
|
- results.append(dataMatch(pv, data[pk], _r=_r+1))
|
|
1051
|
+ results.append(dataMatch(pv, data[pk]))
|
1052
|
1052
|
except KeyError:
|
1053
|
1053
|
results.append(False)
|
1054
|
1054
|
return all(results)
|
1055
|
1055
|
|
1056
|
|
- if _r == rmax:
|
1057
|
|
- raise RuntimeError("recursion limit hit")
|
1058
|
|
-
|
1059
|
1056
|
result = None
|
1060
|
1057
|
if pattern == data:
|
1061
|
1058
|
result = True
|
|
@@ -1318,7 +1315,6 @@ class Cartman:
|
1318
|
1315
|
optimization became possible based on what was used.
|
1319
|
1316
|
"""
|
1320
|
1317
|
|
1321
|
|
-
|
1322
|
1318
|
# TODO: support for arbitrary ordering (profile / nginx)
|
1323
|
1319
|
# TODO: implement getstats and fmtstats
|
1324
|
1320
|
# TODO: N-wise
|
|
@@ -1332,13 +1328,9 @@ class Cartman:
|
1332
|
1328
|
class Iterable(_BaseMark):
|
1333
|
1329
|
pass
|
1334
|
1330
|
|
1335
|
|
- def __init__(self, source, scheme, recursion_limit=10, _r=0):
|
|
1331
|
+ def __init__(self, source, scheme):
|
1336
|
1332
|
self.source = source
|
1337
|
1333
|
self.scheme = scheme
|
1338
|
|
- self.recursion_limit = recursion_limit
|
1339
|
|
- self._r = _r
|
1340
|
|
- if self._r > self.recursion_limit:
|
1341
|
|
- raise RuntimeError("recursion limit exceeded")
|
1342
|
1334
|
|
1343
|
1335
|
# validate scheme + source and throw useful error
|
1344
|
1336
|
scheme_ok = isinstance(self.scheme, collections.Mapping)
|
|
@@ -1374,7 +1366,7 @@ class Cartman:
|
1374
|
1366
|
elif self._means_iterable(subscheme):
|
1375
|
1367
|
return subsource
|
1376
|
1368
|
else: # try to use it as scheme
|
1377
|
|
- return iter(Cartman(subsource, subscheme, _r=self._r+1))
|
|
1369
|
+ return iter(Cartman(subsource, subscheme))
|
1378
|
1370
|
|
1379
|
1371
|
def __iter__(self):
|
1380
|
1372
|
|