Updated Caper to version 0.2.2

This commit is contained in:
Dean Gardiner
2013-10-16 14:58:47 +13:00
parent 6259684487
commit 07abf7c83d
4 changed files with 2 additions and 130 deletions
+1 -60
View File
@@ -12,10 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import pprint
import re
from logr import Logr
from caper.helpers import is_list_type, clean_dict
from caper.helpers import is_list_type
class FragmentMatcher(object):
@@ -57,8 +56,6 @@ class FragmentMatcher(object):
self.regex[group_name].append((weight, weight_patterns))
pprint.pprint(self.regex)
def find_group(self, name):
for group_name, weight_groups in self.regex.items():
if group_name and group_name == name:
@@ -66,62 +63,6 @@ class FragmentMatcher(object):
return None
def parser_match(self, parser, group_name, single=True):
"""
:type parser: caper.parsers.base.Parser
"""
result = None
for group, weight_groups in self.regex.items():
if group_name and group != group_name:
continue
# TODO handle multiple weights
weight, patterns = weight_groups[0]
for pattern in patterns:
fragments = []
pattern_matched = True
pattern_result = {}
for fragment_pattern in pattern:
if not parser.fragment_available():
pattern_matched = False
break
fragment = parser.next_fragment()
fragments.append(fragment)
Logr.debug('[r"%s"].match("%s")', fragment_pattern.pattern, fragment.value)
match = fragment_pattern.match(fragment.value)
if match:
Logr.debug('Pattern "%s" matched', fragment_pattern.pattern)
else:
pattern_matched = False
break
pattern_result.update(clean_dict(match.groupdict()))
if pattern_matched:
if result is None:
result = {}
if group not in result:
result[group] = {}
Logr.debug('Matched on <%s>', ' '.join([f.value for f in fragments]))
result[group].update(pattern_result)
parser.commit()
if single:
return result
else:
parser.rewind()
return result
def value_match(self, value, group_name=None, single=True):
result = None