(b)
| 245 | |
| 246 | |
| 247 | def detect_encoding(b): |
| 248 | bstartswith = b.startswith |
| 249 | if bstartswith((codecs.BOM_UTF32_BE, codecs.BOM_UTF32_LE)): |
| 250 | return 'utf-32' |
| 251 | if bstartswith((codecs.BOM_UTF16_BE, codecs.BOM_UTF16_LE)): |
| 252 | return 'utf-16' |
| 253 | if bstartswith(codecs.BOM_UTF8): |
| 254 | return 'utf-8-sig' |
| 255 | |
| 256 | if len(b) >= 4: |
| 257 | if not b[0]: |
| 258 | # 00 00 -- -- - utf-32-be |
| 259 | # 00 XX -- -- - utf-16-be |
| 260 | return 'utf-16-be' if b[1] else 'utf-32-be' |
| 261 | if not b[1]: |
| 262 | # XX 00 00 00 - utf-32-le |
| 263 | # XX 00 00 XX - utf-16-le |
| 264 | # XX 00 XX -- - utf-16-le |
| 265 | return 'utf-16-le' if b[2] or b[3] else 'utf-32-le' |
| 266 | elif len(b) == 2: |
| 267 | if not b[0]: |
| 268 | # 00 XX - utf-16-be |
| 269 | return 'utf-16-be' |
| 270 | if not b[1]: |
| 271 | # XX 00 - utf-16-le |
| 272 | return 'utf-16-le' |
| 273 | # default |
| 274 | return 'utf-8' |
| 275 | |
| 276 | |
| 277 | def load(fp, *, cls=None, object_hook=None, parse_float=None, |
no outgoing calls
no test coverage detected
searching dependent graphs…