X-Git-Url: https://git.mdrn.pl/librarian.git/blobdiff_plain/d9dc96ea261fdeed57bbb57c4405003893668d8d..fe8e5b5e224d32baebbdaa2fecf4a847ed4e5354:/librarian/functions.py diff --git a/librarian/functions.py b/librarian/functions.py index e91d7e1..40f06cd 100644 --- a/librarian/functions.py +++ b/librarian/functions.py @@ -115,3 +115,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)