Ticket #5747 (closed defect: fixed)

Opened 4 years ago

Last modified 3 months ago

[Patch] Using of deprecated sha module in graphviz.py

Reported by: shurup Assigned to: rjollos
Priority: normal Component: GraphvizPlugin
Severity: normal Keywords: patch
Cc: py.hieroglyph@googlemail.com, shogsbro, cboos, hasienda Trac Release: 0.11

Description

We've updated Python from 2.5 to 2.6 on our server with Trac installation. After that, we're getting Python warnings every single time graphviz plugin is used. The warning is as follows:

/usr/lib64/python2.6/site-packages/graphviz-0.7.4-py2.6.egg/graphviz/graphviz.py:23:
DeprecationWarning: the sha module is deprecated; use the hashlib module instead

The problem exists in 0.7.6dev version as well. I guess, this should be fixed.

Attachments

GraphViz-fix-py26-sha.patch (1.1 kB) - added by itamarost on 09/26/10 10:56:30.
Patch to fix sha module deprecation in Python 2.6 while maintaining compatability
GraphViz-fix-py26-sha.2.patch (1.1 kB) - added by itamarost on 09/26/10 11:01:43.
same patch, fixed mistake in import

Change History

09/11/09 17:16:24 changed by bobbysmith007

Index: graphviz/graphviz.py
===================================================================
--- graphviz/graphviz.py        (revision 6531)
+++ graphviz/graphviz.py        (working copy)
@@ -20,7 +20,7 @@
 import locale
 import os
 import re
-import sha
+import hashlib
 import subprocess
 import sys

@@ -310,7 +310,7 @@
         encoded_cmd = (processor + unicode(self.processor_options)) \
                 .encode(self.encoding)
         encoded_content = content.encode(self.encoding)
-        sha_key  = sha.new(encoded_cmd + encoded_content).hexdigest()
+        sha_key  = hashlib.sha1(encoded_cmd + encoded_content).hexdigest()
         img_name = '%s.%s.%s' % (sha_key, processor, out_format)
         # cache: hash.<dot>.<png>
         img_path = os.path.join(self.cache_dir, img_name)

I made the change earlier today, and this seems to work.

03/03/10 13:00:09 changed by anonymous

  • cc set to py.hieroglyph@googlemail.com.

Added cc for fix updates...

03/03/10 15:31:00 changed by AdrianFritz

  • summary changed from Using of deprecated sha module in graphviz.py to [Patch] Using of deprecated sha module in graphviz.py.

03/03/10 16:06:03 changed by bobbysmith007

  • keywords set to patch.

09/11/10 19:38:19 changed by paresh.solanki@bellfruitgames.co.uk

This works for me too.

Can this be applied to the next version?

09/14/10 23:23:14 changed by shogsbro

It would be nice to get some of these trivial updates applied to the SVN tree.

09/14/10 23:23:32 changed by shogsbro

  • cc changed from py.hieroglyph@googlemail.com to py.hieroglyph@googlemail.com, shogsbro.

09/16/10 02:14:25 changed by rjollos

It looks like cboos is maintaining this plugin, so you might need to talk with him.

09/26/10 10:56:30 changed by itamarost

  • attachment GraphViz-fix-py26-sha.patch added.

Patch to fix sha module deprecation in Python 2.6 while maintaining compatability

09/26/10 10:59:26 changed by itamarost

  • priority changed from low to normal.

I have attached a GraphViz-fix-py26-sha.patch that fixes the deprecation warning in Python 2.6 without breaking compatibility (since hashlib does not exist in pre-2.5).

Basically, I simply reused the fix that was made in Trac core via the trac.util.compat module.

Hope this gets in soon...

09/26/10 11:01:43 changed by itamarost

  • attachment GraphViz-fix-py26-sha.2.patch added.

same patch, fixed mistake in import

10/28/11 04:40:58 changed by olaf.meeuwissen@avasys.jp

+1 and #8938 seems to be a duplicate of this ticket

10/28/11 04:45:34 changed by rjollos

  • cc changed from py.hieroglyph@googlemail.com, shogsbro to py.hieroglyph@googlemail.com, shogsbro, cboos.

I'd like to finally get this fixed too and get rid of the warnings in my log file. I'll go ahead and take care of committing this to the repos if cboos has no objections (or if we don't hear anything back in the standard 2 week time period).

01/17/12 05:00:56 changed by kuaima@gmail.com

+1. It's annoying in the log to see the warning.

01/17/12 05:02:36 changed by kuaima@gmail.com

Another suggestion, only replace module sha with hashlib.sha1 works for me. My environment pyton 2.6.7.

01/23/12 09:23:46 changed by rjollos

  • owner changed from pkropf to rjollos.

I'd like to go ahead and fix this if the maintainer has no objections.

(follow-up: ↓ 19 ) 02/09/12 03:51:02 changed by rjollos

  • status changed from new to assigned.

I've issued sufficient warning in comment:11 and comment:14 ... time to apply this ;)

The patch by itamarost is great, except sha1 doesn't exist doesn't exist in trac.util.compat in 0.11, and we are trying to maintain compatibility on plugins back to 0.11.

hasienda, this is a perfect candidate for the trachacks-compat class, or whatever we end up calling it. From trac-0.11-stable:

try:
    from hashlib import md5, sha1
except ImportError:
    from md5 import md5
    from sha import new as sha1

02/09/12 04:03:53 changed by rjollos

(In [11263]) Refs #5747: (0.11 branch) Replaced import of deprecated sha with import of sha1 from the hashlib library. Falls back to still use sha if hashlib (since Python 2.5) is not available.

Thank you to bobbysmith007 and itamarost for useful suggestions on a solution.

This has been tested with trac0.11 and trac0.13dev [t 10966] with Python 2.6.

02/09/12 04:09:10 changed by rjollos

  • cc changed from py.hieroglyph@googlemail.com, shogsbro, cboos to py.hieroglyph@googlemail.com, shogsbro, cboos, hasienda.

I'll leave this ticket open for a while to see if there are any issues.

hasienda, I had meant to cc you on comment:15, which you might find interesting.

02/14/12 21:39:48 changed by rjollos

  • status changed from assigned to closed.
  • resolution set to fixed.

(in reply to: ↑ 15 ) 05/10/12 00:32:36 changed by rjollos

Replying to rjollos:

hasienda, this is a perfect candidate for the trachacks-compat class, or whatever we end up calling it. From trac-0.11-stable:

There is a similar issue for the WorkLogPlugin in #9990.

02/21/13 22:03:36 changed by rjollos

It looks like the fix in [11263] will need to be merged over to the 1.0 branch, depending on what you decide to do with trunk going forward.


Add/Change #5747 ([Patch] Using of deprecated sha module in graphviz.py)




Change Properties
Action