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


Python YowsupConnectionManager.disconnect方法代码示例

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


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

示例1: __init__

# 需要导入模块: from Yowsup.connectionmanager import YowsupConnectionManager [as 别名]
# 或者: from Yowsup.connectionmanager.YowsupConnectionManager import disconnect [as 别名]
class WWMCore:
	def __init__(self):
		
		self.connectionManager = YowsupConnectionManager()
		self.connectionManager.setAutoPong(Config.keepAlive)

		self.signalsInterface = self.connectionManager.getSignalsInterface()
		self.methodsInterface = self.connectionManager.getMethodsInterface()
		
		self.yowsupRanOnce = 0
		
		self.listener = None
		self.sender	= None
		self.session = None
		self.httpRequestHandler = None
		self.instanceId = None
		self.status = Constants.INSTANCESTATUS_INITED
		
		self.dbi = DBI() #Use this for HTTP requests only. For every other case, Go ahead and create a different connection for now
		self.callbackDBI = CallbackDBI()	#Extra care for preventing interference
		#self.dbiCursor = None
		self.yowsupStarted = 0
	
	#Just to keep track of the instances created
	def registerInstance(self, procId):
		timeNow = time.time()
		procId = os.getpid()
		status = Constants.INSTANCESTATUS_STARTED
		authStatus = Constants.AUTHSTATUS_IDLE
		self.dbiCursor.execute("INSERT INTO pythoninstances (phone, procId, lastUpdated,status, authStatus) VALUES(%s, %s, %s, %s)", (self.session.phone, procId, timeNow, status,authStatus))
		#self.instanceId = 

	def genAESKey(self, str):
		#md5 hash of reverse of str
		return hashlib.md5(str[::-1]).hexdigest()
	
		
	def initSender(self):
		if self.sender==None:
			self.sender= Sender(self)
		
	def initListener(self):
		if self.listener==None:
			self.listener = Listener(self)
	
	#deprecated
	def initDBI(self):
		print "Call to Core.initDBI which is deprecated"
		'''
		try:
			self.dbi = MySQLdb.connect('localhost','root','','webwhatsapp')
			self.dbiCursor = self.dbi.cursor(MySQLdb.cursors.DictCursor)
		except MySQLdb.Error, e:
			raise WWMException("MySQL could not connect: %s" %e)
		'''
		
	def getDBICursor(self): #returns dbi and cursor
		return self.dbiCursor
	
	#This method is called from session
	def initSession(self, phone, AESKey):
		print "Core.initSession called"
		if self.session == None or self.session.authStatus == Constants.AUTHSTATUS_IDLE:	#self.yowsupStarted==0 and 
			self.yowsupStarted = 1
			if self.session == None:
				self.session = Session(self, phone, AESKey)
				self.session.getAuthData()
				self.signalsInterface.registerListener("disconnected", self.onDisconnected) 
			self.session.login()
		else:
			print "\nPretty sure yowsup is already started."
	
	def authCallback(self,isSuccess):	#Called manually from Session
		if isSuccess:
			self.yowsupRanOnce==1 #Very important flag
			
			#This is done earlier in initSession with the above flag to differentiate between pre auth disco and post auth disco
			#self.signalsInterface.registerListener("disconnected", self.onDisconnected) 
			
			self.status = Constants.INSTANCESTATUS_RUNNING
			self.yowsupStarted=1
		else:
			self.yowsupStarted= 0
	
	def onDisconnected(self, reason):
		print "Core.onDisconnected called"
		
		if self.status==Constants.INSTANCESTATUS_WRAPPEDUP:
			print "Core.onDisconnected: Disconnected and wrapping up"
			return #And die
		
		
		self.yowsupStarted = 0
		self.session.authStatus = Constants.AUTHSTATUS_IDLE
		#self.session.updateAuthStatus(Constants.AUTHSTATUS_IDLE)
		
		
		if self.yowsupRanOnce==0:
			print "Could not connect. Rerun startYowsup to try again"
			return
#.........这里部分代码省略.........
开发者ID:akshayah3,项目名称:webwhatsapp,代码行数:103,代码来源:Core.py


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