Python 3 port:
/!\ this is a huge commit /!\ starting from this commit, SàT is needs Python 3.6+ /!\ SàT maybe be instable or some feature may not work anymore, this will improve with time This patch port backend, bridge and frontends to Python 3. Roughly this has been done this way: - 2to3 tools has been applied (with python 3.7) - all references to python2 have been replaced with python3 (notably shebangs) - fixed files not handled by 2to3 (notably the shell script) - several manual fixes - fixed issues reported by Python 3 that where not handled in Python 2 - replaced "async" with "async_" when needed (it's a reserved word from Python 3.7) - replaced zope's "implements" with @implementer decorator - temporary hack to handle data pickled in database, as str or bytes may be returned, to be checked later - fixed hash comparison for password - removed some code which is not needed anymore with Python 3 - deactivated some code which needs to be checked (notably certificate validation) - tested with jp, fixed reported issues until some basic commands worked - ported Primitivus (after porting dependencies like urwid satext) - more manual fixes
This commit is contained in:
parent
d21a6a660f
commit
fbfe96c505
12 changed files with 6336 additions and 6398 deletions
|
|
@ -66,12 +66,12 @@ class Const(constants.Const):
|
|||
|
||||
# Chats
|
||||
CHAT_STATE_ICON = {
|
||||
"": u" ",
|
||||
"active": u"✔",
|
||||
"inactive": u"☄",
|
||||
"gone": u"✈",
|
||||
"composing": u"✎",
|
||||
"paused": u"…",
|
||||
"": " ",
|
||||
"active": "✔",
|
||||
"inactive": "☄",
|
||||
"gone": "✈",
|
||||
"composing": "✎",
|
||||
"paused": "…",
|
||||
}
|
||||
|
||||
# Blogs
|
||||
|
|
|
|||
|
|
@ -40,12 +40,12 @@ import time
|
|||
|
||||
try:
|
||||
# FIXME: to be removed when an acceptable solution is here
|
||||
unicode("") # XXX: unicode doesn't exist in pyjamas
|
||||
str("") # XXX: unicode doesn't exist in pyjamas
|
||||
except (
|
||||
TypeError,
|
||||
AttributeError,
|
||||
): # Error raised is not the same depending on pyjsbuild options
|
||||
unicode = str
|
||||
str = str
|
||||
|
||||
|
||||
class ProfileManager(object):
|
||||
|
|
@ -139,7 +139,7 @@ class ProfileManager(object):
|
|||
)
|
||||
|
||||
def _plug_profile_getFeaturesEb(self, failure):
|
||||
log.error(u"Couldn't get features: {}".format(failure))
|
||||
log.error("Couldn't get features: {}".format(failure))
|
||||
self._plug_profile_getFeaturesCb({})
|
||||
|
||||
def _plug_profile_getFeaturesCb(self, features):
|
||||
|
|
@ -154,14 +154,14 @@ class ProfileManager(object):
|
|||
self._plug_profile_gotCachedValues({})
|
||||
|
||||
def _plug_profile_failedCachedValues(self, failure):
|
||||
log.error(u"Couldn't get cached values: {}".format(failure))
|
||||
log.error("Couldn't get cached values: {}".format(failure))
|
||||
self._plug_profile_gotCachedValues({})
|
||||
|
||||
def _plug_profile_gotCachedValues(self, cached_values):
|
||||
contact_list = self.host.contact_lists[self.profile]
|
||||
# add the contact list and its listener
|
||||
for entity_s, data in cached_values.iteritems():
|
||||
for key, value in data.iteritems():
|
||||
for entity_s, data in cached_values.items():
|
||||
for key, value in data.items():
|
||||
self.host.entityDataUpdatedHandler(entity_s, key, value, self.profile)
|
||||
|
||||
if not self.connected:
|
||||
|
|
@ -203,7 +203,7 @@ class ProfileManager(object):
|
|||
|
||||
for contact in presences:
|
||||
for res in presences[contact]:
|
||||
jabber_id = (u"%s/%s" % (jid.JID(contact).bare, res)) if res else contact
|
||||
jabber_id = ("%s/%s" % (jid.JID(contact).bare, res)) if res else contact
|
||||
show = presences[contact][res][0]
|
||||
priority = presences[contact][res][1]
|
||||
statuses = presences[contact][res][2]
|
||||
|
|
@ -216,7 +216,7 @@ class ProfileManager(object):
|
|||
self.profile,
|
||||
callback=lambda data, contact=contact: gotEntityData(data, contact),
|
||||
errback=lambda failure, contact=contact: log.debug(
|
||||
u"No cache data for {}".format(contact)
|
||||
"No cache data for {}".format(contact)
|
||||
),
|
||||
)
|
||||
|
||||
|
|
@ -238,7 +238,7 @@ class ProfilesManager(object):
|
|||
return profile in self._profiles
|
||||
|
||||
def __iter__(self):
|
||||
return self._profiles.iterkeys()
|
||||
return iter(self._profiles.keys())
|
||||
|
||||
def __getitem__(self, profile):
|
||||
return self._profiles[profile]
|
||||
|
|
@ -246,11 +246,11 @@ class ProfilesManager(object):
|
|||
def __len__(self):
|
||||
return len(self._profiles)
|
||||
|
||||
def iteritems(self):
|
||||
return self._profiles.iteritems()
|
||||
def items(self):
|
||||
return self._profiles.items()
|
||||
|
||||
def itervalues(self):
|
||||
return self._profiles.itervalues()
|
||||
def values(self):
|
||||
return self._profiles.values()
|
||||
|
||||
def plug(self, profile):
|
||||
if profile in self._profiles:
|
||||
|
|
@ -271,7 +271,7 @@ class ProfilesManager(object):
|
|||
del self._profiles[profile]
|
||||
|
||||
def chooseOneProfile(self):
|
||||
return self._profiles.keys()[0]
|
||||
return list(self._profiles.keys())[0]
|
||||
|
||||
|
||||
class QuickApp(object):
|
||||
|
|
@ -350,13 +350,13 @@ class QuickApp(object):
|
|||
self.ns_map = ns_map
|
||||
|
||||
def _namespacesGetEb(self, failure_):
|
||||
log.error(_(u"Can't get namespaces map: {msg}").format(msg=failure_))
|
||||
log.error(_("Can't get namespaces map: {msg}").format(msg=failure_))
|
||||
|
||||
def _encryptionPluginsGetCb(self, plugins):
|
||||
self.encryption_plugins = plugins
|
||||
|
||||
def _encryptionPluginsGetEb(self, failure_):
|
||||
log.warning(_(u"Can't retrieve encryption plugins: {msg}").format(msg=failure_))
|
||||
log.warning(_("Can't retrieve encryption plugins: {msg}").format(msg=failure_))
|
||||
|
||||
def onBridgeConnected(self):
|
||||
self.bridge.namespacesGet(
|
||||
|
|
@ -402,13 +402,13 @@ class QuickApp(object):
|
|||
|
||||
def _bridgeEb(self, failure):
|
||||
if isinstance(failure, exceptions.BridgeExceptionNoService):
|
||||
print(_(u"Can't connect to SàT backend, are you sure it's launched ?"))
|
||||
print((_("Can't connect to SàT backend, are you sure it's launched ?")))
|
||||
sys.exit(1)
|
||||
elif isinstance(failure, exceptions.BridgeInitError):
|
||||
print(_(u"Can't init bridge"))
|
||||
print((_("Can't init bridge")))
|
||||
sys.exit(1)
|
||||
else:
|
||||
print(_(u"Error while initialising bridge: {}".format(failure)))
|
||||
print((_("Error while initialising bridge: {}".format(failure))))
|
||||
|
||||
@property
|
||||
def current_profile(self):
|
||||
|
|
@ -459,10 +459,10 @@ class QuickApp(object):
|
|||
or if connection has been lost and a reconnection is needed
|
||||
"""
|
||||
if state:
|
||||
log.debug(u"we are synchronised with server")
|
||||
log.debug("we are synchronised with server")
|
||||
if self.AUTO_RESYNC:
|
||||
# we are resynchronising all widgets
|
||||
log.debug(u"doing a full widgets resynchronisation")
|
||||
log.debug("doing a full widgets resynchronisation")
|
||||
for w in self.widgets:
|
||||
try:
|
||||
resync = w.resync
|
||||
|
|
@ -474,7 +474,7 @@ class QuickApp(object):
|
|||
|
||||
self._sync = state
|
||||
else:
|
||||
log.debug(u"we have lost synchronisation with server")
|
||||
log.debug("we have lost synchronisation with server")
|
||||
self._sync = state
|
||||
# we've lost synchronisation, all widgets must be notified
|
||||
# note: this is always called independently of AUTO_RESYNC
|
||||
|
|
@ -496,7 +496,7 @@ class QuickApp(object):
|
|||
@param with_profile (boolean): True if the signal concerns a specific profile,
|
||||
in that case the profile name has to be passed by the caller
|
||||
"""
|
||||
log.debug(u"registering signal {name}".format(name=function_name))
|
||||
log.debug("registering signal {name}".format(name=function_name))
|
||||
if handler is None:
|
||||
handler = getattr(self, "{}{}".format(function_name, "Handler"))
|
||||
if not with_profile:
|
||||
|
|
@ -582,7 +582,7 @@ class QuickApp(object):
|
|||
pass
|
||||
else:
|
||||
profile = kwargs.get("profile")
|
||||
for listener, profiles_filter in listeners.iteritems():
|
||||
for listener, profiles_filter in listeners.items():
|
||||
if profile is None or not profiles_filter or profile in profiles_filter:
|
||||
listener(*args, **kwargs)
|
||||
|
||||
|
|
@ -617,7 +617,7 @@ class QuickApp(object):
|
|||
cached_signals = self.signals_cache.pop(profile, [])
|
||||
for function_name, handler, args, kwargs in cached_signals:
|
||||
log.debug(
|
||||
u"Calling cached signal [%s] with args %s and kwargs %s"
|
||||
"Calling cached signal [%s] with args %s and kwargs %s"
|
||||
% (function_name, args, kwargs)
|
||||
)
|
||||
handler(*args, **kwargs)
|
||||
|
|
@ -632,7 +632,7 @@ class QuickApp(object):
|
|||
if not errback:
|
||||
|
||||
def errback(failure):
|
||||
log.error(_(u"Can't connect profile [%s]") % failure)
|
||||
log.error(_("Can't connect profile [%s]") % failure)
|
||||
try:
|
||||
module = failure.module
|
||||
except AttributeError:
|
||||
|
|
@ -790,8 +790,8 @@ class QuickApp(object):
|
|||
widget.onMessageState(uid, status, profile)
|
||||
|
||||
def messageSend(self, to_jid, message, subject=None, mess_type="auto", extra=None, callback=None, errback=None, profile_key=C.PROF_KEY_NONE):
|
||||
if not subject and not extra and (not message or message == {u'': u''}):
|
||||
log.debug(u"Not sending empty message")
|
||||
if not subject and not extra and (not message or message == {'': ''}):
|
||||
log.debug("Not sending empty message")
|
||||
return
|
||||
|
||||
if subject is None:
|
||||
|
|
@ -812,7 +812,7 @@ class QuickApp(object):
|
|||
return
|
||||
|
||||
self.bridge.messageSend(
|
||||
unicode(to_jid),
|
||||
str(to_jid),
|
||||
message,
|
||||
subject,
|
||||
mess_type,
|
||||
|
|
@ -857,8 +857,8 @@ class QuickApp(object):
|
|||
def mucRoomJoinedHandler(self, room_jid_s, occupants, user_nick, subject, profile):
|
||||
"""Called when a MUC room is joined"""
|
||||
log.debug(
|
||||
u"Room [{room_jid}] joined by {profile}, users presents:{users}".format(
|
||||
room_jid=room_jid_s, profile=profile, users=occupants.keys()
|
||||
"Room [{room_jid}] joined by {profile}, users presents:{users}".format(
|
||||
room_jid=room_jid_s, profile=profile, users=list(occupants.keys())
|
||||
)
|
||||
)
|
||||
room_jid = jid.JID(room_jid_s)
|
||||
|
|
@ -876,7 +876,7 @@ class QuickApp(object):
|
|||
def mucRoomLeftHandler(self, room_jid_s, profile):
|
||||
"""Called when a MUC room is left"""
|
||||
log.debug(
|
||||
u"Room [%(room_jid)s] left by %(profile)s"
|
||||
"Room [%(room_jid)s] left by %(profile)s"
|
||||
% {"room_jid": room_jid_s, "profile": profile}
|
||||
)
|
||||
room_jid = jid.JID(room_jid_s)
|
||||
|
|
@ -893,7 +893,7 @@ class QuickApp(object):
|
|||
)
|
||||
chat_widget.changeUserNick(old_nick, new_nick)
|
||||
log.debug(
|
||||
u"user [%(old_nick)s] is now known as [%(new_nick)s] in room [%(room_jid)s]"
|
||||
"user [%(old_nick)s] is now known as [%(new_nick)s] in room [%(room_jid)s]"
|
||||
% {"old_nick": old_nick, "new_nick": new_nick, "room_jid": room_jid}
|
||||
)
|
||||
|
||||
|
|
@ -905,7 +905,7 @@ class QuickApp(object):
|
|||
)
|
||||
chat_widget.setSubject(subject)
|
||||
log.debug(
|
||||
u"new subject for room [%(room_jid)s]: %(subject)s"
|
||||
"new subject for room [%(room_jid)s]: %(subject)s"
|
||||
% {"room_jid": room_jid, "subject": subject}
|
||||
)
|
||||
|
||||
|
|
@ -974,7 +974,7 @@ class QuickApp(object):
|
|||
main_notif_dict = self.profiles[profile].notifications
|
||||
|
||||
if entity is C.ENTITY_ALL:
|
||||
selected_notifs = main_notif_dict.itervalues()
|
||||
selected_notifs = iter(main_notif_dict.values())
|
||||
exact_jid = False
|
||||
else:
|
||||
if entity is None:
|
||||
|
|
@ -989,7 +989,7 @@ class QuickApp(object):
|
|||
for notifs_from_select in selected_notifs:
|
||||
|
||||
if type_ is None:
|
||||
type_notifs = notifs_from_select.itervalues()
|
||||
type_notifs = iter(notifs_from_select.values())
|
||||
else:
|
||||
type_notifs = (notifs_from_select.get(type_, []),)
|
||||
|
||||
|
|
@ -1080,10 +1080,10 @@ class QuickApp(object):
|
|||
callbacks.append((callback, errback))
|
||||
|
||||
def progressStartedHandler(self, pid, metadata, profile):
|
||||
log.info(u"Progress {} started".format(pid))
|
||||
log.info("Progress {} started".format(pid))
|
||||
|
||||
def progressFinishedHandler(self, pid, metadata, profile):
|
||||
log.info(u"Progress {} finished".format(pid))
|
||||
log.info("Progress {} finished".format(pid))
|
||||
try:
|
||||
callbacks = self._progress_ids.pop(pid)
|
||||
except KeyError:
|
||||
|
|
@ -1095,7 +1095,7 @@ class QuickApp(object):
|
|||
self.callListeners("progressFinished", pid, metadata, profile=profile)
|
||||
|
||||
def progressErrorHandler(self, pid, err_msg, profile):
|
||||
log.warning(u"Progress {pid} error: {err_msg}".format(pid=pid, err_msg=err_msg))
|
||||
log.warning("Progress {pid} error: {err_msg}".format(pid=pid, err_msg=err_msg))
|
||||
try:
|
||||
callbacks = self._progress_ids.pop(pid)
|
||||
except KeyError:
|
||||
|
|
@ -1109,7 +1109,7 @@ class QuickApp(object):
|
|||
def _subscribe_cb(self, answer, data):
|
||||
entity, profile = data
|
||||
type_ = "subscribed" if answer else "unsubscribed"
|
||||
self.bridge.subscription(type_, unicode(entity.bare), profile_key=profile)
|
||||
self.bridge.subscription(type_, str(entity.bare), profile_key=profile)
|
||||
|
||||
def subscribeHandler(self, type, raw_jid, profile):
|
||||
"""Called when a subsciption management signal is received"""
|
||||
|
|
@ -1118,18 +1118,18 @@ class QuickApp(object):
|
|||
# this is a subscription confirmation, we just have to inform user
|
||||
# TODO: call self.getEntityMBlog to add the new contact blogs
|
||||
self.showDialog(
|
||||
_(u"The contact {contact} has accepted your subscription").format(
|
||||
_("The contact {contact} has accepted your subscription").format(
|
||||
contact=entity.bare
|
||||
),
|
||||
_(u"Subscription confirmation"),
|
||||
_("Subscription confirmation"),
|
||||
)
|
||||
elif type == "unsubscribed":
|
||||
# this is a subscription refusal, we just have to inform user
|
||||
self.showDialog(
|
||||
_(u"The contact {contact} has refused your subscription").format(
|
||||
_("The contact {contact} has refused your subscription").format(
|
||||
contact=entity.bare
|
||||
),
|
||||
_(u"Subscription refusal"),
|
||||
_("Subscription refusal"),
|
||||
"error",
|
||||
)
|
||||
elif type == "subscribe":
|
||||
|
|
@ -1137,8 +1137,8 @@ class QuickApp(object):
|
|||
# TODO: use sat.stdui.ui_contact_list to display the groups selector
|
||||
self.showDialog(
|
||||
_(
|
||||
u"The contact {contact} wants to subscribe to your presence"
|
||||
u".\nDo you accept ?"
|
||||
"The contact {contact} wants to subscribe to your presence"
|
||||
".\nDo you accept ?"
|
||||
).format(contact=entity.bare),
|
||||
_("Subscription confirmation"),
|
||||
"yes/no",
|
||||
|
|
@ -1147,11 +1147,11 @@ class QuickApp(object):
|
|||
)
|
||||
|
||||
def _debugHandler(self, action, parameters, profile):
|
||||
if action == u"widgets_dump":
|
||||
if action == "widgets_dump":
|
||||
from pprint import pformat
|
||||
log.info(u"Widgets dump:\n{data}".format(data=pformat(self.widgets._widgets)))
|
||||
log.info("Widgets dump:\n{data}".format(data=pformat(self.widgets._widgets)))
|
||||
else:
|
||||
log.warning(u"Unknown debug action: {action}".format(action=action))
|
||||
log.warning("Unknown debug action: {action}".format(action=action))
|
||||
|
||||
|
||||
def showDialog(self, message, title, type="info", answer_cb=None, answer_data=None):
|
||||
|
|
@ -1178,11 +1178,11 @@ class QuickApp(object):
|
|||
pass # FIXME
|
||||
|
||||
def dialogFailure(self, failure):
|
||||
log.warning(u"Failure: {}".format(failure))
|
||||
log.warning("Failure: {}".format(failure))
|
||||
|
||||
def progressIdHandler(self, progress_id, profile):
|
||||
"""Callback used when an action result in a progress id"""
|
||||
log.info(u"Progress ID received: {}".format(progress_id))
|
||||
log.info("Progress ID received: {}".format(progress_id))
|
||||
|
||||
def isHidden(self):
|
||||
"""Tells if the frontend window is hidden.
|
||||
|
|
@ -1193,11 +1193,11 @@ class QuickApp(object):
|
|||
|
||||
def paramUpdateHandler(self, name, value, namespace, profile):
|
||||
log.debug(
|
||||
_(u"param update: [%(namespace)s] %(name)s = %(value)s")
|
||||
_("param update: [%(namespace)s] %(name)s = %(value)s")
|
||||
% {"namespace": namespace, "name": name, "value": value}
|
||||
)
|
||||
if (namespace, name) == ("Connection", "JabberID"):
|
||||
log.debug(_(u"Changing JID to %s") % value)
|
||||
log.debug(_("Changing JID to %s") % value)
|
||||
self.profiles[profile].whoami = jid.JID(value)
|
||||
elif (namespace, name) == ("General", C.SHOW_OFFLINE_CONTACTS):
|
||||
self.contact_lists[profile].showOfflineContacts(C.bool(value))
|
||||
|
|
@ -1264,13 +1264,13 @@ class QuickApp(object):
|
|||
|
||||
# we ignore metadata
|
||||
action_data = {
|
||||
k: v for k, v in action_data.iteritems() if not k.startswith("meta_")
|
||||
k: v for k, v in action_data.items() if not k.startswith("meta_")
|
||||
}
|
||||
|
||||
if action_data:
|
||||
raise exceptions.DataError(
|
||||
u"Not all keys in action_data are managed ({keys})".format(
|
||||
keys=", ".join(action_data.keys())
|
||||
"Not all keys in action_data are managed ({keys})".format(
|
||||
keys=", ".join(list(action_data.keys()))
|
||||
)
|
||||
)
|
||||
|
||||
|
|
@ -1348,10 +1348,10 @@ class QuickApp(object):
|
|||
|
||||
def _avatarGetEb(self, failure_, entity, contact_list):
|
||||
# FIXME: bridge needs a proper error handling
|
||||
if "NotFound" in unicode(failure_):
|
||||
log.info(u"No avatar found for {entity}".format(entity=entity))
|
||||
if "NotFound" in str(failure_):
|
||||
log.info("No avatar found for {entity}".format(entity=entity))
|
||||
else:
|
||||
log.warning(u"Can't get avatar: {}".format(failure_))
|
||||
log.warning("Can't get avatar: {}".format(failure_))
|
||||
contact_list.setCache(entity, "avatar", self.getDefaultAvatar(entity))
|
||||
|
||||
def getAvatar(
|
||||
|
|
@ -1383,7 +1383,7 @@ class QuickApp(object):
|
|||
avatar = None
|
||||
if avatar is None:
|
||||
self.bridge.avatarGet(
|
||||
unicode(entity),
|
||||
str(entity),
|
||||
cache_only,
|
||||
hash_only,
|
||||
profile=profile,
|
||||
|
|
@ -1413,7 +1413,7 @@ class QuickApp(object):
|
|||
def onExit(self):
|
||||
"""Must be called when the frontend is terminating"""
|
||||
to_unplug = []
|
||||
for profile, profile_manager in self.profiles.iteritems():
|
||||
for profile, profile_manager in self.profiles.items():
|
||||
if profile_manager.connected and profile_manager.autodisconnect:
|
||||
# The user wants autodisconnection
|
||||
self.disconnect(profile)
|
||||
|
|
|
|||
|
|
@ -30,12 +30,12 @@ from sat.tools.common import data_format
|
|||
|
||||
try:
|
||||
# FIXME: to be removed when an acceptable solution is here
|
||||
unicode("") # XXX: unicode doesn't exist in pyjamas
|
||||
str("") # XXX: unicode doesn't exist in pyjamas
|
||||
except (
|
||||
TypeError,
|
||||
AttributeError,
|
||||
): # Error raised is not the same depending on pyjsbuild options
|
||||
unicode = str
|
||||
str = str
|
||||
|
||||
ENTRY_CLS = None
|
||||
COMMENTS_CLS = None
|
||||
|
|
@ -266,7 +266,7 @@ class Entry(EntriesManager):
|
|||
for key in keys_to_keep:
|
||||
value = getattr(self.item, key)
|
||||
if value is not None:
|
||||
mb_data[key] = unicode(value)
|
||||
mb_data[key] = str(value)
|
||||
|
||||
for prefix in ("content", "title"):
|
||||
for suffix in ("", "_rich", "_xhtml"):
|
||||
|
|
@ -287,7 +287,7 @@ class Entry(EntriesManager):
|
|||
mb_data['groups'] = list(self.blog.targets)
|
||||
|
||||
self.blog.host.bridge.mbSend(
|
||||
unicode(self.service or ""),
|
||||
str(self.service or ""),
|
||||
self.node or "",
|
||||
data_format.serialise(mb_data),
|
||||
profile=self.blog.profile,
|
||||
|
|
@ -300,14 +300,14 @@ class Entry(EntriesManager):
|
|||
all children entries will be recursively removed too
|
||||
"""
|
||||
# XXX: named delete and not remove to avoid conflict with pyjamas
|
||||
log.debug(u"deleting entry {}".format("EDIT ENTRY" if self.new else self.item.id))
|
||||
log.debug("deleting entry {}".format("EDIT ENTRY" if self.new else self.item.id))
|
||||
for child in self.entries:
|
||||
child.delete()
|
||||
try:
|
||||
self.manager.entries.remove(self)
|
||||
except ValueError:
|
||||
if self != self.manager.edit_entry:
|
||||
log.error(u"Internal Error: entry not found in manager")
|
||||
log.error("Internal Error: entry not found in manager")
|
||||
else:
|
||||
self.manager.edit_entry = None
|
||||
if not self.new:
|
||||
|
|
@ -328,12 +328,12 @@ class Entry(EntriesManager):
|
|||
# TODO: manage several comments nodes case.
|
||||
if self.item.comments:
|
||||
self.blog.host.bridge.psNodeDelete(
|
||||
unicode(self.item.comments_service) or "",
|
||||
str(self.item.comments_service) or "",
|
||||
self.item.comments_node,
|
||||
profile=self.blog.profile,
|
||||
)
|
||||
self.blog.host.bridge.mbRetract(
|
||||
unicode(self.service or ""),
|
||||
str(self.service or ""),
|
||||
self.node or "",
|
||||
self.item.id,
|
||||
profile=self.blog.profile,
|
||||
|
|
@ -358,10 +358,10 @@ class QuickBlog(EntriesManager, quick_widgets.QuickWidget):
|
|||
quick_widgets.QuickWidget.__init__(self, host, targets, C.PROF_KEY_NONE)
|
||||
self._targets_type = C.ALL
|
||||
else:
|
||||
assert isinstance(targets[0], basestring)
|
||||
assert isinstance(targets[0], str)
|
||||
quick_widgets.QuickWidget.__init__(self, host, targets[0], C.PROF_KEY_NONE)
|
||||
for target in targets[1:]:
|
||||
assert isinstance(target, basestring)
|
||||
assert isinstance(target, str)
|
||||
self.addTarget(target)
|
||||
self._targets_type = C.GROUP
|
||||
|
||||
|
|
@ -375,7 +375,7 @@ class QuickBlog(EntriesManager, quick_widgets.QuickWidget):
|
|||
raise ValueError("Unkown targets type")
|
||||
|
||||
def __str__(self):
|
||||
return u"Blog Widget [target: {}, profile: {}]".format(
|
||||
return "Blog Widget [target: {}, profile: {}]".format(
|
||||
", ".join(self.targets), self.profile
|
||||
)
|
||||
|
||||
|
|
@ -436,7 +436,7 @@ class QuickBlog(EntriesManager, quick_widgets.QuickWidget):
|
|||
own_pep = self.host.whoami.bare
|
||||
self.host.bridge.mbGetFromManyWithComments(
|
||||
C.JID,
|
||||
(unicode(own_pep),),
|
||||
(str(own_pep),),
|
||||
10,
|
||||
10,
|
||||
{},
|
||||
|
|
@ -446,7 +446,7 @@ class QuickBlog(EntriesManager, quick_widgets.QuickWidget):
|
|||
)
|
||||
else:
|
||||
raise NotImplementedError(
|
||||
u"{} target type is not managed".format(self._targets_type)
|
||||
"{} target type is not managed".format(self._targets_type)
|
||||
)
|
||||
|
||||
def isJidAccepted(self, jid_):
|
||||
|
|
|
|||
|
|
@ -43,12 +43,12 @@ ROOM_USER_MOVED = (ROOM_USER_JOINED, ROOM_USER_LEFT)
|
|||
|
||||
try:
|
||||
# FIXME: to be removed when an acceptable solution is here
|
||||
unicode("") # XXX: unicode doesn't exist in pyjamas
|
||||
str("") # XXX: unicode doesn't exist in pyjamas
|
||||
except (
|
||||
TypeError,
|
||||
AttributeError,
|
||||
): # Error raised is not the same depending on pyjsbuild options
|
||||
unicode = str
|
||||
str = str
|
||||
|
||||
# FIXME: day_format need to be settable (i18n)
|
||||
|
||||
|
|
@ -78,23 +78,20 @@ class Message(object):
|
|||
)
|
||||
# is user mentioned here ?
|
||||
if self.parent.type == C.CHAT_GROUP and not self.own_mess:
|
||||
for m in msg.itervalues():
|
||||
for m in msg.values():
|
||||
if self.parent.nick.lower() in m.lower():
|
||||
self._mention = True
|
||||
break
|
||||
self.handleMe()
|
||||
self.widgets = set() # widgets linked to this message
|
||||
|
||||
def __unicode__(self):
|
||||
return u"Message<{mess_type}> [{time}]{nick}> {message}".format(
|
||||
def __str__(self):
|
||||
return "Message<{mess_type}> [{time}]{nick}> {message}".format(
|
||||
mess_type=self.type,
|
||||
time=self.time_text,
|
||||
nick=self.nick,
|
||||
message=self.main_message)
|
||||
|
||||
def __str__(self):
|
||||
return self.__unicode__().encode('utf-8', 'ignore')
|
||||
|
||||
@property
|
||||
def host(self):
|
||||
return self.parent.host
|
||||
|
|
@ -126,28 +123,28 @@ class Message(object):
|
|||
return self.message[""]
|
||||
except KeyError:
|
||||
try:
|
||||
lang, mess = self.message.iteritems().next()
|
||||
lang, mess = next(iter(self.message.items()))
|
||||
self.selected_lang = lang
|
||||
return mess
|
||||
except StopIteration:
|
||||
log.error(u"Can't find message for uid {}".format(self.uid))
|
||||
log.error("Can't find message for uid {}".format(self.uid))
|
||||
return ""
|
||||
|
||||
@property
|
||||
def main_message_xhtml(self):
|
||||
"""rich message"""
|
||||
xhtml = {k: v for k, v in self.extra.iteritems() if "html" in k}
|
||||
xhtml = {k: v for k, v in self.extra.items() if "html" in k}
|
||||
if xhtml:
|
||||
# FIXME: we only return first found value for now
|
||||
return next(xhtml.itervalues())
|
||||
return next(iter(xhtml.values()))
|
||||
|
||||
@property
|
||||
def time_text(self):
|
||||
"""Return timestamp in a nicely formatted way"""
|
||||
# if the message was sent before today, we print the full date
|
||||
timestamp = time.localtime(self.timestamp)
|
||||
time_format = u"%c" if timestamp < self.parent.day_change else u"%H:%M"
|
||||
return time.strftime(time_format, timestamp).decode(getlocale()[1] or "utf-8")
|
||||
time_format = "%c" if timestamp < self.parent.day_change else "%H:%M"
|
||||
return time.strftime(time_format, timestamp)
|
||||
|
||||
@property
|
||||
def avatar(self):
|
||||
|
|
@ -162,7 +159,7 @@ class Message(object):
|
|||
try:
|
||||
return self.extra["user_nick"]
|
||||
except KeyError:
|
||||
log.error(u"extra data is missing user nick for uid {}".format(self.uid))
|
||||
log.error("extra data is missing user nick for uid {}".format(self.uid))
|
||||
return ""
|
||||
# FIXME: converted getSpecials to list for pyjamas
|
||||
if self.parent.type == C.CHAT_GROUP or entity in list(
|
||||
|
|
@ -197,8 +194,8 @@ class Message(object):
|
|||
# TODO: XHTML-IM /me are not handled
|
||||
me = False
|
||||
# we need to check /me for every message
|
||||
for m in self.message.itervalues():
|
||||
if m.startswith(u"/me "):
|
||||
for m in self.message.values():
|
||||
if m.startswith("/me "):
|
||||
me = True
|
||||
else:
|
||||
me = False
|
||||
|
|
@ -207,8 +204,8 @@ class Message(object):
|
|||
self.type = C.MESS_TYPE_INFO
|
||||
self.extra["info_type"] = "me"
|
||||
nick = self.nick
|
||||
for lang, mess in self.message.iteritems():
|
||||
self.message[lang] = u"* " + nick + mess[3:]
|
||||
for lang, mess in self.message.items():
|
||||
self.message[lang] = "* " + nick + mess[3:]
|
||||
|
||||
|
||||
class MessageWidget(object):
|
||||
|
|
@ -245,7 +242,7 @@ class Occupant(object):
|
|||
@property
|
||||
def jid(self):
|
||||
"""jid in the room"""
|
||||
return jid.JID(u"{}/{}".format(self.parent.target.bare, self.nick))
|
||||
return jid.JID("{}/{}".format(self.parent.target.bare, self.nick))
|
||||
|
||||
@property
|
||||
def real_jid(self):
|
||||
|
|
@ -295,10 +292,10 @@ class QuickChat(quick_widgets.QuickWidget):
|
|||
if type_ == C.CHAT_GROUP:
|
||||
if target.resource:
|
||||
raise exceptions.InternalError(
|
||||
u"a group chat entity can't have a resource"
|
||||
"a group chat entity can't have a resource"
|
||||
)
|
||||
if nick is None:
|
||||
raise exceptions.InternalError(u"nick must not be None for group chat")
|
||||
raise exceptions.InternalError("nick must not be None for group chat")
|
||||
|
||||
self.nick = nick
|
||||
self.occupants = {}
|
||||
|
|
@ -306,7 +303,7 @@ class QuickChat(quick_widgets.QuickWidget):
|
|||
else:
|
||||
if occupants is not None or nick is not None:
|
||||
raise exceptions.InternalError(
|
||||
u"only group chat can have occupants or nick"
|
||||
"only group chat can have occupants or nick"
|
||||
)
|
||||
self.messages = OrderedDict() # key: uid, value: Message instance
|
||||
self.games = {} # key=game name (unicode), value=instance of quick_games.RoomGame
|
||||
|
|
@ -334,25 +331,25 @@ class QuickChat(quick_widgets.QuickWidget):
|
|||
# FIXME: we don't use getter/setter here because of pyjamas
|
||||
# TODO: use proper getter/setter once we get rid of pyjamas
|
||||
if self._locked:
|
||||
log.warning(u"{wid} is already locked!".format(wid=self))
|
||||
log.warning("{wid} is already locked!".format(wid=self))
|
||||
return
|
||||
self._locked = True
|
||||
# messageNew signals are cached when locked
|
||||
self._cache = OrderedDict()
|
||||
log.debug(u"{wid} is now locked".format(wid=self))
|
||||
log.debug("{wid} is now locked".format(wid=self))
|
||||
|
||||
def setUnlocked(self):
|
||||
if not self._locked:
|
||||
log.debug(u"{wid} was already unlocked".format(wid=self))
|
||||
log.debug("{wid} was already unlocked".format(wid=self))
|
||||
return
|
||||
self._locked = False
|
||||
for uid, data in self._cache.iteritems():
|
||||
for uid, data in self._cache.items():
|
||||
if uid not in self.messages:
|
||||
self.messageNew(*data)
|
||||
else:
|
||||
log.debug(u"discarding message already in history: {data}, ".format(data=data))
|
||||
log.debug("discarding message already in history: {data}, ".format(data=data))
|
||||
del self._cache
|
||||
log.debug(u"{wid} is now unlocked".format(wid=self))
|
||||
log.debug("{wid} is now unlocked".format(wid=self))
|
||||
|
||||
def postInit(self):
|
||||
"""Method to be called by frontend after widget is initialised
|
||||
|
|
@ -404,8 +401,8 @@ class QuickChat(quick_widgets.QuickWidget):
|
|||
if self._resync_lock:
|
||||
return
|
||||
self._resync_lock = True
|
||||
log.debug(u"resynchronising {self}".format(self=self))
|
||||
for mess in reversed(self.messages.values()):
|
||||
log.debug("resynchronising {self}".format(self=self))
|
||||
for mess in reversed(list(self.messages.values())):
|
||||
if mess.type == C.MESS_TYPE_INFO:
|
||||
continue
|
||||
last_message = mess
|
||||
|
|
@ -417,7 +414,7 @@ class QuickChat(quick_widgets.QuickWidget):
|
|||
if self.type == C.CHAT_GROUP:
|
||||
self.occupantsClear()
|
||||
self.host.bridge.mucOccupantsGet(
|
||||
unicode(self.target), self.profile, callback=self.updateOccupants,
|
||||
str(self.target), self.profile, callback=self.updateOccupants,
|
||||
errback=log.error)
|
||||
self.historyPrint(
|
||||
size=C.HISTORY_LIMIT_NONE,
|
||||
|
|
@ -427,15 +424,15 @@ class QuickChat(quick_widgets.QuickWidget):
|
|||
|
||||
## Widget management ##
|
||||
|
||||
def __unicode__(self):
|
||||
return u"Chat Widget [target: {}, type: {}, profile: {}]".format(
|
||||
def __str__(self):
|
||||
return "Chat Widget [target: {}, type: {}, profile: {}]".format(
|
||||
self.target, self.type, self.profile
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def getWidgetHash(target, profiles):
|
||||
profile = list(profiles)[0]
|
||||
return profile + "\n" + unicode(target.bare)
|
||||
return profile + "\n" + str(target.bare)
|
||||
|
||||
@staticmethod
|
||||
def getPrivateHash(target, profile):
|
||||
|
|
@ -443,7 +440,7 @@ class QuickChat(quick_widgets.QuickWidget):
|
|||
|
||||
This method should be used with force_hash to get unique widget for private MUC conversations
|
||||
"""
|
||||
return (unicode(profile), target)
|
||||
return (str(profile), target)
|
||||
|
||||
def addTarget(self, target):
|
||||
super(QuickChat, self).addTarget(target)
|
||||
|
|
@ -456,7 +453,7 @@ class QuickChat(quick_widgets.QuickWidget):
|
|||
"""copy important attribute for a new widget"""
|
||||
kwargs["type_"] = self.type
|
||||
if self.type == C.CHAT_GROUP:
|
||||
kwargs["occupants"] = {o.nick: o.data for o in self.occupants.itervalues()}
|
||||
kwargs["occupants"] = {o.nick: o.data for o in self.occupants.values()}
|
||||
kwargs["subject"] = self.subject
|
||||
try:
|
||||
kwargs["nick"] = self.nick
|
||||
|
|
@ -492,7 +489,7 @@ class QuickChat(quick_widgets.QuickWidget):
|
|||
def setOccupants(self, occupants):
|
||||
"""Set the whole list of occupants"""
|
||||
assert len(self.occupants) == 0
|
||||
for nick, data in occupants.iteritems():
|
||||
for nick, data in occupants.items():
|
||||
# XXX: this log is disabled because it's really too verbose
|
||||
# but kept commented as it may be useful for debugging
|
||||
# log.debug(u"adding occupant {nick} to {room}".format(
|
||||
|
|
@ -510,12 +507,12 @@ class QuickChat(quick_widgets.QuickWidget):
|
|||
updated_occupants = set(occupants)
|
||||
left_occupants = local_occupants - updated_occupants
|
||||
joined_occupants = updated_occupants - local_occupants
|
||||
log.debug(u"updating occupants for {room}:\n"
|
||||
u"left: {left_occupants}\n"
|
||||
u"joined: {joined_occupants}"
|
||||
log.debug("updating occupants for {room}:\n"
|
||||
"left: {left_occupants}\n"
|
||||
"joined: {joined_occupants}"
|
||||
.format(room=self.target,
|
||||
left_occupants=u", ".join(left_occupants),
|
||||
joined_occupants=u", ".join(joined_occupants)))
|
||||
left_occupants=", ".join(left_occupants),
|
||||
joined_occupants=", ".join(joined_occupants)))
|
||||
for nick in left_occupants:
|
||||
self.removeUser(occupants[nick])
|
||||
for nick in joined_occupants:
|
||||
|
|
@ -533,7 +530,7 @@ class QuickChat(quick_widgets.QuickWidget):
|
|||
try:
|
||||
occupant = self.occupants.pop(nick)
|
||||
except KeyError:
|
||||
log.warning(u"Trying to remove an unknown occupant: {}".format(nick))
|
||||
log.warning("Trying to remove an unknown occupant: {}".format(nick))
|
||||
else:
|
||||
return occupant
|
||||
|
||||
|
|
@ -602,12 +599,12 @@ class QuickChat(quick_widgets.QuickWidget):
|
|||
if filters is None:
|
||||
filters = {}
|
||||
if size == 0:
|
||||
log.debug(u"Empty history requested, skipping")
|
||||
log.debug("Empty history requested, skipping")
|
||||
self._onHistoryPrinted()
|
||||
return
|
||||
log_msg = _(u"now we print the history")
|
||||
log_msg = _("now we print the history")
|
||||
if size != C.HISTORY_LIMIT_DEFAULT:
|
||||
log_msg += _(u" ({} messages)".format(size))
|
||||
log_msg += _(" ({} messages)".format(size))
|
||||
log.debug(log_msg)
|
||||
|
||||
if self.type == C.CHAT_ONE2ONE:
|
||||
|
|
@ -661,17 +658,17 @@ class QuickChat(quick_widgets.QuickWidget):
|
|||
callback()
|
||||
|
||||
def _historyGetEb(err):
|
||||
log.error(_(u"Can't get history: {}").format(err))
|
||||
log.error(_("Can't get history: {}").format(err))
|
||||
self._onHistoryPrinted()
|
||||
if callback is not None:
|
||||
callback()
|
||||
|
||||
self.host.bridge.historyGet(
|
||||
unicode(self.host.profiles[profile].whoami.bare),
|
||||
unicode(target),
|
||||
str(self.host.profiles[profile].whoami.bare),
|
||||
str(target),
|
||||
size,
|
||||
True,
|
||||
{k: unicode(v) for k,v in filters.iteritems()},
|
||||
{k: str(v) for k,v in filters.items()},
|
||||
profile,
|
||||
callback=_historyGetCb,
|
||||
errback=_historyGetEb,
|
||||
|
|
@ -683,7 +680,7 @@ class QuickChat(quick_widgets.QuickWidget):
|
|||
self.messageEncryptionStarted(session_data)
|
||||
|
||||
def messageEncryptionGetEb(self, failure_):
|
||||
log.error(_(u"Can't get encryption state: {reason}").format(reason=failure_))
|
||||
log.error(_("Can't get encryption state: {reason}").format(reason=failure_))
|
||||
|
||||
def getEncryptionState(self):
|
||||
"""Retrieve encryption state with current target.
|
||||
|
|
@ -693,7 +690,7 @@ class QuickChat(quick_widgets.QuickWidget):
|
|||
"""
|
||||
if self.type == C.CHAT_GROUP:
|
||||
return
|
||||
self.host.bridge.messageEncryptionGet(unicode(self.target.bare), self.profile,
|
||||
self.host.bridge.messageEncryptionGet(str(self.target.bare), self.profile,
|
||||
callback=self.messageEncryptionGetCb,
|
||||
errback=self.messageEncryptionGetEb)
|
||||
|
||||
|
|
@ -715,7 +712,7 @@ class QuickChat(quick_widgets.QuickWidget):
|
|||
return
|
||||
|
||||
if not msg and not subject and type_ != C.MESS_TYPE_INFO:
|
||||
log.warning(u"Received an empty message for uid {}".format(uid))
|
||||
log.warning("Received an empty message for uid {}".format(uid))
|
||||
return
|
||||
|
||||
if self.type == C.CHAT_GROUP:
|
||||
|
|
@ -734,7 +731,7 @@ class QuickChat(quick_widgets.QuickWidget):
|
|||
pass
|
||||
else:
|
||||
user_data = {
|
||||
k[5:]: v for k, v in extra.iteritems() if k.startswith("user_")
|
||||
k[5:]: v for k, v in extra.items() if k.startswith("user_")
|
||||
}
|
||||
if info_type == ROOM_USER_JOINED:
|
||||
self.addUser(user_data)
|
||||
|
|
@ -747,18 +744,18 @@ class QuickChat(quick_widgets.QuickWidget):
|
|||
self.messages[uid] = message
|
||||
|
||||
if "received_timestamp" in extra:
|
||||
log.warning(u"Delayed message received after history, this should not happen")
|
||||
log.warning("Delayed message received after history, this should not happen")
|
||||
self.createMessage(message)
|
||||
|
||||
def messageEncryptionStarted(self, session_data):
|
||||
self.encrypted = True
|
||||
log.debug(_(u"message encryption started with {target} using {encryption}").format(
|
||||
target=self.target, encryption=session_data[u'name']))
|
||||
log.debug(_("message encryption started with {target} using {encryption}").format(
|
||||
target=self.target, encryption=session_data['name']))
|
||||
|
||||
def messageEncryptionStopped(self, session_data):
|
||||
self.encrypted = False
|
||||
log.debug(_(u"message encryption stopped with {target} (was using {encryption})")
|
||||
.format(target=self.target, encryption=session_data[u'name']))
|
||||
log.debug(_("message encryption stopped with {target} (was using {encryption})")
|
||||
.format(target=self.target, encryption=session_data['name']))
|
||||
|
||||
def createMessage(self, message, append=False):
|
||||
"""Must be implemented by frontend to create and show a new message widget
|
||||
|
|
@ -810,12 +807,12 @@ class QuickChat(quick_widgets.QuickWidget):
|
|||
count = wid.reentered_count = 1
|
||||
nick = wid.mess_data.nick
|
||||
if message.info_type == ROOM_USER_LEFT:
|
||||
wid.message = _(u"<= {nick} has left the room ({count})").format(
|
||||
wid.message = _("<= {nick} has left the room ({count})").format(
|
||||
nick=nick, count=count
|
||||
)
|
||||
else:
|
||||
wid.message = _(
|
||||
u"<=> {nick} re-entered the room ({count})"
|
||||
"<=> {nick} re-entered the room ({count})"
|
||||
).format(nick=nick, count=count)
|
||||
wid.reentered_count += 1
|
||||
return True
|
||||
|
|
@ -845,7 +842,7 @@ class QuickChat(quick_widgets.QuickWidget):
|
|||
This change the subject on the room itself (i.e. via XMPP),
|
||||
while setSubject change the subject of this widget
|
||||
"""
|
||||
self.host.bridge.mucSubject(unicode(self.target), new_subject, self.profile)
|
||||
self.host.bridge.mucSubject(str(self.target), new_subject, self.profile)
|
||||
|
||||
def addGamePanel(self, widget):
|
||||
"""Insert a game panel to this Chat dialog.
|
||||
|
|
@ -879,7 +876,7 @@ class QuickChat(quick_widgets.QuickWidget):
|
|||
self.occupants[nick].state = state
|
||||
except KeyError:
|
||||
log.warning(
|
||||
u"{nick} not found in {room}, ignoring new chat state".format(
|
||||
"{nick} not found in {room}, ignoring new chat state".format(
|
||||
nick=nick, room=self.target.bare
|
||||
)
|
||||
)
|
||||
|
|
@ -902,7 +899,7 @@ class QuickChat(quick_widgets.QuickWidget):
|
|||
# entity is not here anymore
|
||||
pass
|
||||
|
||||
for m in self.messages.values():
|
||||
for m in list(self.messages.values()):
|
||||
if m.nick == entity.resource:
|
||||
for w in m.widgets:
|
||||
w.update({"avatar": filename})
|
||||
|
|
@ -911,8 +908,8 @@ class QuickChat(quick_widgets.QuickWidget):
|
|||
entity.bare == self.target.bare
|
||||
or entity.bare == self.host.profiles[profile].whoami.bare
|
||||
):
|
||||
log.info(u"avatar updated for {}".format(entity))
|
||||
for m in self.messages.values():
|
||||
log.info("avatar updated for {}".format(entity))
|
||||
for m in list(self.messages.values()):
|
||||
if m.from_jid.bare == entity.bare:
|
||||
for w in m.widgets:
|
||||
w.update({"avatar": filename})
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ log = getLogger(__name__)
|
|||
|
||||
try:
|
||||
# FIXME: to be removed when an acceptable solution is here
|
||||
unicode("") # XXX: unicode doesn't exist in pyjamas
|
||||
str("") # XXX: unicode doesn't exist in pyjamas
|
||||
except (TypeError, AttributeError): # Error raised is not the same depending on
|
||||
# pyjsbuild options
|
||||
# XXX: pyjamas' max doesn't support key argument, so we implement it ourself
|
||||
|
|
@ -46,7 +46,7 @@ except (TypeError, AttributeError): # Error raised is not the same depending on
|
|||
# next doesn't exist in pyjamas
|
||||
def next(iterable, *args):
|
||||
try:
|
||||
return iterable.next()
|
||||
return iterable.__next__()
|
||||
except StopIteration as e:
|
||||
if args:
|
||||
return args[0]
|
||||
|
|
@ -184,7 +184,7 @@ class ProfileContactList(object):
|
|||
@return (dict[jid.JID, set(unicode)])
|
||||
"""
|
||||
result = {}
|
||||
for group, data in self._groups.iteritems():
|
||||
for group, data in self._groups.items():
|
||||
for entity in data["jids"]:
|
||||
result.setdefault(entity, set()).add(group)
|
||||
return result
|
||||
|
|
@ -203,7 +203,7 @@ class ProfileContactList(object):
|
|||
|
||||
entities are not sorted
|
||||
"""
|
||||
return self._cache.iteritems()
|
||||
return iter(self._cache.items())
|
||||
|
||||
@property
|
||||
def items(self):
|
||||
|
|
@ -214,7 +214,7 @@ class ProfileContactList(object):
|
|||
"""
|
||||
return {
|
||||
jid_: cache
|
||||
for jid_, cache in self._cache.iteritems()
|
||||
for jid_, cache in self._cache.items()
|
||||
if self.entityVisible(jid_)
|
||||
}
|
||||
|
||||
|
|
@ -340,9 +340,9 @@ class ProfileContactList(object):
|
|||
@raise ValueError: the entity is not bare
|
||||
"""
|
||||
if entity.resource:
|
||||
raise ValueError(u"getFullJid must be used with a bare jid")
|
||||
raise ValueError("getFullJid must be used with a bare jid")
|
||||
main_resource = self.getCache(entity, C.CONTACT_MAIN_RESOURCE)
|
||||
return jid.JID(u"{}/{}".format(entity, main_resource))
|
||||
return jid.JID("{}/{}".format(entity, main_resource))
|
||||
|
||||
def setGroupData(self, group, name, value):
|
||||
"""Register a data for a group
|
||||
|
|
@ -508,7 +508,7 @@ class ProfileContactList(object):
|
|||
if entity.resource
|
||||
else cache
|
||||
)
|
||||
for attribute, value in attributes.iteritems():
|
||||
for attribute, value in attributes.items():
|
||||
if value is None:
|
||||
# XXX: pyjamas hack: we need to use pop instead of del
|
||||
try:
|
||||
|
|
@ -596,7 +596,7 @@ class ProfileContactList(object):
|
|||
try:
|
||||
groups = self._cache[entity_bare].get(C.CONTACT_GROUPS, set())
|
||||
except KeyError:
|
||||
log.error(_(u"Trying to delete an unknow entity [{}]").format(entity))
|
||||
log.error(_("Trying to delete an unknow entity [{}]").format(entity))
|
||||
try:
|
||||
self._roster.remove(entity_bare)
|
||||
except KeyError:
|
||||
|
|
@ -639,8 +639,8 @@ class ProfileContactList(object):
|
|||
del cache[C.CONTACT_RESOURCES][entity.resource]
|
||||
except KeyError:
|
||||
log.error(
|
||||
u"Presence unavailable received "
|
||||
u"for an unknown resource [{}]".format(entity)
|
||||
"Presence unavailable received "
|
||||
"for an unknown resource [{}]".format(entity)
|
||||
)
|
||||
if not cache[C.CONTACT_RESOURCES]:
|
||||
cache[C.CONTACT_MAIN_RESOURCE] = None
|
||||
|
|
@ -648,8 +648,8 @@ class ProfileContactList(object):
|
|||
if not entity.resource:
|
||||
log.warning(
|
||||
_(
|
||||
u"received presence from entity "
|
||||
u"without resource: {}".format(entity)
|
||||
"received presence from entity "
|
||||
"without resource: {}".format(entity)
|
||||
)
|
||||
)
|
||||
resources_data = cache[C.CONTACT_RESOURCES]
|
||||
|
|
@ -703,12 +703,12 @@ class ProfileContactList(object):
|
|||
try:
|
||||
cache = self._cache[entity.bare]
|
||||
except:
|
||||
log.error(u"Try to unselect an entity not in cache")
|
||||
log.error("Try to unselect an entity not in cache")
|
||||
else:
|
||||
try:
|
||||
cache[C.CONTACT_SELECTED].remove(entity.resource)
|
||||
except KeyError:
|
||||
log.error(u"Try to unselect a not selected entity")
|
||||
log.error("Try to unselect a not selected entity")
|
||||
else:
|
||||
self._selected.remove(entity)
|
||||
self.update([entity], C.UPDATE_SELECTION)
|
||||
|
|
@ -721,15 +721,15 @@ class ProfileContactList(object):
|
|||
"""
|
||||
if entity is None:
|
||||
self._selected.clear()
|
||||
for cache in self._cache.itervalues():
|
||||
for cache in self._cache.values():
|
||||
cache[C.CONTACT_SELECTED].clear()
|
||||
self.update(type_=C.UPDATE_SELECTION, profile=self.profile)
|
||||
else:
|
||||
log.debug(u"select %s" % entity)
|
||||
log.debug("select %s" % entity)
|
||||
try:
|
||||
cache = self._cache[entity.bare]
|
||||
except:
|
||||
log.error(u"Try to select an entity not in cache")
|
||||
log.error("Try to select an entity not in cache")
|
||||
else:
|
||||
cache[C.CONTACT_SELECTED].add(entity.resource)
|
||||
self._selected.add(entity)
|
||||
|
|
@ -777,7 +777,7 @@ class QuickContactListHandler(object):
|
|||
global handler
|
||||
if handler is not None:
|
||||
raise exceptions.InternalError(
|
||||
u"QuickContactListHandler must be instanciated only once"
|
||||
"QuickContactListHandler must be instanciated only once"
|
||||
)
|
||||
handler = self
|
||||
self._clist = {} # key: profile, value: ProfileContactList
|
||||
|
|
@ -794,7 +794,7 @@ class QuickContactListHandler(object):
|
|||
@param entity (jid.JID): jid of the entity (resource is not ignored,
|
||||
use bare jid if needed)
|
||||
"""
|
||||
for contact_list in self._clist.itervalues():
|
||||
for contact_list in self._clist.values():
|
||||
if entity in contact_list:
|
||||
return True
|
||||
return False
|
||||
|
|
@ -806,7 +806,7 @@ class QuickContactListHandler(object):
|
|||
@return (set[jid.JID])
|
||||
"""
|
||||
entities = set()
|
||||
for contact_list in self._clist.itervalues():
|
||||
for contact_list in self._clist.values():
|
||||
entities.update(contact_list.roster)
|
||||
return entities
|
||||
|
||||
|
|
@ -817,7 +817,7 @@ class QuickContactListHandler(object):
|
|||
@return (set[jid.JID])
|
||||
"""
|
||||
entities = set()
|
||||
for contact_list in self._clist.itervalues():
|
||||
for contact_list in self._clist.values():
|
||||
entities.update(contact_list.roster_connected)
|
||||
return entities
|
||||
|
||||
|
|
@ -829,7 +829,7 @@ class QuickContactListHandler(object):
|
|||
@return (dict[unicode,set(jid.JID)])
|
||||
"""
|
||||
groups = {}
|
||||
for contact_list in self._clist.itervalues():
|
||||
for contact_list in self._clist.values():
|
||||
groups.update(contact_list.roster_entities_by_group)
|
||||
return groups
|
||||
|
||||
|
|
@ -841,7 +841,7 @@ class QuickContactListHandler(object):
|
|||
@return (dict[jid.JID, set(unicode)])
|
||||
"""
|
||||
entities = {}
|
||||
for contact_list in self._clist.itervalues():
|
||||
for contact_list in self._clist.values():
|
||||
entities.update(contact_list.roster_groups_by_entities)
|
||||
return entities
|
||||
|
||||
|
|
@ -852,7 +852,7 @@ class QuickContactListHandler(object):
|
|||
@return (set): set of selected entities
|
||||
"""
|
||||
entities = set()
|
||||
for contact_list in self._clist.itervalues():
|
||||
for contact_list in self._clist.values():
|
||||
entities.update(contact_list.selected)
|
||||
return entities
|
||||
|
||||
|
|
@ -862,7 +862,7 @@ class QuickContactListHandler(object):
|
|||
|
||||
items are unordered
|
||||
"""
|
||||
for profile, contact_list in self._clist.iteritems():
|
||||
for profile, contact_list in self._clist.items():
|
||||
for bare_jid, cache in contact_list.all_iter:
|
||||
data = cache.copy()
|
||||
data[C.CONTACT_PROFILE] = profile
|
||||
|
|
@ -876,8 +876,8 @@ class QuickContactListHandler(object):
|
|||
key: bare jid, value: data
|
||||
"""
|
||||
items = {}
|
||||
for profile, contact_list in self._clist.iteritems():
|
||||
for bare_jid, cache in contact_list.items.iteritems():
|
||||
for profile, contact_list in self._clist.items():
|
||||
for bare_jid, cache in contact_list.items.items():
|
||||
data = cache.copy()
|
||||
items[bare_jid] = data
|
||||
data[C.CONTACT_PROFILE] = profile
|
||||
|
|
@ -953,7 +953,7 @@ class QuickContactListHandler(object):
|
|||
@return (set[jid.JID])
|
||||
"""
|
||||
entities = set()
|
||||
for contact_list in self._clist.itervalues():
|
||||
for contact_list in self._clist.values():
|
||||
entities.update(contact_list.getSpecialExtras(special_type))
|
||||
return entities
|
||||
|
||||
|
|
@ -984,13 +984,13 @@ class QuickContactListHandler(object):
|
|||
assert profile in self._clist
|
||||
to_fill.add(profile)
|
||||
else:
|
||||
to_fill.update(self._clist.keys())
|
||||
to_fill.update(list(self._clist.keys()))
|
||||
|
||||
remaining = to_fill.difference(filled)
|
||||
if remaining != to_fill:
|
||||
log.debug(
|
||||
u"Not re-filling already filled contact list(s) for {}".format(
|
||||
u", ".join(to_fill.intersection(filled))
|
||||
"Not re-filling already filled contact list(s) for {}".format(
|
||||
", ".join(to_fill.intersection(filled))
|
||||
)
|
||||
)
|
||||
for profile in remaining:
|
||||
|
|
@ -1001,17 +1001,17 @@ class QuickContactListHandler(object):
|
|||
|
||||
@param keep_cache: if True, don't reset the cache
|
||||
"""
|
||||
for contact_list in self._clist.itervalues():
|
||||
for contact_list in self._clist.values():
|
||||
contact_list.clearContacts(keep_cache)
|
||||
# we need a full update
|
||||
self.update()
|
||||
|
||||
def select(self, entity):
|
||||
for contact_list in self._clist.itervalues():
|
||||
for contact_list in self._clist.values():
|
||||
contact_list.select(entity)
|
||||
|
||||
def unselect(self, entity):
|
||||
for contact_list in self._clist.itervalues():
|
||||
for contact_list in self._clist.values():
|
||||
contact_list.select(entity)
|
||||
|
||||
def lockUpdate(self, locked=True, do_update=True):
|
||||
|
|
@ -1025,8 +1025,8 @@ class QuickContactListHandler(object):
|
|||
what youa re doing!
|
||||
"""
|
||||
log.debug(
|
||||
u"Contact lists updates are now {}".format(
|
||||
u"LOCKED" if locked else u"UNLOCKED"
|
||||
"Contact lists updates are now {}".format(
|
||||
"LOCKED" if locked else "UNLOCKED"
|
||||
)
|
||||
)
|
||||
self._update_locked = locked
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ class QuickContactManagement(object):
|
|||
|
||||
def add(self, entity):
|
||||
"""Add contact to the list, update resources"""
|
||||
if not self.__contactlist.has_key(entity.bare):
|
||||
if entity.bare not in self.__contactlist:
|
||||
self.__contactlist[entity.bare] = {"resources": []}
|
||||
if not entity.resource:
|
||||
return
|
||||
|
|
@ -53,7 +53,7 @@ class QuickContactManagement(object):
|
|||
"""Return all contacts which are in given group"""
|
||||
result = []
|
||||
for contact in self.__contactlist:
|
||||
if self.__contactlist[contact].has_key("groups"):
|
||||
if "groups" in self.__contactlist[contact]:
|
||||
if group in self.__contactlist[contact]["groups"]:
|
||||
result.append(JID(contact))
|
||||
return result
|
||||
|
|
@ -63,11 +63,11 @@ class QuickContactManagement(object):
|
|||
@param entity: jid of the contact
|
||||
@param name: name of the attribute
|
||||
@return: asked attribute"""
|
||||
if self.__contactlist.has_key(entity.bare):
|
||||
if entity.bare in self.__contactlist:
|
||||
if name == "status": # FIXME: for the moment, we only use the first status
|
||||
if self.__contactlist[entity.bare]["statuses"]:
|
||||
return self.__contactlist[entity.bare]["statuses"].values()[0]
|
||||
if self.__contactlist[entity.bare].has_key(name):
|
||||
return list(self.__contactlist[entity.bare]["statuses"].values())[0]
|
||||
if name in self.__contactlist[entity.bare]:
|
||||
return self.__contactlist[entity.bare][name]
|
||||
else:
|
||||
log.debug(_("Trying to get attribute for an unknown contact"))
|
||||
|
|
@ -75,7 +75,7 @@ class QuickContactManagement(object):
|
|||
|
||||
def isConnected(self, entity):
|
||||
"""Tell if the contact is online"""
|
||||
return self.__contactlist.has_key(entity.bare)
|
||||
return entity.bare in self.__contactlist
|
||||
|
||||
def remove(self, entity):
|
||||
"""remove resource. If no more resource is online or is no resource is specified, contact is deleted"""
|
||||
|
|
@ -95,7 +95,7 @@ class QuickContactManagement(object):
|
|||
@param key: name of the attribute
|
||||
@param value: value of the attribute
|
||||
"""
|
||||
if self.__contactlist.has_key(entity.bare):
|
||||
if entity.bare in self.__contactlist:
|
||||
self.__contactlist[entity.bare][key] = value
|
||||
else:
|
||||
log.debug(_("Trying to update an unknown contact: %s") % entity.bare)
|
||||
|
|
|
|||
|
|
@ -33,15 +33,15 @@ class QuickTarotGame(object):
|
|||
for player in players:
|
||||
self.played[player] = None
|
||||
self.player_nick = parent.nick
|
||||
self.bottom_nick = unicode(self.player_nick)
|
||||
self.bottom_nick = str(self.player_nick)
|
||||
idx = self.players.index(self.player_nick)
|
||||
idx = (idx + 1) % len(self.players)
|
||||
self.right_nick = unicode(self.players[idx])
|
||||
self.right_nick = str(self.players[idx])
|
||||
idx = (idx + 1) % len(self.players)
|
||||
self.top_nick = unicode(self.players[idx])
|
||||
self.top_nick = str(self.players[idx])
|
||||
idx = (idx + 1) % len(self.players)
|
||||
self.left_nick = unicode(self.players[idx])
|
||||
self.bottom_nick = unicode(self.player_nick)
|
||||
self.left_nick = str(self.players[idx])
|
||||
self.bottom_nick = str(self.player_nick)
|
||||
self.selected = [] # Card choosed by the player (e.g. during ecart)
|
||||
self.hand_size = 13 # number of cards in a hand
|
||||
self.hand = []
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ from sat_frontends.tools import jid
|
|||
from sat_frontends.tools import games
|
||||
from sat_frontends.quick_frontend.constants import Const as C
|
||||
|
||||
import quick_chat
|
||||
from . import quick_chat
|
||||
|
||||
|
||||
class RoomGame(object):
|
||||
|
|
@ -82,9 +82,9 @@ class RoomGame(object):
|
|||
if real_class == cls:
|
||||
host.showDialog(
|
||||
_(
|
||||
u"A {game} activity between {players} has been started, but you couldn't take part because your client doesn't support it."
|
||||
"A {game} activity between {players} has been started, but you couldn't take part because your client doesn't support it."
|
||||
).format(game=cls._game_name, players=", ".join(players)),
|
||||
_(u"{game} Game").format(game=cls._game_name),
|
||||
_("{game} Game").format(game=cls._game_name),
|
||||
)
|
||||
return
|
||||
panel = real_class(chat_widget, referee, players, *args)
|
||||
|
|
|
|||
|
|
@ -19,12 +19,12 @@
|
|||
|
||||
try:
|
||||
# FIXME: to be removed when an acceptable solution is here
|
||||
unicode("") # XXX: unicode doesn't exist in pyjamas
|
||||
str("") # XXX: unicode doesn't exist in pyjamas
|
||||
except (
|
||||
TypeError,
|
||||
AttributeError,
|
||||
): # Error raised is not the same depending on pyjsbuild options
|
||||
unicode = str
|
||||
str = str
|
||||
|
||||
from sat.core.log import getLogger
|
||||
from sat.core.i18n import _, languageSwitch
|
||||
|
|
@ -100,11 +100,11 @@ class MenuItem(MenuBase):
|
|||
|
||||
else:
|
||||
if caller is None:
|
||||
log.error(u"Caller can't be None with a dictionary as data_collector")
|
||||
log.error("Caller can't be None with a dictionary as data_collector")
|
||||
return {}
|
||||
data = {}
|
||||
for data_key, caller_attr in data_collector.iteritems():
|
||||
data[data_key] = unicode(getattr(caller, caller_attr))
|
||||
for data_key, caller_attr in data_collector.items():
|
||||
data[data_key] = str(getattr(caller, caller_attr))
|
||||
return data
|
||||
|
||||
def call(self, caller, profile=C.PROF_KEY_NONE):
|
||||
|
|
@ -189,7 +189,7 @@ class MenuSeparator(MenuItem):
|
|||
|
||||
def __init__(self):
|
||||
MenuSeparator.SEP_IDX += 1
|
||||
name = u"___separator_{}".format(MenuSeparator.SEP_IDX)
|
||||
name = "___separator_{}".format(MenuSeparator.SEP_IDX)
|
||||
MenuItem.__init__(self, name, name)
|
||||
|
||||
|
||||
|
|
@ -208,7 +208,7 @@ class MenuContainer(MenuBase):
|
|||
return item.canonical in self._items
|
||||
|
||||
def __iter__(self):
|
||||
return self._items.itervalues()
|
||||
return iter(self._items.values())
|
||||
|
||||
def __getitem__(self, item):
|
||||
try:
|
||||
|
|
@ -218,8 +218,8 @@ class MenuContainer(MenuBase):
|
|||
|
||||
def getOrCreate(self, item):
|
||||
log.debug(
|
||||
u"MenuContainer getOrCreate: item=%s name=%s\nlist=%s"
|
||||
% (item, item.canonical, self._items.keys())
|
||||
"MenuContainer getOrCreate: item=%s name=%s\nlist=%s"
|
||||
% (item, item.canonical, list(self._items.keys()))
|
||||
)
|
||||
try:
|
||||
return self[item]
|
||||
|
|
@ -229,7 +229,7 @@ class MenuContainer(MenuBase):
|
|||
|
||||
def getActiveMenus(self):
|
||||
"""Return an iterator on active children"""
|
||||
for child in self._items.itervalues():
|
||||
for child in self._items.values():
|
||||
if child.ACTIVE:
|
||||
yield child
|
||||
|
||||
|
|
@ -347,7 +347,7 @@ class QuickMenusManager(object):
|
|||
try:
|
||||
return QuickMenusManager._data_collectors[type_]
|
||||
except KeyError:
|
||||
log.error(u"No data collector registered for {}".format(type_))
|
||||
log.error("No data collector registered for {}".format(type_))
|
||||
return None
|
||||
|
||||
def addMenuItem(self, type_, path, item, path_i18n=None, top_extra=None):
|
||||
|
|
@ -375,14 +375,14 @@ class QuickMenusManager(object):
|
|||
elif isinstance(container_item, MenuHook):
|
||||
# MenuHook must not be replaced
|
||||
log.debug(
|
||||
u"ignoring menu at path [{}] because a hook is already in place".format(
|
||||
"ignoring menu at path [{}] because a hook is already in place".format(
|
||||
path
|
||||
)
|
||||
)
|
||||
else:
|
||||
log.error(u"Conflicting menus at path [{}]".format(path))
|
||||
log.error("Conflicting menus at path [{}]".format(path))
|
||||
else:
|
||||
log.debug(u"Adding menu [{type_}] {path}".format(type_=type_, path=path))
|
||||
log.debug("Adding menu [{type_}] {path}".format(type_=type_, path=path))
|
||||
menu_container.append(item)
|
||||
self.host.callListeners("menu", type_, path, path_i18n, item)
|
||||
|
||||
|
|
@ -461,7 +461,7 @@ class QuickMenusManager(object):
|
|||
type_, path[-1], path_i18n[-1], callback=callback, extra=extra
|
||||
)
|
||||
self.addMenuItem(type_, path[:-1], menu_item, path_i18n[:-1], top_extra)
|
||||
log.info(u"Menu hook set on {path} ({type_})".format(path=path, type_=type_))
|
||||
log.info("Menu hook set on {path} ({type_})".format(path=path, type_=type_))
|
||||
|
||||
def addCategory(self, type_, path, path_i18n=None, extra=None, top_extra=None):
|
||||
"""Create a category with all parents, and set extra on the last one
|
||||
|
|
|
|||
|
|
@ -122,7 +122,7 @@ class QuickProfileManager(object):
|
|||
)
|
||||
|
||||
def getProfileNameEb(failure):
|
||||
log.error(u"Can't retrieve profile name: {}".format(failure))
|
||||
log.error("Can't retrieve profile name: {}".format(failure))
|
||||
|
||||
for profile_key in profile_keys:
|
||||
self.host.bridge.profileNameGet(
|
||||
|
|
@ -130,7 +130,7 @@ class QuickProfileManager(object):
|
|||
)
|
||||
|
||||
def getParamError(self, __):
|
||||
self.host.showDialog(_(u"Error"), _("Can't get profile parameter"), "error")
|
||||
self.host.showDialog(_("Error"), _("Can't get profile parameter"), "error")
|
||||
|
||||
## Helping methods ##
|
||||
|
||||
|
|
@ -215,14 +215,14 @@ class QuickProfileManager(object):
|
|||
self.host.bridge.setParam(
|
||||
"JabberID", login, "Connection", profile_key=self.current.profile
|
||||
)
|
||||
log.info(u"login updated for profile [{}]".format(self.current.profile))
|
||||
log.info("login updated for profile [{}]".format(self.current.profile))
|
||||
if password != self.current.password and self.current.password is not None:
|
||||
self.current.password = password
|
||||
self.host.bridge.setParam(
|
||||
"Password", password, "Connection", profile_key=self.current.profile
|
||||
)
|
||||
log.info(
|
||||
u"password updated for profile [{}]".format(self.current.profile)
|
||||
"password updated for profile [{}]".format(self.current.profile)
|
||||
)
|
||||
|
||||
## graphic updates (should probably be overriden in frontends) ##
|
||||
|
|
|
|||
|
|
@ -50,5 +50,5 @@ def check_options():
|
|||
|
||||
(options, args) = parser.parse_args()
|
||||
if options.profile:
|
||||
options.profile = options.profile.decode("utf-8")
|
||||
options.profile = options.profile
|
||||
return options
|
||||
|
|
|
|||
|
|
@ -29,12 +29,12 @@ classes_map = {}
|
|||
|
||||
try:
|
||||
# FIXME: to be removed when an acceptable solution is here
|
||||
unicode("") # XXX: unicode doesn't exist in pyjamas
|
||||
str("") # XXX: unicode doesn't exist in pyjamas
|
||||
except (
|
||||
TypeError,
|
||||
AttributeError,
|
||||
): # Error raised is not the same depending on pyjsbuild options
|
||||
unicode = str
|
||||
str = str
|
||||
|
||||
|
||||
def register(base_cls, child_cls=None):
|
||||
|
|
@ -63,8 +63,8 @@ class QuickWidgetsManager(object):
|
|||
|
||||
def __iter__(self):
|
||||
"""Iterate throught all widgets"""
|
||||
for widget_map in self._widgets.itervalues():
|
||||
for widget_instances in widget_map.itervalues():
|
||||
for widget_map in self._widgets.values():
|
||||
for widget_instances in widget_map.values():
|
||||
for widget in widget_instances:
|
||||
yield widget
|
||||
|
||||
|
|
@ -114,14 +114,14 @@ class QuickWidgetsManager(object):
|
|||
return
|
||||
else:
|
||||
if target is not None:
|
||||
filter_hash = unicode(class_.getWidgetHash(target, profiles))
|
||||
filter_hash = str(class_.getWidgetHash(target, profiles))
|
||||
else:
|
||||
filter_hash = None
|
||||
if filter_hash is not None:
|
||||
for widget in widgets_map.get(filter_hash, []):
|
||||
yield widget
|
||||
else:
|
||||
for widget_instances in widgets_map.itervalues():
|
||||
for widget_instances in widgets_map.values():
|
||||
for widget in widget_instances:
|
||||
yield widget
|
||||
|
||||
|
|
@ -136,7 +136,7 @@ class QuickWidgetsManager(object):
|
|||
@return: a class_ instance or None if the widget doesn't exist
|
||||
"""
|
||||
assert (target is not None) or (profiles is not None)
|
||||
if profiles is not None and isinstance(profiles, unicode):
|
||||
if profiles is not None and isinstance(profiles, str):
|
||||
profiles = [profiles]
|
||||
class_ = self.getRealClass(class_)
|
||||
hash_ = class_.getWidgetHash(target, profiles)
|
||||
|
|
@ -223,7 +223,7 @@ class QuickWidgetsManager(object):
|
|||
|
||||
if widget is None:
|
||||
# we need to create a new widget
|
||||
log.debug(u"Creating new widget for target {} {}".format(target, cls))
|
||||
log.debug("Creating new widget for target {} {}".format(target, cls))
|
||||
widget = cls(*_args, **_kwargs)
|
||||
widgets_map[hash_] = [widget]
|
||||
|
||||
|
|
@ -248,13 +248,13 @@ class QuickWidgetsManager(object):
|
|||
recreateArgs(_args, _kwargs)
|
||||
widget = cls(*_args, **_kwargs)
|
||||
widgets_map[hash_].append(widget)
|
||||
log.debug(u"widget <{wid}> already exists, a new one has been recreated"
|
||||
log.debug("widget <{wid}> already exists, a new one has been recreated"
|
||||
.format(wid=widget))
|
||||
elif callable(on_existing_widget):
|
||||
widget = on_existing_widget(widget)
|
||||
if widget is None:
|
||||
raise exceptions.InternalError(
|
||||
u"on_existing_widget method must return the widget to use")
|
||||
"on_existing_widget method must return the widget to use")
|
||||
else:
|
||||
raise exceptions.InternalError(
|
||||
"Unexpected on_existing_widget value ({})".format(on_existing_widget))
|
||||
|
|
@ -295,9 +295,9 @@ class QuickWidgetsManager(object):
|
|||
try:
|
||||
widgets_map = self._widgets[class_.__name__]
|
||||
except KeyError:
|
||||
log.error(u"no widgets_map found for class {cls}".format(cls=class_))
|
||||
log.error("no widgets_map found for class {cls}".format(cls=class_))
|
||||
return
|
||||
widget_hash = unicode(class_.getWidgetHash(widget_to_delete.target,
|
||||
widget_hash = str(class_.getWidgetHash(widget_to_delete.target,
|
||||
widget_to_delete.profiles))
|
||||
widget_instances = widgets_map[widget_hash]
|
||||
if all_instances:
|
||||
|
|
@ -306,16 +306,16 @@ class QuickWidgetsManager(object):
|
|||
try:
|
||||
widget_instances.remove(widget_to_delete)
|
||||
except ValueError:
|
||||
log.error(u"widget_to_delete not found in widget instances")
|
||||
log.error("widget_to_delete not found in widget instances")
|
||||
return
|
||||
|
||||
log.debug(u"widget {} deleted".format(widget_to_delete))
|
||||
log.debug("widget {} deleted".format(widget_to_delete))
|
||||
|
||||
if not widget_instances:
|
||||
# all instances with this hash have been deleted
|
||||
# we remove the hash itself
|
||||
del widgets_map[widget_hash]
|
||||
log.debug(u"All instances of {cls} with hash {widget_hash} have been deleted"
|
||||
log.debug("All instances of {cls} with hash {widget_hash} have been deleted"
|
||||
.format(cls=class_, widget_hash=widget_hash))
|
||||
|
||||
|
||||
|
|
@ -345,7 +345,7 @@ class QuickWidget(object):
|
|||
self.addTarget(target)
|
||||
self.profiles = set()
|
||||
self._sync = True
|
||||
if isinstance(profiles, basestring):
|
||||
if isinstance(profiles, str):
|
||||
self.addProfile(profiles)
|
||||
elif profiles is None:
|
||||
if not self.PROFILES_ALLOW_NONE:
|
||||
|
|
@ -430,7 +430,7 @@ class QuickWidget(object):
|
|||
@param profiles: profile(s) associated to target, see __init__ docstring
|
||||
@return: a hash (can correspond to one or many targets or profiles, depending of widget class)
|
||||
"""
|
||||
return unicode(target) # by defaut, there is one hash for one target
|
||||
return str(target) # by defaut, there is one hash for one target
|
||||
|
||||
# widget life events
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue