mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-11-29 20:45:11 +00:00
docs: apply simplified technical english across docs and docstrings.
This commit is contained in:
@@ -10,7 +10,7 @@ from unshackle.core.proxies.proxy import Proxy
|
||||
|
||||
class Basic(Proxy):
|
||||
def __init__(self, **countries: dict[str, Union[str, list[str]]]):
|
||||
"""Basic Proxy Service using Proxies specified in the config."""
|
||||
"""Basic proxy provider that uses the proxies given in the configuration file."""
|
||||
self.countries = {k.lower(): v for k, v in countries.items()}
|
||||
|
||||
def __repr__(self) -> str:
|
||||
|
||||
@@ -24,11 +24,11 @@ class ExpressVPN(Proxy):
|
||||
ExpressVPN HTTPS proxy provider.
|
||||
|
||||
Mirrors the ExpressVPN Android TV app: an OAuth 2.0 device authorization grant obtains
|
||||
API tokens (interactive on first run, silent via cached refresh token afterwards), a
|
||||
API tokens (interactive on first run, silent through a cached refresh token afterwards), a
|
||||
subscription receipt (SRT) resolves proxy-capable locations, and get_proxy() returns an
|
||||
authenticated HTTPS proxy URL (https://cat:<token>@server:443).
|
||||
|
||||
Query format (after the provider prefix, e.g. "expressvpn:ca"):
|
||||
Query format (after the proxy provider prefix, for example "expressvpn:ca"):
|
||||
ca random location in the country (smart connection)
|
||||
us-ny city
|
||||
us-ny-2 / usny2 pinned server by position
|
||||
@@ -56,13 +56,14 @@ class ExpressVPN(Proxy):
|
||||
enable: bool = False,
|
||||
):
|
||||
"""
|
||||
Proxy Service using ExpressVPN app proxy credentials.
|
||||
Proxy provider that uses ExpressVPN app proxy credentials.
|
||||
|
||||
region_map maps a country code to an optional city/server preset (e.g. "us": "ny-02")
|
||||
applied when the CLI query names only the country; empty values mean smart connection.
|
||||
server_map maps aliases to location slugs or concrete .expressprovider.com hosts.
|
||||
Tokens are optional: without them, cached tokens are used, else account_json is read.
|
||||
Set enable: true to run the one-time interactive device login when no session exists.
|
||||
region_map maps a country code to an optional city/server preset (for example "us":
|
||||
"ny-02") applied when the CLI query names only the country. Empty values mean a smart
|
||||
connection. server_map maps aliases to location slugs or concrete
|
||||
.expressprovider.com hosts. Tokens are optional: without them, unshackle uses the
|
||||
cached tokens, or else it reads account_json. Set enable: true to do the one-time
|
||||
interactive device login when no login session exists.
|
||||
"""
|
||||
if region_map is not None and not isinstance(region_map, dict):
|
||||
raise TypeError(f"Expected region_map to be a dict mapping aliases to locations, not '{region_map!r}'.")
|
||||
@@ -109,7 +110,7 @@ class ExpressVPN(Proxy):
|
||||
return "ExpressVPN HTTPS Proxy"
|
||||
|
||||
def has_silent_session(self) -> bool:
|
||||
"""Whether tokens can be obtained without the interactive device login."""
|
||||
"""Whether unshackle can get tokens without the interactive device login."""
|
||||
return bool(
|
||||
self.tokens
|
||||
or self.access_token
|
||||
@@ -194,7 +195,7 @@ class ExpressVPN(Proxy):
|
||||
return self.match_city(pool, city_query)
|
||||
|
||||
def match_city(self, locations: list[dict], city_query: str) -> Optional[dict]:
|
||||
"""Match a city query by abbreviation ("ny"), exact slug, slug prefix, then substring."""
|
||||
"""Find the city that matches the query by abbreviation ("ny"), exact slug, slug prefix, then substring."""
|
||||
city_query = city_query.strip().lower()
|
||||
abbrev, exact, prefix, substring = [], [], [], []
|
||||
for loc in locations:
|
||||
@@ -337,7 +338,7 @@ class ExpressVPN(Proxy):
|
||||
return response.json()
|
||||
|
||||
def device_login(self) -> Optional[dict]:
|
||||
"""One-time interactive bootstrap via the OAuth 2.0 device authorization grant (RFC 8628)."""
|
||||
"""One-time interactive bootstrap through the OAuth 2.0 device authorization grant (RFC 8628)."""
|
||||
response = self.request(
|
||||
"POST",
|
||||
f"{self.AUTH_BASE}/device/code",
|
||||
@@ -515,7 +516,7 @@ def jwt_expired(token: Optional[str]) -> bool:
|
||||
|
||||
|
||||
def write_private(path: Path, content: str) -> None:
|
||||
"""Write content to path created with owner-only (0600) permissions."""
|
||||
"""Write text to path. The new file has owner-only (0600) permissions."""
|
||||
if hasattr(os, "fchmod"):
|
||||
fd = os.open(str(path), os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o600)
|
||||
try:
|
||||
|
||||
@@ -37,7 +37,7 @@ def cleanup_all_gluetun_containers():
|
||||
|
||||
|
||||
def register_cleanup():
|
||||
"""Register cleanup handlers (only once)."""
|
||||
"""Add the cleanup handlers to atexit, one time only."""
|
||||
global cleanup_registered
|
||||
with cleanup_lock:
|
||||
if not cleanup_registered:
|
||||
@@ -49,7 +49,7 @@ def register_cleanup():
|
||||
|
||||
class Gluetun(Proxy):
|
||||
"""
|
||||
Dynamic Gluetun VPN-to-HTTP Proxy Provider with multi-provider support.
|
||||
Dynamic Gluetun VPN-to-HTTP proxy provider that can use more than one VPN provider.
|
||||
|
||||
Automatically manages Docker containers running Gluetun for WireGuard/OpenVPN VPN connections.
|
||||
Supports multiple VPN providers in a single configuration using query format: provider:region
|
||||
@@ -170,7 +170,7 @@ class Gluetun(Proxy):
|
||||
**kwargs,
|
||||
):
|
||||
"""
|
||||
Initialize Gluetun proxy provider with multi-provider support.
|
||||
Initialise the Gluetun proxy provider that can use more than one VPN provider.
|
||||
|
||||
Args:
|
||||
providers: Dict of VPN provider configurations
|
||||
@@ -187,7 +187,7 @@ class Gluetun(Proxy):
|
||||
container_prefix: Docker container name prefix (default: "unshackle-gluetun")
|
||||
auth_user: Optional HTTP proxy authentication username
|
||||
auth_password: Optional HTTP proxy authentication password
|
||||
verify_ip: Automatically verify IP and region after connection (default: True)
|
||||
verify_ip: Automatically make sure that the IP and region are correct after connection (default: True)
|
||||
"""
|
||||
if not binaries.Docker:
|
||||
raise RuntimeError(
|
||||
@@ -497,7 +497,7 @@ class Gluetun(Proxy):
|
||||
return port
|
||||
|
||||
def is_port_in_use(self, port: int) -> bool:
|
||||
"""Check if a port is in use on the system or by any Docker container."""
|
||||
"""Return True if the port is in use on the system or by any Docker container."""
|
||||
import socket
|
||||
|
||||
try:
|
||||
@@ -523,7 +523,7 @@ class Gluetun(Proxy):
|
||||
|
||||
def build_server_hostname(self, provider_name: str, country_code: str, server_num: str) -> str:
|
||||
"""
|
||||
Build a server hostname for specific server selection.
|
||||
Assemble a server hostname for specific server selection.
|
||||
|
||||
Args:
|
||||
provider_name: VPN provider name (e.g., "nordvpn")
|
||||
@@ -550,9 +550,9 @@ class Gluetun(Proxy):
|
||||
|
||||
def ensure_image_available(self, image: str = "qmcgaw/gluetun:latest") -> bool:
|
||||
"""
|
||||
Ensure the Gluetun Docker image is available locally.
|
||||
Make sure that the Gluetun Docker image is available locally.
|
||||
|
||||
If the image is not present, it will be pulled. This prevents
|
||||
If the image is not present, unshackle runs `docker pull` to get it. This prevents
|
||||
the container creation from timing out during the first run.
|
||||
|
||||
Args:
|
||||
@@ -609,11 +609,11 @@ class Gluetun(Proxy):
|
||||
hostname: Optional[str] = None,
|
||||
):
|
||||
"""
|
||||
Create and start a Gluetun Docker container.
|
||||
Make and start a Gluetun Docker container.
|
||||
|
||||
Credentials go into a temporary env-file with restricted permissions and are passed with --env-file,
|
||||
never as "-e KEY=VALUE" arguments, so they stay out of process listings. The file is overwritten and
|
||||
deleted once "docker run" returns.
|
||||
Credentials go into a temporary env-file with restricted permissions. unshackle gives that file
|
||||
to Docker with --env-file, never as "-e KEY=VALUE" arguments, so the credentials stay out of
|
||||
process listings. unshackle overwrites and deletes the file once "docker run" returns.
|
||||
"""
|
||||
start_time = time.time()
|
||||
|
||||
@@ -831,7 +831,7 @@ class Gluetun(Proxy):
|
||||
pass
|
||||
|
||||
def is_container_running(self, container_name: str) -> bool:
|
||||
"""Check if a Docker container is running."""
|
||||
"""Return True if the Docker container operates."""
|
||||
try:
|
||||
result = subprocess.run(
|
||||
[
|
||||
@@ -858,13 +858,13 @@ class Gluetun(Proxy):
|
||||
|
||||
def get_existing_container_info(self, container_name: str) -> Optional[dict]:
|
||||
"""
|
||||
Check if a container exists in Docker and get its info.
|
||||
Find whether a container exists in Docker, and get its info.
|
||||
|
||||
This handles multiple Unshackle sessions - if another session already
|
||||
created the container, we'll reuse it instead of trying to create a duplicate.
|
||||
This lets several copies of unshackle share one container - if another copy
|
||||
already made the container, unshackle uses it again instead of a duplicate.
|
||||
|
||||
Args:
|
||||
container_name: Name of the container to check
|
||||
container_name: Name of the container to examine
|
||||
|
||||
Returns:
|
||||
Dict with container info if exists and running, None otherwise
|
||||
@@ -1082,11 +1082,11 @@ class Gluetun(Proxy):
|
||||
|
||||
def verify_container(self, query_key: str, max_retries: int = 3):
|
||||
"""
|
||||
Verify container's VPN IP and region using ipinfo.io lookup.
|
||||
Make sure that the container's VPN IP and region are correct with an ipinfo.io lookup.
|
||||
|
||||
Uses the shared get_ip_info function with a session configured to use
|
||||
Uses the shared get_ip_info function with an HTTP session configured to use
|
||||
the Gluetun proxy. Retries with exponential backoff if the network
|
||||
isn't ready immediately after the VPN connects.
|
||||
is not ready immediately after the VPN connects.
|
||||
|
||||
Args:
|
||||
query_key: The container query key (provider:region)
|
||||
@@ -1234,13 +1234,13 @@ class Gluetun(Proxy):
|
||||
Remove a stopped container with the given name if it exists.
|
||||
|
||||
This prevents "container name already in use" errors when a previous
|
||||
container wasn't properly cleaned up.
|
||||
container was not properly cleaned up.
|
||||
|
||||
Args:
|
||||
container_name: Name of the container to check and remove
|
||||
container_name: Name of the container to examine and remove
|
||||
|
||||
Returns:
|
||||
True if a container was removed, False otherwise
|
||||
True if unshackle removed a container, False otherwise
|
||||
"""
|
||||
try:
|
||||
# Check if container exists (running or stopped)
|
||||
@@ -1312,7 +1312,7 @@ class Gluetun(Proxy):
|
||||
pass
|
||||
|
||||
def build_proxy_uri(self, port: int) -> str:
|
||||
"""Build HTTP proxy URI."""
|
||||
"""Assemble the HTTP proxy URI."""
|
||||
if self.auth_user and self.auth_password:
|
||||
return f"http://{self.auth_user}:{self.auth_password}@localhost:{port}"
|
||||
return f"http://localhost:{port}"
|
||||
|
||||
@@ -10,7 +10,7 @@ from unshackle.core.proxies.proxy import Proxy
|
||||
class Hola(Proxy):
|
||||
def __init__(self):
|
||||
"""
|
||||
Proxy Service using Hola's direct connections via the hola-proxy project.
|
||||
Proxy provider that uses Hola's direct connections through the hola-proxy project.
|
||||
https://github.com/Snawoot/hola-proxy
|
||||
"""
|
||||
self.binary = binaries.HolaProxy
|
||||
|
||||
@@ -11,9 +11,9 @@ from unshackle.core.proxies.proxy import Proxy
|
||||
class NordVPN(Proxy):
|
||||
def __init__(self, username: str, password: str, server_map: Optional[dict[str, int]] = None):
|
||||
"""
|
||||
Proxy Service using NordVPN Service Credentials.
|
||||
Proxy provider that uses NordVPN Service Credentials.
|
||||
|
||||
A username and password must be provided. These are Service Credentials, not your Login Credentials.
|
||||
You must give a username and password. These are Service Credentials, not your Login Credentials.
|
||||
The Service Credentials can be found here: https://my.nordaccount.com/dashboard/nordvpn/
|
||||
"""
|
||||
if not username:
|
||||
@@ -45,7 +45,7 @@ class NordVPN(Proxy):
|
||||
"""
|
||||
Get an HTTP(SSL) proxy URI for a NordVPN server.
|
||||
|
||||
HTTP proxies under port 80 were disabled on the 15th of Feb, 2021:
|
||||
NordVPN disabled HTTP proxies under port 80 on the 15th of Feb, 2021:
|
||||
https://nordvpn.com/blog/removing-http-proxies
|
||||
|
||||
Supports:
|
||||
@@ -112,7 +112,7 @@ class NordVPN(Proxy):
|
||||
return f"https://{self.username}:{self.password}@{hostname}:89"
|
||||
|
||||
def get_country(self, by_id: Optional[int] = None, by_code: Optional[str] = None) -> Optional[dict]:
|
||||
"""Search for a Country and it's metadata."""
|
||||
"""Find a Country and its metadata."""
|
||||
if all(x is None for x in (by_id, by_code)):
|
||||
raise ValueError("At least one search query must be made.")
|
||||
|
||||
|
||||
@@ -23,12 +23,12 @@ class ProtonVPN(Proxy):
|
||||
"""
|
||||
Proton VPN HTTPS proxy provider.
|
||||
|
||||
Authenticates via TV login (a self-sustaining session cached at <cache>/vpn/protonvpn.json, the
|
||||
Authenticates through TV login (a self-sustaining login session cached at <cache>/vpn/protonvpn.json, the
|
||||
only refreshable kind) or an exported account.proton.me cookie session (AUTH-<UID>, access only,
|
||||
re-export on expiry). Resolves a server by country/city, mints short-lived proxy credentials, and
|
||||
returns an authenticated HTTPS proxy URL (https://user:pass@server:4443).
|
||||
|
||||
Query format (after the provider prefix, e.g. "protonvpn:us"):
|
||||
Query format (after the proxy provider prefix, for example "protonvpn:us"):
|
||||
us random server in the country (paid preferred over free)
|
||||
us12 Proton server #12 (the number shown in the connection log)
|
||||
us:ny city, NordVPN-style
|
||||
@@ -211,7 +211,7 @@ class ProtonVPN(Proxy):
|
||||
return None
|
||||
|
||||
def api(self, method: str, path: str) -> Optional[requests.Response]:
|
||||
"""Call the Proton API, refreshing the session once on a 401."""
|
||||
"""Call the Proton API, and refresh the login session one time on a 401."""
|
||||
if not self.access_token:
|
||||
self.load_session()
|
||||
if not self.access_token:
|
||||
@@ -305,7 +305,10 @@ class ProtonVPN(Proxy):
|
||||
self.tv_login()
|
||||
|
||||
def tv_login(self) -> bool:
|
||||
"""Fork a TV session and have the user approve the code at proton.me/tv; tokens refresh like the cookie path."""
|
||||
"""Fork a TV login session and let the user approve the code at proton.me/tv.
|
||||
|
||||
Tokens refresh like the cookie path.
|
||||
"""
|
||||
headers = {
|
||||
"x-pm-appversion": self.TV_APP_VERSION,
|
||||
"x-pm-locale": "en",
|
||||
@@ -437,7 +440,7 @@ def server_no(server: dict) -> Optional[int]:
|
||||
|
||||
|
||||
def write_private(path: Path, content: str) -> None:
|
||||
"""Write content to path created with owner-only (0600) permissions."""
|
||||
"""Write text to path. The new file has owner-only (0600) permissions."""
|
||||
if hasattr(os, "fchmod"):
|
||||
fd = os.open(str(path), os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o600)
|
||||
try:
|
||||
|
||||
@@ -21,10 +21,10 @@ class Proxy:
|
||||
@abstractmethod
|
||||
def get_proxy(self, query: str) -> Optional[str]:
|
||||
"""
|
||||
Get a Proxy URI from the Proxy Service.
|
||||
Get a proxy URI from the proxy provider.
|
||||
|
||||
Only return None if the query was accepted, but no proxy could be returned.
|
||||
Otherwise, please use exceptions to denote any errors with the call or query.
|
||||
Return None only when this method accepts the query but can give no proxy.
|
||||
Otherwise, use exceptions to denote any errors with the call or query.
|
||||
|
||||
The returned Proxy URI must be a string supported by Python-Requests:
|
||||
'{scheme}://[{user}:{pass}@]{host}:{port}'
|
||||
|
||||
@@ -13,7 +13,7 @@ log = logging.getLogger("proxies")
|
||||
|
||||
|
||||
def initialize_proxy_providers() -> List[Any]:
|
||||
"""Initialize and return available proxy providers from config."""
|
||||
"""Initialise and return available proxy providers from config."""
|
||||
proxy_providers: list = []
|
||||
try:
|
||||
from unshackle.core import binaries
|
||||
@@ -56,7 +56,7 @@ def initialize_proxy_providers() -> List[Any]:
|
||||
|
||||
|
||||
def resolve_proxy(proxy: str, proxy_providers: List[Any]) -> Optional[str]:
|
||||
"""Resolve a proxy parameter to an actual proxy URI.
|
||||
"""Change a proxy parameter to a real proxy URI.
|
||||
|
||||
Accepts:
|
||||
- Direct URI: "https://...", "socks5://..."
|
||||
|
||||
@@ -11,9 +11,9 @@ from unshackle.core.proxies.proxy import Proxy
|
||||
class SurfsharkVPN(Proxy):
|
||||
def __init__(self, username: str, password: str, server_map: Optional[dict[str, int]] = None):
|
||||
"""
|
||||
Proxy Service using SurfsharkVPN Service Credentials.
|
||||
Proxy provider that uses SurfsharkVPN Service Credentials.
|
||||
|
||||
A username and password must be provided. These are Service Credentials, not your Login Credentials.
|
||||
You must give a username and password. These are Service Credentials, not your Login Credentials.
|
||||
The Service Credentials can be found here: https://my.surfshark.com/vpn/manual-setup/main/openvpn
|
||||
"""
|
||||
if not username:
|
||||
@@ -94,7 +94,7 @@ class SurfsharkVPN(Proxy):
|
||||
return f"https://{self.username}:{self.password}@{hostname}:443"
|
||||
|
||||
def get_country(self, by_id: Optional[int] = None, by_code: Optional[str] = None) -> Optional[dict]:
|
||||
"""Search for a Country and it's metadata."""
|
||||
"""Find a Country and its metadata."""
|
||||
if all(x is None for x in (by_id, by_code)):
|
||||
raise ValueError("At least one search query must be made.")
|
||||
|
||||
|
||||
@@ -11,13 +11,13 @@ from unshackle.core.proxies.proxy import Proxy
|
||||
class WindscribeVPN(Proxy):
|
||||
def __init__(self, username: str, password: str, server_map: Optional[dict[str, str]] = None):
|
||||
"""
|
||||
Proxy Service using WindscribeVPN Service Credentials.
|
||||
Proxy provider that uses WindscribeVPN Service Credentials.
|
||||
|
||||
A username and password must be provided. These are Service Credentials, not your Login Credentials.
|
||||
You must give a username and password. These are Service Credentials, not your Login Credentials.
|
||||
The Service Credentials can be found here: https://windscribe.com/getconfig/openvpn
|
||||
|
||||
server_map pins a query to a hostname. Its keys are either a country code ("ca") or a country
|
||||
code with a city ("ca:toronto"), and a pinned hostname is used before any server lookup.
|
||||
code with a city ("ca:toronto"), and unshackle uses a pinned hostname before any server lookup.
|
||||
"""
|
||||
if not username:
|
||||
raise ValueError("No Username was provided to the WindscribeVPN Proxy Service.")
|
||||
@@ -130,7 +130,7 @@ class WindscribeVPN(Proxy):
|
||||
A random hostname from matching servers, or None if the country has no servers.
|
||||
|
||||
Raises:
|
||||
ValueError: If a city was given and no server in that country matches it.
|
||||
ValueError: If you give a city and no server in that country matches it.
|
||||
"""
|
||||
hostnames = []
|
||||
|
||||
|
||||
Reference in New Issue
Block a user