File: __init__.py

package info (click to toggle)
felix 1.1.1-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 4,992 kB
  • ctags: 1,178
  • sloc: python: 7,260; makefile: 408; sh: 58
file content (21 lines) | stat: -rw-r--r-- 612 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#line 63 "interscript/src/encoding.ipk"
# encoding subpackage

iso10646_signatures = (
  ('\xFE\xFF'        , 'utf16'),   # unicode, also ucs2
  ('\xFF\xFE'        , 'utf16le'), # little endian unicode, also ucs2le
  ('\x00\x00\xFE\xFE' , 'ucs4'),    # full four byte encoding
  ('\xFE\xFE\x00\x00' , 'ucs4le'),  # little endian four byte encoding
  ('\xEF\xBB\xBF'    , 'utf8')     # utf8
)

def autodetect(filename):
  f = open(filename,'rb')
  data = f.read(4)
  f.close()
  data = data +'XXXX'
  for signature,name in signatures:
    if signature == data[:len(signature)]:
      return name
  return 'utf8'