""" Qpy example module. """ # f, an html template def f [html] (x): "
" x "
" # f_equivalent, a function with the same behavior as f from qpy import h8 as qpy_h8 def f_equivalent(x): qpy_accumulation = [] qpy_append = qpy_accumulation.append qpy_append(qpy_h8("
")) qpy_append(x) qpy_append(qpy_h8("
")) return qpy_h8.from_list(qpy_accumulation) import dis print "Here is the byte-code for the template f:" dis.disassemble(f.func_code) print print "Here is the byte-code for the function f_equivalent:" dis.disassemble(f_equivalent.func_code) print for x in (None, 1, 'ok', '
', str): print "f(%r) -> %r" % (x, f(x)) assert f(x) == f_equivalent(x) assert isinstance(f(x), qpy_h8) print "Success!"