Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

demo/md5_ftpd.py should use hashlib module instead of the deprecated md5 module #80

Closed
giampaolo opened this issue May 28, 2014 · 14 comments
Labels
bug Component-Scripts imported imported from old googlecode site and very likely outdated

Comments

@giampaolo
Copy link
Owner

From fogWra...@gmail.com on October 12, 2008 21:53:07

MD5 has been deprecated and the use of hashlib instead would be preferred

Original issue: http://code.google.com/p/pyftpdlib/issues/detail?id=80

@giampaolo
Copy link
Owner Author

From billiej...@gmail.com on October 13, 2008 11:14:44

Summary: demo/md5_ftpd.py should use hashlib module instead of the deprecated md5 module
Status: Accepted
Labels: Version-0.5.0 Milestone-0.6.0 Component-Scripts

@giampaolo
Copy link
Owner Author

From billiej...@gmail.com on October 15, 2008 10:08:40

The patch in attachment works with Python 2.5 and 2.6 but I can't find a valid
modification which works also for Python 2.3 and 2.4.
Do you have any advice?

Attachment: md5_ftpd.patch

@giampaolo
Copy link
Owner Author

From jlo...@gmail.com on October 15, 2008 10:19:22

Updating code from my previous comment, I like this better: 

try:
    import hashlib.md5 as md5
except ImportError:
    import md5

Tested on my box that works in 2.3, 2.4, 2.5 Python (don't have 2.6 installed 
right now).

@giampaolo
Copy link
Owner Author

From billiej...@gmail.com on October 15, 2008 10:34:41

Python 2.6 ( r26 :66721, Oct  2 2008, 11:35:03) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> import hashlib.md5 as md5
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named md5
>>>

@giampaolo
Copy link
Owner Author

From jlo...@gmail.com on October 15, 2008 10:36:53

Hmm...does it work on Python 2.5 for you? Did they really change the hashlib module
interface *again* in 2.6?

@giampaolo
Copy link
Owner Author

From billiej...@gmail.com on October 15, 2008 10:58:52

Yeah it works on 2.5 and earlier.
I'm going to ask on python ml.

@giampaolo
Copy link
Owner Author

From jlo...@gmail.com on October 15, 2008 11:04:21

Nevermind, I see the problem now...we pretty much have to update the code like they
did here: http://code.djangoproject.com/ticket/7919 try:
    import hashlib
    md5_constructor = hashlib.md5
except ImportError:
    import md5
    md5_constructor = md5.new

Then the rest of the code would need to be updated to use the md5 constructor instead
of md5.new() etc. Looks like there's no "nice" way to have hashlib as a drop in
replacement for the old md5 module.

@giampaolo
Copy link
Owner Author

From billiej...@gmail.com on October 15, 2008 11:12:32

Damn... that's really ugly. Why did they do that?
If md5 module won't be removed from the 2.X trunk we could just filter the warning:

import warnings
warnings.filterwarnings("ignore")
import md5
warnings.filterwarnings("default")

...but that's ugly too.

@giampaolo
Copy link
Owner Author

From jlo...@gmail.com on October 15, 2008 11:14:19

It's ugly, but we can get away with this (just tested on all versions I have here
locally and it seems to work): 

try:
    import hashlib as md5
    md5.new = md5.md5
except ImportError:
    import md5

Either that, or the previous approach I suggested where we create an "md5" function
aliased to the right module's method on import. I think abstracting it away is a
little cleaner personally, but either should work.

@giampaolo
Copy link
Owner Author

From billiej...@gmail.com on October 15, 2008 11:16:49

What about this?

try:
    from hashlib import md5
except ImportError:
    from md5 import new as md5

It seems to work on all versions.

@giampaolo
Copy link
Owner Author

From jlo...@gmail.com on October 15, 2008 11:35:38

That should work too, but that will still require changing the code to use md5()
instead of md5.new() Either way works for me though.

@giampaolo
Copy link
Owner Author

From billiej...@gmail.com on October 15, 2008 11:56:45

Fixed in r410 .
Thanks guys.

Status: Finished

@giampaolo
Copy link
Owner Author

From billiej...@gmail.com on November 20, 2008 12:56:32

Labels: Milestone-0.5.1

@giampaolo
Copy link
Owner Author

From billiej...@gmail.com on January 21, 2009 10:05:51

Fixed in version 0.5.1 released on 2009-01-21.

Status: Fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Component-Scripts imported imported from old googlecode site and very likely outdated
Projects
None yet
Development

No branches or pull requests

1 participant