Mercurial > hgrepos > Python > apps > py-cutils
comparison cutils/treesum.py @ 322:0cabc5439505
treesum: Remove CRC32Output completely
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Wed, 26 Mar 2025 13:00:40 +0100 |
| parents | 49ecfff4f319 |
| children | 48430941c18c |
comparison
equal
deleted
inserted
replaced
| 321:49ecfff4f319 | 322:0cabc5439505 |
|---|---|
| 1241 return u"/".join(top) + u"/" + name | 1241 return u"/".join(top) + u"/" + name |
| 1242 else: | 1242 else: |
| 1243 return name | 1243 return name |
| 1244 | 1244 |
| 1245 | 1245 |
| 1246 class CRC32Output(object): | |
| 1247 | |
| 1248 """Wrapper for a minimal binary file contextmanager that calculates | |
| 1249 the CRC32 of the written bytes on the fly. | |
| 1250 | |
| 1251 Also acts as context manager proxy for the given context manager. | |
| 1252 | |
| 1253 """ | |
| 1254 | |
| 1255 __slots__ = ("_fp_cm", "_fp", "_crc32") | |
| 1256 | |
| 1257 def __init__(self, fp_cm): | |
| 1258 self._fp_cm = fp_cm | |
| 1259 self._fp = None | |
| 1260 self.resetdigest() | |
| 1261 | |
| 1262 def __enter__(self): | |
| 1263 assert self._fp is None | |
| 1264 self._fp = self._fp_cm.__enter__() | |
| 1265 return self | |
| 1266 | |
| 1267 def __exit__(self, *args): | |
| 1268 rv = self._fp_cm.__exit__(*args) | |
| 1269 self._fp = None | |
| 1270 return rv | |
| 1271 | |
| 1272 def write(self, what): | |
| 1273 self._fp.write(what) | |
| 1274 self._crc32.update(what) | |
| 1275 | |
| 1276 def flush(self): | |
| 1277 self._fp.flush() | |
| 1278 | |
| 1279 def resetdigest(self): | |
| 1280 """Reset the current CRC digest""" | |
| 1281 self._crc32 = crc32() | |
| 1282 | |
| 1283 def hexcrcdigest(self): | |
| 1284 """ | |
| 1285 | |
| 1286 :rtype: str | |
| 1287 | |
| 1288 """ | |
| 1289 return self._crc32.hexdigest() | |
| 1290 | |
| 1291 | |
| 1292 def normalized_compatible_mode_str(mode): | 1246 def normalized_compatible_mode_str(mode): |
| 1293 # XXX FIXME: Windows and "executable" | 1247 # XXX FIXME: Windows and "executable" |
| 1294 modebits = stat.S_IMODE(mode) | 1248 modebits = stat.S_IMODE(mode) |
| 1295 modestr = "%o" % (modebits,) | 1249 modestr = "%o" % (modebits,) |
| 1296 if not modestr.startswith("0"): | 1250 if not modestr.startswith("0"): |
