Best Python code snippet using yandex-tank
anonymizer_controller.py
Source:anonymizer_controller.py
1# Python bytecode 2.7 (decompiled from Python 2.7)2# Embedded file name: scripts/client/gui/game_control/anonymizer_controller.py3import logging4import BigWorld5from Event import Event6from gui import SystemMessages7from gui.ClientUpdateManager import g_clientUpdateManager8from gui.impl import backport9from gui.impl.gen import R10from gui.anonymizer.contacts_uploader import ContactsUploader11from helpers import dependency12from skeletons.gui.game_control import IAnonymizerController13from skeletons.gui.lobby_context import ILobbyContext14from skeletons.gui.shared import IItemsCache15_logger = logging.getLogger(__name__)16_RSettingsError = R.strings.messenger.server.errors.settingError17class AnonymizerController(IAnonymizerController):18 __lobbyContext = dependency.descriptor(ILobbyContext)19 __itemsCache = dependency.descriptor(IItemsCache)20 __slots__ = ('__isEnabled', '__isRestricted', '__isAnonymized', '__isInBattle', '__uploader')21 def __init__(self):22 self.onStateChanged = Event()23 self.__isEnabled = False24 self.__isRestricted = False25 self.__isAnonymized = False26 self.__isInBattle = False27 self.__uploader = ContactsUploader()28 def onConnected(self):29 self.__uploader.init()30 def onDisconnected(self):31 self.__uploader.fini()32 self.__clear()33 def onLobbyInited(self, _):34 self.__isInBattle = False35 self.__addListeners()36 self.__update()37 def onAvatarBecomePlayer(self):38 self.__removeListeners()39 self.__isInBattle = True40 def onAccountBecomeNonPlayer(self):41 if self.__uploader.isProcessing:42 _logger.info('contacts uploader stopping because of onAccountBecomeNonPlayer.')43 self.__uploader.stop()44 @property45 def isInBattle(self):46 return self.__isInBattle47 @property48 def isEnabled(self):49 return self.__isEnabled50 @property51 def isRestricted(self):52 return self.__isRestricted53 @property54 def isAnonymized(self):55 return self.__isEnabled and self.__isAnonymized56 def setAnonymized(self, value):57 if self.isEnabled and not self.isRestricted:58 if value != self.__isAnonymized:59 self.__isAnonymized = value60 BigWorld.player().anonymizer.setAnonymized(self.__isAnonymized, self.__onSetAnonymizedResponse)61 else:62 self.__pushChangeUnavailableMessage()63 def __addListeners(self):64 g_clientUpdateManager.addCallbacks({'cache.SPA': self.__onCacheSPAChanged,65 'anonymizer.enabled': self.__onAnonymizedStateChanged,66 'anonymizer.contactsFeedback': self.__onContactsFeedback})67 self.__lobbyContext.getServerSettings().onServerSettingsChange += self.__onServerSettingsChanged68 def __removeListeners(self):69 self.__lobbyContext.getServerSettings().onServerSettingsChange -= self.__onServerSettingsChanged70 g_clientUpdateManager.removeObjectCallbacks(self)71 def __update(self):72 self.__isEnabled = self.__lobbyContext.getServerSettings().isAnonymizerEnabled()73 self.__isRestricted = self.__itemsCache.items.stats.isAnonymousRestricted74 self.__isAnonymized = self.__itemsCache.items.anonymizer.isPlayerAnonymized75 self.__processContacts()76 self.onStateChanged(enabled=self.isEnabled, restricted=self.isRestricted, anonymized=self.isAnonymized)77 def __clear(self):78 self.onStateChanged.clear()79 self.__removeListeners()80 self.__isEnabled = False81 self.__isRestricted = False82 self.__isAnonymized = False83 self.__isInBattle = False84 def __onServerSettingsChanged(self, *_):85 self.__isEnabled = self.__lobbyContext.getServerSettings().isAnonymizerEnabled()86 self.onStateChanged(enabled=self.isEnabled)87 def __onCacheSPAChanged(self, *_):88 self.__isRestricted = self.__itemsCache.items.stats.isAnonymousRestricted89 self.onStateChanged(restricted=self.isRestricted)90 def __onAnonymizedStateChanged(self, *_):91 self.__isAnonymized = self.__itemsCache.items.anonymizer.isPlayerAnonymized92 self.onStateChanged(anonymized=self.isAnonymized)93 def __onContactsFeedback(self, *_):94 self.__processContacts()95 def __processContacts(self):96 contactsFeedback = self.__itemsCache.items.anonymizer.contactsFeedback97 if contactsFeedback:98 arenaUniqueID, contactsBlob = self.__itemsCache.items.anonymizer.contactsFeedback[0]99 if self.__uploader.isProcessing:100 if self.__uploader.arenaUniqueID == arenaUniqueID:101 _logger.info('contacts uploader continue upload arenaID %s', arenaUniqueID)102 return103 self.__uploader.stop()104 self.__uploader.start(arenaUniqueID, contactsBlob)105 elif self.__uploader.isProcessing:106 self.__uploader.stop()107 def __onSetAnonymizedResponse(self, resultID, errorCode):108 if errorCode:109 self.__onAnonymizedStateChanged()110 self.__pushChangeUnavailableMessage()111 _logger.debug('setAnonymized response: %s', (resultID, errorCode))112 @staticmethod113 def __pushChangeUnavailableMessage():...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!