/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: Canonical.com Patch Queue Manager
  • Date: 2008-09-29 08:49:52 UTC
  • mfrom: (3741.2.1 trunk)
  • Revision ID: pqm@pqm.ubuntu.com-20080929084952-3d81d63rru8tt8mm
(vila) Fix python-2.6 various compatibility issues

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 and md5 modules are deprecated in python2.6 but hashlib is available as
 
56
# of 2.5
 
57
if sys.version_info < (2, 5):
 
58
    import md5 as _mod_md5
 
59
    md5 = _mod_md5.new
 
60
    import sha as _mod_sha
 
61
    sha = _mod_sha.new
 
62
else:
 
63
    from hashlib import (
 
64
        md5,
 
65
        sha1 as sha,
 
66
        )
 
67
 
56
68
 
57
69
import bzrlib
58
70
from bzrlib import symbol_versioning
569
581
 
570
582
    The file cursor should be already at the start.
571
583
    """
572
 
    s = sha.new()
 
584
    s = sha()
573
585
    BUFSIZE = 128<<10
574
586
    while True:
575
587
        b = f.read(BUFSIZE)
581
593
 
582
594
def sha_file_by_name(fname):
583
595
    """Calculate the SHA1 of a file by reading the full text"""
584
 
    s = sha.new()
 
596
    s = sha()
585
597
    f = os.open(fname, os.O_RDONLY | O_BINARY)
586
598
    try:
587
599
        while True:
593
605
        os.close(f)
594
606
 
595
607
 
596
 
def sha_strings(strings, _factory=sha.new):
 
608
def sha_strings(strings, _factory=sha):
597
609
    """Return the sha-1 of concatenation of strings"""
598
610
    s = _factory()
599
611
    map(s.update, strings)
600
612
    return s.hexdigest()
601
613
 
602
614
 
603
 
def sha_string(f, _factory=sha.new):
 
615
def sha_string(f, _factory=sha):
604
616
    return _factory(f).hexdigest()
605
617
 
606
618
 
607
619
def fingerprint_file(f):
608
620
    b = f.read()
609
621
    return {'size': len(b),
610
 
            'sha1': sha.new(b).hexdigest()}
 
622
            'sha1': sha(b).hexdigest()}
611
623
 
612
624
 
613
625
def compare_files(a, b):