evennia.utils.optionhandler

class evennia.utils.optionhandler.InMemorySaveHandler[源代码]

基类:object

Fallback SaveHandler, implementing a minimum of the required save mechanism and storing data in memory.

__init__()[源代码]

Initialize self. See help(type(self)) for accurate signature.

add(key, value=None, **kwargs)[源代码]
get(key, default=None, **kwargs)[源代码]
class evennia.utils.optionhandler.OptionHandler(obj, options_dict=None, savefunc=None, loadfunc=None, save_kwargs=None, load_kwargs=None)[源代码]

基类:object

This is a generic Option handler. Retrieve options either as properties on this handler or by using the .get method.

This is used for Account.options but it could be used by Scripts or Objects just as easily. All it needs to be provided is an options_dict.

__init__(obj, options_dict=None, savefunc=None, loadfunc=None, save_kwargs=None, load_kwargs=None)[源代码]

Initialize an OptionHandler.

参数
  • obj (object) – The object this handler sits on. This is usually a TypedObject.

  • options_dict (dict) – A dictionary of option keys, where the values are options. The format of those tuples is: (‘key’, “Description to show”, ‘option_type’, <default value>)

  • savefunc (callable) – A callable for all options to call when saving itself. It will be called as savefunc(key, value, **save_kwargs). A common one to pass would be AttributeHandler.add.

  • loadfunc (callable) – A callable for all options to call when loading data into itself. It will be called as loadfunc(key, default=default, **load_kwargs). A common one to pass would be AttributeHandler.get.

  • save_kwargs (any) – Optional extra kwargs to pass into savefunc above.

  • load_kwargs (any) – Optional extra kwargs to pass into loadfunc above.

提示

Both loadfunc and savefunc must be specified. If only one is given, the other will be ignored and in-memory storage will be used.

get(key, default=None, return_obj=False, raise_error=False)[源代码]

Retrieves an Option stored in the handler. Will load it if it doesn’t exist.

参数
  • key (str) – The option key to retrieve.

  • default (any) – What to return if the option is defined.

  • return_obj (bool, optional) – If True, returns the actual option object instead of its value.

  • raise_error (bool, optional) – Raise Exception if key is not found in options.

返回

option_value (any or Option) – An option value the Option itself.

引发

KeyError – If option is not defined.

set(key, value, **kwargs) → BaseOption[源代码]

Change an individual option.

参数
  • key (str) – The key of an option that can be changed. Allows partial matching.

  • value (str) – The value that should be checked, coerced, and stored.:

  • kwargs (any, optional) – These are passed into the Option’s validation function, save function and display function and allows to customize either.

返回

BaseOption

The matched object. Its new value can be accessed with

op.value or op.display().

all(return_objs=False)[源代码]

Get all options defined on this handler.

参数

return_objs (bool, optional) – Return the actual Option objects rather than their values.

返回

all_options (dict)

All options on this handler, either {key: value}

or {key: <Option>} if return_objs is True.