本文整理汇总了Python中pymarc.record.Record类的典型用法代码示例。如果您正苦于以下问题:Python Record类的具体用法?Python Record怎么用?Python Record使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Record类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_pubyear
def test_pubyear(self):
record = Record()
self.assertEqual(record.pubyear(), None)
record.add_field(
Field(
"260",
[" ", " "],
subfields=[
"a",
"Paris :",
"b",
"Gauthier-Villars ;",
"a",
"Chicago :",
"b",
"University of Chicago Press,",
"c",
"1955.",
],
)
)
self.assertEqual(record.pubyear(), "1955.")
record = Record()
self.assertEqual(record.pubyear(), None)
record.add_field(Field("264", [" ", "1"], subfields=["a", "London :", "b", "Penguin,", "c", "1961."]))
self.assertEqual(record.pubyear(), "1961.")
示例2: test_notes
def test_notes(self):
record = Record()
self.assertEquals(record.notes(), [])
record.add_field(
Field("500", [" ", " "], subfields=["a", "Recast in bronze from artist's plaster original of 1903."])
)
self.assertEquals(record.notes()[0].format_field(), "Recast in bronze from artist's plaster original of 1903.")
示例3: test_remove_fields
def test_remove_fields(self):
with open("test/testunimarc.dat", "rb") as fh:
record = Record(fh.read(), force_utf8=True)
self.assertTrue(len(record.get_fields("899")) != 0)
self.assertTrue(len(record.get_fields("702")) != 0)
record.remove_fields("899", "702")
self.assertTrue(len(record.get_fields("899")) == 0)
self.assertTrue(len(record.get_fields("702")) == 0)
示例4: test_add_field
def test_add_field(self):
record = Record()
field = Field(
tag = '245',
indicators = ['1', '0'],
subfields = ['a', 'Python', 'c', 'Guido'])
record.add_field(field)
self.assertTrue(field in record.fields, msg='found field')
示例5: test_remove_fields
def test_remove_fields(self):
with open('test/testunimarc.dat', 'rb') as fh:
record = Record(fh.read(), force_utf8=True)
self.assertTrue(len(record.get_fields('899'))!=0)
self.assertTrue(len(record.get_fields('702'))!=0)
record.remove_fields('899', '702')
self.assertTrue(len(record.get_fields('899'))==0)
self.assertTrue(len(record.get_fields('702'))==0)
示例6: test_membership
def test_membership(self):
record = Record()
title = Field(
tag = '245',
indicators = ['1', '0'],
subfields = ['a', 'Python', 'c', 'Guido'])
record.add_field(title)
self.assertTrue('245' in record)
self.assertFalse('999' in record)
示例7: test_quick_access
def test_quick_access(self):
record = Record()
title = Field(
tag = '245',
indicators = ['1', '0'],
subfields = ['a', 'Python', 'c', 'Guido'])
record.add_field(title)
self.assertEqual(record['245'], title, 'short access')
self.assertEqual(record['999'], None, 'short access with no field')
示例8: test_alphatag
def test_alphatag(self):
record = Record()
record.add_field(Field('CAT', [' ', ' '], subfields=['a', 'foo']))
record.add_field(Field('CAT', [' ', ' '], subfields=['b', 'bar']))
fields = record.get_fields('CAT')
self.assertEqual(len(fields), 2)
self.assertEqual(fields[0]['a'], 'foo')
self.assertEqual(fields[1]['b'], 'bar')
self.assertEqual(record['CAT']['a'], 'foo')
示例9: test_init_with_no_leader
def test_init_with_no_leader(self):
"""
Test creating a Record object with no leader argument.
"""
record = Record()
record.add_field(Field(tag="245", indicators=["0", "1"], subfields=["a", "The pragmatic programmer"]))
transmission_format = record.as_marc()
transmission_format_leader = transmission_format[0:24]
self.assertEqual(transmission_format_leader, b"00067 2200037 4500")
示例10: test_init_with_leader
def test_init_with_leader(self):
"""
Test creating a Record with a leader argument.
"""
record = Record(leader="abcdefghijklmnopqrstuvwx")
record.add_field(Field(tag="245", indicators=["0", "1"], subfields=["a", "The pragmatic programmer"]))
transmission_format = record.as_marc()
transmission_format_leader = transmission_format[0:24]
self.assertEqual(transmission_format_leader, b"00067fghij2200037rst4500")
示例11: test_pubyear
def test_pubyear(self):
record = Record()
self.assertEqual(record.pubyear(), None)
record.add_field(Field('260', [' ', ' '],
subfields=['a', 'Paris :', 'b', 'Gauthier-Villars ;', 'a', 'Chicago :', 'b', 'University of Chicago Press,', 'c', '1955.']))
self.assertEqual(record.pubyear(), '1955.')
record = Record()
self.assertEqual(record.pubyear(), None)
record.add_field(Field('264', [' ', '1'],
subfields=['a', 'London :', 'b', 'Penguin,', 'c', '1961.']))
self.assertEqual(record.pubyear(), '1961.')
示例12: test_as_marc_with_explicit_leader
def test_as_marc_with_explicit_leader(self):
"""
Test setting an explicit leader.
as_marc() should use the whole leader as set.
"""
record = Record()
record.add_field(Field(tag="245", indicators=["0", "1"], subfields=["a", "The pragmatic programmer"]))
record.leader = "00067 2200037 4500"
leader_not_touched = record.leader
transmission_format = record.as_marc()
leader_touched = record.leader
self.assertTrue(leader_not_touched == leader_touched)
示例13: standardize_maemarc
def standardize_maemarc(fid, mae_marc, fname_suffix):
marc_file = MARC_FILE % fname_suffix
mae_marc = mae_marc.replace("\r", "")
mae_marc = mae_marc.strip()
mae_marc = mae_marc.rstrip("&")
mae_marc = mae_marc.rstrip("%")
parts = mae_marc.split('\n')
header = parts[:2]
tags_values = parts[2:]
ret = []
writer = MARCWriter(file(marc_file, 'a+'))
record = Record()
control = parts[1:2][0][:-1]
field = Field(tag = '001', data = fid)
record.add_field(field)
#field = Field(tag = '008', data = control)
#record.add_field(field)
for dat in tags_values:
dat = dat.strip('\n')
tag = dat[0:3]
values = []
subfields = []
for v in dat[6:-1].split('$'):
subfield = v[:1]
value = v[1:]
if (tag == '260') and (subfield == 'c'):
value = value.lstrip('c')
value = value.rstrip(".")
subfields.append(subfield)
subfields.append(value)
if tag == '245':
indicator = ['1', '0']
elif tag == '041':
indicator = ['1', '0']
else:
indicator = ['', '']
field = Field(tag, indicator, subfields)
record.add_field(field)
if tag:
ret.append({tag:subfields})
print "final output:"
print record
writer.write(record)
writer.close()
示例14: test_as_marc_leader
def test_as_marc_leader(self):
record = Record()
record.add_field(
Field(
tag = '245',
indicators = ['0','1'],
subfields = ['a', 'The pragmatic programmer']))
record.leader = '00067 2200037 4500'
leader_not_touched = record.leader
transmission_format = record.as_marc()
leader_touched = record.leader
self.assertTrue(leader_not_touched==leader_touched)
示例15: test_title
def test_title(self):
record = Record()
self.assertEquals(record.title(), None)
record.add_field(Field("245", [0, 1], subfields=["a", "Foo :", "b", "bar"]))
self.assertEquals(record.title(), "Foo :bar")
record = Record()
record.add_field(Field("245", [0, 1], subfields=["a", "Farghin"]))
self.assertEquals(record.title(), "Farghin")