From f254ee3211d18af79ed5c2fd1fa87c23658c7b6b Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Thu, 18 Jan 2018 14:13:40 +0100 Subject: [PATCH] Nautilus shell integration: Port to Python 3 --- shell_integration/nautilus/syncstate.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/shell_integration/nautilus/syncstate.py b/shell_integration/nautilus/syncstate.py index 082be4e22..6ea719100 100644 --- a/shell_integration/nautilus/syncstate.py +++ b/shell_integration/nautilus/syncstate.py @@ -17,6 +17,7 @@ import os import urllib +import urllib.parse import socket import tempfile @@ -34,7 +35,7 @@ print("Initializing "+appname+"-client-nautilus extension") def get_local_path(url): if url[0:7] == 'file://': url = url[7:] - return urllib.unquote(url) + return urllib.parse.unquote(url) def get_runtime_dir(): """Returns the value of $XDG_RUNTIME_DIR, a directory path. @@ -56,7 +57,7 @@ class SocketConnect(GObject.GObject): self._watch_id = 0 self._sock = None self._listeners = [self._update_registered_paths] - self._remainder = '' + self._remainder = ''.encode() self.nautilusVFSFile_table = {} # not needed in this object actually but shared # all over the other objects. @@ -74,7 +75,7 @@ class SocketConnect(GObject.GObject): # print("Server command: " + cmd) if self.connected: try: - self._sock.send(cmd) + self._sock.send(cmd.encode()) except: print("Sending failed.") self.reconnect() @@ -113,17 +114,17 @@ class SocketConnect(GObject.GObject): # Prepend the remaining data from last call if len(self._remainder) > 0: data = self._remainder + data - self._remainder = '' + self._remainder = ''.encode() if len(data) > 0: # Remember the remainder for next round - lastNL = data.rfind('\n'); + lastNL = data.rfind('\n'.encode()); if lastNL > -1 and lastNL < len(data): self._remainder = data[lastNL+1:] data = data[:lastNL] - for l in data.split('\n'): - self._handle_server_response(l) + for l in data.split('\n'.encode()): + self._handle_server_response(l.decode()) else: return False