Modify

Opened 5 years ago

Last modified 13 months ago

#5747 reopened defect

[Patch] Uses deprecated sha module in graphviz.py

Reported by: shurup Owned by: rjollos
Priority: normal Component: GraphvizPlugin
Severity: normal Keywords: patch
Cc: py.hieroglyph@…, shogsbro, cboos, hasienda Trac Release: 1.0

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 (2)

GraphViz-fix-py26-sha.patch (1.1 KB) - added by itamarost 4 years ago.
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 4 years ago.
same patch, fixed mistake in import

Download all attachments as: .zip

Change History (25)

comment:1 Changed 5 years ago by bobbysmith007

  • graphviz/graphviz.py

     
    2020import locale 
    2121import os 
    2222import re 
    23 import sha 
     23import hashlib 
    2424import subprocess 
    2525import sys 
    2626 
     
    310310        encoded_cmd = (processor + unicode(self.processor_options)) \ 
    311311                .encode(self.encoding) 
    312312        encoded_content = content.encode(self.encoding) 
    313         sha_key  = sha.new(encoded_cmd + encoded_content).hexdigest() 
     313        sha_key  = hashlib.sha1(encoded_cmd + encoded_content).hexdigest() 
    314314        img_name = '%s.%s.%s' % (sha_key, processor, out_format) 
    315315        # cache: hash.<dot>.<png> 
    316316        img_path = os.path.join(self.cache_dir, img_name) 

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

comment:2 Changed 4 years ago by anonymous

  • Cc py.hieroglyph@… added

Added cc for fix updates...

comment:3 Changed 4 years ago by AdrianFritz

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

comment:4 Changed 4 years ago by bobbysmith007

  • Keywords patch added

comment:5 Changed 4 years ago by paresh.solanki@…

This works for me too.

Can this be applied to the next version?

comment:6 Changed 4 years ago by shogsbro

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

comment:7 Changed 4 years ago by shogsbro

  • Cc shogsbro added

comment:8 Changed 4 years ago by rjollos

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

Changed 4 years ago by itamarost

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

comment:9 Changed 4 years ago 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...

Changed 4 years ago by itamarost

same patch, fixed mistake in import

comment:10 Changed 3 years ago by olaf.meeuwissen@…

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

comment:11 Changed 3 years ago by rjollos

  • Cc cboos added

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).

comment:12 Changed 3 years ago by kuaima@…

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

comment:13 Changed 3 years ago by kuaima@…

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

comment:14 Changed 3 years ago by rjollos

  • Owner changed from pkropf to rjollos

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

comment:15 follow-up: Changed 3 years ago 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

comment:16 Changed 3 years ago 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.

comment:17 Changed 3 years ago by rjollos

  • Cc hasienda added

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.

comment:18 Changed 3 years ago by rjollos

  • Resolution set to fixed
  • Status changed from assigned to closed

comment:19 in reply to: ↑ 15 Changed 2 years ago 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.

comment:20 Changed 18 months ago 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.

comment:21 Changed 15 months ago by andrex

  • Resolution fixed deleted
  • Status changed from closed to reopened
  • Trac Release changed from 0.11 to 1.0

Reopening for Trac 1.0, since the problem hasn't been fixed yet in the 1.0 branch.

comment:22 Changed 13 months ago by rjollos

If no one object, we could merge recent changes on the graphvizplugin/branches/1.0 branch back to graphvizplugin/trunk. Future development would then presumably follow the Trac's practice of making bugfixes on the branch and merging them to trunk. For [11263], we could make the change on the branch and do a record-only merge so that we don't get a conflict when merging 1.0 to the trunk.

Version 1, edited 13 months ago by rjollos (previous) (next) (diff)

comment:23 Changed 13 months ago by rjollos

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

Add Comment

Modify Ticket

Action
as reopened .
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.