Esempio n. 1
0
	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()
Esempio n. 2
0
	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()
Esempio n. 3
0
 def args_container(self):
     return one(self.xpath('BracedExpression'))
Esempio n. 4
0
 def name(self):
     return one(self.xpath('./Identifier'))
Esempio n. 5
0
	def args_body(self):
		return one(self.xpath('./CheetahVarBody'))
Esempio n. 6
0
	def args_container(self):
		return one(self.args_body.xpath('./CheetahVarNameChunks/CallArgString'))
Esempio n. 7
0
	def name(self):
		return one(self.args_body.xpath('./CheetahVarNameChunks/DottedName[1]'))
Esempio n. 8
0
 def args_container(self):
     return one(self.xpath('BracedExpression'))
Esempio n. 9
0
 def name(self):
     return one(self.xpath('./Identifier'))
Esempio n. 10
0
	def args_body(self):
		return one(self.xpath('./CheetahVarBody'))
Esempio n. 11
0
	def args_container(self):
		return one(self.args_body.xpath('./CheetahVarNameChunks/CallArgString'))
Esempio n. 12
0
	def name(self):
		return one(self.args_body.xpath('./CheetahVarNameChunks/DottedName[1]'))