本文整理汇总了Python中Kernel.Utils.extract_code方法的典型用法代码示例。如果您正苦于以下问题:Python Utils.extract_code方法的具体用法?Python Utils.extract_code怎么用?Python Utils.extract_code使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Kernel.Utils
的用法示例。
在下文中一共展示了Utils.extract_code方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: remove_comments_by_hash
# 需要导入模块: from Kernel import Utils [as 别名]
# 或者: from Kernel.Utils import extract_code [as 别名]
def remove_comments_by_hash(obj):
res = []
for i in xrange(len(obj)):
aux = obj[i].strip().lower()
if len(aux)>0:
if aux[0]=="#":
if aux.find("#comments-start")==0 or aux.find("#comments-end")==0 or aux.find("#include")==0 or \
aux.find("#notrayicon")==0 or aux.find("#onautoitstartregister")==0 or aux.find("#pragma")==0 or \
aux.find("#requireadmin")==0 or aux.find("#cs")==0 or aux.find("#ce")==0:
res.append(obj[i])
else: res.append(obj[i])
return res
def remove_region_directive(obj):
for i in xrange(len(obj)):
aux = obj[i].lower().strip()
if aux.find("#region")==0 or aux.find("#endregion")==0: obj[i] = "\n"
return obj
def remove_comments_by_comment_tag(code): return sub(r"#comments-start.*#comments-end[^\n]*","",code,flags=DOTALL)
def remove_comments_by_c_tag(code): return sub(r"#cs.*#ce[^\n]*","",code,flags=DOTALL)
def remove_comments_by_tag(code): return remove_comments_by_c_tag(remove_comments_by_comment_tag(code))
########################################
if __name__ == "__main__":
a = Utils.extract_code("runpe_danyfirex.au3")
a = Utils.get_string_from_code(a)
a = remove_comments(a)
print a
示例2: sub
# 需要导入模块: from Kernel import Utils [as 别名]
# 或者: from Kernel.Utils import extract_code [as 别名]
try:
if identifiers[i]: obj = sub(r"\$"+identifiers[i][1:]+r"\b","$"+replaces[i]+" ",obj)
except: continue
return obj.split(boundary)
def hide_variable_names(obj):
identifiers = list(ex.extract_defined_variables_from_obj(obj)) # Extraer solo las que se definen en el script #
replaces = Utils.mod_names_hash(identifiers)
boundary = "\n"+Utils.generate_random_string(20,30)+"\n"
obj = boundary.join(obj)
for i in xrange(len(identifiers)):
if identifiers[i]: obj = sub(r"\$"+identifiers[i][1:]+r"\b","$"+replaces[i]+" ",obj)
return obj.split(boundary)
def hide_function_names(obj):
identifiers = list(ex.extract_func_names_from_obj(obj))
replaces = Utils.mod_names_identifier(identifiers)
obj = "\n".join(obj)
for i in xrange(len(identifiers)):
if identifiers[i]: obj = sub(r""+identifiers[i]+r"\s*\(",replaces[i]+"(",obj)
return obj.split("\n")
if __name__ == "__main__":
obj = Utils.extract_code("test.au3")
obj = hide_variable_names(obj)
obj = hide_function_names(obj)
Utils.write_code(Utils.get_string_from_obj(obj),"testmod.au3")
#print generate_graph(obj)
示例3: raw_input
# 需要导入模块: from Kernel import Utils [as 别名]
# 或者: from Kernel.Utils import extract_code [as 别名]
if ex.is_do_while(line): flags[1] = 1
if ex.is_while(line): flags[0] = 1
if ex.is_for_to(line): flags[2] = 1
if ex.is_for_in(line): flags[3] = 1
if ex.is_func(line): flags[4] = 1
if ex.is_if(line): flags[5] = 1
if ex.is_select(line): flags[6] = 1
if ex.is_switch(line): flags[7] = 1
if ex.is_with(line): flags[8] = 1
if ex.is_end_while(line): flags[0] = 0
if ex.is_until(line): flags[1] = 0
if ex.is_next(line):
if flags[2]==1: flags[2] = 0 # Si es TO #
else: flags[3] = 0 # Si es IN #
if ex.is_end_func(line): flags[4] = 0
if ex.is_end_if(line): flags[5] = 0
if ex.is_end_select(line): flags[6] = 0
if ex.is_end_switch(line): flags[7] = 0
if ex.is_end_with(line): flags[8] = 0
raw_input()
print flags
if __name__ == "__main__":
obj = Utils.remove_comments(Utils.extract_code("test.au3"))
print generate_graph(obj)