speasy.core.any_files module
- class speasy.core.any_files.AnyFile(url, file_impl: IOBase, status=200)[source]
Bases:
IOBase
- close()[source]
Flush and close the IO object.
This method has no effect if the file is already closed.
- property ok
- readline(*args, **kwargs)[source]
Read and return a line from the stream.
If size is specified, at most size bytes will be read.
The line terminator is always b’n’ for binary files; for text files, the newlines argument to open can be used to select the line terminator(s) recognized.
- seek(*args, **kwargs)[source]
Change the stream position to the given byte offset.
- offset
The stream position, relative to ‘whence’.
- whence
The relative position to seek from.
The offset is interpreted relative to the position indicated by whence. Values for whence are:
os.SEEK_SET or 0 – start of stream (the default); offset should be zero or positive
os.SEEK_CUR or 1 – current stream position; offset may be negative
os.SEEK_END or 2 – end of stream; offset is usually negative
Return the new absolute position.
- property status_code
- property url
- class speasy.core.any_files.PendingRequest[source]
Bases:
object
- property elapsed_time
- property pid
- 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, disable_cache=False, force_refresh=False) 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.
- disable_cachebool
Determines whether the cache is disabled for remote file listings.
- force_refreshbool
Forces a refresh of the cache for remote file listings.
- Returns:
- List[str]
A list of files that match the specified regex pattern, either from a remote source or a local directory.