changeset 357755b75a6b in /home/hg/repos/python-nbxmpp
details:http://hg.gajim.org/python-nbxmpp?cmd=changeset;node=357755b75a6b
description: fix some type comparion error due to py2 and py3 support
diffstat:
nbxmpp/auth_nb.py | 5 ++---
nbxmpp/protocol.py | 18 +++++++++---------
nbxmpp/simplexml.py | 5 +++--
3 files changed, 14 insertions(+), 14 deletions(-)
diffs (82 lines):
diff -r d1b4a9aedbc9 -r 357755b75a6b nbxmpp/auth_nb.py
--- a/nbxmpp/auth_nb.py Sun Jun 29 17:33:32 2014 +0200
+++ b/nbxmpp/auth_nb.py Sun Jun 29 17:35:05 2014 +0200
@@ -452,9 +452,8 @@
chal = _challenge_splitter(data)
if not self.realm and 'realm' in chal:
self.realm = chal['realm']
- if 'qop' in chal and ((isinstance(chal['qop'], str) and \
- chal['qop'] =='auth') or (isinstance(chal['qop'], list) and 'auth' in \
- chal['qop'])):
+ if 'qop' in chal and ((chal['qop'] =='auth') or \
+ (isinstance(chal['qop'], list) and 'auth' in chal['qop'])):
self.resp = {}
self.resp['username'] = self.username
if self.realm:
diff -r d1b4a9aedbc9 -r 357755b75a6b nbxmpp/protocol.py
--- a/nbxmpp/protocol.py Sun Jun 29 17:33:32 2014 +0200
+++ b/nbxmpp/protocol.py Sun Jun 29 17:35:05 2014 +0200
@@ -1555,11 +1555,11 @@
"""
Add one more label-option pair to this field
"""
- if isinstance(opt, str):
- self.addChild('option').setTagData('value', opt)
- else:
+ if isinstance(opt, list):
self.addChild('option', {'label': opt[0]}).setTagData('value',
opt[1])
+ else:
+ self.addChild('option').setTagData('value', opt)
def getType(self):
"""
@@ -1626,12 +1626,12 @@
newdata.append(DataField(name, data[name]))
data = newdata
for child in data:
- if isinstance(child, str):
+ if child.__class__.__name__ == 'DataField':
+ self.kids.append(child)
+ elif isinstance(child, Node):
+ self.kids.append(DataField(node=child))
+ else: # Must be a string
self.addInstructions(child)
- elif child.__class__.__name__ == 'DataField':
- self.kids.append(child)
- else:
- self.kids.append(DataField(node=child))
def getType(self):
"""
@@ -1700,7 +1700,7 @@
for field in self.getTags('field'):
name = field.getAttr('var')
typ = field.getType()
- if isinstance(typ, str) and typ.endswith('-multi'):
+ if typ and typ.endswith('-multi'):
val = []
for i in field.getTags('value'):
val.append(i.getData())
diff -r d1b4a9aedbc9 -r 357755b75a6b nbxmpp/simplexml.py
--- a/nbxmpp/simplexml.py Sun Jun 29 17:33:32 2014 +0200
+++ b/nbxmpp/simplexml.py Sun Jun 29 17:35:05 2014 +0200
@@ -144,7 +144,8 @@
self.namespace, self.name = tag.split()
else:
self.name = tag
- if isinstance(payload, str): payload=[payload]
+ if not isinstance(payload, list):
+ payload = [payload]
for i in payload:
if isinstance(i, Node):
self.addChild(node=i)
@@ -404,7 +405,7 @@
replaces all node's previous content. If you wish just to add child or
CDATA - use addData or addChild methods
"""
- if isinstance(payload, str):
+ if not isinstance(payload, list):
payload = [payload]
if add:
self.kids += payload