Open
Description
It would be great if the following header is supported:
#! /usr/bin/env python
# -*- coding: utf-8 -*-
please see:
pep-0263
hax workaround:
def get_encoding(path):
if not isinstance(path, Path):
path = Path(path)
with open(path, 'rb') as stream:
raw_bytes = stream.read(1024)
encoding = chardet.detect(raw_bytes)['encoding']
if path.suffix.lower() == '.py':
start_pos = raw_bytes.find(b'-*- coding: ')
if start_pos != -1:
start_pos += 12
end_pos = raw_bytes[start_pos:].find(b' -*-')
if end_pos:
end_pos += start_pos
coding = raw_bytes[start_pos:end_pos]
encoding = coding.decode(encoding)
return encoding
<
3D09
/div>
Metadata
Metadata
Assignees
Labels
No labels