core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'

This commit is contained in:
Goffi 2014-03-21 16:27:09 +01:00
commit 005ec59a8a
2 changed files with 123 additions and 101 deletions

View file

@ -241,14 +241,14 @@ class Memory(object):
"""
return self.params.asyncDeleteProfile(name, force)
def addToHistory(self, from_jid, to_jid, message, type_='chat', extra=None, timestamp=None, profile="@NONE@"):
assert profile != "@NONE@"
def addToHistory(self, from_jid, to_jid, message, type_='chat', extra=None, timestamp=None, profile=C.PROF_KEY_NONE):
assert profile != C.PROF_KEY_NONE
if extra is None:
extra = {}
return self.storage.addToHistory(from_jid, to_jid, message, type_, extra, timestamp, profile)
def getHistory(self, from_jid, to_jid, limit=0, between=True, profile="@NONE@"):
assert profile != "@NONE@"
def getHistory(self, from_jid, to_jid, limit=0, between=True, profile=C.PROF_KEY_NONE):
assert profile != C.PROF_KEY_NONE
return self.storage.getHistory(jid.JID(from_jid), jid.JID(to_jid), limit, between, profile)
def addServerFeature(self, feature, jid_, profile):
@ -319,7 +319,7 @@ class Memory(object):
entities.update(set_)
return entities
def hasServerFeature(self, feature, jid_=None, profile_key="@NONE@"):
def hasServerFeature(self, feature, jid_=None, profile_key=C.PROF_KEY_NONE):
"""Tell if the specified server has the required feature
@param feature: requested feature
@param jid_: the jid of the target server (None for profile's server)
@ -387,7 +387,7 @@ class Memory(object):
"""Set a misc data for an entity
@param entity_jid: JID of the entity, or '@ALL@' to update all entities)
@param key: key to set (eg: "type")
@param value: value for this key (eg: "chatroom"), or '@NONE@' to delete
@param value: value for this key (eg: "chatroom"), or C.PROF_KEY_NONE to delete
@param profile_key: %(doc_profile_key)s
"""
profile = self.getProfileName(profile_key)
@ -403,7 +403,7 @@ class Memory(object):
entities_map = {entity: self.entitiesCache[profile][entity]}
for entity in entities_map:
entity_map = entities_map[entity]
if value == "@NONE@" and key in entity_map:
if value == C.PROF_KEY_NONE and key in entity_map:
del entity_map[key]
else:
entity_map[key] = value
@ -473,31 +473,31 @@ class Memory(object):
return self.subscriptions[profile]
def getStringParamA(self, name, category, attr="value", profile_key='@NONE@'):
def getStringParamA(self, name, category, attr="value", profile_key=C.PROF_KEY_NONE):
return self.params.getStringParamA(name, category, attr, profile_key)
def getParamA(self, name, category, attr="value", profile_key='@NONE@'):
def getParamA(self, name, category, attr="value", profile_key=C.PROF_KEY_NONE):
return self.params.getParamA(name, category, attr, profile_key)
def asyncGetParamA(self, name, category, attr="value", security_limit=C.NO_SECURITY_LIMIT, profile_key='@NONE@'):
def asyncGetParamA(self, name, category, attr="value", security_limit=C.NO_SECURITY_LIMIT, profile_key=C.PROF_KEY_NONE):
return self.params.asyncGetParamA(name, category, attr, security_limit, profile_key)
def asyncGetStringParamA(self, name, category, attr="value", security_limit=C.NO_SECURITY_LIMIT, profile_key='@NONE@'):
def asyncGetStringParamA(self, name, category, attr="value", security_limit=C.NO_SECURITY_LIMIT, profile_key=C.PROF_KEY_NONE):
return self.params.asyncGetStringParamA(name, category, attr, security_limit, profile_key)
def getParamsUI(self, security_limit=C.NO_SECURITY_LIMIT, app='', profile_key='@NONE@'):
def getParamsUI(self, security_limit=C.NO_SECURITY_LIMIT, app='', profile_key=C.PROF_KEY_NONE):
return self.params.getParamsUI(security_limit, app, profile_key)
def getParams(self, security_limit=C.NO_SECURITY_LIMIT, app='', profile_key='@NONE@'):
def getParams(self, security_limit=C.NO_SECURITY_LIMIT, app='', profile_key=C.PROF_KEY_NONE):
return self.params.getParams(security_limit, app, profile_key)
def getParamsForCategory(self, category, security_limit=C.NO_SECURITY_LIMIT, app='', profile_key='@NONE@'):
def getParamsForCategory(self, category, security_limit=C.NO_SECURITY_LIMIT, app='', profile_key=C.PROF_KEY_NONE):
return self.params.getParamsForCategory(category, security_limit, app, profile_key)
def getParamsCategories(self):
return self.params.getParamsCategories()
def setParam(self, name, value, category, security_limit=C.NO_SECURITY_LIMIT, profile_key='@NONE@'):
def setParam(self, name, value, category, security_limit=C.NO_SECURITY_LIMIT, profile_key=C.PROF_KEY_NONE):
return self.params.setParam(name, value, category, security_limit, profile_key)
def updateParams(self, xml):

View file

@ -176,7 +176,7 @@ class Params(object):
info(_('No profile exist yet'))
return ""
return default # FIXME: temporary, must use real default value, and fallback to first one if it doesn't exists
elif profile_key == '@NONE@':
elif profile_key == C.PROF_KEY_NONE:
raise exceptions.ProfileNotSetError
elif return_profile_keys and profile_key in ["@ALL@"]:
return profile_key # this value must be managed by the caller
@ -323,11 +323,11 @@ class Params(object):
return "true" if result else "false"
return result
def getStringParamA(self, name, category, attr="value", profile_key="@NONE@"):
def getStringParamA(self, name, category, attr="value", profile_key=C.PROF_KEY_NONE):
""" Same as getParamA but for bridge: convert non string value to string """
return self.__type_to_string(self.getParamA(name, category, attr, profile_key))
def getParamA(self, name, category, attr="value", profile_key="@NONE@"):
def getParamA(self, name, category, attr="value", profile_key=C.PROF_KEY_NONE):
"""Helper method to get a specific attribute
@param name: name of the parameter
@param category: category of the parameter
@ -360,12 +360,12 @@ class Params(object):
value = self._getParam(category, name, profile=profile)
return self._getAttr(node[1], attr, value)
def asyncGetStringParamA(self, name, category, attr="value", security_limit=C.NO_SECURITY_LIMIT, profile_key="@NONE@"):
def asyncGetStringParamA(self, name, category, attr="value", security_limit=C.NO_SECURITY_LIMIT, profile_key=C.PROF_KEY_NONE):
d = self.asyncGetParamA(name, category, attr, security_limit, profile_key)
d.addCallback(self.__type_to_string)
return d
def asyncGetParamA(self, name, category, attr="value", security_limit=C.NO_SECURITY_LIMIT, profile_key="@NONE@"):
def asyncGetParamA(self, name, category, attr="value", security_limit=C.NO_SECURITY_LIMIT, profile_key=C.PROF_KEY_NONE):
"""Helper method to get a specific attribute
@param name: name of the parameter
@param category: category of the parameter
@ -402,7 +402,7 @@ class Params(object):
d = self.storage.getIndParam(category, name, profile)
return d.addCallback(lambda value: self._getAttr(node[1], attr, value))
def _getParam(self, category, name, type_=C.INDIVIDUAL, cache=None, profile="@NONE@"):
def _getParam(self, category, name, type_=C.INDIVIDUAL, cache=None, profile=C.PROF_KEY_NONE):
"""Return the param, or None if it doesn't exist
@param category: param category
@param name: param name
@ -416,7 +416,7 @@ class Params(object):
return self.params_gen[(category, name)]
return None # This general param has the default value
assert (type_ == C.INDIVIDUAL)
if profile == "@NONE@":
if profile == C.PROF_KEY_NONE:
raise exceptions.ProfileNotSetError
if profile in self.params:
cache = self.params[profile] # if profile is in main cache, we use it,
@ -608,10 +608,10 @@ class Params(object):
categories.append(cat.getAttribute("name"))
return categories
def setParam(self, name, value, category, security_limit=C.NO_SECURITY_LIMIT, profile_key='@NONE@'):
def setParam(self, name, value, category, security_limit=C.NO_SECURITY_LIMIT, profile_key=C.PROF_KEY_NONE):
"""Set a parameter, return None if the parameter is not in param xml"""
#TODO: use different behaviour depending of the data type (e.g. password encrypted)
if profile_key != "@NONE@":
if profile_key != C.PROF_KEY_NONE:
profile = self.getProfileName(profile_key)
if not profile:
error(_('Trying to set parameter for an unknown profile'))
@ -638,7 +638,7 @@ class Params(object):
return
assert (node[0] == C.INDIVIDUAL)
assert (profile_key != "@NONE@")
assert (profile_key != C.PROF_KEY_NONE)
type_ = node[1].getAttribute("type")
if type_ == "button":