25def pybinding(fortran_in, scope, fortran_out, python_out, libso,
26 tpfileIsNam=False, Findexing=False):
28 :param fortran_in: FORTRAN input file
29 :param scope: scope to deal with
30 :param fortran_out: FORTRAN output file
31 :param python_out: python output file
32 :param libso: path to the shared lib (relative to the python_out file)
33 or list of possible paths
34 :param tpfileIsNam: True if tpfile is a namelist
35 :param Findexing: True to keep the same index order as in the FORTRAN subroutine
38 if isinstance(libso, str):
41 def findcomponents(bound):
43 :param bound: a string representing an array bound
44 :returns: a list of components
45 If bound is '5+(X+3)', result is ['5', 'X', '3']
50 for op
in (
'+',
'-',
'*',
'/',
'(',
')'):
51 elemlist = elemlist.replace(op,
' ')
52 return elemlist.split(
' ')
62 pftin = PYFT(fortran_in)
63 scopeNode = pftin.getScopeNode(scope, excludeContains=
True)
64 kind, name = scope.split(
'/')[-1].split(
':')
66 kind = {
'sub':
'SUBROUTINE',
67 'func':
'FUNCTION'}[kind]
81 docstringIN = [
"Input arguments:"]
82 docstringOUT = [
"Output arguments:"]
83 for N
in scopeNode.findall(
'.//{*}dummy-arg-LT/{*}arg-N/{*}N'):
84 var = scopeNode.varList.findVar(n2name(N), exactScope=
True)
86 raise PybindingError(n2name(N) +
' seems to be undeclared')
87 vartype = var[
't'].replace(
' ',
'').upper()
88 if vartype ==
'TYPE(DIMPHYEX_T)':
89 moduleList.append(
'USE MODD_DIMPHYEX, ONLY: DIMPHYEX_t')
90 declList.append(
'TYPE(DIMPHYEX_t) :: D')
91 for v
in [
'NIT',
'NKT',
'NKL',
'NVEXT']:
92 declList.append(
'INTEGER, INTENT(IN) :: ' + v)
93 argList1.append((v,
'INTEGER',
False,
'IN',
None))
94 docstringIN.append(f
" {v} (IN) to replace the FORTRAN D structure")
95 copyList.append(
'D%NIT=NIT')
96 copyList.append(
'D%NIB=1')
97 copyList.append(
'D%NIE=NIT')
98 copyList.append(
'D%NJT=1')
99 copyList.append(
'D%NJB=1')
100 copyList.append(
'D%NJE=1')
101 copyList.append(
'D%NIJT=NIT')
102 copyList.append(
'D%NIJB=1')
103 copyList.append(
'D%NIJE=NIT')
104 copyList.append(
'D%NKL=NKL')
105 copyList.append(
'D%NKT=NKT')
106 copyList.append(
'D%NKA=MERGE(1, NKT, NKL==1)')
107 copyList.append(
'D%NKU=MERGE(NKT, 1, NKL==1)')
108 copyList.append(
'D%NKB=D%NKA+NKL*NVEXT')
109 copyList.append(
'D%NKE=D%NKU-NKL*NVEXT')
110 copyList.append(
'D%NKTB=1+NVEXT')
111 copyList.append(
'D%NKTE=NKT-NVEXT')
112 copyList.append(
'D%NIBC=1')
113 copyList.append(
'D%NJBC=1')
114 copyList.append(
'D%NIEC=NIT')
115 copyList.append(
'D%NJEC=1')
117 elif vartype ==
'TYPE(PHYEX_AERO_T)':
118 moduleList.append(
'USE MODD_PHYEX_AERO, ONLY: PHYEX_AERO_t')
119 moduleList.append(
'USE MODD_MISC_OFFLINE, ONLY: MISC_OFFLINE_t')
120 declList.append(
'TYPE(PHYEX_AERO_t) :: PHYAERO')
121 declList.append(
'TYPE(MISC_OFFLINE_t), TARGET :: MISC')
122 copyList.append(
'PHYAERO%LSALT = MISC%LSALT')
123 copyList.append(
'PHYAERO%NMODE_SLT = MISC%NMODE_SLT')
124 copyList.append(
'PHYAERO%XINISIG_SLT => MISC%XINISIG_SLT')
125 copyList.append(
'PHYAERO%CRGUNITS = MISC%CRGUNITS')
126 copyList.append(
'PHYAERO%XINIRADIUS_SLT=> MISC%XINIRADIUS_SLT')
127 copyList.append(
'PHYAERO%XDENSITY_SALT = MISC%XDENSITY_SALT')
128 argList2.append(
'PHYAERO')
129 elif vartype
in [
'TYPE(NSV_T)',]:
130 moduleList.append(
'USE MODD_' + vartype[5:-3] +
', ONLY: T' + vartype[5:-3])
131 declList.append(
'INTEGER, INTENT(IN) :: NSV')
132 argList1.append((
'NSV',
'INTEGER',
False,
'IN',
None))
133 docstringIN.append(
" NSV (IN) to replace the FORTRAN TNSV structure")
134 copyList.append(
'TNSV%NSV=NSV')
135 argList2.append(
'T'+vartype[5:-3])
136 elif vartype
in [
'TYPE(CST_T)',
'TYPE(ELEC_PARAM_T)',
'TYPE(ELEC_DESCR_T)',
137 'TYPE(PARAM_LIMA_T)',
'TYPE(PARAM_LIMA_WARM_T)',
'TYPE(PARAM_LIMA_COLD_T)',
138 'TYPE(PARAM_LIMA_MIXED_T)']:
139 moduleList.append(
'USE MODD_' + vartype[5:-3] +
', ONLY: ' + vartype[5:-3])
140 argList2.append(vartype[5:-3])
141 elif vartype ==
'TYPE(ICET_PARAM_T)':
142 moduleList.append(
'USE MODD_ICET_PARAM, ONLY: ICE_T_PARAMETERS')
143 argList2.append(
'ICE_T_PARAMETERS')
144 elif vartype
in [
'TYPE(NEB_T)',
'TYPE(RAIN_ICE_PARAM_T)',
'TYPE(PARAM_ICE_T)',
145 'TYPE(RAIN_ICE_DESCR_T)',
'TYPE(TURB_T)',
'TYPE(PARAM_MFSHALL_T)']:
146 moduleList.append(
'USE MODD_' + vartype[5:-3] +
'_N, ONLY: ' + vartype[5:-3] +
'N')
147 argList2.append(vartype[5:-3] +
'N')
148 elif vartype ==
'TYPE(CSTURB_T)':
149 moduleList.append(
'USE MODD_CTURB, ONLY: CSTURB')
150 argList2.append(vartype[5:-3])
151 elif vartype ==
'TYPE(TBUDGETCONF_T)':
152 moduleList.append(
'USE MODD_BUDGET, ONLY: TBUCONF_ASSOCIATE, TBUCONF')
153 argList2.append(
'TBUCONF')
154 copyList.append(
'CALL TBUCONF_ASSOCIATE')
155 elif vartype ==
'TYPE(TBUDGETDATA_PTR)':
156 moduleList.append(
'USE MODD_BUDGET, ONLY: NBUDGET_RH, TBUDGETDATA_PTR')
157 moduleList.append(
'USE MODE_BUDGET_OFFLINE, ONLY: TBUDGETDATA_OFFLINE')
158 declList.append(
'TYPE(TBUDGETDATA_PTR), DIMENSION(NBUDGET_RH) :: YLBUDGET')
159 declList.append(
'TYPE(TBUDGETDATA_OFFLINE), DIMENSION(NBUDGET_RH), TARGET :: YLOFFBUD')
160 declList.append(
'INTEGER :: JRR')
161 copyList.append(
'DO JRR=1, NBUDGET_RH\n YLBUDGET(JRR)%PTR => YLOFFBUD(JRR)\n YLBUDGET(JRR)%PTR%NBUDGET=JRR\nENDDO')
162 argList2.append(
'YLBUDGET')
163 elif vartype ==
'TYPE(TFILEDATA)':
164 moduleList.append(
'USE MODD_IO, ONLY: TFILEDATA')
165 declList.append(
'TYPE(TFILEDATA) :: TPFILE')
166 declList.append(
'INTEGER, INTENT(IN) :: KUNIT')
167 argList1.append((
'KUNIT',
'INTEGER',
False,
'IN',
None))
168 docstringIN.append(
" KUNIT (IN) to replace the FORTRAN TFILEDATA structure")
169 copyList.append(
'TPFILE%NLU=KUNIT')
170 argList2.append(
'TPFILE')
171 if var[
'n'] ==
'TPFILE' and name ==
"INI_PHYEX":
174 declList.append(f
'CHARACTER(LEN={namfile_len}) :: SLOCAL_NAMFILE')
175 declList.append(
'INTEGER :: ILOOPVAR_NAMFILE')
176 declList.append(f
'CHARACTER, DIMENSION({namfile_len}), INTENT(IN) :: NAMFILE')
177 argList1.append((
'NAMFILE',
'CHARACTER',
False,
'IN', ((
None, str(namfile_len)),)))
178 docstringIN.append(
" NAMFILE (IN) to replace the FORTRAN TFILEDATA structure")
179 copyList.append(f
'DO ILOOPVAR_NAMFILE=1, {namfile_len}\n' + \
180 ' SLOCAL_NAMFILE(ILOOPVAR_NAMFILE:ILOOPVAR_NAMFILE)=' + \
181 'NAMFILE(ILOOPVAR_NAMFILE)\n' + \
183 copyList.append(
'IF (KUNIT/=0) OPEN(KUNIT, FILE=SLOCAL_NAMFILE)')
184 elif vartype ==
'TYPE(TLES_T)':
185 moduleList.append(
'USE MODD_LES, ONLY: TLES_t')
186 declList.append(
'TYPE(TLES_t) :: TLES')
187 copyList.append(
'TLES%LLES=.FALSE.')
188 copyList.append(
'TLES%LLES_CALL=.FALSE.')
189 argList2.append(
'TLES')
190 elif vartype ==
'TYPE(PHYEX_T)':
192 elif vartype.startswith(
'TYPE('):
193 raise NotImplementedError(
'Does not know how to deal with ' +
194 f
'argument of type {vartype} ' +
196 elif var[
'n'] ==
'KSPLITR':
197 moduleList.append(
'USE MODD_CLOUDPAR_n, ONLY: KSPLITR => NSPLITR')
198 argList2.append(
'KSPLITR')
199 elif vartype.startswith(
'CHARACTER(LEN=')
and vartype[14:].split(
')')[0] !=
'1':
200 charlen = int(vartype[14:].split(
')')[0])
205 replvar[
'as'] = [(
None, str(charlen))] + var[
'as']
206 replvar[
't'] =
'CHARACTER(KIND=C_CHAR)'
207 argList1.append((replvar[
'n'], replvar[
't'],
208 replvar[
'opt'], replvar[
'i'].upper(), replvar[
'as']))
209 docstr =
', OPTIONAL' if replvar[
'opt']
else ''
210 docstr = f
" {var['n']} ({var['i']}{docstr})"
211 if replvar[
'i']
in (
'IN',
'INOUT'):
212 docstringIN.append(docstr)
213 if replvar[
'i']
in (
'OUT',
'INOUT'):
214 docstringOUT.append(docstr)
215 declList.append(pftin.varSpec2stmt(replvar))
218 localvar = var.copy()
219 localvar[
'n'] =
'SLOCAL_' + var[
'n']
221 localvar[
'arg'] =
False
222 declList.append(pftin.varSpec2stmt(localvar))
223 argList2.append(localvar[
'n'])
226 if len(var[
'as']) == 0:
227 declList.append(f
"INTEGER :: ILOOPVAR_{var['n']}")
228 arrayElem =
'{name}(ILOOPVAR_{name})'.format(name=var[
'n'])
229 strElem =
'SLOCAL_{name}(ILOOPVAR_{name}:ILOOPVAR_{name})'.format(name=var[
'n'])
230 loopBegin =
'DO ILOOPVAR_{name}=1, {len}\n'.format(name=var[
'n'], len=str(charlen))
233 loopVars = [f
"ILOOPVAR_{var['n']}_{i}" for i
in range(len(var[
'as']) + 1)]
234 declList.append(
'INTEGER :: ' +
', '.join(loopVars))
236 for d
in range(len(var[
'as'])):
237 loopBegin += (
"DO ILOOPVAR_{varname}_{i}=LBOUND(SLOCAL_{varname}, {i}), " + \
238 "UBOUND(SLOCAL_{varname}, {i})\n"
239 ).format(varname=var[
'n'], i=str(d + 1))
240 loopBegin +=
'DO ILOOPVAR_{name}_0=1, {len}\n'.format(name=var[
'n'], len=str(charlen))
241 arrayElem =
'{name}(ILOOPVAR_{name}_0, {loopv})'.format(
242 name=var[
'n'], loopv=
', '.join(loopVars[1:]))
243 strElem =
'SLOCAL_{name}({loopv})(ILOOPVAR_{name}_0:ILOOPVAR_{name}_0)'.format(
244 name=var[
'n'], loopv=
', '.join(loopVars[1:]))
245 loopEnd =
'ENDDO\n' * len(loopVars)
246 if replvar[
'i']
in (
'IN',
'INOUT'):
247 copyList.append(loopBegin + f
' {strElem}={arrayElem}\n' + loopEnd)
248 if replvar[
'i']
in (
'OUT',
'INOUT'):
250 raise NotImplementedError(
'Optional character strings in OUT/INOUT')
251 copyBackList.append(loopBegin + f
' {arrayElem}={strElem}\n' + loopEnd)
253 if var[
'n'] ==
'KLUOUT' and name ==
"INI_PHYEX":
254 flush.append(
'KLUOUT')
256 localvar = var.copy()
257 if vartype.startswith(
'LOGICAL'):
258 replvar[
't'] =
'LOGICAL(KIND=C_BOOL)'
259 localvar[
'n'] =
'SLOCAL_' + var[
'n']
261 localvar[
'arg'] =
False
262 localvar[
'opt'] =
False
266 copyList.append(
'SLOCAL_{varname}={varname}'.format(varname=var[
'n']))
267 argList1.append((replvar[
'n'], replvar[
't'].replace(
' ',
'').upper(),
268 replvar[
'opt'], replvar[
'i'].upper(), replvar[
'as']))
269 docstr =
', OPTIONAL' if replvar[
'opt']
else ''
270 docstr = f
" {var['n']} ({var['i']}{docstr})"
271 if replvar[
'i']
in (
'IN',
'INOUT'):
272 docstringIN.append(docstr)
273 if replvar[
'i']
in (
'OUT',
'INOUT'):
274 docstringOUT.append(docstr)
275 argList2.append(localvar[
'n'])
276 for d
in replvar[
'as']:
277 if 'NIT' in d[1]
or 'NIJT' in d[1]:
287 elif 'KGRADIENTSGOG' in d[1]:
288 d[1] =
'KGRADIENTSGOG'
289 elif 'KGRADIENTSLEO' in d[1]:
290 d[1] =
'KGRADIENTSLEO'
293 declList.append(pftin.varSpec2stmt(replvar))
294 if vartype.startswith(
'LOGICAL'):
295 declList.append(pftin.varSpec2stmt(localvar))
296 if 'JPSVMAX' not in extra
and \
297 'JPSVMAX' in [elem
for d
in var[
'as']
for di
in d
for elem
in findcomponents(di)]:
298 extra.append(
'JPSVMAX')
299 moduleList.append(
'USE MODD_PARAMETERS, ONLY: JPSVMAX')
300 moduleListHelper.append(
'USE MODD_PARAMETERS, ONLY: JPSVMAX')
306 for vv, mod
in ((
'NSP',
'MODD_CH_AEROSOL'), (
'NCARB',
'MODD_CH_AEROSOL'),
307 (
'NSOA',
'MODD_CH_AEROSOL'), (
'NTURB_S',
'MODD_TURB_n')):
308 if vv
not in extra
and \
309 vv
in [elem
for d
in var[
'as']
for di
in d
for elem
in findcomponents(di)]:
311 moduleList.append(f
'USE {mod}, ONLY: {vv}')
312 moduleListHelper.append(f
'USE {mod}, ONLY: {vv}')
317 exists = os.path.exists(fortran_out)
318 with open(fortran_out,
'a', encoding=
"utf-8")
as f:
323 argList1name = [v[0]
for v
in argList1]
324 f.write((
'{kind} PY{name}({argList}) ' + \
325 'BIND(C, name="PY{name}")\n').format(kind=kind,
326 argList=
', &\n '.join(argList1name),
328 if scope.split(
'/')[0].split(
':')[0] ==
'module':
329 f.write(f
"\nUSE {scope.split('/')[0].split(':')[1]}\n")
331 f.write(f
'\nUSE MODI_{name}\n')
332 f.write(
'\n'.join(moduleList) +
'\n')
333 f.write(
'\nUSE, INTRINSIC :: ISO_C_BINDING, ONLY: C_CHAR, C_BOOL\n')
334 f.write(
'\nIMPLICIT NONE\n')
335 f.write(
'\n'.join(declList) +
'\n')
336 f.write(
'\n'.join(copyList) +
'\n')
337 f.write(f
"CALL {name}(" +
', &\n '.join(argList2) +
")\n")
338 if len(copyBackList) > 0:
339 f.write(
'\n'.join(copyBackList) +
'\n')
341 f.write(f
"FLUSH({unit})\n")
342 f.write(f
'END {kind} PY{name}')
346 extraname = [
'K_' + e
for e
in extra]
347 f.write((
'{kind} HPY{name}({argList}) ' + \
348 'BIND(C, name="HPY{name}")\n').format(kind=kind,
349 argList=
', &\n '.join(argList1name + extraname),
351 f.write(
'\n'.join(moduleListHelper) +
'\n')
352 f.write(
'\nUSE, INTRINSIC :: ISO_C_BINDING, ONLY: C_CHAR, C_BOOL\n')
353 f.write(
'INTEGER(KIND=4), INTENT(OUT) :: ' + (
', &\n '.join(argList1name + extraname)) +
'\n')
354 for varname, vartype, _, _, _
in argList1:
355 f.write(vartype +
' :: ' +
'K_' + varname +
'\n')
356 for varname, vartype, _, _, _
in argList1:
357 if vartype.startswith(
'CHARACTER'):
358 f.write(f
'{varname}=0\n')
360 f.write(
'{varname}=KIND(K_{varname})\n'.format(varname=varname))
361 for varname
in extra:
362 f.write(f
'K_{varname}={varname}\n')
363 f.write(f
'END {kind} HPY{name}')
366 exists = os.path.exists(python_out)
367 with open(python_out,
'a', encoding=
"utf-8")
as f:
369 f.write(
'#!/usr/bin/env python3\n')
370 f.write(
'import numpy\n')
371 f.write(
'import ctypesForFortran\n')
372 f.write(
'from ctypesForFortran import string2array, array2string\n')
373 f.write(
'import sys\n')
374 f.write(
'import os\n')
375 f.write(
'from functools import lru_cache\n')
377 f.write(
'IN = ctypesForFortran.IN\n')
378 f.write(
'OUT = ctypesForFortran.OUT\n')
379 f.write(
'INOUT = ctypesForFortran.INOUT\n')
380 f.write(
'MISSING = ctypesForFortran.MISSING\n')
381 f.write(
'MAO = ctypesForFortran.MANDATORY_AFTER_OPTIONAL\n')
383 f.write(
'ctypesFF = None\n')
386 f.write(
'_dirname = os.path.dirname(os.path.realpath(__file__))\n')
387 for libsoname
in libso:
388 f.write(f
'_libso = os.path.join(_dirname, {libsoname!r})\n')
389 f.write(
'if ctypesFF is None and os.path.exists(_libso):\n')
390 f.write(
' ctypesFF, handle = ctypesForFortran.ctypesForFortranFactory(_libso)\n')
391 f.write(
'if ctypesFF is None:\n')
392 f.write(f
' raise IOError("Shared lib is missing (tested path are: {", ".join(libso)}).")\n')
394 f.write(
'def close():\n')
395 f.write(
' ctypesForFortran.dlclose(handle)\n')
396 f.write(
'\n@lru_cache\n')
397 f.write(
"@ctypesFF(prefix='', suffix='')\n")
398 f.write(f
"def HPY{name}():\n")
399 f.write(f
" return ([], [(numpy.int32, None, OUT)] * {len(argList1 + extra)}, None)\n")
407 for _, vartype, opt, intent, _
in argList1:
408 if intent
in (
'OUT',
'INOUT'):
409 if vartype.startswith(
'CHARACTER'):
412 raise NotImplementedError(
'Character strings in OUT/INOUT after ' + \
413 'an optional OUT/INOUT argument')
414 strOutPos.append(iout)
418 if len(strOutPos) > 0:
419 f.write(f
"@array2string({strOutPos})\n")
420 f.write(
"@ctypesFF(prefix='', suffix='', castInput=True, " + \
421 f
"indexing='{'F' if Findexing else 'C'}')\n")
424 for varname, _, opt, intent, _
in argList1:
425 if intent
in (
'IN',
'INOUT'):
427 argList.append(varname +
'=MISSING')
430 argList.append(varname +
'=MAO')
432 argList.append(varname)
433 outvar = [varname
for (varname, _, _, intent, _)
in argList1
if intent
in (
'OUT',
'INOUT')]
434 argList.append(
'missingOUT=None')
435 f.write(f
"def PY{name}({', '.join(argList)}):\n")
437 f.write(
" Wrapping to provide a python binding using pybinding " + \
438 "from the PHYEX package.\n")
439 f.write(f
" Original file is {fortran_in}\n\n")
440 f.write(
" Special notes for OPTIONAL variables:\n")
441 f.write(
" - To be absent on input, the variable must receive the MISSING\n")
442 f.write(
" special value.\n")
443 f.write(
" - For a variable with OUT intent, the variable name must be added in the\n")
444 f.write(
" missingOUT list to not be returned by the python function.\n")
445 f.write(
" - For a variable with INOUT intent, its presence or absence is\n")
446 f.write(
" simultaneous at input and output\n\n")
447 f.write(
" " +
"\n ".join(docstringIN) +
"\n")
448 f.write(
" " +
"\n ".join(docstringOUT) +
"\n")
450 f.write(
" missingOUT = [] if missingOUT is None else missingOUT\n")
451 if len(argList1 + extra) == 1:
453 f.write(f
" kinds = (HPY{name}(), )\n")
455 f.write(f
" kinds = HPY{name}()\n")
457 f.write(f
" {', '.join(['_' + e for e in extra])}, = kinds[{len(argList1)}:]\n")
460 for ivar, (varname, vartype, opt, intent, dim)
in enumerate(argList1):
461 if vartype.startswith(
'INTEGER'):
462 npkind = {4:
'numpy.int32', 8:
'numpy.int64'}
463 elif vartype.startswith(
'REAL'):
464 npkind = {4:
'numpy.float32', 8:
'numpy.float64'}
465 elif vartype.startswith(
'LOGICAL(KIND=C_BOOL)'):
467 elif vartype.startswith(
'CHARACTER'):
470 raise NotImplementedError(
'Argument type not yet implemented: ' + vartype)
471 if intent
in (
'IN',
'INOUT'):
472 if vartype.startswith(
'CHARACTER'):
473 inlist.append(f
'string2array({varname}, {dim[0][1]}), #{varname}')
475 inlist.append(f
'{varname}, #{varname}')
477 if not (dim
is None or len(dim) == 0):
480 raise NotImplementedError(
'Array with non-zero indexing not implemented')
482 for elem
in findcomponents(d[1]):
483 if elem
in (
'NIT',
'NIJT'):
484 strdimpart = re.sub(rf
'\b{elem}\b',
'NIT', strdimpart)
486 strdimpart = re.sub(rf
'\b{elem}\b',
'1', strdimpart)
489 elif elem
in argList1name:
491 elif elem
in (
'JPSVMAX',
'NSV',
'NSP',
'NCARB',
'NSOA',
'NTURB_S',
492 'KGRADIENTSLEO',
'KGRADIENTSGOG',
'KSOA'):
493 strdimpart = re.sub(rf
'\b{elem}\b', f
'_{elem}', strdimpart)
497 except ValueError
as verr:
498 raise NotImplementedError(f
'Dimension not implemeneted ({elem}) ' + \
499 f
'for variable {varname}')
from verr
500 strdim.append(strdimpart)
505 strdim =
'(' +
', '.join(strdim) +
',)'
507 if vartype.startswith(
'CHARACTER'):
508 strdim =
'(' +
', '.join([
'1'] + strdim[1:][::-1] + [strdim[0]]) +
',)'
510 strdim =
'(' +
', '.join(strdim[::-1]) +
',)'
511 kind = repr(npkind).replace(
"'",
"") + f
'[kinds[{ivar}]]'
512 if opt
and intent ==
'OUT':
513 kind = f
'MISSING if "{varname.upper()}" in missingOUT else {kind}'
514 alllist.append(f
'({kind}, {strdim}, {intent}), #{varname}')
515 f.write((
" return ([{inlist}\n" + \
519 " None)\n").format(inlist=
'\n '.join(inlist),
520 alllist=
'\n '.join(alllist)))