Beispiel #1
0
def subprocess(handler):
    '''Used by test_cache.TestSubprocess to check if gramex.cache.Subprocess works'''
    kwargs = {}
    if handler.args.get('out'):
        kwargs['stream_stdout'] = [handler.write] * len(handler.args['out'])
    if handler.args.get('err'):
        kwargs['stream_stderr'] = [handler.write] * len(handler.args['err'])
    if handler.args.get('buf'):
        buf = handler.args['buf'][0]
        kwargs['buffer_size'] = int(buf) if buf.isdigit() else buf
    if handler.args.get('env'):
        kwargs['env'] = dict(os.environ)
        kwargs['env'][str('GRAMEXTESTENV')] = str('test')   # env keys & values can only by str()
    handler.write('stream: ')
    proc = Subprocess(handler.args['args'], universal_newlines=True, **kwargs)
    stdout, stderr = yield proc.wait_for_exit()
    raise gen.Return(b'return: ' + stdout + stderr)
Beispiel #2
0
    def get(self, *path_args):
        if self.redirects:
            self.save_redirect_page()
        for header_name, header_value in self.headers.items():
            self.set_header(header_name, header_value)

        proc = Subprocess(
            self.cmdargs,
            shell=self.shell,
            cwd=self.cwd,
            stream_stdout=self.stream_stdout,
            stream_stderr=self.stream_stderr,
            buffer_size=self.buffer_size,
        )
        yield proc.wait_for_exit()
        # Wait for process to finish
        proc.proc.wait()
        if self.redirects:
            self.redirect_next()
Beispiel #3
0
    def get(self, *path_args):
        if self.redirects:
            self.save_redirect_page()
        for header_name, header_value in self.headers.items():
            self.set_header(header_name, header_value)

        proc = Subprocess(
            self.cmdargs,
            # shell=True is safe here if app developer explicitly requests it
            shell=self.shell,  # nosec
            cwd=self.cwd,
            stream_stdout=self.stream_stdout,
            stream_stderr=self.stream_stderr,
            buffer_size=self.buffer_size,
        )
        yield proc.wait_for_exit()
        # Wait for process to finish
        proc.proc.wait()
        if self.redirects:
            self.redirect_next()