Пример #1
0
	def run(self):
		while(True):
			func,args=self._queue.put()
			try:
				func(*args)
			except Exception,e:
				printf('Exception in task thread traceback: %s'%str(e))
			self._queue.task_done()
	def __RegisterHandlers(self):
		printf('Registry handlers')
		self.XMPP.registerHandler("iq",self.__Iq)
		self.XMPP.registerHandler("message",self.__Message)
	def _connection(self):
		self.stage.emit(1)
		printf('Connection established',FLAG_SUCESS)
		self.XMPP=client.Client(self._config.host(),self._config.port(),bind=self)
		if not self.XMPP.connect(self._config.ssl(),self._config.resolver()):
			self.streamError.emit(0x1)
			printf("Connection isn't possible",FLAG_WARNING)
			return False
		printf("Connection is established",FLAG_SUCESS)
		self.stage.emit(2)
		if not self.XMPP.auth(self._config.user(),self._config.password(),self._config.resource()):
			self.streamError.emit(0x2)
			printf("Authentification error",FLAG_WARNING)
			return False
		printf("Authentification is successful",FLAG_SUCESS)
		self.stage.emit(3)
		self.XMPP.setStatus(None, None,self._config.priority())
		printf('Set status and priority %d'%self._config.priority())
		return True
	def run(self):
		printf('Starting connertion thred of %s'%str(self))
		self.setPriority(self.HighestPriority)
		if self._connection():
			printf('Connection established',FLAG_SUCESS)
			self._RegisterHandlers()
			self.connected.emit()
			try:
				while self.XMPP.process(5):
					pass
				self.disconnected.emit()
				printf('Disconnected')
			except protocol.Conflict:
				self.streamError.emit(0x3)
				printf('Resources conflict',FLAG_WARNING)
			except protocol.SystemShutdown:
				printf('The remote server shutdown',FLAG_WARNING)
				self.streamError.emit(0x4)
			except protocol.StreamError,e:
				self.dropConnection()
				printf('Exception of stream %s'%str(e),FLAG_ERROR)
			except Exception:
				self.streamError.emit(0xF)
				printf('Exception in Thread: %s traceback : %s '%(str(self),traceback.format_exc()),FLAG_ERROR)
			def __call__(self,*args):
				self.response.emit(args)
				printf('Emit response iq of %s'%str(self))
					pass
				self.disconnected.emit()
				printf('Disconnected')
			except protocol.Conflict:
				self.streamError.emit(0x3)
				printf('Resources conflict',FLAG_WARNING)
			except protocol.SystemShutdown:
				printf('The remote server shutdown',FLAG_WARNING)
				self.streamError.emit(0x4)
			except protocol.StreamError,e:
				self.dropConnection()
				printf('Exception of stream %s'%str(e),FLAG_ERROR)
			except Exception:
				self.streamError.emit(0xF)
				printf('Exception in Thread: %s traceback : %s '%(str(self),traceback.format_exc()),FLAG_ERROR)
		printf('Thread is terminating')
	def _connection(self):
		self.stage.emit(1)
		printf('Connection established',FLAG_SUCESS)
		self.XMPP=client.Client(self._config.host(),self._config.port(),bind=self)
		if not self.XMPP.connect(self._config.ssl(),self._config.resolver()):
			self.streamError.emit(0x1)
			printf("Connection isn't possible",FLAG_WARNING)
			return False
		printf("Connection is established",FLAG_SUCESS)
		self.stage.emit(2)
		if not self.XMPP.auth(self._config.user(),self._config.password(),self._config.resource()):
			self.streamError.emit(0x2)
			printf("Authentification error",FLAG_WARNING)
			return False
		printf("Authentification is successful",FLAG_SUCESS)