evennia.utils.optionclasses¶
Option classes store user- or server Options in a generic way while also providing validation.
-
class
evennia.utils.optionclasses.
BaseOption
(handler, key, description, default)[source]¶ Bases:
object
Abstract Class to deal with encapsulating individual Options. An Option has a name/key, a description to display in relevant commands and menus, and a default value. It saves to the owner’s Attributes using its Handler’s save category.
Designed to be extremely overloadable as some options can be cantankerous.
- Properties:
valid: Shortcut to the loaded VALID_HANDLER. validator_key (str): The key of the Validator this uses.
-
__init__
(handler, key, description, default)[source]¶ - Parameters
handler (OptionHandler) – The OptionHandler that ‘owns’ this Option.
key (str) – The name this will be used for storage in a dictionary. Must be unique per OptionHandler.
description (str) – What this Option’s text will show in commands and menus.
default – A default value for this Option.
-
property
changed
¶
-
property
default
¶
-
property
value
¶
-
set
(value, **kwargs)[source]¶ Takes user input and stores appropriately. This method allows for passing extra instructions into the validator.
- Parameters
value (str) – The new value of this Option.
kwargs (any) – Any kwargs will be passed into self.validate(value, **kwargs) and self.save(**kwargs).
-
load
()[source]¶ Takes the provided save data, validates it, and gets this Option ready to use.
- Returns
Boolean – Whether loading was successful.
-
save
(**kwargs)[source]¶ Stores the current value using .handler.save_handler(self.key, value, **kwargs) where kwargs are a combination of those passed into this function and the ones specified by the OptionHandler.
- Keyword Arguments
any (any) – Not used by default. These are passed in from self.set and allows the option to let the caller customize saving by overriding or extend the default save kwargs
-
deserialize
(save_data)[source]¶ Perform sanity-checking on the save data as it is loaded from storage. This isn’t the same as what validator-functions provide (those work on user input). For example, save data might be a timedelta or a list or some other object.
- Parameters
save_data – The data to check.
- Returns
any (any) –
- Whatever the Option needs to track, like a string or a
datetime. The display hook is responsible for what is actually displayed to user.
-
serialize
()[source]¶ Serializes the save data for Attribute storage.
- Returns
any (any) – Whatever is best for storage.
-
validate
(value, **kwargs)[source]¶ Validate user input, which is presumed to be a string.
- Parameters
value (str) – User input.
account (AccountDB) – The Account that is performing the validation. This is necessary because of other settings which may affect the check, such as an Account’s timezone affecting how their datetime entries are processed.
- Returns
any (any) – The results of the validation.
- Raises
ValidationError – If input value failed validation.
-
display
(**kwargs)[source]¶ Renders the Option’s value as something pretty to look at.
- Keyword Arguments
any (any) – These are options passed by the caller to potentially customize display dynamically.
- Returns
str –
- How the stored value should be projected to users (e.g. a raw
timedelta is pretty ugly).
-
class
evennia.utils.optionclasses.
Text
(handler, key, description, default)[source]¶ Bases:
evennia.utils.optionclasses.BaseOption
-
deserialize
(save_data)[source]¶ Perform sanity-checking on the save data as it is loaded from storage. This isn’t the same as what validator-functions provide (those work on user input). For example, save data might be a timedelta or a list or some other object.
- Parameters
save_data – The data to check.
- Returns
any (any) –
- Whatever the Option needs to track, like a string or a
datetime. The display hook is responsible for what is actually displayed to user.
-
-
class
evennia.utils.optionclasses.
Email
(handler, key, description, default)[source]¶ Bases:
evennia.utils.optionclasses.BaseOption
-
validate
(value, **kwargs)[source]¶ Validate user input, which is presumed to be a string.
- Parameters
value (str) – User input.
account (AccountDB) – The Account that is performing the validation. This is necessary because of other settings which may affect the check, such as an Account’s timezone affecting how their datetime entries are processed.
- Returns
any (any) – The results of the validation.
- Raises
ValidationError – If input value failed validation.
-
deserialize
(save_data)[source]¶ Perform sanity-checking on the save data as it is loaded from storage. This isn’t the same as what validator-functions provide (those work on user input). For example, save data might be a timedelta or a list or some other object.
- Parameters
save_data – The data to check.
- Returns
any (any) –
- Whatever the Option needs to track, like a string or a
datetime. The display hook is responsible for what is actually displayed to user.
-
-
class
evennia.utils.optionclasses.
Boolean
(handler, key, description, default)[source]¶ Bases:
evennia.utils.optionclasses.BaseOption
-
validate
(value, **kwargs)[source]¶ Validate user input, which is presumed to be a string.
- Parameters
value (str) – User input.
account (AccountDB) – The Account that is performing the validation. This is necessary because of other settings which may affect the check, such as an Account’s timezone affecting how their datetime entries are processed.
- Returns
any (any) – The results of the validation.
- Raises
ValidationError – If input value failed validation.
-
display
(**kwargs)[source]¶ Renders the Option’s value as something pretty to look at.
- Keyword Arguments
any (any) – These are options passed by the caller to potentially customize display dynamically.
- Returns
str –
- How the stored value should be projected to users (e.g. a raw
timedelta is pretty ugly).
-
serialize
()[source]¶ Serializes the save data for Attribute storage.
- Returns
any (any) – Whatever is best for storage.
-
deserialize
(save_data)[source]¶ Perform sanity-checking on the save data as it is loaded from storage. This isn’t the same as what validator-functions provide (those work on user input). For example, save data might be a timedelta or a list or some other object.
- Parameters
save_data – The data to check.
- Returns
any (any) –
- Whatever the Option needs to track, like a string or a
datetime. The display hook is responsible for what is actually displayed to user.
-
-
class
evennia.utils.optionclasses.
Color
(handler, key, description, default)[source]¶ Bases:
evennia.utils.optionclasses.BaseOption
-
validate
(value, **kwargs)[source]¶ Validate user input, which is presumed to be a string.
- Parameters
value (str) – User input.
account (AccountDB) – The Account that is performing the validation. This is necessary because of other settings which may affect the check, such as an Account’s timezone affecting how their datetime entries are processed.
- Returns
any (any) – The results of the validation.
- Raises
ValidationError – If input value failed validation.
-
display
(**kwargs)[source]¶ Renders the Option’s value as something pretty to look at.
- Keyword Arguments
any (any) – These are options passed by the caller to potentially customize display dynamically.
- Returns
str –
- How the stored value should be projected to users (e.g. a raw
timedelta is pretty ugly).
-
deserialize
(save_data)[source]¶ Perform sanity-checking on the save data as it is loaded from storage. This isn’t the same as what validator-functions provide (those work on user input). For example, save data might be a timedelta or a list or some other object.
- Parameters
save_data – The data to check.
- Returns
any (any) –
- Whatever the Option needs to track, like a string or a
datetime. The display hook is responsible for what is actually displayed to user.
-
-
class
evennia.utils.optionclasses.
Timezone
(handler, key, description, default)[source]¶ Bases:
evennia.utils.optionclasses.BaseOption
-
validate
(value, **kwargs)[source]¶ Validate user input, which is presumed to be a string.
- Parameters
value (str) – User input.
account (AccountDB) – The Account that is performing the validation. This is necessary because of other settings which may affect the check, such as an Account’s timezone affecting how their datetime entries are processed.
- Returns
any (any) – The results of the validation.
- Raises
ValidationError – If input value failed validation.
-
property
default
¶
-
deserialize
(save_data)[source]¶ Perform sanity-checking on the save data as it is loaded from storage. This isn’t the same as what validator-functions provide (those work on user input). For example, save data might be a timedelta or a list or some other object.
- Parameters
save_data – The data to check.
- Returns
any (any) –
- Whatever the Option needs to track, like a string or a
datetime. The display hook is responsible for what is actually displayed to user.
-
-
class
evennia.utils.optionclasses.
UnsignedInteger
(handler, key, description, default)[source]¶ Bases:
evennia.utils.optionclasses.BaseOption
-
validator_key
= 'unsigned_integer'¶
-
validate
(value, **kwargs)[source]¶ Validate user input, which is presumed to be a string.
- Parameters
value (str) – User input.
account (AccountDB) – The Account that is performing the validation. This is necessary because of other settings which may affect the check, such as an Account’s timezone affecting how their datetime entries are processed.
- Returns
any (any) – The results of the validation.
- Raises
ValidationError – If input value failed validation.
-
deserialize
(save_data)[source]¶ Perform sanity-checking on the save data as it is loaded from storage. This isn’t the same as what validator-functions provide (those work on user input). For example, save data might be a timedelta or a list or some other object.
- Parameters
save_data – The data to check.
- Returns
any (any) –
- Whatever the Option needs to track, like a string or a
datetime. The display hook is responsible for what is actually displayed to user.
-
-
class
evennia.utils.optionclasses.
SignedInteger
(handler, key, description, default)[source]¶ Bases:
evennia.utils.optionclasses.BaseOption
-
validate
(value, **kwargs)[source]¶ Validate user input, which is presumed to be a string.
- Parameters
value (str) – User input.
account (AccountDB) – The Account that is performing the validation. This is necessary because of other settings which may affect the check, such as an Account’s timezone affecting how their datetime entries are processed.
- Returns
any (any) – The results of the validation.
- Raises
ValidationError – If input value failed validation.
-
deserialize
(save_data)[source]¶ Perform sanity-checking on the save data as it is loaded from storage. This isn’t the same as what validator-functions provide (those work on user input). For example, save data might be a timedelta or a list or some other object.
- Parameters
save_data – The data to check.
- Returns
any (any) –
- Whatever the Option needs to track, like a string or a
datetime. The display hook is responsible for what is actually displayed to user.
-
-
class
evennia.utils.optionclasses.
PositiveInteger
(handler, key, description, default)[source]¶ Bases:
evennia.utils.optionclasses.BaseOption
-
validate
(value, **kwargs)[source]¶ Validate user input, which is presumed to be a string.
- Parameters
value (str) – User input.
account (AccountDB) – The Account that is performing the validation. This is necessary because of other settings which may affect the check, such as an Account’s timezone affecting how their datetime entries are processed.
- Returns
any (any) – The results of the validation.
- Raises
ValidationError – If input value failed validation.
-
deserialize
(save_data)[source]¶ Perform sanity-checking on the save data as it is loaded from storage. This isn’t the same as what validator-functions provide (those work on user input). For example, save data might be a timedelta or a list or some other object.
- Parameters
save_data – The data to check.
- Returns
any (any) –
- Whatever the Option needs to track, like a string or a
datetime. The display hook is responsible for what is actually displayed to user.
-
-
class
evennia.utils.optionclasses.
Duration
(handler, key, description, default)[source]¶ Bases:
evennia.utils.optionclasses.BaseOption
-
validate
(value, **kwargs)[source]¶ Validate user input, which is presumed to be a string.
- Parameters
value (str) – User input.
account (AccountDB) – The Account that is performing the validation. This is necessary because of other settings which may affect the check, such as an Account’s timezone affecting how their datetime entries are processed.
- Returns
any (any) – The results of the validation.
- Raises
ValidationError – If input value failed validation.
-
deserialize
(save_data)[source]¶ Perform sanity-checking on the save data as it is loaded from storage. This isn’t the same as what validator-functions provide (those work on user input). For example, save data might be a timedelta or a list or some other object.
- Parameters
save_data – The data to check.
- Returns
any (any) –
- Whatever the Option needs to track, like a string or a
datetime. The display hook is responsible for what is actually displayed to user.
-
-
class
evennia.utils.optionclasses.
Datetime
(handler, key, description, default)[source]¶ Bases:
evennia.utils.optionclasses.BaseOption
-
validate
(value, **kwargs)[source]¶ Validate user input, which is presumed to be a string.
- Parameters
value (str) – User input.
account (AccountDB) – The Account that is performing the validation. This is necessary because of other settings which may affect the check, such as an Account’s timezone affecting how their datetime entries are processed.
- Returns
any (any) – The results of the validation.
- Raises
ValidationError – If input value failed validation.
-
deserialize
(save_data)[source]¶ Perform sanity-checking on the save data as it is loaded from storage. This isn’t the same as what validator-functions provide (those work on user input). For example, save data might be a timedelta or a list or some other object.
- Parameters
save_data – The data to check.
- Returns
any (any) –
- Whatever the Option needs to track, like a string or a
datetime. The display hook is responsible for what is actually displayed to user.
-
-
class
evennia.utils.optionclasses.
Future
(handler, key, description, default)[source]¶ Bases:
evennia.utils.optionclasses.Datetime
-
validate
(value, **kwargs)[source]¶ Validate user input, which is presumed to be a string.
- Parameters
value (str) – User input.
account (AccountDB) – The Account that is performing the validation. This is necessary because of other settings which may affect the check, such as an Account’s timezone affecting how their datetime entries are processed.
- Returns
any (any) – The results of the validation.
- Raises
ValidationError – If input value failed validation.
-
-
class
evennia.utils.optionclasses.
Lock
(handler, key, description, default)[source]¶ Bases:
evennia.utils.optionclasses.Text
-
validate
(value, **kwargs)[source]¶ Validate user input, which is presumed to be a string.
- Parameters
value (str) – User input.
account (AccountDB) – The Account that is performing the validation. This is necessary because of other settings which may affect the check, such as an Account’s timezone affecting how their datetime entries are processed.
- Returns
any (any) – The results of the validation.
- Raises
ValidationError – If input value failed validation.
-