本文整理汇总了Python中resync.resource.Resource类的典型用法代码示例。如果您正苦于以下问题:Python Resource类的具体用法?Python Resource怎么用?Python Resource使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Resource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test13_mime_type
def test13_mime_type(self):
r = Resource(uri='tv1', mime_type='text/plain')
self.assertEqual( r.mime_type, 'text/plain' )
r.mime_type = None
self.assertEqual( r.mime_type, None )
r = Resource(uri='tv2')
self.assertEqual( r.mime_type, None )
示例2: test1c_same
def test1c_same(self):
"""Same with lastmod instead of direct timestamp"""
r1 = Resource("a")
r1lm = "2012-01-01T00:00:00Z"
r1.lastmod = r1lm
r2 = Resource("a")
for r2lm in (
"2012",
"2012-01",
"2012-01-01",
"2012-01-01T00:00Z",
"2012-01-01T00:00:00Z",
"2012-01-01T00:00:00.000000Z",
"2012-01-01T00:00:00.000000000000Z",
"2012-01-01T00:00:00.000000000001Z", # below resolution
"2012-01-01T00:00:00.00+00:00",
"2012-01-01T00:00:00.00-00:00",
"2012-01-01T02:00:00.00-02:00",
"2011-12-31T23:00:00.00+01:00",
):
r2.lastmod = r2lm
self.assertEqual(
r1.timestamp, r2.timestamp, ("%s (%f) == %s (%f)" % (r1lm, r1.timestamp, r2lm, r2.timestamp))
)
self.assertEqual(r1, r2)
示例3: test_01_resource_str
def test_01_resource_str(self):
r1 = Resource("a3")
r1.lastmod = "2012-01-11T01:02:03"
self.assertEqual(
Sitemap().resource_as_xml(r1),
"<?xml version='1.0' encoding='UTF-8'?>\n<url><loc>a3</loc><lastmod>2012-01-11T01:02:03</lastmod></url>",
)
示例4: test01d_same
def test01d_same(self):
"""Same with slight timestamp diff"""
r1 = Resource('a')
r1.lastmod='2012-01-02T01:02:03Z'
r2 = Resource('a')
r2.lastmod='2012-01-02T01:02:03.99Z'
self.assertNotEqual( r1.timestamp, r2.timestamp )
self.assertEqual( r1, r2 )
示例5: test1d_same
def test1d_same(self):
"""Same with slight timestamp diff"""
r1 = Resource("a")
r1.lastmod = "2012-01-02T01:02:03Z"
r2 = Resource("a")
r2.lastmod = "2012-01-02T01:02:03.99Z"
self.assertNotEqual(r1.timestamp, r2.timestamp)
self.assertEqual(r1, r2)
示例6: test_03_resource_str_hashes
def test_03_resource_str_hashes(self):
r1 = Resource('03hashes',1234.1)
r1.md5 = 'aaa'
r1.sha1 = 'bbb'
self.assertEqual( Sitemap().resource_as_xml(r1), "<url><loc>03hashes</loc><lastmod>1970-01-01T00:20:34.100000Z</lastmod><rs:md hash=\"md5:aaa sha-1:bbb\" /></url>" )
r1.sha256 = 'ccc'
self.assertEqual( Sitemap().resource_as_xml(r1), "<url><loc>03hashes</loc><lastmod>1970-01-01T00:20:34.100000Z</lastmod><rs:md hash=\"md5:aaa sha-1:bbb sha-256:ccc\" /></url>" )
r1.sha1 = None
self.assertEqual( Sitemap().resource_as_xml(r1), "<url><loc>03hashes</loc><lastmod>1970-01-01T00:20:34.100000Z</lastmod><rs:md hash=\"md5:aaa sha-256:ccc\" /></url>" )
示例7: test10_md_at_roundtrips
def test10_md_at_roundtrips(self):
r = Resource('a')
r.md_at='2013-03-14'
self.assertEqual( r.md_at, '2013-03-14T00:00:00Z' )
r.md_at='2013-03-14T00:00:00+00:00'
self.assertEqual( r.md_at, '2013-03-14T00:00:00Z' )
r.md_at='2013-03-14T00:00:00-00:00'
self.assertEqual( r.md_at, '2013-03-14T00:00:00Z' )
r.md_at='2013-03-14T18:37:36Z'
self.assertEqual( r.md_at, '2013-03-14T18:37:36Z' )
示例8: test11_md_completed_roundtrips
def test11_md_completed_roundtrips(self):
r = Resource('a')
r.md_completed='2013-04-14'
self.assertEqual( r.md_completed, '2013-04-14T00:00:00Z' )
r.md_completed='2013-04-14T00:00:00+00:00'
self.assertEqual( r.md_completed, '2013-04-14T00:00:00Z' )
r.md_completed='2013-04-14T00:00:00-00:00'
self.assertEqual( r.md_completed, '2013-04-14T00:00:00Z' )
r.md_completed='2013-04-14T18:37:36Z'
self.assertEqual( r.md_completed, '2013-04-14T18:37:36Z' )
示例9: test6_has_md5
def test6_has_md5(self):
r1 = Resource(uri="a")
r2 = Resource(uri="b")
m = Inventory()
self.assertFalse(m.has_md5())
m.add(r1)
m.add(r2)
self.assertFalse(m.has_md5())
r1.md5 = "aabbcc"
self.assertTrue(m.has_md5())
示例10: test09_changetypeerror
def test09_changetypeerror(self):
r1 = Resource('a')
self.assertEqual( r1.change, None )
r1.change = 'deleted'
self.assertEqual( r1.change, 'deleted' )
self.assertRaises( ChangeTypeError, Resource, 'a', change="bad" )
# disable checking
Resource.CHANGE_TYPES = False
r1 = Resource( 'a', change="bad" )
self.assertEqual( r1.change, 'bad' )
示例11: test6_has_md5
def test6_has_md5(self):
r1 = Resource(uri='a')
r2 = Resource(uri='b')
i = ResourceList()
self.assertFalse( i.has_md5() )
i.add(r1)
i.add(r2)
self.assertFalse( i.has_md5() )
r1.md5="aabbcc"
self.assertTrue( i.has_md5() )
示例12: test_build_ex_17
def test_build_ex_17(self):
"""Resource Dump with 3 entries and some metadata"""
rd = ResourceDump()
rd.up='http://example.com/dataset1/capabilitylist.xml'
rd.md_at="2013-01-03T09:00:00Z"
rd.md_completed="2013-01-03T09:04:00Z"
z1 = Resource( uri='http://example.com/resourcedump-part1.zip',
mime_type="application/zip",
length=4765,
md_at="2013-01-03T09:00:00Z",
md_completed="2013-01-03T09:02:00Z" )
z1.link_set( rel="contents",
href="http://example.com/resourcedump_manifest-part1.xml",
mime_type="application/xml" )
rd.add( z1 )
z2 = Resource( uri='http://example.com/resourcedump-part2.zip',
mime_type="application/zip",
length=9875,
md_at="2013-01-03T09:01:00Z",
md_completed="2013-01-03T09:03:00Z" )
z2.link_set( rel="contents",
href="http://example.com/resourcedump_manifest-part2.xml",
mime_type="application/xml" )
rd.add( z2 )
z3 = Resource( uri='http://example.com/resourcedump-part3.zip',
mime_type="application/zip",
length=2298,
md_at="2013-01-03T09:03:00Z",
md_completed="2013-01-03T09:04:00Z" )
z3.link_set( rel="contents",
href="http://example.com/resourcedump_manifest-part3.xml",
mime_type="application/xml" )
rd.add( z3 )
ex_xml = self._open_ex('resourcesync_ex_17').read()
self._assert_xml_equal( rd.as_xml(), ex_xml )
示例13: test_build_ex_07
def test_build_ex_07(self):
"""A Source Description document """
sd = SourceDescription()
sd.describedby = 'http://example.com/info-about-source.xml'
r = Resource( uri='http://example.com/dataset1/capabilitylist.xml',
capability='capabilitylist' )
r.link_set( rel='describedby',
href='http://example.com/info_about_set1_of_resources.xml' )
sd.add( r )
ex_xml = self._open_ex('resourcesync_ex_7').read()
self._assert_xml_equal( sd.as_xml(), ex_xml )
示例14: test_04_resource_str
def test_04_resource_str(self):
r1 = Resource(uri='4a',lastmod="2013-01-02",length=9999,md5='ab54de')
r1.ln = [{ 'rel':'duplicate',
'pri':'1',
'href':'http://mirror1.example.com/res1',
'modified':'2013-01-02T18:00:00Z' }]
self.assertEqual( Sitemap().resource_as_xml(r1), "<url><loc>4a</loc><lastmod>2013-01-02T00:00:00Z</lastmod><rs:md hash=\"md5:ab54de\" length=\"9999\" /><rs:ln href=\"http://mirror1.example.com/res1\" modified=\"2013-01-02T18:00:00Z\" pri=\"1\" rel=\"duplicate\" /></url>" )
# add another two rs:ln's
r1.ln.append( { 'rel':'num2' } )
r1.ln.append( { 'rel':'num3' } )
self.assertEqual( Sitemap().resource_as_xml(r1), "<url><loc>4a</loc><lastmod>2013-01-02T00:00:00Z</lastmod><rs:md hash=\"md5:ab54de\" length=\"9999\" /><rs:ln href=\"http://mirror1.example.com/res1\" modified=\"2013-01-02T18:00:00Z\" pri=\"1\" rel=\"duplicate\" /><rs:ln rel=\"num2\" /><rs:ln rel=\"num3\" /></url>" )
示例15: test07_hashes
def test07_hashes(self):
r1 = Resource(uri='a')
r2 = Resource(uri='b')
i = ResourceList()
self.assertEqual(i.hashes(), set())
i.add(r1)
i.add(r2)
self.assertEqual(i.hashes(), set())
r1.md5 = "aabbcc"
self.assertEqual(i.hashes(), set(['md5']))
r2.sha1 = "ddeeff"
self.assertEqual(i.hashes(), set(['md5', 'sha-1']))