def testSimpleCases(self): f = Finder.Finder(['abc', 'aabcd']) self.assertSetEqual(set(['abc']), set(f.find('abc'))) self.assertSetEqual(set(['aabcd']), set(f.find('cbada'))) self.assertListEqual([], f.find('cbade')) f = Finder.Finder(['abc', 'aabcd', 'adcba']) self.assertSetEqual(set(['aabcd', 'adcba']), set(f.find('dbcaa')))
def testWrongInitParams(self): with self.assertRaises(TypeError): Finder.Finder('') with self.assertRaises(TypeError): Finder.Finder([1, '2']) self.assertIsInstance(Finder.Finder([]), Finder.Finder) self.assertIsInstance(Finder.Finder(['1', '2']), Finder.Finder)
def main(): #Abrindo csv e gerando json csv = open('./dados/dados.csv', 'r') json = open('./dados/dados.json', 'w') column = ("nome", "latitude", "longitude", "estado") dados_csv = maincsv.DictReader(csv, column) dados_json = mainjson.dumps([x for x in dados_csv]) json.write(dados_json) dados_json = mainjson.loads(dados_json) csv.close() json.close() #Testando Dijsktra com Digrafo Normal print('Teste Dijkstra') d1 = Digrafo(6) d1.inicializar_matriz(0) d1.inserir_aresta(0, 2, 7) d1.inserir_aresta(0, 4, 4) d1.inserir_aresta(0, 3, 2) d1.inserir_aresta(1, 2, 0) d1.inserir_aresta(2, 4, 1) d1.inserir_aresta(3, 4, 1) d1.inserir_aresta(3, 5, 3) d1.inserir_aresta(4, 1, 4) d1.inserir_aresta(4, 5, 1) d1.inserir_aresta(5, 1, 2) d1.mostrar_matriz() distancia = Finder.dijkstra(d1.matriz_adj, d1.n_vertices, 0) print(distancia) #Calculando distancias entre coordenadas print('\nTeste Distancia entre Coordenadas') print( Finder.distancia(float(dados_json[0]['longitude']), float(dados_json[0]['latitude']), float(dados_json[1]['longitude']), float(dados_json[1]['latitude']))) #Calculando custos e gerando array print('\nTeste Matriz com custos') print(Finder.custo(dados_json)) #Inicio do trabalho implementacional print('\nTeste dijsktra + Coordenadas') entrada = int(input('Raio: ')) d2 = Digrafo(len(dados_json)) d2.inicializar_matriz(0) d2.matriz_adj = d2.matriz_adj + Finder.custo(dados_json) d2.mostrar_matriz() distancia2 = Finder.dijkstra(d2.matriz_adj, d2.n_vertices, 0) print(distancia2)
def main(): usage = 'python %prog [-p <project> -f <file> -l <lines> -e <evaluate> -s <save>]' parser = optparse.OptionParser(usage) parser.add_option('-a', '--all', dest = 'All', type = 'int', default = 0, help = 'input "-a 1" to find all qualified cnnvd and apis') parser.add_option('-p', '--project', dest = 'Project', type = 'string', help = 'Java project directory') parser.add_option('-f', '--file', dest = 'File', type = 'string', help = 'vulnerable file in project') parser.add_option('-l', '--line', dest = 'Line', type = 'int', help = 'vulnerable line') parser.add_option('-e', '--evaluate', dest = 'Evaluate', type = 'int', default = 0, help = 'input "-e 1" to compute projects\' stars and forks, input "-e 2" to compute projects\' vulnerable api num, input "-e 3" to compute both') parser.add_option('-s', '--save', dest = 'Save', type = 'int', default = 0, help = 'input "-s 1" to save into database') options, args=parser.parse_args() if options.All == 1: Finder.start() jar.find_jars() if options.Evaluate == 1: Evaluator.compute_project_star_fork() elif options.Evaluate == 2: Evaluator.compute_vulnerable_api_num() elif options.Evaluate == 3: Evaluator.compute_project_star_fork() Evaluator.compute_vulnerable_api_num() if options.Save == 1: Saver.save_api_into_database() Saver.save_vul_into_database() elif options.Project != None and options.File != None and options.Line != None: udbfile = options.Project + '.udb' os.system('und create -languages Java ' + udbfile) os.system('und add ' + options.Project + ' ' + udbfile) os.system('und analyze ' + udbfile) db = understand.open(udbfile) lines = [] lines.append(str(options.Line)) apis_file = open('./api_json/'+options.Project+'.json', 'a+',encoding='utf-8') total_api = [] Finder.find_vulnerable_api(db, file_name, lines, apis_file, total_api) jar.find_jar(options.Project) else: if options.Evaluate != 0: if options.Evaluate == 1: Evaluator.compute_project_star_fork() elif options.Evaluate == 2: Evaluator.compute_vulnerable_api_num() elif options.Evaluate == 3: Evaluator.compute_project_star_fork() Evaluator.compute_vulnerable_api_num() if options.Save == 1: Saver.save_api_into_database() Saver.save_vul_into_database() else: if options.Save == 1: Saver.save_api_into_database() Saver.save_vul_into_database() else: print('you should input project, file and line at the same time!')
def touched_ae(dst): pardir = os.path.split(dst)[0] if not pardir: pardir = os.curdir import Finder f = Finder.Finder() f.update(File.FSRef(pardir))
def testBigInitialisationWith2KAndFind50kTimes(self): init_lower_case = [] init_all = [] max_count = 1000 for val in itertools.permutations(string.ascii_lowercase): max_count -= 1 if max_count <= 0: break init_lower_case.append("".join(val)) init_all.append("".join(val)) max_count = 1000 for val in itertools.permutations(string.ascii_uppercase): max_count -= 1 if max_count <= 0: break init_all.append("".join(val)) startTime = time.time_ns() / (10 ** 9) testFinder = Finder.Finder(init_all) print('%s init: %.6f sec' % (self.id(), time.time_ns() / (10 ** 9) - startTime)) startTime = time.time_ns() / (10 ** 9) for _ in range(50000): res = testFinder.find("".join(string.ascii_lowercase)) print('%s 50K Find: %.6f sec' % (self.id(), time.time_ns() / (10 ** 9) - startTime)) self.assertSetEqual(set(res), set(init_lower_case))
def _getfinder(): """returns basic (recyclable) Finder AE interface object""" global _finder_talker if not _finder_talker: _finder_talker = Finder.Finder() _finder_talker.send_flags = _finder_talker.send_flags | AppleEvents.kAECanInteract | AppleEvents.kAECanSwitchLayer return _finder_talker
def touched_ae(dst): """Tell the finder a file has changed""" pardir = os.path.split(dst)[0] if not pardir: pardir = os.curdir import Finder f = Finder.Finder() f.update(File.FSRef(pardir))
def subroutine_class(file_path): sub_name = Finder.get_sub(file_path) use_list = Finder.get_use(file_path) var_list = Finder.get_var(file_path) meth_list = [] call_list = Finder.get_call(file_path) type_stat = Finder.get_type(file_path) # Function type could come here, but it is set to "" in mother path = file_path subroutine = Subroutine(sub_name, \ path, \ use_list, \ var_list, \ meth_list, \ call_list, \ type_stat) return subroutine
def program_class(file_path): prog_name = Finder.get_prog(file_path) use_list = Finder.get_use(file_path) var_list = Finder.get_var(file_path) meth_list = [] call_list = Finder.get_call(file_path) type_stat = Finder.get_type(file_path) # Function type could come here, but it is set to "" in mother path = file_path program = Program(prog_name, \ path, \ use_list, \ var_list, \ meth_list, \ call_list, \ type_stat) return program
def program_objects(file_paths, mod_list): program_list = [] for i in range(len(file_paths)): program_name = Finder.get_prog(file_paths[i]) # find program from file paths if program_name != 0: # if it is program then append to list program_list.append(program_class(file_paths[i])) return program_list
def function_objects(file_paths, mod_list): functions_list = [] for i in range(len(file_paths)): fun_name = Finder.get_fun(file_paths[i]) # find functions from file paths if fun_name != 0: # if it is function then append to list functions_list.append(function_class(file_paths[i])) return functions_list
def subroutine_objects(file_paths, mod_list): subroutines_list = [] for i in range(len(file_paths)): sub_name = Finder.get_sub( file_paths[i]) # find subroutines from file paths if sub_name != 0: # if it is sub then append to list subroutines_list.append(subroutine_class(file_paths[i])) return subroutines_list
def module_objects(file_paths, mod_list): modules_list = [] for i in range(len(file_paths)): module_name = Finder.get_mod( file_paths[i]) # find modules from file paths if module_name != []: # if it is module append to list modules_list.append(module_class(file_paths[i])) return modules_list
def testBigInitialisationWith100K(self): cur_initialisation = [] max_count = 100000 for val in itertools.permutations(string.ascii_lowercase): max_count -= 1 if max_count <= 0: break cur_initialisation.append("".join(val)) startTime = time.time_ns() / (10 ** 9) testFinder = Finder.Finder(cur_initialisation) print('%s init: %.6f sec' % (self.id(), time.time_ns() / (10 ** 9) - startTime)) startTime = time.time_ns() / (10 ** 9) res = testFinder.find("".join(string.ascii_lowercase)) print('%s find: %.6f sec' % (self.id(), time.time_ns() / (10 ** 9) - startTime)) self.assertSetEqual(set(res), set(cur_initialisation))
def __init__(self, window, window_title, video_source=0): self.window = window self.window.title(window_title) self.video_source = video_source # open video source (by default this will try to open the computer webcam) self.vid = VideoCapture.MyVideoCapture(self.video_source) # Create a canvas that can fit the above video source size self.canvas = tkinter.Canvas(window, width=self.vid.width, height=self.vid.height) self.canvas.pack() # After it is called once, the update method will be automatically called every delay milliseconds self.delay = 15 self.finder = Finder.FeatureFinder() self.update() self.window.mainloop()
def echo(update: Update, context: CallbackContext): key = update.message.text if not is_ascii(key): update.message.reply_text( "corrently we can't support this language, please try english.") else: result = {} start = time.time() for i in range(0, 45, 3): find = Finder.CacheSearch(key, i) if find != None: keys = list(find.keys())[0] result[keys] = find[keys] end = time.time() output = "search result ({} seconds)\n--------------------------------------------\n".format( round(end - start, 2)) #keys = list(result.keys())[0] for i in range(len(result) - 1, -1, -1): key = list(result.keys())[i] output += "\n{}: {}\ndownload: /{}\n--------------------------------------------\n".format( i + 1, result[key], key) update.message.reply_text(output, parse_mode=ParseMode.HTML)
def main(): parser = OptionParser(usage="usage: %prog [options] ", version="%prog 1.0") parser.add_option("-i", "--init", action="store_true", dest="init", default=False, help=u"初始化数据库") parser.add_option("-s", "--string", action="store", dest="search_string", default="", help=u"搜索字符串") (options, args) = parser.parse_args() if options.init: init() exit(0) Configuration.load('debug.yml') DBMS.create_table(Configuration.db_path) Sensor.sensor('20170225') Spider.spider(file_date='20170225', log_type='postran') conditions = parse_search_string(options.search_string) conditions["logType"] = 'postran' finder_result = Finder.finder(conditions) #finder_result = Finder.finder({'logType': 'postran', 'FileDate': '20140715', 'rrn': '141960021923', 'amount': '', # 'MrchId': ''}) Filter.filter_by_call(finder_result)
def module_class(file_path): module_name = Finder.get_mod(file_path) use_list = Finder.get_use(file_path) var_list = Finder.get_var(file_path) meth_list = Finder.get_meth(file_path) call_list = Finder.get_call(file_path) type_stat = Finder.get_type(file_path) # Function type could come here, but it is set to "" in mother path = file_path module = Module(module_name, \ path, \ use_list, \ var_list, \ meth_list, \ call_list, \ type_stat) return module
def function_class(file_path): fun_name = Finder.get_fun(file_path) use_list = Finder.get_use(file_path) var_list = Finder.get_var(file_path) meth_list = [] call_list = Finder.get_call(file_path) type_stat = Finder.get_type(file_path) fun_type = Finder.get_fun_type(file_path) path = file_path function = Function(fun_name, \ path, \ use_list, \ var_list, \ meth_list, \ call_list, \ type_stat, \ fun_type) return function
from hashTables import Files from target_zone import * from Finder import * if __name__ == "__main__": bd = Files() bd.bd_filler() song_hash_data = 'D:/курсач/songs data/три белых коня/after/DaryaLoban.txt' find = Finder(song_hash_data, bd) find.take_targets() find.comparator()
"""macostools - Various utility functions for MacOS.
if __name__ == "__main__": inputFile = file(INPUT_FILE) outputFile = file(OUTPUT_FILE, "w") numTestCases = int(inputFile.readline()) for tcIndex in range(numTestCases): numNumbers = int(inputFile.readline()) print "numbers:", numNumbers x = inputFile.readline().rstrip().split() y = inputFile.readline().rstrip().split() x = [long(value) for value in x] y = [long(value) for value in y] print "x:", x print "y:", y finder = Finder(x, y) minScalar = finder.getMinScalar() outputFile.write("Case #" + str(tcIndex + 1) + ": ") outputFile.write('%d ' % minScalar) outputFile.write("\n") outputFile.close() inputFile.close()
import cv2 import numpy as np import Finder import VideoCapture import statistics import matplotlib.pyplot as plt finder = Finder.FeatureFinder() videocap = VideoCapture.MyVideoCapture() face = cv2.imread("face.jpg") img = face gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) blur = cv2.GaussianBlur(gray, (7, 7), 0) _, threshold = cv2.threshold(blur, 25, 255, cv2.THRESH_BINARY_INV) while True: ret, frame = videocap.get_frame() finder.set_image(frame) if len(finder.roi) == 0: finder.find_face() if len(finder.roi != 0): face = finder.roi blur = cv2.GaussianBlur(face, (7, 7), 0) _, threshold = cv2.threshold(blur, 25, 255, cv2.THRESH_BINARY_INV) contours, heirarchy = cv2.findContours(threshold, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) for cnt in contours: cv2.drawContours(img, [cnt], -1, (0, 0, 255), 1) # M = cv2.moments(cnt) # cX = int(M["m10"] / M["m00"]) # cY = int(M["m01"] / M["m00"])
# Help.helper(query) elif query[0] == 'g' or query[0] == 'google': if len(query) > 1: webbrowser.open('http://www.google.com/search?q=' + query[1]) else: webbrowser.open('http://www.google.com/search?q=') elif query[0] == 'ddg' or query[0] == 'duckduckgo': if len(query) > 1: webbrowser.open('http://www.duckduckgo.com/' + query[1]) else: webbrowser.open('http://www.duckduckgo.com/') elif query[0] == 'find': Finder.find(query[1], plat) elif 'run' == query[0] or 'start' == query[0]: Finder.run(query[1], plat) elif query[0] == 'open': Finder.open(query[1], plat) # pass elif 'music' in query or 'songs' in query or 'song' in query: Music.run_query(query, plat) # elif 'login' in query: # subprocess.call("%USERPROFILE%\Documents\MyCyberoam.py",shell=True) elif 'change' == query[0] and 'wallpaper' in query[1].lower():
"""Utility routines depending on the finder,
from Bio import SeqIO import os import Finder os.getcwd() os.chdir('C:/Users/alexa/OneDrive/Coursera/Python for Genomic Data Science') # TODO: Loop through a FASTA file and store each identifier in a value and the sequence in a key my_seq = Finder.parse_fasta("test.fasta") Finder.quickView(my_seq) print("Number of identifiers = ", len(my_seq)) # Get each identifier and sequence and store them in a dict seq_dict = {} for i, record in enumerate(my_seq): seq_dict[record.id] = record.seq.lower() # TODO: Get open reading frames for each identifier in each frame and store them in respective dict frameOne = {} frameTwo = {} frameThree = {} frameList = [frameOne, frameTwo, frameThree] orfs = [] for key, value in seq_dict.items(): start_Codons = Finder.has_start_codon(str(value)) stop_Codons = Finder.has_stop_codon(str(value)) orfs = Finder.find_orf(start_Codons, stop_Codons, 1) frameOne[key] = (orfs) print(frameOne) ''' for i, frame in range(len(frameList)):
def _getfinder(): global _finder_talker if not _finder_talker: _finder_talker = Finder.Finder() _finder_talker.send_flags = _finder_talker.send_flags | AppleEvents.kAECanInteract | AppleEvents.kAECanSwitchLayer return _finder_talker
def parse_preJS(sourcefile, v, link_target): if not (os.path.exists(sourcefile)): raise Exceptions.SourceNotFound(sourcefile) if not (sourcefile.endswith(".preJS")): raise SuffixMismatch(sourcefile) source = "" with open(sourcefile, "r") as f: vlog("Reading '%s' ... " % sourcefile, v) source = f.read() # Find all include directives # vlog("Finding includes...", v) includes = Finder.find_includes(source) include_iter = 1 while includes: for include in includes: include_tokens = Lex.include_directive_parser.parse(include) vlog("\tIncluding '%s' ..." % include_tokens["filename"], v) included_text = IncludeResolver.resolve_include(sourcefile, include_tokens["filename"], v) source = source.replace(include, included_text, 1) while include in source: source = source.replace(include, "") # If the included files also contain includes, we'll go through those next # includes = Finder.find_includes(source) if includes: include_iter += 1 vlog("Performing include pass %d" % include_iter, v) vlog("Included files: %s" % (repr(IncludeResolver.global_includes_resolved)), v) # After includes, we then do our define directives # vlog("\n", v) vlog("Finding symbol definitions...", v) define_iter = 1 defines = Finder.find_definitions(source) while defines: vlog("Processing %d symbol definitions" % (len(defines)), v) for define in defines: define_tokens = Lex.define_directive_parser.parse(define) # vlog("'%s' defined as '%s'\n" % (define_tokens["name"], define_tokens["definition"]),v) name = "@%s" % define_tokens["name"] while name in source: source = source.replace(name, define_tokens["definition"]) while define in source: source = source.replace(define, "") # In case someone tries to do some fancy defining # defines = Finder.find_definitions(source) if defines: define_iter += 1 vlog("Performing definition pass %d" % define_iter, v) # Now that we've processed our standard directives, we can take care of # our syntacitcal sugar. We'll start with 'sub' macros, as they are # slightly more abstract sub_iter = 1 vlog("Finding substitution macros...", v) subs = Finder.find_substitutions(source) while subs: vlog("Resolving %d substitution macros..." % len(subs), v) for sub in subs: sub_tokens = Lex.substitution_macro_parser.parse(sub) resolution = Substitutor.sub(sub_tokens) while sub in source: source = source.replace(sub, resolution) subs = Finder.find_substitutions(source) if subs: sub_iter += 1 vlog("Performing pass %d of substitution macros" % sub_iter, v) # And then the anonymous for, in loops: loop_iter = 1 vlog("Finding anonymous for-in loops...", v) loops = Finder.find_anon_for_in_loops(source) while loops: vlog("Rewriting %d loops with symbol base %s" % (len(loops), Loops.global_random_symbol), v) for loop in loops: try: loop_tokens = Lex.anon_for_in_parser.parse(loop) resolution = Loops.anon_for_in(loop_tokens, v) while loop in source: source = source.replace(loop, resolution) except Exception as e: print (e.__str__()) print "Unchecked error near %s - this is the utility's fault, not yours" % repr(loop[:32]) raise e loops = Finder.find_anon_for_in_loops(source) if loops: loop_iter += 1 vlog("Performing pass %d of anonymous for-in loops" % loop_iter, v) while source[1] == "\n": source = source.replace("\n", "", 1) # And then markdown links vlog("Finding markdown links...", v) links = [] strlits = Finder.find_string_literals(source) for literal in strlits: links.extend(Finder.find_markdown_links(literal)) for link in links: link_tokens = Lex.markdown_link_parser.parse(link) if link_target: target_template = 'target=\\"%s\\"' % link_target template = '<a href=\\"%s\\" %s>%s</a>' html_link = template % (link_tokens["anchor"], target_template, link_tokens["text"]) while link in source: source = source.replace(link, html_link) return source
# #------------------------------------------ #--------------------------------------- # Find object coordinates in Xfig units #--------------------------------------- Xfig.find_coordinates(obj_list, box_margins) if xy_specified != "None": obj_list = Objects.load_xy_coordinates(xy_specified, \ obj_list, \ object_hierarchy) #---------------------------- # Find calls between objects #---------------------------- obj_list = Finder.get_new_calls(file_paths, obj_list, obj_memb) #------------------------------------ # Create connections between objects #------------------------------------ offset stride spl_list = Spline.connect_objects(obj_list, box_margins, box_margins * 0.5) #---------------- # Open Xfig file #---------------- file = open(Const.FIG_FILE_NAME, "w") #------------------ # Write header out #------------------ Xfig.write_header(file)
import time import Finder while True: try: Finder.finder() except Exception as e: print(e) time.sleep(20) pass else: break