def wrap(instruction_line, tokens): try: rv = f(instruction_line, tokens) if rv is None: raise InstructionSyntaxException("") else: return rv except InstructionSyntaxException: Logger.add_error("Invalid instruction: '%s'. Instruction ignored" % instruction_line) raise
def describe_window(self, hwnd=None): if facade.has_win_implementation(): try: nbr_of_children = len(facade.get_children(hwnd)) if hwnd is None: hwnd = facade.get_active_window() rect = facade.get_window_rect(hwnd) Logger.bold_header("Window Description \n hwnd: %d \n Classname: '%s' \n Label: '%s'\n Nbr of children: %d\n Position: (%d, %d)\n Size: (%d, %d)" % ( hwnd, facade.get_classname(hwnd), facade.get_window_text(hwnd), nbr_of_children, rect[0], rect[1], rect[2], rect[3])) Logger.header2("Native Description") self.describe_children(hwnd) except Exception, ex: Logger.add_error("Native windows description failed")
def __init__(self, manuscript, timedelay): self.timedelay = timedelay self.popup = None self.execution_started = False self.windows = [] self.instructions = [] for line in [ line for line in manuscript.get_instructions() if not line.startswith("#") and len(line.strip()) > 0 ]: try: instruction = parse(line) except Exception: Logger.add_error("Can't parse instruction: '%s'" % line) raise if instruction is not None: self.instructions.append(instruction) collector = [] for instruction in self.instructions: collector.append(instruction.to_unicode()) Logger.header("Effective Instructions:\n %s" % "\n ".join(collector))
def run_python_file(args): """Run a python file as if it were the main program on the command line. `args` is the argument array to present as sys.argv, including the first element representing the file being executed. Lifted straight from coverage.py by Ned Batchelder """ try: # In Py 2.x, the builtins were in __builtin__ BUILTINS = sys.modules['__builtin__'] except KeyError: # pragma: no cover - not worried about Python 3 yet... # In Py 3.x, they're in builtins BUILTINS = sys.modules['builtins'] filename = args[0] # Create a module to serve as __main__ old_main_mod = sys.modules['__main__'] main_mod = imp.new_module('__main__') sys.modules['__main__'] = main_mod main_mod.__file__ = filename main_mod.__builtins__ = BUILTINS # Set sys.argv and the first path element properly. old_argv = sys.argv old_path0 = sys.path[0] sys.argv = args sys.path[0] = os.path.dirname(filename) try: sys.stdout = open('outfile.txt', 'w') source = open(filename, 'rU').read() exec compile(source, filename, "exec") in main_mod.__dict__ except Exception, ex: Logger.add_error("%s" % ex) Logger.failure("Exception in application")
def scan(text): global _tab_count global _print_unknown_only global _first_char_on_line global _col prevcol = 1 _tab_count = 0 _col = 0 text = text.strip() nbr_of_chars = len(text) i = 0 nbr_of_unkown = 0 tokens = [] _first_char_on_line = ' ' while i < nbr_of_chars: lexeme = u"unknown" typename = "Unknown" token = UNKNOWN subid = None # Comment if i == 0 and text[i] == '#': lexeme = text.decode("utf-8") typename = "Comment" token = Token(KEYWORD, text, ID_COMMENT, col=0) tokens.append(token) return tokens # Space elif text[i] == ' ': lexeme = u" " typename = "Space" token = SPACE # Tab elif text[i] == '\t': lexeme = u" " typename = "Tab" token = TAB _tab_count = _tab_count + 1 # Left Parenthesis elif text[i] == '(': lexeme = u"(" typename = "Left Parenthesis" token = LP # Right Parenthesis elif text[i] == ')': lexeme = u")" typename = "Right Parenthesis" token = RP elif text[i] == '=': lexeme = u"=" typename = "Equal sign" token = EQ elif text[i] == '+': lexeme = u"+" typename = "Plus sign" token = PLUS elif text[i] == ',': lexeme = u"," typename = "Comma" token = COMMA elif text[i] == '|': lexeme = u"|" typename = "Or" token = OR elif text[i] == '"': lexeme, token, subid, i = _parse_string(text, i) typename = "String" _col = i + 1 elif text[i] == "'": lexeme, token, subid, i = _parse_string(text, i) typename = "String" _col = i + 1 elif text[i].isalnum() or text[i] in ID_SPECIAL_CHARS: lexeme, token, subid, i = _parse_identifier(text, i) typename = "Identifier" _col = i + 1 # Unknown token else: if text[i].isspace(): lexeme = u" " typename = "Space" token = SPACE else: nbr_of_unkown = nbr_of_unkown + 1 lexeme = u"%c" % text[i] i += 1 _col += 1 # Print result if _print_unknown_only: if (token == UNKNOWN): msg = "%d %d %s %s" % (i, token, typename, lexeme) Logger.add_error(msg) if typename != "Space": token = Token(token, lexeme, subid, col=prevcol) tokens.append(token) prevcol = _col if nbr_of_unkown > 0: msg = "Nbr of unknown tokens encountered = %d" % nbr_of_unkown Logger.add_error(msg) return tokens
def __init__(self, msg): Logger.add_error(msg)