Source code for soulfire.download_connect

# Generated from soulfire/download.proto. DO NOT EDIT.
# Generated by protoc-gen-connectrpc-py v0.13.0 with parameter "protobuf=google".
# ruff: noqa: PGH004
# ruff: noqa
# pyright: reportDeprecated=false
# ty: ignore[unused-ignore-comment]
# ty: ignore[deprecated, unused-ignore-comment]
# fmt: off

from __future__ import annotations

from typing import Protocol, TYPE_CHECKING

from connectrpc.client import ConnectClient, ConnectClientSync
from connectrpc.code import Code
from connectrpc.compat import google_protobuf_binary_codec, google_protobuf_codecs
from connectrpc.compression.gzip import GzipCompression
from connectrpc.errors import ConnectError
from connectrpc.method import IdempotencyLevel, MethodInfo, StreamType
from connectrpc.protocol import ProtocolType
from connectrpc.server import ConnectASGIApplication, ConnectWSGIApplication, DEFAULT_READ_MAX_BYTES, Endpoint, EndpointSync
from pyqwest import Client, SyncClient

from .download_pb2 import DownloadRequest, DownloadResponse

if TYPE_CHECKING:
    from collections.abc import AsyncGenerator, Iterable, Mapping

    from connectrpc.codec import Codec
    from connectrpc.compression import Compression
    from connectrpc.interceptor import Interceptor, InterceptorSync
    from connectrpc.request import Headers, RequestContext



_DEFAULT_CODECS = google_protobuf_codecs()
_PROTO_BINARY_CODEC = google_protobuf_binary_codec()
_GZIP_COMPRESSION = GzipCompression()

