Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
fb9653a6
Commit
fb9653a6
authored
May 13, 2003
by
Andrew M. Kuchling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't use 'file' as a variable name
Modernize the code a bit Add docstring
parent
87ddce1b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
24 deletions
+17
-24
Tools/scripts/sum5.py
Tools/scripts/sum5.py
+17
-24
No files found.
Tools/scripts/sum5.py
View file @
fb9653a6
#! /usr/bin/env python
# print md5 checksum for files
"""Python utility to print MD5 checksums of argument files.
"""
bufsize
=
8096
fnfilter
=
None
...
...
@@ -17,22 +19,19 @@ file ... : files to sum; '-' or no files means stdin
import
sys
import
os
import
getopt
import
md5
import
regsub
StringType
=
type
(
''
)
FileType
=
type
(
sys
.
stdin
)
def
sum
(
*
files
):
sts
=
0
if
files
and
type
(
files
[
-
1
])
==
FileType
:
if
files
and
isinstance
(
files
[
-
1
],
file
)
:
out
,
files
=
files
[
-
1
],
files
[:
-
1
]
else
:
out
=
sys
.
stdout
if
len
(
files
)
==
1
and
type
(
files
[
0
])
!=
StringType
:
if
len
(
files
)
==
1
and
not
isinstance
(
files
[
0
],
str
)
:
files
=
files
[
0
]
for
f
in
files
:
if
type
(
f
)
==
StringType
:
if
isinstance
(
f
,
str
)
:
if
f
==
'-'
:
sts
=
printsumfp
(
sys
.
stdin
,
'<stdin>'
,
out
)
or
sts
else
:
...
...
@@ -41,19 +40,19 @@ def sum(*files):
sts
=
sum
(
f
,
out
)
or
sts
return
sts
def
printsum
(
file
,
out
=
sys
.
stdout
):
def
printsum
(
file
name
,
out
=
sys
.
stdout
):
try
:
fp
=
open
(
file
,
rmode
)
fp
=
open
(
file
name
,
rmode
)
except
IOError
,
msg
:
sys
.
stderr
.
write
(
'%s: Can
\
'
t open: %s
\
n
'
%
(
file
,
msg
))
sys
.
stderr
.
write
(
'%s: Can
\
'
t open: %s
\
n
'
%
(
file
name
,
msg
))
return
1
if
fnfilter
:
file
=
fnfilter
(
fil
e
)
sts
=
printsumfp
(
fp
,
file
,
out
)
file
name
=
fnfilter
(
filenam
e
)
sts
=
printsumfp
(
fp
,
file
name
,
out
)
fp
.
close
()
return
sts
def
printsumfp
(
fp
,
file
,
out
=
sys
.
stdout
):
def
printsumfp
(
fp
,
file
name
,
out
=
sys
.
stdout
):
m
=
md5
.
new
()
try
:
while
1
:
...
...
@@ -61,20 +60,13 @@ def printsumfp(fp, file, out = sys.stdout):
if
not
data
:
break
m
.
update
(
data
)
except
IOError
,
msg
:
sys
.
stderr
.
write
(
'%s: I/O error: %s
\
n
'
%
(
file
,
msg
))
sys
.
stderr
.
write
(
'%s: I/O error: %s
\
n
'
%
(
file
name
,
msg
))
return
1
out
.
write
(
'%s %s
\
n
'
%
(
hexify
(
m
.
digest
()),
fil
e
))
out
.
write
(
'%s %s
\
n
'
%
(
m
.
hexdigest
(),
filenam
e
))
return
0
def
hexify
(
s
):
res
=
''
for
c
in
s
:
res
=
res
+
'%02x'
%
ord
(
c
)
return
res
def
main
(
args
=
sys
.
argv
[
1
:],
out
=
sys
.
stdout
):
global
fnfilter
,
rmode
,
bufsize
import
getopt
try
:
opts
,
args
=
getopt
.
getopt
(
args
,
'blts:'
)
except
getopt
.
error
,
msg
:
...
...
@@ -89,7 +81,8 @@ def main(args = sys.argv[1:], out = sys.stdout):
rmode
=
'r'
if
o
==
'-s'
:
bufsize
=
int
(
a
)
if
not
args
:
args
=
[
'-'
]
if
not
args
:
args
=
[
'-'
]
return
sum
(
args
,
out
)
if
__name__
==
'__main__'
or
__name__
==
sys
.
argv
[
0
]:
...
...
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