Skip to content
Browse files

Re-raise the suppressed ValueError if calling 'typefunc()' without ar…

…guments failed in 'parse_inform_output'
  • Loading branch information...
1 parent 79c347c commit d09152401a9e051b1ccd66e79d43ada12aebed4d @jonashaag committed Sep 27, 2010
Showing with 11 additions and 2 deletions.
  1. +11 −2 lowlevel.py
View
13 lowlevel.py
@@ -1,4 +1,5 @@
import os
+import sys
from future_builtins import zip
from subprocess import Popen, PIPE
try:
@@ -15,6 +16,9 @@
class ExecutionError(Exception):
""" Raised if a MediaInfo command returns an exit code other than 0. """
+def _raise(*exc_info):
+ raise exc_info[0], exc_info[1], exc_info[2]
+
def format_inform(**inform):
sections = []
for section_name, params in inform.iteritems():
@@ -41,20 +45,25 @@ def parse_inform_output(output, inform):
values = params.split(PARAM_SEP)
sec = {}
for inform_param, value in zip(inform[section], values):
+ # TODO: put that typefunc stuff away
if isinstance(inform_param, basestring):
name, typefunc = inform_param, lambda x:x
else:
name, typefunc = inform_param
try:
sec[name] = typefunc(value)
except ValueError:
+ value_error = sys.exc_info()
if value == '':
# if `value` is an empty string, try `typefunc` without
# arguments. useful e.g. for `typefunc` == `int`,
# which does not allow empty strings as argument.
- sec[name] = typefunc()
+ try:
+ sec[name] = typefunc()
+ except TypeError:
+ _raise(*value_error)
else:
- raise
+ _raise(*value_error)
sections[section] = sec
return sections

0 comments on commit d091524

Please sign in to comment.
Something went wrong with that request. Please try again.