@@ -855,14 +855,20 @@ def add(self, t, p1, p2=None, p3=None):
855855 branch = self
856856 for element in a [0 :- 1 ]:
857857 try :
858- branch = getattr (branch , element )
858+ if '-' in element :
859+ branch = getattr (element , element .replace ('-' ,'_' ))
860+ else :
861+ branch = getattr (branch , element )
859862 except :
860863 # should never happen
861864 raise CloudFlareAPIError (0 , 'api load name failed' )
862865 name = a [- 1 ]
863866
864867 try :
865- f = getattr (branch , name )
868+ if '-' in name :
869+ f = getattr (element , name .replace ('-' ,'_' ))
870+ else :
871+ f = getattr (branch , name )
866872 # already exists - don't let it overwrite
867873 raise CloudFlareAPIError (0 , 'api duplicate name found: %s/**%s**' % ('/' .join (a [0 :- 1 ]), name ))
868874 except AttributeError :
@@ -886,7 +892,8 @@ def add(self, t, p1, p2=None, p3=None):
886892 if '-' in name :
887893 # dashes (vs underscores) cause issues in Python and other languages
888894 setattr (branch , name .replace ('-' ,'_' ), f )
889- setattr (branch , name , f )
895+ else :
896+ setattr (branch , name , f )
890897
891898 def api_list (self , m = None , s = '' ):
892899 """recursive walk of the api tree returning a list of api calls"""
@@ -907,7 +914,8 @@ def api_list(self, m=None, s=''):
907914 if 'delete' in d or 'get' in d or 'patch' in d or 'post' in d or 'put' in d :
908915 # only show the result if a call exists for this part
909916 if '_parts' in d :
910- w .append (s + '/' + n )
917+ # handle underscores by returning the actual API call vs the method name
918+ w .append (str (a )[1 :- 1 ].replace ('/:id/' ,'/' ))
911919 w = w + self .api_list (a , s + '/' + n )
912920 return w
913921
0 commit comments