9
9
import sys
10
10
import hashlib
11
11
12
+
12
13
def file_hash (filename ):
13
14
""" Get byte contents of file `filename`, return SHA1 hash
14
15
@@ -24,9 +25,15 @@ def file_hash(filename):
24
25
"""
25
26
# Open the file, read contents as bytes.
26
27
# Calculate, return SHA1 has on the bytes from the file.
28
+ # LAB(begin solution)
27
29
with open (filename , 'rb' ) as fobj :
28
30
contents = fobj .read ()
29
31
return hashlib .sha1 (contents ).hexdigest ()
32
+ # LAB(replace solution)
33
+ # This is a placeholder, replace it to write your solution.
34
+ raise NotImplementedError (
35
+ 'This is just a template -- you are expected to code this.' )
36
+ # LAB(end solution)
30
37
31
38
32
39
def validate_data (data_directory ):
@@ -48,6 +55,11 @@ def validate_data(data_directory):
48
55
``data_hashes.txt`` file.
49
56
"""
50
57
# Read lines from ``data_hashes.txt`` file.
58
+ # Split into SHA1 hash and filename
59
+ # Calculate actual hash for given filename.
60
+ # If hash for filename is not the same as the one in the file, raise
61
+ # ValueError
62
+ # LAB(begin solution)
51
63
for line in open (op .join (data_directory , 'data_hashes.txt' ), 'rt' ):
52
64
# Split into SHA1 hash and filename
53
65
hash , filename = line .strip ().split ()
@@ -57,6 +69,10 @@ def validate_data(data_directory):
57
69
# ValueError
58
70
if hash != actual_hash :
59
71
raise ValueError ("Hash for {} does not match" .format (filename ))
72
+ # LAB(replace solution)
73
+ # This is a placeholder, replace it to write your solution.
74
+ raise NotImplementedError ('This is just a template -- you are expected to code this.' )
75
+ # LAB(end solution)
60
76
61
77
62
78
def main ():
0 commit comments