New paste Repaste Download
tmpdir = local('/tmp/pytest-of-root/pytest-9/test_download_subtitle0')
    def test_download_subtitle(tmpdir):
        url = 'http://server.com/foo.gz'
        subtitle_filename = str(tmpdir / 'subtitle.srt')
    
        # write binary contents to ensure that we are not trying to encode/decode
        # subtitles (see issue #20)
        sub_contents = b'\xff' * 10
    
        gzip_filename = str(tmpdir / 'sub.gz')
        with closing(GzipFile(gzip_filename, 'wb')) as f:
            f.write(sub_contents)
    
        with patch('ss.urlopen') as urlopen_mock:
            urlopen_mock.return_value = open(gzip_filename, 'rb')
>           download_subtitle(url, subtitle_filename)
tests/test_ss.py:222:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
subtitle_url = 'http://server.com/foo.gz'
subtitle_filename = '/tmp/pytest-of-root/pytest-9/test_download_subtitle0/subtitle.srt'
    def download_subtitle(subtitle_url, subtitle_filename):
        # first download it and save to a temp dir
        urlfile = urlopen(subtitle_url)
        try:
            gzip_subtitle_contents = urlfile.read()
        finally:
            urlfile.close()
    
        tempdir = tempfile.mkdtemp()
        try:
            basename = subtitle_url.split('/')[-1]
            tempfilename = os.path.join(tempdir, basename)
            with open(tempfilename, 'wb') as f:
                f.write(gzip_subtitle_contents)
    
            f = gzip.GzipFile(tempfilename, 'r')
            try:
>               subtitle_contents = f.read().decode('utf-8')
E               UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
ss.py:152: UnicodeDecodeError
Filename: None. Size: 2kb. View raw, , hex, or download this file.

This paste expires on 2026-04-10 08:58:42.118444+00:00. Pasted through deprecated-web.