X-Git-Url: https://git.mdrn.pl/librarian.git/blobdiff_plain/387bff61a13e750e1ef4e015025415a8b311b25b..5bc29f19f308610c944d63597962fb3b0f468c54:/librarian/functions.py diff --git a/librarian/functions.py b/librarian/functions.py index 523b3d5..9490cbb 100644 --- a/librarian/functions.py +++ b/librarian/functions.py @@ -104,3 +104,17 @@ def reg_texcommand(): _register_function(texcommand) +def reg_get(format_): + def get(context, *args): + obj = format_ + for arg in args: + if hasattr(obj, arg): + obj = getattr(obj, arg) + else: + try: + obj = obj[arg] + except (TypeError, KeyError), e: + # Just raise proper AttributeError. + getattr(obj, arg) + return obj + _register_function(get)