Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add a command-line tool. Bump version to 1.1.

  • Loading branch information...
commit 0f302b986fba92a73ecd2b1f9003bba9cffe3219 1 parent b9b5516
@erikrose erikrose authored
Showing with 53 additions and 2 deletions.
  1. +39 −0 bin/chardetect.py
  2. +1 −1  chardet/__init__.py
  3. +13 −1 setup.py
View
39 bin/chardetect.py
@@ -0,0 +1,39 @@
+#!/usr/bin/env python
+"""
+Script which takes one or more file paths and reports on their detected
+encodings
+
+Example::
+
+ % chardetect.py somefile someotherfile
+ somefile: windows-1252 with confidence 0.5
+ someotherfile: ascii with confidence 1.0
+
+"""
+from sys import argv
+
+from chardet.universaldetector import UniversalDetector
+
+
+def description_of(path):
+ """Return a string describing the probable encoding of a file."""
+ u = UniversalDetector()
+ for line in open(path, 'rb'):
+ u.feed(line)
+ u.close()
+ result = u.result
+ if result['encoding']:
+ return '%s: %s with confidence %s' % (path,
+ result['encoding'],
+ result['confidence'])
+ else:
+ return '%s: no result' % path
+
+
+def main():
+ for path in argv[1:]:
+ print description_of(path)
+
+
+if __name__ == '__main__':
+ main()
View
2  chardet/__init__.py
@@ -15,7 +15,7 @@
# 02110-1301 USA
######################### END LICENSE BLOCK #########################
-__version__ = "1.0.1"
+__version__ = "1.1"
def detect(aBuf):
import universaldetector
View
14 setup.py
@@ -10,7 +10,7 @@
setup(
name = 'chardet',
- version = '1.0.3',
+ version = '1.1',
description = 'Universal encoding detector',
long_description = """\
Universal character encoding detector
@@ -30,6 +30,17 @@
- TIS-620 (Thai)
Requires Python 2.1 or later
+
+Command-line Tool
+-----------------
+
+chardet comes with a command-line script which reports on the encodings of one
+or more files::
+
+ % chardetect.py somefile someotherfile
+ somefile: windows-1252 with confidence 0.5
+ someotherfile: ascii with confidence 1.0
+
""",
author='Mark Pilgrim',
author_email = 'mark@diveintomark.org',
@@ -48,5 +59,6 @@
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: Text Processing :: Linguistic",
],
+ scripts=['bin/chardetect.py'],
packages = ['chardet']
)
Please sign in to comment.
Something went wrong with that request. Please try again.