Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
news
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Sartika Aritonang
news
Commits
f5fa518f
Commit
f5fa518f
authored
May 29, 2020
by
Sartika Aritonang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
3cf676ba
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
85 additions
and
0 deletions
+85
-0
chardetect.py
stbi/Lib/site-packages/pip/_vendor/chardet/cli/chardetect.py
+85
-0
No files found.
stbi/Lib/site-packages/pip/_vendor/chardet/cli/chardetect.py
0 → 100644
View file @
f5fa518f
#!/usr/bin/env python
"""
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.
"""
from
__future__
import
absolute_import
,
print_function
,
unicode_literals
import
argparse
import
sys
from
pip._vendor.chardet
import
__version__
from
pip._vendor.chardet.compat
import
PY2
from
pip._vendor.chardet.universaldetector
import
UniversalDetector
def
description_of
(
lines
,
name
=
'stdin'
):
"""
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
"""
u
=
UniversalDetector
()
for
line
in
lines
:
line
=
bytearray
(
line
)
u
.
feed
(
line
)
# shortcut out of the loop to save reading further - particularly useful if we read a BOM.
if
u
.
done
:
break
u
.
close
()
result
=
u
.
result
if
PY2
:
name
=
name
.
decode
(
sys
.
getfilesystemencoding
(),
'ignore'
)
if
result
[
'encoding'
]:
return
'{0}: {1} with confidence {2}'
.
format
(
name
,
result
[
'encoding'
],
result
[
'confidence'
])
else
:
return
'{0}: no result'
.
format
(
name
)
def
main
(
argv
=
None
):
"""
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
"""
# Get command line arguments
parser
=
argparse
.
ArgumentParser
(
description
=
"Takes one or more file paths and reports their detected
\
encodings"
)
parser
.
add_argument
(
'input'
,
help
=
'File whose encoding we would like to determine.
\
(default: stdin)'
,
type
=
argparse
.
FileType
(
'rb'
),
nargs
=
'*'
,
default
=
[
sys
.
stdin
if
PY2
else
sys
.
stdin
.
buffer
])
parser
.
add_argument
(
'--version'
,
action
=
'version'
,
version
=
'
%(prog)
s {0}'
.
format
(
__version__
))
args
=
parser
.
parse_args
(
argv
)
for
f
in
args
.
input
:
if
f
.
isatty
():
print
(
"You are running chardetect interactively. Press "
+
"CTRL-D twice at the start of a blank line to signal the "
+
"end of your input. If you want help, run chardetect "
+
"--help
\n
"
,
file
=
sys
.
stderr
)
print
(
description_of
(
f
,
f
.
name
))
if
__name__
==
'__main__'
:
main
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment