Fix AttributeHandler.get with no Attributes. Also make return_list=True return [] rather than [None]. Resolves #1866

This commit is contained in:
Griatch 2019-09-08 19:18:19 +02:00
parent ea07a81696
commit bb5324ba52
3 changed files with 21 additions and 28 deletions

View file

@ -2,14 +2,14 @@
## Evennia 1.0 (2019-) (WIP) ## Evennia 1.0 (2019-) (WIP)
### Already in master ### Already in master
- `py` command now reroutes stdout to output results in-game client. `py` - `py` command now reroutes stdout to output results in-game client. `py`
without arguments starts a full interactive Python console. without arguments starts a full interactive Python console.
- Webclient default to a single input pane instead of two. Now defaults to no help-popup. - Webclient default to a single input pane instead of two. Now defaults to no help-popup.
- Webclient fix of prompt display - Webclient fix of prompt display
- Webclient multimedia support for relaying images, video and sounds via - Webclient multimedia support for relaying images, video and sounds via
`.msg(image=URL)`, `.msg(video=URL)` `.msg(image=URL)`, `.msg(video=URL)`
and `.msg(audio=URL)` and `.msg(audio=URL)`
- Add Spanish translation (fermuch) - Add Spanish translation (fermuch)
- Expand `GLOBAL_SCRIPTS` container to always start scripts and to include all - Expand `GLOBAL_SCRIPTS` container to always start scripts and to include all
@ -19,6 +19,10 @@ without arguments starts a full interactive Python console.
- Make new `CHANNEL_MUDINFO` setting for specifying the mudinfo channel - Make new `CHANNEL_MUDINFO` setting for specifying the mudinfo channel
- Make `CHANNEL_CONNECTINFO` take full channel definition - Make `CHANNEL_CONNECTINFO` take full channel definition
- Make `DEFAULT_CHANNELS` list auto-create channels missing at reload - Make `DEFAULT_CHANNELS` list auto-create channels missing at reload
- Webclient `ANSI->HTML` parser updated. Webclient line width changed from 1.6em to 1.1em
to better make ANSI graphics look the same as for third-party clients
- `AttributeHandler.get(return_list=True)` will return `[]` if there are no
Attributes instead of `[None]`.
## Evennia 0.9 (2018-2019) ## Evennia 0.9 (2018-2019)
@ -57,12 +61,12 @@ without arguments starts a full interactive Python console.
- Change webclient from old txws version to use more supported/feature-rich Autobahn websocket library - Change webclient from old txws version to use more supported/feature-rich Autobahn websocket library
#### Evennia game index #### Evennia game index
- Made Evennia game index client a part of core - now configured from settings file (old configs - Made Evennia game index client a part of core - now configured from settings file (old configs
need to be moved) need to be moved)
- The `evennia connections` command starts a wizard that helps you connect your game to the game index. - The `evennia connections` command starts a wizard that helps you connect your game to the game index.
- The game index now accepts games with no public telnet/webclient info (for early prototypes). - The game index now accepts games with no public telnet/webclient info (for early prototypes).
#### New golden-layout based Webclient UI (@friarzen) #### New golden-layout based Webclient UI (@friarzen)
- Features - Features
@ -197,9 +201,9 @@ without arguments starts a full interactive Python console.
### Contribs ### Contribs
- Evscaperoom - a full puzzle engine for making multiplayer escape rooms in Evennia. Used to make - Evscaperoom - a full puzzle engine for making multiplayer escape rooms in Evennia. Used to make
the entry for the MUD-Coder's Guild's 2019 Game Jam with the theme "One Room", where it ranked #1. the entry for the MUD-Coder's Guild's 2019 Game Jam with the theme "One Room", where it ranked #1.
- Evennia game-index client no longer a contrib - moved into server core and configured with new - Evennia game-index client no longer a contrib - moved into server core and configured with new
setting `GAME_INDEX_ENABLED`. setting `GAME_INDEX_ENABLED`.
- The `extended_room` contrib saw some backwards-incompatible refactoring: - The `extended_room` contrib saw some backwards-incompatible refactoring:
+ All commands now begin with `CmdExtendedRoom`. So before it was `CmdExtendedLook`, now + All commands now begin with `CmdExtendedRoom`. So before it was `CmdExtendedLook`, now

View file

@ -223,7 +223,7 @@ def _run_code_snippet(caller, pycode, mode="eval", measure_time=False,
sys.stdout = old_stdout sys.stdout = old_stdout
sys.stderr = old_stderr sys.stderr = old_stderr
if not ret: if ret is None:
return return
for session in sessions: for session in sessions:

View file

@ -420,10 +420,11 @@ class AttributeHandler(object):
return_list (bool, optional): return_list (bool, optional):
Returns: Returns:
result (any or list): One or more matches for keys and/or categories. Each match will be result (any or list): One or more matches for keys and/or
the value of the found Attribute(s) unless `return_obj` is True, at which point it categories. Each match will be the value of the found Attribute(s)
will be the attribute object itself or None. If `return_list` is True, this will unless `return_obj` is True, at which point it will be the
always be a list, regardless of the number of elements. attribute object itself or None. If `return_list` is True, this
will always be a list, regardless of the number of elements.
Raises: Raises:
AttributeError: If `raise_exception` is set and no matching Attribute AttributeError: If `raise_exception` is set and no matching Attribute
@ -431,15 +432,6 @@ class AttributeHandler(object):
""" """
class RetDefault(object):
"""Holds default values"""
def __init__(self):
self.key = None
self.value = default
self.category = None
self.strvalue = str(default) if default is not None else None
ret = [] ret = []
for keystr in make_iter(key): for keystr in make_iter(key):
# it's okay to send a None key # it's okay to send a None key
@ -450,13 +442,12 @@ class AttributeHandler(object):
raise AttributeError raise AttributeError
elif return_obj: elif return_obj:
ret.append(None) ret.append(None)
else:
ret.append(RetDefault())
if accessing_obj: if accessing_obj:
# check 'attrread' locks # check 'attrread' locks
ret = [attr for attr in ret if attr.access(accessing_obj, ret = [attr for attr in ret if attr.access(accessing_obj,
self._attrread, default=default_access)] self._attrread,
default=default_access)]
if strattr: if strattr:
ret = ret if return_obj else [attr.strvalue for attr in ret if attr] ret = ret if return_obj else [attr.strvalue for attr in ret if attr]
else: else:
@ -464,9 +455,7 @@ class AttributeHandler(object):
if return_list: if return_list:
return ret if ret else [default] if default is not None else [] return ret if ret else [default] if default is not None else []
elif not ret: return ret[0] if ret and len(ret) == 1 else ret or default
return ret if len(key) > 1 else default
return ret[0] if len(ret) == 1 else ret
def add(self, key, value, category=None, lockstring="", def add(self, key, value, category=None, lockstring="",
strattr=False, accessing_obj=None, default_access=True): strattr=False, accessing_obj=None, default_access=True):