classification
Title: sha and md5 fixer
Type: behavior Stage: resolved
Components: 2to3 (2.x to 3.x conversion tool) Versions: Python 3.3, Python 3.4, Python 2.7
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: meador.inge Nosy List: aronacher, benjamin.peterson, christian.heimes, collinwinter, dmalcolm, eric.araujo, ezio.melotti, gregory.p.smith, loewis, meador.inge
Priority: normal Keywords: patch

Created on 2008-03-22 01:00 by loewis, last changed 2019-09-25 09:59 by christian.heimes. This issue is now closed.

Files
File name Uploaded Description Edit
issue-2454.patch meador.inge, 2010-02-01 01:40 review
issue2454-2.patch meador.inge, 2012-11-22 03:21 review
Messages (15)
msg64305 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2008-03-22 01:00
Usages of the md5 module could be fixed, as it's unavailable in 3k.

In particular:

import md5 -> import hashlib
md5.new(...) -> hashlib.md5(...)
md5.md5(...) -> hashlib.md5(...)

Notice that users could already change this manually in 2.6, since
hashlib is available since 2.5, so the fixer is not strictly needed, but
would be convenient.
msg64306 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2008-03-22 01:02
And do the same for:

sha.sha1 -> hashlib.sha1
sha.new  -> hashlib.sha1
msg98643 - (view) Author: Meador Inge (meador.inge) * (Python committer) Date: 2010-02-01 01:40
Attached a patch that provides a (sha | md5) -> hashlib fixer, covering test cases, and updated documentation.
msg110796 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2010-07-19 18:45
The patch looks clean to me although I don't feel qualified to comment on the technical aspects.  I've tested it on Windows Vista 32 bit against the 2.7 and 3.1 maintainance releases and py3k.  The 2.7 run was fine, both 3.x runs failed.

  File "c:\release31-maint\lib\lib2to3\fixes\fix_hash.py", line 27
    "md5": u"md5",
                ^
SyntaxError: invalid syntax

I've stared at the code until I'm blue in the face and can't see what's wrong, I'm sure someone else will spot the problem in seconds.

I also noticed a small typo in the rst file "modules where deprecated"
should read "modules were deprecated".
msg110802 - (view) Author: Dave Malcolm (dmalcolm) (Python committer) Date: 2010-07-19 19:27
The 'u' prefix went away in Python 3, use an unadorned '' or "" for a unicode value.

$ python3
Python 3.1.2 (r312:79147, May 25 2010, 12:21:57) 
[GCC 4.4.3 20100422 (Red Hat 4.4.3-18)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> u"foo"
  File "<stdin>", line 1
    u"foo"
         ^
SyntaxError: invalid syntax
msg110803 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2010-07-19 19:51
I've successfully rerun the tests for 3.x having stripped the 'u' prefix.
msg111458 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2010-07-24 11:38
Can this be committed please.  In msg110796 I over-emphasised the technical aspects, the patch is actually against 2to3.
msg111460 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-07-24 11:46
Minor nit: I suggest naming the fixer fix_hashlib, since the name fix_hash could easily be understood as something fixing __hash__ (even if such a fix is impossible for a machine to do).

This fix could also go into fix_imports, but it’s useful as a standalone fixer e.g. to run on code that drops <2.5 compatibility.
msg175232 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2012-11-09 13:14
What's the status of this?
msg175239 - (view) Author: Meador Inge (meador.inge) * (Python committer) Date: 2012-11-09 14:27
I haven't touched the patch since I attached it.  I will refresh it today with the feedback given.
msg176094 - (view) Author: Meador Inge (meador.inge) * (Python committer) Date: 2012-11-22 03:21
Attached is a refreshed patch that works for all active branches.  The only real change from the original is Éric's suggestion to s/hash/hashlib/.  The 'u' prefix isn't an issue any longer because of PEP 414.

Benjamin, does the attached look OK to you?  If so, then I will commit it.
msg176150 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2012-11-23 04:11
I'm not sure how much this is needed considering hashlib has been around, since 2.5. I hope people aren't having to port from before then.
msg176172 - (view) Author: Meador Inge (meador.inge) * (Python committer) Date: 2012-11-23 14:25
> I'm not sure how much this is needed considering hashlib has been around, since 2.5.
> I hope people aren't having to port from before then.

Martin alluded to that when he opened the issue saying this wasn't necessary, but a nice
to have.  However, it has been over four years since the issue was opened.  Maybe it
should just be closed.  I don't really have an opinion either way.

Martin, are you still interested in this?
msg176233 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2012-11-23 20:06
Any code conversion is useful. This will help with old libraries and is
even good for just updating old 2.4 code to 2.7 best practices.
msg353160 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2019-09-25 09:59
The issue is already fixed. Python 3.7+ no longer import the md5 module directly.
History
Date User Action Args
2019-09-25 09:59:24christian.heimessetstatus: open -> closed

nosy: + christian.heimes
messages: + msg353160

resolution: out of date
stage: patch review -> resolved
2014-02-03 19:06:13BreamoreBoysetnosy: - BreamoreBoy
2012-11-23 20:06:56gregory.p.smithsetmessages: + msg176233
2012-11-23 14:25:22meador.ingesetmessages: + msg176172
2012-11-23 04:11:25benjamin.petersonsetmessages: + msg176150
2012-11-22 03:21:20meador.ingesetfiles: + issue2454-2.patch
assignee: benjamin.peterson -> meador.inge
messages: + msg176094

versions: + Python 2.7, Python 3.3, Python 3.4
2012-11-09 14:27:35meador.ingesetmessages: + msg175239
2012-11-09 13:14:35ezio.melottisetnosy: + ezio.melotti
messages: + msg175232
2011-01-04 02:04:11pitrousetassignee: collinwinter -> benjamin.peterson
nosy: loewis, collinwinter, gregory.p.smith, benjamin.peterson, aronacher, eric.araujo, dmalcolm, meador.inge, BreamoreBoy
2010-07-24 11:46:07eric.araujosetnosy: + eric.araujo
messages: + msg111460
2010-07-24 11:38:18BreamoreBoysetmessages: + msg111458
2010-07-19 19:51:54BreamoreBoysetmessages: + msg110803
2010-07-19 19:27:32dmalcolmsetnosy: + dmalcolm
messages: + msg110802
2010-07-19 18:45:46BreamoreBoysetnosy: + BreamoreBoy
messages: + msg110796
2010-02-01 06:40:54loewissetnosy: loewis, collinwinter, gregory.p.smith, benjamin.peterson, aronacher, meador.inge
components: + 2to3 (2.x to 3.x conversion tool)
2010-02-01 03:28:55brian.curtinsetnosy: loewis, collinwinter, gregory.p.smith, benjamin.peterson, aronacher, meador.inge
type: behavior
components: - 2to3 (2.x to 3.x conversion tool)
stage: patch review
2010-02-01 01:40:37meador.ingesetfiles: + issue-2454.patch

nosy: + meador.inge
messages: + msg98643

keywords: + patch
2009-02-11 04:41:38ajaksu2setnosy: + benjamin.peterson
2008-12-08 15:04:13aronachersetnosy: + aronacher
2008-04-09 03:19:13collinwintersetpriority: normal
2008-03-22 01:03:27benjamin.petersonsettitle: md5 fixer -> sha and md5 fixer
2008-03-22 01:02:20gregory.p.smithsetnosy: + gregory.p.smith
messages: + msg64306
2008-03-22 01:00:42loewiscreate