当前位置: 首页>>代码示例>>Python>>正文


Python Output.send方法代码示例

本文整理汇总了Python中output.Output.send方法的典型用法代码示例。如果您正苦于以下问题:Python Output.send方法的具体用法?Python Output.send怎么用?Python Output.send使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在output.Output的用法示例。


在下文中一共展示了Output.send方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: handler

# 需要导入模块: from output import Output [as 别名]
# 或者: from output.Output import send [as 别名]
class handler(object):
	def __init__(self, endpoint):
		log.debug('Constructed new extra.irc.server.handler')
		self.endpoint = endpoint
		self.out = Output(self.endpoint.sendLine)
		self.uplinkAuthed = False

	def ident(self):
		log.debug("Starting server ident")
		self.out.send("PASS {0} :TS".format(Config.password('uplink_send')))
		self.out.send("CAPAB :ENCAP EX IE HOPS SVS CHW QS EOB KLN GLN KNOCK UNKLN DLN UNDLN")
		self.out.send("SID {0} 1 {1} :{2}".format(Config.hostname, Config.token, Config.info))
		self.out.send("SERVER {0} 1 :{1}".format(Config.hostname, Config.info))
		self.out.send("SVINFO 6 5 0 :{0}".format(time()))
		log.debug("Completed server ident")

	def __getattr__(self, name):
		def unhandled(line):
			log.notice("{0} UNHANDLED > {1}".format(name, line))
		return unhandled

	def handleLine(self, line):
		try:
			getattr(self, line.cmd)(line)
		except UplinkNotAuthedError:
			log.error('Uplink server is not authenticated for {0} from {1}'.format(line.cmd, line.prefix))

	def checkUplinkAuthed(self):
		if self.uplinkAuthed:
			log.debug3('Server is authenticated')
		else:
			raise UplinkNotAuthedError()

	def ERROR(self, line):
		log.fatal("Received ERROR line: {0}".format(line.text))
		sys.exit(1)

	def PING(self, line):
		self.out.send("PONG :{0}".format(line.text))

	def AWAY(self, line):
		log.debug2('Got AWAY')

	def EOB(self, line):
		log.debug2("Got EOB")
		self.checkUplinkAuthed()

	def PASS(self, line):
		log.debug2("Got PASS")
		if line.prefix is None:
			log.info("Checking PASS from uplink server")
			if line.args[0] != Config.password('uplink_accept'):
				raise Exception('Uplink server supplied invalid password')
			else:
				log.info('Uplink server PASS OK')
				self.uplinkAuthed = True
		else:
			log.debug1('Got PASS from {0}'.format(line.prefix))

	def SERVER(self, line):
		log.debug2("Got SERVER")
		self.checkUplinkAuthed()
		self.endpoint.state.servers.add(name=line.args[0], token=line.args[1], desc=line.text)
		if line.prefix is None:
			self.endpoint.uplinkServer = line.args[0]
		log.debug2('Finished SERVER handling')

	def NICK(self, line):
		log.debug2('Got NICK line')
		self.checkUplinkAuthed()
		if line.prefix is None or self.endpoint.state.isServer(line.prefix):
			self.endpoint.state.nicks.add(
				nick=line.args[0],
				user=line.args[4],
				host=line.args[5],
				server=line.args[6],
				modes=line.args[3][1:],
				realname=line.text
			)
		elif self.endpoint.state.isNick(line.args[0]):
			self.endpoint.state.changeNick(line.handle.nick, line.args[0])
		else:
			log.warning('Input to NICK is an unhandled condition')
		log.debug2('Finished NICK handling')

	def SJOIN(self, line):
		log.debug2('Got SJOIN')
		self.checkUplinkAuthed()

		chan = line.args[1]
		cmodes = line.args[2][1:]
		newchan = {'channel':chan, 'modes':cmodes, 'mode_k':'', 'mode_l':''}

		# handle mode args
		mode_args = collections.deque(line.args[3:] + ['',''])
		for modechar in cmodes:
			if modechar in 'kl':
				newchan['mode_' + modechar] = mode_args.popleft()
			elif modechar in 'ohvbeI':
				raise Exception('List mode in SJOIN')
#.........这里部分代码省略.........
开发者ID:ashafer01,项目名称:ExtraIRC,代码行数:103,代码来源:serverHandler.py


注:本文中的output.Output.send方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。