def parse_shell(self, value): """Parse the supplied shell code in a string, returning the external commands it executes. """ h = hash(str(value)) if h in shellparsecache: self.execs = shellparsecache[h]["execs"] return self.execs if h in shellparsecacheextras: self.execs = shellparsecacheextras[h]["execs"] return self.execs try: tokens, _ = pyshyacc.parse(value, eof=True, debug=False) except pyshlex.NeedMore: raise sherrors.ShellSyntaxError("Unexpected EOF") for token in tokens: self.process_tokens(token) self.execs = set(cmd for cmd in self.allexecs if cmd not in self.funcdefs) shellparsecacheextras[h] = {} shellparsecacheextras[h]["execs"] = self.execs return self.execs
def _parse_shell(self, value): try: tokens, _ = pyshyacc.parse(value, eof=True, debug=False) except pyshlex.NeedMore: raise sherrors.ShellSyntaxError("Unexpected EOF") for token in tokens: self.process_tokens(token)
def parse_shell(self, value): """Parse the supplied shell code in a string, returning the external commands it executes. """ try: tokens, _ = pyshyacc.parse(value, eof=True, debug=False) except pyshlex.NeedMore: raise ShellSyntaxError("Unexpected EOF") for token in tokens: self.process_tokens(token) cmds = set(cmd for cmd in self.execs if cmd not in self.funcdefs) return cmds
def translate(self, shell, toplevel=False): commands, leftover = pyshyacc.parse(shell, True) if toplevel: return self.translate_toplevel(commands) return flatten(self.translate_commands(commands))