/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

  • Committer: Vincent Ladeuil
  • Date: 2007-10-24 13:56:34 UTC
  • mto: (3928.1.1 bzr.integration)
  • mto: This revision was merged to the branch mainline in revision 3929.
  • Revision ID: v.ladeuil+lp@free.fr-20071024135634-d8os3by1g6f45q12
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.

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
                    splitdrive as _nt_splitdrive,
36
36
                    )
37
37
import posixpath
38
 
import sha
39
38
import shutil
40
39
from shutil import (
41
40
    rmtree,
53
52
    )
54
53
""")
55
54
 
 
55
# sha is deprecated in python2.6 but haslib is available as of 2.5
 
56
if sys.version_info < (2, 5):
 
57
    import md5
 
58
    import sha
 
59
else:
 
60
    from hashlib import (
 
61
        md5,
 
62
        sha1 as sha,
 
63
        )
 
64
 
 
65
 
56
66
import bzrlib
57
67
from bzrlib import symbol_versioning
58
68
from bzrlib.symbol_versioning import (
580
590
def sha_file(f):
581
591
    if getattr(f, 'tell', None) is not None:
582
592
        assert f.tell() == 0
583
 
    s = sha.new()
 
593
    s = sha()
584
594
    BUFSIZE = 128<<10
585
595
    while True:
586
596
        b = f.read(BUFSIZE)
592
602
 
593
603
def sha_file_by_name(fname):
594
604
    """Calculate the SHA1 of a file by reading the full text"""
595
 
    s = sha.new()
 
605
    s = sha()
596
606
    f = os.open(fname, os.O_RDONLY | O_BINARY)
597
607
    try:
598
608
        while True:
604
614
        os.close(f)
605
615
 
606
616
 
607
 
def sha_strings(strings, _factory=sha.new):
 
617
def sha_strings(strings, _factory=sha):
608
618
    """Return the sha-1 of concatenation of strings"""
609
619
    s = _factory()
610
620
    map(s.update, strings)
611
621
    return s.hexdigest()
612
622
 
613
623
 
614
 
def sha_string(f, _factory=sha.new):
 
624
def sha_string(f, _factory=sha):
615
625
    return _factory(f).hexdigest()
616
626
 
617
627
 
618
628
def fingerprint_file(f):
619
629
    b = f.read()
620
630
    return {'size': len(b),
621
 
            'sha1': sha.new(b).hexdigest()}
 
631
            'sha1': sha(b).hexdigest()}
622
632
 
623
633
 
624
634
def compare_files(a, b):