All pastes #1498303 Raw Edit

Someone

public text v1 · immutable
#1498303 ·published 2009-07-17 14:45 UTC
rendered paste body
Index: flumotion/test/test_common_bundle.py
===================================================================
--- flumotion/test/test_common_bundle.py	(revision 7989)
+++ flumotion/test/test_common_bundle.py	(working copy)
@@ -23,12 +23,12 @@
 
 from flumotion.common import testsuite
 
-from flumotion.common import bundle
+from flumotion.common import bundle, python
+
 import tempfile
 import os
 import StringIO
 import zipfile
-import md5
 import time
 
 
@@ -76,7 +76,7 @@
 
     def testBundlerOneFile(self):
         data = open(self.filename, "r").read()
-        md5sum = md5.new(data).hexdigest()
+        md5sum = python.md5(data).hexdigest()
         name = os.path.split(self.filename)[1]
         b = self.bundler.bundle()
         sum = b.md5sum
@@ -88,7 +88,7 @@
         self.failIf(zip.testzip())
         data = zip.read(name)
         self.failUnless(data)
-        self.assertEquals(md5sum, md5.new(data).hexdigest())
+        self.assertEquals(md5sum, python.md5(data).hexdigest())
 
     # create a bundle of two files then update one of them and check
     # the md5sum changes
Index: flumotion/twisted/credentials.py
===================================================================
--- flumotion/twisted/credentials.py	(revision 7989)
+++ flumotion/twisted/credentials.py	(working copy)
@@ -23,11 +23,9 @@
 Flumotion Twisted credentials
 """
 
-import md5
-
 import random
 
-from flumotion.common import log
+from flumotion.common import log, python
 from twisted.cred import credentials
 from zope.interface import implements
 
@@ -137,8 +135,7 @@
     """
     Respond to a given crypt challenge with our cryptPassword.
     """
-    import md5
-    md = md5.new()
+    md = python.md5()
     md.update(cryptPassword)
     md.update(challenge)
     return md.digest()
@@ -163,7 +160,7 @@
     crap = ''
     for x in range(random.randrange(15, 25)):
         crap = crap + chr(random.randint(65, 90) + x - x) # pychecker madness
-    crap = md5.new(crap).digest()
+    crap = python.md5(crap).digest()
     return crap
 
 
@@ -367,7 +364,7 @@
         elif self._algorithm == 'MD5-sess':
             HA1 = ha1.decode('hex')
 
-            m = md5.md5()
+            m = python.md5()
             m.update(HA1)
             m.update(':')
             m.update(nonce)
@@ -380,7 +377,7 @@
     def _calculateHA2(self, method, uri):
         # We don't support auth-int, otherwise we'd optionally need to do
         # some more work here
-        m = md5.md5()
+        m = python.md5()
         m.update(method)
         m.update(':')
         m.update(uri)
@@ -391,7 +388,7 @@
         HA1 = self._calculateHA1(ha1, nonce, cnonce)
         HA2 = self._calculateHA2(method, uri)
 
-        m = md5.md5()
+        m = python.md5()
         m.update(HA1)
         m.update(':')
         m.update(nonce)
Index: flumotion/monitor/nagios/stream.py
===================================================================
--- flumotion/monitor/nagios/stream.py	(revision 7989)
+++ flumotion/monitor/nagios/stream.py	(working copy)
@@ -29,8 +29,6 @@
 import re
 import time
 import datetime
-import md5
-import sha
 import urlparse
 import urllib2
 
@@ -40,7 +38,7 @@
 from twisted.internet import reactor, defer
 
 from flumotion.admin import admin, connections
-from flumotion.common import errors, keycards
+from flumotion.common import errors, keycards, python
 from flumotion.monitor.nagios import util
 
 URLFINDER = "http://[^\s'\"]*" # to search urls in playlists
@@ -65,9 +63,9 @@
     stop_time = '%08x' % (time.time() + int(timeout))
     hashable = secret_key + relative_path + start_time + stop_time
     if type == 'md5':
-        hashed = md5.md5(hashable).hexdigest()
+        hashed = python.md5(hashable).hexdigest()
     else:
-        hashed = sha.sha(hashable).hexdigest()
+        hashed = python.sha(hashable).hexdigest()
     return '%s%s%s' % (hashed, start_time, stop_time)
 
 
Index: flumotion/common/bundle.py
===================================================================
--- flumotion/common/bundle.py	(revision 7989)
+++ flumotion/common/bundle.py	(working copy)
@@ -25,13 +25,12 @@
 
 import StringIO
 import errno
-import md5
 import os
 import sys
 import tempfile
 import zipfile
 
-from flumotion.common import errors, dag
+from flumotion.common import errors, dag, python
 from flumotion.common.python import makedirs
 
 __all__ = ['Bundle', 'Bundler', 'Unbundler', 'BundlerBasket']
@@ -77,7 +76,7 @@
         @returns: the md5 sum a 32 character string of hex characters.
         """
         data = open(self.source, "r").read()
