File: _connect.py

package info (click to toggle)
python-socks 2.7.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 544 kB
  • sloc: python: 5,195; sh: 8; makefile: 3
file content (19 lines) | stat: -rw-r--r-- 420 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import socket
from typing import Optional, Tuple
from ._stream import SyncSocketStream


def connect_tcp(
    host: str,
    port: int,
    timeout: Optional[float] = None,
    local_addr: Optional[Tuple[str, int]] = None,
) -> SyncSocketStream:
    address = (host, port)
    sock = socket.create_connection(
        address,
        timeout,
        source_address=local_addr,
    )

    return SyncSocketStream(sock)