/** * Python urllib module for TypeScript * * Provides URL handling and parsing utilities. * * @see {@link https://docs.python.org/3/library/urllib.html | Python urllib documentation} * @module */ /** * Parsed URL result structure. */ interface ParseResult { /** URL scheme (e.g., "http", "https") */ scheme: string; /** Network location (e.g., "example.com:8080") */ netloc: string; /** URL path */ path: string; /** Query parameters (without leading ?) */ params: string; /** Query string (without leading ?) */ query: string; /** Fragment (without leading #) */ fragment: string; /** Username if present */ username: string | null; /** Password if present */ password: string | null; /** Hostname */ hostname: string | null; /** Port number */ port: number | null; } /** * Parse a URL into its components. * * @param urlstring - The URL to parse * @param scheme - Default scheme if not present in URL * @param allowFragments - Whether to parse fragments (default: true) * @returns Parsed URL components * * @example * ```typescript * const result = urlparse("https://user:pass@example.com:8080/path?query=1#frag") * console.log(result.scheme) // "https" * console.log(result.hostname) // "example.com" * console.log(result.port) // 8080 * ``` */ declare function urlparse(urlstring: string, scheme?: string, allowFragments?: boolean): ParseResult; /** * Combine URL components back into a URL string. * * @param components - URL components tuple [scheme, netloc, path, params, query, fragment] * @returns Combined URL string */ declare function urlunparse(components: [string, string, string, string, string, string] | ParseResult): string; /** * Join a base URL with another URL. * * @param base - Base URL * @param url - URL to join (can be relative) * @param allowFragments - Whether to allow fragments * @returns Combined URL */ declare function urljoin(base: string, url: string, allowFragments?: boolean): string; /** * Encode a dictionary or sequence of tuples as a query string. * * @param query - Query parameters as object or array of tuples * @param doseq - If true, treat sequence values as separate parameters * @returns URL-encoded query string */ declare function urlencode(query: Record | [string, string][], doseq?: boolean): string; /** * Parse a query string into a dictionary. * * @param qs - Query string to parse * @param keepBlankValues - Whether to keep blank values * @returns Object mapping keys to arrays of values */ declare function parseQs(qs: string, keepBlankValues?: boolean): Record; /** * Parse a query string into a dictionary (single values). * * @param qs - Query string to parse * @param keepBlankValues - Whether to keep blank values * @returns Object mapping keys to single values */ declare function parseQsl(qs: string, keepBlankValues?: boolean): [string, string][]; /** * Percent-encode a string for use in a URL. * * @param s - String to encode * @param safe - Characters that should not be encoded (default: empty) * @returns Percent-encoded string */ declare function quote(s: string, safe?: string): string; /** * Like quote() but also encodes forward slashes. * * @param s - String to encode * @param safe - Characters that should not be encoded * @returns Percent-encoded string */ declare function quotePlus(s: string, safe?: string): string; /** * Decode a percent-encoded string. * * @param s - String to decode * @returns Decoded string */ declare function unquote(s: string): string; /** * Like unquote() but also decodes plus signs as spaces. * * @param s - String to decode * @returns Decoded string */ declare function unquotePlus(s: string): string; /** * Split a URL after the scheme into [scheme, rest]. * * @param url - URL to split * @returns Tuple of [scheme, rest] */ declare function splittype(url: string): [string, string]; /** * Split a URL after the host into [host, rest]. * * @param url - URL to split * @returns Tuple of [host, rest] */ declare function splithost(url: string): [string | null, string]; /** * Split a host into [user, host]. * * @param host - Host string (may include user:pass@) * @returns Tuple of [user, host] */ declare function splituser(host: string): [string | null, string]; /** * Split a user:pass into [user, password]. * * @param user - User string (may include :pass) * @returns Tuple of [user, password] */ declare function splitpasswd(user: string): [string, string | null]; /** * Split a host:port into [host, port]. * * @param host - Host string (may include :port) * @returns Tuple of [host, port] */ declare function splitport(host: string): [string, string | null]; /** * Namespace object for parse functions (urllib.parse compatibility). */ declare const parse: { urlparse: typeof urlparse; urlunparse: typeof urlunparse; urljoin: typeof urljoin; urlencode: typeof urlencode; parseQs: typeof parseQs; parseQsl: typeof parseQsl; quote: typeof quote; quotePlus: typeof quotePlus; unquote: typeof unquote; unquotePlus: typeof unquotePlus; splittype: typeof splittype; splithost: typeof splithost; splituser: typeof splituser; splitpasswd: typeof splitpasswd; splitport: typeof splitport; }; type urllibModule_ParseResult = ParseResult; declare const urllibModule_parse: typeof parse; declare const urllibModule_parseQs: typeof parseQs; declare const urllibModule_parseQsl: typeof parseQsl; declare const urllibModule_quote: typeof quote; declare const urllibModule_quotePlus: typeof quotePlus; declare const urllibModule_splithost: typeof splithost; declare const urllibModule_splitpasswd: typeof splitpasswd; declare const urllibModule_splitport: typeof splitport; declare const urllibModule_splittype: typeof splittype; declare const urllibModule_splituser: typeof splituser; declare const urllibModule_unquote: typeof unquote; declare const urllibModule_unquotePlus: typeof unquotePlus; declare const urllibModule_urlencode: typeof urlencode; declare const urllibModule_urljoin: typeof urljoin; declare const urllibModule_urlparse: typeof urlparse; declare const urllibModule_urlunparse: typeof urlunparse; declare namespace urllibModule { export { type urllibModule_ParseResult as ParseResult, urllibModule_parse as parse, urllibModule_parseQs as parseQs, urllibModule_parseQsl as parseQsl, urllibModule_quote as quote, urllibModule_quotePlus as quotePlus, urllibModule_splithost as splithost, urllibModule_splitpasswd as splitpasswd, urllibModule_splitport as splitport, urllibModule_splittype as splittype, urllibModule_splituser as splituser, urllibModule_unquote as unquote, urllibModule_unquotePlus as unquotePlus, urllibModule_urlencode as urlencode, urllibModule_urljoin as urljoin, urllibModule_urlparse as urlparse, urllibModule_urlunparse as urlunparse }; } export { type ParseResult as P, parseQs as a, parseQsl as b, quotePlus as c, splitpasswd as d, splitport as e, splittype as f, splituser as g, unquote as h, unquotePlus as i, urlencode as j, urljoin as k, urlparse as l, urlunparse as m, parse as p, quote as q, splithost as s, urllibModule as u };