diff options
author | Patrick Monnerat <[email protected]> | 2019-01-26 15:22:58 +0100 |
---|---|---|
committer | Victor Kareh <[email protected]> | 2019-01-30 15:59:07 -0500 |
commit | 6447d7c97a71521f2cdc0765a81c20aec8b90e04 (patch) | |
tree | a9c36cae6fb6e7ef26b52845cd36c32fe87f07fd /examples/md5sum-property-page.py | |
parent | a6a1bed0d97285ad9fabff9a5116f5b6a0e2c000 (diff) | |
download | python-caja-6447d7c97a71521f2cdc0765a81c20aec8b90e04.tar.bz2 python-caja-6447d7c97a71521f2cdc0765a81c20aec8b90e04.tar.xz |
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
Diffstat (limited to 'examples/md5sum-property-page.py')
-rw-r--r-- | examples/md5sum-property-page.py | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/examples/md5sum-property-page.py b/examples/md5sum-property-page.py index dd2a7ee..6f3f345 100644 --- a/examples/md5sum-property-page.py +++ b/examples/md5sum-property-page.py @@ -1,5 +1,11 @@ import hashlib -import urllib + +try: + # Python 3. + from urllib.parse import unquote +except: + # Python 2. + from urllib import unquote from gi.repository import Caja, Gtk, GObject @@ -18,7 +24,7 @@ class MD5SumPropertyPage(GObject.GObject, Caja.PropertyPageProvider): if file.is_directory(): return - filename = urllib.unquote(file.get_uri()[7:]) + filename = unquote(file.get_uri()[7:]) self.property_label = Gtk.Label('MD5Sum') self.property_label.show() @@ -35,7 +41,7 @@ class MD5SumPropertyPage(GObject.GObject, Caja.PropertyPageProvider): md5sum = hashlib.md5() with open(filename,'rb') as f: - for chunk in iter(lambda: f.read(8192), ''): + for chunk in iter(lambda: f.read(8192), b''): md5sum.update(chunk) f.close() |