Skip to content

Commit

Permalink
[Usenet Parser] TOWN releases are now correctly parsed
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzeman committed Dec 10, 2013
1 parent 1cbafba commit 68596ca
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
8 changes: 4 additions & 4 deletions src/caper/constraint.py
Expand Up @@ -92,11 +92,11 @@ def constraint_result(self, parent_node, fragment):

ckey = self.kwargs.get('key')

for tag, keys in parent_node.captured():
for tag, result in parent_node.captured():
if tag != ctag:
continue

if not ckey or ckey in keys:
if not ckey or ckey in result.keys():
return 1.0, True

return 0.0, False
Expand All @@ -108,8 +108,8 @@ def constraint_failure(self, parent_node, fragment, match):
return 0, False

def constraint_success(self, parent_node, fragment, match):
#if match and match.success:
# return 1.0, True
if match and match.success:
return 1.0, True

return 0, False

Expand Down
29 changes: 22 additions & 7 deletions src/caper/parsers/usenet.py
Expand Up @@ -31,7 +31,7 @@
]),

('detail', [
r'[\s-]*\"(?P<file_name>.*?)\"(\s(?P<extra>yEnc))?'
r'[\s-]*\"(?P<file_name>.*?)\".*?(?P<extra>yEnc)'
])
]

Expand Down Expand Up @@ -59,13 +59,28 @@ def run(self, closures):
.until_failure()\
.execute()

self.capture_fragment('release_name', single=False)\
.until(fragment__re='part')\
.execute()
# TODO multiple-chains?
is_town_release = False
has_part = False

self.capture_fragment('part', regex='part', single=True)\
.until_success()\
.execute()
for tag, result in self.result.heads[0].captured():
if tag == 'usenet' and result.get('group') == 'TOWN':
is_town_release = True

if tag == 'part':
has_part = True

# TOWN usenet releases do not contain release names
if not is_town_release:
self.capture_fragment('release_name', single=False)\
.until(fragment__re='part')\
.execute()

# If we already have the part (TOWN releases), ignore matching part again
if not is_town_release and not has_part:
self.capture_fragment('part', regex='part', single=True) \
.until_success()\
.execute()

self.capture_closure('detail', regex='detail', single=False)\
.execute()
Expand Down
4 changes: 2 additions & 2 deletions src/caper/result.py
Expand Up @@ -45,13 +45,13 @@ def captured(self):
cur = self

if cur.match:
yield cur.match.tag, cur.match.result.keys()
yield cur.match.tag, cur.match.result

while cur.parent:
cur = cur.parent

if cur.match:
yield cur.match.tag, cur.match.result.keys()
yield cur.match.tag, cur.match.result


class CaperRootNode(CaperNode):
Expand Down

0 comments on commit 68596ca

Please sign in to comment.