Remove trailing whitespaces.

This commit is contained in:
Emmanuel Gil Peyrot 2013-01-18 17:55:34 +01:00
commit 27b3592e16
3 changed files with 899 additions and 899 deletions

View file

@ -40,7 +40,7 @@ SAVEFILE_DATABASE="/sat.db"
class Params():
"""This class manage parameters with xml"""
### TODO: add desciption in params
#TODO: move Watched in a plugin
default_xml = u"""
<params>
@ -84,7 +84,7 @@ class Params():
source_set = set(source_map.keys())
dest_set = set(dest_map.keys())
to_add = source_set.difference(dest_set)
for node_key in to_add:
dest_node.appendChild(source_map[node_key].cloneNode(True))
@ -97,12 +97,12 @@ class Params():
self.dom = minidom.parse(xml_file)
default_dom = minidom.parseString(Params.default_xml.encode('utf-8'))
self._mergeParams(default_dom.documentElement, self.dom.documentElement)
def loadGenParams(self):
"""Load general parameters data from storage
@return: deferred triggered once params are loaded"""
return self.storage.loadGenParams(self.params_gen)
def loadIndParams(self, profile, cache=None):
"""Load individual parameters
set self.params cache or a temporary cache
@ -112,7 +112,7 @@ class Params():
if cache == None:
self.params[profile] = {}
return self.storage.loadIndParams(self.params[profile] if cache==None else cache, profile)
def purgeProfile(self, profile):
"""Remove cache data of a profile
@param profile: %(doc_profile)s"""
@ -279,7 +279,7 @@ class Params():
@param category: category of the parameter
@param attr: name of the attribute (default: "value")
@param profile: owner of the param (@ALL@ for everyone)
@return: attribute"""
#FIXME: looks really dirty and buggy, need to be reviewed/refactored
node = self.__getParamNode(name, category)
@ -290,19 +290,19 @@ class Params():
if node[0] == 'general':
value = self.__getParam(None, category, name, 'general')
return self.__getAttr(node[1], attr, value)
assert(node[0] == 'individual')
profile = self.getProfileName(profile_key)
if not profile:
error(_('Requesting a param for an non-existant profile'))
raise exceptions.ProfileUnknownError
if profile not in self.params:
error(_('Requesting synchronous param for not connected profile'))
raise exceptions.NotConnectedProfileError(profile)
if attr == "value":
if attr == "value":
value = self.__getParam(profile, category, name)
return self.__getAttr(node[1], attr, value)
@ -325,15 +325,15 @@ class Params():
if node[0] == 'general':
value = self.__getParam(None, category, name, 'general')
return defer.succeed(self.__getAttr(node[1], attr, value))
assert(node[0] == 'individual')
profile = self.getProfileName(profile_key)
if not profile:
error(_('Requesting a param for a non-existant profile'))
return defer.fail()
if attr != "value":
if attr != "value":
return defer.succeed(node[1].getAttribute(attr))
try:
value = self.__getParam(profile, category, name)
@ -396,7 +396,7 @@ class Params():
for param_node in params:
name = param_node.getAttribute('name')
if name not in dest_params:
dest_params[name] = param_node.cloneNode(True)
dest_cat.appendChild(dest_params[name])
@ -407,8 +407,8 @@ class Params():
if new_node:
prof_xml.documentElement.appendChild(dest_cat)
return prof_xml
if self.params.has_key(profile):
d = defer.succeed(None)
profile_cache = self.params[profile]
@ -435,13 +435,13 @@ class Params():
if not profile:
error(_("Asking params for inexistant profile"))
return ""
def returnXML(prof_xml):
return_xml = prof_xml.toxml()
prof_xml.unlink()
return return_xml
return self.__constructProfileXml(profile).addCallback(returnXML)
return self.__constructProfileXml(profile).addCallback(returnXML)
def getParamsForCategory(self, category, profile_key):
"""Return node's xml for selected category"""
@ -460,7 +460,7 @@ class Params():
prof_xml.unlink()
return "<category />"
d = self.__constructProfileXml(profile)
return d.addCallback(returnCategoryXml)
@ -475,7 +475,7 @@ class Params():
@return: a tuple with the node type and the the node, or None if not found"""
for type_node in self.dom.documentElement.childNodes:
if ( ((_type == "@ALL@" or _type == "@GENERAL@") and type_node.nodeName == 'general')
if ( ((_type == "@ALL@" or _type == "@GENERAL@") and type_node.nodeName == 'general')
or ( (_type == "@ALL@" or _type == "@INDIVIDUAL@") and type_node.nodeName == 'individual') ):
for node in type_node.getElementsByTagName('category'):
if node.getAttribute("name") == category:
@ -484,7 +484,7 @@ class Params():
if param.getAttribute("name") == name:
return (type_node.nodeName, param)
return None
def getParamsCategories(self):
"""return the categories availables"""
categories=[]
@ -507,7 +507,7 @@ class Params():
if not node:
error(_('Requesting an unknown parameter (%(category)s/%(name)s)') % {'category':category, 'name':name})
return
if node[0] == 'general':
self.params_gen[(category, name)] = value
self.storage.setGenParam(category, name, value)
@ -515,10 +515,10 @@ class Params():
if self.host.isConnected(profile):
self.host.bridge.paramUpdate(name, value, category, profile)
return
assert (node[0] == 'individual')
assert (profile_key != "@NONE@")
_type = node[1].getAttribute("type")
if _type=="button":
print "clique",node.toxml()
@ -533,7 +533,7 @@ class Memory:
def __init__(self, host):
info (_("Memory manager init"))
self.initialized = defer.Deferred()
self.initialized = defer.Deferred()
self.host = host
self.entitiesCache={} #XXX: keep presence/last resource/other data in cache
# /!\ an entity is not necessarily in roster
@ -611,7 +611,7 @@ class Memory:
@param profile: %(doc_profile)s"""
info(_("[%s] Profile session started" % profile))
self.entitiesCache[profile] = {}
def purgeProfileSession(self, profile):
"""Delete cache of data of profile
@param profile: %(doc_profile)s"""
@ -628,7 +628,7 @@ class Memory:
#TODO: need to encrypt files (at least passwords !) and set permissions
param_file_xml = os.path.expanduser(self.getConfig('','local_dir')+
self.host.get_const('savefile_param_xml'))
self.params.save_xml(param_file_xml)
debug(_("params saved"))
@ -647,13 +647,13 @@ class Memory:
@param name: Profile name
"""
return self.params.createProfile(name)
def asyncCreateProfile(self, name):
"""Create a new profile
@param name: Profile name
"""
return self.params.asyncCreateProfile(name)
def deleteProfile(self, name):
"""Delete an existing profile
@param name: Name of the profile"""
@ -674,7 +674,7 @@ class Memory:
if not self.server_features.has_key(profile):
self.server_features[profile] = []
self.server_features[profile].append(feature)
def addServerIdentity(self, category, _type, entity, profile):
"""Add an identity discovered from server
@param feature: string of the feature
@ -727,7 +727,7 @@ class Memory:
return self.entitiesCache[profile][entity]["last_resource"]
except KeyError:
return ""
def getPresenceStatus(self, profile_key):
profile = self.getProfileName(profile_key)
if not profile:
@ -782,7 +782,7 @@ class Memory:
if there is no value of a given key, resulting dict will
have nothing with that key nether
@raise: exceptions.UnknownEntityError if entity is not in cache
exceptions.ProfileNotInCacheError if profile is not in cache
exceptions.ProfileNotInCacheError if profile is not in cache
"""
profile = self.getProfileName(profile_key)
if not profile:
@ -819,14 +819,14 @@ class Memory:
if not self.subscriptions.has_key(profile):
self.subscriptions[profile] = {}
self.subscriptions[profile][entity_jid] = _type
def delWaitingSub(self, entity_jid, profile_key):
"""Called when a subcription request is finished"""
profile = self.getProfileName(profile_key)
assert(profile)
if self.subscriptions.has_key(profile) and self.subscriptions[profile].has_key(entity_jid):
del self.subscriptions[profile][entity_jid]
def getWaitingSub(self, profile_key):
"""Called to get a list of currently waiting subscription requests"""
profile = self.getProfileName(profile_key)
@ -835,38 +835,38 @@ class Memory:
return {}
if not self.subscriptions.has_key(profile):
return {}
return self.subscriptions[profile]
def getStringParamA(self, name, category, attr="value", profile_key='@DEFAULT@'):
return self.params.getStringParamA(name, category, attr, profile_key)
def getParamA(self, name, category, attr="value", profile_key='@DEFAULT@'):
return self.params.getParamA(name, category, attr, profile_key)
def asyncGetParamA(self, name, category, attr="value", profile_key='@DEFAULT@'):
return self.params.asyncGetParamA(name, category, attr, profile_key)
def asyncGetStringParamA(self, name, category, attr="value", profile_key='@DEFAULT@'):
return self.params.asyncGetStringParamA(name, category, attr, profile_key)
def getParamsUI(self, profile_key):
return self.params.getParamsUI(profile_key)
def getParams(self, profile_key):
return self.params.getParams(profile_key)
return self.params.getParams(profile_key)
def getParamsForCategory(self, category, profile_key):
return self.params.getParamsForCategory(category, profile_key)
return self.params.getParamsForCategory(category, profile_key)
def getParamsCategories(self):
return self.params.getParamsCategories()
def setParam(self, name, value, category, profile_key):
return self.params.setParam(name, value, category, profile_key)
def importParams(self, xml):
return self.params.importParams(xml)
def setDefault(self, name, category, callback, errback=None):
return self.params.setDefault(name, category, callback, errback)

View file

@ -74,7 +74,7 @@ class PersistentDict:
def __cmp__(self, other):
return self._cache.__cmp__(other)
def __hash__(self):
return self._cache.__hash__()
@ -117,7 +117,7 @@ class PersistentDict:
class PersistentBinaryDict(PersistentDict):
"""Persistent dict where value can be any python data (instead of string only)"""
def load(self):
"""load persistent data from storage
"""

View file

@ -68,7 +68,7 @@ class SqliteStorage():
def fillProfileCache(ignore):
d = self.dbpool.runQuery("SELECT name,id FROM profiles").addCallback(self._profilesCache)
d.chainDeferred(self.initialized)
defer.DeferredList(init_defers).addCallback(fillProfileCache)
#Profiles
@ -77,8 +77,8 @@ class SqliteStorage():
@param profiles_result: result of the sql profiles query"""
for profile in profiles_result:
name, id = profile
self.profiles[name] = id
self.profiles[name] = id
def getProfilesList(self):
""""Return list of all registered profiles"""
return self.profiles.keys()
@ -87,23 +87,23 @@ class SqliteStorage():
"""return True if profile_name exists
@param profile_name: name of the profile to check"""
return self.profiles.has_key(profile_name)
def createProfile(self, name):
"""Create a new profile
@param name: name of the profile
@return: deferred triggered once profile is actually created"""
def getProfileId(ignore):
return self.dbpool.runQuery("SELECT (id) FROM profiles WHERE name = ?", (name,))
def profile_created(profile_id):
_id = profile_id[0][0]
self.profiles[name] = _id #we synchronise the cache
d = self.dbpool.runQuery("INSERT INTO profiles(name) VALUES (?)", (name,))
d.addCallback(getProfileId)
d.addCallback(profile_created)
return d
def deleteProfile(self, name):
"""Delete profile
@param name: name of the profile
@ -126,7 +126,7 @@ class SqliteStorage():
for param in result:
category,name,value = param
params_gen[(category, name)] = value
debug(_("loading general parameters from database"))
debug(_("loading general parameters from database"))
return self.dbpool.runQuery("SELECT category,name,value FROM param_gen").addCallback(fillParams)
def loadIndParams(self, params_ind, profile):
@ -138,7 +138,7 @@ class SqliteStorage():
for param in result:
category,name,value = param
params_ind[(category, name)] = value
debug(_("loading individual parameters from database"))
debug(_("loading individual parameters from database"))
d = self.dbpool.runQuery("SELECT category,name,value FROM param_ind WHERE profile_id=?", (self.profiles[profile],))
d.addCallback(fillParams)
return d
@ -218,7 +218,7 @@ class SqliteStorage():
values.append(_jid.resource)
return '(%s=? AND %s_res=?)' % (_type, _type)
return '%s=?' % (_type,)
if between:
query_parts.append("(%s OR %s) AND (%s or %s)" % (test_jid('source', from_jid),
test_jid('source', to_jid),
@ -233,7 +233,7 @@ class SqliteStorage():
if limit:
query_parts.append("LIMIT ?")
values.append(limit)
d = self.dbpool.runQuery(" ".join(query_parts), values)
return d.addCallback(sqliteToDict)
@ -247,7 +247,7 @@ class SqliteStorage():
for private in result:
key,value = private
private_gen[key] = value
debug(_("loading general private values [namespace: %s] from database") % (namespace,))
debug(_("loading general private values [namespace: %s] from database") % (namespace,))
d = self.dbpool.runQuery("SELECT key,value FROM private_gen WHERE namespace=?", (namespace,)).addCallback(fillPrivates)
return d.addErrback(lambda x: debug(_("No data present in database for namespace %s") % namespace))
@ -273,7 +273,7 @@ class SqliteStorage():
@param value: value to set
@return: deferred"""
d = self.dbpool.runQuery("REPLACE INTO private_gen(namespace,key,value) VALUES (?,?,?)", (namespace,key,value))
d.addErrback(lambda ignore: error(_("Can't set general private value (%(key)s) [namespace:%(namespace)s] in database" %
d.addErrback(lambda ignore: error(_("Can't set general private value (%(key)s) [namespace:%(namespace)s] in database" %
{"namespace":namespace, "key":key})))
return d
@ -295,7 +295,7 @@ class SqliteStorage():
@param key: key of the private value
@return: deferred"""
d = self.dbpool.runQuery("DELETE FROM private_gen WHERE namespace=? AND key=?", (namespace,key))
d.addErrback(lambda ignore: error(_("Can't delete general private value (%(key)s) [namespace:%(namespace)s] in database" %
d.addErrback(lambda ignore: error(_("Can't delete general private value (%(key)s) [namespace:%(namespace)s] in database" %
{"namespace":namespace, "key":key})))
return d
@ -320,7 +320,7 @@ class SqliteStorage():
for private in result:
key,value = private
private_gen[key] = pickle.loads(str(value))
debug(_("loading general private binary values [namespace: %s] from database") % (namespace,))
debug(_("loading general private binary values [namespace: %s] from database") % (namespace,))
d = self.dbpool.runQuery("SELECT key,value FROM private_gen_bin WHERE namespace=?", (namespace,)).addCallback(fillPrivates)
return d.addErrback(lambda x: debug(_("No binary data present in database for namespace %s") % namespace))
@ -346,7 +346,7 @@ class SqliteStorage():
@param value: value to set
@return: deferred"""
d = self.dbpool.runQuery("REPLACE INTO private_gen_bin(namespace,key,value) VALUES (?,?,?)", (namespace,key,pickle.dumps(value,0)))
d.addErrback(lambda ignore: error(_("Can't set general private binary value (%(key)s) [namespace:%(namespace)s] in database" %
d.addErrback(lambda ignore: error(_("Can't set general private binary value (%(key)s) [namespace:%(namespace)s] in database" %
{"namespace":namespace, "key":key})))
return d
@ -368,7 +368,7 @@ class SqliteStorage():
@param key: key of the private value
@return: deferred"""
d = self.dbpool.runQuery("DELETE FROM private_gen_bin WHERE namespace=? AND key=?", (namespace,key))
d.addErrback(lambda ignore: error(_("Can't delete general private binary value (%(key)s) [namespace:%(namespace)s] in database" %
d.addErrback(lambda ignore: error(_("Can't delete general private binary value (%(key)s) [namespace:%(namespace)s] in database" %
{"namespace":namespace, "key":key})))
return d