Edgewall Software
Modify

Ticket #7458 (closed defect: fixed)

Opened 4 years ago

Last modified 3 years ago

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

Reported by: mad Owned by: rblank
Priority: normal Milestone: 0.11.3
Component: general Version: 0.11-stable
Severity: minor Keywords: patch
Cc: mad@…
Release Notes:
API 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

trac-0.11-hashlib.patch (5.2 KB) - added by mad 4 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 4 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@…> 4 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 3 years ago.
Updated patch to get rid of deprecation warnings
trac-0.11-hashlib-2.patch (1.4 KB) - added by mad 3 years ago.
Fixed patch to metion the right python version

Download all attachments as: .zip

Change History

Changed 4 years ago by mad

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

comment:1 Changed 4 years ago by nkantrowitz

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

comment:2 Changed 4 years ago by eblot

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 Changed 4 years ago by mad

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

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

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.

Changed 4 years ago by mad

Updated version with sha module replacement and fixed login href

Changed 4 years ago by Remy Blank <remy.blank@…>

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

comment:5 Changed 4 years ago by Remy Blank <remy.blank@…>

  • 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 Changed 4 years ago by Remy Blank <remy.blank@…>

  • Cc remy.blank@… added

comment:7 Changed 4 years ago by cboos

  • Milestone set to 0.11.1
  • Owner set to remy.blank@…
  • Severity changed from normal to minor

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

comment:8 Changed 4 years ago by cboos

  • Resolution set to fixed
  • Status changed from new to closed

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 Changed 3 years ago by mad

  • Resolution fixed deleted
  • Status changed from closed to reopened

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.

Changed 3 years ago by mad

Updated patch to get rid of deprecation warnings

comment:10 Changed 3 years ago by rblank

  • Cc remy.blank@… removed
  • Milestone changed from 0.11.1 to 0.11.3
  • Owner changed from remy.blank@… to rblank
  • Status changed from reopened to new

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.

Changed 3 years ago by mad

Fixed patch to metion the right python version

comment:11 Changed 3 years ago by mad

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 Changed 3 years ago by rblank

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 Changed 3 years ago by mad

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 Changed 3 years ago by rblank

  • Resolution set to fixed
  • Status changed from new to closed

Fixed in [7696].

comment:15 follow-up: Changed 3 years ago by jevans

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

comment:16 in reply to: ↑ 15 Changed 3 years ago by jevans

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?.

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
to The owner will be changed from rblank. Next status will be 'closed'
Author


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

 
Note: See TracTickets for help on using tickets.