本文整理汇总了Python中SyncController.SyncController.request方法的典型用法代码示例。如果您正苦于以下问题:Python SyncController.request方法的具体用法?Python SyncController.request怎么用?Python SyncController.request使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SyncController.SyncController
的用法示例。
在下文中一共展示了SyncController.request方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Shop
# 需要导入模块: from SyncController import SyncController [as 别名]
# 或者: from SyncController.SyncController import request [as 别名]
class Shop(object):
def __init__(self):
self.__account = None
self.__syncController = None
self.__cache = {}
self.__persistentCache = SimpleCache('account_caches', 'shop')
self.__ignore = True
self.__isSynchronizing = False
self.__syncID = 0
self.__isFirstSync = True
return
def onAccountBecomePlayer(self):
self.__ignore = False
self.__isFirstSync = True
self.synchronize()
def onAccountBecomeNonPlayer(self):
self.__ignore = True
self.__isSynchronizing = False
def setAccount(self, account):
self.__account = account
self.__persistentCache.setAccount(account)
if self.__syncController is not None:
self.__syncController.destroy()
self.__syncController = None
if account is not None:
self.__syncController = SyncController(account, self.__sendSyncRequest, self.__onSyncResponse, self.__onSyncComplete)
return
def synchronize(self, serverCacheRev = None):
LOG_DEBUG('Shop.synchronize: cli_rev=%s, serv_rev=%s' % (self.__getCacheRevision(), serverCacheRev))
if self.__ignore:
return
elif self.__getCacheRevision() == serverCacheRev:
return
elif self.__isSynchronizing:
return
else:
self.__isSynchronizing = True
if not self.__isFirstSync:
events.onShopResyncStarted()
self.__syncController.request(self.__getNextSyncID(), None)
return
def resynchronize(self):
LOG_DEBUG('resynchronize')
if self.__ignore:
return
else:
self.__cache.clear()
self.__persistentCache.clear()
self.__isSynchronizing = True
self.__isFirstSync = False
events.onShopResyncStarted()
self.__syncController.request(self.__getNextSyncID(), None)
return
def waitForSync(self, callback):
if self.__ignore:
if callback is not None:
callback(AccountCommands.RES_NON_PLAYER, None)
return
elif not self.__isSynchronizing:
callback(AccountCommands.RES_CACHE, self.__getCacheRevision())
return
else:
proxy = lambda resultID, data: callback(resultID, self.__getCacheRevision())
self.__syncController.request(self.__syncID, proxy)
return
def getCache(self, callback):
self.__getValue(None, callback)
return
def getAllItems(self, callback):
self.__getValue('items', callback)
def getSellPriceModifiers(self, compDescr, callback):
proxy = lambda resultID, _data, rev: self.__onGetSellPriceModifiers(resultID, compDescr, callback)
self.__getValue('sellPriceModif', proxy)
def getSellPrice(self, buyPrice, sellPriceModifiers, itemTypeID):
shopRev, exchangeRate, exchangeRateForShellsAndEqs, sellPriceModif, sellPriceFactor, sellForGold = sellPriceModifiers
if not shopRev == self.__getCacheRevision():
raise AssertionError
if itemTypeID in (_SHELL, _EQUIPMENT):
exchangeRate = exchangeRateForShellsAndEqs
sellPrice = sellForGold and (int(ceil(sellPriceFactor * buyPrice[0])), int(ceil(sellPriceFactor * buyPrice[1])))
else:
sellPrice = (int(ceil(sellPriceFactor * (buyPrice[0] + buyPrice[1] * exchangeRate))), 0)
return sellPrice
def getPrice(self, typeCompDescr, callback):
proxy = lambda resultID, items, rev: self.__onGetPriceResponse(resultID, typeCompDescr, callback)
self.__getValue('items', proxy)
def getRentPackets(self, typeCompDescr, callback):
#.........这里部分代码省略.........
示例2: AccountSyncData
# 需要导入模块: from SyncController import SyncController [as 别名]
# 或者: from SyncController.SyncController import request [as 别名]
class AccountSyncData(object):
def __init__(self):
self.revision = 0
self.__account = None
self.__syncController = None
self.__ignore = True
self.__isSynchronized = False
self.__syncID = 0
self.__subscribers = []
self.__isFirstSync = True
self.__persistentCache = SimpleCache('account_caches', 'data')
self.__persistentCache.data = None
self.__persistentCache.isDirty = False
return
def onAccountBecomePlayer(self):
self.__ignore = False
self.__isFirstSync = True
self._synchronize()
def onAccountBecomeNonPlayer(self):
self.__ignore = True
self.__isSynchronized = False
def setAccount(self, account):
self.__account = account
if self.__syncController is not None:
self.__syncController.destroy()
self.__syncController = None
self.__savePersistentCache()
if account is not None:
oldName = self.__persistentCache.getAccountName()
raise oldName is None or oldName == account.name or AssertionError
self.__persistentCache.setAccountName(account.name)
self.__syncController = SyncController(account, self.__sendSyncRequest, self.__onSyncResponse, self.__onSyncComplete)
return
def waitForSync(self, callback):
if self.__ignore:
if callback is not None:
callback(AccountCommands.RES_NON_PLAYER)
return
elif self.__isSynchronized:
callback(AccountCommands.RES_CACHE)
return
else:
if callback is not None:
self.__subscribers.append(callback)
return
def updatePersistentCache(self, ext, isFullSync):
if ext.pop('__cache', None) is not None:
if not self.__persistentCache.data:
desc, cacheData = self.__persistentCache.data = self.__persistentCache.get()
if accountDataPersistentHash(cacheData) != desc:
LOG_ERROR('Local account data cache is corrupted: resync')
self._resynchronize()
return False
self.__persistentCache.data = cacheData
self.__persistentCache.isDirty = False
else:
cacheData = self.__persistentCache.data
if cacheData is None:
LOG_ERROR("Incorrect cache state while syncing data: server said to use cache but I don't have any")
self._resynchronize()
return False
accountDataMergePersistent(ext, cacheData)
if synchronizeDicts(accountDataGetDiffForPersistent(ext), self.__persistentCache.data)[1]:
self.__persistentCache.isDirty = True
else:
if self.__persistentCache.data is None:
self.__persistentCache.data = {}
synchronizeDicts(accountDataGetDiffForPersistent(ext), self.__persistentCache.data)
self.__persistentCache.isDirty = True
return True
def _synchronize(self):
if self.__ignore:
return
elif self.__isSynchronized:
return
else:
self.__syncController.request(self.__getNextSyncID(), None)
return
def _resynchronize(self):
LOG_MX('resynchronize')
if self.__ignore:
return
else:
self.__isSynchronized = False
self.revision = 0
self.__clearPersistentCache()
self.__syncController.request(self.__getNextSyncID(), None)
return
def __onSyncResponse(self, syncID, resultID, ext = {}):
if resultID == AccountCommands.RES_NON_PLAYER:
return
#.........这里部分代码省略.........
示例3: DossierCache
# 需要导入模块: from SyncController import SyncController [as 别名]
# 或者: from SyncController.SyncController import request [as 别名]
class DossierCache(object):
def __init__(self, accountName):
self.__account = None
self.__syncController = None
p = os.path
prefsFilePath = unicode(BigWorld.wg_getPreferencesFilePath(), 'utf-8', errors='ignore')
self.__cacheDir = p.join(p.dirname(prefsFilePath), 'dossier_cache')
self.__cacheFileName = p.join(self.__cacheDir, '%s.dat' % base64.b32encode('%s;%s' % (str(BigWorld.server()), accountName)))
self.__cache = {}
self.__maxChangeTime = 0
self.__version = 0
self.__ignore = True
self.__isSynchronizing = False
self.__syncID = 0
self.__isFirstSync = True
self.__readCache()
return
def onAccountBecomePlayer(self):
self.__ignore = False
self.__isFirstSync = True
self.synchronize()
def onAccountBecomeNonPlayer(self):
self.__ignore = True
self.__isSynchronizing = False
def setAccount(self, account):
self.__account = account
if self.__syncController is not None:
self.__syncController.destroy()
self.__syncController = None
if account is not None:
self.__syncController = SyncController(account, self.__sendSyncRequest, self.__onSyncResponse, self.__onSyncComplete)
return
def synchronize(self):
if self.__ignore:
return
elif self.__isSynchronizing:
return
else:
self.__isSynchronizing = True
self.__syncController.request(self.__getNextSyncID(), None)
return
def resynchronize(self):
LOG_DEBUG('resynchronize', self.__maxChangeTime)
if self.__ignore:
return
else:
self.__isSynchronizing = True
self.__syncController.request(self.__getNextSyncID(), None)
return
def waitForSync(self, callback):
if self.__ignore:
if callback is not None:
callback(AccountCommands.RES_NON_PLAYER, None)
return
elif not self.__isSynchronizing:
callback(AccountCommands.RES_CACHE)
return
else:
proxy = lambda resultID, data: callback(resultID)
self.__syncController.request(self.__syncID, proxy)
return
def get(self, dossierType, ownerID, callback = None):
getter = lambda cache: cache.get((dossierType, ownerID), (0, ''))[1]
self.__get(getter, '', callback)
def getCache(self, callback = None):
getter = lambda cache: cache
self.__get(getter, None, callback)
return
def __get(self, getterFromCache, default, callback):
if self.__ignore:
if callback is not None:
callback(AccountCommands.RES_NON_PLAYER, default)
return
elif not self.__isSynchronizing:
self.__onGetResponse(AccountCommands.RES_CACHE, getterFromCache, default, callback)
return
else:
proxy = lambda resultID, data: self.__onGetResponse(resultID, getterFromCache, default, callback)
self.__syncController.request(self.__syncID, proxy)
return
def __onSyncResponse(self, syncID, resultID, ext = {}):
if resultID == AccountCommands.RES_NON_PLAYER:
return
if syncID != self.__syncID:
return
if resultID < 0:
LOG_ERROR('Dossier synchronization failed. Repeating')
self.resynchronize()
return
#.........这里部分代码省略.........
示例4: AccountSyncData
# 需要导入模块: from SyncController import SyncController [as 别名]
# 或者: from SyncController.SyncController import request [as 别名]
class AccountSyncData(object):
def __init__(self):
self.revision = 0
self.__account = None
self.__syncController = None
self.__ignore = True
self.__isSynchronized = False
self.__syncID = 0
self.__subscribers = []
self.__isFirstSync = True
return
def onAccountBecomePlayer(self):
self.__ignore = False
self.__isFirstSync = True
self._synchronize()
def onAccountBecomeNonPlayer(self):
self.__ignore = True
self.__isSynchronized = False
def setAccount(self, account):
self.__account = account
if self.__syncController is not None:
self.__syncController.destroy()
self.__syncController = None
if account is not None:
self.__syncController = SyncController(account, self.__sendSyncRequest, self.__onSyncResponse, self.__onSyncComplete)
return
def waitForSync(self, callback):
if self.__ignore:
if callback is not None:
callback(AccountCommands.RES_NON_PLAYER)
return
elif self.__isSynchronized:
callback(AccountCommands.RES_CACHE)
return
else:
if callback is not None:
self.__subscribers.append(callback)
return
def _synchronize(self):
if self.__ignore:
return
elif self.__isSynchronized:
return
else:
self.__syncController.request(self.__getNextSyncID(), None)
return
def _resynchronize(self):
LOG_MX('resynchronize')
if self.__ignore:
return
else:
self.__isSynchronized = False
self.revision = 0
self.__syncController.request(self.__getNextSyncID(), None)
return
def __onSyncResponse(self, syncID, resultID, ext = {}):
if resultID == AccountCommands.RES_NON_PLAYER:
return
if syncID != self.__syncID:
return
if resultID < 0:
LOG_ERROR('Data synchronization failed.')
self._resynchronize()
return
if self.revision != ext.get('prevRev', self.revision):
LOG_ERROR('Incorrect diff received', self.revision, ext['prevRev'])
self._resynchronize()
return
self.revision = ext.get('rev', self.revision)
self.__isSynchronized = True
self.__account._update(not self.__isFirstSync, ext)
self.__isFirstSync = False
subscribers = self.__subscribers
self.__subscribers = []
for callback in subscribers:
callback(resultID)
def __onSyncComplete(self, syncID, data):
if syncID != self.__syncID:
return
elif data is None:
return
else:
self.revision = data['rev']
self.__account._update(False, data)
self._synchronize()
return
def __getNextSyncID(self):
self.__syncID += 1
if self.__syncID > 30000:
self.__syncID = 1
#.........这里部分代码省略.........