Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def redirected_stdo(module, stdout=None, stderr=None):
conn = module.client.conn
if stdout is None:
stdout = module.stdout
if stderr is None:
stderr = module.stdout
hotpatch_oswrite(conn)
orig_stdout = conn.modules.sys.stdout
orig_stderr = conn.modules.sys.stderr
try:
conn.modules.sys.stdout = restricted(stdout,["softspace", "write", "flush"])
conn.modules.sys.stderr = restricted(stderr,["softspace", "write", "flush"])
yield
finally:
conn.modules.sys.stdout = orig_stdout
conn.modules.sys.stderr = orig_stderr
"""
conn = module.client.conn
orig_stdin = conn.modules.sys.stdin
orig_stdout = conn.modules.sys.stdout
orig_stderr = conn.modules.sys.stderr
if stdout is None:
stdout = module.stdout
if stderr is None:
stderr = module.stdout
try:
conn.modules.sys.stdin = restricted(sys.stdin, ["softspace", "write", "readline", "encoding", "close"])
conn.modules.sys.stdout = restricted(stdout, ["softspace", "write", "readline", "encoding", "close", "flush"])
conn.modules.sys.stderr = restricted(stderr, ["softspace", "write", "readline", "encoding", "close", "flush"])
yield
finally:
conn.modules.sys.stdin = orig_stdin
conn.modules.sys.stdout = orig_stdout
conn.modules.sys.stderr = orig_stderr
with redirected_stdio(conn):
conn.modules.sys.stdout.write("hello\n") # will be printed locally
"""
conn = module.client.conn
orig_stdin = conn.modules.sys.stdin
orig_stdout = conn.modules.sys.stdout
orig_stderr = conn.modules.sys.stderr
if stdout is None:
stdout = module.stdout
if stderr is None:
stderr = module.stdout
try:
conn.modules.sys.stdin = restricted(sys.stdin, ["softspace", "write", "readline", "encoding", "close"])
conn.modules.sys.stdout = restricted(stdout, ["softspace", "write", "readline", "encoding", "close", "flush"])
conn.modules.sys.stderr = restricted(stderr, ["softspace", "write", "readline", "encoding", "close", "flush"])
yield
finally:
conn.modules.sys.stdin = orig_stdin
conn.modules.sys.stdout = orig_stdout
conn.modules.sys.stderr = orig_stderr
Redirects the other party's ``stdin``, ``stdout`` and ``stderr`` to
those of the local party, so remote IO will occur locally.
Example usage::
with redirected_stdio(conn):
conn.modules.sys.stdout.write("hello\n") # will be printed locally
"""
orig_stdin = conn.modules.sys.stdin
orig_stdout = conn.modules.sys.stdout
orig_stderr = conn.modules.sys.stderr
try:
conn.modules.sys.stdin =restricted(sys.stdin, ["softspace", "write", "readline", "encoding", "close"])
conn.modules.sys.stdout = restricted(sys.stdout, ["softspace", "write", "readline", "encoding", "close", "flush"])
conn.modules.sys.stderr = restricted(sys.stderr, ["softspace", "write", "readline", "encoding", "close", "flush"])
yield
finally:
conn.modules.sys.stdin = orig_stdin
conn.modules.sys.stdout = orig_stdout
conn.modules.sys.stderr = orig_stderr
Redirects the other party's ``stdin``, ``stdout`` and ``stderr`` to
those of the local party, so remote IO will occur locally.
Example usage::
with redirected_stdio(conn):
conn.modules.sys.stdout.write("hello\n") # will be printed locally
"""
orig_stdin = conn.modules.sys.stdin
orig_stdout = conn.modules.sys.stdout
orig_stderr = conn.modules.sys.stderr
try:
conn.modules.sys.stdin =restricted(sys.stdin, ["softspace", "write", "readline", "encoding", "close"])
conn.modules.sys.stdout = restricted(sys.stdout, ["softspace", "write", "readline", "encoding", "close", "flush"])
conn.modules.sys.stderr = restricted(sys.stderr, ["softspace", "write", "readline", "encoding", "close", "flush"])
yield
finally:
conn.modules.sys.stdin = orig_stdin
conn.modules.sys.stdout = orig_stdout
conn.modules.sys.stderr = orig_stderr
ns = module.client.conn.namespace
stdin = sys.stdin
if stdout is None:
stdout = module.stdout
if stderr is None:
stderr = module.stdout
try:
ns['redirect_stdio'](
restricted(
stdin, ['softspace', 'write', 'readline', 'encoding', 'close']),
restricted(
stdout, ['softspace', 'write', 'readline', 'encoding', 'close']),
restricted(
stderr, ['softspace', 'write', 'readline', 'encoding', 'close']))
module.client.conn.register_remote_cleanup(ns['reset_stdio'])
yield
finally:
ns['reset_stdio']()
module.client.conn.unregister_remote_cleanup(ns['reset_stdio'])
r"""
Redirects the other party's ``stdin``, ``stdout`` and ``stderr`` to
those of the local party, so remote IO will occur locally.
Example usage::
with redirected_stdio(conn):
conn.modules.sys.stdout.write("hello\n") # will be printed locally
"""
orig_stdin = conn.modules.sys.stdin
orig_stdout = conn.modules.sys.stdout
orig_stderr = conn.modules.sys.stderr
try:
conn.modules.sys.stdin =restricted(sys.stdin, ["softspace", "write", "readline", "encoding", "close"])
conn.modules.sys.stdout = restricted(sys.stdout, ["softspace", "write", "readline", "encoding", "close", "flush"])
conn.modules.sys.stderr = restricted(sys.stderr, ["softspace", "write", "readline", "encoding", "close", "flush"])
yield
finally:
conn.modules.sys.stdin = orig_stdin
conn.modules.sys.stdout = orig_stdout
conn.modules.sys.stderr = orig_stderr
def redirected_stdo(module, stdout=None, stderr=None):
ns = module.client.conn.namespace
if stdout is None:
stdout = module.stdout
if stderr is None:
stderr = module.stdout
try:
ns['redirect_stdo'](
restricted(
stdout, ['softspace', 'write', 'flush']),
restricted(
stderr, ['softspace', 'write', 'flush']))
module.client.conn.register_remote_cleanup(ns['reset_stdo'])
yield
finally:
ns['reset_stdo']()
module.client.conn.unregister_remote_cleanup(ns['reset_stdo'])
def redirected_stdio(conn):
r"""
Redirects the other party's ``stdin``, ``stdout`` and ``stderr`` to
those of the local party, so remote IO will occur locally.
Example usage::
with redirected_stdio(conn):
conn.modules.sys.stdout.write("hello\n") # will be printed locally
"""
orig_stdin = conn.modules.sys.stdin
orig_stdout = conn.modules.sys.stdout
orig_stderr = conn.modules.sys.stderr
try:
conn.modules.sys.stdin =restricted(sys.stdin, ["softspace", "write", "readline", "encoding", "close"])
conn.modules.sys.stdout = restricted(sys.stdout, ["softspace", "write", "readline", "encoding", "close", "flush"])
conn.modules.sys.stderr = restricted(sys.stderr, ["softspace", "write", "readline", "encoding", "close", "flush"])
yield
finally:
conn.modules.sys.stdin = orig_stdin
conn.modules.sys.stdout = orig_stdout
conn.modules.sys.stderr = orig_stderr
conn.modules.sys.stdout.write("hello\n") # will be printed locally
"""
ns = module.client.conn.namespace
stdin = sys.stdin
if stdout is None:
stdout = module.stdout
if stderr is None:
stderr = module.stdout
try:
ns['redirect_stdio'](
restricted(
stdin, ['softspace', 'write', 'readline', 'encoding', 'close']),
restricted(
stdout, ['softspace', 'write', 'readline', 'encoding', 'close']),
restricted(
stderr, ['softspace', 'write', 'readline', 'encoding', 'close']))
module.client.conn.register_remote_cleanup(ns['reset_stdio'])
yield
finally:
ns['reset_stdio']()
module.client.conn.unregister_remote_cleanup(ns['reset_stdio'])