Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_location(self):
record = Record()
loc1 = "=852 \\\\$aAmerican Institute of Physics.$bNiels Bohr Library and Archives.$eCollege Park, MD"
loc2 = "=852 01$aCtY$bMain$hLB201$i.M63"
loclist = [loc1, loc2]
self.assertEqual(record.location(), [])
record.add_field(Field("040", [" ", " "], subfields=["a", "DLC", "c", "DLC"]))
record.add_field(
Field(
"852",
[" ", " "],
subfields=[
"a",
"American Institute of Physics.",
"b",
"Niels Bohr Library and Archives.",
"e",
"College Park, MD",
],
)
)
record.add_field(
Field(
"852",
[0, 1],
def test_added_entries(self):
record = Record()
ae1 = "=730 0\\$aTosefta.$lEnglish.$f1977."
ae2 = "=700 10$aLe Peu, Pepe."
aelist = [ae1, ae2]
self.assertEqual(record.addedentries(), [])
record.add_field(
Field(
"730",
[0, " "],
subfields=["a", "Tosefta.", "l", "English.", "f", "1977."],
)
)
record.add_field(Field("700", [1, 0], subfields=["a", "Le Peu, Pepe."]))
record.add_field(Field("245", [0, 0], subfields=["a", "Le Peu's Tosefa."]))
self.assertEqual(len(record.addedentries()), 2)
self.assertEqual(record.addedentries()[0].__str__(), ae1)
self.assertEqual(record.addedentries()[1].__str__(), ae2)
raelist = [rae.__str__() for rae in record.addedentries()]
self.assertEqual(aelist, raelist)
def test_author(self):
record = Record()
self.assertEqual(record.author(), None)
record.add_field(
Field("100", [1, 0], subfields=["a", "Bletch, Foobie,", "d", "1979-1981."])
)
self.assertEqual(record.author(), "Bletch, Foobie, 1979-1981.")
record = Record()
record.add_field(
Field("130", [0, " "], subfields=["a", "Bible.", "l", "Python."])
)
self.assertEqual(record.author(), None)
def test_issn(self):
record = Record()
self.assertEqual(record.issn(), None)
record.add_field(
Field(tag="022", indicators=["0", ""], subfields=["a", "0395-2037"])
)
self.assertEqual(record.issn(), "0395-2037")
def test_multi_find(self):
record = Record()
subject1 = Field(
tag="650", indicators=["", "0"], subfields=["a", "Programming Language"]
)
record.add_field(subject1)
subject2 = Field(
tag="651", indicators=["", "0"], subfields=["a", "Object Oriented"]
)
record.add_field(subject2)
found = record.get_fields("650", "651")
self.assertEqual(len(found), 2)
.exclude(marc_tag=None)\
.exclude(marc_tag='')\
.order_by('marc_tag')
except Exception as e:
raise S2MarcError('Skipped. Couldn\'t retrieve varfields. '
'({})'.format(e), str(r))
for vf in varfields:
tag = vf.marc_tag
ind1 = vf.marc_ind1
ind2 = vf.marc_ind2
content = vf.field_content
try:
if tag in ['{:03}'.format(num) for num in range(1,10)]:
field = pymarc.field.Field(tag=tag, data=content)
else:
field = pymarc.field.Field(
tag=tag,
indicators=[ind1, ind2],
subfields=re.split(r'\|([a-z0-9])', content)[1:]
)
if tag == '856' and field['u'] is not None:
field['u'] = re.sub(r'^([^ ]+) ".*$', r'\1',
field['u'])
marc_record.add_ordered_field(field)
except Exception as e:
raise S2MarcError('Skipped. Couldn\'t create MARC field '
'for {}. ({})'.format(vf.marc_tag, e), str(r))
break
if not marc_record.fields:
raise S2MarcError('Skipped. No MARC fields on Bib record.', str(r))
# Now add various metadata to the 907 field, starting with the
# record number
field_total = len(directory) / DIRECTORY_ENTRY_LEN
# add fields to our record using directory offsets
field_count = 0
while field_count < field_total:
entry_start = field_count * DIRECTORY_ENTRY_LEN
entry_end = entry_start + DIRECTORY_ENTRY_LEN
entry = directory[entry_start:entry_end]
entry_tag = entry[0:3]
entry_length = int(entry[3:7])
entry_offset = int(entry[7:12])
entry_data = marc[base_address + entry_offset :
base_address + entry_offset + entry_length - 1]
if entry_tag < '010':
field = Field(tag=entry_tag, data=entry_data)
else:
subfields = list()
subs = entry_data.split(SUBFIELD_INDICATOR)
first_indicator = subs[0][0]
second_indicator = subs[0][1]
for subfield in subs[1:]:
if len(subfield) == 0:
continue
code = subfield[0]
data = subfield[1:]
subfields.append(code)
subfields.append(data)
field = Field(
tag = entry_tag,
indicators = [first_indicator, second_indicator],
subfields = subfields,
def _one_to_marc(self, r):
marc_record = self.compile_original_marc(r)
if not marc_record.fields:
raise S2MarcError('Skipped. No MARC fields on Bib record.', str(r))
bundle = self.custom_data_pipeline.do(r, marc_record)
marc_record.add_ordered_field(*self.to_9xx_converter.do(bundle))
marc_record.remove_fields('001')
hacked_id = 'a{}'.format(bundle['id'])
marc_record.add_grouped_field(make_pmfield('001', data=hacked_id))
material_type = r.bibrecordproperty_set.all()[0].material.code
metadata_field = pymarc.field.Field(
tag='957',
indicators=[' ', ' '],
subfields=['d', material_type]
)
marc_record.add_ordered_field(metadata_field)
# For each call number in the record, add a 909 field.
i = 0
for cn, ctype in r.get_call_numbers():
subfield_data = []
if i == 0:
try:
srt = helpers.NormalizedCallNumber(cn, ctype).normalize()
except helpers.CallNumberError:
srt = helpers.NormalizedCallNumber(cn, 'other').normalize()
# For each call number in the record, add a 909 field.
i = 0
for cn, ctype in r.get_call_numbers():
subfield_data = []
if i == 0:
try:
srt = helpers.NormalizedCallNumber(cn, ctype).normalize()
except helpers.CallNumberError:
srt = helpers.NormalizedCallNumber(cn, 'other').normalize()
subfield_data = ['a', cn, 'b', srt]
subfield_data.extend([self.cn_type_subfield_mapping[ctype], cn])
cn_field = pymarc.field.Field(
tag='959',
indicators=[' ', ' '],
subfields=subfield_data
)
marc_record.add_ordered_field(cn_field)
i += 1
# If this record has a media game facet field: clean it up,
# split by semicolon, and put into 910$a (one 910, and one $a
# per token)
media_tokens = self._record_get_media_game_facet_tokens(r, marc_record)
if media_tokens is not None:
mf_subfield_data = []
for token in media_tokens:
mf_subfield_data += ['a', token]
mf_field = pymarc.field.Field(
# record number
recnum = r.record_metadata.get_iii_recnum(True)
suppressed = 'true' if r.is_suppressed else 'false'
material_type = r.bibrecordproperty_set.all()[0].material\
.materialpropertyname_set.all()[0].name
metadata_field = pymarc.field.Field(
tag='907',
indicators=[' ', ' '],
subfields=['a', '.{}'.format(recnum), 'b', str(r.id),
'c', suppressed, 'd', material_type]
)
# Add a list of attached items to the 908 field.
marc_record.add_ordered_field(metadata_field)
for item_link in r.bibrecorditemrecordlink_set.all():
item = item_link.item_record
item_field = pymarc.field.Field(
tag='908',
indicators=[' ', ' '],
subfields=['a', item.record_metadata.get_iii_recnum(True),
'b', str(item.pk)]
)
marc_record.add_ordered_field(item_field)
# For each call number in the record, add a 909 field.
i = 0
for cn, ctype in r.get_call_numbers():
subfield_data = []
if i == 0:
try:
srt = helpers.NormalizedCallNumber(cn, ctype).normalize()
except helpers.CallNumberError:
srt = helpers.NormalizedCallNumber(cn, 'other').normalize()