Edgewall Software
Modify

Opened 16 years ago

Closed 16 years ago

Last modified 16 years ago

#7458 closed defect (fixed)

[patch] The md5 module is deprecated in python, use hashlib instead

Reported by: mad Owned by: Remy Blank
Priority: normal Milestone: 0.11.3
Component: general Version: 0.11-stable
Severity: minor Keywords: patch
Cc: mad@… Branch:
Release Notes:
API Changes:
Internal Changes:

Description

Hello,

the md5 module is deprecated, hashlib should be used instead. here is a simple patch against 0.11 to kill the warnings.

Attachments (5)

trac-0.11-hashlib.patch (5.2 KB ) - added by mad 16 years ago.
patch to replace the usage of the depecated md5 module with hashlib
trac-0.11-hashlib.2.patch (5.2 KB ) - added by mad 16 years ago.
Updated version with sha module replacement and fixed login href
7458-hashlib-r7376.patch (4.4 KB ) - added by Remy Blank <remy.blank@…> 16 years ago.
Patch against 0.11-stable that implements the solution suggested by eblot
trac-0.11.2-hashlib.patch (2.0 KB ) - added by mad 16 years ago.
Updated patch to get rid of deprecation warnings
trac-0.11-hashlib-2.patch (1.4 KB ) - added by mad 16 years ago.
Fixed patch to metion the right python version

Download all attachments as: .zip

Change History (21)

by mad, 16 years ago

Attachment: trac-0.11-hashlib.patch added

patch to replace the usage of the depecated md5 module with hashlib

comment:1 by Noah Kantrowitz, 16 years ago

This is not possible without dropping support for Python 2.4. Not going to happen for a while.

comment:2 by Emmanuel Blot, 16 years ago

It could be implemented with compatibility for previous release of Python:

try:
    import hashlib
    md = hashlib.md5()
except ImportError:
    # for Python << 2.5
    import md5
    md = md5.new()

comment:3 by mad, 16 years ago

the patch was wrong in some way, with it applied the login href was missing. strange…

comment:4 by Remy Blank <remy.blank@…>, 16 years ago

Yes, the search and replace was a bit too hasty. I would guess that the substitution at line 38 of trac/web/auth.py is wrong.

by mad, 16 years ago

Attachment: trac-0.11-hashlib.2.patch added

Updated version with sha module replacement and fixed login href

by Remy Blank <remy.blank@…>, 16 years ago

Attachment: 7458-hashlib-r7376.patch added

Patch against 0.11-stable that implements the solution suggested by eblot

comment:5 by Remy Blank <remy.blank@…>, 16 years ago

Keywords: patch added

The patch above imports either hashlib.md5 or md5.md5 into trac.util, and all users of md5 import it from there.

The same import hack is applied separately to contrib/htdigest.py so that it doesn't have to depend on trac.util.

The patch proposed by mad also fixed trac/wiki/default-pages/TracStandalone, but I understand these pages are imported from the live Trac instance on t.e.o during the release process. So I'll patch TracStandalone with the same hack.

comment:6 by Remy Blank <remy.blank@…>, 16 years ago

Cc: remy.blank@… added

comment:7 by Christian Boos, 16 years ago

Milestone: 0.11.1
Owner: set to remy.blank@…
Severity: normalminor

attachment:7458-hashlib-r7376.patch looks great, I'll apply it later today.

comment:8 by Christian Boos, 16 years ago

Resolution: fixed
Status: newclosed

Applied with minor tweaking in (moved the hashlib import logic in trac.util.compat, where we usually place this sort of things). It's still importable directly from trac.util though.

Patch applied in r7384.

comment:9 by mad, 16 years ago

Resolution: fixed
Status: closedreopened

I've upgraded my Trac environment to 0.11.2 today and everything is running on Python 2.6 here. I got some errors about the deprecation of module sha which i fixed myself on 0.11 as shown in my last patch… I've updated my patch to 0.11.2 and fixed the comments to blame python version 2.6 and not 2.5 which was wrong.

by mad, 16 years ago

Attachment: trac-0.11.2-hashlib.patch added

Updated patch to get rid of deprecation warnings

comment:10 by Remy Blank, 16 years ago

Cc: remy.blank@… removed
Milestone: 0.11.10.11.3
Owner: changed from remy.blank@… to Remy Blank
Status: reopenednew

That's true, we should have done both at the same time. The md5 and sha modules are actually deprecated since 2.5 (see the docs), but they only started generating a warning in 2.6.

by mad, 16 years ago

Attachment: trac-0.11-hashlib-2.patch added

Fixed patch to metion the right python version

comment:11 by mad, 16 years ago

Please scratch my last patch and please take a look here:

http://docs.python.org/whatsnew/2.6.html

The actual deprecation is listed in the docs of Python 2.6 The hashlib module itself was just added in version 2.5

comment:12 by Remy Blank, 16 years ago

It's really only a detail, but look at the top of:

http://www.python.org/doc/2.5.2/lib/module-sha.html

Anyway, I'm waiting for 0.11.2.1 to be out, then I'll fix the deprecation. Thanks for reporting the success with 2.6.

comment:13 by mad, 16 years ago

the two sides of the same medal ;)

to be clear, we faced no problems with trac-0.11 on python 2.6 even the actual trac-0.11 branch of bitten works like a charm here.

thanks for providing such a good environment for our development.

comment:14 by Remy Blank, 16 years ago

Resolution: fixed
Status: newclosed

Fixed in [7696].

comment:15 by jevans, 16 years ago

I see these warnings in Trac 0.11.4 trac-admin with Python 2.6. Should that be a separate ticket?

in reply to:  15 comment:16 by jevans, 16 years ago

Replying to jevans:

I see these warnings in Trac 0.11.4 trac-admin with Python 2.6. Should that be a separate ticket?

Sorry, they appear to come from AccountManager.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Remy Blank.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Remy Blank to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.