當前位置: 首頁>>代碼示例>>Python>>正文


Python change_list.ChangeList類代碼示例

本文整理匯總了Python中resync.change_list.ChangeList的典型用法代碼示例。如果您正苦於以下問題:Python ChangeList類的具體用法?Python ChangeList怎麽用?Python ChangeList使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了ChangeList類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test02_dump_check_files

 def test02_dump_check_files(self):
     cl=ChangeList()
     cl.add( Resource('http://ex.org/a', length=7, path='resync/test/testdata/a', change="updated") )
     cl.add( Resource('http://ex.org/b', length=21, path='resync/test/testdata/b', change="updated") )
     d=Dump(resources=cl)
     self.assertTrue(d.check_files())
     self.assertEqual(d.total_size, 28)
開發者ID:uweschmitt,項目名稱:resync,代碼行數:7,代碼來源:test_dump.py

示例2: 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,代碼來源:

示例3: test07_as_xml

 def test07_as_xml(self):
     cl = ChangeList()
     cl.md_from = '1970-01-01T00:00:00Z'
     cl.add( Resource('a',timestamp=1,change='updated') )
     cl.add( Resource('b',timestamp=2,change='updated') )
     xml = cl.as_xml()
     self.assertTrue( re.search(r'<rs:md .*capability="changelist"', xml), 'XML has capability' )
     self.assertTrue( re.search(r'<rs:md .*from="\d\d\d\d\-\d\d\-\d\dT\d\d:\d\d:\d\dZ"', xml), 'XML has from to seconds precision (and not more)' )
     self.assertTrue( re.search(r'<url><loc>a</loc><lastmod>1970-01-01T00:00:01Z</lastmod>', xml), 'XML has resource a' ) 
開發者ID:,項目名稱:,代碼行數:9,代碼來源:

示例4: write_change_list

 def write_change_list(self,outfile=None,ref_sitemap=None,newref_sitemap=None,
                       empty=None,links=None,dump=None):
     cl = ChangeList(ln=links)
     if (not empty):
         # 1. Get and parse reference sitemap
         old_rl = self.read_reference_resource_list(ref_sitemap)
         # 2. Depending on whether a newref_sitemap was specified, either read that 
         # or build resource_list from files on disk
         if (newref_sitemap is None):
             # Get resource list from disk
             new_rl = self.resource_list
         else:
             new_rl = self.read_reference_resource_list(newref_sitemap,name='new reference')
         # 3. Calculate change list
         (same,updated,deleted,created)=old_rl.compare(new_rl)   
         cl.add_changed_resources( updated, change='updated' )
         cl.add_changed_resources( deleted, change='deleted' )
         cl.add_changed_resources( created, change='created' )
     # 4. Write out change list
     kwargs = { 'pretty_xml': True,
                'mapper' : self.mapper }
     if (self.max_sitemap_entries is not None):
         kwargs['max_sitemap_entries'] = self.max_sitemap_entries
     if (outfile is None):
         print cl.as_xml(**kwargs)
     else:
         cl.write(basename=outfile,**kwargs)
     self.write_dump_if_requested(cl,dump)
開發者ID:semantalytics,項目名稱:resync,代碼行數:28,代碼來源:client.py

示例5: test_ex_03

 def test_ex_03(self):
     """resourcesync_ex_3 is a simple change_list with 2 resources"""
     cl=ChangeList()
     cl.parse('tests/testdata/examples_from_spec/resourcesync_ex_3.xml')
     self.assertEqual( len(cl.resources), 2, '2 resources')
     sms = sorted(cl.uris())
     self.assertEqual( sms, ['http://example.com/res2.pdf','http://example.com/res3.tiff'] )
     self.assertEqual( cl.resources[0].lastmod, '2013-01-02T13:00:00Z' )
     self.assertEqual( cl.resources[1].lastmod, '2013-01-02T18:00:00Z' )
     self.assertEqual( cl.resources[0].change, 'updated' )
     self.assertEqual( cl.resources[1].change, 'deleted' )
開發者ID:,項目名稱:,代碼行數:11,代碼來源:

示例6: test03_with_repeats_again

 def test03_with_repeats_again(self):
     r1 = Resource(uri='a',length=1,change='created')
     r2 = Resource(uri='b',length=2,change='created')
     i = ChangeList()
     i.add(r1)
     i.add(r2)
     self.assertEqual( len(i), 2 )
     # Can add another Resource with same URI
     r1d = Resource(uri='a',length=10,change='created')
     i.add(r1d)
     self.assertEqual( len(i), 3 )
開發者ID:,項目名稱:,代碼行數:11,代碼來源:

