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
51a2776c
Commit
51a2776c
authored
May 29, 2020
by
Sartika Aritonang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
80884f71
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
58 additions
and
0 deletions
+58
-0
hash.py
stbi/Lib/site-packages/pip/_internal/commands/hash.py
+58
-0
No files found.
stbi/Lib/site-packages/pip/_internal/commands/hash.py
0 → 100644
View file @
51a2776c
# The following comment should be removed at some point in the future.
# mypy: disallow-untyped-defs=False
from
__future__
import
absolute_import
import
hashlib
import
logging
import
sys
from
pip._internal.cli.base_command
import
Command
from
pip._internal.cli.status_codes
import
ERROR
from
pip._internal.utils.hashes
import
FAVORITE_HASH
,
STRONG_HASHES
from
pip._internal.utils.misc
import
read_chunks
,
write_output
logger
=
logging
.
getLogger
(
__name__
)
class
HashCommand
(
Command
):
"""
Compute a hash of a local package archive.
These can be used with --hash in a requirements file to do repeatable
installs.
"""
usage
=
'
%
prog [options] <file> ...'
ignore_require_venv
=
True
def
__init__
(
self
,
*
args
,
**
kw
):
super
(
HashCommand
,
self
)
.
__init__
(
*
args
,
**
kw
)
self
.
cmd_opts
.
add_option
(
'-a'
,
'--algorithm'
,
dest
=
'algorithm'
,
choices
=
STRONG_HASHES
,
action
=
'store'
,
default
=
FAVORITE_HASH
,
help
=
'The hash algorithm to use: one of {}'
.
format
(
', '
.
join
(
STRONG_HASHES
)))
self
.
parser
.
insert_option_group
(
0
,
self
.
cmd_opts
)
def
run
(
self
,
options
,
args
):
if
not
args
:
self
.
parser
.
print_usage
(
sys
.
stderr
)
return
ERROR
algorithm
=
options
.
algorithm
for
path
in
args
:
write_output
(
'
%
s:
\n
--hash=
%
s:
%
s'
,
path
,
algorithm
,
_hash_of_file
(
path
,
algorithm
))
def
_hash_of_file
(
path
,
algorithm
):
"""Return the hash digest of a file."""
with
open
(
path
,
'rb'
)
as
archive
:
hash
=
hashlib
.
new
(
algorithm
)
for
chunk
in
read_chunks
(
archive
):
hash
.
update
(
chunk
)
return
hash
.
hexdigest
()
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