mirror of https://gitlab.com/bashrc2/epicyon
flake8 format
parent
dc2386c583
commit
bb12ce191e
42
xmpp.py
42
xmpp.py
|
|
@ -1,12 +1,11 @@
|
||||||
__filename__="xmpp.py"
|
__filename__ = "xmpp.py"
|
||||||
__author__="Bob Mottram"
|
__author__ = "Bob Mottram"
|
||||||
__license__="AGPL3+"
|
__license__ = "AGPL3+"
|
||||||
__version__="1.1.0"
|
__version__ = "1.1.0"
|
||||||
__maintainer__="Bob Mottram"
|
__maintainer__ = "Bob Mottram"
|
||||||
__email__="bob@freedombone.net"
|
__email__ = "bob@freedombone.net"
|
||||||
__status__="Production"
|
__status__ = "Production"
|
||||||
|
|
||||||
import json
|
|
||||||
|
|
||||||
def getXmppAddress(actorJson: {}) -> str:
|
def getXmppAddress(actorJson: {}) -> str:
|
||||||
"""Returns xmpp address for the given actor
|
"""Returns xmpp address for the given actor
|
||||||
|
|
@ -16,15 +15,15 @@ def getXmppAddress(actorJson: {}) -> str:
|
||||||
for propertyValue in actorJson['attachment']:
|
for propertyValue in actorJson['attachment']:
|
||||||
if not propertyValue.get('name'):
|
if not propertyValue.get('name'):
|
||||||
continue
|
continue
|
||||||
nameLower=propertyValue['name'].lower()
|
nameLower = propertyValue['name'].lower()
|
||||||
if not (nameLower.startswith('xmpp') or \
|
if not (nameLower.startswith('xmpp') or
|
||||||
nameLower.startswith('jabber')):
|
nameLower.startswith('jabber')):
|
||||||
continue
|
continue
|
||||||
if not propertyValue.get('type'):
|
if not propertyValue.get('type'):
|
||||||
continue
|
continue
|
||||||
if not propertyValue.get('value'):
|
if not propertyValue.get('value'):
|
||||||
continue
|
continue
|
||||||
if propertyValue['type']!='PropertyValue':
|
if propertyValue['type'] != 'PropertyValue':
|
||||||
continue
|
continue
|
||||||
if '@' not in propertyValue['value']:
|
if '@' not in propertyValue['value']:
|
||||||
continue
|
continue
|
||||||
|
|
@ -33,23 +32,24 @@ def getXmppAddress(actorJson: {}) -> str:
|
||||||
return propertyValue['value']
|
return propertyValue['value']
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
def setXmppAddress(actorJson: {},xmppAddress: str) -> None:
|
|
||||||
|
def setXmppAddress(actorJson: {}, xmppAddress: str) -> None:
|
||||||
"""Sets an xmpp address for the given actor
|
"""Sets an xmpp address for the given actor
|
||||||
"""
|
"""
|
||||||
if not actorJson.get('attachment'):
|
if not actorJson.get('attachment'):
|
||||||
actorJson['attachment']=[]
|
actorJson['attachment'] = []
|
||||||
|
|
||||||
# remove any existing value
|
# remove any existing value
|
||||||
propertyFound=None
|
propertyFound = None
|
||||||
for propertyValue in actorJson['attachment']:
|
for propertyValue in actorJson['attachment']:
|
||||||
if not propertyValue.get('name'):
|
if not propertyValue.get('name'):
|
||||||
continue
|
continue
|
||||||
if not propertyValue.get('type'):
|
if not propertyValue.get('type'):
|
||||||
continue
|
continue
|
||||||
if not (propertyValue['name'].lower().startswith('xmpp') or \
|
if not (propertyValue['name'].lower().startswith('xmpp') or
|
||||||
propertyValue['name'].lower().startswith('jabber')):
|
propertyValue['name'].lower().startswith('jabber')):
|
||||||
continue
|
continue
|
||||||
propertyFound=propertyValue
|
propertyFound = propertyValue
|
||||||
break
|
break
|
||||||
if propertyFound:
|
if propertyFound:
|
||||||
actorJson['attachment'].remove(propertyFound)
|
actorJson['attachment'].remove(propertyFound)
|
||||||
|
|
@ -66,16 +66,16 @@ def setXmppAddress(actorJson: {},xmppAddress: str) -> None:
|
||||||
continue
|
continue
|
||||||
if not propertyValue.get('type'):
|
if not propertyValue.get('type'):
|
||||||
continue
|
continue
|
||||||
nameLower=propertyValue['name'].lower()
|
nameLower = propertyValue['name'].lower()
|
||||||
if not (nameLower.startswith('xmpp') or \
|
if not (nameLower.startswith('xmpp') or
|
||||||
nameLower.startswith('jabber')):
|
nameLower.startswith('jabber')):
|
||||||
continue
|
continue
|
||||||
if propertyValue['type']!='PropertyValue':
|
if propertyValue['type'] != 'PropertyValue':
|
||||||
continue
|
continue
|
||||||
propertyValue['value']=xmppAddress
|
propertyValue['value'] = xmppAddress
|
||||||
return
|
return
|
||||||
|
|
||||||
newXmppAddress={
|
newXmppAddress = {
|
||||||
"name": "XMPP",
|
"name": "XMPP",
|
||||||
"type": "PropertyValue",
|
"type": "PropertyValue",
|
||||||
"value": xmppAddress
|
"value": xmppAddress
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue