]> gitweb @ CieloNegro.org - youtube-dl.git/commitdiff
Merge branch 'paged-lists'
authorPhilipp Hagemeister <phihag@phihag.de>
Wed, 22 Jan 2014 19:00:16 +0000 (20:00 +0100)
committerPhilipp Hagemeister <phihag@phihag.de>
Wed, 22 Jan 2014 19:00:16 +0000 (20:00 +0100)
Conflicts:
test/test_utils.py
youtube_dl/extractor/youtube.py

1  2 
test/test_utils.py
youtube_dl/YoutubeDL.py
youtube_dl/extractor/youtube.py
youtube_dl/utils.py

index a17483ada829345e8e96f23dbdeaeea7a5451294,349c1107f4c123fd043682428b36def8690708cb..c68e0e96844213f6626c950bd89487b74223593e
@@@ -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'), '"&amp;x=y&amp;z=a')
 +        self.assertEqual(
 +            fix_xml_ampersands('"&amp;x=y&wrong;&z=a'),
 +            '"&amp;x=y&amp;wrong;&amp;z=a')
 +        self.assertEqual(
 +            fix_xml_ampersands('&amp;&apos;&gt;&lt;&quot;'),
 +            '&amp;&apos;&gt;&lt;&quot;')
 +        self.assertEqual(
 +            fix_xml_ampersands('&#1234;&#x1abC;'), '&#1234;&#x1abC;')
 +        self.assertEqual(fix_xml_ampersands('&#&#'), '&amp;#&amp;#')
 +
+     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()
Simple merge
index 870b7c4cabb502f870b7f1aeee9b5295156b3e29,dd1a58f3fc0f5448fdf1266ef0b51840a6307d8e..57b8fdff7204b1fbb5dc6d88742704638995b0eb
@@@ -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,
Simple merge