示例7: test3_change_list

 def test3_change_list(self):
     src = ChangeList()
     src.add( Resource('a',timestamp=1) )
     src.add( Resource('b',timestamp=2) )
     src.add( Resource('c',timestamp=3) )
     src.add( Resource('d',timestamp=4)) 
     src.add( Resource('e',timestamp=5) )
     self.assertEqual(len(src), 5, "5 things in src")
開發者ID:semantalytics,項目名稱:resync,代碼行數:8,代碼來源:test_change_list.py

示例8: test4_iter

 def test4_iter(self):
     i = ChangeList()
     i.add(Resource("a", timestamp=1, change="created"))
     i.add(Resource("b", timestamp=2, change="created"))
     i.add(Resource("c", timestamp=3, change="created"))
     i.add(Resource("d", timestamp=4, change="created"))
     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:EHRI,項目名稱:resync,代碼行數:12,代碼來源:test_change_list.py

示例9: test4_iter

 def test4_iter(self):
     i = ChangeList()
     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:semantalytics,項目名稱:resync,代碼行數:12,代碼來源:test_change_list.py

示例10: test08_parse

    def test08_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="changelist" from="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 change="deleted" length="32" /></url>\
</urlset>'
        cl=ChangeList()
        cl.parse(fh=io.StringIO(xml))
        self.assertEqual( len(cl.resources), 2, 'got 2 resources')
        self.assertEqual( cl.md['capability'], 'changelist', 'capability set' )
        self.assertEqual( cl.md['md_from'], '2013-01-01' )
開發者ID:,項目名稱:,代碼行數:12,代碼來源:

示例11: test05_iter

 def test05_iter(self):
     i = ChangeList()
     i.add( Resource('a',timestamp=1,change='created') )
     i.add( Resource('b',timestamp=2,change='created') )
     i.add( Resource('c',timestamp=3,change='created') )
     i.add( Resource('d',timestamp=4,change='created') )
     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,代碼來源:

示例12: test20_as_xml

 def test20_as_xml(self):
     cl = ChangeList()
     cl.md_from = "1970-01-01T00:00:00Z"
     cl.add(Resource("a", timestamp=1, change="updated"))
     cl.add(Resource("b", timestamp=2, change="updated"))
     xml = cl.as_xml()
     self.assertTrue(re.search(r'<rs:md .*capability="changelist"', xml), "XML has capability")
     self.assertTrue(
         re.search(r'<rs:md .*from="\d\d\d\d\-\d\d\-\d\dT\d\d:\d\d:\d\dZ"', xml),
         "XML has from to seconds precision (and not more)",
     )
     self.assertTrue(
         re.search(r"<url><loc>a</loc><lastmod>1970-01-01T00:00:01Z</lastmod>", xml), "XML has resource a"
     )
開發者ID:EHRI,項目名稱:resync,代碼行數:14,代碼來源:test_change_list.py

示例13: test1_set_with_repeats

 def test1_set_with_repeats(self):
     src = ChangeList()
     src.add( Resource('a',timestamp=1) )
     src.add( Resource('b',timestamp=1) )
     src.add( Resource('c',timestamp=1) )
     src.add( Resource('a',timestamp=2) )
     src.add( Resource('b',timestamp=2) )
     self.assertEqual(len(src), 5, "5 changes in change_list")
開發者ID:semantalytics,項目名稱:resync,代碼行數:8,代碼來源:test_change_list.py

示例14: test3_change_list

 def test3_change_list(self):
     src = ChangeList()
     src.add(Resource("a", timestamp=1, change="created"))
     src.add(Resource("b", timestamp=2, change="created"))
     src.add(Resource("c", timestamp=3, change="created"))
     src.add(Resource("d", timestamp=4, change="created"))
     src.add(Resource("e", timestamp=5, change="created"))
     self.assertEqual(len(src), 5, "5 things in src")
開發者ID:EHRI,項目名稱:resync,代碼行數:8,代碼來源:test_change_list.py

示例15: test04_change_list

 def test04_change_list(self):
     cl = ChangeList()
     cl.add( Resource('a',timestamp=1,change='created') )
     cl.add( Resource('b',timestamp=2,change='created') )
     cl.add( Resource('c',timestamp=3,change='created') )
     cl.add( Resource('d',timestamp=4,change='created') ) 
     cl.add( Resource('e',timestamp=5,change='created') )
     self.assertEqual(len(cl), 5, "5 things in src")
開發者ID:,項目名稱:,代碼行數:8,代碼來源:


注:本文中的resync.change_list.ChangeList類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。