Exemplo n.º 1
0
    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
Exemplo n.º 2
0
    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
Exemplo n.º 3
0
    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)
Exemplo n.º 4
0
    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)
Exemplo n.º 5
0
    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
Exemplo n.º 6
0
 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))