-        return md5.new(data).hexdigest()
+        return python.md5(data).hexdigest()
 
     def timestamp(self):
         """
@@ -135,7 +134,7 @@
         Set the bundle to the given data representation of the zip file.
         """
         self.zip = zip
-        self.md5sum = md5.new(self.zip).hexdigest()
+        self.md5sum = python.md5(self.zip).hexdigest()
 
     def getZip(self):
         """
Index: flumotion/common/python.py
===================================================================
--- flumotion/common/python.py	(revision 7989)
+++ flumotion/common/python.py	(working copy)
@@ -88,3 +88,13 @@
         mkdir(name, mode)
 else:
     from os import makedirs
+
+# python 2.6 deprecates sha and md5 modules in favor of hashlib
+try:
+    _hashlib = __import__("hashlib")
+except ImportError:
+    from md5 import md5
+    from sha import sha as sha1
+else:
+    from hashlib import md5 as md5
+    from hashlib import sha1 as sha1
Index: flumotion/common/messages.py
===================================================================
--- flumotion/common/messages.py	(revision 7989)
+++ flumotion/common/messages.py	(working copy)
@@ -30,6 +30,7 @@
 from flumotion.common import log
 from flumotion.configure import configure
 from flumotion.common.i18n import FancyEqMixin, Translatable
+from flumotion.common.i18n import *
 
 __version__ = "$Rev$"
 
Index: flumotion/common/registry.py
===================================================================
--- flumotion/common/registry.py	(revision 7989)
+++ flumotion/common/registry.py	(working copy)
@@ -23,7 +23,6 @@
 """
 
 import os
-import sets
 import stat
 import errno
 import sys
@@ -39,6 +38,13 @@
 
 __all__ = ['ComponentRegistry', 'registry']
 __version__ = "$Rev$"
+
+# to work with python 2.3 as well; sets was deprecated in 2.6
+try:
+    set
+except NameError:
+    from sets import Set as set
+
 # Re-enable when reading the registry cache is lighter-weight, or we
 # decide that it's a good idea, or something. See #799.
 READ_CACHE = False
@@ -1695,9 +1701,9 @@
 
         # A bit complicated because we want to allow FLU_PROJECT_PATH to
         # point to nonexistent directories
-        registryPaths = sets.Set(self._getRegistryPathsFromEnviron())
-        oldRegistryPaths = sets.Set([directory.getPath()
-                                     for directory in self.getDirectories()])
+        registryPaths = set(self._getRegistryPathsFromEnviron())
+        oldRegistryPaths = set([directory.getPath()
+                                for directory in self.getDirectories()])
         if registryPaths != oldRegistryPaths:
             if oldRegistryPaths - registryPaths:
                 return True
Index: flumotion/admin/admin.py
===================================================================
--- flumotion/admin/admin.py	(revision 7989)
+++ flumotion/admin/admin.py	(working copy)
@@ -421,8 +421,8 @@
                          '</connection>'])
 
             import os
-            import md5
-            md5sum = md5.new(s).hexdigest()
+            from flumotion.common import python
+            md5sum = python.md5(s).hexdigest()
             f = os.path.join(configure.registrydir, '%s.connection' % md5sum)
             try:
                 h = open(f, 'w')
Index: flumotion/component/bouncers/saltsha256.py
===================================================================
--- flumotion/component/bouncers/saltsha256.py	(revision 7989)
+++ flumotion/component/bouncers/saltsha256.py	(working copy)
@@ -20,10 +20,9 @@
 # Headers in this file shall remain intact.
 
 """
-an bouncer with a username/salt/sha256 data backend
+a bouncer with a username/salt/sha256 data backend
 """
 
