def remove_call(self): args_body = self.args_body args_container = one(args_body.xpath('./CheetahVarNameChunks/CallArgString')) args = self.args if not args: # no arguments. assert args_container.totext().strip('(\n\t )') == '', args_container.totext() self.remove_self() return if len(args) == 1 and ( args[0].tag == 'CheetahVar' or ( args[0].tag == 'Py' and len(args[0].text) >= 2 and args[0].text[0] == args[0].text[-1] and args[0].text[0] in '"'"'" ) ): #just one cheetah var / Python string arg = args[0] self.replace_self(arg) # replace the right paren with whatever followed the `self` token assert arg.tail.strip() == ')', repr(arg.tostring()) arg.tail = self.tail elif ( # Python tokens without spaces all(arg.tag == 'Py' for arg in args) and all(arg.tail == '' for arg in args[:-1]) and args[-1].tail.strip() == ')' ): #just one Python variable. #replace the call with just the arg (keep the $) namechunks = one(args_body.xpath('./CheetahVarNameChunks')) namechunks.clear() namechunks.extend(args) args[-1].tail = '' else: #there's something more complicated here. #just remove the method name (keep the $()) self.name.remove_self()
def args_container(self): return one(self.xpath('BracedExpression'))
def name(self): return one(self.xpath('./Identifier'))
def args_body(self): return one(self.xpath('./CheetahVarBody'))
def args_container(self): return one(self.args_body.xpath('./CheetahVarNameChunks/CallArgString'))
def name(self): return one(self.args_body.xpath('./CheetahVarNameChunks/DottedName[1]'))