mirror of
https://github.com/gradio-app/gradio.git
synced 2025-03-07 11:46:51 +08:00
refactor: f-string for tunneling.py (#1819)
* refactor: f-string for tunneling.py * formatting Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
This commit is contained in:
parent
175bba2117
commit
8212c462ae
@ -22,14 +22,14 @@ def handler(chan, host, port):
|
|||||||
try:
|
try:
|
||||||
sock.connect((host, port))
|
sock.connect((host, port))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
verbose("Forwarding request to {}:{} failed: {}".format(host, port, e))
|
verbose(f"Forwarding request to {host}:{port} failed: {e}")
|
||||||
return
|
return
|
||||||
|
|
||||||
verbose(
|
verbose(
|
||||||
"Connected! Tunnel open {} -> {} -> {}".format(
|
"Connected! Tunnel open "
|
||||||
chan.origin_addr, chan.getpeername(), (host, port)
|
f"{chan.origin_addr} -> {chan.getpeername()} -> {(host, port)}"
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
r, w, x = select.select([sock, chan], [], [])
|
r, w, x = select.select([sock, chan], [], [])
|
||||||
if sock in r:
|
if sock in r:
|
||||||
@ -44,11 +44,7 @@ def handler(chan, host, port):
|
|||||||
sock.send(data)
|
sock.send(data)
|
||||||
chan.close()
|
chan.close()
|
||||||
sock.close()
|
sock.close()
|
||||||
verbose(
|
verbose(f"Tunnel closed from {chan.origin_addr}")
|
||||||
"Tunnel closed from {}".format(
|
|
||||||
chan.origin_addr,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def reverse_forward_tunnel(server_port, remote_host, remote_port, transport):
|
def reverse_forward_tunnel(server_port, remote_host, remote_port, transport):
|
||||||
@ -69,12 +65,9 @@ def verbose(s, debug_mode=False):
|
|||||||
|
|
||||||
def create_tunnel(payload, local_server, local_server_port):
|
def create_tunnel(payload, local_server, local_server_port):
|
||||||
client = paramiko.SSHClient()
|
client = paramiko.SSHClient()
|
||||||
# client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
||||||
client.set_missing_host_key_policy(paramiko.WarningPolicy())
|
client.set_missing_host_key_policy(paramiko.WarningPolicy())
|
||||||
|
|
||||||
verbose(
|
verbose(f'Conecting to ssh host {payload["host"]}:{payload["port"]} ...')
|
||||||
"Connecting to ssh host {}:{} ...".format(payload["host"], int(payload["port"]))
|
|
||||||
)
|
|
||||||
try:
|
try:
|
||||||
with warnings.catch_warnings():
|
with warnings.catch_warnings():
|
||||||
warnings.simplefilter("ignore")
|
warnings.simplefilter("ignore")
|
||||||
@ -85,17 +78,12 @@ def create_tunnel(payload, local_server, local_server_port):
|
|||||||
pkey=paramiko.RSAKey.from_private_key(StringIO(payload["key"])),
|
pkey=paramiko.RSAKey.from_private_key(StringIO(payload["key"])),
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(
|
print(f'*** Failed to connect to {payload["host"]}:{payload["port"]}: {e}')
|
||||||
"*** Failed to connect to {}:{}: {}".format(
|
|
||||||
payload["host"], int(payload["port"]), e
|
|
||||||
)
|
|
||||||
)
|
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
verbose(
|
verbose(
|
||||||
"Now forwarding remote port {} to {}:{} ...".format(
|
f'Now forwarding remote port {payload["remote_port"]}'
|
||||||
int(payload["remote_port"]), local_server, local_server_port
|
f"to {local_server}:{local_server_port} ..."
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
thread = threading.Thread(
|
thread = threading.Thread(
|
||||||
|
Loading…
Reference in New Issue
Block a user