Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get(self, key, *args):
value = dict.get(self, key, *args)
if not value:
return ''
if hasattr(value, '__iter__'):
value = '|'.join([x for x in value if x])
# converting to utf8 with yaz-marcdump instead -- it handles
# oddities better
return pymarc.marc8.marc8_to_unicode(value).encode('utf8')
# convert to unicode if value is a string
#if type(value) == type(''):
# value = unicode(value, 'utf8')
# converting to NFC form lessens character encoding issues
value = unicodedata.normalize('NFC', value)
return value.encode('utf8')
def map_marc8_field(f):
"""Map MARC8 field."""
if f.is_control_field():
f.data = marc8_to_unicode(f.data)
else:
f.subfields = map(marc8_to_unicode, f.subfields)
return f
def map_marc8_field(f):
"""Map MARC8 field."""
if f.is_control_field():
f.data = marc8_to_unicode(f.data)
else:
f.subfields = map(marc8_to_unicode, f.subfields)
return f
for subfield in subs[1:]:
skip_bytes = 1
if len(subfield) == 0:
continue
try:
code = subfield[0:1].decode("ascii")
except UnicodeDecodeError:
warnings.warn(BadSubfieldCodeWarning())
code, skip_bytes = normalize_subfield_code(subfield)
data = subfield[skip_bytes:]
if to_unicode:
if self.leader[9] == "a" or force_utf8:
data = data.decode("utf-8", utf8_handling)
elif encoding == "iso8859-1":
data = marc8_to_unicode(data, hide_utf8_warnings)
else:
data = data.decode(encoding)
subfields.append(code)
subfields.append(data)
if to_unicode:
field = Field(
tag=entry_tag,
indicators=[first_indicator, second_indicator],
subfields=subfields,
)
else:
field = RawField(
tag=entry_tag,
indicators=[first_indicator, second_indicator],
subfields=subfields,
)