Calculate the md5 checksum of a file-like object without reading its whole content in memory. >>> from io import BytesIO >>> md5sum(BytesIO(b'file content to hash')) '784406af91dd5a54fbb9c84c2236595a'
(file: IO[bytes])
| 136 | |
| 137 | |
| 138 | def md5sum(file: IO[bytes]) -> str: |
| 139 | """Calculate the md5 checksum of a file-like object without reading its |
| 140 | whole content in memory. |
| 141 | |
| 142 | >>> from io import BytesIO |
| 143 | >>> md5sum(BytesIO(b'file content to hash')) |
| 144 | '784406af91dd5a54fbb9c84c2236595a' |
| 145 | """ |
| 146 | warnings.warn( |
| 147 | ( |
| 148 | "The scrapy.utils.misc.md5sum function is deprecated and will be " |
| 149 | "removed in a future version of Scrapy." |
| 150 | ), |
| 151 | ScrapyDeprecationWarning, |
| 152 | stacklevel=2, |
| 153 | ) |
| 154 | m = hashlib.md5() # noqa: S324 |
| 155 | while True: |
| 156 | d = file.read(8096) |
| 157 | if not d: |
| 158 | break |
| 159 | m.update(d) |
| 160 | return m.hexdigest() |
| 161 | |
| 162 | |
| 163 | def rel_has_nofollow(rel: str | None) -> bool: |