qsearch.options

A class for holding and managing options that are passed to various other classes in the Qsearch suite.

Options objects work like dictionaries, but if an Options object is queried for an item and it does not have it, it first checks its defaults and smart_defaults properties for the item before throwing an error. This allows the setting of default values which are easily overridden by user-provided values. The smart_defaults dictionary contains functions that return an object, allowing for default behavior that is dependent on other settings within the Options object.

Options objects are also designed to be easily combinable through functions such as update and updated.

Options objects are used ubiquitously throughout Qsearch

Module Contents

Classes

Options

This class manages options that are passed between various Qsearch objects.

Attributes

_options_actual_parameters

qsearch.options._options_actual_parameters = ['defaults', 'smart_defaults', 'required', 'cache', 'load_error']
class qsearch.options.Options(defaults={}, smart_defaults={}, **xtraargs)

This class manages options that are passed between various Qsearch objects.

filtered(*names)

Returns an Options object with only parameters in the specified list names.

__getitem__(name)
__delitem__(name)
__getattr__(name)
__setattr__(name, value)

Implement setattr(self, name, value).

__contains__(name)
manually_entered(*names, location='dict', operator='all')
empty_copy()

Create an Options object with the same defaults but without any specific values.

copy()

Create a full copy of an Options object.

__copy__()
updated(other=None, **xtraargs)

Return a new Options object that is a copy of this object, updated with the contents of other and xtraargs.

update(other=None, **xtraargs)

Mutate the current Options object with the contents of other and xtraargs.

_update_dict(otherdict)
set_defaults(**args)

Set default values for this Options object.

If an Options object is queried for a value, and it does not contain it, it will check its defaults list before throwing an error.

set_smart_defaults(**args)

Set smart_defaults values for this Options object.

If an Options object is queried for a value, and it does not contain it, it will check its smart_defaults list before throwing an error. If it does find a function in smart_defaults, it calls that function, passing itself as the argument, and returns the return value of that function, caching it for next time.

make_required(*names)

Marking names as required will cause the Options object to throw an error if it does not contain it, even if it has defaults or smart_defaults defined.

remove_defaults(*names)

Removes the defaults for the specified names.

remove_smart_defaults(*names)

Removes the smart_defaults for the specified names.

generate_cache()

Caches valuesa for all functions in smart_defaults.

save(filepath=None)

Saves the Options object to a file, or to a returned tuple.

load(filepath_or_tuple, strict=False)

Loads the Options object from a file or tuple.

If strict is left as False, the Options object will attempt to gracefully handle errors when loading its contents, relying on its ability to fallback to defaults or smart_defaults if those are able to load successfully.

If strict is set to True, the Options object will throw an error upon any error while loading.

__getstate__()
__setstate__(state)