edsu/pymarc — Issue #23: handling MARC21/ANSEL encoded readers with wrong leader[9]
Author: godmar
Created: 2012-03-08 18:32:28+00:00
State: open

If I have a MARC record where leader[9] == 'a' but that contains ANSEL-encoded data, which is read with a MarcReader where to_unicode=False, then pymarc fails to write the record because the presence of leader[9] forces UTF8 encoding, which blows up for ANSEL strings. See https://github.com/mbklein/pymarc/commit/ff312861096ecaa527d210836dbef904c24baee6

(Of course, if the record is reader with 'to_unicode=True', it'll blow up during reader because the record can't be utf8-decoded.)

It seems to me a better strategy might be to remember in the record whether it should be utf8-encoded on write, rather than relying on the (possibly erronenous) leader[9] field. In short, code like this shouldn't fail even with defective/misencoded records:

for record in marcreader:
if (somecondition):
marcwriter.write(record)