[mod_python] odd behaviour of the md5-module in modpy

Nikolaus Schlemm nikl at nikl.net
Mon Jun 26 11:32:07 EDT 2006


"Deron Meranda" <deron.meranda at gmail.com> responded offlist:
> What version of python do you have, and what version of
> mod_python?  Can you provide an simple example of how
> you're importing the module and calling it?

i'm using python 2.4.3-1ubuntu1 and libapache2-mod-python-3.1.4-0ubuntu1 on my 
ubuntu box and python 2.3.5-11 and libapache2-mod-python-3.2.8-1 on debian.

tested both with the following snippet:

    from mod_python import apache 
 
    # from http://www.ietf.org/rfc/rfc1321.txt
    MD5_TESTS = { 
        "": "d41d8cd98f00b204e9800998ecf8427e", 
        "a": "0cc175b9c0f1b6a831c399e269772661", 
        "abc": "900150983cd24fb0d6963f7d28e17f72", 
        "message digest": "f96b697d7cb7938d525a2f31aaf161d0", 
        "abcdefghijklmnopqrstuvwxyz": "c3fcd3d76192e4007dfb496cca67e13b", 
        "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789": "d174ab98d277d9f5a5611c2c9f419d9f", 
        "12345678901234567890123456789012345678901234567890123456789012345678901234567890": "57edf4a22be3c955ac49da2e2107b67a" 
    } 
 
    def handler(req): 
        import md5 
        req.content_type = 'text/plain' 
        req.write('md5: %s\n' % md5.__file__) 
        for k, v in MD5_TESTS.items(): 
            m = md5.new(k).hexdigest() 
            req.write('"%s" -> "%s" ? %s\n' % (k, m, (m == v)))  
        return apache.OK 

which e.g. leads to:

    md5: /usr/lib/python2.4/lib-dynload/md5.so
    "" -> "0000000000000000d09215a3e97561b3" ? False
    "a" -> "0000000000000000d09215a3e97561b3" ? False
    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" -> "0000000000000000d09215a3e97561b3" ? 
False
    "12345678901234567890123456789012345678901234567890123456789012345678901234567890" -> "0000000000000000d09215a3e97561b3" ? 
False
    "message digest" -> "0000000000000000d09215a3e97561b3" ? False
    "abc" -> "0000000000000000d09215a3e97561b3" ? False
    "abcdefghijklmnopqrstuvwxyz" -> "0000000000000000d09215a3e97561b3" ? False

> Are you calling the hexdigest() method, or just digest() to get
> the value?
hexdigest()

> Are you sure you're not picking up some other module that
> may be named "md5", or that you're not overloading the
> variable.  Try displaying the value of md5.__file__
/usr/lib/python2.4/lib-dynload/md5.so on ubuntu (the same but 2.3 on debian)

> Also there should have been a file called "test_md5.py" which came
> with your python (perhaps as /usr/lib/python2.4/test/test_md5.py).
> Run it from a shell prompt and make sure all the tests pass.
neither distro has a test_md5.py - but using the module _anywhere_ outside of 
modpy works..

> Also to there are several official test vectors listed at the end
> of RFC 1321, which you should use to make sure you're getting
> the correct hash values: http://www.ietf.org/rfc/rfc1321.txt
running those hash-calculations e.g. in the interpreter works totally fine...
-- 
cheers,

	Nikl


More information about the Mod_python mailing list