-import md5
 import random
 
 from twisted.python import components
Index: flumotion/component/bouncers/bouncer.py
===================================================================
--- flumotion/component/bouncers/bouncer.py	(revision 7989)
+++ flumotion/component/bouncers/bouncer.py	(working copy)
@@ -83,13 +83,12 @@
 call removeKeycardId when the keycard is no longer used.
 """
 
-import md5
 import random
 import time
 
 from twisted.internet import defer, reactor
 
-from flumotion.common import interfaces, keycards, errors
+from flumotion.common import interfaces, keycards, errors, python
 from flumotion.common.poller import Poller
 from flumotion.common.componentui import WorkerComponentUIState
 
@@ -703,7 +702,7 @@
                 else:
                     # random-ish salt, otherwise it's too obvious
                     string = str(random.randint(pow(10, 10), pow(10, 11)))
-                    md = md5.new()
+                    md = python.md5()
                     md.update(string)
                     keycard.salt = md.hexdigest()[:2]
                     self.debug("user not found, inventing bogus salt")
Index: flumotion/component/bouncers/plug.py
===================================================================
--- flumotion/component/bouncers/plug.py	(revision 7989)
+++ flumotion/component/bouncers/plug.py	(working copy)
@@ -83,13 +83,12 @@
 call removeKeycardId when the keycard is no longer used.
 """
 
-import md5
 import random
 import time
 
 from twisted.internet import defer, reactor
 
-from flumotion.common import keycards, common, errors
+from flumotion.common import keycards, common, errors, python
 from flumotion.common.poller import Poller
 from flumotion.component.plugs import base as pbase
 from flumotion.twisted import credentials
@@ -331,7 +330,7 @@
                 else:
                     # random-ish salt, otherwise it's too obvious
                     string = str(random.randint(pow(10, 10), pow(10, 11)))
-                    md = md5.new()
+                    md = python.md5()
                     md.update(string)
                     keycard.salt = md.hexdigest()[:2]
                     self.debug("user not found, inventing bogus salt")
Index: flumotion/component/bouncers/htpasswdcrypt.py
===================================================================
--- flumotion/component/bouncers/htpasswdcrypt.py	(revision 7989)
+++ flumotion/component/bouncers/htpasswdcrypt.py	(working copy)
@@ -23,7 +23,6 @@
 an htpasswd-backed bouncer with crypt passwords
 """
 
-import md5
 import random
 
 from twisted.python import components
Index: flumotion/component/misc/httpserver/cachedprovider.py
===================================================================
--- flumotion/component/misc/httpserver/cachedprovider.py	(revision 7989)
+++ flumotion/component/misc/httpserver/cachedprovider.py	(working copy)
@@ -21,7 +21,6 @@
 
 import errno
 import os
-import sha # hashlib is not available with python 2.4
 import stat
 import tempfile
 import threading
@@ -29,7 +28,7 @@
 
 from twisted.internet import defer, reactor, abstract
 
-from flumotion.common import log, format, common
+from flumotion.common import log, format, common, python
 from flumotion.component.misc.httpserver import cachestats
 from flumotion.component.misc.httpserver import fileprovider
 from flumotion.component.misc.httpserver import localpath
@@ -168,7 +167,7 @@
         """
         ident = self._identifiers.get(path, None)
         if ident is None:
-            hash = sha.sha()
+            hash = python.sha()
             hash.update(path)
             ident = hash.digest().encode("hex").strip('\n')
             # Prevent the cache from growing endlessly
Index: common/validate-registry.py
===================================================================
--- common/validate-registry.py	(revision 7989)
+++ common/validate-registry.py	(working copy)
@@ -16,10 +16,13 @@
 _old_showwarning = warnings.showwarning
 
 
-def showwarning(message, category, filename, lineno, file=None):
-    _old_showwarning(message, category, filename, lineno, file)
+def showwarning(message, category, filename, lineno, file=None, line=None):
+    _old_showwarning(message, category, filename, lineno, file, line=line)
     if category is not DeprecationWarning:
         return
+    # uncomment to see better where the problem comes from when it claims
+    # to be in ihooks.py
+    # import traceback; traceback.print_stack()
     global exitCode
     exitCode += 1
 warnings.showwarning = showwarning