From 79c89b2a4b2a1cb5e5c3fbcd251e0bbd11d28626 Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Thu, 18 Apr 2019 01:14:08 -0700 Subject: [PATCH] Rename empty-named patterns on gdsii save --- masque/file/gdsii.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/masque/file/gdsii.py b/masque/file/gdsii.py index cb40616..b164561 100644 --- a/masque/file/gdsii.py +++ b/masque/file/gdsii.py @@ -459,17 +459,20 @@ def _disambiguate_pattern_names(patterns): i = 0 suffixed_name = sanitized_name - while suffixed_name in used_names: + while suffixed_name in used_names or suffixed_name == '': suffix = base64.b64encode(struct.pack('>Q', i), b'$?').decode('ASCII') suffixed_name = sanitized_name + '$' + suffix[:-1].lstrip('A') i += 1 - if suffixed_name != sanitized_name: + if sanitized_name == '': + logger.warning('Empty pattern name saved as "{}"'.format(suffixed_name)) + elif suffixed_name != sanitized_name: logger.warning('Pattern name "{}" appears multiple times; renaming to "{}"'.format(pat.name, suffixed_name)) encoded_name = suffixed_name.encode('ASCII') if len(encoded_name) == 0: + # Should never happen since zero-length names are replaced raise PatternError('Zero-length name after sanitize+encode, originally "{}"'.format(pat.name)) if len(encoded_name) > 32: raise PatternError('Pattern name "{}" length > 32 after encode, originally "{}"'.format(encoded_name, pat.name))