comparison sat/memory/memory.py @ 2765:378188abe941

misc: replaced all "dummy" by the more conventional and readable "__" ("_" being used for gettext)
author Goffi <goffi@goffi.org>
date Fri, 11 Jan 2019 11:13:15 +0100
parents 5060cbeec01e
children 003b8b4b56a7
comparison
equal deleted inserted replaced
2764:92af49cde255 2765:378188abe941
351 @raise exceptions.ProfileUnknownError if profile doesn't exists 351 @raise exceptions.ProfileUnknownError if profile doesn't exists
352 @raise exceptions.PasswordError: the password does not match 352 @raise exceptions.PasswordError: the password does not match
353 """ 353 """
354 profile = self.getProfileName(profile) 354 profile = self.getProfileName(profile)
355 355
356 def createSession(dummy): 356 def createSession(__):
357 """Called once params are loaded.""" 357 """Called once params are loaded."""
358 self._entities_cache[profile] = {} 358 self._entities_cache[profile] = {}
359 log.info(u"[{}] Profile session started".format(profile)) 359 log.info(u"[{}] Profile session started".format(profile))
360 return False 360 return False
361 361
362 def backendInitialised(dummy): 362 def backendInitialised(__):
363 def doStartSession(dummy=None): 363 def doStartSession(__=None):
364 if self.isSessionStarted(profile): 364 if self.isSessionStarted(profile):
365 log.info("Session already started!") 365 log.info("Session already started!")
366 return True 366 return True
367 try: 367 try:
368 # if there is a value at this point in self._entities_cache, 368 # if there is a value at this point in self._entities_cache,
556 #   raise ValueError(_(u"Plugin {component} is not an entry point !".format( 556 #   raise ValueError(_(u"Plugin {component} is not an entry point !".format(
557 #   component = component))) 557 #   component = component)))
558 558
559 d = self.params.createProfile(name, component) 559 d = self.params.createProfile(name, component)
560 560
561 def initPersonalKey(dummy): 561 def initPersonalKey(__):
562 # be sure to call this after checking that the profile doesn't exist yet 562 # be sure to call this after checking that the profile doesn't exist yet
563 personal_key = BlockCipher.getRandomKey( 563 personal_key = BlockCipher.getRandomKey(
564 base64=True 564 base64=True
565 ) # generated once for all and saved in a PersistentDict 565 ) # generated once for all and saved in a PersistentDict
566 self.auth_sessions.newSession( 566 self.auth_sessions.newSession(
567 {C.MEMORY_CRYPTO_KEY: personal_key}, profile=name 567 {C.MEMORY_CRYPTO_KEY: personal_key}, profile=name
568 ) # will be encrypted by setParam 568 ) # will be encrypted by setParam
569 569
570 def startFakeSession(dummy): 570 def startFakeSession(__):
571 # avoid ProfileNotConnected exception in setParam 571 # avoid ProfileNotConnected exception in setParam
572 self._entities_cache[name] = None 572 self._entities_cache[name] = None
573 self.params.loadIndParams(name) 573 self.params.loadIndParams(name)
574 574
575 def stopFakeSession(dummy): 575 def stopFakeSession(__):
576 del self._entities_cache[name] 576 del self._entities_cache[name]
577 self.params.purgeProfile(name) 577 self.params.purgeProfile(name)
578 578
579 d.addCallback(initPersonalKey) 579 d.addCallback(initPersonalKey)
580 d.addCallback(startFakeSession) 580 d.addCallback(startFakeSession)
581 d.addCallback( 581 d.addCallback(
582 lambda dummy: self.setParam( 582 lambda __: self.setParam(
583 C.PROFILE_PASS_PATH[1], password, C.PROFILE_PASS_PATH[0], profile_key=name 583 C.PROFILE_PASS_PATH[1], password, C.PROFILE_PASS_PATH[0], profile_key=name
584 ) 584 )
585 ) 585 )
586 d.addCallback(stopFakeSession) 586 d.addCallback(stopFakeSession)
587 d.addCallback(lambda dummy: self.auth_sessions.profileDelUnique(name)) 587 d.addCallback(lambda __: self.auth_sessions.profileDelUnique(name))
588 return d 588 return d
589 589
590 def asyncDeleteProfile(self, name, force=False): 590 def asyncDeleteProfile(self, name, force=False):
591 """Delete an existing profile 591 """Delete an existing profile
592 592
594 @param force: force the deletion even if the profile is connected. 594 @param force: force the deletion even if the profile is connected.
595 To be used for direct calls only (not through the bridge). 595 To be used for direct calls only (not through the bridge).
596 @return: a Deferred instance 596 @return: a Deferred instance
597 """ 597 """
598 598
599 def cleanMemory(dummy): 599 def cleanMemory(__):
600 self.auth_sessions.profileDelUnique(name) 600 self.auth_sessions.profileDelUnique(name)
601 try: 601 try:
602 del self._entities_cache[name] 602 del self._entities_cache[name]
603 except KeyError: 603 except KeyError:
604 pass 604 pass
1098 data[data_key] = cipher 1098 data[data_key] = cipher
1099 return data.force(data_key) 1099 return data.force(data_key)
1100 1100
1101 return d.addCallback(cb) 1101 return d.addCallback(cb)
1102 1102
1103 def done(dummy): 1103 def done(__):
1104 log.debug( 1104 log.debug(
1105 _(u"Personal data (%(ns)s, %(key)s) has been successfuly encrypted") 1105 _(u"Personal data (%(ns)s, %(key)s) has been successfuly encrypted")
1106 % {"ns": C.MEMORY_CRYPTO_NAMESPACE, "key": data_key} 1106 % {"ns": C.MEMORY_CRYPTO_NAMESPACE, "key": data_key}
1107 ) 1107 )
1108 1108