verboselib.cli.encoding   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 10
dl 0
loc 14
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A has_bom() 0 8 2
1
import codecs
2
3
from pathlib import Path
4
5
6
def has_bom(file_path: Path) -> bool:
7
  with file_path.open("rb") as f:
8
    sample = f.read(4)
9
10
  return (
11
       sample[:3] == b"\xef\xbb\xbf"
12
    or sample.startswith(codecs.BOM_UTF16_LE)
13
    or sample.startswith(codecs.BOM_UTF16_BE)
14
  )
15