Rev 2930: Fix python2.6 deprecation warnings (still 4 failures 5 errors in test suite). in http://code.launchpad.net/%7Ev-ladeuil/bzr/bzr.python26
Vincent Ladeuil
v.ladeuil+lp at free.fr
Wed Oct 24 14:56:52 BST 2007
At http://code.launchpad.net/%7Ev-ladeuil/bzr/bzr.python26
------------------------------------------------------------
revno: 2930
revision-id:v.ladeuil+lp at free.fr-20071024135634-d8os3by1g6f45q12
parent: pqm at pqm.ubuntu.com-20071023082111-h6u34i4gvlb2nwch
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: bzr.python26
timestamp: Wed 2007-10-24 15:56:34 +0200
message:
Fix python2.6 deprecation warnings (still 4 failures 5 errors in test suite).
* bzrlib/osutils.py:
Wrap md5 and sha imports to be compatible with python 2.4, 2.5,
2.6.
Replace all sha.new() calls by sha() calls they are reputedly
faster (not profiled).
* bzrlib/weave.py:
Update sha import, fix use.
* bzrlib/transport/http/_urllib2_wrappers.py:
Update sha and md5 imports, fix uses.
* bzrlib/tests/test_testament.py:
Update sha import.
* bzrlib/tests/test_knit.py:
Update sha import, fix uses.
* bzrlib/tests/test_hashcache.py:
Update sha import, fix use.
* bzrlib/tests/repository_implementations/test_check_reconcile.py:
Update sha import, fix use.
* bzrlib/tests/HTTPTestUtil.py:
Update md5 import, fix uses. Delete useless sha import.
* bzrlib/testament.py:
Update sha import.
* bzrlib/hashcache.py:
Update sha import.
* bzrlib/revisionspec.py:
(RevisionSpec.__new__): Remove useless parameters since python2.6
is stricter.
modified:
bzrlib/hashcache.py hashcache.py-20050706091756-fe3a8cc1143ff24f
bzrlib/osutils.py osutils.py-20050309040759-eeaff12fbf77ac86
bzrlib/revisionspec.py revisionspec.py-20050907152633-17567659fd5c0ddb
bzrlib/testament.py testament.py-20051011100429-6d319a18183b13c8
bzrlib/tests/HTTPTestUtil.py HTTPTestUtil.py-20050914180604-247d3aafb7a43343
bzrlib/tests/repository_implementations/test_check_reconcile.py test_broken.py-20070928125406-62236394w0jpbpd6-2
bzrlib/tests/test_hashcache.py testhashcache.py-20050706091800-0288ab2659338981
bzrlib/tests/test_knit.py test_knit.py-20051212171302-95d4c00dd5f11f2b
bzrlib/tests/test_testament.py testtestament.py-20051011100429-5df1657310caa929
bzrlib/transport/http/_urllib2_wrappers.py _urllib2_wrappers.py-20060913231729-ha9ugi48ktx481ao-1
bzrlib/weave.py knit.py-20050627021749-759c29984154256b
-------------- next part --------------
=== modified file 'bzrlib/hashcache.py'
--- a/bzrlib/hashcache.py 2007-02-26 01:06:36 +0000
+++ b/bzrlib/hashcache.py 2007-10-24 13:56:34 +0000
@@ -30,9 +30,8 @@
CACHE_HEADER = "### bzr hashcache v5\n"
import os, stat, time
-import sha
-from bzrlib.osutils import sha_file, pathjoin, safe_unicode
+from bzrlib.osutils import sha_file, sha_string, pathjoin, safe_unicode
from bzrlib.trace import mutter, warning
from bzrlib.atomicfile import AtomicFile
from bzrlib.errors import BzrError
@@ -164,7 +163,7 @@
if stat.S_ISREG(mode):
digest = self._really_sha1_file(abspath)
elif stat.S_ISLNK(mode):
- digest = sha.new(os.readlink(abspath)).hexdigest()
+ digest = sha_string(os.readlink(abspath))
else:
raise BzrError("file %r: unknown file stat mode: %o"%(abspath,mode))
=== modified file 'bzrlib/osutils.py'
--- a/bzrlib/osutils.py 2007-10-22 15:54:47 +0000
+++ b/bzrlib/osutils.py 2007-10-24 13:56:34 +0000
@@ -35,7 +35,6 @@
splitdrive as _nt_splitdrive,
)
import posixpath
-import sha
import shutil
from shutil import (
rmtree,
@@ -53,6 +52,17 @@
)
""")
+# sha is deprecated in python2.6 but haslib is available as of 2.5
+if sys.version_info < (2, 5):
+ import md5
+ import sha
+else:
+ from hashlib import (
+ md5,
+ sha1 as sha,
+ )
+
+
import bzrlib
from bzrlib import symbol_versioning
from bzrlib.symbol_versioning import (
@@ -580,7 +590,7 @@
def sha_file(f):
if getattr(f, 'tell', None) is not None:
assert f.tell() == 0
- s = sha.new()
+ s = sha()
BUFSIZE = 128<<10
while True:
b = f.read(BUFSIZE)
@@ -592,7 +602,7 @@
def sha_file_by_name(fname):
"""Calculate the SHA1 of a file by reading the full text"""
- s = sha.new()
+ s = sha()
f = os.open(fname, os.O_RDONLY | O_BINARY)
try:
while True:
@@ -604,21 +614,21 @@
os.close(f)
-def sha_strings(strings, _factory=sha.new):
+def sha_strings(strings, _factory=sha):
"""Return the sha-1 of concatenation of strings"""
s = _factory()
map(s.update, strings)
return s.hexdigest()
-def sha_string(f, _factory=sha.new):
+def sha_string(f, _factory=sha):
return _factory(f).hexdigest()
def fingerprint_file(f):
b = f.read()
return {'size': len(b),
- 'sha1': sha.new(b).hexdigest()}
+ 'sha1': sha(b).hexdigest()}
def compare_files(a, b):
=== modified file 'bzrlib/revisionspec.py'
--- a/bzrlib/revisionspec.py 2007-08-20 13:03:46 +0000
+++ b/bzrlib/revisionspec.py 2007-10-24 13:56:34 +0000
@@ -136,7 +136,7 @@
def __new__(cls, spec, _internal=False):
if _internal:
- return object.__new__(cls, spec, _internal=_internal)
+ return object.__new__(cls)
symbol_versioning.warn('Creating a RevisionSpec directly has'
' been deprecated in version 0.11. Use'
=== modified file 'bzrlib/testament.py'
--- a/bzrlib/testament.py 2007-02-18 00:22:24 +0000
+++ b/bzrlib/testament.py 2007-10-24 13:56:34 +0000
@@ -70,9 +70,12 @@
# revisions can be serialized.
from copy import copy
-from sha import sha
-from bzrlib.osutils import contains_whitespace, contains_linebreaks
+from bzrlib.osutils import (
+ contains_whitespace,
+ contains_linebreaks,
+ sha,
+ )
class Testament(object):
=== modified file 'bzrlib/tests/HTTPTestUtil.py'
--- a/bzrlib/tests/HTTPTestUtil.py 2007-07-03 07:03:32 +0000
+++ b/bzrlib/tests/HTTPTestUtil.py 2007-10-24 13:56:34 +0000
@@ -16,15 +16,14 @@
from cStringIO import StringIO
import errno
-import md5
from SimpleHTTPServer import SimpleHTTPRequestHandler
import re
-import sha
import socket
import time
import urllib2
import urlparse
+from bzrlib.osutils import md5
from bzrlib.smart import protocol
from bzrlib.tests import TestCaseWithTransport
from bzrlib.tests.HttpServer import (
@@ -500,7 +499,7 @@
A1 = '%s:%s:%s' % (user, realm, password)
A2 = '%s:%s' % (command, auth['uri'])
- H = lambda x: md5.new(x).hexdigest()
+ H = lambda x: md5(x).hexdigest()
KD = lambda secret, data: H("%s:%s" % (secret, data))
nonce_count = int(auth['nc'], 16)
=== modified file 'bzrlib/tests/repository_implementations/test_check_reconcile.py'
--- a/bzrlib/tests/repository_implementations/test_check_reconcile.py 2007-10-03 10:54:07 +0000
+++ b/bzrlib/tests/repository_implementations/test_check_reconcile.py 2007-10-24 13:56:34 +0000
@@ -20,9 +20,8 @@
"""
-import sha
-
from bzrlib.inventory import Inventory, InventoryFile
+from bzrlib.osutils import sha
from bzrlib.revision import Revision
from bzrlib.tests import TestNotApplicable
from bzrlib.tests.repository_implementations import TestCaseWithRepository
@@ -90,7 +89,7 @@
entry.revision = revision
entry.text_size = 0
file_contents = '%sline\n' % entry.revision
- entry.text_sha1 = sha.sha(file_contents).hexdigest()
+ entry.text_sha1 = sha(file_contents).hexdigest()
inv.add(entry)
vf = repo.weave_store.get_weave_or_empty(file_id,
repo.get_transaction())
=== modified file 'bzrlib/tests/test_hashcache.py'
--- a/bzrlib/tests/test_hashcache.py 2006-09-20 14:03:05 +0000
+++ b/bzrlib/tests/test_hashcache.py 2007-10-24 13:56:34 +0000
@@ -15,18 +15,18 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
import os
-import sha
import stat
import sys
import time
+from bzrlib import osutils
from bzrlib.errors import BzrError
from bzrlib.hashcache import HashCache
from bzrlib.tests import TestCaseInTempDir, TestSkipped, TestCase
def sha1(t):
- return sha.new(t).hexdigest()
+ return osutils.sha(t).hexdigest()
def pause():
=== modified file 'bzrlib/tests/test_knit.py'
--- a/bzrlib/tests/test_knit.py 2007-10-15 09:04:41 +0000
+++ b/bzrlib/tests/test_knit.py 2007-10-24 13:56:34 +0000
@@ -19,7 +19,6 @@
from cStringIO import StringIO
import difflib
import gzip
-import sha
import sys
from bzrlib import (
@@ -50,7 +49,7 @@
WeaveToKnit,
KnitSequenceMatcher,
)
-from bzrlib.osutils import split_lines
+from bzrlib.osutils import sha, split_lines
from bzrlib.tests import (
Feature,
TestCase,
@@ -370,7 +369,7 @@
return sio.getvalue()
def test_valid_knit_data(self):
- sha1sum = sha.new('foo\nbar\n').hexdigest()
+ sha1sum = sha('foo\nbar\n').hexdigest()
gz_txt = self.create_gz_content('version rev-id-1 2 %s\n'
'foo\n'
'bar\n'
@@ -388,7 +387,7 @@
self.assertEqual([('rev-id-1', gz_txt)], raw_contents)
def test_not_enough_lines(self):
- sha1sum = sha.new('foo\n').hexdigest()
+ sha1sum = sha('foo\n').hexdigest()
# record says 2 lines data says 1
gz_txt = self.create_gz_content('version rev-id-1 2 %s\n'
'foo\n'
@@ -405,7 +404,7 @@
self.assertEqual([('rev-id-1', gz_txt)], raw_contents)
def test_too_many_lines(self):
- sha1sum = sha.new('foo\nbar\n').hexdigest()
+ sha1sum = sha('foo\nbar\n').hexdigest()
# record says 1 lines data says 2
gz_txt = self.create_gz_content('version rev-id-1 1 %s\n'
'foo\n'
@@ -423,7 +422,7 @@
self.assertEqual([('rev-id-1', gz_txt)], raw_contents)
def test_mismatched_version_id(self):
- sha1sum = sha.new('foo\nbar\n').hexdigest()
+ sha1sum = sha('foo\nbar\n').hexdigest()
gz_txt = self.create_gz_content('version rev-id-1 2 %s\n'
'foo\n'
'bar\n'
@@ -441,7 +440,7 @@
data.read_records_iter_raw(records))
def test_uncompressed_data(self):
- sha1sum = sha.new('foo\nbar\n').hexdigest()
+ sha1sum = sha('foo\nbar\n').hexdigest()
txt = ('version rev-id-1 2 %s\n'
'foo\n'
'bar\n'
@@ -460,7 +459,7 @@
data.read_records_iter_raw(records))
def test_corrupted_data(self):
- sha1sum = sha.new('foo\nbar\n').hexdigest()
+ sha1sum = sha('foo\nbar\n').hexdigest()
gz_txt = self.create_gz_content('version rev-id-1 2 %s\n'
'foo\n'
'bar\n'
=== modified file 'bzrlib/tests/test_testament.py'
--- a/bzrlib/tests/test_testament.py 2007-03-06 00:28:36 +0000
+++ b/bzrlib/tests/test_testament.py 2007-10-24 13:56:34 +0000
@@ -19,12 +19,11 @@
# TODO: Testaments with x-bits
import os
-from sha import sha
from bzrlib.tests import TestCaseWithTransport
from bzrlib.testament import Testament, StrictTestament, StrictTestament3
from bzrlib.transform import TreeTransform
-from bzrlib.osutils import has_symlinks
+from bzrlib.osutils import sha, has_symlinks
class TestamentSetup(TestCaseWithTransport):
=== modified file 'bzrlib/transport/http/_urllib2_wrappers.py'
--- a/bzrlib/transport/http/_urllib2_wrappers.py 2007-07-04 12:28:56 +0000
+++ b/bzrlib/transport/http/_urllib2_wrappers.py 2007-10-24 13:56:34 +0000
@@ -48,8 +48,6 @@
# ensure that.
import httplib
-import md5
-import sha
import socket
import urllib
import urllib2
@@ -61,6 +59,7 @@
from bzrlib import __version__ as bzrlib_version
from bzrlib import (
errors,
+ osutils,
ui,
)
@@ -1073,9 +1072,9 @@
H = None
KD = None
if algorithm == 'MD5':
- H = lambda x: md5.new(x).hexdigest()
+ H = lambda x: osutils.md5(x).hexdigest()
elif algorithm == 'SHA':
- H = lambda x: sha.new(x).hexdigest()
+ H = lambda x: osutils.sha(x).hexdigest()
if H is not None:
KD = lambda secret, data: H("%s:%s" % (secret, data))
return H, KD
@@ -1084,7 +1083,7 @@
def get_new_cnonce(nonce, nonce_count):
raw = '%s:%d:%s:%s' % (nonce, nonce_count, time.ctime(),
urllib2.randombytes(8))
- return sha.new(raw).hexdigest()[:16]
+ return osutils.sha(raw).hexdigest()[:16]
class DigestAuthHandler(AbstractAuthHandler):
=== modified file 'bzrlib/weave.py'
--- a/bzrlib/weave.py 2007-10-05 05:52:45 +0000
+++ b/bzrlib/weave.py 2007-10-24 13:56:34 +0000
@@ -71,7 +71,6 @@
from copy import copy
from cStringIO import StringIO
import os
-import sha
import time
import warnings
@@ -86,7 +85,7 @@
WeaveRevisionNotPresent,
)
import bzrlib.errors as errors
-from bzrlib.osutils import sha_strings
+from bzrlib.osutils import sha, sha_strings
import bzrlib.patiencediff
from bzrlib.tsort import topo_sort
from bzrlib.versionedfile import VersionedFile, InterVersionedFile
@@ -697,7 +696,7 @@
# For creating the ancestry, IntSet is much faster (3.7s vs 0.17s)
# The problem is that set membership is much more expensive
name = self._idx_to_name(i)
- sha1s[name] = sha.new()
+ sha1s[name] = sha()
texts[name] = []
new_inc = set([name])
for p in self._parents[i]:
More information about the bazaar-commits
mailing list