2012-03-21 22:26:01 |
Hobson Lane |
description |
Looks like a local variable, type needs to be defined at the start of _compute_value() because it is used throughout. Alternatively it should us self.type insted of type to raise XmpValueError. It seems there are a lot of repeated patterns that could be turned into static functions to reduce these sorts of errors.
Lines 185-204 of src/pyexiv2/xmp.py:
def _compute_value(self):
# Lazy computation of the value from the raw value
if self.type.startswith(('seq', 'bag', 'alt')):
type = self.type[4:]
if type.lower().startswith('closed choice of'):
type = type[17:]
self._value = map(lambda x: self._convert_to_python(x, type), self._raw_value)
elif self.type == 'Lang Alt':
self._value = {}
for k, v in self._raw_value.iteritems():
try:
self._value[unicode(k, 'utf-8')] = unicode(v, 'utf-8')
except TypeError:
raise XmpValueError(self._raw_value, type) # FIXME: variable type is undefined here |
Looks like a local variable, `type`, needs to be defined at the start of XmpTag._compute_value() because it is used throughout. Alternatively compute_value should use self.type insted of type to raise XmpValueError. It seems there are a lot of repeated patterns that could be turned into static functions to reduce these sorts of errors.
Lines 185-204 of src/pyexiv2/xmp.py:
def _compute_value(self):
# Lazy computation of the value from the raw value
if self.type.startswith(('seq', 'bag', 'alt')):
type = self.type[4:]
if type.lower().startswith('closed choice of'):
type = type[17:]
self._value = map(lambda x: self._convert_to_python(x, type), self._raw_value)
elif self.type == 'Lang Alt':
self._value = {}
for k, v in self._raw_value.iteritems():
try:
self._value[unicode(k, 'utf-8')] = unicode(v, 'utf-8')
except TypeError:
raise XmpValueError(self._raw_value, type) # FIXME: variable type is undefined here |
|