From 6447d7c97a71521f2cdc0765a81c20aec8b90e04 Mon Sep 17 00:00:00 2001 From: Patrick Monnerat Date: Sat, 26 Jan 2019 15:22:58 +0100 Subject: Modernize examples The example extension scripts need to be in sync with new versions of referenced foreign packages. This commit also makes them compatible with Python version 3 (retaining Python 2 compatibility). An additional example extension "mixed" is added: it implements all caja extension features and can also be used as a new extension pattern. See source header comment for a description. Ref: https://github.com/mate-desktop/python-caja/pull/34#issuecomment-457257832 --- examples/open-terminal.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'examples/open-terminal.py') diff --git a/examples/open-terminal.py b/examples/open-terminal.py index 1d0e5aa..c80552a 100644 --- a/examples/open-terminal.py +++ b/examples/open-terminal.py @@ -1,6 +1,12 @@ # This example is contributed by Martin Enlund import os -import urllib + +try: + # Python 3. + from urllib.parse import unquote +except: + # Python 2. + from urllib import unquote from gi.repository import Caja, GObject, Gio @@ -12,7 +18,7 @@ class OpenTerminalExtension(Caja.MenuProvider, GObject.GObject): self.gsettings = Gio.Settings.new(TERMINAL_SCHEMA) def _open_terminal(self, file): - filename = urllib.unquote(file.get_uri()[7:]) + filename = unquote(file.get_uri()[7:]) terminal = self.gsettings[TERMINAL_KEY] os.chdir(filename) -- cgit v1.2.1