[docs] class DownloadService(Protocol): """ Service for downloading content from remote URLs through the SoulFire server. This service acts as a proxy, allowing clients to fetch remote resources using the server's network connection and optionally through a configured proxy. Use cases include: - Downloading resources that may be blocked from the client's network - Fetching content through a specific proxy for anonymity or geo-unlocking - Centralizing external API calls through the server The service uses a Reactor Netty HTTP client with: - 5-second response timeout - Automatic compression support - Default Accept, Accept-Language, and User-Agent headers Authorization: - Requires a valid JWT token - Caller must have DOWNLOAD_URL permission for the specified instance Error handling: - Returns gRPC INTERNAL status on network errors, timeouts, or server failures - The error description contains details about the failure """
[docs] async def download(self, request: DownloadRequest, ctx: RequestContext[DownloadRequest, DownloadResponse], /) -> DownloadResponse: """ Downloads content from the specified URI and returns the response. Makes an HTTP GET request to the URI specified in the request, optionally routing through a proxy. Custom headers can be provided to customize the request. Parameters: request - Contains the target URI, instance ID for permissions, optional headers, and optional proxy configuration Returns: The downloaded content as bytes, along with response headers and HTTP status code Errors: PERMISSION_DENIED - Caller lacks DOWNLOAD_URL permission for the instance INTERNAL - Network error, connection timeout, invalid URI, or other server error """ raise ConnectError(Code.UNIMPLEMENTED, 'Not implemented')
[docs] class DownloadServiceASGIApplication(ConnectASGIApplication[DownloadService]): def __init__( self, service: DownloadService | AsyncGenerator[DownloadService], *, interceptors: Iterable[Interceptor] = (), read_max_bytes: int | None = DEFAULT_READ_MAX_BYTES, compressions: Iterable[Compression] | None = None, codecs: Iterable[Codec] | None = _DEFAULT_CODECS, ) -> None: super().__init__( service=service, endpoints=lambda svc: { "/soulfire.v1.DownloadService/Download": Endpoint.unary( method=MethodInfo( name="Download", service_name="soulfire.v1.DownloadService", input=DownloadRequest, output=DownloadResponse, idempotency_level=IdempotencyLevel.UNKNOWN, stream_type=StreamType.UNARY, ), function=svc.download, ), }, interceptors=interceptors, read_max_bytes=read_max_bytes, compressions=compressions, codecs=codecs, ) @property def path(self) -> str: """Returns the URL path to mount the application to when serving multiple applications.""" return "/soulfire.v1.DownloadService"
[docs] class DownloadServiceClient(ConnectClient): """ Service for downloading content from remote URLs through the SoulFire server. This service acts as a proxy, allowing clients to fetch remote resources using the server's network connection and optionally through a configured proxy. Use cases include: - Downloading resources that may be blocked from the client's network - Fetching content through a specific proxy for anonymity or geo-unlocking - Centralizing external API calls through the server The service uses a Reactor Netty HTTP client with: - 5-second response timeout - Automatic compression support - Default Accept, Accept-Language, and User-Agent headers Authorization: - Requires a valid JWT token - Caller must have DOWNLOAD_URL permission for the specified instance Error handling: - Returns gRPC INTERNAL status on network errors, timeouts, or server failures - The error description contains details about the failure """ def __init__( self, address: str, *, codec: Codec | None = _PROTO_BINARY_CODEC, protocol: ProtocolType = ProtocolType.CONNECT, accept_compression: Iterable[Compression] | None = None, send_compression: Compression | None = _GZIP_COMPRESSION, timeout_ms: int | None = None, read_max_bytes: int | None = None, interceptors: Iterable[Interceptor] = (), http_client: Client | None = None, ) -> None: super().__init__( address=address, codec=codec, protocol=protocol, accept_compression=accept_compression, send_compression=send_compression, timeout_ms=timeout_ms, read_max_bytes=read_max_bytes, interceptors=interceptors, http_client=http_client, )
[docs] async def download( self, request: DownloadRequest, *, headers: Headers | Mapping[str, str] | None = None, timeout_ms: int | None = None, ) -> DownloadResponse: """ Downloads content from the specified URI and returns the response. Makes an HTTP GET request to the URI specified in the request, optionally routing through a proxy. Custom headers can be provided to customize the request. Parameters: request - Contains the target URI, instance ID for permissions, optional headers, and optional proxy configuration Returns: The downloaded content as bytes, along with response headers and HTTP status code Errors: PERMISSION_DENIED - Caller lacks DOWNLOAD_URL permission for the instance INTERNAL - Network error, connection timeout, invalid URI, or other server error """ return await self.execute_unary( request=request, method=MethodInfo( name="Download", service_name="soulfire.v1.DownloadService", input=DownloadRequest, output=DownloadResponse, idempotency_level=IdempotencyLevel.UNKNOWN, stream_type=StreamType.UNARY, ), headers=headers, timeout_ms=timeout_ms, )
[docs] class DownloadServiceSync(Protocol): """ Service for downloading content from remote URLs through the SoulFire server. This service acts as a proxy, allowing clients to fetch remote resources using the server's network connection and optionally through a configured proxy. Use cases include: - Downloading resources that may be blocked from the client's network - Fetching content through a specific proxy for anonymity or geo-unlocking - Centralizing external API calls through the server The service uses a Reactor Netty HTTP client with: - 5-second response timeout - Automatic compression support - Default Accept, Accept-Language, and User-Agent headers Authorization: - Requires a valid JWT token - Caller must have DOWNLOAD_URL permission for the specified instance Error handling: - Returns gRPC INTERNAL status on network errors, timeouts, or server failures - The error description contains details about the failure """
[docs] def download(self, request: DownloadRequest, ctx: RequestContext[DownloadRequest, DownloadResponse], /) -> DownloadResponse: """ Downloads content from the specified URI and returns the response. Makes an HTTP GET request to the URI specified in the request, optionally routing through a proxy. Custom headers can be provided to customize the request. Parameters: request - Contains the target URI, instance ID for permissions, optional headers, and optional proxy configuration Returns: The downloaded content as bytes, along with response headers and HTTP status code Errors: PERMISSION_DENIED - Caller lacks DOWNLOAD_URL permission for the instance INTERNAL - Network error, connection timeout, invalid URI, or other server error """ raise ConnectError(Code.UNIMPLEMENTED, 'Not implemented')
[docs] class DownloadServiceWSGIApplication(ConnectWSGIApplication): def __init__( self, service: DownloadServiceSync, interceptors: Iterable[InterceptorSync] = (), read_max_bytes: int | None = DEFAULT_READ_MAX_BYTES, compressions: Iterable[Compression] | None = None, codecs: Iterable[Codec] | None = _DEFAULT_CODECS, ) -> None: super().__init__( endpoints={ "/soulfire.v1.DownloadService/Download": EndpointSync.unary( method=MethodInfo( name="Download", service_name="soulfire.v1.DownloadService", input=DownloadRequest, output=DownloadResponse, idempotency_level=IdempotencyLevel.UNKNOWN, stream_type=StreamType.UNARY, ), function=service.download, ), }, interceptors=interceptors, read_max_bytes=read_max_bytes, compressions=compressions, codecs=codecs, ) @property def path(self) -> str: """Returns the URL path to mount the application to when serving multiple applications.""" return "/soulfire.v1.DownloadService"
[docs] class DownloadServiceClientSync(ConnectClientSync): """ Service for downloading content from remote URLs through the SoulFire server. This service acts as a proxy, allowing clients to fetch remote resources using the server's network connection and optionally through a configured proxy. Use cases include: - Downloading resources that may be blocked from the client's network - Fetching content through a specific proxy for anonymity or geo-unlocking - Centralizing external API calls through the server The service uses a Reactor Netty HTTP client with: - 5-second response timeout - Automatic compression support - Default Accept, Accept-Language, and User-Agent headers Authorization: - Requires a valid JWT token - Caller must have DOWNLOAD_URL permission for the specified instance Error handling: - Returns gRPC INTERNAL status on network errors, timeouts, or server failures - The error description contains details about the failure """ def __init__( self, address: str, *, codec: Codec | None = _PROTO_BINARY_CODEC, protocol: ProtocolType = ProtocolType.CONNECT, accept_compression: Iterable[Compression] | None = None, send_compression: Compression | None = _GZIP_COMPRESSION, timeout_ms: int | None = None, read_max_bytes: int | None = None, interceptors: Iterable[InterceptorSync] = (), http_client: SyncClient | None = None, ) -> None: super().__init__( address=address, codec=codec, protocol=protocol, accept_compression=accept_compression, send_compression=send_compression, timeout_ms=timeout_ms, read_max_bytes=read_max_bytes, interceptors=interceptors, http_client=http_client, )
[docs] def download( self, request: DownloadRequest, *, headers: Headers | Mapping[str, str] | None = None, timeout_ms: int | None = None, ) -> DownloadResponse: """ Downloads content from the specified URI and returns the response. Makes an HTTP GET request to the URI specified in the request, optionally routing through a proxy. Custom headers can be provided to customize the request. Parameters: request - Contains the target URI, instance ID for permissions, optional headers, and optional proxy configuration Returns: The downloaded content as bytes, along with response headers and HTTP status code Errors: PERMISSION_DENIED - Caller lacks DOWNLOAD_URL permission for the instance INTERNAL - Network error, connection timeout, invalid URI, or other server error """ return self.execute_unary( request=request, method=MethodInfo( name="Download", service_name="soulfire.v1.DownloadService", input=DownloadRequest, output=DownloadResponse, idempotency_level=IdempotencyLevel.UNKNOWN, stream_type=StreamType.UNARY, ), headers=headers, timeout_ms=timeout_ms, )