From: Philipp Hagemeister Date: Wed, 22 Jan 2014 19:00:16 +0000 (+0100) Subject: Merge branch 'paged-lists' X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=65697b3bf3bf6eaeb91a34e5308a6d2239118071;p=youtube-dl Merge branch 'paged-lists' Conflicts: test/test_utils.py youtube_dl/extractor/youtube.py --- 65697b3bf3bf6eaeb91a34e5308a6d2239118071 diff --cc test/test_utils.py index a17483ada,349c1107f..c68e0e968 --- a/test/test_utils.py +++ b/test/test_utils.py @@@ -16,9 -16,9 +16,10 @@@ from youtube_dl.utils import DateRange, encodeFilename, find_xpath_attr, + fix_xml_ampersands, get_meta_content, orderedSet, + PagedList, parse_duration, sanitize_filename, shell_quote, @@@ -201,18 -201,26 +202,39 @@@ class TestUtil(unittest.TestCase) self.assertEqual(parse_duration('9:12:43'), 33163) self.assertEqual(parse_duration('x:y'), None) + def test_fix_xml_ampersands(self): + self.assertEqual( + fix_xml_ampersands('"&x=y&z=a'), '"&x=y&z=a') + self.assertEqual( + fix_xml_ampersands('"&x=y&wrong;&z=a'), + '"&x=y&wrong;&z=a') + self.assertEqual( + fix_xml_ampersands('&'><"'), + '&'><"') + self.assertEqual( + fix_xml_ampersands('Ӓ᪼'), 'Ӓ᪼') + self.assertEqual(fix_xml_ampersands('&#&#'), '&#&#') + + def test_paged_list(self): + def testPL(size, pagesize, sliceargs, expected): + def get_page(pagenum): + firstid = pagenum * pagesize + upto = min(size, pagenum * pagesize + pagesize) + for i in range(firstid, upto): + yield i + + pl = PagedList(get_page, pagesize) + got = pl.getslice(*sliceargs) + self.assertEqual(got, expected) + + testPL(5, 2, (), [0, 1, 2, 3, 4]) + testPL(5, 2, (1,), [1, 2, 3, 4]) + testPL(5, 2, (2,), [2, 3, 4]) + testPL(5, 2, (4,), [4]) + testPL(5, 2, (0, 3), [0, 1, 2]) + testPL(5, 2, (1, 4), [1, 2, 3]) + testPL(5, 2, (2, 99), [2, 3, 4]) + testPL(5, 2, (20, 99), []) + if __name__ == '__main__': unittest.main() diff --cc youtube_dl/extractor/youtube.py index 870b7c4ca,dd1a58f3f..57b8fdff7 --- a/youtube_dl/extractor/youtube.py +++ b/youtube_dl/extractor/youtube.py @@@ -27,7 -27,7 +27,8 @@@ from ..utils import get_element_by_id, get_element_by_attribute, ExtractorError, + int_or_none, + PagedList, RegexNotFoundError, unescapeHTML, unified_strdate,