[totem] Port opensubtitles to python3
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [totem] Port opensubtitles to python3
- Date: Tue, 30 Apr 2013 06:58:38 +0000 (UTC)
commit 6022536e085e65c086282c831f27000b13f3abfe
Author: Ignacio Casal Quinteiro <icq gnome org>
Date: Mon Apr 29 17:13:27 2013 +0200
Port opensubtitles to python3
src/plugins/opensubtitles/hash.py | 6 +++---
src/plugins/opensubtitles/opensubtitles.plugin.in | 2 +-
src/plugins/opensubtitles/opensubtitles.py | 20 +++++++++-----------
3 files changed, 13 insertions(+), 15 deletions(-)
---
diff --git a/src/plugins/opensubtitles/hash.py b/src/plugins/opensubtitles/hash.py
index 26aa0d9..aac056a 100644
--- a/src/plugins/opensubtitles/hash.py
+++ b/src/plugins/opensubtitles/hash.py
@@ -21,9 +21,9 @@ def hash_file (name):
if filesize < 65536 * 2:
return SIZE_ERROR, 0
- file_handle = file (file_to_hash.get_path (), "rb")
+ file_handle = open (file_to_hash.get_path (), "rb")
- for _ in range (65536 / bytesize):
+ for _ in range(int(65536 / bytesize)):
buf = file_handle.read (bytesize)
(l_value,) = struct.unpack (longlongformat, buf)
file_hash += l_value
@@ -34,7 +34,7 @@ def hash_file (name):
if file_handle.tell() != max (0, filesize - 65536):
return SEEK_ERROR, 0
- for _ in range (65536/bytesize):
+ for _ in range(int(65536/bytesize)):
buf = file_handle.read (bytesize)
(l_value,) = struct.unpack (longlongformat, buf)
file_hash += l_value
diff --git a/src/plugins/opensubtitles/opensubtitles.plugin.in
b/src/plugins/opensubtitles/opensubtitles.plugin.in
index fea2a22..9a9f3e4 100644
--- a/src/plugins/opensubtitles/opensubtitles.plugin.in
+++ b/src/plugins/opensubtitles/opensubtitles.plugin.in
@@ -1,5 +1,5 @@
[Plugin]
-Loader=python
+Loader=python3
Module=opensubtitles
IAge=1
_Name=Subtitle Downloader
diff --git a/src/plugins/opensubtitles/opensubtitles.py b/src/plugins/opensubtitles/opensubtitles.py
index 5f53034..ca316ef 100644
--- a/src/plugins/opensubtitles/opensubtitles.py
+++ b/src/plugins/opensubtitles/opensubtitles.py
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
-from gi.repository import GObject, Peas, Gtk, Gdk # pylint: disable-msg=E0611
+from gi.repository import GLib, GObject, Peas, Gtk, Gdk # pylint: disable-msg=E0611
from gi.repository import Gio, Pango, Totem # pylint: disable-msg=E0611
-import xmlrpclib
+import xmlrpc.client
import threading
import xdg.BaseDirectory
from os import sep, path, mkdir
@@ -16,8 +16,6 @@ gettext.textdomain ("totem")
D_ = gettext.dgettext
_ = gettext.gettext
-GObject.threads_init ()
-
USER_AGENT = 'Totem'
OK200 = '200 OK'
TOTEM_REMOTE_COMMAND_REPLACE = 14
@@ -271,7 +269,7 @@ class OpenSubtitlesModel (object):
# We have already logged-in before, check the connection
try:
result = self._server.NoOperation (self._token)
- except (xmlrpclib.Fault, xmlrpclib.ProtocolError):
+ except (xmlrpc.client.Fault, xmlrpc.client.ProtocolError):
pass
if result and result['status'] != OK200:
return (True, '')
@@ -279,7 +277,7 @@ class OpenSubtitlesModel (object):
try:
result = self._server.LogIn (username, password, self.lang,
USER_AGENT)
- except (xmlrpclib.Fault, xmlrpclib.ProtocolError):
+ except (xmlrpc.client.Fault, xmlrpc.client.ProtocolError):
pass
if result and result.get ('status') == OK200:
@@ -319,7 +317,7 @@ class OpenSubtitlesModel (object):
try:
result = self._server.SearchSubtitles (self._token,
[searchdata])
- except xmlrpclib.ProtocolError:
+ except xmlrpc.client.ProtocolError:
message = _(u'Could not contact the OpenSubtitles website.')
if result.get ('data'):
@@ -346,7 +344,7 @@ class OpenSubtitlesModel (object):
try:
result = self._server.DownloadSubtitles (self._token,
[subtitle_id])
- except xmlrpclib.ProtocolError:
+ except xmlrpc.client.ProtocolError:
message = error_message
if result and result.get ('status') == OK200:
@@ -422,7 +420,7 @@ class OpenSubtitles (GObject.Object, # pylint: disable-msg=R0902
self._totem.connect ('file-closed', self.__on_totem__file_closed)
# Obtain the ServerProxy and init the model
- server = xmlrpclib.Server ('http://api.opensubtitles.org/xml-rpc')
+ server = xmlrpc.client.Server ('http://api.opensubtitles.org/xml-rpc')
self._model = OpenSubtitlesModel (server)
def do_deactivate (self):
@@ -584,10 +582,10 @@ class OpenSubtitles (GObject.Object, # pylint: disable-msg=R0902
thread = SearchThread (self._model, movie_hash, movie_size)
thread.start ()
- GObject.idle_add (self._populate_treeview, thread)
+ GLib.idle_add (self._populate_treeview, thread)
self._progress.set_text (_(u'Searching subtitles…'))
- GObject.timeout_add (350, self._progress_bar_increment, thread)
+ GLib.timeout_add (350, self._progress_bar_increment, thread)
def _populate_treeview (self, search_thread):
if not search_thread.done:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]