Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(2)

Side by Side Diff: Lib/filecmp.py

Issue 10639: reindent.py converts newlines to platform default
Patch Set: Created 8 years, 8 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/email/utils.py ('k') | Lib/ftplib.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 """Utilities for comparing files and directories. 1 """Utilities for comparing files and directories.
2 2
3 Classes: 3 Classes:
4 dircmp 4 dircmp
5 5
6 Functions: 6 Functions:
7 cmp(f1, f2, shallow=True) -> int 7 cmp(f1, f2, shallow=True) -> int
8 cmpfiles(a, b, common) -> ([], [], []) 8 cmpfiles(a, b, common) -> ([], [], [])
9 9
10 """ 10 """
(...skipping 30 matching lines...) Expand all
41 41
42 s1 = _sig(os.stat(f1)) 42 s1 = _sig(os.stat(f1))
43 s2 = _sig(os.stat(f2)) 43 s2 = _sig(os.stat(f2))
44 if s1[0] != stat.S_IFREG or s2[0] != stat.S_IFREG: 44 if s1[0] != stat.S_IFREG or s2[0] != stat.S_IFREG:
45 return False 45 return False
46 if shallow and s1 == s2: 46 if shallow and s1 == s2:
47 return True 47 return True
48 if s1[1] != s2[1]: 48 if s1[1] != s2[1]:
49 return False 49 return False
50 50
51 outcome = _cache.get((f1, f2, s1, s2)) 51 result = _cache.get((f1, f2))
52 if outcome is None: 52 if result and (s1, s2) == result[:2]:
53 outcome = _do_cmp(f1, f2) 53 return result[2]
54 if len(_cache) > 100: # limit the maximum size of the cache 54 outcome = _do_cmp(f1, f2)
55 _cache.clear() 55 _cache[f1, f2] = s1, s2, outcome
56 _cache[f1, f2, s1, s2] = outcome
57 return outcome 56 return outcome
58 57
59 def _sig(st): 58 def _sig(st):
60 return (stat.S_IFMT(st.st_mode), 59 return (stat.S_IFMT(st.st_mode),
61 st.st_size, 60 st.st_size,
62 st.st_mtime) 61 st.st_mtime)
63 62
64 def _do_cmp(f1, f2): 63 def _do_cmp(f1, f2):
65 bufsize = BUFSIZE 64 bufsize = BUFSIZE
66 with open(f1, 'rb') as fp1, open(f2, 'rb') as fp2: 65 with open(f1, 'rb') as fp1, open(f2, 'rb') as fp2:
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 if len(args) != 2: 286 if len(args) != 2:
288 raise getopt.GetoptError('need exactly two args', None) 287 raise getopt.GetoptError('need exactly two args', None)
289 dd = dircmp(args[0], args[1]) 288 dd = dircmp(args[0], args[1])
290 if ('-r', '') in options: 289 if ('-r', '') in options:
291 dd.report_full_closure() 290 dd.report_full_closure()
292 else: 291 else:
293 dd.report() 292 dd.report()
294 293
295 if __name__ == '__main__': 294 if __name__ == '__main__':
296 demo() 295 demo()
OLDNEW
« no previous file with comments | « Lib/email/utils.py ('k') | Lib/ftplib.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+