comparison src/memory/params.py @ 1409:3265a2639182

massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
author souliane <souliane@mailoo.org>
date Thu, 16 Apr 2015 14:57:57 +0200
parents 069ad98b360d
children c7fd121a6180
comparison
equal deleted inserted replaced
1408:8a7145138330 1409:3265a2639182
130 """Remove cache data of a profile 130 """Remove cache data of a profile
131 @param profile: %(doc_profile)s""" 131 @param profile: %(doc_profile)s"""
132 try: 132 try:
133 del self.params[profile] 133 del self.params[profile]
134 except KeyError: 134 except KeyError:
135 log.error(_("Trying to purge cache of a profile not in memory: [%s]") % profile) 135 log.error(_(u"Trying to purge cache of a profile not in memory: [%s]") % profile)
136 136
137 def save_xml(self, filename): 137 def save_xml(self, filename):
138 """Save parameters template to xml file""" 138 """Save parameters template to xml file"""
139 with open(filename, 'wb') as xml_file: 139 with open(filename, 'wb') as xml_file:
140 xml_file.write(self.dom.toxml('utf-8')) 140 xml_file.write(self.dom.toxml('utf-8'))
200 elif profile_key == C.PROF_KEY_NONE: 200 elif profile_key == C.PROF_KEY_NONE:
201 raise exceptions.ProfileNotSetError 201 raise exceptions.ProfileNotSetError
202 elif return_profile_keys and profile_key in ["@ALL@"]: 202 elif return_profile_keys and profile_key in ["@ALL@"]:
203 return profile_key # this value must be managed by the caller 203 return profile_key # this value must be managed by the caller
204 if not self.storage.hasProfile(profile_key): 204 if not self.storage.hasProfile(profile_key):
205 log.error(_('Trying to access an unknown profile (%s)') % profile_key) 205 log.error(_(u'Trying to access an unknown profile (%s)') % profile_key)
206 return "" # FIXME: raise exceptions.ProfileUnknownError here (must be well checked, this method is used in lot of places) 206 return "" # FIXME: raise exceptions.ProfileUnknownError here (must be well checked, this method is used in lot of places)
207 return profile_key 207 return profile_key
208 208
209 def __get_unique_node(self, parent, tag, name): 209 def __get_unique_node(self, parent, tag, name):
210 """return node with given tag 210 """return node with given tag
281 @param xml: XML definition of the parameters to be added 281 @param xml: XML definition of the parameters to be added
282 @param security_limit: -1 means no security, 0 is the maximum security then the higher the less secure 282 @param security_limit: -1 means no security, 0 is the maximum security then the higher the less secure
283 @param app: name of the frontend registering the parameters 283 @param app: name of the frontend registering the parameters
284 """ 284 """
285 if not app: 285 if not app:
286 log.warning(_("Trying to register frontends parameters with no specified app: aborted")) 286 log.warning(_(u"Trying to register frontends parameters with no specified app: aborted"))
287 return 287 return
288 if not hasattr(self, "frontends_cache"): 288 if not hasattr(self, "frontends_cache"):
289 self.frontends_cache = [] 289 self.frontends_cache = []
290 if app in self.frontends_cache: 290 if app in self.frontends_cache:
291 log.debug(_("Trying to register twice frontends parameters for %(app)s: aborted" % {"app": app})) 291 log.debug(_(u"Trying to register twice frontends parameters for %(app)s: aborted" % {"app": app}))
292 return 292 return
293 self.frontends_cache.append(app) 293 self.frontends_cache.append(app)
294 self.updateParams(xml, security_limit, app) 294 self.updateParams(xml, security_limit, app)
295 log.debug("Frontends parameters registered for %(app)s" % {'app': app}) 295 log.debug(u"Frontends parameters registered for %(app)s" % {'app': app})
296 296
297 def __default_ok(self, value, name, category): 297 def __default_ok(self, value, name, category):
298 #FIXME: will not work with individual parameters 298 #FIXME: will not work with individual parameters
299 self.setParam(name, value, category) 299 self.setParam(name, value, category)
300 300
301 def __default_ko(self, failure, name, category): 301 def __default_ko(self, failure, name, category):
302 log.error(_("Can't determine default value for [%(category)s/%(name)s]: %(reason)s") % {'category': category, 'name': name, 'reason': str(failure.value)}) 302 log.error(_(u"Can't determine default value for [%(category)s/%(name)s]: %(reason)s") % {'category': category, 'name': name, 'reason': str(failure.value)})
303 303
304 def setDefault(self, name, category, callback, errback=None): 304 def setDefault(self, name, category, callback, errback=None):
305 """Set default value of parameter 305 """Set default value of parameter
306 'default_cb' attibute of parameter must be set to 'yes' 306 'default_cb' attibute of parameter must be set to 'yes'
307 @param name: name of the parameter 307 @param name: name of the parameter
312 #TODO: send signal param update if value changed 312 #TODO: send signal param update if value changed
313 #TODO: manage individual paramaters 313 #TODO: manage individual paramaters
314 log.debug ("setDefault called for %(category)s/%(name)s" % {"category": category, "name": name}) 314 log.debug ("setDefault called for %(category)s/%(name)s" % {"category": category, "name": name})
315 node = self._getParamNode(name, category, '@ALL@') 315 node = self._getParamNode(name, category, '@ALL@')
316 if not node: 316 if not node:
317 log.error(_("Requested param [%(name)s] in category [%(category)s] doesn't exist !") % {'name': name, 'category': category}) 317 log.error(_(u"Requested param [%(name)s] in category [%(category)s] doesn't exist !") % {'name': name, 'category': category})
318 return 318 return
319 if node[1].getAttribute('default_cb') == 'yes': 319 if node[1].getAttribute('default_cb') == 'yes':
320 # del node[1].attributes['default_cb'] # default_cb is not used anymore as a flag to know if we have to set the default value, 320 # del node[1].attributes['default_cb'] # default_cb is not used anymore as a flag to know if we have to set the default value,
321 # and we can still use it later e.g. to call a generic setDefault method 321 # and we can still use it later e.g. to call a generic setDefault method
322 value = self._getParam(category, name, C.GENERAL) 322 value = self._getParam(category, name, C.GENERAL)
352 value_to_use = selected[0].getAttribute('value') 352 value_to_use = selected[0].getAttribute('value')
353 log.info(_("Unset parameter (%(cat)s, %(param)s) of type list will use the default option '%(value)s'") % 353 log.info(_("Unset parameter (%(cat)s, %(param)s) of type list will use the default option '%(value)s'") %
354 {'cat': cat, 'param': param, 'value': value_to_use}) 354 {'cat': cat, 'param': param, 'value': value_to_use})
355 return value_to_use 355 return value_to_use
356 if len(selected) == 0: 356 if len(selected) == 0:
357 log.error(_('Parameter (%(cat)s, %(param)s) of type list has no default option!') % {'cat': cat, 'param': param}) 357 log.error(_(u'Parameter (%(cat)s, %(param)s) of type list has no default option!') % {'cat': cat, 'param': param})
358 else: 358 else:
359 log.error(_('Parameter (%(cat)s, %(param)s) of type list has more than one default option!') % {'cat': cat, 'param': param}) 359 log.error(_(u'Parameter (%(cat)s, %(param)s) of type list has more than one default option!') % {'cat': cat, 'param': param})
360 raise exceptions.DataError 360 raise exceptions.DataError
361 return value_to_use 361 return value_to_use
362 return node.getAttribute(attr) 362 return node.getAttribute(attr)
363 363
364 def _getAttr(self, node, attr, value): 364 def _getAttr(self, node, attr, value):
430 @return: attribute 430 @return: attribute
431 """ 431 """
432 #FIXME: looks really dirty and buggy, need to be reviewed/refactored 432 #FIXME: looks really dirty and buggy, need to be reviewed/refactored
433 node = self._getParamNode(name, category) 433 node = self._getParamNode(name, category)
434 if not node: 434 if not node:
435 log.error(_("Requested param [%(name)s] in category [%(category)s] doesn't exist !") % {'name': name, 'category': category}) 435 log.error(_(u"Requested param [%(name)s] in category [%(category)s] doesn't exist !") % {'name': name, 'category': category})
436 raise exceptions.NotFound 436 raise exceptions.NotFound
437 437
438 if attr == 'value' and node[1].getAttribute('type') == 'password': 438 if attr == 'value' and node[1].getAttribute('type') == 'password':
439 raise exceptions.InternalError('To retrieve password values, use asyncGetParamA instead of getParamA') 439 raise exceptions.InternalError('To retrieve password values, use asyncGetParamA instead of getParamA')
440 440
470 @param profile: owner of the param (@ALL@ for everyone) 470 @param profile: owner of the param (@ALL@ for everyone)
471 @return: Deferred 471 @return: Deferred
472 """ 472 """
473 node = self._getParamNode(name, category) 473 node = self._getParamNode(name, category)
474 if not node: 474 if not node:
475 log.error(_("Requested param [%(name)s] in category [%(category)s] doesn't exist !") % {'name': name, 'category': category}) 475 log.error(_(u"Requested param [%(name)s] in category [%(category)s] doesn't exist !") % {'name': name, 'category': category})
476 raise ValueError("Requested param doesn't exist") 476 raise ValueError("Requested param doesn't exist")
477 477
478 if not self.checkSecurityLimit(node[1], security_limit): 478 if not self.checkSecurityLimit(node[1], security_limit):
479 log.warning(_("Trying to get parameter '%(param)s' in category '%(cat)s' without authorization!!!" 479 log.warning(_(u"Trying to get parameter '%(param)s' in category '%(cat)s' without authorization!!!"
480 % {'param': name, 'cat': category})) 480 % {'param': name, 'cat': category}))
481 raise exceptions.PermissionError 481 raise exceptions.PermissionError
482 482
483 if node[0] == C.GENERAL: 483 if node[0] == C.GENERAL:
484 value = self._getParam(category, name, C.GENERAL) 484 value = self._getParam(category, name, C.GENERAL)
734 @return: a deferred None value when everything is done 734 @return: a deferred None value when everything is done
735 """ 735 """
736 if profile_key != C.PROF_KEY_NONE: 736 if profile_key != C.PROF_KEY_NONE:
737 profile = self.getProfileName(profile_key) 737 profile = self.getProfileName(profile_key)
738 if not profile: 738 if not profile:
739 log.error(_('Trying to set parameter for an unknown profile')) 739 log.error(_(u'Trying to set parameter for an unknown profile'))
740 raise exceptions.ProfileUnknownError 740 raise exceptions.ProfileUnknownError
741 741
742 node = self._getParamNode(name, category, '@ALL@') 742 node = self._getParamNode(name, category, '@ALL@')
743 if not node: 743 if not node:
744 log.error(_('Requesting an unknown parameter (%(category)s/%(name)s)') 744 log.error(_(u'Requesting an unknown parameter (%(category)s/%(name)s)')
745 % {'category': category, 'name': name}) 745 % {'category': category, 'name': name})
746 return defer.succeed(None) 746 return defer.succeed(None)
747 747
748 if not self.checkSecurityLimit(node[1], security_limit): 748 if not self.checkSecurityLimit(node[1], security_limit):
749 log.warning(_("Trying to set parameter '%(param)s' in category '%(cat)s' without authorization!!!" 749 log.warning(_(u"Trying to set parameter '%(param)s' in category '%(cat)s' without authorization!!!"
750 % {'param': name, 'cat': category})) 750 % {'param': name, 'cat': category}))
751 return defer.succeed(None) 751 return defer.succeed(None)
752 752
753 type_ = node[1].getAttribute("type") 753 type_ = node[1].getAttribute("type")
754 if type_ == 'int': 754 if type_ == 'int':
756 value = node[1].getAttribute("value") 756 value = node[1].getAttribute("value")
757 else: 757 else:
758 try: 758 try:
759 int(value) 759 int(value)
760 except ValueError: 760 except ValueError:
761 log.debug(_("Trying to set parameter '%(param)s' in category '%(cat)s' with an non-integer value" 761 log.debug(_(u"Trying to set parameter '%(param)s' in category '%(cat)s' with an non-integer value"
762 % {'param': name, 'cat': category})) 762 % {'param': name, 'cat': category}))
763 return defer.succeed(None) 763 return defer.succeed(None)
764 if node[1].hasAttribute("constraint"): 764 if node[1].hasAttribute("constraint"):
765 constraint = node[1].getAttribute("constraint") 765 constraint = node[1].getAttribute("constraint")
766 try: 766 try:
784 assert (node[0] == C.INDIVIDUAL) 784 assert (node[0] == C.INDIVIDUAL)
785 assert (profile_key != C.PROF_KEY_NONE) 785 assert (profile_key != C.PROF_KEY_NONE)
786 786
787 d_list = [] 787 d_list = []
788 if type_ == "button": 788 if type_ == "button":
789 log.debug("Clicked param button %s" % node.toxml()) 789 log.debug(u"Clicked param button %s" % node.toxml())
790 return defer.succeed(None) 790 return defer.succeed(None)
791 d = defer.succeed(value) 791 d = defer.succeed(value)
792 if type_ == "password": 792 if type_ == "password":
793 try: 793 try:
794 personal_key = self.host.memory.auth_sessions.profileGetUnique(profile)[C.MEMORY_CRYPTO_KEY] 794 personal_key = self.host.memory.auth_sessions.profileGetUnique(profile)[C.MEMORY_CRYPTO_KEY]