Browse Source

Do not care about recursion limit (Python will)

Alois Mahdal 10 years ago
parent
commit
d01ccf2bf0
1 changed files with 5 additions and 13 deletions
  1. 5
    13
      sznqalibs/hoover.py

+ 5
- 13
sznqalibs/hoover.py View File

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