Skip to content

Commit

Permalink
Merge pull request #5599 from hornc/dnb
Browse files Browse the repository at this point in the history
Import DNB ids from MARC records
  • Loading branch information
mekarpeles authored Sep 14, 2021
2 parents 81dae35 + 9605eae commit d7eaa20
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 45 deletions.
13 changes: 6 additions & 7 deletions openlibrary/catalog/marc/marc_binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,13 @@
from openlibrary.catalog.marc.marc_base import MarcBase, MarcException, BadMARC


import six


marc8 = MARC8ToUnicode(quiet=True)


class BadLength(MarcException):
pass


def norm(s):
return normalize('NFC', six.text_type(s))


def handle_wrapped_lines(_iter):
"""
Handles wrapped MARC fields, which appear to be multiple
Expand Down Expand Up @@ -86,6 +79,9 @@ def remove_brackets(self):
self.line = b''.join([line[0:4], line[5:-2], last_byte])

def get_subfields(self, want):
"""
:rtype: collections.Iterable[tuple]
"""
want = set(want)
for i in self.line[3:-1].split(b'\x1f'):
code = i and (chr(i[0]) if isinstance(i[0], int) else i[0])
Expand All @@ -100,6 +96,9 @@ def get_contents(self, want):
return contents

def get_subfield_values(self, want):
"""
:rtype: list[str]
"""
return [v for k, v in self.get_subfields(want)]

def get_all_subfields(self):
Expand Down
Loading

0 comments on commit d7eaa20

Please sign in to comment.