Hello,

yesterday I upgraded from Python 2.3 to Python 2.6 and re-installed
Ply 2.5 for Python 2.6. I now get DeprecationWarning messages when
using ply (yacc), due to the use of the md5 module. Since Python 2.5,
the hashlib module is preferred (and the md5 module deprecated). I
created a patch that gets rid of the DeprecationWarning message, while
still allowing Ply 2.5 to run on older as well as newer Python
versions.

****** start of patch *********

--- yacc.py
+++ yacc.py
@@ -71,7 +71,18 @@
 yaccdevel   = 0                # Set to True if developing yacc.
This turns off optimized
                                # implementations of certain
functions.

-import re, types, sys, cStringIO, md5, os.path
+import re, types, sys, cStringIO, os.path
+
+# The hashlib module (new in Python 2.5) is preferred over the md5
module. The
+# (old) md5 module is deprecated since Python 2.5.
+try:
+    import hashlib
+    def new_md5():
+        return hashlib.md5()
+except:
+    import md5
+    def new_md5():
+        return md5.new()

 # Exception raised for yacc-related errors
 class YaccError(Exception):   pass
@@ -1156,7 +1167,7 @@

     Errorfunc    = None    # User defined error handler

-    Signature    = md5.new()   # Digital signature of the grammar
rules, precedence
+    Signature    = new_md5()   # Digital signature of the grammar
rules, precedence
                                # and other information.  Used to
determined when a
                                # parsing table needs to be
regenerated.

****** end of patch *********

Dennis
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"ply-hack" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/ply-hack?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to