<_9Y�
� @ s� d Z d d l m Z m Z m Z d d l Z d d l Z d d l m Z d d l m
Z
d d l m Z d d d � Z
d d
d � Z e d k r� e � d S)
a
Script which takes one or more file paths and reports on their detected
encodings
Example::
% chardetect somefile someotherfile
somefile: windows-1252 with confidence 0.5
someotherfile: ascii with confidence 1.0
If no paths are provided, it takes its input from stdin.
� )�absolute_import�print_function�unicode_literalsN)�__version__)�PY2)�UniversalDetector�stdinc C s� t � } x1 | D]) } t | � } | j | � | j r Pq W| j � | j } t rn | j t j � d � } | d r� d j
| | d | d � Sd j
| � Sd S)z�
Return a string describing the probable encoding of a file or
list of strings.
:param lines: The lines to get the encoding of.
:type lines: Iterable of bytes
:param name: Name of file or collection of lines
:type name: str
�ignore�encodingz{0}: {1} with confidence {2}Z
confidencez{0}: no resultN)r � bytearrayZfeed�done�close�resultr �decode�sys�getfilesystemencoding�format)�lines�name�u�liner � r �/chardetect.py�description_of s
r c
C s� t j d d � } | j d d d d t j d � d d d
t rH t j n t j j g �| j d d d
d
d j t � �| j
| � } xR | j D]G } | j � r� t
d d d d d t j �t
t | | j � � q� Wd S)z�
Handles command line arguments and gets things started.
:param argv: List of arguments, as if specified on the command-line.
If None, ``sys.argv[1:]`` is used instead.
:type argv: list of str
�descriptionzVTakes one or more file paths and reports their detected encodings�input�helpz^File whose encoding we would like to determine. (default: stdin)�type�rb�nargs�*�defaultz --version�action�versionz%(prog)s {0}z0You are running chardetect interactively. Press z8CTRL-D twice at the start of a blank line to signal the z4end of your input. If you want help, run chardetect z--help
�fileN)�argparse�ArgumentParser�add_argumentZFileTyper r r �bufferr r �
parse_argsr �isatty�print�stderrr r )�argv�parser�args�fr r r �main6 s r1 �__main__)�__doc__Z
__future__r r r r% r Zchardetr Zchardet.compatr Zchardet.universaldetectorr r r1 �__name__r r r r �<module> s