Commit f64509e3 authored by Andrew M. Kuchling's avatar Andrew M. Kuchling

Move all the imports to the top; use md5.new()

parent 30dd9bc0
import string import string
import md5
from sys import argv
def MDPrint(str): def MDPrint(str):
outstr = '' outstr = ''
...@@ -20,8 +22,6 @@ def makestr(start, end): ...@@ -20,8 +22,6 @@ def makestr(start, end):
return result return result
from md5 import md5
def MDTimeTrial(): def MDTimeTrial():
TEST_BLOCK_SIZE = 1000 TEST_BLOCK_SIZE = 1000
TEST_BLOCKS = 10000 TEST_BLOCKS = 10000
...@@ -42,7 +42,7 @@ def MDTimeTrial(): ...@@ -42,7 +42,7 @@ def MDTimeTrial():
print 'MD5 time trial. Processing', TEST_BYTES, 'characters...' print 'MD5 time trial. Processing', TEST_BYTES, 'characters...'
t1 = time() t1 = time()
mdContext = md5() mdContext = md5.new()
for i in range(TEST_BLOCKS): for i in range(TEST_BLOCKS):
mdContext.update(data) mdContext.update(data)
...@@ -57,13 +57,13 @@ def MDTimeTrial(): ...@@ -57,13 +57,13 @@ def MDTimeTrial():
def MDString(str): def MDString(str):
MDPrint(md5(str).digest()) MDPrint(md5.new(str).digest())
print '"' + str + '"' print '"' + str + '"'
def MDFile(filename): def MDFile(filename):
f = open(filename, 'rb'); f = open(filename, 'rb');
mdContext = md5() mdContext = md5.new()
while 1: while 1:
data = f.read(1024) data = f.read(1024)
...@@ -78,7 +78,7 @@ def MDFile(filename): ...@@ -78,7 +78,7 @@ def MDFile(filename):
import sys import sys
def MDFilter(): def MDFilter():
mdContext = md5() mdContext = md5.new()
while 1: while 1:
data = sys.stdin.read(16) data = sys.stdin.read(16)
...@@ -106,8 +106,6 @@ def MDTestSuite(): ...@@ -106,8 +106,6 @@ def MDTestSuite():
MDFile('foo') MDFile('foo')
from sys import argv
# I don't wanna use getopt(), since I want to use the same i/f... # I don't wanna use getopt(), since I want to use the same i/f...
def main(): def main():
if len(argv) == 1: if len(argv) == 1:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment