Beispiel #1
0
    def _expand_parameter(self, wtree, quoted=False, split=False):
        """Return a valid wtree or an empty list when no parameter results."""
        # Get the parameter name
        # TODO: implement weird expansion rules with ':'
        name = pyshlex.wordtree_as_string(wtree[1:-1])
        if not is_name(name) and not is_special_param(name):
            raise ExpansionError('Bad substitution "%s"' % name)
        # TODO: implement special parameters
        if name in ("@", "*"):
            args = self._env.get_positional_args()
            if len(args) == 0:
                return []
            if len(args) < 2:
                return ["", "".join(args), ""]

            sep = self._env.get("IFS", "")[:1]
            if split and quoted and name == "@":
                # Introduce a new token to tell the caller that these parameters
                # cause a split as specified in 2.5.2
                return ["@"] + args + [""]
            else:
                return ["", sep.join(args), ""]

        return ["", self._env.get(name, ""), ""]
Beispiel #2
0
    def _expand_parameter(self, wtree, quoted=False, split=False):
        """Return a valid wtree or an empty list when no parameter results."""
        # Get the parameter name
        # TODO: implement weird expansion rules with ':'
        name = pyshlex.wordtree_as_string(wtree[1:-1])
        if not is_name(name) and not is_special_param(name):
            raise ExpansionError('Bad substitution "%s"' % name)
        # TODO: implement special parameters
        if name in ('@', '*'):
            args = self._env.get_positional_args()
            if len(args) == 0:
                return []
            if len(args) < 2:
                return ['', ''.join(args), '']

            sep = self._env.get('IFS', '')[:1]
            if split and quoted and name == '@':
                # Introduce a new token to tell the caller that these parameters
                # cause a split as specified in 2.5.2
                return ['@'] + args + ['']
            else:
                return ['', sep.join(args), '']

        return ['', self._env.get(name, ''), '']
Beispiel #3
0
 def _expand_command(self, wtree):
     # BUG: there is something to do with backslashes and quoted
     # characters here
     command = pyshlex.wordtree_as_string(wtree[1:-1])
     status, output = self.subshell_output(command)
     return status, ["", output, ""]
Beispiel #4
0
 def _expand_command(self, wtree):
     # BUG: there is something to do with backslashes and quoted
     # characters here
     command = pyshlex.wordtree_as_string(wtree[1:-1])
     status, output = self.subshell_output(command)
     return status, ['', output, '']