Skip to content

Commit

Permalink
fixed bug with could_be formats, and cleaned up value parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
amccollum committed Feb 10, 2010
1 parent 73f542c commit 8c86296
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
7 changes: 3 additions & 4 deletions microtron/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def _parse_node(self, node, format):
if '__type__' in value:
value['__type__'] += ' ' + format_results[0].pop('__type__')

value.update(results[0])
value.update(format_results[0])

except:
pass
Expand Down Expand Up @@ -157,18 +157,17 @@ def _parse_node(self, node, format):
return result

def _parse_value(self, node):
text_expr = 'normalize-space(string(.))'
value_expr = 'descendant::*[contains(concat(" ", normalize-space(@class), " "), " value ")]'
value_nodes = node.xpath(value_expr)

if value_nodes:
return self._parse_text(" ".join(value_node.xpath(text_expr) for value_node in value_nodes))
return " ".join(self._parse_text(value_node) for value_node in value_nodes)

elif node.tag == 'abbr' and 'title' in node.attrib:
return node.attrib['title']

else:
return node.xpath(text_expr)
return self._parse_text(node)

def _parse_text(self, node):
text_expr = 'normalize-space(string(.))'
Expand Down
1 change: 1 addition & 0 deletions parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def parse(argv = None):
options, arguments = parser.parse_args(argv[1:])
if len(arguments) != 3:
parser.error('Incorrect number of arguments')

source_filename = os.path.abspath(arguments[0])
formats_filename = os.path.abspath(arguments[1])
format = arguments[2]
Expand Down

0 comments on commit 8c86296

Please sign in to comment.