本文整理汇总了Python中resync.resource_list.ResourceList类的典型用法代码示例。如果您正苦于以下问题:Python ResourceList类的具体用法?Python ResourceList怎么用?Python ResourceList使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ResourceList类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test01_no_links
def test01_no_links(self):
xml = run_resync(['--write-resourcelist',
'http://example.org/t', 'tests/testdata/dir1'])
rl = ResourceList()
rl.parse(fh=io.BytesIO(xml))
self.assertEqual(len(rl), 2)
self.assertEqual(rl.link('describedby'), None)
开发者ID:resync,项目名称:resync,代码行数:7,代码来源:test_client_link_options.py
示例2: test04_dump_multi_file_max_size
def test04_dump_multi_file_max_size(self):
rl=ResourceList()
for letter in map(chr,xrange(ord('a'),ord('l')+1)):
uri='http://ex.org/%s' % (letter)
fname='resync/test/testdata/a_to_z/%s' % (letter)
rl.add( Resource(uri, path=fname) )
self.assertEqual( len(rl), 12 )
d2=Dump(rl)
tmpbase=os.path.join(self.tmpdir,'test0f_')
d2.max_size=2000
n=d2.write(tmpbase)
self.assertEqual( n, 2, 'expect to write 2 dump files' )
self.assertTrue( os.path.isfile(tmpbase+'00000.zip') )
self.assertTrue( os.path.isfile(tmpbase+'00001.zip') )
# Look at the first file in detail
zipf=tmpbase+'00000.zip'
zo=zipfile.ZipFile(zipf,'r')
self.assertEqual( zo.namelist(), ['manifest.xml','a','b','c','d','e','f'] )
#self.assertEqual( zo.getinfo('manifest.xml').file_size, 470 )
self.assertEqual( zo.getinfo('a').file_size, 9 )
self.assertEqual( zo.getinfo('b').file_size, 1116 )
self.assertEqual( zo.getinfo('c').file_size, 32 )
self.assertEqual( zo.getinfo('d').file_size, 13 )
self.assertEqual( zo.getinfo('e').file_size, 20 )
self.assertEqual( zo.getinfo('f').file_size, 1625 )
zo.close()
os.unlink(zipf)
# Check second and third files have expected contents
zipf=tmpbase+'00001.zip'
zo=zipfile.ZipFile(zipf,'r')
self.assertEqual( zo.namelist(), ['manifest.xml','g','h','i','j','k','l'] )
zo.close()
os.unlink(zipf)
开发者ID:uweschmitt,项目名称:resync,代码行数:33,代码来源:test_dump.py
示例3: read_reference_resource_list
def read_reference_resource_list(self,ref_sitemap,name='reference'):
"""Read reference resource list and return the ResourceList object
name parameter just uses in output messages to say what type
of resource list is being read.
"""
rl = ResourceList()
self.logger.info("Reading reference %s resource list from %s ..." % (name,ref_sitemap))
rl.mapper=self.mapper
rl.read(uri=ref_sitemap,index_only=(not self.allow_multifile))
num_entries = len(rl.resources)
self.logger.info("Read %s resource list with %d entries in %d sitemaps" % (name,num_entries,rl.num_files))
if (self.verbose):
to_show = 100
override_str = ' (override with --max-sitemap-entries)'
if (self.max_sitemap_entries):
to_show = self.max_sitemap_entries
override_str = ''
if (num_entries>to_show):
print "Showing first %d entries sorted by URI%s..." % (to_show,override_str)
n=0
for r in rl.resources:
print r
n+=1
if ( n >= to_show ):
break
return(rl)
开发者ID:semantalytics,项目名称:resync,代码行数:27,代码来源:client.py
示例4: test00_dump_creation
def test00_dump_creation(self):
i = ResourceList()
i.add(Resource("http://ex.org/a", length=1, path="resync/test/testdata/a"))
i.add(Resource("http://ex.org/b", length=2, path="resync/test/testdata/b"))
d = Dump()
d.check_files(resource_list=i)
self.assertEqual(d.total_size, 28)
开发者ID:semantalytics,项目名称:resync,代码行数:7,代码来源:test_dump.py
示例5: test20_as_xml
def test20_as_xml(self):
rl = ResourceList()
rl.add( Resource('a',timestamp=1) )
rl.add( Resource('b',timestamp=2) )
xml = rl.as_xml()
self.assertTrue( re.search(r'<rs:md .*capability="resourcelist"', xml), 'XML has capability' )
self.assertTrue( re.search(r'<url><loc>a</loc><lastmod>1970-01-01T00:00:01Z</lastmod></url>', xml), 'XML has resource a' )
开发者ID:,项目名称:,代码行数:7,代码来源:
示例6: test_build_ex_01
def test_build_ex_01(self):
"""Simple Resource List document """
rl = ResourceList()
rl.md_at = '2013-01-03T09:00:00Z'
rl.add( Resource('http://example.com/res1') )
rl.add( Resource('http://example.com/res2') )
ex_xml = self._open_ex('resourcesync_ex_1').read()
self._assert_xml_equal( rl.as_xml(), ex_xml )
开发者ID:,项目名称:,代码行数:8,代码来源:
示例7: test_09_print_from_iter
def test_09_print_from_iter(self):
r1 = Resource(uri='a',lastmod='2001-01-01',length=1234)
r2 = Resource(uri='b',lastmod='2002-02-02',length=56789)
m = ResourceList()
m.add(r1)
m.add(r2)
i = iter(m)
self.assertEqual( Sitemap().resources_as_xml(i), "<?xml version='1.0' encoding='UTF-8'?>\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\" xmlns:rs=\"http://www.openarchives.org/rs/terms/\"><url><loc>a</loc><lastmod>2001-01-01T00:00:00Z</lastmod><rs:md length=\"1234\" /></url><url><loc>b</loc><lastmod>2002-02-02T00:00:00Z</lastmod><rs:md length=\"56789\" /></url></urlset>")
开发者ID:,项目名称:,代码行数:8,代码来源:
示例8: test_ex_01
def test_ex_01(self):
"""resourcesync_ex_1 is a simple resource_list with 2 resources, no metadata"""
rl=ResourceList()
rl.parse(uri='tests/testdata/examples_from_spec/resourcesync_ex_1.xml')
self.assertEqual( rl.capability, 'resourcelist' )
self.assertEqual( len(rl.resources), 2, '2 resources')
sms = sorted(rl.uris())
self.assertEqual( sms, ['http://example.com/res1','http://example.com/res2'] )
self.assertEqual( rl.resources['http://example.com/res1'].lastmod, None )
开发者ID:,项目名称:,代码行数:9,代码来源:
示例9: test_08_print_non_ascii_uri
def test_08_print_non_ascii_uri(self):
"""Verify that valid Unicode uri values give good XML out."""
m = ResourceList(md={'capability': 'resourcelist', 'modified': None})
m.add(Resource(uri=u'a_\u00c3_b'))
m.add(Resource(uri=u'c_\u1234_d'))
xml = Sitemap().resources_as_xml(m)
self.assertTrue(re.search(u'<loc>a_.*_b</loc>', xml))
self.assertTrue(re.search(u'<loc>a_\u00c3_b</loc>', xml))
self.assertTrue(re.search(u'<loc>c_\u1234_d</loc>', xml))
开发者ID:resync,项目名称:resync,代码行数:9,代码来源:test_sitemap.py
示例10: test20_as_xml
def test20_as_xml(self):
rl = ResourceList()
rl.add( Resource('a',timestamp=1) )
rl.add( Resource('b',timestamp=2) )
xml = rl.as_xml()
print xml
self.assertTrue( re.search(r'<rs:md .*capability="resourcelist"', xml), 'XML has capability' )
self.assertTrue( re.search(r'<rs:md .*modified="\d\d\d\d\-\d\d\-\d\dT\d\d:\d\d:\d\dZ"', xml), 'XML has modified to seconds precision (and not more)' )
self.assertTrue( re.search(r'<url><loc>a</loc><lastmod>1970-01-01T00:00:01Z</lastmod></url>', xml), 'XML has resource a' )
开发者ID:semantalytics,项目名称:resync,代码行数:9,代码来源:test_resource_list.py
示例11: test_ex_08
def test_ex_08(self):
"""resourcesync_ex_8 is a simple Resource List Index with 2 Resource Lists"""
rl=ResourceList()
rl.read(uri='tests/testdata/examples_from_spec/resourcesync_ex_8.xml',index_only=True)
self.assertEqual( rl.capability, 'resourcelist' )
self.assertEqual( rl.md_at, '2013-01-03T09:00:00Z' )
self.assertEqual( len(rl.resources), 2, '2 resources')
sms = sorted(rl.uris())
self.assertEqual( sms, ['http://example.com/resourcelist-part1.xml',
'http://example.com/resourcelist-part2.xml'] )
开发者ID:,项目名称:,代码行数:10,代码来源:
示例12: test_08_print
def test_08_print(self):
r1 = Resource(uri='a',lastmod='2001-01-01',length=1234)
r2 = Resource(uri='b',lastmod='2002-02-02',length=56789)
r3 = Resource(uri='c',lastmod='2003-03-03',length=0)
m = ResourceList(md={'capability':'resourcelist','modified':None})
m.add(r1)
m.add(r2)
m.add(r3)
#print m
self.assertEqual( Sitemap().resources_as_xml(m), "<?xml version='1.0' encoding='UTF-8'?>\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\" xmlns:rs=\"http://www.openarchives.org/rs/terms/\"><rs:md capability=\"resourcelist\" /><url><loc>a</loc><lastmod>2001-01-01T00:00:00Z</lastmod><rs:md length=\"1234\" /></url><url><loc>b</loc><lastmod>2002-02-02T00:00:00Z</lastmod><rs:md length=\"56789\" /></url><url><loc>c</loc><lastmod>2003-03-03T00:00:00Z</lastmod><rs:md length=\"0\" /></url></urlset>")
开发者ID:,项目名称:,代码行数:10,代码来源:
示例13: test_01_read_local_filenames
def test_01_read_local_filenames(self):
rl = ResourceList()
rl.read('tests/testdata/sitemapindex2/sitemap.xml')
self.assertEqual( len(rl.resources), 17, '17 resources from 3 sitemaps listed')
sr = sorted(rl.uris())
self.assertEqual( sr[0], 'http://localhost:8888/resources/1' )
self.assertEqual( sr[1], 'http://localhost:8888/resources/10' )
self.assertEqual( sr[2], 'http://localhost:8888/resources/100' )
self.assertEqual( sr[3], 'http://localhost:8888/resources/1000' )
self.assertEqual( sr[16], 'http://localhost:8888/resources/826' )
开发者ID:,项目名称:,代码行数:10,代码来源:
示例14: test31_parse_no_capability
def test31_parse_no_capability(self):
xml='<?xml version=\'1.0\' encoding=\'UTF-8\'?>\n\
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\
<url><loc>http://example.com/res1</loc><lastmod>2012-03-14T18:37:36Z</lastmod></url>\
</urlset>'
rl=ResourceList()
rl.parse(fh=io.StringIO(xml))
self.assertEqual( len(rl.resources), 1, 'got 1 resource')
self.assertEqual( rl.md['capability'], 'resourcelist', 'capability set by reading routine' )
self.assertFalse( 'from' in rl.md )
开发者ID:,项目名称:,代码行数:10,代码来源:
示例15: test06_add_changed_resources
def test06_add_changed_resources(self):
added = ResourceList()
added.add( Resource('a',timestamp=1,change='created') )
added.add( Resource('d',timestamp=4,change='created') )
self.assertEqual(len(added), 2, "2 things in added resource_list")
changes = ChangeList()
changes.add_changed_resources( added, change='created' )
self.assertEqual(len(changes), 2, "2 things added")
i = iter(changes)
first = next(i)
self.assertEqual(first.uri, 'a', "changes[0].uri=a")
self.assertEqual(first.timestamp, 1, "changes[0].timestamp=1")
self.assertEqual(first.change, 'created') #, "changes[0].change=createdd")
second = next(i)
self.assertEqual(second.timestamp, 4, "changes[1].timestamp=4")
self.assertEqual(second.change, 'created', "changes[1].change=createdd")
# Now add some with updated (one same, one diff)
updated = ResourceList()
updated.add( Resource('a',timestamp=5,change='created') )
updated.add( Resource('b',timestamp=6,change='created') )
self.assertEqual(len(updated), 2, "2 things in updated resource_list")
changes.add_changed_resources( updated, change='updated' )
self.assertEqual(len(changes), 4, "4 = 2 old + 2 things updated")
# Make new resource_list from the changes which should not have dupes
dst = ResourceList()
dst.add( changes, replace=True )
self.assertEqual(len(dst), 3, "3 unique resources")
self.assertEqual(dst.resources['a'].timestamp, 5 ) # 5 was later in last the 1
self.assertEqual(dst.resources['a'].change, 'updated')
self.assertEqual(dst.resources['b'].timestamp, 6)
self.assertEqual(dst.resources['b'].change, 'updated')
self.assertEqual(dst.resources['d'].timestamp, 4)
self.assertEqual(dst.resources['d'].change, 'created')
开发者ID:,项目名称:,代码行数:33,代码来源:
示例16: test_ex_02
def test_ex_02(self):
"""resourcesync_ex_2 is a simple resource_list with 2 resources, some metadata"""
rl=ResourceList()
rl.parse(uri='tests/testdata/examples_from_spec/resourcesync_ex_2.xml')
self.assertEqual( len(rl.resources), 2, '2 resources')
sms = sorted(rl.uris())
self.assertEqual( sms, ['http://example.com/res1','http://example.com/res2'] )
self.assertEqual( rl.resources['http://example.com/res1'].lastmod, '2013-01-02T13:00:00Z' )
self.assertEqual( rl.resources['http://example.com/res2'].lastmod, '2013-01-02T14:00:00Z' )
self.assertEqual( rl.resources['http://example.com/res1'].md5, '1584abdf8ebdc9802ac0c6a7402c03b6' )
self.assertEqual( rl.resources['http://example.com/res2'].md5, '1e0d5cb8ef6ba40c99b14c0237be735e' )
开发者ID:,项目名称:,代码行数:11,代码来源:
示例17: test_02_read_with_mapper
def test_02_read_with_mapper(self):
rl = ResourceList()
rl.mapper = Mapper(['http://localhost/=tests/testdata/sitemapindex2/'])
rl.read('tests/testdata/sitemapindex2/sitemap_mapper.xml')
self.assertEqual( len(rl.resources), 17, '17 resources from 3 sitemaps listed')
sr = sorted(rl.uris())
self.assertEqual( sr[0], 'http://localhost:8888/resources/1' )
self.assertEqual( sr[1], 'http://localhost:8888/resources/10' )
self.assertEqual( sr[2], 'http://localhost:8888/resources/100' )
self.assertEqual( sr[3], 'http://localhost:8888/resources/1000' )
self.assertEqual( sr[16], 'http://localhost:8888/resources/826' )
开发者ID:,项目名称:,代码行数:11,代码来源:
示例18: test30_parse
def test30_parse(self):
xml='<?xml version=\'1.0\' encoding=\'UTF-8\'?>\n\
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:rs="http://www.openarchives.org/rs/terms/">\
<rs:md capability="resourcelist" modified="2013-01-01"/>\
<url><loc>/tmp/rs_test/src/file_a</loc><lastmod>2012-03-14T18:37:36Z</lastmod><rs:md change="updated" length="12" /></url>\
<url><loc>/tmp/rs_test/src/file_b</loc><lastmod>2012-03-14T18:37:36Z</lastmod><rs:md length="32" /></url>\
</urlset>'
rl=ResourceList()
rl.parse(fh=StringIO.StringIO(xml))
self.assertEqual( len(rl.resources), 2, 'got 2 resources')
self.assertEqual( rl.md['capability'], 'resourcelist', 'capability set' )
self.assertEqual( rl.md['modified'], '2013-01-01' )
开发者ID:semantalytics,项目名称:resync,代码行数:12,代码来源:test_resource_list.py
示例19: test06_add_iterable
def test06_add_iterable(self):
r1 = Resource(uri='a',length=1)
r2 = Resource(uri='b',length=2)
i = ResourceList()
i.add( [r1,r2] )
self.assertRaises( ResourceListDupeError, i.add, r1)
self.assertRaises( ResourceListDupeError, i.add, r2)
# allow dupes
r1d = Resource(uri='a',length=10)
i.add( [r1d] ,replace=True)
self.assertEqual( len(i), 2 )
self.assertEqual( i.resources['a'].length, 10 )
开发者ID:,项目名称:,代码行数:12,代码来源:
示例20: test08_iter
def test08_iter(self):
i = ResourceList()
i.add( Resource('a',timestamp=1) )
i.add( Resource('b',timestamp=2) )
i.add( Resource('c',timestamp=3) )
i.add( Resource('d',timestamp=4) )
resources=[]
for r in i:
resources.append(r)
self.assertEqual(len(resources), 4)
self.assertEqual( resources[0].uri, 'a')
self.assertEqual( resources[3].uri, 'd')
开发者ID:,项目名称:,代码行数:12,代码来源:
注:本文中的resync.resource_list.ResourceList类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论