예제 #1
0
파일: molter.py 프로젝트: philipn/molt
    def func(u=None):
        if u is None:
            u = ""
        bytes_in = u.encode(defaults.LAMBDA_ENCODING, errors=defaults.ENCODING_ERRORS)

        stdout, stderr, return_code = call_script(path, bytes_in)

        return stdout.decode(defaults.LAMBDA_ENCODING, errors=defaults.ENCODING_ERRORS)
예제 #2
0
    def test(self):
        with self.sandboxDir() as dir_path:
            path = os.path.join(dir_path, "test.sh")
            _create_file(path, SHEBANG_LINE)
            args = [path]

            # Will not work until we set the executable bit.
            # TODO: switch from Exception to OSError.  We cannot do this
            #   until we've changed our implementation of reraise() to
            #   preserve the exception type.
            self.assertRaises(Exception, call_script, args)
            set_executable_bit(path)
            stdout_data, stderr_data, return_code = call_script(args)
예제 #3
0
    def _call_script(self, script_name, u):
        """
        Return stdout as a unicode string.

        """
        script_path = self._get_script_path(script_name)

        base_name = os.path.basename(script_path)
        new_path = os.path.join(self.temp_dir, base_name)

        copyfile(script_path, new_path)
        set_executable_bit(new_path)

        bytes_in = u.encode(ENCODING_DEFAULT)

        stdout, stderr, return_code = call_script([new_path], bytes_in)

        stdout = stdout.decode(ENCODING_DEFAULT)

        return stdout
예제 #4
0
def _call_script(args):
    stdout, stderr, return_code = call_script(args)

    stdout, stderr = (s.decode(ENCODING_DEFAULT) for s in (stdout, stderr))

    return stdout, stderr, return_code