Changeset 5048
- Timestamp:
- Feb 19, 2008, 10:30:48 AM (16 years ago)
- Location:
- anuga_core/source/anuga/utilities
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/utilities/system_tools.py
r5046 r5048 170 170 if verbose is True: 171 171 print 'Version info stored to %s' %filename 172 172 173 def safe_crc(string): 174 """64 bit safe crc computation. 175 176 See Guido's 64 bit fix at http://bugs.python.org/issue1202 177 """ 178 179 from zlib import crc32 180 import os 181 182 x = crc32(string) 183 184 if os.name == 'posix' and os.uname()[4] == 'x86_64': 185 crcval = x - ((x & 0x80000000) << 1) 186 else: 187 crcval = x 188 189 return crcval 190 173 191 174 192 def compute_checksum(filename, max_length=2**20): … … 180 198 """ 181 199 182 from zlib import crc32183 184 200 fid = open(filename, 'rb') # Use binary for portability 185 x = crc32(fid.read(max_length)) 186 201 crcval = safe_crc(fid.read(max_length)) 187 202 fid.close() 188 203 189 if os.name == 'posix' and os.uname()[4] == 'x86_64':190 #Guido's 64 bit fix (http://bugs.python.org/issue1202)191 crcval = x - ((x & 0x80000000) << 1)192 else:193 crcval = x194 204 return crcval -
anuga_core/source/anuga/utilities/test_system_tools.py
r5044 r5048 39 39 # Generate a text file 40 40 tmp_fd , tmp_name = mkstemp(suffix='.tmp', dir='.') 41 fid = os.fdopen(tmp_fd, 'w ')41 fid = os.fdopen(tmp_fd, 'w+b') 42 42 string = 'My temp file with textual content. AAAABBBBCCCC1234' 43 43 fid.write(string) 44 44 fid.close() 45 45 46 ref_crc = zlib.crc32(string) 46 # Have to apply the 64 bit fix here since we aren't comparing two 47 # files, but rather a string and a file. 48 ref_crc = safe_crc(string) 49 47 50 checksum = compute_checksum(tmp_name) 48 51 assert checksum == ref_crc … … 60 63 fid.close() 61 64 62 63 ref_crc = zlib.crc32(string) 65 ref_crc = safe_crc(string) 64 66 checksum = compute_checksum(tmp_name) 65 67
Note: See TracChangeset
for help on using the changeset viewer.