How to use function_re method in autopy

Best Python code snippet using autopy

extract-tpdfs.py

Source:extract-tpdfs.py Github

copy

Full Screen

1#!/usr/bin/env python32#3# todo:4#5import argparse6import re7import string8parser = argparse.ArgumentParser(9formatter_class=argparse.RawTextHelpFormatter,\10description = \11'''Extract relevant functions: TPDFs, anomalous exponents, etc. from12TPDFsAtNNLO.frm and write them down in Mathematica format.'''13)14args = parser.parse_args()15#-------------------------------------------------------------------------------16# Extract specific function from the content17#-------------------------------------------------------------------------------18def extract_function(function,content):19 function_re = re.compile('Global ({0}) = ([^;]*);'.format(re.escape(function)))20 function_search = function_re.search(content)21 all_function = function_re.findall(content)22 if len(all_function) > 1: 23 print("Error, all_function list cannot be longer than 1")24 exit(1)25 return(all_function[0])26#-------------------------------------------------------------------------------27# Replace FORM symbols by Mathematica symbols28#-------------------------------------------------------------------------------29def replacements(content):30 # FORM-style functions into Mathematica-style functions31 output = re.sub(r'([HP]|Zeta|delta)\(([^\)]*)\)',r'\1[\2]',content)32 # splitting functions naming consistent with Mathematica file33 output = re.sub(r'P\[([qg])\,([qg])\,(-*z)\]',r'p\g<1>\g<2>0[\3]',output)34 output = output.replace("delta","DiracDelta")35 output = output.replace("PlPr","plus")36 output = re.sub(r'(plus)\(([^\)]*)\)',r'\1[\2]',output)37 output = output.replace("[1-z]","(1-z)")38 output = output.replace("Ca","CA")39 output = output.replace("Cf","CF")40 output = output.replace("Tf","TF")41 output = output.replace("Nf","nf")42 output = output.replace("Lp","LT")43 return output44#-------------------------------------------------------------------------------45#-------------------------------------------------------------------------------46def remove_white(str):47 res = str 48 for white in string.whitespace:49 res = res.replace(white,"")50 return res51#-------------------------------------------------------------------------------52#-------------------------------------------------------------------------------53def simplify_name(str):54 output = re.sub(r'[\[\]\,\{\}\/\(\)z]',r'',str)55 return output56#-------------------------------------------------------------------------------57#-------------------------------------------------------------------------------58if __name__ == '__main__':59 infile = "TPDFsAtNNLO.frm"60 content = ""61 with open(infile) as fh:62 content = fh.read()63 functions = {"[F,{q},(1)]","[F,{g},(1)]",\64 "[F,{q},(2)]","[F,{g},(2)]",\65 "[I,{g/q},(1),z]","[I,{q/g},(1),z]",\66 "[I,{g/q},(2),z]","[I,{q/g},(2),z]",\67 "[I,{q/q},(1),z]","[I,{q/q},(2),z]",\68 "[I,{g/g},(1),z]","[I,{g/g},(2),z]"\69 }70 #out = "{"71 out = "\n"72 for function in functions:73 res = extract_function(function,content)74 name = simplify_name(res[0])+"GLY"75 res = remove_white(res[1])76 #res = res[1]77 res = replacements(res)78 out += "{0}[z_] := {1};\n\n".format(name, res)79 #out += "{0} -> {1},".format(name, res)80 #out = out.rstrip(",")81 #out += "}"82 with open("../GLYResults.m","w") as fh:...

Full Screen

Full Screen

python.py

Source:python.py Github

copy

Full Screen

1# coding=utf82import vim3import re4import px.whitespaces5import px.buffer6function_re = re.compile('^def ')7method_re = re.compile('^\s+def ')8class_re = re.compile('^class ')9def ensure_newlines(buffer, cursor):10 line_number, _ = cursor11 line = buffer[line_number]12 if function_re.match(line):13 px.whitespaces.ensure_newlines(buffer, (line_number, 0), 2)14 if method_re.match(line):15 px.whitespaces.ensure_newlines(buffer, (line_number, 0), 1)16 if class_re.match(line):17 px.whitespaces.ensure_newlines(buffer, (line_number, 0), 2)18def ensure_newlines_after(buffer, cursor):19 x, line_number = px.buffer.get_next_nonempty_line(buffer, cursor[0])20 if line_number <= 0:21 return22 else:23 ensure_newlines(buffer, (line_number, 0))24def ensure_indent(buffer, cursor, indent):25 if vim.eval('&et') == "1":26 indent_symbol = ' ' * int(vim.eval('&sw'))27 else:28 indent_symbol = '\t'29 buffer[cursor[0]] = indent_symbol * indent...

Full Screen

Full Screen

registers.py

Source:registers.py Github

copy

Full Screen

1import re2import subprocess3import sys4def demangle(mangled):5 cmd = ['echo %s | c++filt' % mangled]6 return subprocess.check_output(cmd, shell=True)7def process_report(fn, filt):8 current_function = ''9 function_re = re.compile(r'Compiling entry function \'(\w+)\'')10 register_re = re.compile(r'Used (\d+) registers')11 f = open(fn, 'r')12 for line in f:13 match = re.search(function_re, line)14 if match:15 current_function = demangle(match.group(1))16 match = re.search(register_re, line)17 if match:18 if re.search(filt, current_function):19 print(current_function + ': ' + match.group(1))20 f.close()21if __name__ == '__main__':22 filt = re.compile(sys.argv[2])23 process_report(sys.argv[1], filt)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autopy automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful