code style reformatting using black
This commit is contained in:
parent
4127bcffd0
commit
744cb0c503
1 changed files with 21394 additions and 10488 deletions
|
|
@ -22,6 +22,7 @@ from sat.core.i18n import _
|
|||
from sat.core.constants import Const as C
|
||||
from sat.core import exceptions
|
||||
from sat.core.log import getLogger
|
||||
|
||||
log = getLogger(__name__)
|
||||
from twisted.internet import defer
|
||||
from twisted.words.protocols.jabber import jid
|
||||
|
|
@ -31,24 +32,37 @@ import os.path
|
|||
PLUGIN_INFO = {
|
||||
C.PI_NAME: "Identity Plugin",
|
||||
C.PI_IMPORT_NAME: "IDENTITY",
|
||||
C.PI_TYPE: C.PLUG_TYPE_MISC ,
|
||||
C.PI_TYPE: C.PLUG_TYPE_MISC,
|
||||
C.PI_PROTOCOLS: [],
|
||||
C.PI_DEPENDENCIES: ["XEP-0054"],
|
||||
C.PI_RECOMMENDATIONS: [],
|
||||
C.PI_MAIN: "Identity",
|
||||
C.PI_HANDLER: "no",
|
||||
C.PI_DESCRIPTION: _("""Identity manager""")
|
||||
C.PI_DESCRIPTION: _("""Identity manager"""),
|
||||
}
|
||||
|
||||
|
||||
class Identity(object):
|
||||
|
||||
def __init__(self, host):
|
||||
log.info(_(u"Plugin Identity initialization"))
|
||||
self.host = host
|
||||
self._v = host.plugins[u'XEP-0054']
|
||||
host.bridge.addMethod(u"identityGet", u".plugin", in_sign=u'ss', out_sign=u'a{ss}', method=self._getIdentity, async=True)
|
||||
host.bridge.addMethod(u"identitySet", u".plugin", in_sign=u'a{ss}s', out_sign=u'', method=self._setIdentity, async=True)
|
||||
self._v = host.plugins[u"XEP-0054"]
|
||||
host.bridge.addMethod(
|
||||
u"identityGet",
|
||||
u".plugin",
|
||||
in_sign=u"ss",
|
||||
out_sign=u"a{ss}",
|
||||
method=self._getIdentity,
|
||||
async=True,
|
||||
)
|
||||
host.bridge.addMethod(
|
||||
u"identitySet",
|
||||
u".plugin",
|
||||
in_sign=u"a{ss}s",
|
||||
out_sign=u"",
|
||||
method=self._setIdentity,
|
||||
async=True,
|
||||
)
|
||||
|
||||
def _getIdentity(self, jid_str, profile):
|
||||
jid_ = jid.JID(jid_str)
|
||||
|
|
@ -70,23 +84,25 @@ class Identity(object):
|
|||
# we first check roster
|
||||
roster_item = yield client.roster.getItem(jid_.userhostJID())
|
||||
if roster_item is not None and roster_item.name:
|
||||
id_data[u'nick'] = roster_item.name
|
||||
id_data[u"nick"] = roster_item.name
|
||||
elif jid_.resource and self._v.isRoom(client, jid_):
|
||||
id_data[u'nick'] = jid_.resource
|
||||
id_data[u"nick"] = jid_.resource
|
||||
else:
|
||||
# and finally then vcard
|
||||
# and finally then vcard
|
||||
nick = yield self._v.getNick(client, jid_)
|
||||
id_data[u'nick'] = nick if nick else jid_.user.capitalize()
|
||||
id_data[u"nick"] = nick if nick else jid_.user.capitalize()
|
||||
|
||||
try:
|
||||
avatar_path = id_data[u'avatar'] = yield self._v.getAvatar(client, jid_, cache_only=False)
|
||||
avatar_path = id_data[u"avatar"] = yield self._v.getAvatar(
|
||||
client, jid_, cache_only=False
|
||||
)
|
||||
except exceptions.NotFound:
|
||||
pass
|
||||
else:
|
||||
if avatar_path:
|
||||
id_data[u'avatar_basename'] = os.path.basename(avatar_path)
|
||||
id_data[u"avatar_basename"] = os.path.basename(avatar_path)
|
||||
else:
|
||||
del id_data[u'avatar']
|
||||
del id_data[u"avatar"]
|
||||
|
||||
defer.returnValue(id_data)
|
||||
|
||||
|
|
@ -101,8 +117,7 @@ class Identity(object):
|
|||
- nick: nickname
|
||||
the vCard will be updated
|
||||
"""
|
||||
if id_data.keys() != [u'nick']:
|
||||
raise NotImplementedError(u'Only nick can be updated for now')
|
||||
if u'nick' in id_data:
|
||||
return self._v.setNick(client, id_data[u'nick'])
|
||||
|
||||
if id_data.keys() != [u"nick"]:
|
||||
raise NotImplementedError(u"Only nick can be updated for now")
|
||||
if u"nick" in id_data:
|
||||
return self._v.setNick(client, id_data[u"nick"])
|
||||
|
|
|
|||
Loading…
Reference in a new issue