Mercurial > libervia-backend
comparison src/memory/memory.py @ 916:1a759096ccbd
core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 21 Mar 2014 16:27:09 +0100 |
parents | 1a3ba959f0ab |
children | ed9841e6d84a |
comparison
equal
deleted
inserted
replaced
915:6f96ee4d8cc0 | 916:1a759096ccbd |
---|---|
239 To be used for direct calls only (not through the bridge). | 239 To be used for direct calls only (not through the bridge). |
240 @return: a Deferred instance | 240 @return: a Deferred instance |
241 """ | 241 """ |
242 return self.params.asyncDeleteProfile(name, force) | 242 return self.params.asyncDeleteProfile(name, force) |
243 | 243 |
244 def addToHistory(self, from_jid, to_jid, message, type_='chat', extra=None, timestamp=None, profile="@NONE@"): | 244 def addToHistory(self, from_jid, to_jid, message, type_='chat', extra=None, timestamp=None, profile=C.PROF_KEY_NONE): |
245 assert profile != "@NONE@" | 245 assert profile != C.PROF_KEY_NONE |
246 if extra is None: | 246 if extra is None: |
247 extra = {} | 247 extra = {} |
248 return self.storage.addToHistory(from_jid, to_jid, message, type_, extra, timestamp, profile) | 248 return self.storage.addToHistory(from_jid, to_jid, message, type_, extra, timestamp, profile) |
249 | 249 |
250 def getHistory(self, from_jid, to_jid, limit=0, between=True, profile="@NONE@"): | 250 def getHistory(self, from_jid, to_jid, limit=0, between=True, profile=C.PROF_KEY_NONE): |
251 assert profile != "@NONE@" | 251 assert profile != C.PROF_KEY_NONE |
252 return self.storage.getHistory(jid.JID(from_jid), jid.JID(to_jid), limit, between, profile) | 252 return self.storage.getHistory(jid.JID(from_jid), jid.JID(to_jid), limit, between, profile) |
253 | 253 |
254 def addServerFeature(self, feature, jid_, profile): | 254 def addServerFeature(self, feature, jid_, profile): |
255 """Add a feature discovered from server | 255 """Add a feature discovered from server |
256 @param feature: string of the feature | 256 @param feature: string of the feature |
317 entities = set() | 317 entities = set() |
318 for set_ in self.server_identities[profile][jid_].values(): | 318 for set_ in self.server_identities[profile][jid_].values(): |
319 entities.update(set_) | 319 entities.update(set_) |
320 return entities | 320 return entities |
321 | 321 |
322 def hasServerFeature(self, feature, jid_=None, profile_key="@NONE@"): | 322 def hasServerFeature(self, feature, jid_=None, profile_key=C.PROF_KEY_NONE): |
323 """Tell if the specified server has the required feature | 323 """Tell if the specified server has the required feature |
324 @param feature: requested feature | 324 @param feature: requested feature |
325 @param jid_: the jid of the target server (None for profile's server) | 325 @param jid_: the jid of the target server (None for profile's server) |
326 @param profile_key: %(doc_profile_key)s | 326 @param profile_key: %(doc_profile_key)s |
327 """ | 327 """ |
385 | 385 |
386 def updateEntityData(self, entity_jid, key, value, profile_key): | 386 def updateEntityData(self, entity_jid, key, value, profile_key): |
387 """Set a misc data for an entity | 387 """Set a misc data for an entity |
388 @param entity_jid: JID of the entity, or '@ALL@' to update all entities) | 388 @param entity_jid: JID of the entity, or '@ALL@' to update all entities) |
389 @param key: key to set (eg: "type") | 389 @param key: key to set (eg: "type") |
390 @param value: value for this key (eg: "chatroom"), or '@NONE@' to delete | 390 @param value: value for this key (eg: "chatroom"), or C.PROF_KEY_NONE to delete |
391 @param profile_key: %(doc_profile_key)s | 391 @param profile_key: %(doc_profile_key)s |
392 """ | 392 """ |
393 profile = self.getProfileName(profile_key) | 393 profile = self.getProfileName(profile_key) |
394 if not profile: | 394 if not profile: |
395 raise exceptions.ProfileUnknownError(_('Trying to get entity data for a non-existant profile')) | 395 raise exceptions.ProfileUnknownError(_('Trying to get entity data for a non-existant profile')) |
401 entity = entity_jid.userhost() | 401 entity = entity_jid.userhost() |
402 self.entitiesCache[profile].setdefault(entity, {}) | 402 self.entitiesCache[profile].setdefault(entity, {}) |
403 entities_map = {entity: self.entitiesCache[profile][entity]} | 403 entities_map = {entity: self.entitiesCache[profile][entity]} |
404 for entity in entities_map: | 404 for entity in entities_map: |
405 entity_map = entities_map[entity] | 405 entity_map = entities_map[entity] |
406 if value == "@NONE@" and key in entity_map: | 406 if value == C.PROF_KEY_NONE and key in entity_map: |
407 del entity_map[key] | 407 del entity_map[key] |
408 else: | 408 else: |
409 entity_map[key] = value | 409 entity_map[key] = value |
410 if isinstance(value, basestring): | 410 if isinstance(value, basestring): |
411 self.host.bridge.entityDataUpdated(entity, key, value, profile) | 411 self.host.bridge.entityDataUpdated(entity, key, value, profile) |
471 if profile not in self.subscriptions: | 471 if profile not in self.subscriptions: |
472 return {} | 472 return {} |
473 | 473 |
474 return self.subscriptions[profile] | 474 return self.subscriptions[profile] |
475 | 475 |
476 def getStringParamA(self, name, category, attr="value", profile_key='@NONE@'): | 476 def getStringParamA(self, name, category, attr="value", profile_key=C.PROF_KEY_NONE): |
477 return self.params.getStringParamA(name, category, attr, profile_key) | 477 return self.params.getStringParamA(name, category, attr, profile_key) |
478 | 478 |
479 def getParamA(self, name, category, attr="value", profile_key='@NONE@'): | 479 def getParamA(self, name, category, attr="value", profile_key=C.PROF_KEY_NONE): |
480 return self.params.getParamA(name, category, attr, profile_key) | 480 return self.params.getParamA(name, category, attr, profile_key) |
481 | 481 |
482 def asyncGetParamA(self, name, category, attr="value", security_limit=C.NO_SECURITY_LIMIT, profile_key='@NONE@'): | 482 def asyncGetParamA(self, name, category, attr="value", security_limit=C.NO_SECURITY_LIMIT, profile_key=C.PROF_KEY_NONE): |
483 return self.params.asyncGetParamA(name, category, attr, security_limit, profile_key) | 483 return self.params.asyncGetParamA(name, category, attr, security_limit, profile_key) |
484 | 484 |
485 def asyncGetStringParamA(self, name, category, attr="value", security_limit=C.NO_SECURITY_LIMIT, profile_key='@NONE@'): | 485 def asyncGetStringParamA(self, name, category, attr="value", security_limit=C.NO_SECURITY_LIMIT, profile_key=C.PROF_KEY_NONE): |
486 return self.params.asyncGetStringParamA(name, category, attr, security_limit, profile_key) | 486 return self.params.asyncGetStringParamA(name, category, attr, security_limit, profile_key) |
487 | 487 |
488 def getParamsUI(self, security_limit=C.NO_SECURITY_LIMIT, app='', profile_key='@NONE@'): | 488 def getParamsUI(self, security_limit=C.NO_SECURITY_LIMIT, app='', profile_key=C.PROF_KEY_NONE): |
489 return self.params.getParamsUI(security_limit, app, profile_key) | 489 return self.params.getParamsUI(security_limit, app, profile_key) |
490 | 490 |
491 def getParams(self, security_limit=C.NO_SECURITY_LIMIT, app='', profile_key='@NONE@'): | 491 def getParams(self, security_limit=C.NO_SECURITY_LIMIT, app='', profile_key=C.PROF_KEY_NONE): |
492 return self.params.getParams(security_limit, app, profile_key) | 492 return self.params.getParams(security_limit, app, profile_key) |
493 | 493 |
494 def getParamsForCategory(self, category, security_limit=C.NO_SECURITY_LIMIT, app='', profile_key='@NONE@'): | 494 def getParamsForCategory(self, category, security_limit=C.NO_SECURITY_LIMIT, app='', profile_key=C.PROF_KEY_NONE): |
495 return self.params.getParamsForCategory(category, security_limit, app, profile_key) | 495 return self.params.getParamsForCategory(category, security_limit, app, profile_key) |
496 | 496 |
497 def getParamsCategories(self): | 497 def getParamsCategories(self): |
498 return self.params.getParamsCategories() | 498 return self.params.getParamsCategories() |
499 | 499 |
500 def setParam(self, name, value, category, security_limit=C.NO_SECURITY_LIMIT, profile_key='@NONE@'): | 500 def setParam(self, name, value, category, security_limit=C.NO_SECURITY_LIMIT, profile_key=C.PROF_KEY_NONE): |
501 return self.params.setParam(name, value, category, security_limit, profile_key) | 501 return self.params.setParam(name, value, category, security_limit, profile_key) |
502 | 502 |
503 def updateParams(self, xml): | 503 def updateParams(self, xml): |
504 return self.params.updateParams(xml) | 504 return self.params.updateParams(xml) |
505 | 505 |