evennia.objects.manager¶
Custom manager for Objects.
- class evennia.objects.manager.ObjectManager(*args, **kwargs)[source]¶
Bases:
ObjectDBManager,TypeclassManager
- class evennia.objects.manager.ObjectDBManager(*args, **kwargs)[source]¶
Bases:
TypedObjectManagerThis ObjectManager implements methods for searching and manipulating Objects directly from the database.
Evennia-specific search methods (will return Typeclasses or lists of Typeclasses, whereas Django-general methods will return Querysets or database objects).
dbref (converter) dbref_search get_dbref_range object_totals typeclass_search get_object_with_account get_objs_with_key_and_typeclass get_objs_with_attr get_objs_with_attr_match get_objs_with_db_property get_objs_with_db_property_match get_objs_with_key_or_alias get_contents search_object (interface to many of the above methods,
equivalent to evennia.search_object)
copy_object
- get_object_with_account(ostring, exact=True, candidates=None)[source]¶
Search for an object based on its account’s name or dbref.
- Parameters:
ostring (str or int) – Search criterion or dbref. Searching for an account is sometimes initiated by appending an * to the beginning of the search criterion (e.g. in local_and_global_search). This is stripped here.
exact (bool, optional) – Require an exact account match.
candidates (list, optional) – Only search among this list of possible object candidates.
- Returns:
match (query) – Matching query.
- get_objs_with_key_and_typeclass(oname, otypeclass_path, candidates=None)[source]¶
Returns objects based on simultaneous key and typeclass match.
- Parameters:
oname (str) – Object key to search for
otypeclass_path (str) – Full Python path to tyepclass to search for
candidates (list, optional) – Only match among the given list of candidates.
- Returns:
matches (query) – The matching objects.
- get_objs_with_attr(attribute_name, candidates=None)[source]¶
Get objects based on having a certain Attribute defined.
- Parameters:
attribute_name (str) – Attribute name to search for.
candidates (list, optional) – Only match among the given list of object candidates.
- Returns:
matches (query) – All objects having the given attribute_name defined at all.
- get_objs_with_attr_value(attribute_name, attribute_value, candidates=None, typeclasses=None)[source]¶
Get all objects having the given attrname set to the given value.
- Parameters:
attribute_name (str) – Attribute key to search for.
attribute_value (any) – Attribute value to search for. This can also be database objects.
candidates (list, optional) – Candidate objects to limit search to.
typeclasses (list, optional) – Python pats to restrict matches with.
- Returns:
Queryset –
- Iterable with 0, 1 or more matches fullfilling both the attribute_name and
attribute_value criterions.
Notes
This uses the Attribute’s PickledField to transparently search the database by matching the internal representation. This is reasonably effective but since Attribute values cannot be indexed, searching by Attribute key is to be preferred whenever possible.
- get_objs_with_db_property(property_name, candidates=None)[source]¶
Get all objects having a given db field property.
- Parameters:
property_name (str) – The name of the field to match for.
candidates (list, optional) – Only search among th egiven candidates.
- Returns:
matches (list) – The found matches.
- get_objs_with_db_property_value(property_name, property_value, candidates=None, typeclasses=None)[source]¶
Get objects with a specific field name and value.
- Parameters:
property_name (str) – Field name to search for.
property_value (any) – Value required for field with property_name to have.
candidates (list, optional) – List of objects to limit search to.
typeclasses (list, optional) – List of typeclass-path strings to restrict matches with
- Returns:
Queryset – Iterable with 0, 1 or more matches.
- get_contents(location, excludeobj=None)[source]¶
Get all objects that has a location set to this one.
- Parameters:
location (Object) – Where to get contents from.
excludeobj (Object or list, optional) – One or more objects to exclude from the match.
- Returns:
Queryset – Iterable with 0, 1 or more matches.
- get_objs_with_key_or_alias(ostring, exact=True, candidates=None, typeclasses=None)[source]¶
- Parameters:
ostring (str) – A search criterion.
exact (bool, optional) – Require exact match of ostring (still case-insensitive). If False, will do fuzzy matching with a regex filter.
candidates (list) – Only match among these candidates.
typeclasses (list) – Only match objects with typeclasses having thess path strings.
- Returns:
Queryset – An iterable with 0, 1 or more matches.
- search_object(searchdata, attribute_name=None, typeclass=None, candidates=None, exact=True, use_dbref=True, tags=None)[source]¶
Search as an object globally or in a list of candidates and return results. Always returns a QuerySet of Objects.
- Parameters:
searchdata (str or Object) – The entity to match for. This is usually a key string but may also be an object itself. By default (if no attribute_name is set), this will search object.key and object.aliases. Can also be on the form #dbref, which will (if exact=True) be matched against primary key.
attribute_name (str) – Use this named Attribute to match searchdata against, instead of the defaults. If this is the name of a database field (with or without the db_ prefix), that will be matched too.
typeclass (str or TypeClass) – restrict matches to objects having this typeclass. This will help speed up global searches.
candidates (list) – If supplied, search will only be performed among the candidates in this list. A common list of candidates is the contents of the current location searched.
exact (bool) – Match names/aliases exactly or partially. Partial matching matches the beginning of words in the names/aliases, using a matching routine to separate multiple matches in names with multiple components (so “bi sw” will match “Big sword”). Since this is more expensive than exact matching, it is recommended to be used together with the candidates keyword to limit the number of possibilities. This value has no meaning if searching for attributes/properties.
use_dbref (bool) – If False, bypass direct lookup of a string on the form #dbref and treat it like any string.
tags (list) – A list of tuples (tagkey, tagcategory) where the matched object must have _all_ tags in order to be considered a match.
- Returns:
matches (QuerySet) – Matching objects
- object_search(searchdata, attribute_name=None, typeclass=None, candidates=None, exact=True, use_dbref=True, tags=None)¶
Search as an object globally or in a list of candidates and return results. Always returns a QuerySet of Objects.
- Parameters:
searchdata (str or Object) – The entity to match for. This is usually a key string but may also be an object itself. By default (if no attribute_name is set), this will search object.key and object.aliases. Can also be on the form #dbref, which will (if exact=True) be matched against primary key.
attribute_name (str) – Use this named Attribute to match searchdata against, instead of the defaults. If this is the name of a database field (with or without the db_ prefix), that will be matched too.
typeclass (str or TypeClass) – restrict matches to objects having this typeclass. This will help speed up global searches.
candidates (list) – If supplied, search will only be performed among the candidates in this list. A common list of candidates is the contents of the current location searched.
exact (bool) – Match names/aliases exactly or partially. Partial matching matches the beginning of words in the names/aliases, using a matching routine to separate multiple matches in names with multiple components (so “bi sw” will match “Big sword”). Since this is more expensive than exact matching, it is recommended to be used together with the candidates keyword to limit the number of possibilities. This value has no meaning if searching for attributes/properties.
use_dbref (bool) – If False, bypass direct lookup of a string on the form #dbref and treat it like any string.
tags (list) – A list of tuples (tagkey, tagcategory) where the matched object must have _all_ tags in order to be considered a match.
- Returns:
matches (QuerySet) – Matching objects
- search(searchdata, attribute_name=None, typeclass=None, candidates=None, exact=True, use_dbref=True, tags=None)¶
Search as an object globally or in a list of candidates and return results. Always returns a QuerySet of Objects.
- Parameters:
searchdata (str or Object) – The entity to match for. This is usually a key string but may also be an object itself. By default (if no attribute_name is set), this will search object.key and object.aliases. Can also be on the form #dbref, which will (if exact=True) be matched against primary key.
attribute_name (str) – Use this named Attribute to match searchdata against, instead of the defaults. If this is the name of a database field (with or without the db_ prefix), that will be matched too.
typeclass (str or TypeClass) – restrict matches to objects having this typeclass. This will help speed up global searches.
candidates (list) – If supplied, search will only be performed among the candidates in this list. A common list of candidates is the contents of the current location searched.
exact (bool) – Match names/aliases exactly or partially. Partial matching matches the beginning of words in the names/aliases, using a matching routine to separate multiple matches in names with multiple components (so “bi sw” will match “Big sword”). Since this is more expensive than exact matching, it is recommended to be used together with the candidates keyword to limit the number of possibilities. This value has no meaning if searching for attributes/properties.
use_dbref (bool) – If False, bypass direct lookup of a string on the form #dbref and treat it like any string.
tags (list) – A list of tuples (tagkey, tagcategory) where the matched object must have _all_ tags in order to be considered a match.
- Returns:
matches (QuerySet) – Matching objects
- copy_object(original_object, new_key=None, new_location=None, new_home=None, new_permissions=None, new_locks=None, new_aliases=None, new_destination=None)[source]¶
Create and return a new object as a copy of the original object. All will be identical to the original except for the arguments given specifically to this method. Object contents will not be copied.
- Parameters:
original_object (Object) – The object to make a copy from.
new_key (str, optional) – Name of the copy, if different from the original.
new_location (Object, optional) – Alternate location.
new_home (Object, optional) – Change the home location
new_aliases (list, optional) – Give alternate object aliases as a list of strings.
new_destination (Object, optional) – Used only by exits.
- Returns:
copy (Object or None) –
- The copy of original_object,
optionally modified as per the ingoing keyword arguments. None if an error was encountered.
- clear_all_sessids()[source]¶
Clear the db_sessid field of all objects having also the db_account field set.
- create_object(typeclass=None, key=None, location=None, home=None, permissions=None, locks=None, aliases=None, tags=None, destination=None, report_to=None, nohome=False, attributes=None, nattributes=None)[source]¶
Create a new in-game object.
- Keyword Arguments:
typeclass (class or str) – Class or python path to a typeclass.
key (str) – Name of the new object. If not set, a name of #dbref will be set.
location (Object or str) – Obj or #dbref to use as the location of the new object.
home (Object or str) – Obj or #dbref to use as the object’s home location.
permissions (list) – A list of permission strings or tuples (permstring, category).
locks (str) – one or more lockstrings, separated by semicolons.
aliases (list) – A list of alternative keys or tuples (aliasstring, category).
tags (list) – List of tag keys or tuples (tagkey, category) or (tagkey, category, data).
destination (Object or str) – Obj or #dbref to use as an Exit’s target.
report_to (Object) – The object to return error messages to.
nohome (bool) – This allows the creation of objects without a default home location; only used when creating the default location itself or during unittests.
attributes (list) – Tuples on the form (key, value) or (key, value, category), (key, value, lockstring) or (key, value, lockstring, default_access). to set as Attributes on the new object.
nattributes (list) – Non-persistent tuples on the form (key, value). Note that adding this rarely makes sense since this data will not survive a reload.
- Returns:
object (Object) – A newly created object of the given typeclass.
- Raises:
ObjectDB.DoesNotExist – If trying to create an Object with location or home that can’t be found.
- class evennia.objects.manager.Q(*args, _connector=None, _negated=False, **kwargs)[source]¶
Bases:
NodeEncapsulate filters as objects that can then be combined logically (using & and |).
- AND = 'AND'¶
- OR = 'OR'¶
- XOR = 'XOR'¶
- __init__(*args, _connector=None, _negated=False, **kwargs)[source]¶
Construct a new Node. If no connector is given, use the default.
- check(against, using='default')[source]¶
Do a database query to check if the expressions of the Q instance matches against the expressions.
- conditional = True¶
- default = 'AND'¶
- identity¶
- referenced_base_fields¶
Retrieve all base fields referenced directly or through F expressions excluding any fields referenced through joins.
- class evennia.objects.manager.TypeclassManager(*args, **kwargs)[source]¶
Bases:
TypedObjectManagerManager for the typeclasses. The main purpose of this manager is to limit database queries to the given typeclass despite all typeclasses technically being defined in the same core database model.
- all()[source]¶
Overload method to return all matches, filtering for typeclass.
- Returns:
objects (queryset) – The objects found.
- all_family()[source]¶
Return all matches, allowing matches from all subclasses of the typeclass.
- Returns:
objects (list) – The objects found.
- annotate(*args, **kwargs)[source]¶
Overload annotate method to filter on typeclass before annotating. :param *args: Positional arguments passed along to queryset annotate method. :type *args: any :param **kwargs: Keyword arguments passed along to queryset annotate method. :type **kwargs: any
- Returns:
Annotated queryset.
- count()[source]¶
Overload method to return number of matches, filtering for typeclass.
- Returns:
integer – Number of objects found.
- filter(*args, **kwargs)[source]¶
Overload of the standard filter function. This filter will limit itself to only the current typeclass.
- Parameters:
args (any) – These are passed on as arguments to the default django filter method.
- Keyword Arguments:
kwargs (any) – These are passed on as normal arguments to the default django filter method.
- Returns:
objects (queryset) – The objects found.
- filter_family(*args, **kwargs)[source]¶
Variation of filter that allows results both from typeclass and from subclasses of typeclass
- Parameters:
args (any) – These are passed on as arguments to the default django filter method.
- Keyword Arguments:
kwargs (any) – These are passed on as normal arguments to the default django filter method.
- Returns:
objects (list) – The objects found.
- first()[source]¶
Overload method to return first match, filtering for typeclass.
- Returns:
object (object) – The object found.
- Raises:
ObjectNotFound – The exact name of this exception depends on the model base used.
- get(*args, **kwargs)[source]¶
Overload the standard get. This will limit itself to only return the current typeclass.
- Parameters:
args (any) – These are passed on as arguments to the default django get method.
- Keyword Arguments:
kwargs (any) – These are passed on as normal arguments to the default django get method
- Returns:
object (object) – The object found.
- Raises:
ObjectNotFound – The exact name of this exception depends on the model base used.
- get_family(*args, **kwargs)[source]¶
Variation of get that not only returns the current typeclass but also all subclasses of that typeclass.
- Keyword Arguments:
kwargs (any) – These are passed on as normal arguments to the default django get method.
- Returns:
objects (list) – The objects found.
- Raises:
ObjectNotFound – The exact name of this exception depends on the model base used.
- last()[source]¶
Overload method to return last match, filtering for typeclass.
- Returns:
object (object) – The object found.
- Raises:
ObjectNotFound – The exact name of this exception depends on the model base used.
- smart_search(query)[source]¶
Search by supplying a string with optional extra search criteria to aid the query.
- Parameters:
query (All three can be combined in the same) – A search criteria that accepts extra search criteria on the following
forms – [key|alias|#dbref…] [tag==<tagstr>[:category]…] [attr==<key>:<value>:category…]
query
spaces. (separated by)
- Returns:
matches (queryset) –
- A queryset result matching all queries exactly. If wanting to use
spaces or ==, != in tags or attributes, enclose them in quotes.
Example
house = smart_search(“key=foo alias=bar tag=house:building tag=magic attr=color:red”)
Note
The flexibility of this method is limited by the input line format. Tag/attribute matching only works for matching primitives. For even more complex queries, such as ‘in’ operations or object field matching, use the full django query language.
- values(*args, **kwargs)[source]¶
Overload values method to filter on typeclass first. :param *args: Positional arguments passed along to values method. :type *args: any :param **kwargs: Keyword arguments passed along to values method. :type **kwargs: any
- Returns:
Queryset of values dictionaries, just filtered by typeclass first.
- values_list(*args, **kwargs)[source]¶
Overload values method to filter on typeclass first. :param *args: Positional arguments passed along to values_list method. :type *args: any :param **kwargs: Keyword arguments passed along to values_list method. :type **kwargs: any
- Returns:
Queryset of value_list tuples, just filtered by typeclass first.
- class evennia.objects.manager.TypedObjectManager(*args, **kwargs)[source]¶
Bases:
SharedMemoryManagerCommon ObjectManager for all dbobjects.
- create_tag(key=None, category=None, data=None, tagtype=None)[source]¶
Create a new Tag of the base type associated with this object. This makes sure to create case-insensitive tags. If the exact same tag configuration (key+category+tagtype+dbmodel) exists on the model, a new tag will not be created, but an old one returned.
- Parameters:
key (str, optional) – Tag key. Not case sensitive.
category (str, optional) – Tag category. Not case sensitive.
data (str, optional) – Extra information about the tag.
tagtype (str or None, optional) – ‘type’ of Tag, by default this is either None (a normal Tag), alias or permission.
Notes
The data field is not part of the uniqueness of the tag: Setting data on an existing tag will overwrite the old data field. It is intended only as a way to carry information about the tag (like a help text), not to carry any information about the tagged objects themselves.
- dbref(dbref, reqhash=True)[source]¶
Determing if input is a valid dbref.
- Parameters:
dbref (str or int) – A possible dbref.
reqhash (bool, optional) – If the “#” is required for this to be considered a valid hash.
- Returns:
dbref (int or None) – The integer part of the dbref.
Notes
Valid forms of dbref (database reference number) are either a string ‘#N’ or an integer N.
- dbref_search(dbref)[source]¶
Alias to get_id.
- Parameters:
dbref (str or int) – The id to search for.
- Returns:
Queryset – Queryset with 0 or 1 match.
- get_alias(key=None, category=None, obj=None)[source]¶
Get an alias from the database.
- Parameters:
key (str, optional) – The permission’s identifier.
category (str, optional) – The permission’s category.
obj (object, optional) – The object on which this Tag is set.
- Returns:
alias (list) – Alias objects.
- get_attribute(key=None, category=None, value=None, strvalue=None, obj=None, attrtype=None, **kwargs)[source]¶
Return Attribute objects by key, by category, by value, by strvalue, by object (it is stored on) or with a combination of those criteria.
- Parameters:
key (str, optional) – The attribute’s key to search for
category (str, optional) – The category of the attribute(s) to search for.
value (str, optional) – The attribute value to search for. Note that this is not a very efficient operation since it will query for a pickled entity. Mutually exclusive to strvalue.
strvalue (str, optional) – The str-value to search for. Most Attributes will not have strvalue set. This is mutually exclusive to the value keyword and will take precedence if given.
obj (Object, optional) – On which object the Attribute to search for is.
attrype (str, optional) – An attribute-type to search for. By default this is either None (normal Attributes) or “nick”.
**kwargs (any) – Currently unused. Reserved for future use.
- Returns:
list – The matching Attributes.
- get_by_alias(key=None, category=None)[source]¶
Return objects having aliases with a given key or category or combination of the two.
- Parameters:
key (str, optional) – Alias key. Not case sensitive.
category (str, optional) – Alias category. Not case sensitive.
- Returns:
objects (list) – Objects with matching alias.
- get_by_attribute(key=None, category=None, value=None, strvalue=None, attrtype=None, **kwargs)[source]¶
Return objects having attributes with the given key, category, value, strvalue or combination of those criteria.
- Parameters:
key (str, optional) – The attribute’s key to search for
category (str, optional) – The category of the attribute to search for.
value (str, optional) – The attribute value to search for. Note that this is not a very efficient operation since it will query for a pickled entity. Mutually exclusive to strvalue.
strvalue (str, optional) – The str-value to search for. Most Attributes will not have strvalue set. This is mutually exclusive to the value keyword and will take precedence if given.
attrype (str, optional) – An attribute-type to search for. By default this is either None (normal Attributes) or “nick”.
kwargs (any) – Currently unused. Reserved for future use.
- Returns:
obj (list) – Objects having the matching Attributes.
- get_by_nick(key=None, nick=None, category='inputline')[source]¶
Get object based on its key or nick.
- Parameters:
key (str, optional) – The attribute’s key to search for
nick (str, optional) – The nickname to search for
category (str, optional) – The category of the nick to search for.
- Returns:
obj (list) – Objects having the matching Nicks.
- get_by_permission(key=None, category=None)[source]¶
Return objects having permissions with a given key or category or combination of the two.
- Parameters:
key (str, optional) – Permissions key. Not case sensitive.
category (str, optional) – Permission category. Not case sensitive.
- Returns:
objects (list) – Objects with matching permission.
- get_by_tag(key=None, category=None, tagtype=None, **kwargs)[source]¶
Return objects having tags with a given key or category or combination of the two. Also accepts multiple tags/category/tagtype
- Parameters:
key (str or list, optional) – Tag key or list of keys. Not case sensitive.
category (str or list, optional) – Tag category. Not case sensitive. If key is a list, a single category can either apply to all keys in that list or this must be a list matching the key list element by element. If no key is given, all objects with tags of this category are returned.
tagtype (str, optional) – ‘type’ of Tag, by default this is either None (a normal Tag), alias or permission. This always apply to all queried tags.
- Keyword Arguments:
match (str) – “all” (default) or “any”; determines whether the target object must be tagged with ALL of the provided tags/categories or ANY single one. ANY will perform a weighted sort, so objects with more tag matches will outrank those with fewer tag matches.
- Returns:
objects (list) – Objects with matching tag.
- Raises:
IndexError – If key and category are both lists and category is shorter than key.
- get_dbref_range(min_dbref=None, max_dbref=None)[source]¶
Get objects within a certain range of dbrefs.
- Parameters:
min_dbref (int) – Start of dbref range.
max_dbref (int) – End of dbref range (inclusive)
- Returns:
objects (list) –
- TypedObjects with dbrefs within
the given dbref ranges.
- get_id(dbref)[source]¶
Find object with given dbref.
- Parameters:
dbref (str or int) – The id to search for.
- Returns:
object (TypedObject) – The matched object.
- get_nick(key=None, category=None, value=None, strvalue=None, obj=None)[source]¶
Get a nick, in parallel to get_attribute.
- Parameters:
key (str, optional) – The nicks’s key to search for
category (str, optional) – The category of the nicks(s) to search for.
value (str, optional) – The attribute value to search for. Note that this is not a very efficient operation since it will query for a pickled entity. Mutually exclusive to strvalue.
strvalue (str, optional) – The str-value to search for. Most Attributes will not have strvalue set. This is mutually exclusive to the value keyword and will take precedence if given.
obj (Object, optional) – On which object the Attribute to search for is.
- Returns:
nicks (list) – The matching Nicks.
- get_permission(key=None, category=None, obj=None)[source]¶
Get a permission from the database.
- Parameters:
key (str, optional) – The permission’s identifier.
category (str, optional) – The permission’s category.
obj (object, optional) – The object on which this Tag is set.
- Returns:
permission (list) – Permission objects.
- get_tag(key=None, category=None, obj=None, tagtype=None, global_search=False)[source]¶
Return Tag objects by key, by category, by object (it is stored on) or with a combination of those criteria.
- Parameters:
key (str, optional) – The Tag’s key to search for
category (str, optional) – The Tag of the attribute(s) to search for.
obj (Object, optional) – On which object the Tag to search for is.
tagtype (str, optional) – One of None (normal tags), “alias” or “permission”
global_search (bool, optional) – Include all possible tags, not just tags on this object
- Returns:
tag (list) – The matching Tags.
- get_typeclass_totals(*args, **kwargs) object[source]¶
Returns a queryset of typeclass composition statistics.
- Returns:
qs (Queryset) –
- A queryset of dicts containing the typeclass (name),
the count of objects with that typeclass and a float representing the percentage of objects associated with the typeclass.
- object_totals()[source]¶
Get info about database statistics.
- Returns:
census (dict) –
- A dictionary {typeclass_path: number, …} with
all the typeclasses active in-game as well as the number of such objects defined (i.e. the number of database object having that typeclass set on themselves).
- search_dbref(dbref)¶
Alias to get_id.
- Parameters:
dbref (str or int) – The id to search for.
- Returns:
Queryset – Queryset with 0 or 1 match.
- typeclass_search(typeclass, include_children=False, include_parents=False)[source]¶
Searches through all objects returning those which are of the specified typeclass.
- Parameters:
typeclass (str or class) – A typeclass class or a python path to a typeclass.
include_children (bool, optional) – Return objects with given typeclass and all children inheriting from this typeclass. Mutually exclusive to include_parents.
include_parents (bool, optional) – Return objects with given typeclass and all parents to this typeclass. Mutually exclusive to include_children.
- Returns:
objects (list) – The objects found with the given typeclasses.
- Raises:
ImportError – If the provided typeclass is not a valid typeclass or the path to an existing typeclass.
- evennia.objects.manager.class_from_module(path, defaultpaths=None, fallback=None)[source]¶
Return a class from a module, given the class’ full python path. This is primarily used to convert db_typeclass_path:s to classes.
- Parameters:
path (str) – Full Python dot-path to module.
defaultpaths (iterable, optional) – If a direct import from path fails, try subsequent imports by prepending those paths to path.
fallback (str) – If all other attempts fail, use this path as a fallback. This is intended as a last-resort. In the example of Evennia loading, this would be a path to a default parent class in the evennia repo itself.
- Returns:
class (Class) – An uninstantiated class recovered from path.
- Raises:
ImportError – If all loading failed.
- evennia.objects.manager.dbid_to_obj(inp, objclass, raise_errors=True)¶
Convert a #dbref to a valid object.
- Parameters:
inp (str or int) – A valid #dbref.
objclass (class) – A valid django model to filter against.
raise_errors (bool, optional) – Whether to raise errors or return None on errors.
- Returns:
obj (Object or None) – An entity loaded from the dbref.
- Raises:
Exception – If raise_errors is True and objclass.objects.get(id=dbref) did not return a valid object.
- evennia.objects.manager.is_iter(obj)[source]¶
Checks if an object behaves iterably.
- Parameters:
obj (any) – Entity to check for iterability.
- Returns:
is_iterable (bool) – If obj is iterable or not.
Notes
Strings are not accepted as iterable (although they are actually iterable), since string iterations are usually not what we want to do with a string.
- evennia.objects.manager.make_iter(obj)[source]¶
Makes sure that the object is always iterable.
- Parameters:
obj (any) – Object to make iterable.
- Returns:
iterable (list or iterable) –
- The same object
passed-through or made iterable.
- evennia.objects.manager.string_partial_matching(alternatives, inp, ret_index=True)[source]¶
Partially matches a string based on a list of alternatives. Matching is made from the start of each subword in each alternative. Case is not important. So e.g. “bi sh sw” or just “big” or “shiny” or “sw” will match “Big shiny sword”. Scoring is done to allow to separate by most common denominator. You will get multiple matches returned if appropriate.
- Parameters:
alternatives (list of str) – A list of possible strings to match.
inp (str) – Search criterion.
ret_index (bool, optional) – Return list of indices (from alternatives array) instead of strings.
- Returns:
matches (list) – String-matches or indices if ret_index is True.