Beispiel #1
0
def parse(cheetah_content, encoding=None):

    from Cheetah.Compiler import Compiler
    # This is very screwy, but so is cheetah. Apologies.
    compiler = Compiler()
    compiler._parser = InstrumentedParser(cheetah_content, compiler=compiler)
    compiler.compile()
    data = compiler._parser.data

    if DEBUG:
        data = show_data(data, cheetah_content)
    data = nice_names(data)
    data = remove_empty(data)
    data = dedup(data)

    dictnode = parser_data_to_dictnode(data, cheetah_content)

    from refactorlib.parse import dictnode_to_lxml
    from refactorlib.cheetah.node import node_lookup
    root = dictnode_to_lxml(dictnode, node_lookup, encoding)
    return root
Beispiel #2
0
def parse(cheetah_content, encoding=None):

	from Cheetah.Compiler import Compiler
	# This is very screwy, but so is cheetah. Apologies.
	compiler = Compiler()
	compiler._parser = InstrumentedParser(cheetah_content, compiler=compiler)
	compiler.compile()
	data = compiler._parser.data

	if DEBUG:
		data = show_data(data, cheetah_content)
	data = nice_names(data)
	data = remove_empty(data)
	data = dedup(data)

	dictnode = parser_data_to_dictnode(data, cheetah_content)

	from refactorlib.parse import dictnode_to_lxml
	from refactorlib.cheetah.node import node_lookup
	root = dictnode_to_lxml(dictnode, node_lookup, encoding)
	return root
Beispiel #3
0
def compileTemplate(tpl, cplFileName, moduleName):
    """Compile one user template to python bytecode
		Input: (string) template file name;
			(string) compiled (target) file name
		Output: none
	"""
    if not hasTemplating:
        return

    debug("Compiling template %s to file: %s" % (moduleName, cplFileName))
    try:
        debug('  Generating code')
        cpl = Compiler(source=tpl, moduleName=moduleName)
        cpl.compile()
    except:
        printException()
        error('Error compiling template: %s' % moduleName)
        return
    # write compiled template to file
    try:
        debug('  Writing to file')
        fh = open(cplFileName, 'w')
        fh.write(str(cpl))
        fh.close()
    except:
        printException()
        error('Can not write compiled template to file: %s' % cplFileName)
        return
    # compile generated template to python bytecode
    try:
        debug('  Compiling to Python bytecode')
        compiler.compileFile(cplFileName)
    except:
        printException()
        error(
            'Can not compile generated template to python bytecode. File: %s' %
            cplFileName)
        return
Beispiel #4
0
def compileTemplate(tpl, cplFileName, moduleName):
	"""Compile one user template to python bytecode
		Input: (string) template file name;
			(string) compiled (target) file name
		Output: none
	"""
	if not hasTemplating:
		return
	
	debug ("Compiling template %s to file: %s" % (moduleName, cplFileName))
	try:
		debug ('  Generating code')
		cpl = Compiler(source = tpl, moduleName = moduleName)
		cpl.compile()
	except:
		printException()
		error('Error compiling template: %s' % moduleName)
		return
	# write compiled template to file
	try:
		debug ('  Writing to file')
		fh = open(cplFileName, 'w')
		fh.write(str(cpl))
		fh.close()
	except:
		printException()
		error('Can not write compiled template to file: %s' % cplFileName)
		return
	# compile generated template to python bytecode
	try:
		debug ('  Compiling to Python bytecode')
		compiler.compileFile(cplFileName)
	except:
		printException()
		error('Can not compile generated template to python bytecode. File: %s' % cplFileName)
		return