Update the ``current_file`` FileReference with its updated SHA1 hex-encoded checksum. Return a mapping of {'current_file': current_file} 'Z' is a file checksum (for files and links) For example: Z:Q1WTc55xfvPogzA0YUV24D0Ym+MKE= The 1st char is an encoding code: Q means ba
(value, current_file, **kwargs)
| 1105 | |
| 1106 | |
| 1107 | def Z_checksum_handler(value, current_file, **kwargs): |
| 1108 | """ |
| 1109 | Update the ``current_file`` FileReference with its updated SHA1 hex-encoded |
| 1110 | checksum. |
| 1111 | |
| 1112 | Return a mapping of {'current_file': current_file} |
| 1113 | |
| 1114 | 'Z' is a file checksum (for files and links) |
| 1115 | For example: Z:Q1WTc55xfvPogzA0YUV24D0Ym+MKE= |
| 1116 | |
| 1117 | The 1st char is an encoding code: Q means base64 and the 2nd char is |
| 1118 | the type of checksum: 1 means SHA1 so Q1 means based64-encoded SHA1 |
| 1119 | """ |
| 1120 | assert value.startswith('Q1'), ( |
| 1121 | f'Unknown checksum or encoding: should start with Q1 for base64-encoded SHA1: {value}') |
| 1122 | sha1 = base64.b64decode(value[2:]) |
| 1123 | sha1 = codecs.encode(sha1, 'hex').decode('utf-8').lower() |
| 1124 | current_file.sha1 = sha1 |
| 1125 | return {'current_file': current_file} |
| 1126 | |
| 1127 | |
| 1128 | def get_checksum_entries(value): |