Skip to content

Commit f880919

Browse files
committed
fixed error handling for _read_vid_file().
1 parent 16f0443 commit f880919

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

generate_mac/__init__.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def _read_vid_file(vid_file):
3232
file_lines = in_file.readlines()
3333
in_file.close()
3434
except FileNotFoundError:
35-
raise FileNotFoundError("ERROR: Cannot read VID file " + in_file)
35+
raise FileNotFoundError("Cannot read VID file " + vid_file)
3636

3737
# Sanitize inputs
3838
file_lines = generate_mac._strip_comments(file_lines)
@@ -195,20 +195,23 @@ def vid_file_vendor(vid_file,vendor,desc=None):
195195
def vid_provided(vid_bytes):
196196
'''Generates only the Device bytes, given specified VID bytes'''
197197
test_vid = []
198-
i = ""
199198
rand_bytes = ""
200199
output = ""
201200
## Start with error checking
202201
#remove any trailing :
203-
vid_bytes = vid_bytes.rstrip(":")
204-
test_vid = vid_bytes.split(":")
202+
try:
203+
vid_bytes = vid_bytes.rstrip(":")
204+
test_vid = vid_bytes.split(":")
205+
except:
206+
raise ValueError(str(vid_bytes) + ' are not valid VID bytes')
205207
# If there aren't precisely three bytes, its not a VID
206208
if len(test_vid) != 3:
207209
raise ValueError(vid_bytes + ' are not valid VID bytes')
208-
for i in test_vid:
209-
if generate_mac._is_byte(i) == False:
210-
raise ValueError(vid_bytes + ' are not valid VID bytes')
211-
210+
for byte in test_vid:
211+
if generate_mac._is_byte(byte) == False:
212+
raise ValueError(str(vid_bytes) + ' are not valid VID bytes')
213+
214+
# generate some new device bytes
212215
rand_bytes = generate_mac._gen_rand_bytes(3)
213216
output = vid_bytes + ":" + rand_bytes
214217
return output

0 commit comments

Comments
 (0)