Skip to content
This repository has been archived by the owner on Feb 4, 2020. It is now read-only.

Commit

Permalink
Allowed for ISBN checkdigit x/X in Record.isbn
Browse files Browse the repository at this point in the history
  • Loading branch information
godmar committed Mar 12, 2012
1 parent 68b27a2 commit 5a4b77a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pymarc/record.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def sentinel():
finally: finally:
del chain del chain


isbn_regex = re.compile(r'([0-9\-]+)') isbn_regex = re.compile(r'([0-9\-xX]+)')


class Record(object): class Record(object):
""" """
Expand Down Expand Up @@ -351,7 +351,8 @@ def title(self):
def isbn(self): def isbn(self):
""" """
Returns the first ISBN in the record or None if one is not Returns the first ISBN in the record or None if one is not
present. The returned ISBN will be all numberic; so dashes and present. The returned ISBN will be all numeric, except for an
x/X which may occur in the checksum position. Dashes and
extraneous information will be automatically removed. If you need extraneous information will be automatically removed. If you need
this information you'll want to look directly at the 020 field, this information you'll want to look directly at the 020 field,
e.g. record['020']['a'] e.g. record['020']['a']
Expand Down
4 changes: 4 additions & 0 deletions test/record.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ def test_isbn(self):
record = Record() record = Record()
record.add_field(Field('020', [' ', ' '], subfields=['a', '0456789012 (reel 1)'])) record.add_field(Field('020', [' ', ' '], subfields=['a', '0456789012 (reel 1)']))
self.assertEquals(record.isbn(), '0456789012') self.assertEquals(record.isbn(), '0456789012')

record = Record()
record.add_field(Field('020', [' ', ' '], subfields=['a', '006073132X']))
self.assertEquals(record.isbn(), '006073132X')


def test_multiple_isbn(self): def test_multiple_isbn(self):
reader = MARCReader(file('test/multi_isbn.dat')) reader = MARCReader(file('test/multi_isbn.dat'))
Expand Down

0 comments on commit 5a4b77a

Please sign in to comment.