Python 3.0/.1 compatibility

This commit is contained in:
mathieui 2011-11-28 21:27:40 +01:00 committed by Florent Le Coz
parent 73ca8ddca0
commit a1575237fd

View file

@ -1,9 +1,16 @@
import os import os
from sys import version_info
from sleekxmpp.plugins.xep_0048 import * from sleekxmpp.plugins.xep_0048 import *
from core import JID from core import JID
from config import config from config import config
def iter(xml, tag=''):
if version_info[1] >= 2:
return xml.iter(tag)
else:
return xml.getiterator(tag)
preferred = config.get('use_bookmarks_method', 'pep').lower() preferred = config.get('use_bookmarks_method', 'pep').lower()
if preferred not in ('pep', 'privatexml'): if preferred not in ('pep', 'privatexml'):
preferred = 'privatexml' preferred = 'privatexml'
@ -73,10 +80,10 @@ class Bookmark(object):
name = el.get('name') name = el.get('name')
autojoin = True if el.get('autojoin', False) == 'true' else False autojoin = True if el.get('autojoin', False) == 'true' else False
nick = None nick = None
for n in el.iter('nick'): for n in iter(el, 'nick'):
nick = nick.text nick = nick.text
password = None password = None
for p in el.iter('password'): for p in iter(el, 'password'):
password = p.text password = p.text
return Bookmark(jid, name, autojoin, nick, password, method) return Bookmark(jid, name, autojoin, nick, password, method)
@ -150,7 +157,7 @@ def get_pep(xmpp):
iq = xmpp.plugin['xep_0048'].get_bookmarks() iq = xmpp.plugin['xep_0048'].get_bookmarks()
except: except:
return False return False
for conf in iq.xml.iter('{storage:bookmarks}conference'): for conf in iter(iq.xml, '{storage:bookmarks}conference'):
b = Bookmark.parse_from_element(conf, method='pep') b = Bookmark.parse_from_element(conf, method='pep')
if not get_by_jid(b.jid): if not get_by_jid(b.jid):
bookmarks.append(b) bookmarks.append(b)
@ -162,7 +169,7 @@ def get_privatexml(xmpp):
iq = xmpp.plugin['xep_0048'].get_bookmarks_old() iq = xmpp.plugin['xep_0048'].get_bookmarks_old()
except: except:
return False return False
for conf in iq.xml.iter('{storage:bookmarks}conference'): for conf in iter(iq.xml, '{storage:bookmarks}conference'):
b = Bookmark.parse_from_element(conf, method='privatexml') b = Bookmark.parse_from_element(conf, method='privatexml')
if not get_by_jid(b.jid): if not get_by_jid(b.jid):
bookmarks.append(b) bookmarks.append(b)