Modify

Opened 3 years ago

Last modified 2 years ago

#14144 new defect

Python 3 compatibility

Reported by: pulkomandy@… Owned by: ttressieres
Priority: normal Component: DownloadsPlugin
Severity: normal Keywords:
Cc: Trac Release:

Description

Hello, This plugin seems to need only one change to run with Python 3.

  File "/usr/local/lib/python3.10/dist-packages/tracdownloads/api.py", line 827
    except Exception, error:
           ^^^^^^^^^^^^^^^^
SyntaxError: multiple exception types must be parenthesized (api.py, line 827)

As said by Python, adding the parentheses there fixes the problem. Could you integrate that in the next release? Thanks!

Attachments (0)

Change History (1)

comment:1 Changed 2 years ago by pulkomandy@…

Some more patching is needed, otherwise the downloads themselves don't work. This seems to be working for me:

Index: tracdownloads/api.py
===================================================================
--- tracdownloads/api.py        (révision 18497)
+++ tracdownloads/api.py        (copie de travail)
@@ -311,7 +311,7 @@

     def _edit_item(self, table, id, item):
         fields = item.keys()
-        values = item.values()
+        values = list(item.values())
         with self.env.db_transaction as db:
             db("""
                 UPDATE %s SET %s WHERE id=%%s
@@ -513,7 +513,7 @@
                     listener.download_changed(context, new_download, download)

                 # Guess mime type.
-                with open(filepath.encode('utf-8'), 'r') as fileobj:
+                with open(filepath.encode('utf-8'), 'rb') as fileobj:
                     file_data = fileobj.read(1000)
                 mimeview = Mimeview(self.env)
                 mime_type = mimeview.get_mimetype(filepath, file_data)
@@ -824,7 +824,7 @@
             with open(filepath.encode('utf-8'), 'wb+') as fileobj:
                 file.seek(0)
                 shutil.copyfileobj(file, fileobj)
-        except Exception, error:
+        except (Exception, error):
             self.delete_download(download['id'])
             self.log.debug(error)
             try:

Modify Ticket

Change Properties
Set your email in Preferences
Action
as new The owner will remain ttressieres.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.