Python y el lenguaje de formateo Isis

¿Cómo podríamos reemplazar el lenguaje de formateo con Python? ¿Podemos hacer un mapeo pft ⇒ py que nos ayude a ver qué cosas del lenguaje de formateo nos gustaría tener en Python?

Podemos pensar en equivalentes en Python puro, y en algunos casos, equivalentes en el contexto de un lenguaje de templates, e.g. Django.

Otra opción, implementada por Horacio Degiorgi para PHP, es permitir el uso de formatos Isis, usando un parser de pft escrito en Python. Para parsers en Python, ver p.ej. el libro Text Processing in Python, por David Mertz (Addison Wesley, 2003). Versión online: http://gnosis.cx/TPiP/

Algunos ejemplos de pft mapeado a Python:

(v700/)
    for f in rec.get('700'):
        print f

v260^a
    print rec.get('260').get('a')

v500+|; |
    print '; '.join(rec.get('500'))

if p(v100) then 'Author: ', v100, fi
    if rec.get('100'):
        print 'Author: ' + rec.get('100')

if v260^c : '2001' then '*' fi
    if '2001' in rec.get('260').get('c'):
        print '*'

Ver: descripción formal del lenguaje de formateo de cds/isis (Backus-Naur).

Este es un listado alfabético, tomado de http://bvsmodelo.bvsalud.org/download/cisis/CISIS-LinguagemFormato4-en.pdf.

#
%
"string"
'string'
|string|
(format)
/
/*string*/
@

a()

break

c
cat()
continue

d
date, date()

f()

getenv()

if ... then ... else ... fi
iocc

l()
left()
lw()

mXY (mode)
mfn, mfn()
mid()
mstname

n
newline()
nocc()
npost()

p()
proc()
putenv()

rav()
ref()
replace()
right()
rmax()
rmin()
rsum()

s()
select ... case ... elsecase ... endsel
size()
system()

type()

v
val()

x

python isis