def _split(s): """ read a string representing python code and 'print "echo; echo;"' """ out_list = [] cur_substring = "" in_string_type = None for las, cur, nex in threewise(s): cur_substring += cur if not in_string_type: if cur == '"' or cur == "'": # out_list.append((cur_substring,in_string_type)) in_string_type = cur # cur_substring = cur elif (cur == ":" and nex == " "): out_list.append(cur_substring.strip()) cur_substring = "" elif (cur == ";"): out_list.append(cur_substring.strip()) cur_substring = "" else: if (cur == '"' or cur == "'") and las != "\\": #out_list.append((cur_substring,in_string_type)) in_string_type = None #cur_substring = "" if cur_substring: out_list.append(cur_substring.strip()) return out_list
def _paste_lambdas(match_list): """don't want newline after 'lambda x:' """ for las, cur, nex in threewise(match_list): #TODO: replace with regex of exactly the characters allowed in python variable names (instead of strictly alphanumeric)? regex = "lambda[ 0-9A-Za-z]*:$" if las and re.findall(regex, las): continue elif re.findall(regex, cur): yield cur + " " + nex else: yield cur