Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __setitem__(self, key, value):
super(NmlDict, self).__setitem__(key.lower(), value)
tokens = iter(f90)
# Store groups in case-insensitive dictionary
nmls = NmlDict()
for t in tokens:
# Ignore tokens outside of namelist groups
while t != '&':
t = tokens.next()
# Read group name following '&'
t = tokens.next()
g_name = t
g_vars = NmlDict()
v_name = None
v_vals = []
while t != '/':
prior_t = t
t = tokens.next()
if v_name and not t == '=':
# Test if varname contains a vector index
# TODO: Do I need regex?
match = re.search(r'\(\d+\)$', v_name)
if match:
v_index = int(v_name[match.start()+1:-1])
v_name = v_name[:match.start()]
def parse(nml_fname):
f = open(nml_fname, 'r')
f90 = shlex.shlex(f)
f90.commenters = '!'
f90.wordchars += '.-()' # Numerical characters
tokens = iter(f90)
# Store groups in case-insensitive dictionary
nmls = NmlDict()
for t in tokens:
# Ignore tokens outside of namelist groups
while t != '&':
t = tokens.next()
# Read group name following '&'
t = tokens.next()
g_name = t
g_vars = NmlDict()
v_name = None
v_vals = []
while t != '/':