예제 #1
0
	def graceful (self,tokeniser):
		token = tokeniser()
		if not token.isdigit():
			raise Raised("")

		duration = int(token)
		if duration < 0:
			raise Raised("")
		if duration > pow(2,16):
			raise Raised("")

		self.content[Capability.CODE.GRACEFUL_RESTART] = duration
		self._drop_colon(tokeniser)
예제 #2
0
파일: section.py 프로젝트: xw2060/exabgp
	def create_section (self, section, tokeniser):
		name = tokeniser()
		if name == '{':
			# syntax is set in our subclasses
			raise Raised(tokeniser,'was expecting section name',self.syntax)
		self.drop_parenthesis(tokeniser)
		return self.create_content(section,name,tokeniser)
예제 #3
0
 def create_content(self, section, name, tokeniser):
     storage = self.configuration[tokeniser.name][section][name]
     if storage:
         # syntax is set in our subclasses
         raise Raised(
             tokeniser, 'the section name %s/%s for %s is not unique' %
             (section, name, tokeniser.name), self.syntax)
     return storage
예제 #4
0
	def addpath (self,tokeniser):
		ap = tokeniser()
		if ap not in ('receive','send','send/receive','disable','disabled'):
			raise Raised("")

		self.content[Capability.CODE.ADD_PATH] = 0
		if ap.endswith('receive'):
			self.content[Capability.CODE.ADD_PATH] += 1
		if ap.startswith('send'):
			self.content[Capability.CODE.ADD_PATH] += 2

		self._drop_colon(tokeniser)
예제 #5
0
파일: section.py 프로젝트: xw2060/exabgp
	def get_section (self, section, tokeniser):
		name = tokeniser()

		if name == '{':
			tokeniser.rewind(name)
			tokeniser.rewind('anonymous')
			return None

		storage = self.configuration[tokeniser.name][section][name]
		if storage is None:
			# syntax is set in our subclasses
			raise Raised(tokeniser,'the section name %s referenced does not exists' % name,self.syntax)
		return storage
예제 #6
0
	def content (self,producer):
		try:
			while True:
				self.idx_line,self.idx_column,self.line,token = producer()
				if token == '[':
					returned = []
					for token in self.iterate_list(producer):
						returned.append((self.idx_line,self.idx_column,self.line,token))
					return returned
				elif token[0] in ('"',"'"):
					return unescape(token[1:-1])
				else:
					return token
		except ValueError:
			raise Raised(Location(self.idx_line,self.idx_column,self.line),'Could not parse %s' % str(token))
		except StopIteration:
			return None
예제 #7
0
파일: registry.py 프로젝트: PowerDNS/exabgp
	def handle (self,tokeniser):
		# each section can registered named configuration for reference here
		Section.configuration[tokeniser.name] = defaultdict(dictdict)

		def run (search,section,location):
			key = '/'.join(search)
			function = self._handler.get(key,{}).get(section,None)

			if function:
				print 'hit %s/%s' % (key,section)
				instance = self._klass.setdefault(function.im_class,function.im_class())
				instance.location = location
				return function(instance,tokeniser) is None
			return False

		while True:
			token = tokeniser()
			if not token: break

			# if we have both a section and a action, try the action first
			if run(self.stack+[token,],'action',self.stack+[token]):
				continue

			if run(self.stack + [token,],'enter',self.stack):
				self.stack.append(token)
				continue

			if token != '}':
				print
				print 'Available paths are .....'
				print
				for path in sorted(self._handler):
					for action in sorted(self._handler[path]):
						print '/%-40s %s' % (path,action)
				print '....'
				print
				print self.stack+[token,]
				# we need the line and position at this level
				raise Raised(tokeniser,'no parser for the location /%s' % ('/'.join(self.stack+[token,])))

			if run(self.stack,'exit',self.stack[:-1]):
				self.stack.pop()
				continue

			# we need the line and position at this level
			raise Exception('application error, no exit code registered for %s, please report with your configuration' % '/'.join(self.stack))
예제 #8
0
파일: section.py 프로젝트: xw2060/exabgp
	def enter_anonymous (self, tokeniser):
		token = tokeniser()
		if token != '{':
			# syntax is set in our subclasses
			raise Raised(tokeniser,'was expecting {',self.syntax)
		self.content = self.create_content(self.name,'anonymous',tokeniser)
예제 #9
0
파일: section.py 프로젝트: xw2060/exabgp
	def enter_nameless (self, tokeniser):
		token = tokeniser()
		if token != '{':
			# syntax is set in our subclasses
			raise Raised(tokeniser,'was expecting {',self.syntax)
예제 #10
0
파일: section.py 프로젝트: xw2060/exabgp
	def drop_parenthesis (self, tokeniser):
		if tokeniser() != '{':
			# syntax is set in our subclasses
			raise Raised(tokeniser,'missing opening parenthesis "{"',self.syntax)
예제 #11
0
	def _check_duplicate (self,key):
		if key in self.content:
			raise Raised("")
예제 #12
0
	def enter (self,tokeniser):
		token = tokeniser()
		if token != '{':
			raise Raised(self.syntax)
		self.content = dict()