speasy.core.any_files module

class speasy.core.any_files.AnyFile(url, file_impl: IOBase, status=200)[source]

Bases: IOBase

property ok
read(*args, **kwargs)[source]
seek(*args, **kwargs)[source]

Change stream position.

Change the stream position to the given byte offset. The offset is interpreted relative to the position indicated by whence. Values for whence are:

  • 0 – start of stream (the default); offset should be zero or positive

  • 1 – current stream position; offset may be negative

  • 2 – end of stream; offset is usually negative

Return the new absolute position.

property status_code
property url
speasy.core.any_files.any_loc_open(url, timeout: int = 60, headers: dict | None = None, mode='rb', cache_remote_files=False) AnyFile[source]

Opens a file at the specified URL, whether local or remote.

Parameters:
urlstr

The file URL, formatted as either a local path or a standard URL (https://en.wikipedia.org/wiki/URL).

timeoutint

The timeout duration in seconds for remote files (default: 60 seconds).

headersOptional[dict]

Optional HTTP headers to include when requesting remote files.

modestr

The file open mode. Only ‘r’ or ‘rb’ are supported.

cache_remote_filesbool

Determines whether remote files are stored in the Speasy cache for future requests. Files are only downloaded if they have changed (based on the ‘last-modified’ header field).

Returns:
AnyFile

The opened file object.

speasy.core.any_files.list_files(url: str, file_regex: Pattern | str) List[str][source]

Lists files that match the specified regex pattern either from a web page generated by Apache mod_dir or equivalent, or from a local directory.

Parameters:
urlstr

The URL or local path to scan.

file_regexre.Pattern or str

The regular expression pattern used to filter files.

Returns:
List[str]

A list of files that match the specified regex pattern, either from a remote source or a local directory.