UserContentFilterStore

Added in version 2.24.

class UserContentFilterStore(**properties: Any)

Superclasses: Object

Handles storage of user content filters on disk.

The WebKitUserContentFilterStore provides the means to import and save JSON rule sets, which can be loaded later in an efficient manner. Once filters are stored, the UserContentFilter objects which represent them can be added to a UserContentManager with add_filter().

JSON rule sets are imported using save() and stored on disk in an implementation defined format. The contents of a filter store must be managed using the UserContentFilterStore: a list of all the stored filters can be obtained with fetch_identifiers(), load() can be used to retrieve a previously saved filter, and removed from the store with remove().

Constructors

class UserContentFilterStore
classmethod new(storage_path: str) UserContentFilterStore

Create a new UserContentFilterStore to manipulate filters stored at storage_path.

The path must point to a local filesystem, and will be created if needed.

Added in version 2.24.

Parameters:

storage_path – path where data for filters will be stored on disk

Methods

class UserContentFilterStore
fetch_identifiers(cancellable: Cancellable | None = None, callback: Callable[[...], None] | None = None, *user_data: Any) None

Asynchronously retrieve a list of the identifiers for all the stored filters.

When the operation is finished, callback will be invoked, which then can use fetch_identifiers_finish() to obtain the list of filter identifiers.

Added in version 2.24.

Parameters:
  • cancellable – a Cancellable or None to ignore

  • callback – a AsyncReadyCallback to call when the removal is completed

  • user_data – the data to pass to the callback function

fetch_identifiers_finish(result: AsyncResult) list[str]

Finishes an asynchronous fetch of the list of stored filters.

Finishes an asynchronous fetch of the list of identifiers for the stored filters previously started with fetch_identifiers().

Added in version 2.24.

Parameters:

result – a AsyncResult

get_path() str

Gets the storage path for user content filters.

Added in version 2.24.

load(identifier: str, cancellable: Cancellable | None = None, callback: Callable[[...], None] | None = None, *user_data: Any) None

Asynchronously load a content filter given its identifier.

The filter must have been previously stored using save().

When the operation is finished, callback will be invoked, which then can use load_finish() to obtain the resulting filter.

Added in version 2.24.

Parameters:
  • identifier – a filter identifier

  • cancellable – a Cancellable or None to ignore

  • callback – a AsyncReadyCallback to call when the load is completed

  • user_data – the data to pass to the callback function

load_finish(result: AsyncResult) UserContentFilter

Finishes an asynchronous filter load previously started with load().

Added in version 2.24.

Parameters:

result – a AsyncResult

remove(identifier: str, cancellable: Cancellable | None = None, callback: Callable[[...], None] | None = None, *user_data: Any) None

Asynchronously remove a content filter given its identifier.

When the operation is finished, callback will be invoked, which then can use remove_finish() to check whether the removal was successful.

Added in version 2.24.

Parameters:
  • identifier – a filter identifier

  • cancellable – a Cancellable or None to ignore

  • callback – a AsyncReadyCallback to call when the removal is completed

  • user_data – the data to pass to the callback function

remove_finish(result: AsyncResult) bool

Finishes an asynchronous filter removal previously started with remove().

Added in version 2.24.

Parameters:

result – a AsyncResult

save(identifier: str, source: Bytes, cancellable: Cancellable | None = None, callback: Callable[[...], None] | None = None, *user_data: Any) None

Asynchronously save a content filter from a set source rule.

Asynchronously save a content filter from a source rule set in the WebKit content extesions JSON format.

The identifier can be used afterwards to refer to the filter when using remove() and load(). When the identifier has been used in the past, the new filter source will replace the one saved beforehand for the same identifier.

When the operation is finished, callback will be invoked, which then can use save_finish() to obtain the resulting filter.

Added in version 2.24.

Parameters:
  • identifier – a string used to identify the saved filter

  • sourceBytes containing the rule set in JSON format

  • cancellable – a Cancellable or None to ignore

  • callback – a AsyncReadyCallback to call when saving is completed

  • user_data – the data to pass to the callback function

save_finish(result: AsyncResult) UserContentFilter

Finishes an asynchronous filter save previously started with save().

Added in version 2.24.

Parameters:

result – a AsyncResult

save_from_file(identifier: str, file: File, cancellable: Cancellable | None = None, callback: Callable[[...], None] | None = None, *user_data: Any) None

Asynchronously save a content filter from the contents of a file.

Asynchronously save a content filter from the contents of a file, which must be native to the platform, as checked by is_native(). See save() for more details.

When the operation is finished, callback will be invoked, which then can use save_finish() to obtain the resulting filter.

Added in version 2.24.

Parameters:
  • identifier – a string used to identify the saved filter

  • file – a File containing the rule set in JSON format

  • cancellable – a Cancellable or None to ignore

  • callback – a AsyncReadyCallback to call when saving is completed

  • user_data – the data to pass to the callback function

save_from_file_finish(result: AsyncResult) UserContentFilter

Finishes and asynchronous filter save previously started with save_from_file().

Added in version 2.24.

Parameters:

result – a AsyncResult

Properties

class UserContentFilterStore
props.path: str

The directory used for filter storage. This path is used as the base directory where user content filters are stored on disk.

Added in version 2.24.