After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 723074 - Fatal error downloading subtitle
Fatal error downloading subtitle
Status: RESOLVED FIXED
Product: totem
Classification: Core
Component: Subtitle Downloader plugin
unspecified
Other Mac OS
: Normal normal
: ---
Assigned To: General Totem maintainer(s)
General Totem maintainer(s)
Depends on:
Blocks:
 
 
Reported: 2014-01-27 08:44 UTC by Bastien Nocera
Modified: 2014-01-30 10:52 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Bastien Nocera 2014-01-27 08:44:28 UTC
Those are the changes I have right now for more Python3 porting:
diff --git a/src/plugins/opensubtitles/opensubtitles.py b/src/plugins/opensubtitles/opensubtitles.py
index dcf71f1..ad2d906 100644
--- a/src/plugins/opensubtitles/opensubtitles.py
+++ b/src/plugins/opensubtitles/opensubtitles.py
@@ -6,6 +6,8 @@ from gi.repository import Gio, Pango, Totem # pylint: disable-msg=E0611
 
 import xmlrpc.client
 import threading
+from io import StringIO
+import gzip, base64
 from os import sep, path, mkdir
 import gettext
 
@@ -354,9 +356,8 @@ class OpenSubtitlesModel (object):
                     self._lock.release ()
                     return (None, error_message)
 
-                import StringIO, gzip, base64
-                subtitle_decoded = base64.decodestring (subtitle64)
-                subtitle_gzipped = StringIO.StringIO (subtitle_decoded)
+                subtitle_decoded = base64.decodestring (bytes(subtitle64, 'utf-8'))
+                subtitle_gzipped = StringIO (str(subtitle_decoded))
                 subtitle_gzipped_file = gzip.GzipFile (fileobj=subtitle_gzipped)
 
                 self._lock.release ()


Unfortunately it still fails with:
Exception in thread Thread-2:
Traceback (most recent call last):
  • File "/usr/lib64/python3.3/threading.py", line 637 in _bootstrap_inner
    self.run()
  • File "plugins/opensubtitles/opensubtitles.py", line 210 in run
    self._message) = self._model.download_subtitles (self._subtitle_id)
  • File "plugins/opensubtitles/opensubtitles.py", line 365 in download_subtitles
    return (subtitle_gzipped_file.read (), message)
  • File "/usr/lib64/python3.3/gzip.py", line 360 in read
    self._read(readsize)
  • File "/usr/lib64/python3.3/gzip.py", line 441 in _read
    self._read_gzip_header()
  • File "/usr/lib64/python3.3/gzip.py", line 285 in _read_gzip_header
    magic = self.fileobj.read(2)
  • File "/usr/lib64/python3.3/gzip.py", line 93 in read
    self.file.read(size-self._length+read)
TypeError: can't concat bytes to str


Looks like a bug in Python itself? We should probably look at using Gio.ZlibDecompressor instead.
Comment 1 Bastien Nocera 2014-01-30 10:52:15 UTC
I couldn't figure out how to GConverter from Python, even with those docs:
http://lazka.github.io/pgi-docs/api/Gio_2.0/interfaces/Converter.html#Gio.Converter

It expected an allocated buffer as the "out" parameter, when GConverter is the one allocating it...

commit 9d6a14fc25515772048ef07a2dc7343241277a43
Author: Bastien Nocera <hadess@hadess.net>
Date:   Thu Jan 30 11:48:56 2014 +0100

    opensubtitles: Make decoding download items work
    
    Stop using StringIO, gzip and base64 modules, and use GLib for
    the base64 decoding, and zlib for the decompression.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=723074