Improve handling of rs:ln type attribute
This commit is contained in:
parent
2615bef183
commit
bbcdcf6c3c
@ -95,15 +95,22 @@ class ResourceContainer(object):
|
||||
link = link['href']
|
||||
return(link)
|
||||
|
||||
def link_set(self,rel,uri):
|
||||
"""Set/create link with specified rel, and set href to uri"""
|
||||
def link_set(self,rel,href,**atts):
|
||||
"""Set/create link with specified rel, set href and any other attributes
|
||||
|
||||
Any link element must have both rel and href values, the specification
|
||||
also defines the type attributes and others are permitted also
|
||||
"""
|
||||
link = self.link(rel)
|
||||
if (link is not None):
|
||||
# overwrite current value
|
||||
link['href'] = uri
|
||||
link['href'] = href
|
||||
else:
|
||||
# create new link
|
||||
self.ln.append({'rel':rel,'href':uri})
|
||||
link = {'rel':rel,'href':href}
|
||||
self.ln.append(link)
|
||||
for k in atts:
|
||||
link[k] = atts[k]
|
||||
|
||||
@property
|
||||
def description(self):
|
||||
|
||||
@ -133,15 +133,14 @@ class TestExamplesFromSpec(unittest.TestCase):
|
||||
def test_build_ex_2_7(self):
|
||||
""" A ResourceSync Description document """
|
||||
rsd = ResourceSyncDescription()
|
||||
rsd.describedby='http://example.com/info-about-source.xml'
|
||||
## this is only example in spec with content-type on top-level ln
|
||||
rsd.link('describedby')['type']='application/xml'
|
||||
rsd.link_set( rel='describedby',
|
||||
href='http://example.com/info-about-source.xml',
|
||||
type='application/xml' )
|
||||
rsd.md_from=None
|
||||
r = Resource( uri='http://example.com/dataset1/capabilitylist.xml',
|
||||
capability='capabilitylist' )
|
||||
r.ln = []
|
||||
r.ln.append({'rel':'describedby',
|
||||
'href':'http://example.com/info_about_set1_of_resources.xml'})
|
||||
r.link_add( rel='describedby',
|
||||
href='http://example.com/info_about_set1_of_resources.xml' )
|
||||
rsd.add( r )
|
||||
ex_xml = self._open_ex('resourcesync_ex_2_7').read()
|
||||
self._assert_xml_equal( rsd.as_xml(), ex_xml )
|
||||
|
||||
Loading…
Reference in New Issue
Block a user