Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jul 26, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions bin/chardetect.py
Original file line number Diff line number Diff line change
@@ -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()
2 changes: 1 addition & 1 deletion chardet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# 02110-1301 USA
######################### END LICENSE BLOCK #########################

__version__ = "1.0.1"
__version__ = "1.1"

def detect(aBuf):
import universaldetector
Expand Down
14 changes: 13 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

setup(
name = 'chardet',
version = '1.0.3',
version = '1.1',
description = 'Universal encoding detector',
long_description = """\
Universal character encoding detector
Expand All @@ -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',
Expand All @@ -48,5 +59,6 @@
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: Text Processing :: Linguistic",
],
scripts=['bin/chardetect.py'],
packages = ['chardet']
)