From 7f81985911721115566e5516bb34e7b2c80c2165 Mon Sep 17 00:00:00 2001 From: Alexander Graf Date: Sat, 4 Aug 2018 11:39:43 +0200 Subject: [PATCH] _ArbitraryItemFormatter: Allow chaining attributes Override get_value() rather than get_field(), to allow chaining of item attributes, such as --post-metadata-txt={owner_profile.profile_pic_url}. Motivated by #151. --- instaloader/instaloader.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/instaloader/instaloader.py b/instaloader/instaloader.py index 41d819f..36a2367 100644 --- a/instaloader/instaloader.py +++ b/instaloader/instaloader.py @@ -49,11 +49,11 @@ class _ArbitraryItemFormatter(string.Formatter): def __init__(self, item: Any): self._item = item - def get_field(self, field_name, args, kwargs): + def get_value(self, key, args, kwargs): """Override to substitute {ATTRIBUTE} by attributes of our _item.""" - if hasattr(self._item, field_name): - return self._item.__getattribute__(field_name), None - return super().get_field(field_name, args, kwargs) + if hasattr(self._item, key): + return getattr(self._item, key) + return super().get_value(key, args, kwargs) def format_field(self, value, format_spec): """Override :meth:`string.Formatter.format_field` to have our