Skip to content

Commit

Permalink
made getattr() logic more explicit - could lead the way to on-the-fly…
Browse files Browse the repository at this point in the history
… tree building later
  • Loading branch information
mahtin committed Aug 23, 2022
1 parent f96d558 commit 7c25e8b
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions CloudFlare/cloudflare.py
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,7 @@ def add(self, t, p1, p2=None, p3=None, p4=None, p5=None):
branch = getattr(branch, element.replace('-','_'))
else:
branch = getattr(branch, element)
except:
except AttributeError:
# missing path - should never happen unless api_v4 is a busted file
branch = None
break
Expand Down Expand Up @@ -916,7 +916,11 @@ def api_list(self, m=None, s=''):
if n in ['delete', 'get', 'patch', 'post', 'put']:
# gone too far
continue
a = getattr(m, n)
try:
a = getattr(m, n)
except AttributeError:
# really should not happen!
raise CloudFlareAPIError(0, '%s: not found - should not happen' % (n))
d = dir(a)
if '_base' in d:
# it's a known api call - lets show the result and continue down the tree
Expand All @@ -934,6 +938,7 @@ def api_list(self, m=None, s=''):
# handle underscores by returning the actual API call vs the method name
w.append(str(a)[1:-1])
## w.append(str(a)[1:-1].replace('/:id/','/'))
# now recurse downwards into the tree
w = w + self.api_list(a, s + '/' + n)
return w

Expand Down Expand Up @@ -1032,3 +1037,12 @@ def __repr__(self):
self._base.base_url, self._base.raw, self._base.user_agent
)
return s

def __getattr__(self, key):
""" __getattr__ """

# this code will expand later
if key in dir(self):
return self[key]
# this is call to a non-existent endpoint
raise AttributeError(key)

0 comments on commit 7c25e8b

Please sign in to comment.