diff options
author | Guido van Rossum <guido@python.org> | 1999-06-25 14:12:50 +0000 |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1999-06-25 14:12:50 +0000 |
commit | 3aa9ca147b24eb55b350f5dea9ccdf37673de044 (patch) | |
tree | c13a223d802ec5fc015340c6b60f5fecb1a0b43e | |
parent | cf6905f986613b20f00ebbcecf6cc07ce298cbee (diff) | |
download | cpython-git-3aa9ca147b24eb55b350f5dea9ccdf37673de044.tar.gz |
Patch by Mikael Lyngvig:
1. Fix incorrect file open mode on Win32 platforms (use "rb" instead
of "r").
2. Add shallow parameter to cmp.cmp(). If false, deep file
comparisons are made.
The module should be 100 percent backwards compatible.
-rw-r--r-- | Lib/cmp.py | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/Lib/cmp.py b/Lib/cmp.py index 69e6e272c6..f21d3a240e 100644 --- a/Lib/cmp.py +++ b/Lib/cmp.py @@ -12,14 +12,14 @@ import os cache = {} -def cmp(f1, f2): # Compare two files, use the cache if possible. +def cmp(f1, f2, shallow=1): # Compare two files, use the cache if possible. # Return 1 for identical files, 0 for different. # Raise exceptions if either file could not be statted, read, etc. s1, s2 = sig(os.stat(f1)), sig(os.stat(f2)) if s1[0] <> 8 or s2[0] <> 8: # Either is a not a plain file -- always report as different return 0 - if s1 == s2: + if shallow and s1 == s2: # type, size & mtime match -- report same return 1 if s1[:2] <> s2[:2]: # Types or sizes differ, don't bother @@ -52,8 +52,8 @@ def sig(st): # Return signature (i.e., type, size, mtime) from raw stat data def do_cmp(f1, f2): # Compare two files, really bufsize = 8*1024 # Could be tuned - fp1 = open(f1, 'r') - fp2 = open(f2, 'r') + fp1 = open(f1, 'rb') + fp2 = open(f2, 'rb') while 1: b1 = fp1.read(bufsize) b2 = fp2.read(bufsize) |