def ratings_to_message(ratings, target=None, old_rating=None, moved_steps=''): str = '' for person, rating in ratings.items(): if person == target: str += '{} {} → {} {}\n'.format(person, old_rating, rating, moved_steps) else: str += '{} {}\n'.format(person, rating) rreplace(str, '\n', '', 1) return str
def annotate(self, fpath, pred_idx, type_idx): self.__reset() if pred_idx == -1: self.__sift(fpath=fpath) else: self.__sift(pred_idx=pred_idx) # if no proper (i.e. non-property-access) predictions are for this file, # or the predictions are fewer than args.top if len(self.__rel_lines) == 0 or type_idx >= len( self.__rel_lines[0]["predicted_annotation_logprob_dist"]): return fpath self.__type_idx = type_idx with open(fpath) as src: self.__tree = parse(src.read()) # self.__PP.pprint(dump(tree)) new_tree = self.visit(self.__tree) if self.__unmodified: return fpath self.__add_type_imports(self.__get_types_2_import()) new_tree = fix_missing_locations(new_tree) OLD_EXT = ".py" NEW_EXT = f"_tpl_{type_idx}.py" new_fpath = rreplace(fpath, OLD_EXT, NEW_EXT, 1) with open(new_fpath, "w", encoding="utf8") as dst: dst.write(typed_astunparse.unparse(new_tree)) return new_fpath
def prettyPrintLables(lstOfLabels): infoLabels = [x for y in lstOfLabels for x in y] nodeLabel = '' for trInfo in infoLabels: for tdInfo in trInfo: tdInfo = re.sub('[^0-9a-zA-Z_-]+', '', tdInfo) if tdInfo: nodeLabel = nodeLabel + tdInfo + ' : ' nodeLabel = utils.rreplace(nodeLabel, ' : ', '', 1) nodeLabel = nodeLabel + '\n' return nodeLabel
def prettyPrintLables(lstOfLabels): infoLabels = [x for y in lstOfLabels for x in y] nodeLabel='' for trInfo in infoLabels: for tdInfo in trInfo: tdInfo = re.sub('[^0-9a-zA-Z_-]+', '', tdInfo) if tdInfo: nodeLabel = nodeLabel + tdInfo + ' : ' nodeLabel = utils.rreplace(nodeLabel, ' : ', '', 1) nodeLabel = nodeLabel + '\n' return nodeLabel
def number_to_words(self, number): # Clean input (remove any non alphanumeric characters and make uppercase) number = utils.clean_input(number) # Check input if not utils.is_valid_input(number, regex="[\W\D]"): return None, None # returns a string word word, digits = self.find_word(number) if word: number = utils.rreplace(number, digits, word, 1) return word, number else: return None, None
sys.exit(2) if forunwindmax != -1 and not softforunwind: usage(cmd, "error: --for-max-unwind requires --softunwindbound") sys.exit(2) # tool configuration/installation/integrity check (TODO) if not os.path.isfile(backendFilename[format]): usage(cmd, "error: unable to find the given backend (%s)" % backendFilename[format]) sys.exit(2) """ 1'. Intermediate step - if the filename ends with .i, then the file has to be stripped and transformed back into a .c file in order to get properly parsed with PYCparser """ seqfile = utils.rreplace(inputfile, "/", "/_cs_", 1) if "/" in inputfile else "_cs_" + inputfile oldinputfile = inputfile (filestripped, contents) = utils.stripIfNeeded(inputfile) if filestripped: inputfile = inputfile[:-2] + ".strip.c" utils.saveFile(inputfile, contents) logfilename = seqfile + "." + format + ".log" if witness == "" else witness """ 2. Call CSeq and save the sequentialised file as '_cs_.....' """ if donotsequentialize == False: if verbose: print ("\ninput: %s") % (inputfile)