示例#1
0
def parse(python_contents, encoding):
    """Given some python contents as a text string, return the lxml representation.
    """
    lib2to3_python = lib2to3_parse(python_contents)
    dictnode_python = lib2to3_to_dictnode(lib2to3_python)

    from refactorlib.parse import dictnode_to_lxml
    return dictnode_to_lxml(dictnode_python, encoding=encoding)
示例#2
0
def parse(python_contents, encoding):
    """Given some python contents as a text string, return the lxml representation.
    """
    lib2to3_python = lib2to3_parse(python_contents)
    dictnode_python = lib2to3_to_dictnode(lib2to3_python)

    from refactorlib.parse import dictnode_to_lxml
    return dictnode_to_lxml(dictnode_python, encoding=encoding)
示例#3
0
def parse(javascript_contents, encoding='ascii'):
    """
	Given some javascript contents, as a unicode string, return the lxml representation.
	"""
    smjs_javascript = smjs_parse(javascript_contents)
    dictnode_javascript = smjs_to_dictnode(javascript_contents,
                                           smjs_javascript)
    dictnode_javascript = fixup_hierarchy(dictnode_javascript)
    dictnode_javascript = calculate_text(javascript_contents,
                                         dictnode_javascript)

    from refactorlib.parse import dictnode_to_lxml
    return dictnode_to_lxml(dictnode_javascript, encoding=encoding)
示例#4
0
def parse(javascript_contents, encoding='ascii'):
    """Given some javascript contents, as a text string, return the lxml representation.
    "reflectjs" below refers to the Mozilla Reflect protocol:
        * https://developer.mozilla.org/en-US/docs/SpiderMonkey/Parser_API
        * https://npmjs.org/package/reflect
    """
    from refactorlib.dictnode import set_tree_text
    reflectjs_javascript = reflectjs_parse(javascript_contents)
    dictnode_javascript = reflectjs_to_dictnode(reflectjs_javascript)
    dictnode_javascript = set_tree_text(dictnode_javascript, javascript_contents)

    from refactorlib.parse import dictnode_to_lxml
    return dictnode_to_lxml(dictnode_javascript, encoding=encoding)
示例#5
0
def parse(javascript_contents, encoding='ascii'):
    """Given some javascript contents, as a text string, return the lxml representation.
    "reflectjs" below refers to the Mozilla Reflect protocol:
        * https://developer.mozilla.org/en-US/docs/SpiderMonkey/Parser_API
        * https://npmjs.org/package/reflect
    """
    from refactorlib.dictnode import set_tree_text
    reflectjs_javascript = reflectjs_parse(javascript_contents)
    dictnode_javascript = reflectjs_to_dictnode(reflectjs_javascript)
    dictnode_javascript = set_tree_text(dictnode_javascript, javascript_contents)

    from refactorlib.parse import dictnode_to_lxml
    return dictnode_to_lxml(dictnode_javascript, encoding=encoding)
示例#6
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
示例#7
0
def parse(cheetah_content, encoding=None):
    # yelp_cheetah requires text
    if type(cheetah_content) is bytes:
        cheetah_content = cheetah_content.decode('UTF-8')

    compiler = InstrumentedCompiler(cheetah_content)
    compiler.getModuleCode()
    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
示例#8
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
示例#9
0
def parse(cheetah_content, encoding=None):
    # yelp_cheetah requires text
    if type(cheetah_content) is bytes:
        cheetah_content = cheetah_content.decode('UTF-8')

    compiler = InstrumentedCompiler(cheetah_content)
    compiler.getModuleCode()
    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