From dd63b169f177389602e17bc6ced53bd0f1ba0de3 Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Sat, 10 Oct 2015 16:51:21 -0400 Subject: Allow files to be read from strings per #37 Adds a loads() method to the top level module which generates a GerberFile or ExcellonFile from a string --- gerber/utils.py | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) (limited to 'gerber/utils.py') diff --git a/gerber/utils.py b/gerber/utils.py index df26516..1c0af52 100644 --- a/gerber/utils.py +++ b/gerber/utils.py @@ -201,30 +201,20 @@ def decimal_string(value, precision=6, padding=False): return int(floatstr) -def detect_file_format(filename): +def detect_file_format(data): """ Determine format of a file Parameters ---------- - filename : string - Filename of the file to read. + data : string + string containing file data. Returns ------- format : string - File format. either 'excellon' or 'rs274x' + File format. 'excellon' or 'rs274x' or 'unknown' """ - - # Read the first 20 lines (if possible) - lines = [] - with open(filename, 'r') as f: - try: - for i in range(20): - lines.append(f.readline()) - except StopIteration: - pass - - # Look for + lines = data.split('\n') for line in lines: if 'M48' in line: return 'excellon' -- cgit