diff --git a/resync/resource_container.py b/resync/resource_container.py index 4cb5e2f..8e7d8b9 100644 --- a/resync/resource_container.py +++ b/resync/resource_container.py @@ -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): diff --git a/resync/test/test_examples_from_spec.py b/resync/test/test_examples_from_spec.py index a36bd96..0a29aa2 100644 --- a/resync/test/test_examples_from_spec.py +++ b/resync/test/test_examples_from_spec.py @@ -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 )