Skip to content

Commit

Permalink
Add strictness flag to disable assertion checking (some servers don't
Browse files Browse the repository at this point in the history
correctly fill in MARC fields).

Only do unicode normalization during character set conversion when available
(Python 2.3 and later).
  • Loading branch information
asl2 committed Jul 20, 2004
1 parent 33c82e9 commit 229aaee
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions PyZ3950/zmarc.py
Expand Up @@ -154,7 +154,11 @@ class MARC:
# Status, Type, Bib. Level, Type of Ctrl., Enc. Level,
# Descr. Cat. Form, Linked Rcd Reqt are all part of pseudoentry 0

def __init__(self, MARC = None):
def __init__(self, MARC = None, strict = 1):
"""Parses MARC data. According to Bill Oldroyd (Bill.Oldroyd at
bl.uk), some servers don't set the character set and/or other
bits of the MARC header properly, so it's useful to set strict=0
when dealing with such servers."""
self.fields = {}
self.ok = 0
self.marc = MARC
Expand All @@ -166,9 +170,10 @@ def __init__(self, MARC = None):
zerostr = ""
for ind in self.hdrbits: zerostr = zerostr + self.marc[ind]
self.fields [0] = [zerostr]
assert (self.marc[9] == ' ') # 'a' would be UCS/Unicode
assert (self.marc[10] == '2' and self.marc[11] == '2')
assert (self.marc[20:22] == '45')
if strict:
assert (self.marc[9] == ' ') # 'a' would be UCS/Unicode
assert (self.marc[10] == '2' and self.marc[11] == '2')
assert (self.marc[20:22] == '45')
pos = 24
lastpos = baseaddr
while pos < baseaddr:
Expand Down Expand Up @@ -1141,7 +1146,10 @@ class MARC8_to_Unicode:
purposes only. (If you know of either of fonts designed for use
with LC's private-use Unicode assignments, or of attempts to
standardize Unicode characters to allow round-trips from EACC,
please inform me, asl2@pobox.com.) """
or if you need the private-use Unicode character translations,
please inform me, asl2@pobox.com."""



basic_latin = 0x42
ansel = 0x45
Expand Down Expand Up @@ -1193,8 +1201,11 @@ def translate (self, s):
combinings = []
# what to do if combining chars left over?
uni_str = u"".join (uni_list)
# unicodedata.normalize not available until Python 2.3
# uni_str = unicodedata.normalize ('NFC', uni_str)

# unicodedata.normalize not available until Python 2.3
if hasattr (unicodedata, 'normalize'):
uni_str = unicodedata.normalize ('NFC', uni_str)

return uni_str

def test_convert (s, enc):
Expand Down

0 comments on commit 229aaee

Please sign in to comment.