File: isutf8.py

package info (click to toggle)
snpeff 5.4.b%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 757,496 kB
  • sloc: java: 62,572; perl: 2,279; sh: 1,185; python: 744; xml: 507; makefile: 50
file content (29 lines) | stat: -rwxr-xr-x 565 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env python

# FIXME: This script doesn't work in python3

import sys
import os.path

for file in sys.argv:
	if os.path.isfile(file):
		#print "File:", file
		content = open(file, 'rb').read()

		ok = True
		try:
			unicode(content, 'utf-8')
		except UnicodeDecodeError:
			print "File '", file, "' is not UTF-8"
			ok = False

		if not ok:
			lineNum = 1
			for line in content.split('\n'):
				try:
					unicode(line, 'utf-8')
				except UnicodeDecodeError:
					print "\tNon UTF-8 line ", lineNum,":\t", line
					ok = False

				lineNum = lineNum + 1