def serve_starting_page(s): file = s.path.replace('/start.html?f=', '') # Basic protection against evil fake file locations if ('http://' in file) or ('..' in file) or ('/' in file): s.serve_error_page(403) return file = './uploads/' + file # Todo: error handling here - what if the file isn't found? d = Drawing(filename=file) instructions = d.instructions() s.serve_headers(status=200, content_type='text/html') s.wfile.write(bytes(start_page, encoding='ISO-8859-1')) com = Communicator() for i in instructions: print("Sending instruction to drawbot: " + i) com.sendcommand(i) com.close()