diff --git a/CHANGES.md b/CHANGES.md index 1154f03..4a30993 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,9 +6,11 @@ core specification version. Versions 1.0.x implement the v1.0 ResourceSync specification which was standardized as ANSI/NISO Z39.99-2014 . -v1.0.1 2016-01-30 +v1.0.1 2016-03-22 * Improved test coverage * Use defusedxml for safer XML parsing + * Changed parameter str to str_data in ListBase.parse(), str still supported + but deprecated. Issue pointed out by @uweschmitt v1.0.0 2014-06-18 * Update for v1.0, Z39.99-2014 specification (http://www.openarchives.org/rs/1.0/) diff --git a/README b/README index b7da115..2d6be15 100644 --- a/README +++ b/README @@ -2,7 +2,7 @@ resync ====== -.. image:: https://travis-ci.org/resync/resync.png?branch=master +.. image:: https://travis-ci.org/resync/resync.png?branch=1.0.1 :target: https://travis-ci.org/resync/resync :alt: Build status diff --git a/resync/list_base.py b/resync/list_base.py index 735e62d..865e1c5 100644 --- a/resync/list_base.py +++ b/resync/list_base.py @@ -82,22 +82,29 @@ class ListBase(ResourceContainer): """ self.parse(uri=uri) - def parse(self,uri=None,fh=None,str=None): + def parse(self,uri=None,fh=None,str_data=None,**kwargs): """Parse a single XML document for this list Accepts either a uri (uri or default if parameter not specified), - or a filehandle (fh) or a string (str). + or a filehandle (fh) or a string (str_data). Note that this method + does not handle the case of a sitemapindex+sitemaps. - Does not handle the case of sitemapindex+sitemaps + LEGACY SUPPORT - the parameter str may be used in place of str_data + but is deprecated and will be removed in a later version. """ if (uri is not None): try: fh = URLopener().open(uri) except IOError as e: - msg = __builtins__.str(e) - raise Exception("Failed to load sitemap/sitemapindex from %s (%s)" % (uri, e)) - elif (str is not None): - fh=StringIO.StringIO(str) + raise Exception("Failed to load sitemap/sitemapindex from %s (%s)" % (uri,str(e))) + elif (str_data is not None): + fh=io.StringIO(str_data) + elif ('str' in kwargs): + # Legacy support for str argument, see + # https://github.com/resync/resync/pull/21 + # One test for this in tests/test_list_base.py + self.logger.warn("Legacy parse(str=...), use parse(str_data=...) instead") + fh = io.StringIO(kwargs['str']) if (fh is None): raise Exception("Nothing to parse") s = self.new_sitemap() diff --git a/tests/test_capability_list.py b/tests/test_capability_list.py index 1aae2d2..b821683 100644 --- a/tests/test_capability_list.py +++ b/tests/test_capability_list.py @@ -29,7 +29,7 @@ class TestCapabilityList(unittest.TestCase): def test03_parse(self): xml='\nhttp://example.org/resourcelist.xml' cl=CapabilityList() - cl.parse(str=xml) + cl.parse(str_data=xml) self.assertEqual( cl.capability, 'capabilitylist') self.assertEqual( len(cl.resources), 1, 'got 1 resource') [r] = cl.resources diff --git a/tests/test_list_base.py b/tests/test_list_base.py index 21bd31f..9c6d758 100644 --- a/tests/test_list_base.py +++ b/tests/test_list_base.py @@ -47,9 +47,18 @@ class TestListBase(unittest.TestCase): /tmp/rs_test/src/file_a2012-03-14T18:37:36Z\ /tmp/rs_test/src/file_b2012-03-14T18:37:36Z\ ' - lb=ListBase() - lb.parse(fh=io.StringIO(xml)) - self.assertEqual( len(lb.resources), 2, 'got 2 resources') + # parse from string + lb1=ListBase() + lb1.parse(str_data=xml) + self.assertEqual( len(lb1.resources), 2, 'got 2 resources') + # parse from fh + lb2=ListBase() + lb2.parse(fh=io.StringIO(xml)) + self.assertEqual( len(lb2.resources), 2, 'got 2 resources') + # parse from string (LEGACY parameter name, to be removed) + lb3=ListBase() + lb3.parse(str=xml) + self.assertEqual( len(lb3.resources), 2, 'got 2 resources') if __name__ == '__main__': suite = unittest.TestLoader().loadTestsFromTestCase(TestListBase) diff --git a/tests/test_source_description.py b/tests/test_source_description.py index 1323daf..bb97bf8 100644 --- a/tests/test_source_description.py +++ b/tests/test_source_description.py @@ -34,7 +34,7 @@ class TestSourceDescription(unittest.TestCase): def test04_parse(self): xml='\nhttp://example.org/ds1/cl.xmlhttp://example.org/ds2/cl.xmlhttp://example.org/ds3/cl.xml' sd=SourceDescription() - sd.parse(str=xml) + sd.parse(str_data=xml) self.assertEqual( sd.link_href('describedby'), 'http://example.org/about', 'describedby link' ) self.assertEqual( sd.capability, 'description' )