This commit is contained in:
Denis Fomin 2013-01-02 22:13:27 +04:00
commit ac9253e04a
106 changed files with 1283 additions and 1394 deletions

View File

@ -407,7 +407,7 @@ if dbus_support.supported:
return DBUS_DICT_SV()
jid = self._get_real_jid(jid)
cached_vcard = gajim.connections.values()[0].get_cached_vcard(jid)
cached_vcard = list(gajim.connections.values())[0].get_cached_vcard(jid)
if cached_vcard:
return get_dbus_struct(cached_vcard)
@ -428,7 +428,7 @@ if dbus_support.supported:
def account_info(self, account):
'''show info on account: resource, jid, nick, prio, message'''
result = DBUS_DICT_SS()
if gajim.connections.has_key(account):
if account in gajim.connections:
# account is valid
con = gajim.connections[account]
index = con.connected
@ -508,7 +508,7 @@ if dbus_support.supported:
def prefs_store(self):
try:
gajim.interface.save_config()
except Exception, e:
except Exception as e:
return DBUS_BOOLEAN(False)
return DBUS_BOOLEAN(True)

View File

@ -159,7 +159,7 @@ class CommandWindow:
return self.stage_adhoc_commands_window_delete_event(self.window)
def __del__(self):
print 'Object has been deleted.'
print('Object has been deleted.')
# stage 1: waiting for command list
def stage1(self):
@ -281,8 +281,6 @@ class CommandWindow:
# close old stage
self.stage_finish()
assert isinstance(self.commandnode, unicode)
self.form_status = None
self.stages_notebook.set_current_page(
@ -452,7 +450,7 @@ class CommandWindow:
note = command.getTag('note')
if note:
self.notes_label.set_text(note.getData().decode('utf-8'))
self.notes_label.set_text(note.getData())
self.notes_label.set_no_show_all(False)
self.notes_label.show()
else:
@ -510,7 +508,7 @@ class CommandWindow:
try:
errorname = nbxmpp.NS_STANZAS + ' ' + str(errorid)
errordesc = nbxmpp.ERRORS[errorname][2]
error = errordesc.decode('utf-8')
error = errordesc
del errorname, errordesc
except KeyError: # when stanza doesn't have error description
error = _('Service returned an error.')
@ -608,7 +606,6 @@ class CommandWindow:
Send the command with data form. Wait for reply
"""
# create the stanza
assert isinstance(self.commandnode, unicode)
assert action in ('execute', 'prev', 'next', 'complete')
stanza = nbxmpp.Iq(typ='set', to=self.jid)

View File

@ -141,8 +141,7 @@ class AdvancedConfigurationWindow(object):
"""
optname = model[iter_][C_PREFNAME]
opttype = model[iter_][C_TYPE]
if opttype.decode('utf-8') == self.types['boolean'] or optname == 'password':
if opttype == self.types['boolean'] or optname == 'password':
cell.set_property('editable', False)
else:
cell.set_property('editable', True)
@ -153,10 +152,10 @@ class AdvancedConfigurationWindow(object):
# path[1] is the key name
# path[2] is the root of tree
# last two is optional
path = [model[iter_][0].decode('utf-8')]
path = [model[iter_][0]]
parent = model.iter_parent(iter_)
while parent:
path.append(model[parent][0].decode('utf-8'))
path.append(model[parent][0])
parent = model.iter_parent(parent)
return path
@ -194,17 +193,17 @@ class AdvancedConfigurationWindow(object):
def on_advanced_treeview_row_activated(self, treeview, path, column):
modelpath = self.modelfilter.convert_path_to_child_path(path)
modelrow = self.model[modelpath]
option = modelrow[0].decode('utf-8')
if modelrow[2].decode('utf-8') == self.types['boolean']:
option = modelrow[0]
if modelrow[2] == self.types['boolean']:
for key in self.right_true_dict.keys():
if self.right_true_dict[key] == modelrow[1].decode('utf-8'):
if self.right_true_dict[key] == modelrow[1]:
modelrow[1] = str(key)
newval = {'False': True, 'True': False}[modelrow[1]]
if len(modelpath.get_indices()) > 1:
optnamerow = self.model[modelpath.get_indices()[0]]
optname = optnamerow[0].decode('utf-8')
optname = optnamerow[0]
keyrow = self.model[modelpath.get_indices()[:2]]
key = keyrow[0].decode('utf-8')
key = keyrow[0]
self.remember_option(option + '\n' + key + '\n' + optname,
modelrow[1], newval)
gajim.config.set_per(optname, key, option, newval)
@ -234,13 +233,12 @@ class AdvancedConfigurationWindow(object):
modelpath = self.modelfilter.convert_path_to_child_path(path)
modelrow = self.model[modelpath]
modelpath = modelpath.get_indices()
option = modelrow[0].decode('utf-8')
text = text.decode('utf-8')
option = modelrow[0]
if len(modelpath) > 1:
optnamerow = self.model[modelpath[0]]
optname = optnamerow[0].decode('utf-8')
optname = optnamerow[0]
keyrow = self.model[modelpath[:2]]
key = keyrow[0].decode('utf-8')
key = keyrow[0]
self.remember_option(option + '\n' + key + '\n' + optname, modelrow[1],
text)
gajim.config.set_per(optname, key, option, text)
@ -269,12 +267,12 @@ class AdvancedConfigurationWindow(object):
return
modelpath = self.modelfilter.convert_path_to_child_path(path)
modelrow = self.model[modelpath]
option = modelrow[0].decode('utf-8')
option = modelrow[0]
if len(modelpath) > 1:
optnamerow = self.model[modelpath[0]]
optname = optnamerow[0].decode('utf-8')
optname = optnamerow[0]
keyrow = self.model[modelpath[:2]]
key = keyrow[0].decode('utf-8')
key = keyrow[0]
self.remember_option(option + '\n' + key + '\n' + optname,
modelrow[C_VALUE], default)
gajim.config.set_per(optname, key, option, default)
@ -313,11 +311,10 @@ class AdvancedConfigurationWindow(object):
value = str(option)
except:
value = option
value = helpers.ensure_utf8_string(value)
self.model.append(parent, [name, value, type_])
def visible_func(self, model, treeiter, data):
search_string = self.entry.get_text().decode('utf-8').lower()
search_string = self.entry.get_text().lower()
for it in tree_model_pre_order(model, treeiter):
if model[it][C_TYPE] != '':
opt_path = self.get_option_path(model, it)

View File

@ -84,20 +84,20 @@ class AtomWindow:
# fill the fields
if newentry.feed_link is not None:
self.feed_title_label.set_markup(
u'<span foreground="blue" underline="single">%s</span>' % \
'<span foreground="blue" underline="single">%s</span>' % \
GObject.markup_escape_text(newentry.feed_title))
else:
self.feed_title_label.set_markup(
GObject.markup_escape_text(newentry.feed_title))
self.feed_tagline_label.set_markup(
u'<small>%s</small>' % \
'<small>%s</small>' % \
GObject.markup_escape_text(newentry.feed_tagline))
if newentry.title:
if newentry.uri is not None:
self.entry_title_label.set_markup(
u'<span foreground="blue" underline="single">%s</span>' % \
'<span foreground="blue" underline="single">%s</span>' % \
GObject.markup_escape_text(newentry.title))
else:
self.entry_title_label.set_markup(

View File

@ -620,7 +620,7 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
message_buffer = self.msg_textview.get_buffer()
start_iter = message_buffer.get_start_iter()
end_iter = message_buffer.get_end_iter()
message = message_buffer.get_text(start_iter, end_iter, False).decode('utf-8')
message = message_buffer.get_text(start_iter, end_iter, False)
xhtml = self.msg_textview.get_xhtml()
# send the message
@ -917,7 +917,7 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
scroll = False if pos == size else True # are we scrolling?
# we don't want size of the buffer to grow indefinately
max_size = gajim.config.get('key_up_lines')
for i in xrange(size - max_size + 1):
for i in range(size - max_size + 1):
if pos == 0:
break
history.pop(0)
@ -1786,7 +1786,7 @@ class ChatControl(ChatControlBase):
pep = self.contact.pep
img = self._pep_images[pep_type]
if pep_type in pep:
img.set_from_pixbuf(pep[pep_type].asPixbufIcon())
img.set_from_pixbuf(gtkgui_helpers.get_pep_as_pixbuf(pep[pep_type]))
img.set_tooltip_markup(pep[pep_type].asMarkupText())
img.show()
else:
@ -2506,7 +2506,7 @@ class ChatControl(ChatControlBase):
if num_unread == 1 and not gajim.config.get('show_unread_tab_icon'):
unread = '*'
elif num_unread > 1:
unread = '[' + unicode(num_unread) + ']'
unread = '[' + str(num_unread) + ']'
# Draw tab label using chatstate
theme = gajim.config.get('roster_theme')
@ -2843,7 +2843,7 @@ class ChatControl(ChatControlBase):
type_ = model[iter_][2]
if type_ != 'contact': # source is not a contact
return
dropped_jid = data.decode('utf-8')
dropped_jid = data
dropped_transport = gajim.get_transport_name_from_jid(dropped_jid)
c_transport = gajim.get_transport_name_from_jid(c.jid)
@ -3021,7 +3021,7 @@ class ChatControl(ChatControlBase):
# It's why I set it transparent.
image = self.xml.get_object('avatar_image')
pixbuf = image.get_pixbuf()
pixbuf.fill(0xffffff00L) # RGBA
pixbuf.fill(0xffffff00) # RGBA
image.queue_draw()
screen_w = Gdk.Screen.width()

View File

@ -31,8 +31,7 @@ to automatic discovery and dispatching, also features manual control
over the process.
"""
from types import NoneType
from tools import remove
from .tools import remove
COMMANDS = {}
CONTAINERS = {}
@ -71,7 +70,7 @@ def is_command(attribute):
return isinstance(attribute, Command)
def is_root(namespace):
metaclass = namespace.get("__metaclass__", NoneType)
metaclass = namespace.get("__metaclass__", None)
return issubclass(metaclass, Dispatchable)
def get_command(host, name):
@ -83,7 +82,7 @@ def get_command(host, name):
def list_commands(host):
for container in CONTAINERS[host]:
commands = COMMANDS[container]
for name, command in commands.iteritems():
for name, command in commands.items():
yield name, command
class Dispatchable(type):

View File

@ -23,10 +23,10 @@ import re
from types import FunctionType
from inspect import getargspec, getdoc
from dispatcher import Host, Container
from dispatcher import get_command, list_commands
from mapping import parse_arguments, adapt_arguments
from errors import DefinitionError, CommandError, NoCommandError
from .dispatcher import Host, Container
from .dispatcher import get_command, list_commands
from .mapping import parse_arguments, adapt_arguments
from .errors import DefinitionError, CommandError, NoCommandError
class CommandHost(object):
"""
@ -153,7 +153,7 @@ class Command(object):
# Automatically set all the properties passed to a constructor
# by the command decorator.
for key, value in properties.iteritems():
for key, value in properties.items():
setattr(self, key, value)
def __call__(self, *args, **kwargs):
@ -165,7 +165,7 @@ class Command(object):
# command or name attributes set. They will be set to a
# corresponding values right here in case if they was not set by
# the one who raised an exception.
except CommandError, error:
except CommandError as error:
if not error.command and not error.name:
raise CommandError(error.message, self)
raise

View File

@ -35,7 +35,7 @@ detected.
"""
from ..framework import CommandContainer, command, doc
from hosts import *
from .hosts import *
class CustomCommonCommands(CommandContainer):
"""

View File

@ -35,10 +35,10 @@ commands as a frontend.
from subprocess import Popen, PIPE
from os.path import expanduser
from glib import timeout_add
from gi.repository import GObject
from ..framework import CommandContainer, command, doc
from hosts import *
from .hosts import *
class Execute(CommandContainer):
AUTOMATIC = True
@ -64,11 +64,11 @@ class Execute(CommandContainer):
@classmethod
def monitor(cls, processor, popen):
poller = cls.poller(processor, popen)
timeout_add(cls.POLL_INTERVAL, poller.next)
GObject.timeout_add(cls.POLL_INTERVAL, poller.next)
@classmethod
def poller(cls, processor, popen):
for x in xrange(cls.POLL_COUNT):
for x in list(range(cls.POLL_COUNT)):
yield cls.brush(processor, popen)
cls.overdue(processor, popen)
yield False

View File

@ -31,7 +31,6 @@ support interaction between the two and a few utility methods so you
don't need to dig up the code itself to write basic commands.
"""
from types import StringTypes
from traceback import print_exc
from gi.repository import Pango
@ -62,13 +61,13 @@ class ChatCommandProcessor(CommandProcessor):
try:
parents = super(ChatCommandProcessor, self)
parents.execute_command(name, arguments)
except NoCommandError, error:
except NoCommandError as error:
details = dict(name=error.name, message=error.message)
message = "%(name)s: %(message)s\n" % details
message += "Try using the //%(name)s or /say /%(name)s " % details
message += "construct if you intended to send it as a text."
self.echo_error(message)
except CommandError, error:
except CommandError as error:
self.echo_error("%s: %s" % (error.name, error.message))
except Exception:
self.echo_error(_("Error during command execution!"))
@ -98,7 +97,7 @@ class ChatCommandProcessor(CommandProcessor):
def command_postprocessor(self, command, name, arguments, args, kwargs, value):
# If command returns a string - print it to a user. A convenient
# and sufficient in most simple cases shortcut to a using echo.
if value and isinstance(value, StringTypes):
if value and isinstance(value, str):
self.echo(value)
class CommandTools:

View File

@ -30,8 +30,8 @@ from ..errors import CommandError
from ..framework import CommandContainer, command, doc
from ..mapping import generate_usage
from hosts import *
import execute
from .hosts import *
from . import execute
# This holds constants fron the logger, which we'll be using in some of our
# commands.

View File

@ -23,10 +23,9 @@ according to the command properties.
"""
import re
from types import BooleanType, UnicodeType
from operator import itemgetter
from errors import DefinitionError, CommandError
from .errors import DefinitionError, CommandError
# Quite complex piece of regular expression logic to parse options and
# arguments. Might need some tweaking along the way.
@ -62,7 +61,7 @@ def parse_arguments(arguments):
"""
args, opts = [], []
def intersects_opts((given_start, given_end)):
def intersects_opts(given_start, given_end):
"""
Check if given span intersects with any of options.
"""
@ -71,7 +70,7 @@ def parse_arguments(arguments):
return True
return False
def intersects_args((given_start, given_end)):
def intersects_args(given_start, given_end):
"""
Check if given span intersects with any of arguments.
"""
@ -97,14 +96,14 @@ def parse_arguments(arguments):
# conflicted sectors. Remove any arguments that intersect with
# options.
for arg, position in args[:]:
if intersects_opts(position):
if intersects_opts(*position):
args.remove((arg, position))
# Primitive but sufficiently effective way of disposing of
# conflicted sectors. Remove any options that intersect with
# arguments.
for key, value, position in opts[:]:
if intersects_args(position):
if intersects_args(*position):
opts.remove((key, value, position))
return args, opts
@ -207,7 +206,7 @@ def adapt_arguments(command, arguments, args, opts):
# corresponding optin has been given.
if command.expand:
expanded = []
for spec_key, spec_value in norm_kwargs.iteritems():
for spec_key, spec_value in norm_kwargs.items():
letter = spec_key[0] if len(spec_key) > 1 else None
if letter and letter not in expanded:
for index, (key, value, position) in enumerate(opts):
@ -219,7 +218,7 @@ def adapt_arguments(command, arguments, args, opts):
# Detect switches and set their values accordingly. If any of them
# carries a value - append it to args.
for index, (key, value, position) in enumerate(opts):
if isinstance(norm_kwargs.get(key), BooleanType):
if isinstance(norm_kwargs.get(key), bool):
opts[index] = (key, True, position)
if value:
args.append((value, position))
@ -231,8 +230,8 @@ def adapt_arguments(command, arguments, args, opts):
# Stripping down position information supplied with arguments and
# options as it won't be needed again.
args = map(lambda (arg, position): arg, args)
opts = map(lambda (key, value, position): (key, value), opts)
args = map(lambda t: t[0], t[1])
opts = map(lambda t: (t[0], t[1]), opts)
# If command has extra option enabled - collect all extra arguments
# and pass them to a last positional argument command defines as a
@ -265,16 +264,10 @@ def adapt_arguments(command, arguments, args, opts):
# Normally this does not happen unless overlapping is enabled.
for key, value in opts:
initial = norm_kwargs.get(key)
if isinstance(initial, BooleanType):
if not isinstance(value, BooleanType):
if isinstance(initial, bool):
if not isinstance(value, bool):
raise CommandError("%s: Switch can not take an argument" % key, command)
# We need to encode every keyword argument to a simple string, not
# the unicode one, because ** expansion does not support it.
for index, (key, value) in enumerate(opts):
if isinstance(key, UnicodeType):
opts[index] = (key.encode(KEY_ENCODING), value)
# Inject the source arguments as a string as a first argument, if
# command has enabled the corresponding option.
if command.source:
@ -305,7 +298,7 @@ def generate_usage(command, complete=True):
letter = key[0]
key = key.replace('_', '-')
if isinstance(value, BooleanType):
if isinstance(value, bool):
value = str()
else:
value = '=%s' % value

View File

@ -100,13 +100,13 @@ class OldEntry(nbxmpp.Node, object):
if main_feed is not None and source_feed is not None:
return u'%s: %s' % (main_feed, source_feed)
return '%s: %s' % (main_feed, source_feed)
elif main_feed is not None:
return main_feed
elif source_feed is not None:
return source_feed
else:
return u''
return ''
feed_title = property(get_feed_title, None, None,
''' Title of feed. It is built from entry''s original feed title and title of feed
@ -173,4 +173,4 @@ class OldEntry(nbxmpp.Node, object):
updated = property(get_updated, None, None,
''' Last significant modification time. ''')
feed_tagline = u''
feed_tagline = ''

View File

@ -130,7 +130,8 @@ def compute_caps_hash(identities, features, dataforms=[], hash_method='sha-1'):
return 1
S = ''
identities.sort(cmp=sort_identities_func)
from functools import cmp_to_key
identities.sort(key=cmp_to_key(sort_identities_func))
for i in identities:
c = i['category']
type_ = i.get('type', '')
@ -140,7 +141,7 @@ def compute_caps_hash(identities, features, dataforms=[], hash_method='sha-1'):
features.sort()
for f in features:
S += '%s<' % f
dataforms.sort(cmp=sort_dataforms_func)
dataforms.sort(key=cmp_to_key(sort_dataforms_func))
for dataform in dataforms:
# fields indexed by var
fields = {}
@ -157,12 +158,12 @@ def compute_caps_hash(identities, features, dataforms=[], hash_method='sha-1'):
S += '%s<' % value
if hash_method == 'sha-1':
hash_ = hashlib.sha1(S)
hash_ = hashlib.sha1(S.encode('utf-8'))
elif hash_method == 'md5':
hash_ = hashlib.md5(S)
hash_ = hashlib.md5(S.encode('utf-8'))
else:
return ''
return base64.b64encode(hash_.digest())
return base64.b64encode(hash_.digest()).decode('utf-8')
################################################################################

View File

@ -29,16 +29,16 @@ import sys
import stat
from common import gajim
import logger
from common import logger
from common import jingle_xtls
# DO NOT MOVE ABOVE OF import gajim
import sqlite3 as sqlite
def create_log_db():
print _('creating logs database')
print(_('creating logs database'))
con = sqlite.connect(logger.LOG_DB_PATH)
os.chmod(logger.LOG_DB_PATH, 0600) # rw only for us
os.chmod(logger.LOG_DB_PATH, 0o600) # rw only for us
cur = con.cursor()
# create the tables
# kind can be
@ -84,9 +84,9 @@ def create_log_db():
con.close()
def create_cache_db():
print _('creating cache database')
print(_('creating cache database'))
con = sqlite.connect(logger.CACHE_DB_PATH)
os.chmod(logger.CACHE_DB_PATH, 0600) # rw only for us
os.chmod(logger.CACHE_DB_PATH, 0o600) # rw only for us
cur = con.cursor()
cur.executescript(
'''
@ -128,16 +128,16 @@ def create_cache_db():
con.close()
def split_db():
print 'spliting database'
print('spliting database')
if os.name == 'nt':
try:
import configpaths
OLD_LOG_DB_FOLDER = os.path.join(configpaths.fse(
os.environ[u'appdata']), u'Gajim')
os.environ['appdata']), 'Gajim')
except KeyError:
OLD_LOG_DB_FOLDER = u'.'
OLD_LOG_DB_FOLDER = '.'
else:
OLD_LOG_DB_FOLDER = os.path.expanduser(u'~/.gajim')
OLD_LOG_DB_FOLDER = os.path.expanduser('~/.gajim')
tmp = logger.CACHE_DB_PATH
logger.CACHE_DB_PATH = os.path.join(OLD_LOG_DB_FOLDER, 'cache.db')
@ -148,7 +148,7 @@ def split_db():
os.chdir(back)
cur = con.cursor()
cur.execute('''SELECT name FROM sqlite_master WHERE type = 'table';''')
tables = cur.fetchall() # we get [(u'jids',), (u'unread_messages',), ...
tables = cur.fetchall() # we get [('jids',), ('unread_messages',), ...
tables = [t[0] for t in tables]
cur.execute("ATTACH DATABASE '%s' AS cache" % logger.CACHE_DB_PATH)
for table in ('caps_cache', 'rooms_last_message_time', 'roster_entry',
@ -161,9 +161,9 @@ def split_db():
con.commit()
cur.executescript('DROP TABLE %s;' % table)
con.commit()
except sqlite.OperationalError, e:
print >> sys.stderr, 'error moving table %s to cache.db: %s' % \
(table, str(e))
except sqlite.OperationalError as e:
print('error moving table %s to cache.db: %s' % (table, str(e)),
file=sys.stderr)
con.close()
logger.CACHE_DB_PATH = tmp
@ -177,7 +177,7 @@ def check_and_possibly_move_config():
vars['MY_ICONSETS_PATH'] = gajim.MY_ICONSETS_PATH
vars['MY_MOOD_ICONSETS_PATH'] = gajim.MY_MOOD_ICONSETS_PATH
vars['MY_ACTIVITY_ICONSETS_PATH'] = gajim.MY_ACTIVITY_ICONSETS_PATH
import configpaths
from common import configpaths
MY_DATA = configpaths.gajimpaths['MY_DATA']
MY_CONFIG = configpaths.gajimpaths['MY_CONFIG']
MY_CACHE = configpaths.gajimpaths['MY_CACHE']
@ -189,22 +189,22 @@ def check_and_possibly_move_config():
if os.name == 'nt':
try:
OLD_LOG_DB_FOLDER = os.path.join(configpaths.fse(
os.environ[u'appdata']), u'Gajim')
os.environ['appdata']), 'Gajim')
except KeyError:
OLD_LOG_DB_FOLDER = u'.'
OLD_LOG_DB_FOLDER = '.'
else:
OLD_LOG_DB_FOLDER = os.path.expanduser(u'~/.gajim')
OLD_LOG_DB_FOLDER = os.path.expanduser('~/.gajim')
if not os.path.exists(OLD_LOG_DB_FOLDER):
return
OLD_LOG_DB_PATH = os.path.join(OLD_LOG_DB_FOLDER, u'logs.db')
OLD_CACHE_DB_PATH = os.path.join(OLD_LOG_DB_FOLDER, u'cache.db')
vars['OLD_VCARD_PATH'] = os.path.join(OLD_LOG_DB_FOLDER, u'vcards')
vars['OLD_AVATAR_PATH'] = os.path.join(OLD_LOG_DB_FOLDER, u'avatars')
vars['OLD_MY_EMOTS_PATH'] = os.path.join(OLD_LOG_DB_FOLDER, u'emoticons')
vars['OLD_MY_ICONSETS_PATH'] = os.path.join(OLD_LOG_DB_FOLDER, u'iconsets')
vars['OLD_MY_MOOD_ICONSETS_PATH'] = os.path.join(OLD_LOG_DB_FOLDER, u'moods')
OLD_LOG_DB_PATH = os.path.join(OLD_LOG_DB_FOLDER, 'logs.db')
OLD_CACHE_DB_PATH = os.path.join(OLD_LOG_DB_FOLDER, 'cache.db')
vars['OLD_VCARD_PATH'] = os.path.join(OLD_LOG_DB_FOLDER, 'vcards')
vars['OLD_AVATAR_PATH'] = os.path.join(OLD_LOG_DB_FOLDER, 'avatars')
vars['OLD_MY_EMOTS_PATH'] = os.path.join(OLD_LOG_DB_FOLDER, 'emoticons')
vars['OLD_MY_ICONSETS_PATH'] = os.path.join(OLD_LOG_DB_FOLDER, 'iconsets')
vars['OLD_MY_MOOD_ICONSETS_PATH'] = os.path.join(OLD_LOG_DB_FOLDER, 'moods')
vars['OLD_MY_ACTIVITY_ICONSETS_PATH'] = os.path.join(OLD_LOG_DB_FOLDER,
u'activities')
'activities')
OLD_CONFIG_FILES = []
OLD_DATA_FILES = []
for f in os.listdir(OLD_LOG_DB_FOLDER):
@ -249,7 +249,7 @@ def check_and_possibly_move_config():
continue
if not os.path.exists(src):
continue
print 'moving %s to %s' % (src, dst)
print(_('moving %s to %s') % (src, dst))
shutil.move(src, dst)
gajim.logger.init_vars()
gajim.logger.attach_cache_database()
@ -263,7 +263,7 @@ def check_and_possibly_create_paths():
VCARD_PATH = gajim.VCARD_PATH
AVATAR_PATH = gajim.AVATAR_PATH
import configpaths
from common import configpaths
MY_DATA = configpaths.gajimpaths['MY_DATA']
MY_CONFIG = configpaths.gajimpaths['MY_CONFIG']
MY_CACHE = configpaths.gajimpaths['MY_CACHE']
@ -275,57 +275,57 @@ def check_and_possibly_create_paths():
if not os.path.exists(MY_DATA):
create_path(MY_DATA)
elif os.path.isfile(MY_DATA):
print _('%s is a file but it should be a directory') % MY_DATA
print _('Gajim will now exit')
print(_('%s is a file but it should be a directory') % MY_DATA)
print(_('Gajim will now exit'))
sys.exit()
if not os.path.exists(MY_CONFIG):
create_path(MY_CONFIG)
elif os.path.isfile(MY_CONFIG):
print _('%s is a file but it should be a directory') % MY_CONFIG
print _('Gajim will now exit')
print(_('%s is a file but it should be a directory') % MY_CONFIG)
print(_('Gajim will now exit'))
sys.exit()
if not os.path.exists(MY_CACHE):
create_path(MY_CACHE)
elif os.path.isfile(MY_CACHE):
print _('%s is a file but it should be a directory') % MY_CACHE
print _('Gajim will now exit')
print(_('%s is a file but it should be a directory') % MY_CACHE)
print(_('Gajim will now exit'))
sys.exit()
if not os.path.exists(VCARD_PATH):
create_path(VCARD_PATH)
elif os.path.isfile(VCARD_PATH):
print _('%s is a file but it should be a directory') % VCARD_PATH
print _('Gajim will now exit')
print(_('%s is a file but it should be a directory') % VCARD_PATH)
print(_('Gajim will now exit'))
sys.exit()
if not os.path.exists(AVATAR_PATH):
create_path(AVATAR_PATH)
elif os.path.isfile(AVATAR_PATH):
print _('%s is a file but it should be a directory') % AVATAR_PATH
print _('Gajim will now exit')
print(_('%s is a file but it should be a directory') % AVATAR_PATH)
print(_('Gajim will now exit'))
sys.exit()
if not os.path.exists(LOG_DB_FOLDER):
create_path(LOG_DB_FOLDER)
elif os.path.isfile(LOG_DB_FOLDER):
print _('%s is a file but it should be a directory') % LOG_DB_FOLDER
print _('Gajim will now exit')
print(_('%s is a file but it should be a directory') % LOG_DB_FOLDER)
print(_('Gajim will now exit'))
sys.exit()
if not os.path.exists(PLUGINS_CONFIG_PATH):
create_path(PLUGINS_CONFIG_PATH)
elif os.path.isfile(PLUGINS_CONFIG_PATH):
print _('%s is a file but it should be a directory') % PLUGINS_CONFIG_PATH
print _('Gajim will now exit')
print(_('%s is a file but it should be a directory') % PLUGINS_CONFIG_PATH)
print(_('Gajim will now exit'))
sys.exit()
if not os.path.exists(CACHE_DB_FOLDER):
create_path(CACHE_DB_FOLDER)
elif os.path.isfile(CACHE_DB_FOLDER):
print _('%s is a file but it should be a directory') % CACHE_DB_FOLDER
print _('Gajim will now exit')
print(_('%s is a file but it should be a directory') % CACHE_DB_FOLDER)
print(_('Gajim will now exit'))
sys.exit()
check_and_possibly_move_config()
@ -334,18 +334,18 @@ def check_and_possibly_create_paths():
create_log_db()
gajim.logger.init_vars()
elif os.path.isdir(LOG_DB_PATH):
print _('%s is a directory but should be a file') % LOG_DB_PATH
print _('Gajim will now exit')
print(_('%s is a directory but should be a file') % LOG_DB_PATH)
print(_('Gajim will now exit'))
sys.exit()
if not os.path.exists(CACHE_DB_PATH):
create_cache_db()
gajim.logger.attach_cache_database()
elif os.path.isdir(CACHE_DB_PATH):
print _('%s is a directory but should be a file') % CACHE_DB_PATH
print _('Gajim will now exit')
print(_('%s is a directory but should be a file') % CACHE_DB_PATH)
print(_('Gajim will now exit'))
sys.exit()
if not os.path.exists(XTLS_CERTS):
create_path(XTLS_CERTS)
if not os.path.exists(LOCAL_XTLS_CERTS):
@ -363,5 +363,5 @@ def create_path(directory):
create_path(head)
if os.path.exists(directory):
return
print _('creating %s directory') % directory
os.mkdir(directory, 0700)
print(('creating %s directory') % directory)
os.mkdir(directory, 0o700)

View File

@ -23,9 +23,9 @@
##
import nbxmpp
import helpers
import dataforms
import gajim
from common import helpers
from common import dataforms
from common import gajim
import logging
log = logging.getLogger('gajim.c.commands')
@ -104,12 +104,12 @@ class ChangeStatusCommand(AdHocCommand):
var = 'presence-type',
label = 'Type of presence:',
options = [
(u'chat', _('Free for chat')),
(u'online', _('Online')),
(u'away', _('Away')),
(u'xa', _('Extended away')),
(u'dnd', _('Do not disturb')),
(u'offline', _('Offline - disconnect'))],
('chat', _('Free for chat')),
('online', _('Online')),
('away', _('Away')),
('xa', _('Extended away')),
('dnd', _('Do not disturb')),
('offline', _('Offline - disconnect'))],
value = 'online',
required = True),
dataforms.Field('text-multi',
@ -146,7 +146,7 @@ class ChangeStatusCommand(AdHocCommand):
try:
presencedesc = form['presence-desc'].value
except Exception: # same exceptions as in last comment
presencedesc = u''
presencedesc = ''
response, cmd = self.buildResponse(request, status = 'completed')
cmd.addChild('note', {}, _('The status has been changed.'))
@ -197,7 +197,7 @@ class LeaveGroupchatsCommand(AdHocCommand):
options = []
account = self.connection.name
for gc in find_current_groupchats(account):
options.append((u'%s' %(gc[0]), _('%(nickname)s on %(room_jid)s') % \
options.append(('%s' %(gc[0]), _('%(nickname)s on %(room_jid)s') % \
{'nickname': gc[1], 'room_jid': gc[0]}))
if not len(options):
response, cmd = self.buildResponse(request, status = 'completed')
@ -363,11 +363,11 @@ class ConnectionCommands:
# buildReply don't copy the node attribute. Re-add it
q.setAttr('node', nbxmpp.NS_COMMANDS)
for node, cmd in self.__commands.iteritems():
for node, cmd in self.__commands.items():
if cmd.isVisibleFor(self.isSameJID(jid)):
q.addChild('item', {
# TODO: find the jid
'jid': self.getOurBareJID() + u'/' + self.server_resource,
'jid': self.getOurBareJID() + '/' + self.server_resource,
'node': node,
'name': cmd.commandname})

View File

@ -35,7 +35,7 @@
import sys
import re
import copy
import defs
from common import defs
from gi.repository import GObject
(
@ -568,7 +568,7 @@ class Config:
Tree-like interface
"""
if node is None:
for child, option in self.__options[1].iteritems():
for child, option in self.__options[1].items():
yield (child, ), option
for grandparent in self.__options_per_key:
yield (grandparent, ), None
@ -579,7 +579,7 @@ class Config:
elif len(node) == 2:
grandparent, parent = node
children = self.__options_per_key[grandparent][1][parent]
for child, option in children.iteritems():
for child, option in children.items():
yield (grandparent, parent, child), option
else:
raise ValueError('Invalid node')
@ -625,11 +625,9 @@ class Config:
def set(self, optname, value):
if optname not in self.__options[1]:
# raise RuntimeError, 'option %s does not exist' % optname
return
value = self.is_valid(self.__options[0][optname][OPT_TYPE], value)
if value is None:
# raise RuntimeError, 'value of %s cannot be None' % optname
return
self.__options[1][optname] = value
@ -637,7 +635,7 @@ class Config:
def get(self, optname=None):
if not optname:
return self.__options[1].keys()
return list(self.__options[1].keys())
if optname not in self.__options[1]:
return None
return self.__options[1][optname]
@ -666,7 +664,6 @@ class Config:
def add_per(self, typename, name): # per_group_of_option
if typename not in self.__options_per_key:
# raise RuntimeError, 'option %s does not exist' % typename
return
opt = self.__options_per_key[typename]
@ -680,7 +677,6 @@ class Config:
def del_per(self, typename, name, subname = None): # per_group_of_option
if typename not in self.__options_per_key:
# raise RuntimeError, 'option %s does not exist' % typename
return
opt = self.__options_per_key[typename]
@ -693,22 +689,18 @@ class Config:
def set_per(self, optname, key, subname, value): # per_group_of_option
if optname not in self.__options_per_key:
# raise RuntimeError, 'option %s does not exist' % optname
return
if not key:
return
dict_ = self.__options_per_key[optname][1]
if key not in dict_:
# raise RuntimeError, '%s is not a key of %s' % (key, dict_)
self.add_per(optname, key)
obj = dict_[key]
if subname not in obj:
# raise RuntimeError, '%s is not a key of %s' % (subname, obj)
return
typ = self.__options_per_key[optname][0][subname][OPT_TYPE]
value = self.is_valid(typ, value)
if value is None:
# raise RuntimeError, '%s of %s cannot be None' % optname
return
obj[subname] = value
self._timeout_save()
@ -718,7 +710,7 @@ class Config:
return None
dict_ = self.__options_per_key[optname][1]
if not key:
return dict_.keys()
return list(dict_.keys())
if key not in dict_:
if subname in self.__options_per_key[optname][0]:
return self.__options_per_key[optname][0][subname][1]

View File

@ -25,7 +25,7 @@
import os
import sys
import tempfile
import defs
from common import defs
HAVE_XDG = True
try:
__import__(xdg)
@ -61,7 +61,7 @@ def fse(s):
"""
Convert from filesystem encoding if not already Unicode
"""
return unicode(s, sys.getfilesystemencoding())
return s
def windowsify(s):
if os.name == 'nt':
@ -82,10 +82,10 @@ class ConfigPaths:
# variable 'appdata' is in? Assuming it to be in filesystem
# encoding.
self.config_root = self.cache_root = self.data_root = \
os.path.join(fse(os.environ[u'appdata']), u'Gajim')
os.path.join(fse(os.environ['appdata']), 'Gajim')
except KeyError:
# win9x, in cwd
self.config_root = self.cache_root = self.data_root = u'.'
self.config_root = self.cache_root = self.data_root = '.'
else: # Unices
# Pass in an Unicode string, and hopefully get one back.
if HAVE_XDG:
@ -93,23 +93,23 @@ class ConfigPaths:
if not self.config_root:
# Folder doesn't exist yet.
self.config_root = os.path.join(xdg.BaseDirectory.\
xdg_config_dirs[0], u'gajim')
xdg_config_dirs[0], 'gajim')
self.cache_root = os.path.join(xdg.BaseDirectory.xdg_cache_home,
u'gajim')
'gajim')
self.data_root = xdg.BaseDirectory.save_data_path('gajim')
if not self.data_root:
self.data_root = os.path.join(xdg.BaseDirectory.\
xdg_data_dirs[0], u'gajim')
xdg_data_dirs[0], 'gajim')
else:
expand = os.path.expanduser
base = os.getenv('XDG_CONFIG_HOME') or expand(u'~/.config')
self.config_root = os.path.join(base, u'gajim')
base = os.getenv('XDG_CACHE_HOME') or expand(u'~/.cache')
self.cache_root = os.path.join(base, u'gajim')
base = os.getenv('XDG_DATA_HOME') or expand(u'~/.local/share')
self.data_root = os.path.join(base, u'gajim')
base = os.getenv('XDG_CONFIG_HOME') or expand('~/.config')
self.config_root = os.path.join(base, 'gajim')
base = os.getenv('XDG_CACHE_HOME') or expand('~/.cache')
self.cache_root = os.path.join(base, 'gajim')
base = os.getenv('XDG_DATA_HOME') or expand('~/.local/share')
self.data_root = os.path.join(base, 'gajim')
def add(self, name, type_, path):
self.paths[name] = (type_, path)
@ -130,7 +130,7 @@ class ConfigPaths:
except KeyError:
return default
def iteritems(self):
def items(self):
for key in self.paths.iterkeys():
yield (key, self[key])
@ -138,32 +138,32 @@ class ConfigPaths:
if root is not None:
self.config_root = self.cache_root = self.data_root = root
d = {'MY_DATA': '', 'LOG_DB': u'logs.db', 'MY_CACERTS': u'cacerts.pem',
'MY_EMOTS': u'emoticons', 'MY_ICONSETS': u'iconsets',
'MY_MOOD_ICONSETS': u'moods', 'MY_ACTIVITY_ICONSETS': u'activities',
'PLUGINS_USER': u'plugins', 'MY_PEER_CERTS': u'certs'}
d = {'MY_DATA': '', 'LOG_DB': 'logs.db', 'MY_CACERTS': 'cacerts.pem',
'MY_EMOTS': 'emoticons', 'MY_ICONSETS': 'iconsets',
'MY_MOOD_ICONSETS': 'moods', 'MY_ACTIVITY_ICONSETS': 'activities',
'PLUGINS_USER': 'plugins', 'MY_PEER_CERTS': 'certs'}
for name in d:
self.add(name, TYPE_DATA, windowsify(d[name]))
d = {'MY_CACHE': '', 'CACHE_DB': u'cache.db', 'VCARD': u'vcards',
'AVATAR': u'avatars'}
d = {'MY_CACHE': '', 'CACHE_DB': 'cache.db', 'VCARD': 'vcards',
'AVATAR': 'avatars'}
for name in d:
self.add(name, TYPE_CACHE, windowsify(d[name]))
self.add('MY_CONFIG', TYPE_CONFIG, '')
self.add('MY_CERT', TYPE_CONFIG, '')
basedir = fse(os.environ.get(u'GAJIM_BASEDIR', defs.basedir))
self.add('DATA', None, os.path.join(basedir, windowsify(u'data')))
self.add('ICONS', None, os.path.join(basedir, windowsify(u'icons')))
basedir = fse(os.environ.get('GAJIM_BASEDIR', defs.basedir))
self.add('DATA', None, os.path.join(basedir, windowsify('data')))
self.add('ICONS', None, os.path.join(basedir, windowsify('icons')))
self.add('HOME', None, fse(os.path.expanduser('~')))
self.add('PLUGINS_BASE', None, os.path.join(basedir,
windowsify(u'plugins')))
windowsify('plugins')))
try:
self.add('TMP', None, fse(tempfile.gettempdir()))
except IOError, e:
print >> sys.stderr, 'Error opening tmp folder: %s\nUsing %s' % (
str(e), os.path.expanduser('~'))
except IOError as e:
print('Error opening tmp folder: %s\nUsing %s' % (str(e),
os.path.expanduser('~')), file=sys.stderr)
self.add('TMP', None, fse(os.path.expanduser('~')))
try:
@ -173,17 +173,17 @@ class ConfigPaths:
pass
def init_profile(self, profile=''):
conffile = windowsify(u'config')
pidfile = windowsify(u'gajim')
secretsfile = windowsify(u'secrets')
pluginsconfdir = windowsify(u'pluginsconfig')
conffile = windowsify('config')
pidfile = windowsify('gajim')
secretsfile = windowsify('secrets')
pluginsconfdir = windowsify('pluginsconfig')
if len(profile) > 0:
conffile += u'.' + profile
pidfile += u'.' + profile
secretsfile += u'.' + profile
pluginsconfdir += u'.' + profile
pidfile += u'.pid'
conffile += '.' + profile
pidfile += '.' + profile
secretsfile += '.' + profile
pluginsconfdir += '.' + profile
pidfile += '.pid'
self.add('CONFIG_FILE', TYPE_CONFIG, conffile)
self.add('PID_FILE', TYPE_CACHE, pidfile)
self.add('SECRETS_FILE', TYPE_DATA, secretsfile)

View File

@ -59,7 +59,7 @@ from common import gpg
from common import passwords
from common import exceptions
from common import check_X509
from connection_handlers import *
from common.connection_handlers import *
from nbxmpp import Smacks
from string import Template
@ -455,7 +455,7 @@ class CommonConnection:
log_msg = '<body xmlns="%s">%s</body>' % (
nbxmpp.NS_XHTML, xhtml)
gajim.logger.write(kind, jid, log_msg)
except exceptions.PysqliteOperationalError, e:
except exceptions.PysqliteOperationalError as e:
self.dispatch('DB_ERROR', (_('Disk Write Error'),
str(e)))
except exceptions.DatabaseMalformed:
@ -616,7 +616,7 @@ class CommonConnection:
if realm == '':
if event == nbxmpp.transports_nb.DATA_RECEIVED:
gajim.nec.push_incoming_event(StanzaReceivedEvent(None,
conn=self, stanza_str=unicode(data, errors='ignore')))
conn=self, stanza_str=data))
elif event == nbxmpp.transports_nb.DATA_SENT:
gajim.nec.push_incoming_event(StanzaSentEvent(None, conn=self,
stanza_str=data))
@ -1446,7 +1446,7 @@ class Connection(CommonConnection, ConnectionHandlers):
self.connection.send(' ')
def _on_xmpp_ping_answer(self, iq_obj):
id_ = unicode(iq_obj.getAttr('id'))
id_ = iq_obj.getAttr('id')
assert id_ == self.awaiting_xmpp_ping_id
self.awaiting_xmpp_ping_id = None
@ -1607,7 +1607,7 @@ class Connection(CommonConnection, ConnectionHandlers):
self.activate_privacy_rule('invisible')
self.connected = gajim.SHOW_LIST.index('invisible')
self.status = msg
priority = unicode(gajim.get_priority(self.name, 'invisible'))
priority = gajim.get_priority(self.name, 'invisible')
p = nbxmpp.Presence(priority=priority)
p = self.add_sha(p, True)
if msg:
@ -1781,7 +1781,7 @@ class Connection(CommonConnection, ConnectionHandlers):
p.setStatus(msg)
else:
signed = self.get_signed_presence(msg)
priority = unicode(gajim.get_priority(self.name, sshow))
priority = gajim.get_priority(self.name, sshow)
p = nbxmpp.Presence(typ=None, priority=priority, show=sshow, to=jid)
p = self.add_sha(p)
if msg:
@ -1805,7 +1805,7 @@ class Connection(CommonConnection, ConnectionHandlers):
def _update_status(self, show, msg):
xmpp_show = helpers.get_xmpp_show(show)
priority = unicode(gajim.get_priority(self.name, xmpp_show))
priority = gajim.get_priority(self.name, xmpp_show)
p = nbxmpp.Presence(typ=None, priority=priority, show=xmpp_show)
p = self.add_sha(p)
if msg:

View File

@ -39,7 +39,7 @@ from time import (altzone, daylight, gmtime, localtime, mktime, strftime,
from calendar import timegm
import nbxmpp
import common.caps_cache as capscache
from common import caps_cache as capscache
from common import helpers
from common import gajim
@ -181,8 +181,8 @@ class ConnectionDisco:
if not self.connection or self.connected < 2:
return
frm = helpers.get_full_jid_from_iq(iq_obj)
to = unicode(iq_obj.getAttr('to'))
id_ = unicode(iq_obj.getAttr('id'))
to = iq_obj.getAttr('to')
id_ = iq_obj.getAttr('id')
iq = nbxmpp.Iq(to=frm, typ='result', queryNS=nbxmpp.NS_DISCO, frm=to)
iq.setAttr('id', id_)
query = iq.setTag('query')
@ -235,7 +235,7 @@ class ConnectionDisco:
if self.commandInfoQuery(con, iq_obj):
raise nbxmpp.NodeProcessed
id_ = unicode(iq_obj.getAttr('id'))
id_ = iq_obj.getAttr('id')
if id_[:6] == 'Gajim_':
# We get this request from echo.server
raise nbxmpp.NodeProcessed
@ -322,7 +322,7 @@ class ConnectionVcard:
os.remove(path)
# create folder if needed
if not os.path.isdir(path):
os.mkdir(path, 0700)
os.mkdir(path, 0o700)
puny_nick = helpers.sanitize_filename(nick)
path_to_file = os.path.join(gajim.VCARD_PATH, puny_jid, puny_nick)
else:
@ -331,7 +331,7 @@ class ConnectionVcard:
fil = open(path_to_file, 'w')
fil.write(str(card))
fil.close()
except IOError, e:
except IOError as e:
gajim.nec.push_incoming_event(InformationEvent(None, conn=self,
level='error', pri_txt=_('Disk Write Error'), sec_txt=str(e)))
@ -431,7 +431,8 @@ class ConnectionVcard:
if 'PHOTO' in vcard and isinstance(vcard['PHOTO'], dict) and \
'BINVAL' in vcard['PHOTO']:
photo = vcard['PHOTO']['BINVAL']
photo_decoded = base64.decodestring(photo)
photo_decoded = base64.b64decode(photo.encode('utf-8')).decode(
'utf-8')
gajim.interface.save_avatar_files(our_jid, photo_decoded)
avatar_sha = hashlib.sha1(photo_decoded).hexdigest()
iq2.getTag('PHOTO').setTagData('SHA', avatar_sha)
@ -593,7 +594,7 @@ class ConnectionVcard:
elif self.awaiting_answers[id_][0] == ARCHIVING_COLLECTIONS_ARRIVED:
# TODO
print 'ARCHIVING_COLLECTIONS_ARRIVED'
print('ARCHIVING_COLLECTIONS_ARRIVED')
elif self.awaiting_answers[id_][0] == ARCHIVING_COLLECTION_ARRIVED:
def save_if_not_exists(with_, nick, direction, tim, payload):
@ -603,7 +604,7 @@ class ConnectionVcard:
gajim.logger.save_if_not_exists(with_, direction, tim,
msg=payload[0].getData(), nick=nick)
elif payload[0].getName() == 'message':
print 'Not implemented'
print('Not implemented')
chat = iq_obj.getTag('chat')
if chat:
with_ = chat.getAttr('with')
@ -684,7 +685,7 @@ class ConnectionVcard:
'BINVAL' in vcard['PHOTO']:
photo = vcard['PHOTO']['BINVAL']
try:
photo_decoded = base64.decodestring(photo)
photo_decoded = base64.b64decode(photo.encode('utf-8')).decode('utf-8')
avatar_sha = hashlib.sha1(photo_decoded).hexdigest()
except Exception:
avatar_sha = ''
@ -706,7 +707,7 @@ class ConnectionVcard:
puny_nick = helpers.sanitize_filename(resource)
# create folder if needed
if not os.path.isdir(begin_path):
os.mkdir(begin_path, 0700)
os.mkdir(begin_path, 0o700)
begin_path = os.path.join(begin_path, puny_nick)
frm_jid += '/' + resource
if photo_decoded:
@ -947,7 +948,7 @@ class ConnectionHandlersBase:
gajim.config.should_log(self.name, obj.jid):
try:
gajim.logger.write('status', obj.jid, obj.status, obj.show)
except exceptions.PysqliteOperationalError, e:
except exceptions.PysqliteOperationalError as e:
self.dispatch('DB_ERROR', (_('Disk Write Error'), str(e)))
except exceptions.DatabaseMalformed:
pritext = _('Database Error')
@ -970,7 +971,7 @@ class ConnectionHandlersBase:
decmsg = self.gpg.decrypt(encmsg, keyID)
decmsg = self.connection.Dispatcher.replace_non_character(decmsg)
# \x00 chars are not allowed in C (so in GTK)
obj.msgtxt = helpers.decode_string(decmsg.replace('\x00', ''))
obj.msgtxt = decmsg.replace('\x00', '')
obj.encrypted = 'xep27'
self.gpg_messages_to_decrypt.remove([encmsg, keyID, obj])
@ -1017,7 +1018,7 @@ class ConnectionHandlersBase:
gc_contact = gajim.contacts.get_gc_contact(self.name, obj.jid, nick)
if obj.receipt_request_tag and gajim.config.get_per('accounts',
self.name, 'answer_receipts') and ((contact and contact.sub \
not in (u'to', u'none')) or gc_contact) and obj.mtype != 'error':
not in ('to', 'none')) or gc_contact) and obj.mtype != 'error':
receipt = nbxmpp.Message(to=obj.fjid, typ='chat')
receipt.setID(obj.id_)
receipt.setTag('received', namespace='urn:xmpp:receipts',
@ -1069,7 +1070,7 @@ class ConnectionHandlersBase:
try:
gajim.logger.write('error', frm, error_msg, tim=tim,
subject=subject)
except exceptions.PysqliteOperationalError, e:
except exceptions.PysqliteOperationalError as e:
self.dispatch('DB_ERROR', (_('Disk Write Error'), str(e)))
except exceptions.DatabaseMalformed:
pritext = _('Database Error')
@ -1095,7 +1096,7 @@ class ConnectionHandlersBase:
jid = gajim.get_jid_without_resource(jid)
try:
return self.sessions[jid].values()
return list(self.sessions[jid].values())
except KeyError:
return []
@ -1157,7 +1158,7 @@ class ConnectionHandlersBase:
received a thread_id yet and returns the session that we last sent a
message to
"""
sessions = self.sessions[jid].values()
sessions = list(self.sessions[jid].values())
# sessions that we haven't received a thread ID in
idless = [s for s in sessions if not s.received_thread_id]
@ -1178,7 +1179,7 @@ class ConnectionHandlersBase:
Find an active session that doesn't have a control attached
"""
try:
sessions = self.sessions[jid].values()
sessions = list(self.sessions[jid].values())
# filter out everything except the default session type
chat_sessions = [s for s in sessions if isinstance(s,
@ -1549,9 +1550,8 @@ ConnectionJingle, ConnectionIBBytestream):
iq_obj = obj.stanza.buildReply('result')
qp = iq_obj.setQuery()
qp.setTagData('utc', strftime('%Y%m%dT%H:%M:%S', gmtime()))
qp.setTagData('tz', helpers.decode_string(tzname[daylight]))
qp.setTagData('display', helpers.decode_string(strftime('%c',
localtime())))
qp.setTagData('tz', tzname[daylight])
qp.setTagData('display', strftime('%c', localtime()))
else:
iq_obj = obj.stanza.buildReply('error')
err = nbxmpp.ErrorNode(name=nbxmpp.NS_STANZAS + \

View File

@ -39,8 +39,6 @@ from nbxmpp.protocol import NS_CHATSTATES
from common.jingle_transport import JingleTransportSocks5
from common.file_props import FilesProp
import gtkgui_helpers
import logging
log = logging.getLogger('gajim.c.connection_handlers_events')
@ -220,11 +218,11 @@ class TimeResultReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
try:
t = datetime.datetime.strptime(utc_time, '%Y-%m-%dT%H:%M:%SZ')
except ValueError, e:
except ValueError as e:
try:
t = datetime.datetime.strptime(utc_time,
'%Y-%m-%dT%H:%M:%S.%fZ')
except ValueError, e:
except ValueError as e:
log.info('Wrong time format: %s' % str(e))
return
@ -366,10 +364,10 @@ class RosterReceivedEvent(nec.NetworkIncomingEvent):
try:
j = helpers.parse_jid(jid)
except Exception:
print >> sys.stderr, _('JID %s is not RFC compliant. It '
'will not be added to your roster. Use roster '
'management tools such as '
'http://jru.jabberstudio.org/ to remove it') % jid
print(_('JID %s is not RFC compliant. It will not be added '
'to your roster. Use roster management tools such as '
'http://jru.jabberstudio.org/ to remove it') % jid,
file=sys.stderr)
else:
infos = raw_roster[jid]
if jid != our_jid and (not infos['subscription'] or \
@ -905,7 +903,7 @@ class GcPresenceReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
try:
gajim.logger.write('gcstatus', self.fjid, st,
self.show)
except exceptions.PysqliteOperationalError, e:
except exceptions.PysqliteOperationalError as e:
self.conn.dispatch('DB_ERROR', (_('Disk Write Error'),
str(e)))
except exceptions.DatabaseMalformed:
@ -1169,7 +1167,6 @@ class ZeroconfMessageReceivedEvent(MessageReceivedEvent):
self.fjid = key
break
self.fjid = unicode(self.fjid)
self.jid, self.resource = gajim.get_room_and_nick_from_fjid(self.fjid)
def generate(self):
@ -1986,7 +1983,7 @@ class FileRequestReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
self.FT_content.session.ourjid)
self.FT_content.transport.set_connection(
self.FT_content.session.connection)
sid = unicode(self.stanza.getTag('jingle').getAttr('sid'))
sid = self.stanza.getTag('jingle').getAttr('sid')
self.file_props = FilesProp.getNewFileProp(self.conn.name, sid)
self.file_props.transport_sid = self.FT_content.transport.sid
self.FT_content.file_props = self.file_props
@ -2033,8 +2030,7 @@ class FileRequestReceivedEvent(nec.NetworkIncomingEvent, HelperEvent):
else:
si = self.stanza.getTag('si')
self.file_props = FilesProp.getNewFileProp(self.conn.name,
unicode(si.getAttr('id'))
)
si.getAttr('id'))
profile = si.getAttr('profile')
if profile != nbxmpp.NS_FILE:
self.conn.send_file_rejection(self.file_props, code='400',
@ -2183,8 +2179,6 @@ class NotificationEvent(nec.NetworkIncomingEvent):
self.popup_title = _('New Message from %(nickname)s') % \
{'nickname': nick}
self.popup_image = gtkgui_helpers.get_icon_path(self.popup_image, 48)
if not gajim.config.get('notify_on_new_message') or \
not self.first_unread:
self.do_popup = False
@ -2239,6 +2233,28 @@ class NotificationEvent(nec.NetworkIncomingEvent):
self.do_popup = False
def get_path_to_generic_or_avatar(self, generic, jid=None, suffix=None):
"""
Choose between avatar image and default image
Returns full path to the avatar image if it exists, otherwise returns full
path to the image. generic must be with extension and suffix without
"""
if jid:
# we want an avatar
puny_jid = helpers.sanitize_filename(jid)
path_to_file = os.path.join(gajim.AVATAR_PATH, puny_jid) + suffix
path_to_local_file = path_to_file + '_local'
for extension in ('.png', '.jpeg'):
path_to_local_file_full = path_to_local_file + extension
if os.path.exists(path_to_local_file_full):
return path_to_local_file_full
for extension in ('.png', '.jpeg'):
path_to_file_full = path_to_file + extension
if os.path.exists(path_to_file_full):
return path_to_file_full
return os.path.abspath(generic)
def handle_incoming_pres_event(self, pres_obj):
if gajim.jid_is_transport(pres_obj.jid):
return True
@ -2317,8 +2333,8 @@ class NotificationEvent(nec.NetworkIncomingEvent):
iconset = gajim.config.get('iconset')
img_path = os.path.join(helpers.get_iconset_path(iconset),
'48x48', show_image)
self.popup_image = gtkgui_helpers.get_path_to_generic_or_avatar(
img_path, jid=self.jid, suffix=suffix)
self.popup_image = self.get_path_to_generic_or_avatar(img_path,
jid=self.jid, suffix=suffix)
self.popup_timeout = gajim.config.get('notification_timeout')

View File

@ -28,11 +28,13 @@
## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
##
from functools import cmp_to_key
try:
from common import caps_cache
from common.account import Account
import common.gajim
except ImportError, e:
except ImportError as e:
if __name__ != "__main__":
raise ImportError(e)
@ -94,6 +96,8 @@ class Contact(CommonContact):
sub='', ask='', resource='', priority=0, keyID='', client_caps=None,
our_chatstate=None, chatstate=None, last_status_time=None, msg_id=None,
last_activity_time=None):
if not isinstance(jid, str):
print('no str')
CommonContact.__init__(self, jid, account, resource, show, status, name,
our_chatstate, chatstate, client_caps=client_caps)
@ -494,7 +498,7 @@ class Contacts():
return self._contacts.keys()
def get_contacts_jid_list(self):
return [jid for jid, contact in self._contacts.iteritems() if not
return [jid for jid, contact in self._contacts.items() if not
contact[0].is_groupchat()]
def get_contact_from_full_jid(self, fjid):
@ -846,7 +850,7 @@ class MetacontactManager():
Which of the family will be the big brother under wich all others will be
?
"""
family.sort(cmp=self._compare_metacontacts)
family.sort(key=cmp_to_key(self._compare_metacontacts))
return family[-1]

View File

@ -27,7 +27,7 @@ information how to use them, read documentation
"""
import nbxmpp
import helpers
from common import helpers
# exceptions used in this module
# base class
@ -195,7 +195,7 @@ class DataField(ExtendedNode):
Human-readable description of field meaning
"""
def fget(self):
return self.getTagData('desc') or u''
return self.getTagData('desc') or ''
def fset(self, value):
assert isinstance(value, basestring)
@ -345,10 +345,10 @@ class StringField(DataField):
@nested_property
def value():
"""
Value of field. May be any unicode string
Value of field. May be any string
"""
def fget(self):
return self.getTagData('value') or u''
return self.getTagData('value') or ''
def fset(self, value):
assert isinstance(value, basestring)
@ -494,7 +494,7 @@ class TextMultiField(DataField):
Value held in field
"""
def fget(self):
value = u''
value = ''
for element in self.iterTags('value'):
value += '\n' + element.getData()
return value[1:]
@ -643,7 +643,7 @@ class DataForm(ExtendedNode):
"""
# TODO: the same code is in TextMultiField. join them
def fget(self):
value = u''
value = ''
for valuenode in self.getTags('instructions'):
value += '\n' + valuenode.getData()
return value[1:]

View File

@ -38,8 +38,8 @@ try:
except ImportError:
supported = False
if not os.name == 'nt': # only say that to non Windows users
print _('D-Bus python bindings are missing in this computer')
print _('D-Bus capabilities of Gajim cannot be used')
print(_('D-Bus python bindings are missing in this computer'))
print(_('D-Bus capabilities of Gajim cannot be used'))
else:
try:
# test if dbus-x11 is installed
@ -49,14 +49,14 @@ else:
except dbus.DBusException:
supported = False
if not os.name == 'nt': # only say that to non Windows users
print _('D-Bus does not run correctly on this machine')
print _('D-Bus capabilities of Gajim cannot be used')
print(_('D-Bus does not run correctly on this machine'))
print(_('D-Bus capabilities of Gajim cannot be used'))
except exceptions.SystemBusNotPresent:
print _('D-Bus does not run correctly on this machine: system bus not '
'present')
print(_('D-Bus does not run correctly on this machine: system bus not '
'present'))
except exceptions.SessionBusNotPresent:
print _('D-Bus does not run correctly on this machine: session bus not '
'present')
print(_('D-Bus does not run correctly on this machine: session bus not '
'present'))
class SystemBus:
"""
@ -154,7 +154,7 @@ def get_interface(interface, path, start_service=True):
return None
obj = bus.get_object(interface, path)
return dbus.Interface(obj, interface)
except Exception, e:
except Exception as e:
gajim.log.debug(str(e))
return None

View File

@ -64,7 +64,7 @@ class FilesProp:
@classmethod
def getAllFileProp(cls):
return cls._files_props.values()
return list(cls._files_props.values())
@classmethod
def setFileProp(cls, fp, account, sid):

View File

@ -31,10 +31,10 @@ import sys
import logging
import locale
import config
from common import config
import nbxmpp
import defs
import common.ged
from common import defs
from common import ged as ged_module
interface = None # The actual interface (the gtk one for the moment)
thread_interface = None # Interface to run a thread and then a callback
@ -43,16 +43,15 @@ version = config.get('version')
connections = {} # 'account name': 'account (connection.Connection) instance'
ipython_window = None
ged = common.ged.GlobalEventsDispatcher() # Global Events Dispatcher
ged = ged_module.GlobalEventsDispatcher() # Global Events Dispatcher
nec = None # Network Events Controller
plugin_manager = None # Plugins Manager
log = logging.getLogger('gajim')
import logger
logger = logger.Logger() # init the logger
logger = None
import configpaths
from common import configpaths
gajimpaths = configpaths.gajimpaths
VCARD_PATH = gajimpaths['VCARD']
@ -84,8 +83,8 @@ else:
os_info = None # used to cache os information
from contacts import LegacyContactsAPI
from events import Events
from common.contacts import LegacyContactsAPI
from common.events import Events
gmail_domains = ['gmail.com', 'googlemail.com']
@ -221,9 +220,6 @@ gajim_optional_features = {}
# Capabilities hash per account
caps_hash = {}
import caps_cache
caps_cache.initialize(logger)
global_id = 0
def get_an_id():
global global_id
@ -280,13 +276,8 @@ def get_jid_without_resource(jid):
return jid.split('/')[0]
def construct_fjid(room_jid, nick):
"""
Nick is in UTF-8 (taken from treeview); room_jid is in unicode
"""
# fake jid is the jid for a contact in a room
# gaim@conference.jabber.org/nick
if isinstance(nick, str):
nick = unicode(nick, 'utf-8')
return room_jid + '/' + nick
def get_resource_from_jid(jid):

View File

@ -79,7 +79,7 @@ class GlobalEventsDispatcher(object):
if event_name in self.handlers:
try:
self.handlers[event_name].remove((priority, handler))
except ValueError, error:
except ValueError as error:
log.warn('''Function (%s) with priority "%s" never registered
as handler of event "%s". Couldn\'t remove. Error: %s'''
%(handler, priority, event_name, error))
@ -94,7 +94,7 @@ class GlobalEventsDispatcher(object):
return True
except NodeProcessed:
node_processed = True
except Exception, e:
except Exception as e:
log.error('Error while running an even handler: %s' % \
handler)
traceback.print_exc()

View File

@ -22,11 +22,11 @@
## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
##
from gajim import HAVE_GPG
from common.gajim import HAVE_GPG
import os
if HAVE_GPG:
import gnupg
from common import gnupg
class GnuPG(gnupg.GPG):
def __init__(self, use_agent=False):

View File

@ -35,14 +35,14 @@ import locale
import os
import subprocess
import urllib
import urllib2
import urllib
import webbrowser
import errno
import select
import base64
import hashlib
import shlex
import caps_cache
from common import caps_cache
import socket
import time
@ -50,8 +50,8 @@ from gi.repository import GObject
from encodings.punycode import punycode_encode
from string import Template
from i18n import Q_
from i18n import ngettext
from common.i18n import Q_
from common.i18n import ngettext
try:
import winsound # windows-only built-in module for playing wav
@ -122,7 +122,7 @@ def idn_to_ascii(host):
labels = idna.dots.split(host)
converted_labels = []
for label in labels:
converted_labels.append(idna.ToASCII(label))
converted_labels.append(idna.ToASCII(label).decode('utf-8'))
return ".".join(converted_labels)
def ascii_to_idn(host):
@ -144,9 +144,9 @@ def parse_resource(resource):
if resource:
try:
from nbxmpp.stringprepare import resourceprep
return resourceprep.prepare(unicode(resource))
return resourceprep.prepare(resource)
except UnicodeError:
raise InvalidFormat, 'Invalid character in resource.'
raise InvalidFormat('Invalid character in resource.')
def prep(user, server, resource):
"""
@ -156,34 +156,34 @@ def prep(user, server, resource):
#http://svn.twistedmatrix.com/cvs/trunk/twisted/words/protocols/jabber/jid.py
if user is not None:
if len(user) < 1 or len(user) > 1023:
raise InvalidFormat, _('Username must be between 1 and 1023 chars')
raise InvalidFormat(_('Username must be between 1 and 1023 chars'))
try:
from nbxmpp.stringprepare import nodeprep
user = nodeprep.prepare(unicode(user))
user = nodeprep.prepare(user)
except UnicodeError:
raise InvalidFormat, _('Invalid character in username.')
raise InvalidFormat(_('Invalid character in username.'))
else:
user = None
if server is not None:
if len(server) < 1 or len(server) > 1023:
raise InvalidFormat, _('Server must be between 1 and 1023 chars')
raise InvalidFormat(_('Server must be between 1 and 1023 chars'))
try:
from nbxmpp.stringprepare import nameprep
server = nameprep.prepare(unicode(server))
server = nameprep.prepare(server)
except UnicodeError:
raise InvalidFormat, _('Invalid character in hostname.')
raise InvalidFormat(_('Invalid character in hostname.'))
else:
raise InvalidFormat, _('Server address required.')
raise InvalidFormat(_('Server address required.'))
if resource is not None:
if len(resource) < 1 or len(resource) > 1023:
raise InvalidFormat, _('Resource must be between 1 and 1023 chars')
raise InvalidFormat(_('Resource must be between 1 and 1023 chars'))
try:
from nbxmpp.stringprepare import resourceprep
resource = resourceprep.prepare(unicode(resource))
resource = resourceprep.prepare(resource)
except UnicodeError:
raise InvalidFormat, _('Invalid character in resource.')
raise InvalidFormat(_('Invalid character in resource.'))
else:
resource = None
@ -207,7 +207,7 @@ def temp_failure_retry(func, *args, **kwargs):
while True:
try:
return func(*args, **kwargs)
except (os.error, IOError, select.error), ex:
except (os.error, IOError, select.error) as ex:
if ex.errno == errno.EINTR:
continue
else:
@ -264,7 +264,7 @@ def get_uf_show(show, use_mnemonic = False):
uf_show = Q_('?contact has status:Unknown')
else:
uf_show = Q_('?contact has status:Has errors')
return unicode(uf_show)
return uf_show
def get_uf_sub(sub):
if sub == 'none':
@ -278,7 +278,7 @@ def get_uf_sub(sub):
else:
uf_sub = sub
return unicode(uf_sub)
return uf_sub
def get_uf_ask(ask):
if ask is None:
@ -288,7 +288,7 @@ def get_uf_ask(ask):
else:
uf_ask = ask
return unicode(uf_ask)
return uf_ask
def get_uf_role(role, plural = False):
''' plural determines if you get Moderators or Moderator'''
@ -448,43 +448,43 @@ def get_output_of_command(command):
return output
def decode_string(string):
"""
Try to decode (to make it Unicode instance) given string
"""
if isinstance(string, unicode):
return string
# by the time we go to iso15 it better be the one else we show bad characters
encodings = (locale.getpreferredencoding(), 'utf-8', 'iso-8859-15')
for encoding in encodings:
try:
string = string.decode(encoding)
except UnicodeError:
continue
break
#def decode_string(string):
#"""
#Try to decode (to make it Unicode instance) given string
#"""
#if isinstance(string, unicode):
#return string
## by the time we go to iso15 it better be the one else we show bad characters
#encodings = (locale.getpreferredencoding(), 'utf-8', 'iso-8859-15')
#for encoding in encodings:
#try:
#string = string.decode(encoding)
#except UnicodeError:
#continue
#break
return string
#return string
def ensure_utf8_string(string):
"""
Make sure string is in UTF-8
"""
try:
string = decode_string(string).encode('utf-8')
except Exception:
pass
return string
#def ensure_utf8_string(string):
#"""
#Make sure string is in UTF-8
#"""
#try:
#string = decode_string(string).encode('utf-8')
#except Exception:
#pass
#return string
def wrapped_ensure_utf8_string(fn):
def wrapped(n):
return ensure_utf8_string(n)
return wrapped
#def wrapped_ensure_utf8_string(fn):
#def wrapped(n):
#return ensure_utf8_string(n)
#return wrapped
@wrapped_ensure_utf8_string
def escape_text(text):
return GObject.markup_escape_text(text)
#@wrapped_ensure_utf8_string
#def escape_text(text):
#return GObject.markup_escape_text(text)
GObject.markup_escape_text = escape_text
#GObject.markup_escape_text = escape_text
def get_windows_reg_env(varname, default=''):
"""
@ -493,7 +493,7 @@ def get_windows_reg_env(varname, default=''):
'AppData' = %USERPROFILE%\Application Data (also an ENV)
'Desktop' = %USERPROFILE%\Desktop
'Favorites' = %USERPROFILE%\Favorites
'NetHood' = %USERPROFILE%\NetHood
'NetHood' = %USERPROFILE%\ NetHood
'Personal' = D:\My Documents (PATH TO MY DOCUMENTS)
'PrintHood' = %USERPROFILE%\PrintHood
'Programs' = %USERPROFILE%\Start Menu\Programs
@ -555,7 +555,8 @@ def sanitize_filename(filename):
hash = hashlib.md5(filename)
filename = base64.b64encode(hash.digest())
filename = punycode_encode(filename) # make it latin chars only
# make it latin chars only
filename = punycode_encode(filename).decode('utf-8')
filename = filename.replace('/', '_')
if os.name == 'nt':
filename = filename.replace('?', '_').replace(':', '_')\
@ -577,9 +578,6 @@ def reduce_chars_newlines(text, max_chars = 0, max_lines = 0):
string = string[:max_chars - 3] + '...'
return string
if isinstance(text, str):
text = text.decode('utf-8')
if max_lines == 0:
lines = text.split('\n')
else:
@ -635,12 +633,10 @@ def datetime_tuple(timestamp):
from time import strptime
return strptime(timestamp, '%Y%m%dT%H:%M:%S')
# import gajim only when needed (after decode_string is defined) see #4764
import gajim
from common import gajim
if gajim.HAVE_PYCURL:
import pycurl
from cStringIO import StringIO
from io import StringIO
def convert_bytes(string):
suffix = ''
@ -648,13 +644,13 @@ def convert_bytes(string):
# but do we use the standard?
use_kib_mib = gajim.config.get('use_kib_mib')
align = 1024.
bytes = float(string)
if bytes >= align:
bytes = round(bytes/align, 1)
if bytes >= align:
bytes = round(bytes/align, 1)
if bytes >= align:
bytes = round(bytes/align, 1)
bytes_ = float(string)
if bytes_ >= align:
bytes_ = round(bytes_/align, 1)
if bytes_ >= align:
bytes_ = round(bytes_/align, 1)
if bytes_ >= align:
bytes_ = round(bytes_/align, 1)
if use_kib_mib:
#GiB means gibibyte
suffix = _('%s GiB')
@ -678,7 +674,7 @@ def convert_bytes(string):
else:
#B means bytes
suffix = _('%s B')
return suffix % unicode(bytes)
return suffix % str(bytes_)
def get_contact_dict_for_account(account):
"""
@ -904,13 +900,13 @@ def get_icon_name_to_show(contact, account = None):
def get_full_jid_from_iq(iq_obj):
"""
Return the full jid (with resource) from an iq as unicode
Return the full jid (with resource) from an iq
"""
return parse_jid(str(iq_obj.getFrom()))
def get_jid_from_iq(iq_obj):
"""
Return the jid (without resource) from an iq as unicode
Return the jid (without resource) from an iq
"""
jid = get_full_jid_from_iq(iq_obj)
return gajim.get_jid_without_resource(jid)
@ -1431,7 +1427,7 @@ def get_proxy_info(account):
login = ['', '']
addr = env_http_proxy[0].split(':')
proxy = {'host': addr[0], 'type' : u'http', 'user':login[0]}
proxy = {'host': addr[0], 'type' : 'http', 'user':login[0]}
if len(addr) == 2:
proxy['port'] = addr[1]
@ -1442,7 +1438,7 @@ def get_proxy_info(account):
proxy['pass'] = login[1]
proxy['useauth'] = True
else:
proxy['pass'] = u''
proxy['pass'] = ''
return proxy
except Exception:
@ -1465,10 +1461,10 @@ def _get_img_direct(attrs):
# Wait maximum 5s for connection
socket.setdefaulttimeout(5)
try:
req = urllib2.Request(attrs['src'])
req = urllib.request.Request(attrs['src'])
req.add_header('User-Agent', 'Gajim ' + gajim.version)
f = urllib2.urlopen(req)
except Exception, ex:
f = urllib.request.urlopen(req)
except Exception as ex:
log.debug('Error loading image %s ' % attrs['src'] + str(ex))
pixbuf = None
alt = attrs.get('alt', 'Broken image')
@ -1491,7 +1487,7 @@ def _get_img_direct(attrs):
break
try:
temp = f.read(100)
except socket.timeout, ex:
except socket.timeout as ex:
log.debug('Timeout loading image %s ' % attrs['src'] + str(ex))
alt = attrs.get('alt', '')
if alt:
@ -1543,7 +1539,7 @@ def _get_img_proxy(attrs, proxy):
c.close()
t = b.getvalue()
return (t, attrs.get('alt', ''))
except pycurl.error, ex:
except pycurl.error as ex:
alt = attrs.get('alt', '')
if alt:
alt += '\n'
@ -1553,7 +1549,7 @@ def _get_img_proxy(attrs, proxy):
alt += _('Timeout loading image')
else:
alt += _('Error loading image')
except Exception, ex:
except Exception as ex:
log.debug('Error loading image %s ' % attrs['src'] + str(ex))
pixbuf = None
alt = attrs.get('alt', 'Broken image')

View File

@ -24,7 +24,7 @@
import locale
import gettext
import os
import defs
from common import defs
import unicodedata
def paragraph_direction_mark(text):
@ -37,11 +37,11 @@ def paragraph_direction_mark(text):
for char in text:
bidi = unicodedata.bidirectional(char)
if bidi == 'L':
return u'\u200E'
return '\u200E'
elif bidi == 'AL' or bidi == 'R':
return u'\u200F'
return '\u200F'
return u'\u200E'
return '\u200E'
APP = 'gajim'
DIR = defs.localedir
@ -61,9 +61,9 @@ if os.name == 'nt':
if lang:
os.environ['LANG'] = lang
gettext.install(APP, DIR, unicode = True)
gettext.install(APP, DIR)
if gettext._translations:
_translation = gettext._translations.values()[0]
_translation = list(gettext._translations.values())[0]
else:
_translation = gettext.NullTranslations()

View File

@ -68,7 +68,7 @@ try:
rootwindow = libX11.XDefaultRootWindow(dpy_p)
xss_available = True
except OSError, e:
except OSError as e:
# Logging?
xss_available = False
@ -94,6 +94,6 @@ def close():
if __name__ == '__main__':
import time
time.sleep(2.1)
print getIdleSec()
print(getIdleSec())
close()
print getIdleSec()
print(getIdleSec())

View File

@ -27,14 +27,14 @@ Handles the jingle signalling protocol
# - codecs
import nbxmpp
import helpers
import gajim
from common import helpers
from common import gajim
from jingle_session import JingleSession, JingleStates
from common.jingle_session import JingleSession, JingleStates
if gajim.HAVE_FARSTREAM:
from jingle_rtp import JingleAudio, JingleVideo
from jingle_ft import JingleFileTransfer
from jingle_transport import JingleTransportSocks5, JingleTransportIBB
from common.jingle_rtp import JingleAudio, JingleVideo
from common.jingle_ft import JingleFileTransfer
from common.jingle_transport import JingleTransportSocks5, JingleTransportIBB
import logging
logger = logging.getLogger('gajim.c.jingle')

View File

@ -15,9 +15,9 @@
Handles Jingle contents (XEP 0166)
"""
import gajim
from common import gajim
import nbxmpp
from jingle_transport import JingleTransportIBB
from common.jingle_transport import JingleTransportIBB
contents = {}

View File

@ -20,16 +20,16 @@ Handles Jingle File Transfer (XEP 0234)
"""
import hashlib
import gajim
from common import gajim
import nbxmpp
from jingle_content import contents, JingleContent
from jingle_transport import *
from common.jingle_content import contents, JingleContent
from common.jingle_transport import *
from common import helpers
from common.socks5 import Socks5ReceiverClient, Socks5SenderClient
from common.connection_handlers_events import FileRequestReceivedEvent
import threading
import logging
from jingle_ftstates import *
from common.jingle_ftstates import *
log = logging.getLogger('gajim.c.jingle_ft')
STATE_NOT_STARTED = 0

View File

@ -11,9 +11,9 @@
## GNU General Public License for more details.
##
import gajim
from common import gajim
import nbxmpp
from jingle_transport import *
from common.jingle_transport import *
from common.socks5 import Socks5ReceiverClient, Socks5SenderClient

View File

@ -21,14 +21,15 @@ from gi.repository import GObject
import socket
import nbxmpp
import farstream, gst
import farstream
import gst
from glib import GError
import gajim
from common import gajim
from jingle_transport import JingleTransportICEUDP
from jingle_content import contents, JingleContent, JingleContentSetupException
from connection_handlers_events import InformationEvent
from common.jingle_transport import JingleTransportICEUDP
from common.jingle_content import contents, JingleContent, JingleContentSetupException
from common.connection_handlers_events import InformationEvent
import logging
@ -86,8 +87,8 @@ class JingleRTPContent(JingleContent):
try:
ip = socket.getaddrinfo(stun_server, 0, socket.AF_UNSPEC,
socket.SOCK_STREAM)[0][4][0]
except socket.gaierror, (errnum, errstr):
log.warn('Lookup of stun ip failed: %s' % errstr)
except socket.gaierror as e:
log.warn('Lookup of stun ip failed: %s' % str(e))
else:
params['stun-ip'] = ip
@ -104,7 +105,7 @@ class JingleRTPContent(JingleContent):
try:
bin = gst.parse_bin_from_description(pipeline, True)
return bin
except GError, error_str:
except GError as error_str:
gajim.nec.push_incoming_event(InformationEvent(None,
conn=self.session.connection, level='error',
pri_txt=_('%s configuration error') % text.capitalize(),

View File

@ -26,12 +26,12 @@ Handles Jingle sessions (XEP 0166)
# - Tie-breaking
# * timeout
import gajim #Get rid of that?
from common import gajim
import nbxmpp
from jingle_transport import get_jingle_transport, JingleTransportIBB
from jingle_content import get_jingle_content, JingleContentSetupException
from jingle_content import JingleContent
from jingle_ft import STATE_TRANSPORT_REPLACE
from common.jingle_transport import get_jingle_transport, JingleTransportIBB
from common.jingle_content import get_jingle_content, JingleContentSetupException
from common.jingle_content import JingleContent
from common.jingle_ft import STATE_TRANSPORT_REPLACE
from common.connection_handlers_events import *
import logging
log = logging.getLogger("gajim.c.jingle_session")
@ -73,7 +73,6 @@ class JingleSession(object):
self.contents = {} # negotiated contents
self.connection = con # connection to use
# our full jid
#FIXME: Get rid of gajim here?
self.ourjid = gajim.get_jid_from_account(self.connection.name)
if con.server_resource:
self.ourjid = self.ourjid + '/' + con.server_resource

View File

@ -296,7 +296,7 @@ class JingleTransportSocks5(JingleTransport):
cid = host['candidate_id']
break
if cid is None:
raise Exception, 'cid is missing'
raise Exception('cid is missing')
activated.setAttr('cid', cid)
transport.addChild(node=activated)
content.addChild(node=transport)
@ -401,7 +401,7 @@ class JingleTransportICEUDP(JingleTransport):
if 'type' in candidate and candidate['type'] in types:
cand.type = types[candidate['type']]
else:
print 'Unknown type %s', candidate['type']
print('Unknown type %s' % candidate['type'])
candidates.append(cand)
self.remote_candidates.extend(candidates)
return candidates

View File

@ -20,7 +20,6 @@ import os
import nbxmpp
import logging
import common
from common import gajim
log = logging.getLogger('gajim.c.jingle_xtls')
@ -63,7 +62,7 @@ def load_cert_file(cert_path, cert_store):
return
try:
f = open(cert_path)
except IOError, e:
except IOError as e:
log.warning('Unable to open certificate file %s: %s' % (cert_path,
str(e)))
return
@ -79,7 +78,7 @@ def load_cert_file(cert_path, cert_store):
x509cert = OpenSSL.crypto.load_certificate(
OpenSSL.crypto.FILETYPE_PEM, cert)
cert_store.add_cert(x509cert)
except OpenSSL.crypto.Error, exception_obj:
except OpenSSL.crypto.Error as exception_obj:
log.warning('Unable to load a certificate from file %s: %s' %\
(cert_path, exception_obj.args[0][0][2]))
except:
@ -158,7 +157,7 @@ def send_cert_request(con, to_jid):
pubkey = iq.setTag('pubkeys')
pubkey.setNamespace(nbxmpp.NS_PUBKEY_PUBKEY)
con.connection.send(iq)
return unicode(id_)
return str(id_)
# the following code is partly due to pyopenssl examples
@ -201,7 +200,7 @@ def createCertRequest(pkey, digest="md5", **name):
req.sign(pkey, digest)
return req
def createCertificate(req, (issuerCert, issuerKey), serial, (notBefore, notAfter), digest="md5"):
def createCertificate(req, issuerCert, issuerKey, serial, notBefore, notAfter, digest="md5"):
"""
Generate a certificate given a certificate request.
@ -235,7 +234,7 @@ def make_certs(filepath, CN):
"""
key = createKeyPair(TYPE_RSA, 1024)
req = createCertRequest(key, CN=CN)
cert = createCertificate(req, (req, key), 0, (0, 60*60*24*365*5)) # five years
cert = createCertificate(req, req, key, 0, 0, 60*60*24*365*5) # five years
open(filepath + '.pkey', 'w').write(crypto.dump_privatekey(
crypto.FILETYPE_PEM, key))
open(filepath + '.cert', 'w').write(crypto.dump_certificate(

View File

@ -46,14 +46,14 @@ def kwallet_get(folder, entry):
folder: The top-level category to use (normally the programme name)
entry: The key of the entry to retrieve
Returns the passphrase as unicode, False if it cannot be found,
Returns the passphrase, False if it cannot be found,
or None if an error occured.
"""
p = subprocess.Popen(["kwalletcli", "-q", "-f", folder.encode('utf-8'),
"-e", entry.encode('utf-8')], stdout=subprocess.PIPE)
pw = p.communicate()[0]
if p.returncode == 0:
return unicode(pw.decode('utf-8'))
return pw
if p.returncode == 1 or p.returncode == 4:
# ENOENT
return False

View File

@ -33,16 +33,16 @@ import sys
import time
import datetime
from gzip import GzipFile
from cStringIO import StringIO
from io import BytesIO
from gi.repository import GObject
import exceptions
import gajim
import ged
from common import exceptions
from common import gajim
from common import ged
import sqlite3 as sqlite
import configpaths
from common import configpaths
LOG_DB_PATH = configpaths.gajimpaths['LOG_DB']
LOG_DB_FOLDER, LOG_DB_FILE = os.path.split(LOG_DB_PATH)
CACHE_DB_PATH = configpaths.gajimpaths['CACHE_DB']
@ -149,7 +149,7 @@ class Logger:
def attach_cache_database(self):
try:
self.cur.execute("ATTACH DATABASE '%s' AS cache" % CACHE_DB_PATH)
except sqlite.Error, e:
except sqlite.Error as e:
log.debug("Failed to attach cache database: %s" % str(e))
def set_synchronous(self, sync):
@ -158,7 +158,7 @@ class Logger:
self.cur.execute("PRAGMA synchronous = NORMAL")
else:
self.cur.execute("PRAGMA synchronous = OFF")
except sqlite.Error, e:
except sqlite.Error as e:
log.debug("Failed to set_synchronous(%s): %s" % (sync, str(e)))
def init_vars(self):
@ -168,8 +168,8 @@ class Logger:
def _really_commit(self):
try:
self.con.commit()
except sqlite.OperationalError, e:
print >> sys.stderr, str(e)
except sqlite.OperationalError as e:
print(str(e), file=sys.stderr)
self.commit_timout_id = None
return False
@ -188,7 +188,7 @@ class Logger:
def get_jids_already_in_db(self):
try:
self.cur.execute('SELECT jid FROM jids')
# list of tupples: [(u'aaa@bbb',), (u'cc@dd',)]
# list of tupples: [('aaa@bbb',), ('cc@dd',)]
rows = self.cur.fetchall()
except sqlite.DatabaseError:
raise exceptions.DatabaseMalformed
@ -256,11 +256,11 @@ class Logger:
self.cur.execute('INSERT INTO jids (jid, type) VALUES (?, ?)', (jid,
typ))
self.con.commit()
except sqlite.IntegrityError, e:
except sqlite.IntegrityError as e:
# Jid already in DB, maybe added by another instance. re-read DB
self.get_jids_already_in_db()
return self.get_jid_id(jid, typestr)
except sqlite.OperationalError, e:
except sqlite.OperationalError as e:
raise exceptions.PysqliteOperationalError(str(e))
jid_id = self.cur.lastrowid
self.jids_already_in.append(jid)
@ -407,15 +407,15 @@ class Logger:
self.cur.execute(sql, values)
except sqlite.DatabaseError:
raise exceptions.DatabaseMalformed
except sqlite.OperationalError, e:
except sqlite.OperationalError as e:
raise exceptions.PysqliteOperationalError(str(e))
message_id = None
if write_unread:
try:
self.con.commit()
message_id = self.cur.lastrowid
except sqlite.OperationalError, e:
print >> sys.stderr, str(e)
except sqlite.OperationalError as e:
print(str(e), file=sys.stderr)
else:
self._timeout_commit()
if message_id:
@ -522,7 +522,7 @@ class Logger:
# status for roster items
try:
jid_id = self.get_jid_id(jid)
except exceptions.PysqliteOperationalError, e:
except exceptions.PysqliteOperationalError as e:
raise exceptions.PysqliteOperationalError(str(e))
if show is None: # show is None (xmpp), but we say that 'online'
show_col = constants.SHOW_ONLINE
@ -535,7 +535,7 @@ class Logger:
try:
# re-get jid_id for the new jid
jid_id = self.get_jid_id(jid, 'ROOM')
except exceptions.PysqliteOperationalError, e:
except exceptions.PysqliteOperationalError as e:
raise exceptions.PysqliteOperationalError(str(e))
contact_name_col = nick
@ -549,13 +549,13 @@ class Logger:
try:
# re-get jid_id for the new jid
jid_id = self.get_jid_id(jid, 'ROOM')
except exceptions.PysqliteOperationalError, e:
except exceptions.PysqliteOperationalError as e:
raise exceptions.PysqliteOperationalError(str(e))
contact_name_col = nick
else:
try:
jid_id = self.get_jid_id(jid)
except exceptions.PysqliteOperationalError, e:
except exceptions.PysqliteOperationalError as e:
raise exceptions.PysqliteOperationalError(str(e))
if kind == 'chat_msg_recv':
if not self.jid_is_from_pm(jid):
@ -580,7 +580,7 @@ class Logger:
"""
try:
self.get_jid_id(jid)
except exceptions.PysqliteOperationalError, e:
except exceptions.PysqliteOperationalError as e:
# Error trying to create a new jid_id. This means there is no log
return []
where_sql, jid_tuple = self._build_contact_where(account, jid)
@ -624,7 +624,7 @@ class Logger:
"""
try:
self.get_jid_id(jid)
except exceptions.PysqliteOperationalError, e:
except exceptions.PysqliteOperationalError as e:
# Error trying to create a new jid_id. This means there is no log
return []
where_sql, jid_tuple = self._build_contact_where(account, jid)
@ -653,14 +653,14 @@ class Logger:
"""
try:
self.get_jid_id(jid)
except exceptions.PysqliteOperationalError, e:
except exceptions.PysqliteOperationalError as e:
# Error trying to create a new jid_id. This means there is no log
return []
if False: # query.startswith('SELECT '): # it's SQL query (FIXME)
try:
self.cur.execute(query)
except sqlite.OperationalError, e:
except sqlite.OperationalError as e:
results = [('', '', '', '', str(e))]
return results
@ -694,7 +694,7 @@ class Logger:
"""
try:
self.get_jid_id(jid)
except exceptions.PysqliteOperationalError, e:
except exceptions.PysqliteOperationalError as e:
# Error trying to create a new jid_id. This means there is no log
return []
days_with_logs = []
@ -736,7 +736,7 @@ class Logger:
else:
try:
jid_id = self.get_jid_id(jid, 'ROOM')
except exceptions.PysqliteOperationalError, e:
except exceptions.PysqliteOperationalError as e:
# Error trying to create a new jid_id. This means there is no log
return None
where_sql = 'jid_id = ?'
@ -762,7 +762,7 @@ class Logger:
"""
try:
jid_id = self.get_jid_id(jid, 'ROOM')
except exceptions.PysqliteOperationalError, e:
except exceptions.PysqliteOperationalError as e:
# Error trying to create a new jid_id. This means there is no log
return None
where_sql = 'jid_id = %s' % jid_id
@ -802,7 +802,7 @@ class Logger:
for user in family:
try:
jid_id = self.get_jid_id(user['jid'])
except exceptions.PysqliteOperationalError, e:
except exceptions.PysqliteOperationalError as e:
continue
where_sql += 'jid_id = ?'
jid_tuple += (jid_id,)
@ -884,8 +884,7 @@ class Logger:
# ..., 'FEAT', feature1, feature2, ...).join(' '))
# NOTE: if there's a need to do more gzip, put that to a function
try:
data = GzipFile(fileobj=StringIO(str(data))).read().decode(
'utf-8').split('\0')
data = GzipFile(fileobj=BytesIO(data)).read().decode('utf-8').split('\0')
except IOError:
# This data is corrupted. It probably contains non-ascii chars
to_be_removed.append((hash_method, hash_))
@ -927,7 +926,6 @@ class Logger:
# if there's a need to do more gzip, put that to a function
string = StringIO()
gzip = GzipFile(fileobj=string, mode='w')
data = data.encode('utf-8') # the gzip module can't handle unicode objects
gzip.write(data)
gzip.close()
data = string.getvalue()
@ -990,7 +988,7 @@ class Logger:
try:
account_jid_id = self.get_jid_id(account_jid)
jid_id = self.get_jid_id(jid)
except exceptions.PysqliteOperationalError, e:
except exceptions.PysqliteOperationalError as e:
raise exceptions.PysqliteOperationalError(str(e))
self.cur.execute(
'DELETE FROM roster_group WHERE account_jid_id=? AND jid_id=?',
@ -1012,7 +1010,7 @@ class Logger:
try:
account_jid_id = self.get_jid_id(account_jid)
jid_id = self.get_jid_id(jid)
except exceptions.PysqliteOperationalError, e:
except exceptions.PysqliteOperationalError as e:
raise exceptions.PysqliteOperationalError(str(e))
# Update groups information
@ -1048,6 +1046,8 @@ class Logger:
FROM roster_entry re, jids j
WHERE re.account_jid_id=? AND j.jid_id=re.jid_id''', (account_jid_id,))
for jid, jid_id, name, subscription, ask in self.cur:
jid = jid
name = name
data[jid] = {}
if name:
data[jid]['name'] = name
@ -1071,6 +1071,7 @@ class Logger:
WHERE account_jid_id=? AND jid_id=?''',
(account_jid_id, data[jid]['id']))
for (group_name,) in self.cur:
group_name = group_name
data[jid]['groups'].append(group_name)
del data[jid]['id']
@ -1149,7 +1150,7 @@ class Logger:
# when we quit this muc
obj.conn.last_history_time[obj.jid] = tim_f
except exceptions.PysqliteOperationalError, e:
except exceptions.PysqliteOperationalError as e:
obj.conn.dispatch('DB_ERROR', (_('Disk Write Error'), str(e)))
except exceptions.DatabaseMalformed:
pritext = _('Database Error')

View File

@ -19,7 +19,7 @@
##
import logging
import i18n
from common import i18n
def parseLogLevel(arg):
"""
@ -30,7 +30,7 @@ def parseLogLevel(arg):
elif arg.isupper() and hasattr(logging, arg):
return getattr(logging, arg)
else:
print _('%s is not a valid loglevel') % repr(arg)
print(_('%s is not a valid loglevel') % repr(arg))
return 0
def parseLogTarget(arg):
@ -72,7 +72,7 @@ def parseAndSetLogLevels(arg):
target = parseLogTarget(target.strip())
if target:
logging.getLogger(target).setLevel(level)
print "Logger %s level set to %d" % (target, level)
print("Logger %s level set to %d" % (target, level))
class colors:
@ -152,6 +152,12 @@ def init(use_color=False):
root_log.addHandler(consoleloghandler)
root_log.propagate = False
# handle nbxmpp logs too
root_log = logging.getLogger('nbxmpp')
root_log.setLevel(logging.WARNING)
root_log.addHandler(consoleloghandler)
root_log.propagate = False
def set_loglevels(loglevels_string):
parseAndSetLogLevels(loglevels_string)

View File

@ -96,7 +96,7 @@ class ConnectionArchive:
def get_item_pref(self, jid):
jid = nbxmpp.JID(jid)
if unicode(jid) in self.items:
if str(jid) in self.items:
return self.items[jid]
if jid.getStripped() in self.items:

View File

@ -50,7 +50,7 @@ class DeviceManager(object):
except ImportError:
pass
except gst.ElementNotFoundError:
print 'element \'%s\' not found' % name
print('element \'%s\' not found' % name)
class AudioInputManager(DeviceManager):

View File

@ -153,7 +153,7 @@ class NetworkEvent(object):
return True
def _set_kwargs_as_attributes(self, **kwargs):
for k, v in kwargs.iteritems():
for k, v in kwargs.items():
setattr(self, k, v)

View File

@ -36,7 +36,7 @@ from common import helpers
from common import caps_cache
import sqlite3 as sqlite
import logger
from common import logger
class OptionsParser:
def __init__(self, filename):
@ -50,7 +50,8 @@ class OptionsParser:
except Exception:
if os.path.exists(self.__filename):
#we talk about a file
print _('Error: cannot open %s for reading') % self.__filename
print(_('Error: cannot open %s for reading') % self.__filename,
file=sys.stderr)
return False
new_version = gajim.config.get('version')
@ -59,10 +60,6 @@ class OptionsParser:
regex = re.compile(r"(?P<optname>[^.]+)(?:(?:\.(?P<key>.+))?\.(?P<subname>[^.]+))?\s=\s(?P<value>.*)")
for line in fd:
try:
line = line.decode('utf-8')
except UnicodeDecodeError:
line = line.decode(locale.getpreferredencoding())
optname, key, subname, value = regex.match(line).groups()
if key is None:
self.old_values[optname] = value
@ -86,19 +83,12 @@ class OptionsParser:
if value is None:
return
# convert to utf8 before writing to file if needed
if isinstance(value, unicode):
value = value.encode('utf-8')
else:
value = str(value)
if isinstance(opt, unicode):
opt = opt.encode('utf-8')
value = str(value)
s = ''
if parents:
if len(parents) == 1:
return
for p in parents:
if isinstance(p, unicode):
p = p.encode('utf-8')
s += p + '.'
s += opt
fd.write(s + ' = ' + value + '\n')
@ -108,11 +98,11 @@ class OptionsParser:
self.__tempfile = os.path.join(base_dir, '.' + filename)
try:
f = open(self.__tempfile, 'w')
except IOError, e:
except IOError as e:
return str(e)
try:
gajim.config.foreach(self.write_line, f)
except IOError, e:
except IOError as e:
return str(e)
f.flush()
os.fsync(f.fileno())
@ -126,9 +116,9 @@ class OptionsParser:
pass
try:
os.rename(self.__tempfile, self.__filename)
except IOError, e:
except IOError as e:
return str(e)
os.chmod(self.__filename, 0600)
os.chmod(self.__filename, 0o600)
def update_config(self, old_version, new_version):
old_version_list = old_version.split('.') # convert '0.x.y' to (0, x, y)
@ -381,7 +371,7 @@ class OptionsParser:
"""
Apply indeces to the logs database
"""
print _('migrating logs database to indices')
print(_('migrating logs database to indices'))
# FIXME see #2812
back = os.getcwd()
os.chdir(logger.LOG_DB_FOLDER)
@ -654,7 +644,7 @@ class OptionsParser:
'''
)
con.commit()
except sqlite.OperationalError, e:
except sqlite.OperationalError as e:
pass
con.close()
gajim.config.set('version', '0.11.4.4')
@ -714,7 +704,7 @@ class OptionsParser:
"""
dirs = ['../data', gajim.gajimpaths.data_root, gajim.DATA_DIR]
if os.name != 'nt':
dirs.append(os.path.expanduser(u'~/.gajim'))
dirs.append(os.path.expanduser('~/.gajim'))
for evt in gajim.config.get_per('soundevents'):
path = gajim.config.get_per('soundevents', evt, 'path')
# absolute and relative passes are necessary

View File

@ -81,7 +81,7 @@ class GnomePasswordStorage(PasswordStorage):
## migrate the password over to keyring
try:
self.save_password(account_name, password, update=False)
except GnomeKeyringError, e:
except GnomeKeyringError as e:
if e.error == GnomeKeyring.Result.NO_KEYRING_DAEMON:
## no keyring daemon: in the future, stop using it
set_storage(SimplePasswordStorage())

View File

@ -225,8 +225,6 @@ from common import helpers
import nbxmpp
from common import gajim
import gtkgui_helpers
class AbstractPEP(object):
@ -269,10 +267,6 @@ class AbstractPEP(object):
else:
acc.pep[self.type_] = self
def asPixbufIcon(self):
'''SHOULD be implemented by subclasses'''
return None
def asMarkupText(self):
'''SHOULD be implemented by subclasses'''
return ''
@ -300,13 +294,6 @@ class UserMoodPEP(AbstractPEP):
retracted = items.getTag('retract') or not 'mood' in mood_dict
return (mood_dict, retracted)
def asPixbufIcon(self):
assert not self._retracted
received_mood = self._pep_specific_data['mood']
mood = received_mood if received_mood in MOODS else 'unknown'
pixbuf = gtkgui_helpers.load_mood_icon(mood).get_pixbuf()
return pixbuf
def asMarkupText(self):
assert not self._retracted
untranslated_mood = self._pep_specific_data['mood']
@ -346,11 +333,6 @@ class UserTunePEP(AbstractPEP):
'title' in tune_dict)
return (tune_dict, retracted)
def asPixbufIcon(self):
import os
path = os.path.join(gajim.DATA_DIR, 'emoticons', 'static', 'music.png')
return GdkPixbuf.Pixbuf.new_from_file(path)
def asMarkupText(self):
assert not self._retracted
tune = self._pep_specific_data
@ -396,24 +378,6 @@ class UserActivityPEP(AbstractPEP):
retracted = items.getTag('retract') or not 'activity' in activity_dict
return (activity_dict, retracted)
def asPixbufIcon(self):
assert not self._retracted
pep = self._pep_specific_data
activity = pep['activity']
has_known_activity = activity in ACTIVITIES
has_known_subactivity = (has_known_activity and ('subactivity' in pep)
and (pep['subactivity'] in ACTIVITIES[activity]))
if has_known_activity:
if has_known_subactivity:
subactivity = pep['subactivity']
return gtkgui_helpers.load_activity_icon(activity, subactivity).get_pixbuf()
else:
return gtkgui_helpers.load_activity_icon(activity).get_pixbuf()
else:
return gtkgui_helpers.load_activity_icon('unknown').get_pixbuf()
def asMarkupText(self):
assert not self._retracted
pep = self._pep_specific_data
@ -491,10 +455,6 @@ class UserLocationPEP(AbstractPEP):
con = gajim.connections[account].location_info = \
self._pep_specific_data
def asPixbufIcon(self):
path = gtkgui_helpers.get_icon_path('gajim-earth')
return GdkPixbuf.Pixbuf.new_from_file(path)
def asMarkupText(self):
assert not self._retracted
location = self._pep_specific_data

View File

@ -163,7 +163,7 @@ class ConnectionBytestream:
session.approve_content('file', content.name)
return
iq = nbxmpp.Iq(to=unicode(file_props.sender), typ='result')
iq = nbxmpp.Iq(to=file_props.sender, typ='result')
iq.setAttr('id', file_props.request_id)
si = iq.setTag('si', namespace=nbxmpp.NS_SI)
if file_props.offset:
@ -195,7 +195,7 @@ class ConnectionBytestream:
jingle = self._sessions[file_props.sid]
jingle.cancel_session()
return
iq = nbxmpp.Iq(to=unicode(file_props.sender), typ='error')
iq = nbxmpp.Iq(to=file_props.sender, typ='error')
iq.setAttr('id', file_props.request_id)
if code == '400' and typ in ('stream', 'profile'):
name = 'bad-request'
@ -296,7 +296,7 @@ class ConnectionSocks5Bytestream(ConnectionBytestream):
for file_props in FilesProp.getAllFileProp():
if is_transfer_stopped(file_props):
continue
receiver_jid = unicode(file_props.receiver)
receiver_jid = file_props.receiver
if contact.get_full_jid() == receiver_jid:
file_props.error = -5
self.remove_transfer(file_props)
@ -305,7 +305,7 @@ class ConnectionSocks5Bytestream(ConnectionBytestream):
gajim.nec.push_incoming_event(FileRequestErrorEvent(None,
conn=self, jid=contact.jid, file_props=file_props,
error_msg=''))
sender_jid = unicode(file_props.sender)
sender_jid = file_props.sender
if contact.get_full_jid() == sender_jid:
file_props.error = -3
self.remove_transfer(file_props)
@ -354,11 +354,11 @@ class ConnectionSocks5Bytestream(ConnectionBytestream):
file_props.error = -5
from common.connection_handlers_events import FileRequestErrorEvent
gajim.nec.push_incoming_event(FileRequestErrorEvent(None, conn=self,
jid=unicode(receiver), file_props=file_props, error_msg=''))
self._connect_error(unicode(receiver), file_props.sid,
jid=receiver, file_props=file_props, error_msg=''))
self._connect_error(receiver, file_props.sid,
file_props.sid, code=406)
else:
iq = nbxmpp.Iq(to=unicode(receiver), typ='set')
iq = nbxmpp.Iq(to=receiver, typ='set')
file_props.request_id = 'id_' + file_props.sid
iq.setID(file_props.request_id)
query = iq.setTag('query', namespace=nbxmpp.NS_BYTESTREAM)
@ -374,7 +374,7 @@ class ConnectionSocks5Bytestream(ConnectionBytestream):
for host in hosts:
streamhost = nbxmpp.Node(tag='streamhost')
query.addChild(node=streamhost)
streamhost.setAttr('port', unicode(port))
streamhost.setAttr('port', str(port))
streamhost.setAttr('host', host)
streamhost.setAttr('jid', sender)
@ -489,8 +489,8 @@ class ConnectionSocks5Bytestream(ConnectionBytestream):
def _add_proxy_streamhosts_to_query(self, query, file_props):
proxyhosts = self._get_file_transfer_proxies_from_config(file_props)
if proxyhosts:
file_props.proxy_receiver = unicode(file_props.receiver)
file_props.proxy_sender = unicode(file_props.sender)
file_props.proxy_receiver = file_props.receiver
file_props.proxy_sender = file_props.sender
file_props.proxyhosts = proxyhosts
for proxyhost in proxyhosts:
@ -518,12 +518,12 @@ class ConnectionSocks5Bytestream(ConnectionBytestream):
continue
host_dict = {
'state': 0,
'target': unicode(file_props.receiver),
'target': file_props.receiver,
'id': file_props.sid,
'sid': file_props.sid,
'initiator': proxy,
'host': host,
'port': unicode(_port),
'port': str(_port),
'jid': jid
}
proxyhost_dicts.append(host_dict)
@ -563,7 +563,7 @@ class ConnectionSocks5Bytestream(ConnectionBytestream):
iq = nbxmpp.Iq(to=to, typ='error')
iq.setAttr('id', file_props.sid)
err = iq.setTag('error')
err.setAttr('code', unicode(code))
err.setAttr('code', str(code))
err.setData(msg)
self.connection.send(iq)
if code == 404:
@ -593,7 +593,7 @@ class ConnectionSocks5Bytestream(ConnectionBytestream):
# register xmpppy handlers for bytestream and FT stanzas
def _bytestreamErrorCB(self, con, iq_obj):
id_ = unicode(iq_obj.getAttr('id'))
id_ = iq_obj.getAttr('id')
frm = helpers.get_full_jid_from_iq(iq_obj)
query = iq_obj.getTag('query')
gajim.proxy65_manager.error_cb(frm, query)
@ -609,10 +609,10 @@ class ConnectionSocks5Bytestream(ConnectionBytestream):
raise nbxmpp.NodeProcessed
def _bytestreamSetCB(self, con, iq_obj):
target = unicode(iq_obj.getAttr('to'))
id_ = unicode(iq_obj.getAttr('id'))
target = iq_obj.getAttr('to')
id_ = iq_obj.getAttr('id')
query = iq_obj.getTag('query')
sid = unicode(query.getAttr('sid'))
sid = query.getAttr('sid')
file_props = FilesProp.getFileProp(self.name, sid)
streamhosts = []
for item in query.getChildren():
@ -657,7 +657,7 @@ class ConnectionSocks5Bytestream(ConnectionBytestream):
def _ResultCB(self, con, iq_obj):
# if we want to respect xep-0065 we have to check for proxy
# activation result in any result iq
real_id = unicode(iq_obj.getAttr('id'))
real_id = iq_obj.getAttr('id')
if not real_id.startswith('au_'):
return
frm = self._ft_get_from(iq_obj)
@ -671,7 +671,7 @@ class ConnectionSocks5Bytestream(ConnectionBytestream):
def _bytestreamResultCB(self, con, iq_obj):
frm = self._ft_get_from(iq_obj)
real_id = unicode(iq_obj.getAttr('id'))
real_id = iq_obj.getAttr('id')
query = iq_obj.getTag('query')
gajim.proxy65_manager.resolve_result(frm, query)
@ -692,7 +692,7 @@ class ConnectionSocks5Bytestream(ConnectionBytestream):
raise nbxmpp.NodeProcessed
for host in file_props.proxyhosts:
if host['initiator'] == frm and \
unicode(query.getAttr('sid')) == file_props.sid:
query.getAttr('sid') == file_props.sid:
gajim.socks5queue.activate_proxy(host['idx'])
break
raise nbxmpp.NodeProcessed
@ -852,7 +852,8 @@ class ConnectionIBBytestream(ConnectionBytestream):
chunk = file_props.fp.read(file_props.block_size)
if chunk:
datanode = nbxmpp.Node(nbxmpp.NS_IBB + ' data', {'sid': sid,
'seq': file_props.seq}, base64.encodestring(chunk))
'seq': file_props.seq}, base64.b64encode(chunk.encode(
'utf-8')).decode('utf-8'))
file_props.seq += 1
file_props.started = True
if file_props.seq == 65536:
@ -887,7 +888,7 @@ class ConnectionIBBytestream(ConnectionBytestream):
log.debug('ReceiveHandler called sid->%s seq->%s' % (sid, seq))
try:
seq = int(seq)
data = base64.decodestring(data)
data = base64.b64decode(data.encode('utf-8')).decode('utf-8')
except Exception:
seq = ''
data = ''
@ -898,7 +899,7 @@ class ConnectionIBBytestream(ConnectionBytestream):
else:
if not data:
err = nbxmpp.ERR_BAD_REQUEST
elif seq <> file_props.seq:
elif seq != file_props.seq:
err = nbxmpp.ERR_UNEXPECTED_REQUEST
else:
log.debug('Successfull receive sid->%s %s+%s bytes' % (sid,
@ -983,7 +984,7 @@ class ConnectionIBBytestream(ConnectionBytestream):
class ConnectionSocks5BytestreamZeroconf(ConnectionSocks5Bytestream):
def _ft_get_from(self, iq_obj):
return unicode(iq_obj.getFrom())
return iq_obj.getFrom()
def _ft_get_our_jid(self):
return gajim.get_jid_from_account(self.name)

View File

@ -29,7 +29,7 @@ log = logging.getLogger('gajim.c.proxy65_manager')
import nbxmpp
from common import gajim
from common import helpers
from socks5 import Socks5
from common.socks5 import Socks5
from nbxmpp.idlequeue import IdleObject
from common.file_props import FilesProp
@ -117,7 +117,7 @@ class ProxyResolver:
"""
self.host = str(host)
self.port = int(port)
self.jid = unicode(jid)
self.jid = str(jid)
if not self.testit:
self.state = S_FINISHED
return
@ -333,7 +333,7 @@ class HostTester(Socks5, IdleObject):
log.debug('Host Connecting to %s:%s' % (self.host, self.port))
self._send = self._sock.send
self._recv = self._sock.recv
except Exception, ee:
except Exception as ee:
errnum = ee[0]
# 56 is for freebsd
if errnum in (errno.EINPROGRESS, errno.EALREADY, errno.EWOULDBLOCK):
@ -461,7 +461,7 @@ class ReceiverTester(Socks5, IdleObject):
log.debug('Receiver Connecting to %s:%s' % (self.host, self.port))
self._send = self._sock.send
self._recv = self._sock.recv
except Exception, ee:
except Exception as ee:
errnum = ee[0]
# 56 is for freebsd
if errnum in (errno.EINPROGRESS, errno.EALREADY, errno.EWOULDBLOCK):

View File

@ -22,11 +22,13 @@
##
import nbxmpp
import gajim
import connection_handlers
import ged
from connection_handlers_events import PubsubReceivedEvent
from connection_handlers_events import PubsubBookmarksReceivedEvent
from common import gajim
#TODO: Doesn't work
#from common.connection_handlers import PEP_CONFIG
PEP_CONFIG = 'pep_config'
from common import ged
from common.connection_handlers_events import PubsubReceivedEvent
from common.connection_handlers_events import PubsubBookmarksReceivedEvent
import logging
log = logging.getLogger('gajim.c.pubsub')
@ -218,5 +220,5 @@ class ConnectionPubSub:
e = e.addChild('configure', {'node': node})
id_ = self.connection.getAnID()
query.setID(id_)
self.awaiting_answers[id_] = (connection_handlers.PEP_CONFIG,)
self.awaiting_answers[id_] = (PEP_CONFIG,)
self.connection.send(query)

View File

@ -70,33 +70,33 @@ class CommonResolver():
# empty host, return empty list of srv records
on_ready([])
return
if self.resolved_hosts.has_key(host+type):
if host + type in self.resolved_hosts:
# host is already resolved, return cached values
log.debug('%s already resolved: %s' % (host,
self.resolved_hosts[host+type]))
on_ready(host, self.resolved_hosts[host+type])
self.resolved_hosts[host + type]))
on_ready(host, self.resolved_hosts[host + type])
return
if self.handlers.has_key(host+type):
if host + type in self.handlers:
# host is about to be resolved by another connection,
# attach our callback
log.debug('already resolving %s' % host)
self.handlers[host+type].append(on_ready)
self.handlers[host + type].append(on_ready)
else:
# host has never been resolved, start now
log.debug('Starting to resolve %s using %s' % (host, self))
self.handlers[host+type] = [on_ready]
self.handlers[host + type] = [on_ready]
self.start_resolve(host, type)
def _on_ready(self, host, type, result_list):
# practically it is impossible to be the opposite, but who knows :)
host = host.lower()
log.debug('Resolving result for %s: %s' % (host, result_list))
if not self.resolved_hosts.has_key(host+type):
self.resolved_hosts[host+type] = result_list
if self.handlers.has_key(host+type):
for callback in self.handlers[host+type]:
if host + type not in self.resolved_hosts:
self.resolved_hosts[host + type] = result_list
if host + type in self.handlers:
for callback in self.handlers[host + type]:
callback(host, result_list)
del(self.handlers[host+type])
del(self.handlers[host + type])
def start_resolve(self, host, type):
pass
@ -251,8 +251,7 @@ class NSLookupResolver(CommonResolver):
domain = None
if line.startswith(fqdn):
domain = fqdn # For nslookup 9.5
elif helpers.decode_string(line).startswith(ufqdn):
line = helpers.decode_string(line)
elif line.startswith(ufqdn):
domain = ufqdn # For nslookup 9.6
if domain:
rest = line[len(domain):].split('=')
@ -329,7 +328,7 @@ if __name__ == '__main__':
global resolver
host = text_view.get_text()
def on_result(host, result_array):
print 'Result:\n' + repr(result_array)
print('Result:\n' + repr(result_array))
resolver.resolve(host, on_result)
win = Gtk.Window()
win.set_border_width(6)

View File

@ -28,7 +28,7 @@ try:
from docutils import nodes, utils
from docutils.parsers.rst.roles import set_classes
except ImportError:
print "Requires docutils 0.4 for set_classes to be available"
print("Requires docutils 0.4 for set_classes to be available")
def create_xhtml(text):
return None
else:
@ -65,7 +65,7 @@ else:
options={}, content=[]):
try:
valid_text = validator(text)
except ValueError, e:
except ValueError as e:
msg = inliner.reporter.error( e.message % dict(text=text), line=lineno)
prb = inliner.problematic(rawtext, rawtext, msg)
return [prb], [msg]
@ -120,7 +120,7 @@ else:
# in the JEP
# &nbsp; == u"\u00a0"
self.pub.writer.translator_class.attribution_formats['dash'] = (
u'\u2014', '')
'\u2014', '')
self.pub.process_programmatic_settings(settings_spec,
settings_overrides,
config_section)
@ -137,7 +137,7 @@ else:
output = self.pub.publish(enable_exit_status=enable_exit_status)
# kludge until we can get docutils to stop generating (rare) &nbsp;
# entities
return u'\u00a0'.join(self.pub.writer.parts['fragment'].strip().split(
return '\u00a0'.join(self.pub.writer.parts['fragment'].strip().split(
'&nbsp;'))
Generator = HTMLGenerator()
@ -147,7 +147,7 @@ else:
if __name__ == '__main__':
print "test 1\n", Generator.create_xhtml("""
print("test 1\n" + Generator.create_xhtml("""
test::
>>> print 1
@ -157,10 +157,10 @@ test::
this `` should trigger`` should trigger the &nbsp; problem.
""")
print "test 2\n", Generator.create_xhtml("""
"""))
print("test 2\n" + Generator.create_xhtml("""
*test1
test2_
""")
print "test 3\n", Generator.create_xhtml(""":ticket:`316` implements :xep:`71`""")
"""))
print("test 3\n" + Generator.create_xhtml(""":ticket:`316` implements :xep:`71`"""))

View File

@ -22,7 +22,8 @@
##
from common import gajim
import os, sys
import os
import sys
STATE_UNKNOWN = 'OS probably not supported'

View File

@ -33,9 +33,9 @@ from errno import EISCONN
from errno import EINPROGRESS
from errno import EAFNOSUPPORT
from nbxmpp.idlequeue import IdleObject
from file_props import FilesProp
from common.file_props import FilesProp
from common import gajim
import jingle_xtls
from common import jingle_xtls
if jingle_xtls.PYOPENSSL_PRESENT:
import OpenSSL
import logging
@ -463,7 +463,7 @@ class Socks5:
self._sock.setblocking(False)
self._server = ai[4]
break
except socket.error, e:
except socket.error as e:
if not isinstance(e, basestring) and e[0] == EINPROGRESS:
break
# for all other errors, we try other addresses
@ -481,7 +481,7 @@ class Socks5:
self._sock.setblocking(False)
self._send=self._sock.send
self._recv=self._sock.recv
except Exception, ee:
except Exception as ee:
errnum = ee[0]
self.connect_timeout += 1
if errnum == 111 or self.connect_timeout > 1000:
@ -533,9 +533,9 @@ class Socks5:
self.size = self.file_props.offset
self.file.seek(self.size)
self.file_props.received_len = self.size
except IOError, e:
except IOError as e:
self.close_file()
raise IOError, e
raise IOError(str(e))
def close_file(self):
if self.file:
@ -583,7 +583,7 @@ class Socks5:
try:
add = self._recv(64)
except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantWriteError,
OpenSSL.SSL.WantX509LookupError), e:
OpenSSL.SSL.WantX509LookupError) as e:
log.info('SSL rehandshake request : ' + repr(e))
raise e
except Exception:
@ -600,10 +600,10 @@ class Socks5:
try:
self._send(raw_data)
except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantWriteError,
OpenSSL.SSL.WantX509LookupError), e:
OpenSSL.SSL.WantX509LookupError) as e:
log.info('SSL rehandshake request :' + repr(e))
raise e
except Exception, e:
except Exception as e:
self.disconnect()
return len(raw_data)
@ -614,7 +614,7 @@ class Socks5:
else:
try:
self.open_file_for_reading()
except IOError, e:
except IOError as e:
self.state = 8 # end connection
self.disconnect()
self.file_props.error = -7 # unable to read from file
@ -625,10 +625,10 @@ class Socks5:
try:
lenn = self._send(buff)
except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantWriteError,
OpenSSL.SSL.WantX509LookupError), e:
OpenSSL.SSL.WantX509LookupError) as e:
log.info('SSL rehandshake request :' + repr(e))
raise e
except Exception, e:
except Exception as e:
if e.args[0] not in (EINTR, ENOBUFS, EWOULDBLOCK):
# peer stopped reading
self.state = 8 # end connection
@ -671,7 +671,7 @@ class Socks5:
if self.remaining_buff != '':
try:
fd = self.get_fd()
except IOError, e:
except IOError as e:
self.disconnect(False)
self.file_props.error = -6 # file system error
return 0
@ -692,14 +692,14 @@ class Socks5:
else:
try:
fd = self.get_fd()
except IOError, e:
except IOError as e:
self.disconnect(False)
self.file_props.error = -6 # file system error
return 0
try:
buff = self._recv(MAX_BUFF_LEN)
except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantWriteError,
OpenSSL.SSL.WantX509LookupError), e:
OpenSSL.SSL.WantX509LookupError) as e:
log.info('SSL rehandshake request :' + repr(e))
raise e
except Exception:
@ -718,7 +718,7 @@ class Socks5:
return 0
try:
fd.write(buff)
except IOError, e:
except IOError as e:
self.rem_fd(fd)
self.disconnect()
self.file_props.error = -6 # file system error
@ -781,7 +781,7 @@ class Socks5:
auth_mechanisms = []
try:
num_auth = struct.unpack('!xB', buff[:2])[0]
for i in xrange(num_auth):
for i in list(range(num_auth)):
mechanism, = struct.unpack('!B', buff[1 + i])
auth_mechanisms.append(mechanism)
except Exception:
@ -842,7 +842,7 @@ class Socks5:
try:
buff = self._recv()
except (SSL.WantReadError, SSL.WantWriteError,
SSL.WantX509LookupError), e:
SSL.WantX509LookupError) as e:
log.info("SSL rehandshake request : " + repr(e))
raise e
try:
@ -1085,7 +1085,7 @@ class Socks5Server(Socks5):
result = self.start_transfer() # send
self.queue.process_result(result, self)
except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantWriteError,
OpenSSL.SSL.WantX509LookupError), e:
OpenSSL.SSL.WantX509LookupError) as e:
log.info('caught SSL exception, ignored')
else:
self.disconnect()
@ -1123,7 +1123,7 @@ class Socks5Server(Socks5):
else:
self.disconnect()
except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantWriteError,
OpenSSL.SSL.WantX509LookupError), e:
OpenSSL.SSL.WantX509LookupError) as e:
log.info('caught SSL exception, ignored')
return
if self.state < 5:
@ -1229,7 +1229,7 @@ class Socks5Client(Socks5):
result = self.start_transfer() # receive
self.queue.process_result(result, self)
except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantWriteError,
OpenSSL.SSL.WantX509LookupError), e:
OpenSSL.SSL.WantX509LookupError) as e:
log.info('caught SSL exception, ignored')
return
else:
@ -1253,7 +1253,7 @@ class Socks5Client(Socks5):
self.queue.process_result(result, self)
return
except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantWriteError,
OpenSSL.SSL.WantX509LookupError), e:
OpenSSL.SSL.WantX509LookupError) as e:
log.info('caught SSL exception, ignored')
return
self.state += 1
@ -1346,7 +1346,7 @@ class Socks5Listener(IdleObject):
if self.fingerprint is not None:
self._serv = OpenSSL.SSL.Connection(
jingle_xtls.get_context('server'), self._serv)
except socket.error, e:
except socket.error as e:
if e.args[0] == EAFNOSUPPORT:
self.ai = None
continue

View File

@ -45,7 +45,7 @@ if gajim.HAVE_PYCRYPTO:
from Crypto.PublicKey import RSA
from common import dh
import secrets
from . import secrets
XmlDsig = 'http://www.w3.org/2000/09/xmldsig#'

View File

@ -173,7 +173,7 @@ class P2PClient(IdleObject):
id_ = stanza.getID()
if not id_:
id_ = self.Dispatcher.getAnID()
if self.conn_holder.ids_of_awaiting_messages.has_key(self.fd):
if self.fd in self.conn_holder.ids_of_awaiting_messages:
self.conn_holder.ids_of_awaiting_messages[self.fd].append((
id_, thread_id))
else:
@ -195,7 +195,7 @@ class P2PClient(IdleObject):
id_ = stanza.getID()
if not id_:
id_ = self.Dispatcher.getAnID()
if self.conn_holder.ids_of_awaiting_messages.has_key(self.fd):
if self.fd in self.conn_holder.ids_of_awaiting_messages:
self.conn_holder.ids_of_awaiting_messages[self.fd].append((id_,
thread_id))
else:
@ -253,10 +253,10 @@ class P2PClient(IdleObject):
'Incorrect answer from server.')
return
if self.sock_type == TYPE_SERVER:
if attrs.has_key('from'):
if 'from' in attrs:
self.to = attrs['from']
self.send_stream_header()
if attrs.has_key('version') and attrs['version'] == '1.0':
if 'version' in attrs and attrs['version'] == '1.0':
# other part supports stream features
features = Node('stream:features')
self.Dispatcher.send(features)
@ -270,12 +270,12 @@ class P2PClient(IdleObject):
def on_disconnect(self):
if self.conn_holder:
if self.conn_holder.ids_of_awaiting_messages.has_key(self.fd):
if self.fd in self.conn_holder.ids_of_awaiting_messages:
del self.conn_holder.ids_of_awaiting_messages[self.fd]
self.conn_holder.remove_connection(self.sock_hash)
if self.__dict__.has_key('Dispatcher'):
if 'Dispatcher' in self.__dict__:
self.Dispatcher.PlugOut()
if self.__dict__.has_key('P2PConnection'):
if 'P2PConnection' in self.__dict__:
self.P2PConnection.PlugOut()
self.Connection = None
self._caller = None
@ -294,7 +294,7 @@ class P2PClient(IdleObject):
self.Dispatcher.Stream._document_attrs is None:
return
self.onreceive(None)
if self.Dispatcher.Stream._document_attrs.has_key('version') and \
if 'version' in self.Dispatcher.Stream._document_attrs and \
self.Dispatcher.Stream._document_attrs['version'] == '1.0':
#~ self.onreceive(self._on_receive_stream_features)
#XXX continue with TLS
@ -356,7 +356,7 @@ class P2PConnection(IdleObject, PlugIn):
try:
self.ais = socket.getaddrinfo(host, port, socket.AF_UNSPEC,
socket.SOCK_STREAM)
except socket.gaierror, e:
except socket.gaierror as e:
log.info('Lookup failure for %s: %s[%s]', host, e[1],
repr(e[0]), exc_info=True)
else:
@ -418,19 +418,12 @@ class P2PConnection(IdleObject, PlugIn):
"""
Append stanza to the queue of messages to be send if now is False, else
send it instantly
If supplied data is unicode string, encode it to UTF-8.
"""
if self.state <= 0:
return
r = packet
if isinstance(r, unicode):
r = r.encode('utf-8')
elif not isinstance(r, str):
r = ustr(r).encode('utf-8')
if now:
self.sendqueue.insert(0, (r, is_message))
self._do_send()
@ -455,7 +448,7 @@ class P2PConnection(IdleObject, PlugIn):
try:
self._sock.connect(self._server)
self._sock.setblocking(False)
except Exception, ee:
except Exception as ee:
(errnum, errstr) = ee
errors = (errno.EINPROGRESS, errno.EALREADY, errno.EWOULDBLOCK)
if 'WSAEINVAL' in errno.__dict__:
@ -495,7 +488,7 @@ class P2PConnection(IdleObject, PlugIn):
try:
# get as many bites, as possible, but not more than RECV_BUFSIZE
received = self._sock.recv(MAX_BUFF_LEN)
except Exception, e:
except Exception as e:
if len(e.args) > 0 and isinstance(e.args[0], int):
errnum = e[0]
# "received" will be empty anyhow
@ -566,7 +559,7 @@ class P2PConnection(IdleObject, PlugIn):
self._plug_idle()
self._on_send()
except socket.error, e:
except socket.error as e:
if e[0] == socket.SSL_ERROR_WANT_WRITE:
return True
if self.state < 0:
@ -717,7 +710,7 @@ class ClientZeroconf:
if self.ip_to_hash[i] == sock_hash:
del self.ip_to_hash[i]
break
if self.hash_to_port.has_key(sock_hash):
if sock_hash in self.hash_to_port:
del self.hash_to_port[sock_hash]
def start_listener(self, port):
@ -737,7 +730,7 @@ class ClientZeroconf:
def send(self, stanza, is_message=False, now=False, on_ok=None,
on_not_ok=None):
stanza.setFrom(self.roster.zeroconf.name)
to = unicode(stanza.getTo())
to = stanza.getTo()
to = gajim.get_jid_without_resource(to)
try:
@ -802,7 +795,7 @@ class ClientZeroconf:
def on_ok(_waitid):
# if timeout:
# self._owner.set_timeout(timeout)
to = unicode(stanza.getTo())
to = stanza.getTo()
to = gajim.get_jid_without_resource(to)
try:

View File

@ -46,7 +46,7 @@ from common import gajim
from common import ged
from common.zeroconf import client_zeroconf
from common.zeroconf import zeroconf
from connection_handlers_zeroconf import *
from common.zeroconf.connection_handlers_zeroconf import *
from common.connection_handlers_events import *
import locale
@ -91,7 +91,7 @@ class ConnectionZeroconf(CommonConnection, ConnectionHandlersZeroconf):
'is_zeroconf', True)
gajim.config.set_per('accounts', gajim.ZEROCONF_ACC_NAME,
'use_ft_proxies', False)
self.host = unicode(socket.gethostname(), locale.getpreferredencoding())
self.host = socket.gethostname()
gajim.config.set_per('accounts', gajim.ZEROCONF_ACC_NAME, 'hostname',
self.host)
self.port = gajim.config.get_per('accounts', gajim.ZEROCONF_ACC_NAME,
@ -110,8 +110,7 @@ class ConnectionZeroconf(CommonConnection, ConnectionHandlersZeroconf):
'zeroconf_email')
if not self.username:
self.username = unicode(getpass.getuser(),
locale.getpreferredencoding())
self.username = getpass.getuser()
gajim.config.set_per('accounts', gajim.ZEROCONF_ACC_NAME, 'name',
self.username)
else:
@ -427,7 +426,7 @@ class ConnectionZeroconf(CommonConnection, ConnectionHandlersZeroconf):
if realm == '':
if event == nbxmpp.transports_nb.DATA_ERROR:
thread_id = data[1]
frm = unicode(data[0])
frm = data[0]
session = self.get_or_create_session(frm, thread_id)
gajim.nec.push_incoming_event(MessageErrorEvent(
None, conn=self, fjid=frm, error_code=-1, error_msg=_(

View File

@ -32,7 +32,6 @@ class Roster:
self.setItem(val[zeroconf.C_NAME])
def getRoster(self):
#print 'roster_zeroconf.py: getRoster'
if self._data is None:
self._data = {}
self.update_roster()
@ -50,11 +49,9 @@ class Roster:
if key in self._data:
if old_data[key] != self._data[key]:
diffs[key] = self._data[key]['status']
#print 'roster_zeroconf.py: diffs:' + str(diffs)
return diffs
def setItem(self, jid, name='', groups=''):
#print 'roster_zeroconf.py: setItem %s' % jid
contact = self.zeroconf.get_contact(jid)
if not contact:
return
@ -96,34 +93,27 @@ class Roster:
self.setItem(jid=i['jid'], name=i['name'], groups=i['groups'])
def delItem(self, jid):
#print 'roster_zeroconf.py: delItem %s' % jid
if jid in self._data:
del self._data[jid]
def getItem(self, jid):
#print 'roster_zeroconf.py: getItem: %s' % jid
if jid in self._data:
return self._data[jid]
def __getitem__(self, jid):
#print 'roster_zeroconf.py: __getitem__'
return self._data[jid]
def getItems(self):
#print 'roster_zeroconf.py: getItems'
# Return list of all [bare] JIDs that the roster currently tracks.
return self._data.keys()
def keys(self):
#print 'roster_zeroconf.py: keys'
return self._data.keys()
def getRaw(self):
#print 'roster_zeroconf.py: getRaw'
return self._data
def getResources(self, jid):
#print 'roster_zeroconf.py: getResources(%s)' % jid
return {}
def getGroups(self, jid):
@ -142,14 +132,12 @@ class Roster:
return self._data[jid]['txt_dict']['msg']
def getShow(self, jid):
#print 'roster_zeroconf.py: getShow'
return self.getStatus(jid)
def getPriority(self, jid):
return 5
def getSubscription(self, jid):
#print 'roster_zeroconf.py: getSubscription'
return 'both'
def Subscribe(self, jid):

View File

@ -22,7 +22,7 @@ log = logging.getLogger('gajim.c.z.zeroconf_avahi')
try:
import dbus.exceptions
except ImportError, e:
except ImportError as e:
pass
from common.zeroconf.zeroconf import C_BARE_NAME, C_INTERFACE, C_PROTOCOL, C_DOMAIN
@ -224,14 +224,7 @@ class Zeroconf:
return show
def avahi_txt(self):
utf8_dict = {}
for key in self.txt:
val = self.txt[key]
if isinstance(val, unicode):
utf8_dict[key] = val.encode('utf-8')
else:
utf8_dict[key] = val
return self.avahi.dict_to_txt_array(utf8_dict)
return self.avahi.dict_to_txt_array(self.txt)
def create_service(self):
try:
@ -246,7 +239,7 @@ class Zeroconf:
txt = {}
# remove empty keys
for key, val in self.txt.iteritems():
for key, val in self.txt.items():
if val:
txt[key] = val
@ -274,7 +267,7 @@ class Zeroconf:
return True
except dbus.DBusException, e:
except dbus.DBusException as e:
log.debug(str(e))
return False
@ -334,7 +327,7 @@ class Zeroconf:
self.bus.add_signal_receiver(self.avahi_dbus_connect_cb,
'NameOwnerChanged', 'org.freedesktop.DBus',
arg0='org.freedesktop.Avahi')
except Exception, e:
except Exception as e:
# System bus is not present
self.bus = None
log.debug(str(e))
@ -361,7 +354,7 @@ class Zeroconf:
self.avahi.DBUS_PATH_SERVER), self.avahi.DBUS_INTERFACE_SERVER)
self.server.connect_to_signal('StateChanged',
self.server_state_changed_callback)
except Exception, e:
except Exception as e:
# Avahi service is not present
self.server = None
log.debug(str(e))
@ -402,14 +395,14 @@ class Zeroconf:
if self.service_browser:
try:
self.service_browser.Free()
except dbus.DBusException, e:
except dbus.DBusException as e:
log.debug(str(e))
self.service_browser._obj._bus = None
self.service_browser._obj = None
if self.domain_browser:
try:
self.domain_browser.Free()
except dbus.DBusException, e:
except dbus.DBusException as e:
log.debug(str(e))
self.domain_browser._obj._bus = None
self.domain_browser._obj = None

View File

@ -24,7 +24,7 @@ from common.zeroconf.zeroconf import C_BARE_NAME, C_DOMAIN
try:
import pybonjour
except ImportError, e:
except ImportError as e:
pass
@ -224,7 +224,7 @@ class Zeroconf:
regtype = self.stype, port = self.port, txtRecord = self.txt,
callBack = self.service_added_callback)
self.service_sdRef = sdRef
except pybonjour.BonjourError, e:
except pybonjour.BonjourError as e:
self.service_add_fail_callback(e)
else:
gajim.log.debug('Publishing service %s of type %s' % (self.name, self.stype))
@ -248,7 +248,7 @@ class Zeroconf:
self.service_sdRef.close()
self.announced = False
return True
except pybonjour.BonjourError, e:
except pybonjour.BonjourError as e:
gajim.log.debug(e)
return False
@ -282,7 +282,7 @@ class Zeroconf:
gajim.log.debug('starting to browse')
try:
self.browse_sdRef = pybonjour.DNSServiceBrowse(regtype=self.stype, domain=domain, callBack=self.browse_callback)
except pybonjour.BonjourError, e:
except pybonjour.BonjourError as e:
self.error_CB("Error while browsing: %s" % e)
def browse_loop(self):

View File

@ -173,7 +173,7 @@ class PreferencesWindow:
if dir_ != '.svn':
l.append(dir_)
l.append(_('Disabled'))
for i in xrange(len(l)):
for i in range(len(l)):
model.append([l[i]])
if gajim.config.get('emoticons_theme') == l[i]:
emoticons_combobox.set_active(i)
@ -243,7 +243,7 @@ class PreferencesWindow:
l.append(dir)
if l.count == 0:
l.append(' ')
for i in xrange(len(l)):
for i in range(len(l)):
preview = Gtk.Image()
files = []
files.append(os.path.join(helpers.get_iconset_path(l[i]), '16x16',
@ -455,8 +455,8 @@ class PreferencesWindow:
else:
config = gajim.config.get(opt_name + '_device')
for index, (name, value) in enumerate(sorted(device_dict.\
iteritems(), key=key)):
for index, (name, value) in enumerate(sorted(device_dict.items(),
key=key)):
model.append((name, value))
if config == value:
combobox.set_active(index)
@ -684,7 +684,7 @@ class PreferencesWindow:
def on_emoticons_combobox_changed(self, widget):
active = widget.get_active()
model = widget.get_model()
emot_theme = model[active][0].decode('utf-8')
emot_theme = model[active][0]
if emot_theme == _('Disabled'):
gajim.config.set('emoticons_theme', '')
else:
@ -770,7 +770,7 @@ class PreferencesWindow:
def on_theme_combobox_changed(self, widget):
model = widget.get_model()
active = widget.get_active()
config_theme = model[active][0].decode('utf-8').replace(' ', '_')
config_theme = model[active][0].replace(' ', '_')
gajim.config.set('roster_theme', config_theme)
@ -800,7 +800,7 @@ class PreferencesWindow:
def on_iconset_combobox_changed(self, widget):
model = widget.get_model()
active = widget.get_active()
icon_string = model[active][1].decode('utf-8')
icon_string = model[active][1]
gajim.config.set('iconset', icon_string)
gtkgui_helpers.reload_jabber_state_images()
@ -1019,7 +1019,7 @@ class PreferencesWindow:
gajim.config.get('autoxatime') * 60)
def on_auto_away_message_entry_changed(self, widget):
gajim.config.set('autoaway_message', widget.get_text().decode('utf-8'))
gajim.config.set('autoaway_message', widget.get_text())
def on_auto_xa_checkbutton_toggled(self, widget):
self.on_checkbutton_toggled(widget, 'autoxa',
@ -1033,7 +1033,7 @@ class PreferencesWindow:
gajim.config.get('autoxatime') * 60)
def on_auto_xa_message_entry_changed(self, widget):
gajim.config.set('autoxa_message', widget.get_text().decode('utf-8'))
gajim.config.set('autoxa_message', widget.get_text())
def on_prompt_online_status_message_checkbutton_toggled(self, widget):
self.on_checkbutton_toggled(widget, 'ask_online_status')
@ -1067,7 +1067,7 @@ class PreferencesWindow:
def on_default_msg_treemodel_row_changed(self, model, path, iter_):
status = model[iter_][0]
message = model[iter_][2].decode('utf-8')
message = model[iter_][2]
message = helpers.to_one_line(message)
gajim.config.set_per('defaultstatusmsg', status, 'enabled',
model[iter_][3])
@ -1084,20 +1084,18 @@ class PreferencesWindow:
gajim.config.del_per('statusmsg', msg)
iter_ = model.get_iter_first()
while iter_:
val = model[iter_][0].decode('utf-8')
val = model[iter_][0]
if model[iter_][1]: # we have a preset message
if not val: # no title, use message text for title
val = model[iter_][1]
gajim.config.add_per('statusmsg', val)
msg = helpers.to_one_line(model[iter_][1].decode('utf-8'))
msg = helpers.to_one_line(model[iter_][1])
gajim.config.set_per('statusmsg', val, 'message', msg)
i = 2
# store mood / activity
for subname in ('activity', 'subactivity', 'activity_text',
'mood', 'mood_text'):
val = model[iter_][i]
if val:
val = val.decode('utf-8')
gajim.config.set_per('statusmsg', val, subname, val)
i += 1
iter_ = model.iter_next(iter_)
@ -1111,7 +1109,7 @@ class PreferencesWindow:
def on_av_combobox_changed(self, combobox, config_name):
model = combobox.get_model()
active = combobox.get_active()
device = model[active][1].decode('utf-8')
device = model[active][1]
gajim.config.set(config_name, device)
def on_audio_input_combobox_changed(self, widget):
@ -1137,7 +1135,7 @@ class PreferencesWindow:
[self.xml.get_object('stun_server_entry')])
def stun_server_entry_changed(self, widget):
gajim.config.set('stun_server', widget.get_text().decode('utf-8'))
gajim.config.set('stun_server', widget.get_text())
def on_applications_combobox_changed(self, widget):
if widget.get_active() == 0:
@ -1148,13 +1146,13 @@ class PreferencesWindow:
self.xml.get_object('custom_apps_frame').show()
def on_custom_browser_entry_changed(self, widget):
gajim.config.set('custombrowser', widget.get_text().decode('utf-8'))
gajim.config.set('custombrowser', widget.get_text())
def on_custom_mail_client_entry_changed(self, widget):
gajim.config.set('custommailapp', widget.get_text().decode('utf-8'))
gajim.config.set('custommailapp', widget.get_text())
def on_custom_file_manager_entry_changed(self, widget):
gajim.config.set('custom_file_manager', widget.get_text().decode('utf-8'))
gajim.config.set('custom_file_manager', widget.get_text())
def on_log_show_changes_checkbutton_toggled(self, widget):
self.on_checkbutton_toggled(widget, 'log_contact_status_changes')
@ -1260,7 +1258,7 @@ class PreferencesWindow:
def on_proxies_combobox_changed(self, widget):
active = widget.get_active()
proxy = widget.get_model()[active][0].decode('utf-8')
proxy = widget.get_model()[active][0]
if proxy == _('None'):
proxy = ''
@ -1281,7 +1279,7 @@ class PreferencesWindow:
model.clear()
l = gajim.config.get_per('proxies')
l.insert(0, _('None'))
for i in xrange(len(l)):
for i in range(len(l)):
model.append([l[i]])
if our_proxy == l[i]:
proxy_combobox.set_active(i)
@ -1357,11 +1355,11 @@ class ManageProxiesWindow:
model = self.proxies_treeview.get_model()
proxies = gajim.config.get_per('proxies')
i = 1
while ('proxy' + unicode(i)) in proxies:
while ('proxy' + str(i)) in proxies:
i += 1
iter_ = model.append()
model.set(iter_, 0, 'proxy' + unicode(i))
gajim.config.add_per('proxies', 'proxy' + unicode(i))
model.set(iter_, 0, 'proxy' + str(i))
gajim.config.add_per('proxies', 'proxy' + str(i))
self.proxies_treeview.set_cursor(model.get_path(iter_))
def on_remove_proxy_button_clicked(self, widget):
@ -1371,7 +1369,7 @@ class ManageProxiesWindow:
(model, iter_) = sel.get_selected()
if not iter_:
return
proxy = model[iter_][0].decode('utf-8')
proxy = model[iter_][0]
model.remove(iter_)
gajim.config.del_per('proxies', proxy)
self.xml.get_object('remove_proxy_button').set_sensitive(False)
@ -1386,7 +1384,7 @@ class ManageProxiesWindow:
if self.block_signal:
return
act = widget.get_active()
proxy = self.proxyname_entry.get_text().decode('utf-8')
proxy = self.proxyname_entry.get_text()
gajim.config.set_per('proxies', proxy, 'useauth', act)
self.xml.get_object('proxyuser_entry').set_sensitive(act)
self.xml.get_object('proxypass_entry').set_sensitive(act)
@ -1395,7 +1393,7 @@ class ManageProxiesWindow:
if self.block_signal:
return
act = widget.get_active()
proxy = self.proxyname_entry.get_text().decode('utf-8')
proxy = self.proxyname_entry.get_text()
gajim.config.set_per('proxies', proxy, 'bosh_useproxy', act)
self.xml.get_object('proxyhost_entry').set_sensitive(act)
self.xml.get_object('proxyport_entry').set_sensitive(act)
@ -1455,7 +1453,7 @@ class ManageProxiesWindow:
self.xml.get_object('proxy_table').set_sensitive(True)
proxyhost_entry.set_text(gajim.config.get_per('proxies', proxy,
'host'))
proxyport_entry.set_text(unicode(gajim.config.get_per('proxies',
proxyport_entry.set_text(str(gajim.config.get_per('proxies',
proxy, 'port')))
proxyuser_entry.set_text(gajim.config.get_per('proxies', proxy,
'user'))
@ -1484,8 +1482,8 @@ class ManageProxiesWindow:
(model, iter_) = sel.get_selected()
if not iter_:
return
old_name = model.get_value(iter_, 0).decode('utf-8')
new_name = widget.get_text().decode('utf-8')
old_name = model.get_value(iter_, 0)
new_name = widget.get_text()
if new_name == '':
return
if new_name == old_name:
@ -1503,42 +1501,42 @@ class ManageProxiesWindow:
types = ['http', 'socks5', 'bosh']
type_ = self.proxytype_combobox.get_active()
self.show_bosh_fields(types[type_]=='bosh')
proxy = self.proxyname_entry.get_text().decode('utf-8')
proxy = self.proxyname_entry.get_text()
gajim.config.set_per('proxies', proxy, 'type', types[type_])
def on_proxyhost_entry_changed(self, widget):
if self.block_signal:
return
value = widget.get_text().decode('utf-8')
proxy = self.proxyname_entry.get_text().decode('utf-8')
value = widget.get_text()
proxy = self.proxyname_entry.get_text()
gajim.config.set_per('proxies', proxy, 'host', value)
def on_proxyport_entry_changed(self, widget):
if self.block_signal:
return
value = widget.get_text().decode('utf-8')
proxy = self.proxyname_entry.get_text().decode('utf-8')
value = widget.get_text()
proxy = self.proxyname_entry.get_text()
gajim.config.set_per('proxies', proxy, 'port', value)
def on_proxyuser_entry_changed(self, widget):
if self.block_signal:
return
value = widget.get_text().decode('utf-8')
proxy = self.proxyname_entry.get_text().decode('utf-8')
value = widget.get_text()
proxy = self.proxyname_entry.get_text()
gajim.config.set_per('proxies', proxy, 'user', value)
def on_boshuri_entry_changed(self, widget):
if self.block_signal:
return
value = widget.get_text().decode('utf-8')
proxy = self.proxyname_entry.get_text().decode('utf-8')
value = widget.get_text()
proxy = self.proxyname_entry.get_text()
gajim.config.set_per('proxies', proxy, 'bosh_uri', value)
def on_proxypass_entry_changed(self, widget):
if self.block_signal:
return
value = widget.get_text().decode('utf-8')
proxy = self.proxyname_entry.get_text().decode('utf-8')
value = widget.get_text()
proxy = self.proxyname_entry.get_text()
gajim.config.set_per('proxies', proxy, 'pass', value)
@ -1613,7 +1611,7 @@ class AccountsWindow:
model = self.accounts_treeview.get_model()
iter_ = model.get_iter_first()
while iter_:
acct = model[iter_][0].decode('utf-8')
acct = model[iter_][0]
if account == acct:
self.accounts_treeview.set_cursor(model.get_path(iter_))
return
@ -1693,7 +1691,7 @@ class AccountsWindow:
if sel:
(model, iter_) = sel.get_selected()
if iter_:
account = model[iter_][0].decode('utf-8')
account = model[iter_][0]
else:
account = None
else:
@ -1768,7 +1766,7 @@ class AccountsWindow:
proxy_combobox.set_model(model)
l = gajim.config.get_per('proxies')
l.insert(0, _('None'))
for i in xrange(len(l)):
for i in range(len(l)):
model.append([l[i]])
if our_proxy == l[i]:
proxy_combobox.set_active(i)
@ -1957,7 +1955,7 @@ class AccountsWindow:
if not custom_port:
custom_port = 5222
gajim.config.set_per('accounts', account, 'custom_port', custom_port)
self.xml.get_object('custom_port_entry1').set_text(unicode(custom_port))
self.xml.get_object('custom_port_entry1').set_text(str(custom_port))
# Personal tab
gpg_key_label = self.xml.get_object('gpg_key_label1')
@ -2163,7 +2161,7 @@ class AccountsWindow:
# check if jid is conform to RFC and stringprep it
try:
jid = helpers.parse_jid(jid)
except helpers.InvalidFormat, s:
except helpers.InvalidFormat as s:
if not widget.is_focus():
pritext = _('Invalid Jabber ID')
dialogs.ErrorDialog(pritext, str(s))
@ -2240,7 +2238,7 @@ class AccountsWindow:
'utf-8')
try:
resource = helpers.parse_resource(resource)
except helpers.InvalidFormat, s:
except helpers.InvalidFormat as s:
if not widget.is_focus():
pritext = _('Invalid Jabber ID')
dialogs.ErrorDialog(pritext, str(s))
@ -2342,7 +2340,7 @@ class AccountsWindow:
def on_proxies_combobox1_changed(self, widget):
active = widget.get_active()
proxy = widget.get_model()[active][0].decode('utf-8')
proxy = widget.get_model()[active][0]
if proxy == _('None'):
proxy = ''
@ -2384,7 +2382,7 @@ class AccountsWindow:
def on_custom_host_entry1_changed(self, widget):
if self.ignore_events:
return
host = widget.get_text().decode('utf-8')
host = widget.get_text()
if self.option_changed('custom_host', host):
self.need_relogin = True
gajim.config.set_per('accounts', self.current_account, 'custom_host',
@ -2655,7 +2653,7 @@ class AccountsWindow:
def on_first_name_entry2_changed(self, widget):
if self.ignore_events:
return
name = widget.get_text().decode('utf-8')
name = widget.get_text()
if self.option_changed('zeroconf_first_name', name):
self.need_relogin = True
gajim.config.set_per('accounts', self.current_account,
@ -2664,7 +2662,7 @@ class AccountsWindow:
def on_last_name_entry2_changed(self, widget):
if self.ignore_events:
return
name = widget.get_text().decode('utf-8')
name = widget.get_text()
if self.option_changed('zeroconf_last_name', name):
self.need_relogin = True
gajim.config.set_per('accounts', self.current_account,
@ -2673,7 +2671,7 @@ class AccountsWindow:
def on_jabber_id_entry2_changed(self, widget):
if self.ignore_events:
return
id_ = widget.get_text().decode('utf-8')
id_ = widget.get_text()
if self.option_changed('zeroconf_jabber_id', id_):
self.need_relogin = True
gajim.config.set_per('accounts', self.current_account,
@ -2682,7 +2680,7 @@ class AccountsWindow:
def on_email_entry2_changed(self, widget):
if self.ignore_events:
return
email = widget.get_text().decode('utf-8')
email = widget.get_text()
if self.option_changed('zeroconf_email', email):
self.need_relogin = True
gajim.config.set_per('accounts', self.current_account,
@ -2733,7 +2731,7 @@ class FakeDataForm(Gtk.Table, object):
def get_infos(self):
for name in self.entries.keys():
self.infos[name] = self.entries[name].get_text().decode('utf-8')
self.infos[name] = self.entries[name].get_text()
return self.infos
class ServiceRegistrationWindow:
@ -2906,7 +2904,7 @@ class GroupchatConfigWindow:
def on_cell_edited(self, cell, path, new_text):
model = self.affiliation_treeview['outcast'].get_model()
new_text = new_text.decode('utf-8')
new_text = new_text
iter_ = model.get_iter(path)
model[iter_][1] = new_text
@ -2984,12 +2982,12 @@ class GroupchatConfigWindow:
iter_ = model.get_iter_first()
# add new jid
while iter_:
jid = model[iter_][0].decode('utf-8')
jid = model[iter_][0]
actual_jid_list.append(jid)
if jid not in self.start_users_dict[affiliation] or \
(affiliation == 'outcast' and 'reason' in self.start_users_dict[
affiliation][jid] and self.start_users_dict[affiliation][jid]\
['reason'] != model[iter_][1].decode('utf-8')):
['reason'] != model[iter_][1]):
users_dict[jid] = {'affiliation': affiliation}
if affiliation == 'outcast':
users_dict[jid]['reason'] = model[iter_][1].decode(
@ -3236,7 +3234,7 @@ class ManageBookmarksWindow:
# No parent, so we got an account -> add to this.
add_to = iter_
account = model[add_to][1].decode('utf-8')
account = model[add_to][1]
nick = gajim.nicks[account]
iter_ = self.treestore.append(add_to, [account, _('New Group Chat'),
'@', False, False, '', nick, 'in_and_out'])
@ -3269,8 +3267,8 @@ class ManageBookmarksWindow:
#Account data can't be changed
return
if self.server_entry.get_text().decode('utf-8') == '' or \
self.room_entry.get_text().decode('utf-8') == '':
if self.server_entry.get_text() == '' or \
self.room_entry.get_text() == '':
dialogs.ErrorDialog(_('This bookmark has invalid data'),
_('Please be sure to fill out server and room fields or remove this'
' bookmark.'))
@ -3290,34 +3288,26 @@ class ManageBookmarksWindow:
return
for account in self.treestore:
account_unicode = account[1].decode('utf-8')
gajim.connections[account_unicode].bookmarks = []
acct = account[1]
gajim.connections[acct].bookmarks = []
for bm in account.iterchildren():
# Convert True/False/None to '1' or '0'
autojoin = unicode(int(bm[3]))
minimize = unicode(int(bm[4]))
autojoin = str(int(bm[3]))
minimize = str(int(bm[4]))
name = bm[1]
if name:
name = name.decode('utf-8')
jid = bm[2]
if jid:
jid = jid.decode('utf-8')
pw = bm[5]
if pw:
pw = pw.decode('utf-8')
nick = bm[6]
if nick:
nick = nick.decode('utf-8')
# create the bookmark-dict
bmdict = { 'name': name, 'jid': jid, 'autojoin': autojoin,
'minimize': minimize, 'password': pw, 'nick': nick,
'print_status': bm[7]}
gajim.connections[account_unicode].bookmarks.append(bmdict)
gajim.connections[acct].bookmarks.append(bmdict)
gajim.connections[account_unicode].store_bookmarks()
gajim.connections[acct].store_bookmarks()
gajim.interface.roster.set_actions_menu_needs_rebuild()
self.window.destroy()
@ -3353,7 +3343,7 @@ class ManageBookmarksWindow:
# Fill in the data for childs
self.title_entry.set_text(model[iter_][1])
room_jid = model[iter_][2].decode('utf-8')
room_jid = model[iter_][2]
(room, server) = room_jid.split('@')
self.room_entry.set_text(room)
self.server_entry.set_text(server)
@ -3364,7 +3354,7 @@ class ManageBookmarksWindow:
self.minimize_checkbutton.set_sensitive(model[iter_][3])
if model[iter_][5] is not None:
password = model[iter_][5].decode('utf-8')
password = model[iter_][5]
else:
password = None
@ -3374,7 +3364,6 @@ class ManageBookmarksWindow:
self.pass_entry.set_text('')
nick = model[iter_][6]
if nick:
nick = nick.decode('utf-8')
self.nick_entry.set_text(nick)
else:
self.nick_entry.set_text('')
@ -3393,10 +3382,10 @@ class ManageBookmarksWindow:
def on_nick_entry_changed(self, widget):
(model, iter_) = self.selection.get_selected()
if iter_:
nick = self.nick_entry.get_text().decode('utf-8')
nick = self.nick_entry.get_text()
try:
nick = helpers.parse_resource(nick)
except helpers.InvalidFormat, e:
except helpers.InvalidFormat as e:
dialogs.ErrorDialog(_('Invalid nickname'),
_('Character not allowed'))
self.nick_entry.set_text(model[iter_][6])
@ -3407,16 +3396,16 @@ class ManageBookmarksWindow:
(model, iter_) = self.selection.get_selected()
if not iter_:
return
server = widget.get_text().decode('utf-8')
server = widget.get_text()
if '@' in server:
dialogs.ErrorDialog(_('Invalid server'), _('Character not allowed'))
widget.set_text(server.replace('@', ''))
room_jid = self.room_entry.get_text().decode('utf-8').strip() + '@' + \
room_jid = self.room_entry.get_text().strip() + '@' + \
server.strip()
try:
room_jid = helpers.parse_resource(room_jid)
except helpers.InvalidFormat, e:
except helpers.InvalidFormat as e:
dialogs.ErrorDialog(_('Invalid server'),
_('Character not allowed'))
self.server_entry.set_text(model[iter_][2].split('@')[1])
@ -3427,15 +3416,15 @@ class ManageBookmarksWindow:
(model, iter_) = self.selection.get_selected()
if not iter_:
return
room = widget.get_text().decode('utf-8')
room = widget.get_text()
if '@' in room:
dialogs.ErrorDialog(_('Invalid server'), _('Character not allowed'))
widget.set_text(room.replace('@', ''))
room_jid = room.strip() + '@' + \
self.server_entry.get_text().decode('utf-8').strip()
self.server_entry.get_text().strip()
try:
room_jid = helpers.parse_resource(room_jid)
except helpers.InvalidFormat, e:
except helpers.InvalidFormat as e:
dialogs.ErrorDialog(_('Invalid room'),
_('Character not allowed'))
self.room_entry.set_text(model[iter_][2].split('@')[0])
@ -3641,7 +3630,7 @@ class AccountCreationWizardWindow:
dialogs.ErrorDialog(pritext, sectext)
return
server = self.xml.get_object('server_comboboxentry').get_child().\
get_text().decode('utf-8').strip()
get_text().strip()
savepass = self.xml.get_object('save_password_checkbutton').\
get_active()
password = self.xml.get_object('password_entry').get_text().decode(
@ -3655,7 +3644,7 @@ class AccountCreationWizardWindow:
# check if jid is conform to RFC and stringprep it
try:
jid = helpers.parse_jid(jid)
except helpers.InvalidFormat, s:
except helpers.InvalidFormat as s:
pritext = _('Invalid Jabber ID')
dialogs.ErrorDialog(pritext, str(s))
return
@ -3675,7 +3664,7 @@ class AccountCreationWizardWindow:
elif cur_page == 2:
# We are creating a new account
server = self.xml.get_object('server_comboboxentry1').get_child().\
get_text().decode('utf-8')
get_text()
if not server:
dialogs.ErrorDialog(_('Invalid server'),
@ -3691,7 +3680,7 @@ class AccountCreationWizardWindow:
# Get advanced options
proxies_combobox = self.xml.get_object('proxies_combobox')
active = proxies_combobox.get_active()
proxy = proxies_combobox.get_model()[active][0].decode('utf-8')
proxy = proxies_combobox.get_model()[active][0]
if proxy == _('None'):
proxy = ''
config['proxy'] = proxy
@ -3707,7 +3696,7 @@ class AccountCreationWizardWindow:
return
config['custom_port'] = custom_port
config['custom_host'] = self.xml.get_object(
'custom_host_entry').get_text().decode('utf-8')
'custom_host_entry').get_text()
if self.xml.get_object('anonymous_checkbutton2').get_active():
self.modify = True
@ -3768,7 +3757,7 @@ class AccountCreationWizardWindow:
proxies_combobox.set_model(model)
l = gajim.config.get_per('proxies')
l.insert(0, _('None'))
for i in xrange(len(l)):
for i in range(len(l)):
model.append([l[i]])
proxies_combobox.set_active(0)
@ -4161,11 +4150,11 @@ class ManageSoundsWindow:
self.window.show_all()
def on_sounds_treemodel_row_changed(self, model, path, iter_):
sound_event = model[iter_][3].decode('utf-8')
sound_event = model[iter_][3]
gajim.config.set_per('soundevents', sound_event, 'enabled',
bool(model[path][0]))
bool(model[path][0]))
gajim.config.set_per('soundevents', sound_event, 'path',
model[iter_][2].decode('utf-8'))
model[iter_][2])
def sound_toggled_cb(self, cell, path):
model = self.sound_tree.get_model()
@ -4238,7 +4227,7 @@ class ManageSoundsWindow:
def on_cancel(widget):
self.dialog.destroy()
path_to_snd_file = model[iter_][2].decode('utf-8')
path_to_snd_file = model[iter_][2]
self.dialog = dialogs.SoundChooserDialog(path_to_snd_file, on_ok,
on_cancel)

View File

@ -39,7 +39,7 @@ import os
import tooltips
import dialogs
import locale
import Queue
import queue
import urllib
import gtkgui_helpers
@ -336,7 +336,7 @@ class ConversationTextview(GObject.GObject):
# One mark at the begining then 2 marks between each lines
size = gajim.config.get('max_conversation_lines')
size = 2 * size - 1
self.marks_queue = Queue.Queue(size)
self.marks_queue = queue.Queue(size)
self.allow_focus_out_line = True
# holds a mark at the end of --- line
@ -711,7 +711,7 @@ class ConversationTextview(GObject.GObject):
buffer_.delete(start, end)
size = gajim.config.get('max_conversation_lines')
size = 2 * size - 1
self.marks_queue = Queue.Queue(size)
self.marks_queue = queue.Queue(size)
self.focus_out_end_mark = None
self.just_cleared = True
@ -1173,7 +1173,7 @@ class ConversationTextview(GObject.GObject):
all_tags = [(ttt.lookup(t) if isinstance(t, str) else t) for t in all_tags]
buffer_.insert_with_tags(end_iter, special_text, *all_tags)
if 'url' in tags:
puny_text = puny_encode(special_text)
puny_text = puny_encode(special_text).decode('utf-8')
if not puny_text.endswith('-'):
end_iter = buffer_.get_end_iter()
buffer_.insert(end_iter, " (%s)" % puny_text)
@ -1315,10 +1315,6 @@ class ConversationTextview(GObject.GObject):
timestamp_str = helpers.from_one_line(timestamp_str)
format_ += timestamp_str
tim_format = time.strftime(format_, tim)
if locale.getpreferredencoding() not in ('KOI8-R', 'cp1251'):
# if tim_format comes as unicode because of day_str.
# we convert it to the encoding that we want (and that is utf-8)
tim_format = helpers.ensure_utf8_string(tim_format)
return tim_format
def detect_other_text_tag(self, text, kind):
@ -1372,7 +1368,7 @@ class ConversationTextview(GObject.GObject):
xhtml = xhtml.replace('/me', '<i>* %s</i>' % (name,), 1)
self.tv.display_html(xhtml.encode('utf-8'), self)
return
except Exception, e:
except Exception as e:
gajim.log.debug('Error processing xhtml' + str(e))
gajim.log.debug('with |' + xhtml + '|')

View File

@ -75,7 +75,7 @@ class DataFormWidget(Gtk.Alignment, object):
selection.set_mode(Gtk.SelectionMode.MULTIPLE)
def on_data_form_vbox_key_press_event(self, widget, event):
print 'key pressed'
print('key pressed')
def set_data_form(self, dataform):
"""
@ -113,13 +113,13 @@ class DataFormWidget(Gtk.Alignment, object):
def get_title(self):
"""
Get the title of data form, as a unicode object. If no title or no form,
returns u''. Useful for setting window title
Get the title of data form. If no title or no form,
returns ''. Useful for setting window title
"""
if self._data_form is not None:
if self._data_form.title is not None:
return self._data_form.title
return u''
return ''
title = property(get_title, None, None, 'Data form title')
@ -277,7 +277,7 @@ class DataFormWidget(Gtk.Alignment, object):
selection = self.records_treeview.get_selection()
model, rowrefs = selection.get_selected_rows()
# rowref is a list of paths
for i in xrange(len(rowrefs)):
for i in list(range(len(rowrefs))):
rowrefs[i] = Gtk.TreeRowReference(model, rowrefs[i])
# rowref is a list of row references; need to convert because we will
# modify the model, paths would change
@ -540,7 +540,7 @@ class SingleForm(Gtk.Table, object):
field)
widget.set_sensitive(readwrite)
if field.value is None:
field.value = u''
field.value = ''
widget.set_text(field.value)
else:
commonwidget=False
@ -629,7 +629,7 @@ class SingleForm(Gtk.Table, object):
return
try:
newtext = helpers.parse_jid(newtext)
except helpers.InvalidFormat, s:
except helpers.InvalidFormat as s:
dialogs.ErrorDialog(_('Invalid Jabber ID'), str(s))
return
if newtext in field.values:

View File

@ -127,7 +127,7 @@ class EditGroupsDialog:
gajim.interface.roster.draw_group(_('General'), account)
def on_add_button_clicked(self, widget):
group = self.xml.get_object('group_entry').get_text().decode('utf-8')
group = self.xml.get_object('group_entry').get_text()
if not group:
return
# Do not allow special groups
@ -137,7 +137,7 @@ class EditGroupsDialog:
model = self.treeview.get_model()
iter_ = model.get_iter_first()
while iter_:
if model.get_value(iter_, 0).decode('utf-8') == group:
if model.get_value(iter_, 0) == group:
return
iter_ = model.iter_next(iter_)
self.changes_made = True
@ -153,7 +153,7 @@ class EditGroupsDialog:
model[path][1] = True
else:
model[path][1] = not model[path][1]
group = model[path][0].decode('utf-8')
group = model[path][0]
if model[path][1]:
self.add_group(group)
else:
@ -251,7 +251,7 @@ class PassphraseDialog:
if not self.ok_handler:
return
passph = self.passphrase_entry.get_text().decode('utf-8')
passph = self.passphrase_entry.get_text()
if self.check:
checked = self.xml.get_object('save_passphrase_checkbutton').\
@ -325,8 +325,7 @@ class ChooseGPGKeyDialog:
selection = self.keys_treeview.get_selection()
(model, iter_) = selection.get_selected()
if iter_ and response == Gtk.ResponseType.OK:
keyID = [ model[iter_][0].decode('utf-8'),
model[iter_][1].decode('utf-8') ]
keyID = [ model[iter_][0], model[iter_][1] ]
else:
keyID = None
self.on_response(keyID)
@ -458,7 +457,7 @@ class ChangeActivityDialog:
"""
if self.checkbutton.get_active():
self.on_response(self.activity, self.subactivity,
self.entry.get_text().decode('utf-8'))
self.entry.get_text())
else:
self.on_response(None, None, '')
self.window.destroy()
@ -541,7 +540,7 @@ class ChangeMoodDialog:
def on_ok_button_clicked(self, widget):
'''Return mood and messsage (None if no mood selected)'''
message = self.entry.get_text().decode('utf-8')
message = self.entry.get_text()
self.on_response(self.mood, message)
self.window.destroy()
@ -713,8 +712,7 @@ class ChangeStatusMessageDialog(TimeoutDialog):
def on_dialog_response(self, dialog, response):
if response == Gtk.ResponseType.OK:
beg, end = self.message_buffer.get_bounds()
message = self.message_buffer.get_text(beg, end, True).decode('utf-8')\
.strip()
message = self.message_buffer.get_text(beg, end, True).strip()
message = helpers.remove_invalid_xml_chars(message)
msg = helpers.to_one_line(message)
if self.show:
@ -742,7 +740,7 @@ class ChangeStatusMessageDialog(TimeoutDialog):
active = widget.get_active()
if active < 0:
return None
name = model[active][0].decode('utf-8')
name = model[active][0]
self.message_buffer.set_text(self.preset_messages_dict[name][0])
self.pep_dict['activity'] = self.preset_messages_dict[name][1]
self.pep_dict['subactivity'] = self.preset_messages_dict[name][2]
@ -778,10 +776,10 @@ class ChangeStatusMessageDialog(TimeoutDialog):
status_message_to_save_as_preset = self.message_buffer.get_text(
start_iter, finish_iter, True)
def on_ok(msg_name):
msg_text = status_message_to_save_as_preset.decode('utf-8')
msg_text = status_message_to_save_as_preset
msg_text_1l = helpers.to_one_line(msg_text)
if not msg_name: # msg_name was ''
msg_name = msg_text_1l.decode('utf-8')
msg_name = msg_text_1l
def on_ok2():
self.preset_messages_dict[msg_name] = [
@ -1034,7 +1032,7 @@ class AddNewContactWindow:
self._nec_gateway_prompt_received)
def on_register_button_clicked(self, widget):
jid = self.protocol_jid_combobox.get_active_text().decode('utf-8')
jid = self.protocol_jid_combobox.get_active_text()
gajim.connections[self.account].request_register_agent_info(jid)
def on_add_new_contact_window_key_press_event(self, widget, event):
@ -1051,7 +1049,7 @@ class AddNewContactWindow:
"""
When Subscribe button is clicked
"""
jid = self.uid_entry.get_text().decode('utf-8').strip()
jid = self.uid_entry.get_text().strip()
if not jid:
return
@ -1075,7 +1073,7 @@ class AddNewContactWindow:
# check if jid is conform to RFC and stringprep it
try:
jid = helpers.parse_jid(jid)
except helpers.InvalidFormat, s:
except helpers.InvalidFormat as s:
pritext = _('Invalid User ID')
ErrorDialog(pritext, str(s))
return
@ -1091,7 +1089,7 @@ class AddNewContactWindow:
ErrorDialog(pritext, _('You cannot add yourself to your roster.'))
return
nickname = self.nickname_entry.get_text().decode('utf-8') or ''
nickname = self.nickname_entry.get_text() or ''
# get value of account combobox, if account was not specified
if not self.account:
model = self.account_combobox.get_model()
@ -1110,14 +1108,14 @@ class AddNewContactWindow:
message_buffer = self.message_textview.get_buffer()
start_iter = message_buffer.get_start_iter()
end_iter = message_buffer.get_end_iter()
message = message_buffer.get_text(start_iter, end_iter, True).decode('utf-8')
message = message_buffer.get_text(start_iter, end_iter, True)
if self.save_message_checkbutton.get_active():
msg = helpers.to_one_line(message)
gajim.config.set_per('accounts', self.account,
'subscription_request_msg', msg)
else:
message= ''
group = self.group_comboboxentry.get_child().get_text().decode('utf-8')
group = self.group_comboboxentry.get_child().get_text()
groups = []
if group:
groups = [group]
@ -1268,7 +1266,7 @@ class AboutDialog:
dlg.set_transient_for(gajim.interface.roster.window)
dlg.set_name('Gajim')
dlg.set_version(gajim.version)
s = u'Copyright © 2003-2012 Gajim Team'
s = 'Copyright © 2003-2012 Gajim Team'
dlg.set_copyright(s)
copying_file_path = self.get_path('COPYING')
if copying_file_path:
@ -1299,13 +1297,12 @@ class AboutDialog:
if thanks_file_path:
authors.append('\n' + _('THANKS:'))
text = helpers.ensure_utf8_string(open(thanks_file_path).read())
text = open(thanks_file_path).read()
text_splitted = text.split('\n')
text = '\n'.join(text_splitted[:-2]) # remove one english sentence
# and add it manually as translatable
text += helpers.ensure_utf8_string('\n%s\n' % _('Last but not '
'least, we would like to thank all the package maintainers.'
))
text += '\n%s\n' % _('Last but not least, we would like to '
'thank all the package maintainers.')
authors.append(text)
dlg.set_authors(authors)
@ -2007,7 +2004,7 @@ class InputDialog(CommonInputDialog):
self.input_entry.select_region(0, -1) # select all
def get_text(self):
return self.input_entry.get_text().decode('utf-8')
return self.input_entry.get_text()
class InputDialogCheck(InputDialog):
"""
@ -2033,7 +2030,7 @@ class InputDialogCheck(InputDialog):
def on_okbutton_clicked(self, widget):
user_input = self.get_text()
if user_input:
user_input = user_input.decode('utf-8')
user_input = user_input
self.cancel_handler = None
self.dialog.destroy()
if isinstance(self.ok_handler, tuple):
@ -2042,7 +2039,7 @@ class InputDialogCheck(InputDialog):
self.ok_handler(user_input, self.is_checked())
def get_text(self):
return self.input_entry.get_text().decode('utf-8')
return self.input_entry.get_text()
def is_checked(self):
"""
@ -2111,7 +2108,7 @@ class ChangeNickDialog(InputDialogCheck):
def on_okbutton_clicked(self, widget):
nick = self.get_text()
if nick:
nick = nick.decode('utf-8')
nick = nick
# send presence to room
try:
nick = helpers.parse_resource(nick)
@ -2163,7 +2160,7 @@ class InputTextDialog(CommonInputDialog):
def get_text(self):
start_iter, end_iter = self.input_buffer.get_bounds()
return self.input_buffer.get_text(start_iter, end_iter, True).decode('utf-8')
return self.input_buffer.get_text(start_iter, end_iter, True)
class DoubleInputDialog:
"""
@ -2208,8 +2205,8 @@ class DoubleInputDialog:
self.cancel_handler()
def on_okbutton_clicked(self, widget):
user_input1 = self.input_entry1.get_text().decode('utf-8')
user_input2 = self.input_entry2.get_text().decode('utf-8')
user_input1 = self.input_entry1.get_text()
user_input2 = self.input_entry2.get_text()
self.cancel_handler = None
self.dialog.destroy()
if not self.ok_handler:
@ -2325,13 +2322,13 @@ class JoinGroupchatWindow:
if room_jid != '' and room_jid in gajim.gc_connected[account] and\
gajim.gc_connected[account][room_jid]:
ErrorDialog(_('You are already in group chat %s') % room_jid)
raise GajimGeneralException, 'You are already in this group chat'
raise GajimGeneralException('You are already in this group chat')
if nick == '':
nick = gajim.nicks[account]
if gajim.connections[account].connected < 2:
ErrorDialog(_('You are not connected to the server'),
_('You can not join a group chat unless you are connected.'))
raise GajimGeneralException, 'You must be connected to join a groupchat'
raise GajimGeneralException('You must be connected to join a groupchat')
self.xml = gtkgui_helpers.get_gtk_builder('join_groupchat_window.ui')
@ -2464,7 +2461,7 @@ class JoinGroupchatWindow:
def on_account_combobox_changed(self, widget):
model = widget.get_model()
iter_ = widget.get_active_iter()
self.account = model[iter_][0].decode('utf-8')
self.account = model[iter_][0]
self.on_required_entry_changed(self._nickname_entry)
def _set_room_jid(self, room_jid):
@ -2477,11 +2474,11 @@ class JoinGroupchatWindow:
def on_recently_combobox_changed(self, widget):
model = widget.get_model()
iter_ = widget.get_active_iter()
room_jid = model[iter_][0].decode('utf-8')
room_jid = model[iter_][0]
self._set_room_jid(room_jid)
def on_browse_rooms_button_clicked(self, widget):
server = self.server_comboboxentry.get_child().get_text().decode('utf-8')
server = self.server_comboboxentry.get_child().get_text()
if server in gajim.interface.instances[self.account]['disco']:
gajim.interface.instances[self.account]['disco'][server].window.\
present()
@ -2517,13 +2514,13 @@ class JoinGroupchatWindow:
_('You have to choose an account from which you want to join the '
'groupchat.'))
return
nickname = self._nickname_entry.get_text().decode('utf-8')
nickname = self._nickname_entry.get_text()
row = self.server_comboboxentry.get_child().get_displayed_row()
model = self.server_comboboxentry.get_model()
server = model[row][0].decode('utf-8').strip()
server = model[row][0].strip()
room = self._room_jid_entry.get_text().decode('utf-8').strip()
room_jid = room + '@' + server
password = self._password_entry.get_text().decode('utf-8')
password = self._password_entry.get_text()
try:
nickname = helpers.parse_resource(nickname)
except Exception:
@ -2578,7 +2575,7 @@ class SynchroniseSelectAccountDialog:
if not account or gajim.connections[account].connected < 2:
ErrorDialog(_('You are not connected to the server'),
_('Without a connection, you can not synchronise your contacts.'))
raise GajimGeneralException, 'You are not connected to the server'
raise GajimGeneralException('You are not connected to the server')
self.account = account
self.xml = gtkgui_helpers.get_gtk_builder('synchronise_select_account_dialog.ui')
self.dialog = self.xml.get_object('synchronise_select_account_dialog')
@ -2623,7 +2620,7 @@ class SynchroniseSelectAccountDialog:
(model, iter_) = sel.get_selected()
if not iter_:
return
remote_account = model.get_value(iter_, 0).decode('utf-8')
remote_account = model.get_value(iter_, 0)
if gajim.connections[remote_account].connected < 2:
ErrorDialog(_('This account is not connected to the server'),
@ -2696,7 +2693,7 @@ class SynchroniseSelectContactsDialog:
while iter_:
if model[iter_][0]:
# it is selected
remote_jid = model[iter_][1].decode('utf-8')
remote_jid = model[iter_][1]
message = 'I\'m synchronizing my contacts from my %s account, could you please add this address to your contact list?' % \
gajim.get_hostname_from_account(self.remote_account)
remote_contact = gajim.contacts.get_first_contact_from_jid(
@ -2753,7 +2750,7 @@ class NewChatDialog(InputDialog):
else:
try:
jid = helpers.parse_jid(jid)
except helpers.InvalidFormat, e:
except helpers.InvalidFormat as e:
ErrorDialog(_('Invalid JID'), e[0])
return
except:
@ -2767,7 +2764,7 @@ class ChangePasswordDialog:
if not account or gajim.connections[account].connected < 2:
ErrorDialog(_('You are not connected to the server'),
_('Without a connection, you can not change your password.'))
raise GajimGeneralException, 'You are not connected to the server'
raise GajimGeneralException('You are not connected to the server')
self.account = account
self.on_response = on_response
self.xml = gtkgui_helpers.get_gtk_builder('change_password_dialog.ui')
@ -2783,11 +2780,11 @@ class ChangePasswordDialog:
dialog.destroy()
self.on_response(None)
return
password1 = self.password1_entry.get_text().decode('utf-8')
password1 = self.password1_entry.get_text()
if not password1:
ErrorDialog(_('Invalid password'), _('You must enter a password.'))
return
password2 = self.password2_entry.get_text().decode('utf-8')
password2 = self.password2_entry.get_text()
if password1 != password2:
ErrorDialog(_('Passwords do not match'),
_('The passwords typed in both fields must be identical.'))
@ -3123,7 +3120,7 @@ class SingleMessageWindow:
def update_char_counter(self, widget):
characters_no = self.message_tv_buffer.get_char_count()
self.count_chars_label.set_text(unicode(characters_no))
self.count_chars_label.set_text(characters_no)
def send_single_message(self):
if gajim.connections[self.account].connected <= 1:
@ -3139,7 +3136,7 @@ class SingleMessageWindow:
else:
sender_list.append(i[0].jid)
else:
sender_list = [self.to_entry.get_text().decode('utf-8')]
sender_list = [self.to_entry.get_text()]
for to_whom_jid in sender_list:
if to_whom_jid in self.completion_dict:
@ -3152,9 +3149,9 @@ class SingleMessageWindow:
'valid.') % to_whom_jid)
return True
subject = self.subject_entry.get_text().decode('utf-8')
subject = self.subject_entry.get_text()
begin, end = self.message_tv_buffer.get_bounds()
message = self.message_tv_buffer.get_text(begin, end, True).decode('utf-8')
message = self.message_tv_buffer.get_text(begin, end, True)
if '/announce/' in to_whom_jid:
gajim.connections[self.account].send_motd(to_whom_jid, subject,
@ -3561,14 +3558,14 @@ class RosterItemExchangeWindow:
if model[iter_][0]:
a+=1
# it is selected
#remote_jid = model[iter_][1].decode('utf-8')
#remote_jid = model[iter_][1]
message = _('%s suggested me to add you in my roster.'
% self.jid_from)
# keep same groups and same nickname
groups = model[iter_][3].split(', ')
if groups == ['']:
groups = []
jid = model[iter_][1].decode('utf-8')
jid = model[iter_][1]
if gajim.jid_is_transport(self.jid_from):
gajim.connections[self.account].automatically_added.append(
jid)
@ -3584,7 +3581,7 @@ class RosterItemExchangeWindow:
if model[iter_][0]:
a+=1
# it is selected
jid = model[iter_][1].decode('utf-8')
jid = model[iter_][1]
# keep same groups and same nickname
groups = model[iter_][3].split(', ')
if groups == ['']:
@ -3609,7 +3606,7 @@ class RosterItemExchangeWindow:
if model[iter_][0]:
a+=1
# it is selected
jid = model[iter_][1].decode('utf-8')
jid = model[iter_][1]
gajim.connections[self.account].unsubscribe(jid)
gajim.interface.roster.remove_contact(jid, self.account)
gajim.contacts.remove_jid(self.account, jid)
@ -3685,7 +3682,7 @@ class ItemArchivingPreferencesWindow:
if self.item != 'Default':
try:
item = helpers.parse_jid(item)
except helpers.InvalidFormat, s:
except helpers.InvalidFormat as s:
pritext = _('Invalid User ID')
ErrorDialog(pritext, str(s))
return
@ -4164,7 +4161,7 @@ class PrivacyListWindow:
self.active_rule = ''
else:
self.active_rule = \
self.list_of_rules_combobox.get_active_text().decode('utf-8')
self.list_of_rules_combobox.get_active_text()
if self.active_rule != '':
rule_info = self.global_rules[self.active_rule]
self.edit_order_spinbutton.set_value(int(rule_info['order']))
@ -4822,7 +4819,6 @@ class AddSpecialNotificationDialog:
if active == 1: # user selected 'choose sound'
def on_ok(widget, path_to_snd_file):
pass
#print path_to_snd_file
def on_cancel(widget):
widget.set_active(0) # go back to No Sound
@ -4954,7 +4950,7 @@ class TransformChatToMUC:
def on_invite_button_clicked(self, widget):
row = self.server_list_comboboxentry.get_child().get_displayed_row()
model = self.server_list_comboboxentry.get_model()
server = model[row][0].decode('utf-8').strip()
server = model[row][0].strip()
if server == '':
return
gajim.connections[self.account].check_unique_room_id_support(server, self)
@ -4966,7 +4962,7 @@ class TransformChatToMUC:
guests = self.guests_treeview.get_selection().get_selected_rows()
for guest in guests[1]:
iter_ = self.store.get_iter(guest)
guest_list.append(self.store[iter_][2].decode('utf-8'))
guest_list.append(self.store[iter_][2])
for guest in self.auto_jids:
guest_list.append(guest)
room_jid = obj.room_id + '@' + obj.server

View File

@ -193,7 +193,6 @@ class CacheDictionary:
def __contains__(self, key):
return key in self.cache
has_key = __contains__
_icon_cache = CacheDictionary(15)
@ -223,7 +222,7 @@ class Closure(object):
self.removeargs = removeargs
if isinstance(cb, types.MethodType):
self.meth_self = weakref.ref(cb.im_self, self._remove)
self.meth_name = cb.func_name
self.meth_name = cb.__name__
elif callable(cb):
self.meth_self = None
self.cb = weakref.ref(cb, self._remove)
@ -515,7 +514,7 @@ class ServiceDiscoveryWindow(object):
if gajim.connections[account].connected < 2:
dialogs.ErrorDialog(_('You are not connected to the server'),
_('Without a connection, you can not browse available services'))
raise RuntimeError, 'You must be connected to browse services'
raise RuntimeError('You must be connected to browse services')
# Get a ServicesCache object.
try:
@ -800,20 +799,20 @@ _('This type of service does not contain any items to browse.'))
def on_address_comboboxentry_changed(self, widget):
if self.address_comboboxentry.get_active() != -1:
# user selected one of the entries so do auto-visit
jid = self.address_comboboxentry.get_child().get_text().decode('utf-8')
jid = self.address_comboboxentry.get_child().get_text()
try:
jid = helpers.parse_jid(jid)
except helpers.InvalidFormat, s:
except helpers.InvalidFormat as s:
pritext = _('Invalid Server Name')
dialogs.ErrorDialog(pritext, str(s))
return
self.travel(jid, '')
def on_go_button_clicked(self, widget):
jid = self.address_comboboxentry.get_child().get_text().decode('utf-8')
jid = self.address_comboboxentry.get_child().get_text()
try:
jid = helpers.parse_jid(jid)
except helpers.InvalidFormat, s:
except helpers.InvalidFormat as s:
pritext = _('Invalid Server Name')
dialogs.ErrorDialog(pritext, str(s))
return
@ -998,9 +997,9 @@ class AgentBrowser:
model, iter_ = self.window.services_treeview.get_selection().get_selected()
if not iter_:
return
jid = model[iter_][0].decode('utf-8')
jid = model[iter_][0]
if jid:
node = model[iter_][1].decode('utf-8')
node = model[iter_][1]
self.window.open(jid, node)
def update_actions(self):
@ -1012,8 +1011,8 @@ class AgentBrowser:
model, iter_ = self.window.services_treeview.get_selection().get_selected()
if not iter_:
return
jid = model[iter_][0].decode('utf-8')
node = model[iter_][1].decode('utf-8')
jid = model[iter_][0]
node = model[iter_][1]
if jid:
self.cache.get_info(jid, node, self._update_actions, nofetch = True)
@ -1035,8 +1034,8 @@ class AgentBrowser:
model, iter_ = self.window.services_treeview.get_selection().get_selected()
if not iter_:
return
jid = model[iter_][0].decode('utf-8')
node = model[iter_][1].decode('utf-8')
jid = model[iter_][0]
node = model[iter_][1]
if jid:
self.cache.get_info(jid, node, self._default_action, nofetch = True)
@ -1077,8 +1076,8 @@ class AgentBrowser:
"""
iter_ = self.model.get_iter_first()
while iter_:
cjid = self.model.get_value(iter_, 0).decode('utf-8')
cnode = self.model.get_value(iter_, 1).decode('utf-8')
cjid = self.model.get_value(iter_, 0)
cnode = self.model.get_value(iter_, 1)
if jid == cjid and node == cnode:
break
iter_ = self.model.iter_next(iter_)
@ -1226,10 +1225,10 @@ class ToplevelAgentBrowser(AgentBrowser):
# These can be None, apparently
descr1 = model.get_value(iter1, 3)
if descr1:
descr1 = descr1.decode('utf-8')
descr1 = descr1
descr2 = model.get_value(iter2, 3)
if descr2:
descr2 = descr2.decode('utf-8')
descr2 = descr2
# Compare strings
return cmp(descr1, descr2)
return statecmp
@ -1402,7 +1401,7 @@ class ToplevelAgentBrowser(AgentBrowser):
model, iter_ = self.window.services_treeview.get_selection().get_selected()
if not iter_:
return
service = model[iter_][0].decode('utf-8')
service = model[iter_][0]
if service in gajim.interface.instances[self.account]['search']:
gajim.interface.instances[self.account]['search'][service].window.\
present()
@ -1428,8 +1427,8 @@ class ToplevelAgentBrowser(AgentBrowser):
model, iter_ = self.window.services_treeview.get_selection().get_selected()
if not iter_:
return
service = model[iter_][0].decode('utf-8')
node = model[iter_][1].decode('utf-8')
service = model[iter_][0]
node = model[iter_][1]
adhoc_commands.CommandWindow(self.account, service, commandnode=node)
def on_register_button_clicked(self, widget = None):
@ -1440,7 +1439,7 @@ class ToplevelAgentBrowser(AgentBrowser):
model, iter_ = self.window.services_treeview.get_selection().get_selected()
if not iter_:
return
jid = model[iter_][0].decode('utf-8')
jid = model[iter_][0]
if jid:
gajim.connections[self.account].request_register_agent_info(jid)
self.window.destroy(chain = True)
@ -1453,7 +1452,7 @@ class ToplevelAgentBrowser(AgentBrowser):
model, iter_ = self.window.services_treeview.get_selection().get_selected()
if not iter_:
return
service = model[iter_][0].decode('utf-8')
service = model[iter_][0]
if 'join_gc' not in gajim.interface.instances[self.account]:
try:
dialogs.JoinGroupchatWindow(self.account, service)
@ -1486,7 +1485,7 @@ class ToplevelAgentBrowser(AgentBrowser):
self.register_button.set_sensitive(True)
# Guess what kind of service we're dealing with
if self.browse_button:
jid = model[iter_][0].decode('utf-8')
jid = model[iter_][0]
type_ = gajim.get_transport_name_from_jid(jid,
use_config_setting = False)
if type_:
@ -1614,7 +1613,7 @@ class ToplevelAgentBrowser(AgentBrowser):
cat = self._friendly_category(cat, type_)[0]
iter_ = self.model.get_iter_first()
while iter_:
if self.model.get_value(iter_, 3).decode('utf-8') == cat:
if self.model.get_value(iter_, 3) == cat:
break
iter_ = self.model.iter_next(iter_)
if iter_:
@ -1627,8 +1626,8 @@ class ToplevelAgentBrowser(AgentBrowser):
while cat_iter and not iter_:
iter_ = self.model.iter_children(cat_iter)
while iter_:
cjid = self.model.get_value(iter_, 0).decode('utf-8')
cnode = self.model.get_value(iter_, 1).decode('utf-8')
cjid = self.model.get_value(iter_, 0)
cnode = self.model.get_value(iter_, 1)
if jid == cjid and node == cnode:
break
iter_ = self.model.iter_next(iter_)
@ -1699,7 +1698,7 @@ class ToplevelAgentBrowser(AgentBrowser):
# Check if we have to move categories
old_cat_iter = self.model.iter_parent(iter_)
old_cat = self.model.get_value(old_cat_iter, 3).decode('utf-8')
old_cat = self.model.get_value(old_cat_iter, 3)
if self.model.get_value(old_cat_iter, 3) == cat:
# Already in the right category, just update
self.model[iter_][2] = pix
@ -1819,7 +1818,7 @@ class MucBrowser(AgentBrowser):
if not iter:
return
name = gajim.config.get_per('accounts', self.account, 'name')
room_jid = model[iter][0].decode('utf-8')
room_jid = model[iter][0]
bm = {
'name': room_jid.split('@')[0],
'jid': room_jid,
@ -1853,7 +1852,7 @@ class MucBrowser(AgentBrowser):
model, iter_ = self.window.services_treeview.get_selection().get_selected()
if not iter_:
return
service = model[iter_][0].decode('utf-8')
service = model[iter_][0]
if 'join_gc' not in gajim.interface.instances[self.account]:
try:
dialogs.JoinGroupchatWindow(self.account, service)
@ -1926,8 +1925,8 @@ class MucBrowser(AgentBrowser):
pass
while iter_ and self.model.get_path(iter_) != end:
if not self.model.get_value(iter_, 6):
jid = self.model.get_value(iter_, 0).decode('utf-8')
node = self.model.get_value(iter_, 1).decode('utf-8')
jid = self.model.get_value(iter_, 0)
node = self.model.get_value(iter_, 1)
self.cache.get_info(jid, node, self._agent_info)
self._fetch_source = True
return

View File

@ -149,7 +149,7 @@ class FeaturesWindow:
if not rows:
return
path = rows[0]
feature = self.model[path][0].decode('utf-8')
feature = self.model[path][0]
text = self.features[feature][1] + '\n'
if os.name == 'nt':
text = text + self.features[feature][3]

View File

@ -153,12 +153,12 @@ class FileTransfersWindow:
for file_props in allfp:
if file_props.type_ == 's' and file_props.tt_account == account:
# 'account' is the sender
receiver_jid = unicode(file_props.receiver).split('/')[0]
receiver_jid = file_props.receiver.split('/')[0]
if jid == receiver_jid and not is_transfer_stopped(file_props):
active_transfers[0].append(file_props)
elif file_props.type_ == 'r' and file_props.tt_account == account:
# 'account' is the recipient
sender_jid = unicode(file_props.sender).split('/')[0]
sender_jid = file_props.sender.split('/')[0]
if jid == sender_jid and not is_transfer_stopped(file_props):
active_transfers[1].append(file_props)
else:
@ -188,7 +188,7 @@ class FileTransfersWindow:
sectext += '\n\t' + _('Size: %s') % \
helpers.convert_bytes(file_props.size)
if file_props.type_ == 'r':
jid = unicode(file_props.sender).split('/')[0]
jid = file_props.sender.split('/')[0]
sender_name = gajim.contacts.get_first_contact_from_jid(
file_props.tt_account, jid).get_shown_name()
sender = sender_name
@ -198,7 +198,7 @@ class FileTransfersWindow:
sectext += '\n\t' + _('Sender: %s') % sender
sectext += '\n\t' + _('Recipient: ')
if file_props.type_ == 's':
jid = unicode(file_props.receiver).split('/')[0]
jid = file_props.receiver.split('/')[0]
receiver_name = gajim.contacts.get_first_contact_from_jid(
file_props.tt_account, jid).get_shown_name()
recipient = receiver_name
@ -484,7 +484,7 @@ class FileTransfersWindow:
iter_ = self.get_iter_by_sid(file_props.type_, file_props.sid)
if iter_ is None:
return
self.model[iter_][C_SID].decode('utf-8')
self.model[iter_][C_SID]
if status == 'stop':
file_props.stopped = True
elif status == 'ok':
@ -533,7 +533,7 @@ class FileTransfersWindow:
_str += ' '
if percent < 10:
_str += ' '
_str += unicode(percent) + '% \n'
_str += str(percent) + '% \n'
return _str
def _format_time(self, _time):
@ -585,7 +585,7 @@ class FileTransfersWindow:
other = file_props.sender
else: # we send a file
other = file_props.receiver
if isinstance(other, unicode):
if isinstance(other, str):
jid = gajim.get_jid_without_resource(other)
else: # It's a Contact instance
jid = other.jid
@ -677,7 +677,7 @@ class FileTransfersWindow:
"""
iter_ = self.model.get_iter_first()
while iter_:
if typ + sid == self.model[iter_][C_SID].decode('utf-8'):
if typ + sid == self.model[iter_][C_SID]:
return iter_
iter_ = self.model.iter_next(iter_)
@ -713,7 +713,7 @@ class FileTransfersWindow:
file_props.type_ = 's'
file_props.desc = file_desc
file_props.elapsed_time = 0
file_props.size = unicode(stat[6])
file_props.size = str(stat[6])
file_props.sender = account
file_props.receiver = contact
file_props.tt_account = account
@ -769,7 +769,7 @@ class FileTransfersWindow:
except Exception:
self.tooltip.hide_tooltip()
return
sid = self.model[iter_][C_SID].decode('utf-8')
sid = self.model[iter_][C_SID]
file_props = FilesProp.getFilePropByType(sid[0], sid[1:])
if file_props is not None:
if self.tooltip.timeout == 0 or self.tooltip.id != props[0]:
@ -824,7 +824,7 @@ class FileTransfersWindow:
self.set_all_insensitive()
return
current_iter = self.model.get_iter(path)
sid = self.model[current_iter][C_SID].decode('utf-8')
sid = self.model[current_iter][C_SID]
file_props = FilesProp.getFilePropByType(sid[0], sid[1:])
self.remove_menuitem.set_sensitive(is_row_selected)
self.open_folder_menuitem.set_sensitive(is_row_selected)
@ -882,7 +882,7 @@ class FileTransfersWindow:
i = len(self.model) - 1
while i >= 0:
iter_ = self.model.get_iter((i))
sid = self.model[iter_][C_SID].decode('utf-8')
sid = self.model[iter_][C_SID]
file_props = FilesProp.getFilePropByType(sid[0], sid[1:])
if is_transfer_stopped(file_props):
self._remove_transfer(iter_, sid, file_props)
@ -917,7 +917,7 @@ class FileTransfersWindow:
if selected is None or selected[1] is None:
return
s_iter = selected[1]
sid = self.model[s_iter][C_SID].decode('utf-8')
sid = self.model[s_iter][C_SID]
file_props = FilesProp.getFilePropByType(sid[0], sid[1:])
if is_transfer_paused(file_props):
file_props.last_time = time.time()
@ -939,7 +939,7 @@ class FileTransfersWindow:
if selected is None or selected[1] is None:
return
s_iter = selected[1]
sid = self.model[s_iter][C_SID].decode('utf-8')
sid = self.model[s_iter][C_SID]
file_props = FilesProp.getFilePropByType(sid[0], sid[1:])
account = file_props.tt_account
if account not in gajim.connections:
@ -958,7 +958,7 @@ class FileTransfersWindow:
# as it was before setting the timeout
if props and self.tooltip.id == props[0]:
iter_ = self.model.get_iter(props[0])
sid = self.model[iter_][C_SID].decode('utf-8')
sid = self.model[iter_][C_SID]
file_props = FilesProp.getFilePropByType(sid[0], sid[1:])
# bounding rectangle of coordinates for the cell within the treeview
rect = self.tree.get_cell_area(props[0], props[1])
@ -1046,7 +1046,7 @@ class FileTransfersWindow:
if not selected or not selected[1]:
return
s_iter = selected[1]
sid = self.model[s_iter][C_SID].decode('utf-8')
sid = self.model[s_iter][C_SID]
file_props = FilesProp.getFilePropByType(sid[0], sid[1:])
if not file_props.file_name:
return
@ -1068,7 +1068,7 @@ class FileTransfersWindow:
if not selected or not selected[1]:
return
s_iter = selected[1]
sid = self.model[s_iter][C_SID].decode('utf-8')
sid = self.model[s_iter][C_SID]
file_props = FilesProp.getFilePropByType(sid[0], sid[1:])
self._remove_transfer(s_iter, sid, file_props)
self.set_all_insensitive()

View File

@ -42,7 +42,7 @@ except Exception:
def send_error(error_message):
'''Writes error message to stderr and exits'''
print >> sys.stderr, error_message.encode(PREFERRED_ENCODING)
print(error_message, file=sys.stderr)
sys.exit(1)
try:
@ -52,7 +52,7 @@ try:
# test if dbus-x11 is installed
bus = dbus.SessionBus()
except Exception:
print _('D-Bus is not present on this machine or python module is missing')
print(_('D-Bus is not present on this machine or python module is missing'))
sys.exit(1)
OBJ_PATH = '/org/gajim/dbus/RemoteObject'
@ -310,14 +310,15 @@ class GajimRemote:
self.command = sys.argv[1]
if self.command == 'help':
if self.argv_len == 3:
print self.help_on_command(sys.argv[2]).encode(PREFERRED_ENCODING)
print(self.help_on_command(sys.argv[2]).encode(
PREFERRED_ENCODING))
else:
print self.compose_help().encode(PREFERRED_ENCODING)
print(self.compose_help().encode(PREFERRED_ENCODING))
sys.exit(0)
if self.command == 'handle_uri':
self.handle_uri()
if self.command == 'check_gajim_running':
print self.check_gajim_running()
print(self.check_gajim_running())
sys.exit(0)
self.init_connection()
self.check_arguments()
@ -353,28 +354,22 @@ class GajimRemote:
elif self.command == 'list_accounts':
if isinstance(res, list):
for account in res:
if isinstance(account, unicode):
print account.encode(PREFERRED_ENCODING)
else:
print account
print(account)
elif self.command == 'account_info':
if res:
print self.print_info(0, res, True)
print(self.print_info(0, res, True))
elif self.command == 'list_contacts':
for account_dict in res:
print self.print_info(0, account_dict, True)
print(self.print_info(0, account_dict, True))
elif self.command == 'prefs_list':
pref_keys = sorted(res.keys())
for pref_key in pref_keys:
result = '%s = %s' % (pref_key, res[pref_key])
if isinstance(result, unicode):
print result.encode(PREFERRED_ENCODING)
else:
print result
print(result)
elif self.command == 'contact_info':
print self.print_info(0, res, True)
print(self.print_info(0, res, True))
elif res:
print unicode(res).encode(PREFERRED_ENCODING)
print(res)
def check_gajim_running(self):
if not self.sbus:
@ -469,7 +464,7 @@ class GajimRemote:
ret_str +='\t'
elif isinstance(val, int):
ret_str +='\t' + str(val)
elif isinstance(val, (str, unicode)):
elif isinstance(val, str):
ret_str +='\t' + val
elif isinstance(val, (list, tuple)):
res = ''
@ -484,7 +479,7 @@ class GajimRemote:
for key in prop_dict.keys():
val = prop_dict[key]
spacing = ' ' * level * 4
if isinstance(val, (unicode, int, str)):
if isinstance(val, (int, str)):
if val is not None:
val = val.strip()
ret_str += '%s%-10s: %s\n' % (spacing, key, val)

View File

@ -42,7 +42,7 @@ import warnings
if os.name == 'nt':
log_path = os.path.join(os.environ['APPDATA'], 'Gajim')
if not os.path.exists(log_path):
os.mkdir(log_path, 0700)
os.mkdir(log_path, 0o700)
log_file = os.path.join(log_path, 'gajim.log')
fout = open(log_file, 'a')
sys.stdout = fout
@ -65,7 +65,7 @@ if os.name == 'nt':
try:
import nbxmpp
except ImportError:
print 'Gajim needs python-nbxmpp to run. Quiting...'
print('Gajim needs python-nbxmpp to run. Quiting...')
sys.exit()
#from common import demandimport
@ -84,7 +84,7 @@ if os.name == 'nt':
os.environ['LANG'] = lang
gettext.bindtextdomain(APP, DIR)
gettext.textdomain(APP)
gettext.install(APP, DIR, unicode=True)
gettext.install(APP, DIR)
locale.setlocale(locale.LC_ALL, '')
import ctypes
@ -131,15 +131,15 @@ def parseOpts():
longargs += ' class= name= screen= gtk-module= sync g-fatal-warnings'
longargs += ' sm-client-id= sm-client-state-file= sm-disable'
opts = getopt.getopt(sys.argv[1:], shortargs, longargs.split())[0]
except getopt.error, msg1:
print msg1
print 'for help use --help'
except getopt.error as msg1:
print(msg1)
print('for help use --help')
sys.exit(2)
for o, a in opts:
if o in ('-h', '--help'):
print 'gajim [--help] [--quiet] [--verbose] ' + \
print('gajim [--help] [--quiet] [--verbose] ' + \
'[--loglevel subsystem=level[,subsystem=level[...]]] ' + \
'[--profile name] [--config-path]'
'[--profile name] [--config-path]')
sys.exit()
elif o in ('-q', '--quiet'):
logging_helpers.set_quiet()
@ -155,12 +155,8 @@ def parseOpts():
import locale
profile, config_path = parseOpts()
if config_path:
config_path = unicode(config_path, locale.getpreferredencoding())
del parseOpts
profile = unicode(profile, locale.getpreferredencoding())
import common.configpaths
common.configpaths.gajimpaths.init(config_path)
del config_path
@ -182,7 +178,7 @@ if os.name == 'nt':
if self._file is None and self._error is None:
try:
self._file = open(fname, 'a')
except Exception, details:
except Exception as details:
self._error = details
if self._file is not None:
self._file.write(text)
@ -200,11 +196,11 @@ try:
GObject.set_prgname('gajim')
from gi.repository import Gtk
from gi.repository import Gdk
except Warning, msg2:
except Warning as msg2:
if str(msg2) == 'could not open display':
print >> sys.stderr, _('Gajim needs X server to run. Quiting...')
print(_('Gajim needs X server to run. Quiting...'), file=sys.stderr)
else:
print >> sys.stderr, _('importing PyGTK failed: %s') % str(msg2)
print(_('importing PyGTK failed: %s') % str(msg2), file=sys.stderr)
sys.exit()
warnings.resetwarnings()
@ -223,6 +219,10 @@ except exceptions.DatabaseMalformed:
'http://trac.gajim.org/wiki/DatabaseBackup) or remove it (all history '
'will be lost).') % common.logger.LOG_DB_PATH
else:
from common import logger
gajim.logger = logger.Logger()
from common import caps_cache
caps_cache.initialize(gajim.logger)
from common import dbus_support
if dbus_support.supported:
from music_track_listener import MusicTrackListener
@ -357,7 +357,7 @@ def pid_alive():
try:
f1 = open('/proc/%d/cmdline'% pid)
except IOError, e1:
except IOError as e1:
if e1.errno == errno.ENOENT:
return False # file/pid does not exist
raise
@ -419,7 +419,7 @@ try:
f2 = open(pid_filename, 'w')
f2.write(str(os.getpid()))
f2.close()
except IOError, e2:
except IOError as e2:
dlg = dialogs.ErrorDialog(_('Disk Write Error'), str(e2))
dlg.run()
dlg.destroy()
@ -464,4 +464,4 @@ if __name__ == '__main__':
if os.name != 'nt':
Gdk.threads_leave()
except KeyboardInterrupt:
print >> sys.stderr, 'KeyboardInterrupt'
print('KeyboardInterrupt', file=sys.stderr)

View File

@ -89,8 +89,7 @@ class GajimThemesWindow:
def on_theme_cell_edited(self, cell, row, new_name):
model = self.themes_tree.get_model()
iter_ = model.get_iter_from_string(row)
old_name = model.get_value(iter_, 0).decode('utf-8')
new_name = new_name.decode('utf-8')
old_name = model.get_value(iter_, 0)
if old_name == new_name:
return
if old_name == 'default':
@ -150,7 +149,7 @@ class GajimThemesWindow:
self.theme_options_vbox.set_sensitive(False)
self.theme_options_table.set_sensitive(False)
return
self.current_theme = model.get_value(iter_, 0).decode('utf-8')
self.current_theme = model.get_value(iter_, 0)
self.current_theme = self.current_theme.replace(' ', '_')
self.set_theme_options(self.current_theme)
if self.current_theme == 'default':
@ -169,10 +168,10 @@ class GajimThemesWindow:
# don't confuse translators
theme_name = _('theme name')
theme_name_ns = theme_name.replace(' ', '_')
while theme_name_ns + unicode(i) in gajim.config.get_per('themes'):
while theme_name_ns + str(i) in gajim.config.get_per('themes'):
i += 1
model.set_value(iter_, 0, theme_name + unicode(i))
gajim.config.add_per('themes', theme_name_ns + unicode(i))
model.set_value(iter_, 0, theme_name + str(i))
gajim.config.add_per('themes', theme_name_ns + str(i))
self.themes_tree.get_selection().select_iter(iter_)
col = self.themes_tree.get_column(0)
path = model.get_path(iter_)

View File

@ -364,7 +364,7 @@ class GroupchatControl(ChatControlBase):
self.handlers[id_] = widget
self.room_jid = self.contact.jid
self.nick = contact.name.decode('utf-8')
self.nick = contact.name
self.new_nick = ''
self.name = ''
for bm in gajim.connections[self.account].bookmarks:
@ -528,8 +528,6 @@ class GroupchatControl(ChatControlBase):
nick2 = model[iter2][C_NICK]
if not nick1 or not nick2:
return 0
nick1 = nick1.decode('utf-8')
nick2 = nick2.decode('utf-8')
if type1 == 'role':
return locale.strcoll(nick1, nick2)
if type1 == 'contact':
@ -632,7 +630,7 @@ class GroupchatControl(ChatControlBase):
"""
# Get the room_jid from treeview
for contact in self.iter_contact_rows():
nick = contact[C_NICK].decode('utf-8')
nick = contact[C_NICK]
self.draw_contact(nick)
def on_list_treeview_selection_changed(self, selection):
@ -644,7 +642,7 @@ class GroupchatControl(ChatControlBase):
self._last_selected_contact = None
return
contact = model[selected_iter]
nick = contact[C_NICK].decode('utf-8')
nick = contact[C_NICK]
self._last_selected_contact = nick
if contact[C_TYPE] != 'contact':
return
@ -690,7 +688,7 @@ class GroupchatControl(ChatControlBase):
if num_unread == 1:
unread = '*'
elif num_unread > 1:
unread = '[' + unicode(num_unread) + ']'
unread = '[' + str(num_unread) + ']'
label_str = unread + label_str
return (label_str, color)
@ -1043,7 +1041,7 @@ class GroupchatControl(ChatControlBase):
while role_iter:
user_iter = self.model.iter_children(role_iter)
while user_iter:
if nick == self.model[user_iter][C_NICK].decode('utf-8'):
if nick == self.model[user_iter][C_NICK]:
return user_iter
else:
user_iter = self.model.iter_next(user_iter)
@ -1051,9 +1049,7 @@ class GroupchatControl(ChatControlBase):
return None
def print_old_conversation(self, text, contact='', tim=None, xhtml = None,
displaymarking=None):
if isinstance(text, str):
text = unicode(text, 'utf-8')
displaymarking=None):
if contact:
if contact == self.nick: # it's us
kind = 'outgoing'
@ -1079,8 +1075,6 @@ class GroupchatControl(ChatControlBase):
(contact = 'info' in such a case).
If contact is not set: it's a message from the server or help.
"""
if isinstance(text, str):
text = unicode(text, 'utf-8')
other_tags_for_name = []
other_tags_for_text = []
if contact:
@ -1380,7 +1374,7 @@ class GroupchatControl(ChatControlBase):
contact in a room
"""
if nick is None:
nick = model[iter_][C_NICK].decode('utf-8')
nick = model[iter_][C_NICK]
ctrl = self._start_private_message(nick)
if ctrl and msg:
@ -1833,7 +1827,7 @@ class GroupchatControl(ChatControlBase):
def get_role_iter(self, role):
role_iter = self.model.get_iter_first()
while role_iter:
role_name = self.model[role_iter][C_NICK].decode('utf-8')
role_name = self.model[role_iter][C_NICK]
if role == role_name:
return role_iter
role_iter = self.model.iter_next(role_iter)
@ -2138,7 +2132,7 @@ class GroupchatControl(ChatControlBase):
type_ = model[iter_][2]
if type_ != 'contact': # source is not a contact
return
contact_jid = data.decode('utf-8')
contact_jid = data
gajim.connections[self.account].send_invite(self.room_jid, contact_jid)
self.print_conversation(_('%(jid)s has been invited in this room') % {
'jid': contact_jid}, graphics=False)
@ -2203,7 +2197,7 @@ class GroupchatControl(ChatControlBase):
self.nick_hits = [] # clear the hit list
list_nick = gajim.contacts.get_nick_list(self.account,
self.room_jid)
list_nick.sort(key=unicode.lower) # case-insensitive sort
list_nick.sort(key=str.lower) # case-insensitive sort
if begin == '':
# empty message, show lasts nicks that highlighted us first
for nick in self.attention_list:
@ -2312,7 +2306,7 @@ class GroupchatControl(ChatControlBase):
"""
Make contact's popup menu
"""
nick = self.model[iter_][C_NICK].decode('utf-8')
nick = self.model[iter_][C_NICK]
c = gajim.contacts.get_gc_contact(self.account, self.room_jid, nick)
fjid = self.room_jid + '/' + nick
jid = c.jid
@ -2479,7 +2473,7 @@ class GroupchatControl(ChatControlBase):
else:
widget.expand_row(path, False)
else: # We want to send a private message
nick = self.model[path][C_NICK].decode('utf-8')
nick = self.model[path][C_NICK]
self._start_private_message(nick)
def on_list_treeview_row_activated(self, widget, path, col=0):
@ -2512,7 +2506,7 @@ class GroupchatControl(ChatControlBase):
widget.get_selection().select_path(path)
iter_ = self.model.get_iter(path)
if len(path) == 2:
nick = self.model[iter_][C_NICK].decode('utf-8')
nick = self.model[iter_][C_NICK]
self._start_private_message(nick)
return True
@ -2522,7 +2516,7 @@ class GroupchatControl(ChatControlBase):
return True
else:
iter_ = self.model.get_iter(path)
nick = self.model[iter_][C_NICK].decode('utf-8')
nick = self.model[iter_][C_NICK]
if not nick in gajim.contacts.get_nick_list(self.account,
self.room_jid):
# it's a group
@ -2565,13 +2559,13 @@ class GroupchatControl(ChatControlBase):
except Exception:
self.tooltip.hide_tooltip()
return
typ = self.model[iter_][C_TYPE].decode('utf-8')
typ = self.model[iter_][C_TYPE]
if typ == 'contact':
account = self.account
if self.tooltip.timeout == 0 or self.tooltip.id != props[0]:
self.tooltip.id = row
nick = self.model[iter_][C_NICK].decode('utf-8')
nick = self.model[iter_][C_NICK]
self.tooltip.timeout = GObject.timeout_add(500,
self.show_tooltip, gajim.contacts.get_gc_contact(
account, self.room_jid, nick))
@ -2708,8 +2702,8 @@ class GroupchatControl(ChatControlBase):
connection = gajim.connections[self.account]
if fjid in connection.blocked_contacts:
return
new_rule = {'order': u'1', 'type': u'jid', 'action': u'deny',
'value' : fjid, 'child': [u'message', u'iq', u'presence-out']}
new_rule = {'order': '1', 'type': 'jid', 'action': 'deny',
'value' : fjid, 'child': ['message', 'iq', 'presence-out']}
connection.blocked_list.append(new_rule)
connection.blocked_contacts.append(fjid)
self.draw_contact(nick)

View File

@ -29,9 +29,9 @@ from gi.repository import Gtk
from gi.repository import Gdk
from gi.repository import Pango
from common import i18n # installs _() function
import dialogs
from dialogs import HigDialog
from cStringIO import StringIO
from io import StringIO
from common import helpers
_exception_in_progress = threading.Lock()
@ -43,7 +43,7 @@ def _info(type_, value, tb):
_excepthook_save(type_, value, tb)
return
dialog = dialogs.HigDialog(None, Gtk.MessageType.WARNING, Gtk.ButtonsType.NONE,
dialog = HigDialog(None, Gtk.MessageType.WARNING, Gtk.ButtonsType.NONE,
_('A programming error has been detected'),
_('It probably is not fatal, but should be reported '
'to the developers nonetheless.'))

View File

@ -41,6 +41,7 @@ log = logging.getLogger('gajim.gtkgui_helpers')
from common import i18n
from common import gajim
from common import pep
gtk_icon_theme = Gtk.IconTheme.get_default()
gtk_icon_theme.append_search_path(gajim.ICONS_DIR)
@ -48,7 +49,7 @@ gtk_icon_theme.append_search_path(gajim.ICONS_DIR)
def get_icon_pixmap(icon_name, size=16):
try:
return gtk_icon_theme.load_icon(icon_name, size, 0)
except GObject.GError, e:
except GObject.GError as e:
log.error('Unable to load icon %s: %s' % (icon_name, str(e)))
def get_icon_path(icon_name, size=16):
@ -59,7 +60,7 @@ def get_icon_path(icon_name, size=16):
return ""
else:
return icon_info.get_filename()
except GObject.GError, e:
except GObject.GError as e:
log.error("Unable to find icon %s: %s" % (icon_name, str(e)))
import vcard
@ -195,11 +196,11 @@ def get_default_font():
for line in open(xfce_config_file):
if line.find('name="Gtk/FontName"') != -1:
start = line.find('value="') + 7
return line[start:line.find('"', start)].decode('utf-8')
return line[start:line.find('"', start)]
except Exception:
#we talk about file
print >> sys.stderr, _('Error: cannot open %s for reading') % \
xfce_config_file
print(_('Error: cannot open %s for reading') % xfce_config_file,
file=sys.stderr)
elif os.path.exists(kde_config_file):
try:
@ -211,11 +212,11 @@ def get_default_font():
font_name = values[0]
font_size = values[1]
font_string = '%s %s' % (font_name, font_size) # Verdana 9
return font_string.decode('utf-8')
return font_string
except Exception:
#we talk about file
print >> sys.stderr, _('Error: cannot open %s for reading') % \
kde_config_file
print(_('Error: cannot open %s for reading') % kde_config_file,
file=sys.stderr)
return None
@ -316,7 +317,7 @@ class HashDigest:
def __str__(self):
prettydigest = ''
for i in xrange(0, len(self.digest), 2):
for i in list(range(0, len(self.digest), 2)):
prettydigest += self.digest[i:i + 2] + ':'
return prettydigest[:-1]
@ -342,11 +343,11 @@ def parse_server_xml(path_to_file):
xml.sax.parse(path_to_file, handler)
return handler.servers
# handle exception if unable to open file
except IOError, message:
print >> sys.stderr, _('Error reading file:'), message
except IOError as message:
print(_('Error reading file:') + message, file=sys.stderr)
# handle exception parsing file
except xml.sax.SAXParseException, message:
print >> sys.stderr, _('Error parsing file:'), message
except xml.sax.SAXParseException as message:
print(_('Error parsing file:') + message, file=sys.stderr)
def set_unset_urgency_hint(window, unread_messages_no):
"""
@ -384,12 +385,12 @@ def get_abspath_for_script(scriptname, want_type = False):
script += '\nexec python -OOt gajim.py $0 $@\n'
f.write(script)
f.close()
os.chmod(path_to_script, 0700)
os.chmod(path_to_script, 0o700)
except OSError: # do not traceback (could be a permission problem)
#we talk about a file here
s = _('Could not write to %s. Session Management support will '
'not work') % path_to_script
print >> sys.stderr, s
print(s, file=sys.stderr)
else: # normal user (not svn user)
type_ = 'install'
@ -607,7 +608,7 @@ def get_avatar_pixbuf_from_cache(fjid, use_local=True):
if not os.path.isfile(path):
return 'ask'
vcard_dict = gajim.connections.values()[0].get_cached_vcard(fjid,
vcard_dict = list(gajim.connections.values())[0].get_cached_vcard(fjid,
is_groupchat_contact)
if not vcard_dict: # This can happen if cached vcard is too old
return 'ask'
@ -645,28 +646,6 @@ def make_pixbuf_grayscale(pixbuf):
pixbuf.saturate_and_pixelate(pixbuf2, 0.0, False)
return pixbuf2
def get_path_to_generic_or_avatar(generic, jid = None, suffix = None):
"""
Choose between avatar image and default image
Returns full path to the avatar image if it exists, otherwise returns full
path to the image. generic must be with extension and suffix without
"""
if jid:
# we want an avatar
puny_jid = helpers.sanitize_filename(jid)
path_to_file = os.path.join(gajim.AVATAR_PATH, puny_jid) + suffix
path_to_local_file = path_to_file + '_local'
for extension in ('.png', '.jpeg'):
path_to_local_file_full = path_to_local_file + extension
if os.path.exists(path_to_local_file_full):
return path_to_local_file_full
for extension in ('.png', '.jpeg'):
path_to_file_full = path_to_file + extension
if os.path.exists(path_to_file_full):
return path_to_file_full
return os.path.abspath(generic)
def decode_filechooser_file_paths(file_paths):
"""
Decode as UTF-8 under Windows and ask sys.getfilesystemencoding() in POSIX
@ -684,7 +663,7 @@ def decode_filechooser_file_paths(file_paths):
file_path = file_path.decode(sys.getfilesystemencoding())
except Exception:
try:
file_path = file_path.decode('utf-8')
file_path = file_path
except Exception:
pass
file_paths_list.append(file_path)
@ -829,7 +808,7 @@ def on_avatar_save_as_menuitem_activate(widget, jid, default_name=''):
# Save image
try:
pixbuf.savev(file_path, image_format, [], [])
except Exception, e:
except Exception as e:
log.debug('Error saving avatar: %s' % str(e))
if os.path.exists(file_path):
os.remove(file_path)
@ -974,6 +953,38 @@ def load_activity_icon(category, activity = None):
icon_list = _load_icon_list([activity], path)
return icon_list[activity]
def get_pep_as_pixbuf(pep_class):
if isinstance(pep_class, pep.UserMoodPEP):
assert not pep_class._retracted
received_mood = pep_class._pep_specific_data['mood']
mood = received_mood if received_mood in pep.MOODS else 'unknown'
pixbuf = load_mood_icon(mood).get_pixbuf()
return pixbuf
elif isinstance(pep_class, pep.UserTunePEP):
path = os.path.join(gajim.DATA_DIR, 'emoticons', 'static', 'music.png')
return GdkPixbuf.Pixbuf.new_from_file(path)
elif isinstance(pep_class, pep.UserActivityPEP):
assert not pep_class._retracted
pep_ = pep_class._pep_specific_data
activity = pep_['activity']
has_known_activity = activity in pep.ACTIVITIES
has_known_subactivity = (has_known_activity and ('subactivity' in pep_)
and (pep_['subactivity'] in pep.ACTIVITIES[activity]))
if has_known_activity:
if has_known_subactivity:
subactivity = pep_['subactivity']
return load_activity_icon(activity, subactivity).get_pixbuf()
else:
return load_activity_icon(activity).get_pixbuf()
else:
return load_activity_icon('unknown').get_pixbuf()
elif isinstance(pep_class, pep.UserLocationPEP):
path = get_icon_path('gajim-earth')
return GdkPixbuf.Pixbuf.new_from_file(path)
return None
def load_icons_meta():
"""
Load and return - AND + small icons to put on top left of an icon for meta
@ -1091,7 +1102,7 @@ def label_set_autowrap(widget):
"""
if isinstance (widget, Gtk.Container):
children = widget.get_children()
for i in xrange (len (children)):
for i in list(range (len (children))):
label_set_autowrap(children[i])
elif isinstance(widget, Gtk.Label):
widget.set_line_wrap(True)

View File

@ -68,7 +68,7 @@ from groupchat_control import PrivateChatControl
from atom_window import AtomWindow
from session import ChatControlSession
import common.sleepy
from common import sleepy
from nbxmpp import idlequeue
from nbxmpp import Hashes
@ -93,7 +93,7 @@ import config
from threading import Thread
from common import ged
gajimpaths = common.configpaths.gajimpaths
from common.configpaths import gajimpaths
config_filename = gajimpaths['CONFIG_FILE']
from common import optparser
@ -164,7 +164,7 @@ class Interface:
def handle_event_iq_error(self, obj):
#('ERROR_ANSWER', account, (id_, fjid, errmsg, errcode))
if unicode(obj.errcode) in ('400', '403', '406') and obj.id_:
if str(obj.errcode) in ('400', '403', '406') and obj.id_:
# show the error dialog
ft = self.instances['file_transfers']
sid = obj.id_
@ -172,7 +172,7 @@ class Interface:
sid = obj.id_[3:]
file_props = FilesProp.getFileProp(obj.conn.name, sid)
if file_props :
if unicode(obj.errcode) == '400':
if str(obj.errcode) == '400':
file_props.error = -3
else:
file_props.error = -4
@ -181,7 +181,7 @@ class Interface:
error_msg=obj.errmsg))
obj.conn.disconnect_transfer(file_props)
return
elif unicode(obj.errcode) == '404':
elif str(obj.errcode) == '404':
sid = obj.id_
if len(obj.id_) > 3 and obj.id_[2] == '_':
sid = obj.id_[3:]
@ -951,7 +951,7 @@ class Interface:
ft_win = self.instances['file_transfers']
if not file_props.hash_:
# We disn't get the hash, sender probably don't support that
jid = unicode(file_props.sender)
jid = file_props.sender
self.popup_ft_result(account, jid, file_props)
ft_win.set_status(file_props, 'ok')
h = Hashes()
@ -963,7 +963,7 @@ class Interface:
file_.close()
# If the hash we received and the hash of the file are the same,
# then the file is not corrupt
jid = unicode(file_props.sender)
jid = file_props.sender
if file_props.hash_ == hash_:
GObject.idle_add(self.popup_ft_result, account, jid, file_props)
GObject.idle_add(ft_win.set_status, file_props, 'ok')
@ -995,7 +995,7 @@ class Interface:
self.hashThread.start()
gajim.socks5queue.remove_receiver(file_props.sid, True, True)
else: # we send a file
jid = unicode(file_props.receiver)
jid = file_props.receiver
gajim.socks5queue.remove_sender(file_props.sid, True, True)
self.popup_ft_result(account, jid, file_props)
@ -1042,7 +1042,7 @@ class Interface:
if file_props is not None:
if file_props.type_ == 'r':
# get the name of the sender, as it is in the roster
sender = unicode(file_props.sender).split('/')[0]
sender = file_props.sender.split('/')[0]
name = gajim.contacts.get_first_contact_from_jid(account,
sender).get_shown_name()
filename = os.path.basename(file_props.file_name)
@ -1111,11 +1111,11 @@ class Interface:
# Ask offline status in 1 minute so w'are sure we got all online
# presences
GObject.timeout_add_seconds(60, self.ask_offline_status, account)
if state != common.sleepy.STATE_UNKNOWN and connected in (2, 3):
if state != sleepy.STATE_UNKNOWN and connected in (2, 3):
# we go online or free for chat, so we activate auto status
gajim.sleeper_state[account] = 'online'
elif not ((state == common.sleepy.STATE_AWAY and connected == 4) or \
(state == common.sleepy.STATE_XA and connected == 5)):
elif not ((state == sleepy.STATE_AWAY and connected == 4) or \
(state == sleepy.STATE_XA and connected == 5)):
# If we are autoaway/xa and come back after a disconnection, do
# nothing
# Else disable autoaway
@ -1568,7 +1568,7 @@ class Interface:
This is part of rewriting whole events handling system to use GED.
"""
for event_name, event_handlers in self.handlers.iteritems():
for event_name, event_handlers in self.handlers.items():
for event_handler in event_handlers:
prio = ged.GUI1
if type(event_handler) == tuple:
@ -1906,8 +1906,8 @@ class Interface:
self.sth_at_sth_dot_sth = r'\S+@\S+\.\S*[^\s)?]'
# Invalid XML chars
self.invalid_XML_chars = u'[\x00-\x08]|[\x0b-\x0c]|[\x0e-\x1f]|'\
u'[\ud800-\udfff]|[\ufffe-\uffff]'
self.invalid_XML_chars = '[\x00-\x08]|[\x0b-\x0c]|[\x0e-\x1f]|'\
'[\ud800-\udfff]|[\ufffe-\uffff]'
def popup_emoticons_under_button(self, button, parent_win):
"""
@ -1969,7 +1969,7 @@ class Interface:
if not self.image_is_ok(emot_file):
continue
for emot in emots[emot_filename]:
emot = emot.decode('utf-8')
emot = emot
# This avoids duplicated emoticons with the same image eg. :)
# and :-)
if not emot_file in self.emoticons.values():
@ -2342,14 +2342,14 @@ class Interface:
if account not in gajim.sleeper_state or \
not gajim.sleeper_state[account]:
continue
if state == common.sleepy.STATE_AWAKE and \
if state == sleepy.STATE_AWAKE and \
gajim.sleeper_state[account] in ('autoaway', 'autoxa'):
# we go online
self.roster.send_status(account, 'online',
gajim.status_before_autoaway[account])
gajim.status_before_autoaway[account] = ''
gajim.sleeper_state[account] = 'online'
elif state == common.sleepy.STATE_AWAY and \
elif state == sleepy.STATE_AWAY and \
gajim.sleeper_state[account] == 'online' and \
gajim.config.get('autoaway'):
# we save out online status
@ -2369,7 +2369,7 @@ class Interface:
self.roster.send_status(account, 'away', auto_message,
auto=True)
gajim.sleeper_state[account] = 'autoaway'
elif state == common.sleepy.STATE_XA and \
elif state == sleepy.STATE_XA and \
gajim.sleeper_state[account] in ('online', 'autoaway',
'autoaway-forced') and gajim.config.get('autoxa'):
# we go extended away [we pass True to auto param]
@ -2447,7 +2447,7 @@ class Interface:
def save_config(self):
err_str = parser.write()
if err_str is not None:
print >> sys.stderr, err_str
print(err_str, file=sys.stderr)
# it is good to notify the user
# in case he or she cannot see the output of the console
dialogs.ErrorDialog(_('Could not save your settings and '
@ -2491,7 +2491,7 @@ class Interface:
path_to_original_file = path_to_file + extension
try:
pixbuf.savev(path_to_original_file, typ, [], [])
except Exception, e:
except Exception as e:
log.error('Error writing avatar file %s: %s' % (
path_to_original_file, str(e)))
# Generate and save the resized, color avatar
@ -2501,7 +2501,7 @@ class Interface:
extension
try:
pixbuf.savev(path_to_normal_file, 'png', [], [])
except Exception, e:
except Exception as e:
log.error('Error writing avatar file %s: %s' % \
(path_to_original_file, str(e)))
# Generate and save the resized, black and white avatar
@ -2511,7 +2511,7 @@ class Interface:
path_to_bw_file = path_to_file + '_notif_size_bw' + extension
try:
bwbuf.savev(path_to_bw_file, 'png', [], [])
except Exception, e:
except Exception as e:
log.error('Error writing avatar file %s: %s' % \
(path_to_original_file, str(e)))
@ -2609,7 +2609,7 @@ class Interface:
try:
from ipython_view import IPythonView
except ImportError:
print 'ipython_view not found'
print('ipython_view not found')
return
from gi.repository import Pango
@ -2913,7 +2913,7 @@ class Interface:
self.show_vcard_when_connect = []
self.sleeper = common.sleepy.Sleepy(
self.sleeper = sleepy.Sleepy(
gajim.config.get('autoawaytime') * 60, # make minutes to seconds
gajim.config.get('autoxatime') * 60)

View File

@ -122,7 +122,7 @@ def build_invite_submenu(invite_menuitem, list_, ignore_rooms=[]):
minimized_controls = []
for account in connected_accounts:
minimized_controls += \
gajim.interface.minimized_controls[account].values()
list(gajim.interface.minimized_controls[account].values())
for gc_control in gajim.interface.msg_win_mgr.get_controls(
message_control.TYPE_GC) + minimized_controls:
acct = gc_control.account

View File

@ -64,13 +64,13 @@ def parseOpts():
shortargs = 'hc:'
longargs = 'help config_path='
opts = getopt.getopt(sys.argv[1:], shortargs, longargs.split())[0]
except getopt.error, msg:
print str(msg)
print 'for help use --help'
except getopt.error as msg:
print(str(msg))
print('for help use --help')
sys.exit(2)
for o, a in opts:
if o in ('-h', '--help'):
print 'history_manager [--help] [--config-path]'
print('history_manager [--help] [--config-path]')
sys.exit()
elif o in ('-c', '--config-path'):
config_path = a
@ -264,7 +264,7 @@ class HistoryManager:
# get those jids that have at least one entry in logs
self.cur.execute('SELECT jid, jid_id FROM jids WHERE jid_id IN ('
'SELECT distinct logs.jid_id FROM logs) ORDER BY jid')
# list of tupples: [(u'aaa@bbb',), (u'cc@dd',)]
# list of tupples: [('aaa@bbb',), ('cc@dd',)]
rows = self.cur.fetchall()
for row in rows:
self.jids_already_in.append(row[0]) # jid
@ -291,7 +291,7 @@ class HistoryManager:
path = rowref.get_path()
if path is None:
continue
jid = liststore[path][0].decode('utf-8') # jid
jid = liststore[path][0] # jid
self._fill_logs_listview(jid)
def _get_jid_id(self, jid):
@ -642,7 +642,7 @@ class HistoryManager:
dialog.set_transient_for(self.window)
def on_search_db_button_clicked(self, widget):
text = self.search_entry.get_text().decode('utf-8')
text = self.search_entry.get_text()
if not text:
return
@ -655,7 +655,7 @@ class HistoryManager:
def on_search_results_listview_row_activated(self, widget, path, column):
# get log_line_id, jid_id from row we double clicked
log_line_id = self.search_results_liststore[path][0]
jid = self.search_results_liststore[path][1].decode('utf-8')
jid = self.search_results_liststore[path][1]
# make it string as in gtk liststores I have them all as strings
# as this is what db returns so I don't have to fight with types
jid_id = self._get_jid_id(jid)

View File

@ -165,7 +165,7 @@ class HistoryWindow:
keys = completion_dict.keys()
# Move the actual jid at first so we load history faster
actual_jid = self.jid_entry.get_text().decode('utf-8')
actual_jid = self.jid_entry.get_text()
if actual_jid in keys:
keys.remove(actual_jid)
keys.insert(0, actual_jid)
@ -244,7 +244,7 @@ class HistoryWindow:
# Don't disable querybox when we have changed the combobox
# to GC or All and hit enter
return
jid = self.jid_entry.get_text().decode('utf-8')
jid = self.jid_entry.get_text()
account = None # we don't know the account, could be any. Search for it!
self._load_history(jid, account)
self.results_window.set_property('visible', False)
@ -352,7 +352,7 @@ class HistoryWindow:
try:
log_days = gajim.logger.get_days_with_logs(self.jid, year, month,
days_in_this_month, self.account)
except exceptions.PysqliteOperationalError, e:
except exceptions.PysqliteOperationalError as e:
dialogs.ErrorDialog(_('Disk Error'), str(e))
return
for day in log_days:

View File

@ -42,8 +42,8 @@ from gi.repository import Gdk
from gi.repository import GdkPixbuf
import xml.sax, xml.sax.handler
import re
from cStringIO import StringIO
import urllib2
from io import StringIO
import urllib
import operator
if __name__ == '__main__':
@ -491,9 +491,10 @@ class HtmlHandler(xml.sax.handler.ContentHandler):
tag.title = title
return tag
def _update_img(self, (mem, alt), attrs, img_mark):
def _update_img(self, output, attrs, img_mark):
'''Callback function called after the function helpers.download_image.
'''
mem, alt = output
self._process_img(attrs, (mem, alt, img_mark))
def _process_img(self, attrs, loaded=None):
@ -509,7 +510,7 @@ class HtmlHandler(xml.sax.handler.ContentHandler):
# The "data" URL scheme http://tools.ietf.org/html/rfc2397
import base64
img = attrs['src'].split(',')[1]
mem = base64.standard_b64decode(urllib2.unquote(img))
mem = base64.standard_b64decode(urllib.parse.unquote(img))
elif loaded is not None:
(mem, alt, replace_mark) = loaded
update = True
@ -587,7 +588,7 @@ class HtmlHandler(xml.sax.handler.ContentHandler):
self.textbuf.delete_mark(tmpmark)
else:
self._insert_text('[IMG: %s]' % alt, working_iter)
except Exception, ex:
except Exception as ex:
log.error('Error loading image ' + str(ex))
pixbuf = None
alt = attrs.get('alt', 'Broken image')
@ -762,9 +763,9 @@ class HtmlHandler(xml.sax.handler.ContentHandler):
try:
self.textbuf.insert_pixbuf(self.iter,
self.textview.focus_out_line_pixbuf)
#self._insert_text(u'\u2550'*40)
#self._insert_text('\u2550'*40)
self._jump_line()
except Exception, e:
except Exception as e:
log.debug(str('Error in hr'+e))
elif name in LIST_ELEMS:
self.list_counters.pop()
@ -913,7 +914,7 @@ class HtmlTextView(Gtk.TextView):
while (search_iter.compare(end)):
character = search_iter.get_char()
if character == u'\ufffc':
if character == '\ufffc':
anchor = search_iter.get_child_anchor()
if anchor:
text = anchor.get_data('plaintext')

View File

@ -309,11 +309,11 @@ class IterableIPShell:
@param header: Header to be printed before output
@type header: string
"""
if verbose or debug: print header+cmd
if verbose or debug: print(header+cmd)
# flush stdout so we don't mangle python's buffering
if not debug:
input_, output = os.popen4(cmd)
print output.read()
print(output.read())
output.close()
input_.close()

View File

@ -106,7 +106,7 @@ class MessageWindow(object):
'<Control>b', '<Control>F4',
'<Control>w', '<Control>Page_Up', '<Control>Page_Down', '<Alt>Right',
'<Alt>Left', '<Alt>d', '<Alt>c', '<Alt>m', '<Alt>t', 'Escape'] + \
['<Alt>'+str(i) for i in xrange(10)]
['<Alt>'+str(i) for i in list(range(10))]
accel_group = Gtk.AccelGroup()
for key in keys:
keyval, mod = Gtk.accelerator_parse(key)
@ -498,7 +498,7 @@ class MessageWindow(object):
unread_str = ''
if unread > 1:
unread_str = '[' + unicode(unread) + '] '
unread_str = '[' + str(unread) + '] '
elif unread == 1:
unread_str = '* '
else:
@ -693,10 +693,8 @@ class MessageWindow(object):
Return the MessageControl for jid or n, where n is a notebook page index.
When key is an int index acct may be None
"""
if isinstance(key, str):
key = unicode(key, 'utf-8')
if isinstance(key, unicode):
if isinstance(key, str):
jid = key
try:
return self._controls[acct][jid]
@ -858,7 +856,7 @@ class MessageWindow(object):
to_right = False
horiz = self.notebook.get_tab_pos() == Gtk.PositionType.TOP or \
self.notebook.get_tab_pos() == Gtk.PositionType.BOTTOM
for i in xrange(self.notebook.get_n_pages()):
for i in list(range(self.notebook.get_n_pages())):
page = self.notebook.get_nth_page(i)
tab = self.notebook.get_tab_label(page)
tab_alloc = tab.get_allocation()
@ -884,7 +882,7 @@ class MessageWindow(object):
Find the page num of the tab label
"""
page_num = -1
for i in xrange(self.notebook.get_n_pages()):
for i in list(range(self.notebook.get_n_pages())):
page = self.notebook.get_nth_page(i)
tab = self.notebook.get_tab_label(page)
if tab == tab_label:

View File

@ -290,14 +290,14 @@ class MusicTrackListener(GObject.GObject):
if __name__ == '__main__':
def music_track_change_cb(listener, music_track_info):
if music_track_info is None:
print 'Stop!'
print('Stop!')
else:
print music_track_info.title
print(music_track_info.title)
listener = MusicTrackListener.get()
listener.connect('music-track-changed', music_track_change_cb)
track = listener.get_playing_track()
if track is None:
print 'Now not playing anything'
print('Now not playing anything')
else:
print 'Now playing: "%s" by %s' % (track.title, track.artist)
print('Now playing: "%s" by %s' % (track.title, track.artist))
GObject.MainLoop().run()

View File

@ -91,10 +91,10 @@ text=None, timeout=-1):
DesktopNotification(event_type, jid, account, msg_type,
path_to_image, title, GObject.markup_escape_text(text), timeout)
return # sucessfully did D-Bus Notification procedure!
except dbus.DBusException, e:
except dbus.DBusException as e:
# Connection to D-Bus failed
gajim.log.debug(str(e))
except TypeError, e:
except TypeError as e:
# This means that we sent the message incorrectly
gajim.log.debug(str(e))
@ -129,7 +129,7 @@ text=None, timeout=-1):
try:
notification.show()
return
except GObject.GError, e:
except GObject.GError as e:
# Connection to notification-daemon failed, see #2893
gajim.log.debug(str(e))
@ -156,6 +156,9 @@ class Notification:
def _nec_notification(self, obj):
if obj.do_popup:
if isinstance(obj.popup_image, str):
obj.popup_image = gtkgui_helpers.get_icon_path(obj.popup_image,
48)
popup(obj.popup_event_type, obj.jid, obj.conn.name,
obj.popup_msg_type, path_to_image=obj.popup_image,
title=obj.popup_title, text=obj.popup_text,
@ -397,7 +400,7 @@ class DesktopNotification:
dbus.UInt32(self.timeout*1000),
reply_handler=self.attach_by_id,
error_handler=self.notify_another_way)
except Exception, e:
except Exception as e:
self.notify_another_way(e)
else:
try:
@ -412,7 +415,7 @@ class DesktopNotification:
dbus.UInt32(self.timeout*1000),
reply_handler=self.attach_by_id,
error_handler=self.notify_another_way)
except Exception, e:
except Exception as e:
self.notify_another_way(e)
def attach_by_id(self, id_):

View File

@ -24,7 +24,7 @@ Main file of plugins package.
:license: GPL
'''
from pluginmanager import PluginManager
from plugin import GajimPlugin
from .pluginmanager import PluginManager
from .plugin import GajimPlugin
__all__ = ['PluginManager', 'GajimPlugin']

View File

@ -196,7 +196,7 @@ class PluginsWindow(object):
else:
try:
gajim.plugin_manager.activate_plugin(plugin)
except GajimPluginActivateException, e:
except GajimPluginActivateException as e:
WarningDialog(_('Plugin failed'), str(e),
transient_for=self.window)
return
@ -237,11 +237,11 @@ class PluginsWindow(object):
model, iter = selection.get_selected()
if iter:
plugin = model.get_value(iter, PLUGIN)
plugin_name = model.get_value(iter, NAME).decode('utf-8')
plugin_name = model.get_value(iter, NAME)
is_active = model.get_value(iter, ACTIVE)
try:
gajim.plugin_manager.remove_plugin(plugin)
except PluginsystemError, e:
except PluginsystemError as e:
WarningDialog(_('Unable to properly remove the plugin'),
str(e), self.window)
return
@ -264,7 +264,7 @@ class PluginsWindow(object):
return
model = self.installed_plugins_model
for row in xrange(len(model)):
for row in list(range(len(model))):
if plugin == model[row][PLUGIN]:
model.remove(model.get_iter((row, PLUGIN)))
break
@ -280,7 +280,7 @@ class PluginsWindow(object):
def _try_install(zip_filename):
try:
plugin = gajim.plugin_manager.install_from_zip(zip_filename)
except PluginsystemError, er_type:
except PluginsystemError as er_type:
error_text = str(er_type)
if error_text == _('Plugin already exists'):
_on_plugin_exists(zip_filename)

View File

@ -97,7 +97,7 @@ class log_calls(object):
:rtype: function
'''
self.full_func_name += f.func_name
self.full_func_name += f.__name__
if self.log_this_class:
@functools.wraps(f)
def wrapper(*args, **kwargs):

View File

@ -40,30 +40,30 @@ class GajimPlugin(object):
'''
Base class for implementing Gajim plugins.
'''
name = u''
name = ''
'''
Name of plugin.
Will be shown in plugins management GUI.
:type: unicode
:type: str
'''
short_name = u''
short_name = ''
'''
Short name of plugin.
Used for quick indentification of plugin.
:type: unicode
:type: str
:todo: decide whether we really need this one, because class name (with
module name) can act as such short name
'''
version = u''
version = ''
'''
Version of plugin.
:type: unicode
:type: str
:todo: decide how to compare version between each other (which one
is higher). Also rethink: do we really need to compare versions
@ -71,11 +71,11 @@ class GajimPlugin(object):
same plugin class but with different version and we want only the newest
one to be active - is such policy good?
'''
description = u''
description = ''
'''
Plugin description.
:type: unicode
:type: str
:todo: should be allow rich text here (like HTML or reStructuredText)?
'''
@ -83,16 +83,16 @@ class GajimPlugin(object):
'''
Plugin authors.
:type: [] of unicode
:type: [] of str
:todo: should we decide on any particular format of author strings?
Especially: should we force format of giving author's e-mail?
'''
homepage = u''
homepage = ''
'''
URL to plug-in's homepage.
:type: unicode
:type: str
:todo: should we check whether provided string is valid URI? (Maybe
using 'property')
@ -120,7 +120,7 @@ class GajimPlugin(object):
Values are tuples: (default_value, option_description). The first one can
be anything (this is the advantage of using shelve/pickle instead of
custom-made config I/O handling); the second one should be unicode (gettext
custom-made config I/O handling); the second one should be str (gettext
can be used if need and/or translation is planned).
:type: {} of 2-element tuples
@ -196,7 +196,7 @@ class GajimPlugin(object):
def deactivate(self):
pass
import cPickle
import pickle
class GajimPluginConfig():
@log_calls('GajimPluginConfig')
@ -242,7 +242,7 @@ class GajimPluginConfig():
@log_calls('GajimPluginConfig')
def save(self):
fd = open(self.FILE_PATH, 'wb')
cPickle.dump(self.data, fd)
pickle.dump(self.data, fd)
fd.close()
@log_calls('GajimPluginConfig')
@ -250,14 +250,14 @@ class GajimPluginConfig():
if os.path.isfile(self.FILE_PATH):
fd = open(self.FILE_PATH, 'rb')
try:
self.data = cPickle.load(fd)
self.data = pickle.load(fd)
fd.close()
except:
fd.close()
try:
import shelve
s = shelve.open(self.FILE_PATH)
for (k, v) in s.iteritems():
for (k, v) in s.items():
self.data[k] = v
if not isinstance(self.data, dict):
raise GajimPluginException

View File

@ -31,7 +31,7 @@ import sys
import fnmatch
import zipfile
from shutil import rmtree
import ConfigParser
import configparser
from common import gajim
from common import nec
@ -158,7 +158,7 @@ class PluginManager(object):
active yet).
:param gui_extpoint_name: name of GUI extension point.
:type gui_extpoint_name: unicode
:type gui_extpoint_name: str
:param args: parameters to be passed to extension point handlers
(typically and object that invokes `gui_extension_point`;
however, this can be practically anything)
@ -209,7 +209,7 @@ class PluginManager(object):
freedom, but is this necessary?
:param gui_extpoint_name: name of GUI extension point.
:type gui_extpoint_name: unicode
:type gui_extpoint_name: str
:param args: arguments that `PluginManager.gui_extension_point` was
called with for this extension point. This is used (along with
extension point name) to identify element to be removed.
@ -258,14 +258,14 @@ class PluginManager(object):
handlers[0](*args)
def _register_events_handlers_in_ged(self, plugin):
for event_name, handler in plugin.events_handlers.iteritems():
for event_name, handler in plugin.events_handlers.items():
priority = handler[0]
handler_function = handler[1]
gajim.ged.register_event_handler(event_name, priority,
handler_function)
def _remove_events_handler_from_ged(self, plugin):
for event_name, handler in plugin.events_handlers.iteritems():
for event_name, handler in plugin.events_handlers.items():
priority = handler[0]
handler_function = handler[1]
gajim.ged.remove_event_handler(event_name, priority,
@ -302,7 +302,7 @@ class PluginManager(object):
self.active_plugins.append(plugin)
try:
plugin.activate()
except GajimPluginException, e:
except GajimPluginException as e:
self.deactivate_plugin(plugin)
raise GajimPluginActivateException(str(e))
self._set_plugin_active_in_global_config(plugin)
@ -312,7 +312,7 @@ class PluginManager(object):
# remove GUI extension points handlers (provided by plug-in) from
# handlers list
for gui_extpoint_name, gui_extpoint_handlers in \
plugin.gui_extension_points.iteritems():
plugin.gui_extension_points.items():
self.gui_extension_points_handlers[gui_extpoint_name].remove(
gui_extpoint_handlers)
@ -320,7 +320,7 @@ class PluginManager(object):
# cleaning up method that must be provided by plug-in developer
# for each handled GUI extension point)
for gui_extpoint_name, gui_extpoint_handlers in \
plugin.gui_extension_points.iteritems():
plugin.gui_extension_points.items():
if gui_extpoint_name in self.gui_extension_points:
for gui_extension_point_args in self.gui_extension_points[
gui_extpoint_name]:
@ -344,14 +344,14 @@ class PluginManager(object):
@log_calls('PluginManager')
def _add_gui_extension_points_handlers_from_plugin(self, plugin):
for gui_extpoint_name, gui_extpoint_handlers in \
plugin.gui_extension_points.iteritems():
plugin.gui_extension_points.items():
self.gui_extension_points_handlers.setdefault(gui_extpoint_name,
[]).append(gui_extpoint_handlers)
@log_calls('PluginManager')
def _handle_all_gui_extension_points_with_plugin(self, plugin):
for gui_extpoint_name, gui_extpoint_handlers in \
plugin.gui_extension_points.iteritems():
plugin.gui_extension_points.items():
if gui_extpoint_name in self.gui_extension_points:
for gui_extension_point_args in self.gui_extension_points[
gui_extpoint_name]:
@ -394,7 +394,7 @@ class PluginManager(object):
Scans given directory for plugin classes.
:param path: directory to scan for plugins
:type path: unicode
:type path: str
:return: list of found plugin classes (subclasses of `GajimPlugin`
:rtype: [] of class objects
@ -407,7 +407,7 @@ class PluginManager(object):
'''
from plugins.plugins_i18n import _
plugins_found = []
conf = ConfigParser.ConfigParser()
conf = configparser.ConfigParser()
fields = ('name', 'short_name', 'version', 'description', 'authors',
'homepage')
if not os.path.isdir(path):
@ -426,9 +426,9 @@ class PluginManager(object):
module_name = os.path.splitext(elem_name)[0]
try:
module = __import__(module_name)
except ValueError, value_error:
except ValueError as value_error:
log.debug(value_error)
except ImportError, import_error:
except ImportError as import_error:
log.debug(import_error)
elif os.path.isdir(file_path) and scan_dirs:
@ -439,9 +439,9 @@ class PluginManager(object):
file_path += os.path.sep
try:
module = __import__(module_name)
except ValueError, value_error:
except ValueError as value_error:
log.debug(value_error)
except ImportError, import_error:
except ImportError as import_error:
log.debug(import_error)
@ -471,27 +471,27 @@ class PluginManager(object):
conf.readfp(open(manifest_path, 'r'))
for option in fields:
if conf.get('info', option) is '':
raise ConfigParser.NoOptionError, 'field empty'
raise configparser.NoOptionError('field empty')
setattr(module_attr, option, conf.get('info', option))
conf.remove_section('info')
plugins_found.append(module_attr)
except TypeError, type_error:
except TypeError as type_error:
# set plugin localization
try:
module_attr._ = _
except AttributeError, type_error:
except AttributeError as type_error:
pass
except ConfigParser.NoOptionError, type_error:
except configparser.NoOptionError as type_error:
# all fields are required
log.debug('%s : %s' % (module_attr_name,
'wrong manifest file. all fields are required!'))
except ConfigParser.NoSectionError, type_error:
except configparser.NoSectionError as type_error:
# info section are required
log.debug('%s : %s' % (module_attr_name,
'wrong manifest file. info section are required!'))
except ConfigParser.MissingSectionHeaderError, type_error:
except configparser.MissingSectionHeaderError as type_error:
# info section are required
log.debug('%s : %s' % (module_attr_name,
'wrong manifest file. section are required!'))
@ -504,10 +504,10 @@ class PluginManager(object):
'''
try:
zip_file = zipfile.ZipFile(zip_filename)
except zipfile.BadZipfile, e:
except zipfile.BadZipfile as e:
# it is not zip file
raise PluginsystemError(_('Archive corrupted'))
except IOError,e:
except IOError as e:
raise PluginsystemError(_('Archive empty'))
if zip_file.testzip():

View File

@ -36,6 +36,6 @@ if os.name != 'nt':
try:
t = gettext.translation(APP, plugins_locale_dir)
_ = t.gettext
except IOError, msg:
except IOError as msg:
from common import i18n
_ = gettext.gettext

View File

@ -139,7 +139,7 @@ class ProfileWindow:
# and hope that user did not specify in ACE crazy size
scaled_pixbuf = gtkgui_helpers.get_scaled_pixbuf(pixbuf,
'tooltip')
except GObject.GError, msg: # unknown format
except GObject.GError as msg: # unknown format
# msg should be string, not object instance
msg = str(msg)
invalid_file = True
@ -171,7 +171,8 @@ class ProfileWindow:
button.show()
text_button = self.xml.get_object('NOPHOTO_button')
text_button.hide()
self.avatar_encoded = base64.encodestring(data)
self.avatar_encoded = base64.b64encode(data.encode('utf-8')).decode(
'utf-8')
# returns None if unknown type
self.avatar_mime_type = mimetypes.guess_type(path_to_file)[0]
if must_delete:
@ -344,7 +345,7 @@ class ProfileWindow:
'ADR_WORK_REGION', 'ADR_WORK_PCODE', 'ADR_WORK_CTRY']
vcard_ = {}
for e in entries:
txt = self.xml.get_object(e + '_entry').get_text().decode('utf-8')
txt = self.xml.get_object(e + '_entry').get_text()
if txt != '':
vcard_ = self.add_to_vcard(vcard_, e, txt)
@ -354,7 +355,7 @@ class ProfileWindow:
end_iter = buff.get_end_iter()
txt = buff.get_text(start_iter, end_iter, False)
if txt != '':
vcard_['DESC'] = txt.decode('utf-8')
vcard_['DESC'] = txt
# Avatar
if self.avatar_encoded:

View File

@ -72,7 +72,7 @@ def get_dbus_struct(obj):
"""
if obj is None:
return DBUS_NONE()
if isinstance(obj, (unicode, str)):
if isinstance(obj, str):
return DBUS_STRING(obj)
if isinstance(obj, int):
return DBUS_INT32(obj)
@ -613,13 +613,13 @@ class SignalObject(dbus.service.Object):
"""
Get vcard info for a contact. Return cached value of the vcard
"""
if not isinstance(jid, unicode):
jid = unicode(jid)
if not isinstance(jid, str):
jid = str(jid)
if not jid:
raise dbus_support.MissingArgument()
jid = self._get_real_jid(jid)
cached_vcard = gajim.connections.values()[0].get_cached_vcard(jid)
cached_vcard = list(gajim.connections.values())[0].get_cached_vcard(jid)
if cached_vcard:
return get_dbus_struct(cached_vcard)
@ -652,9 +652,9 @@ class SignalObject(dbus.service.Object):
result['name'] = DBUS_STRING(con.name)
result['jid'] = DBUS_STRING(gajim.get_jid_from_account(con.name))
result['message'] = DBUS_STRING(con.status)
result['priority'] = DBUS_STRING(unicode(con.priority))
result['resource'] = DBUS_STRING(unicode(gajim.config.get_per(
'accounts', con.name, 'resource')))
result['priority'] = DBUS_STRING(str(con.priority))
result['resource'] = DBUS_STRING(gajim.config.get_per('accounts',
con.name, 'resource'))
return result
@dbus.service.method(INTERFACE, in_signature='s', out_signature='aa{sv}')
@ -743,7 +743,7 @@ class SignalObject(dbus.service.Object):
def prefs_store(self):
try:
gajim.interface.save_config()
except Exception, e:
except Exception as e:
return DBUS_BOOLEAN(False)
return DBUS_BOOLEAN(True)
@ -907,7 +907,7 @@ class SignalObject(dbus.service.Object):
if not invalid_file and filesize < 16384:
fd = open(picture, 'rb')
data = fd.read()
avatar = base64.encodestring(data)
avatar = base64.b64encode(data.encode('utf-8')).decode('utf-8')
avatar_mime_type = mimetypes.guess_type(picture)[0]
vcard={}
vcard['PHOTO'] = {'BINVAL': avatar}

View File

@ -460,7 +460,7 @@ class RosterWindow:
account_group = 'MERGED'
else:
account_group = account
group = self.model[parent_i][C_JID].decode('utf-8')
group = self.model[parent_i][C_JID]
if group in gajim.groups[account]:
del gajim.groups[account][group]
to_be_removed = parent_i
@ -1063,28 +1063,28 @@ class RosterWindow:
pep_dict = gajim.connections[account].pep
if gajim.config.get('show_mood_in_roster') and 'mood' in pep_dict:
self.model[child_iter][C_MOOD_PIXBUF] = pep_dict['mood'].\
asPixbufIcon()
self.model[child_iter][C_MOOD_PIXBUF] = \
gtkgui_helpers.get_pep_as_pixbuf(pep_dict['mood'])
else:
self.model[child_iter][C_MOOD_PIXBUF] = empty_pixbuf
if gajim.config.get('show_activity_in_roster') and 'activity' in \
pep_dict:
self.model[child_iter][C_ACTIVITY_PIXBUF] = pep_dict['activity'].\
asPixbufIcon()
self.model[child_iter][C_ACTIVITY_PIXBUF] = \
gtkgui_helpers.get_pep_as_pixbuf(pep_dict['activity'])
else:
self.model[child_iter][C_ACTIVITY_PIXBUF] = empty_pixbuf
if gajim.config.get('show_tunes_in_roster') and 'tune' in pep_dict:
self.model[child_iter][C_TUNE_PIXBUF] = pep_dict['tune'].\
asPixbufIcon()
self.model[child_iter][C_TUNE_PIXBUF] = \
gtkgui_helpers.get_pep_as_pixbuf(pep_dict['tune'])
else:
self.model[child_iter][C_TUNE_PIXBUF] = empty_pixbuf
if gajim.config.get('show_location_in_roster') and 'location' in \
pep_dict:
self.model[child_iter][C_LOCATION_PIXBUF] = pep_dict['location'].\
asPixbufIcon()
self.model[child_iter][C_LOCATION_PIXBUF] = \
gtkgui_helpers.get_pep_as_pixbuf(pep_dict['location'])
else:
self.model[child_iter][C_LOCATION_PIXBUF] = empty_pixbuf
@ -1145,8 +1145,8 @@ class RosterWindow:
if self.model[parent_iter][C_TYPE] != 'contact':
# parent is not a contact
return
parent_jid = self.model[parent_iter][C_JID].decode('utf-8')
parent_account = self.model[parent_iter][C_ACCOUNT].decode('utf-8')
parent_jid = self.model[parent_iter][C_JID]
parent_account = self.model[parent_iter][C_ACCOUNT]
self.draw_contact(parent_jid, parent_account)
return False
@ -1203,8 +1203,8 @@ class RosterWindow:
nb_connected_contact += 1
if nb_connected_contact > 1:
# switch back to default writing direction
name += i18n.paragraph_direction_mark(unicode(name))
name += u' (%d)' % nb_connected_contact
name += i18n.paragraph_direction_mark(name)
name += ' (%d)' % nb_connected_contact
# add status msg, if not empty, under contact name in
# the treeview
@ -1257,8 +1257,8 @@ class RosterWindow:
iterC = self.model.iter_children(child_iter)
while iterC:
# a child has awaiting messages?
jidC = self.model[iterC][C_JID].decode('utf-8')
accountC = self.model[iterC][C_ACCOUNT].decode('utf-8')
jidC = self.model[iterC][C_JID]
accountC = self.model[iterC][C_ACCOUNT]
if len(gajim.events.get_events(accountC, jidC)):
icon_name = 'event'
break
@ -1341,7 +1341,7 @@ class RosterWindow:
if not contact:
contact = gajim.contacts.get_contact(account, jid)
if pep_type in contact.pep:
pixbuf = contact.pep[pep_type].asPixbufIcon()
pixbuf = gtkgui_helpers.get_pep_as_pixbuf(contact.pep[pep_type])
else:
pixbuf = empty_pixbuf
for child_iter in iters:
@ -1351,7 +1351,7 @@ class RosterWindow:
iters = self._get_contact_iter(jid, account, model=self.model)
if not iters or not gajim.config.get('show_avatars_in_roster'):
return
jid = self.model[iters[0]][C_JID].decode('utf-8')
jid = self.model[iters[0]][C_JID]
pixbuf = gtkgui_helpers.get_avatar_pixbuf_from_cache(jid)
if pixbuf in (None, 'ask'):
scaled_pixbuf = empty_pixbuf
@ -1500,8 +1500,8 @@ class RosterWindow:
def _readjust_expand_collapse_state(self):
def func(model, path, iter_):
type_ = model[iter_][C_TYPE]
acct = model[iter_][C_ACCOUNT].decode('utf-8')
jid = model[iter_][C_JID].decode('utf-8')
acct = model[iter_][C_ACCOUNT]
jid = model[iter_][C_JID]
key = None
if type_ == 'account':
key = acct
@ -1511,7 +1511,7 @@ class RosterWindow:
parent_iter = model.iter_parent(iter_)
ptype = model[parent_iter][C_TYPE]
if ptype == 'group':
grp = model[parent_iter][C_JID].decode('utf-8')
grp = model[parent_iter][C_JID]
key = acct + grp + jid
if key:
if key in self.collapsed_rows:
@ -1615,11 +1615,10 @@ class RosterWindow:
if not account:
return False
account = account.decode('utf-8')
jid = model[titer][C_JID]
if not jid:
return False
jid = jid.decode('utf-8')
if type_ == 'group':
group = jid
if group == _('Transports'):
@ -1717,8 +1716,8 @@ class RosterWindow:
name2 = model[iter2][C_NAME]
if not name1 or not name2:
return 0
name1 = name1.decode('utf-8')
name2 = name2.decode('utf-8')
name1 = name1
name2 = name2
type1 = model[iter1][C_TYPE]
type2 = model[iter2][C_TYPE]
if type1 == 'self_contact':
@ -1728,10 +1727,10 @@ class RosterWindow:
if type1 == 'group':
name1 = model[iter1][C_JID]
if name1:
name1 = name1.decode('utf-8')
name1 = name1
name2 = model[iter2][C_JID]
if name2:
name2 = name2.decode('utf-8')
name2 = name2
if name1 == _('Transports'):
return 1
if name2 == _('Transports'):
@ -1748,12 +1747,12 @@ class RosterWindow:
account2 = model[iter2][C_ACCOUNT]
if not account1 or not account2:
return 0
account1 = account1.decode('utf-8')
account2 = account2.decode('utf-8')
account1 = account1
account2 = account2
if type1 == 'account':
return locale.strcoll(account1, account2)
jid1 = model[iter1][C_JID].decode('utf-8')
jid2 = model[iter2][C_JID].decode('utf-8')
jid1 = model[iter1][C_JID]
jid2 = model[iter2][C_JID]
if type1 == 'contact':
lcontact1 = gajim.contacts.get_contacts(account1, jid1)
contact1 = gajim.contacts.get_first_contact_from_jid(account1, jid1)
@ -2191,7 +2190,7 @@ class RosterWindow:
gajim.interface.status_sent_to_groups[account] = {}
for gc_control in gajim.interface.msg_win_mgr.get_controls(
message_control.TYPE_GC) + \
gajim.interface.minimized_controls[account].values():
list(gajim.interface.minimized_controls[account].values()):
if gc_control.account == account:
if gajim.gc_connected[account][gc_control.room_jid]:
gajim.connections[account].send_gc_status(
@ -2865,8 +2864,8 @@ class RosterWindow:
if model[titer][C_TYPE] in ('contact', 'self_contact'):
# we're on a contact entry in the roster
if self.tooltip.timeout == 0 or self.tooltip.id != props[0]:
account = model[titer][C_ACCOUNT].decode('utf-8')
jid = model[titer][C_JID].decode('utf-8')
account = model[titer][C_ACCOUNT]
jid = model[titer][C_JID]
self.tooltip.id = row
contacts = gajim.contacts.get_contacts(account, jid)
connected_contacts = []
@ -2881,8 +2880,8 @@ class RosterWindow:
self.show_tooltip, connected_contacts)
elif model[titer][C_TYPE] == 'groupchat':
if self.tooltip.timeout == 0 or self.tooltip.id != props[0]:
account = model[titer][C_ACCOUNT].decode('utf-8')
jid = model[titer][C_JID].decode('utf-8')
account = model[titer][C_ACCOUNT]
jid = model[titer][C_JID]
self.tooltip.id = row
contact = gajim.contacts.get_contacts(account, jid)
self.tooltip.account = account
@ -2891,7 +2890,7 @@ class RosterWindow:
elif model[titer][C_TYPE] == 'account':
# we're on an account entry in the roster
if self.tooltip.timeout == 0 or self.tooltip.id != props[0]:
account = model[titer][C_ACCOUNT].decode('utf-8')
account = model[titer][C_ACCOUNT]
if account == 'all':
self.tooltip.id = row
self.tooltip.account = None
@ -3029,9 +3028,9 @@ class RosterWindow:
continue
accounts.append(account)
self.send_status(account, 'offline', msg, to=contact.jid)
new_rule = {'order': u'1', 'type': u'jid',
'action': u'deny', 'value' : contact.jid,
'child': [u'message', u'iq', u'presence-out']}
new_rule = {'order': '1', 'type': 'jid',
'action': 'deny', 'value' : contact.jid,
'child': ['message', 'iq', 'presence-out']}
gajim.connections[account].blocked_list.append(new_rule)
# needed for draw_contact:
gajim.connections[account].blocked_contacts.append(
@ -3049,9 +3048,9 @@ class RosterWindow:
self.draw_group(group, account)
self.send_status(account, 'offline', msg, to=contact.jid)
self.draw_contact(contact.jid, account)
new_rule = {'order': u'1', 'type': u'group', 'action': u'deny',
'value' : group, 'child': [u'message', u'iq',
u'presence-out']}
new_rule = {'order': '1', 'type': 'group', 'action': 'deny',
'value' : group, 'child': ['message', 'iq',
'presence-out']}
# account is the same for all when we block a group
gajim.connections[list_[0][1]].blocked_list.append(new_rule)
for account in accounts:
@ -3230,7 +3229,7 @@ class RosterWindow:
'attached_gpg_keys').split()
keys = {}
keyID = _('None')
for i in xrange(len(attached_keys)/2):
for i in list(range(len(attached_keys)/2)):
keys[attached_keys[2*i]] = attached_keys[2*i+1]
if attached_keys[2*i] == contact.jid:
keyID = attached_keys[2*i+1]
@ -3287,7 +3286,7 @@ class RosterWindow:
# get the image at 'tooltip size'
# and hope that user did not specify in ACE crazy size
pixbuf = gtkgui_helpers.get_scaled_pixbuf(pixbuf, 'tooltip')
except GObject.GError, msg: # unknown format
except GObject.GError as msg: # unknown format
# msg should be string, not object instance
msg = str(msg)
dialogs.ErrorDialog(_('Could not load image'), msg)
@ -3489,8 +3488,8 @@ class RosterWindow:
path = list_of_paths[0]
type_ = model[path][C_TYPE]
if type_ in ('contact', 'group', 'agent'):
jid = model[path][C_JID].decode('utf-8')
account = model[path][C_ACCOUNT].decode('utf-8')
jid = model[path][C_JID]
account = model[path][C_ACCOUNT]
self.on_rename(widget, type_, jid, account)
elif event.keyval == Gdk.KEY_Delete:
@ -3499,7 +3498,7 @@ class RosterWindow:
if not len(list_of_paths):
return
type_ = model[list_of_paths[0]][C_TYPE]
account = model[list_of_paths[0]][C_ACCOUNT].decode('utf-8')
account = model[list_of_paths[0]][C_ACCOUNT]
if type_ in ('account', 'group', 'self_contact') or \
account == gajim.ZEROCONF_ACC_NAME:
return
@ -3507,8 +3506,8 @@ class RosterWindow:
for path in list_of_paths:
if model[path][C_TYPE] != type_:
return
jid = model[path][C_JID].decode('utf-8')
account = model[path][C_ACCOUNT].decode('utf-8')
jid = model[path][C_JID]
account = model[path][C_ACCOUNT]
contact = gajim.contacts.get_contact_with_highest_priority(
account, jid)
list_.append((contact, account))
@ -3517,8 +3516,8 @@ class RosterWindow:
elif type_ == 'agent':
self.on_remove_agent(widget, list_)
elif not (event.get_state() & (Gdk.ModifierType.CONTROL_MASK | Gdk.ModifierType.MOD1_MASK)) and\
Gdk.keyval_to_unicode(event.keyval):
elif not (event.get_state() & (Gdk.ModifierType.CONTROL_MASK | \
Gdk.ModifierType.MOD1_MASK)) and Gdk.keyval_to_unicode(event.keyval):
# if we got unicode symbol without ctrl / alt
num = Gdk.keyval_to_unicode(event.keyval)
self.enable_rfilter(unichr(num))
@ -3620,7 +3619,7 @@ class RosterWindow:
if type_ in ('agent', 'contact', 'self_contact', 'groupchat'):
self.on_row_activated(widget, path)
elif type_ == 'account':
account = model[path][C_ACCOUNT].decode('utf-8')
account = model[path][C_ACCOUNT]
if account != 'all':
show = gajim.connections[account].connected
if show > 1: # We are connected
@ -3834,7 +3833,7 @@ class RosterWindow:
'contacts.'))
self.update_status_combobox()
return
status = model[active][2].decode('utf-8')
status = model[active][2]
# status "desync'ed" or not
statuses_unified = helpers.statuses_unified()
if (active == 7 and statuses_unified) or (active == 9 and \
@ -3928,7 +3927,7 @@ class RosterWindow:
)
def on_plugins_menuitem_activate(self, widget):
if gajim.interface.instances.has_key('plugins'):
if 'plugins' in gajim.interface.instances:
gajim.interface.instances['plugins'].window.present()
else:
gajim.interface.instances['plugins'] = plugins.gui.PluginsWindow()
@ -4051,7 +4050,7 @@ class RosterWindow:
"""
jid = contact.jid
if resource is not None:
jid = jid + u'/' + resource
jid = jid + '/' + resource
adhoc_commands.CommandWindow(account, jid)
def on_roster_window_focus_in_event(self, widget, event):
@ -4099,8 +4098,8 @@ class RosterWindow:
for path in list_of_paths:
type_ = model[path][C_TYPE]
if type_ in ('contact', 'agent'):
jid = model[path][C_JID].decode('utf-8')
account = model[path][C_ACCOUNT].decode('utf-8')
jid = model[path][C_JID]
account = model[path][C_ACCOUNT]
contact = gajim.contacts.get_first_contact_from_jid(account,
jid)
self.on_info(widget, contact, account)
@ -4113,8 +4112,8 @@ class RosterWindow:
path = list_of_paths[0]
type_ = model[path][C_TYPE]
if type_ in ('contact', 'agent'):
jid = model[path][C_JID].decode('utf-8')
account = model[path][C_ACCOUNT].decode('utf-8')
jid = model[path][C_JID]
account = model[path][C_ACCOUNT]
contact = gajim.contacts.get_first_contact_from_jid(account,
jid)
self.on_history(widget, contact, account)
@ -4129,7 +4128,7 @@ class RosterWindow:
this way)
"""
model = self.modelfilter
account = model[path][C_ACCOUNT].decode('utf-8')
account = model[path][C_ACCOUNT]
type_ = model[path][C_TYPE]
if type_ in ('group', 'account'):
if self.tree.row_expanded(path):
@ -4137,7 +4136,7 @@ class RosterWindow:
else:
self.tree.expand_row(path, False)
return
jid = model[path][C_JID].decode('utf-8')
jid = model[path][C_JID]
resource = None
contact = gajim.contacts.get_contact_with_highest_priority(account, jid)
titer = model.get_iter(path)
@ -4164,7 +4163,7 @@ class RosterWindow:
if not first_ev and model.iter_has_child(titer):
child_iter = model.iter_children(titer)
while not first_ev and child_iter:
child_jid = model[child_iter][C_JID].decode('utf-8')
child_jid = model[child_iter][C_JID]
first_ev = gajim.events.get_first_event(account, child_jid)
if first_ev:
jid = child_jid
@ -4209,11 +4208,11 @@ class RosterWindow:
if self.regroup: # merged accounts
accounts = gajim.connections.keys()
else:
accounts = [model[titer][C_ACCOUNT].decode('utf-8')]
accounts = [model[titer][C_ACCOUNT]]
type_ = model[titer][C_TYPE]
if type_ == 'group':
group = model[titer][C_JID].decode('utf-8')
group = model[titer][C_JID]
child_model[child_iter][C_IMG] = \
gajim.interface.jabber_state_images['16']['opened']
if self.rfilter_enabled:
@ -4246,8 +4245,8 @@ class RosterWindow:
self.tree.expand_row(path, False)
elif type_ == 'contact':
# Metacontact got toggled, update icon
jid = model[titer][C_JID].decode('utf-8')
account = model[titer][C_ACCOUNT].decode('utf-8')
jid = model[titer][C_JID]
account = model[titer][C_ACCOUNT]
contact = gajim.contacts.get_contact(account, jid)
for group in contact.groups:
if account + group + jid in self.collapsed_rows:
@ -4273,7 +4272,7 @@ class RosterWindow:
if self.regroup: # merged accounts
accounts = gajim.connections.keys()
else:
accounts = [model[titer][C_ACCOUNT].decode('utf-8')]
accounts = [model[titer][C_ACCOUNT]]
type_ = model[titer][C_TYPE]
if type_ == 'group':
@ -4281,7 +4280,7 @@ class RosterWindow:
jabber_state_images['16']['closed']
if self.rfilter_enabled:
return
group = model[titer][C_JID].decode('utf-8')
group = model[titer][C_JID]
for account in accounts:
if group in gajim.groups[account]: # This account has this group
gajim.groups[account][group]['expand'] = False
@ -4294,8 +4293,8 @@ class RosterWindow:
self.draw_account(account)
elif type_ == 'contact':
# Metacontact got toggled, update icon
jid = model[titer][C_JID].decode('utf-8')
account = model[titer][C_ACCOUNT].decode('utf-8')
jid = model[titer][C_JID]
account = model[titer][C_ACCOUNT]
contact = gajim.contacts.get_contact(account, jid)
groups = contact.groups
if not groups:
@ -4327,8 +4326,6 @@ class RosterWindow:
if not account:
return
account = account.decode('utf-8')
if type_ == 'contact':
child_iter = model.convert_iter_to_child_iter(titer)
if self.model.iter_has_child(child_iter):
@ -4336,10 +4333,10 @@ class RosterWindow:
# redraw us to show/hide expand icon
if self.filtering:
# Prevent endless loops
jid = model[titer][C_JID].decode('utf-8')
jid = model[titer][C_JID]
GObject.idle_add(self.draw_contact, jid, account)
elif type_ == 'group':
group = model[titer][C_JID].decode('utf-8')
group = model[titer][C_JID]
self._adjust_group_expand_collapse_state(group, account)
elif type_ == 'account':
self._adjust_account_expand_collapse_state(account)
@ -4369,8 +4366,8 @@ class RosterWindow:
# if row[C_TYPE] != 'contact':
# self._last_selected_contact = []
# return
# jid = row[C_JID].decode('utf-8')
# account = row[C_ACCOUNT].decode('utf-8')
# jid = row[C_JID]
# account = row[C_ACCOUNT]
# self._last_selected_contact.append((jid, account))
# GObject.idle_add(self.draw_contact, jid, account, True)
@ -4708,9 +4705,9 @@ class RosterWindow:
path_dest = (path_dest[0], path_dest[1]-1)
# destination: the row something got dropped on
iter_dest = model.get_iter(path_dest)
type_dest = model[iter_dest][C_TYPE].decode('utf-8')
jid_dest = model[iter_dest][C_JID].decode('utf-8')
account_dest = model[iter_dest][C_ACCOUNT].decode('utf-8')
type_dest = model[iter_dest][C_TYPE]
jid_dest = model[iter_dest][C_JID]
account_dest = model[iter_dest][C_ACCOUNT]
# drop on account row in merged mode, we cannot know the desired account
if account_dest == 'all':
@ -4774,7 +4771,7 @@ class RosterWindow:
path_source = treeview.get_selection().get_selected_rows()[1][0]
iter_source = model.get_iter(path_source)
type_source = model[iter_source][C_TYPE]
account_source = model[iter_source][C_ACCOUNT].decode('utf-8')
account_source = model[iter_source][C_ACCOUNT]
if gajim.config.get_per('accounts', account_source, 'is_zeroconf'):
return
@ -4792,14 +4789,14 @@ class RosterWindow:
if account_source != account_dest:
# drop on another account
return
grp_source = model[iter_source][C_JID].decode('utf-8')
grp_source = model[iter_source][C_JID]
delimiter = gajim.connections[account_source].nested_group_delimiter
grp_source_list = grp_source.split(delimiter)
new_grp = None
if type_dest == 'account':
new_grp = grp_source_list[-1]
elif type_dest == 'group':
new_grp = model[iter_dest][C_JID].decode('utf-8') + delimiter +\
new_grp = model[iter_dest][C_JID] + delimiter +\
grp_source_list[-1]
if new_grp:
self.move_group(grp_source, new_grp, account_source)
@ -4821,26 +4818,26 @@ class RosterWindow:
it = iter_source
while model[it][C_TYPE] == 'contact':
it = model.iter_parent(it)
grp_source = model[it][C_JID].decode('utf-8')
grp_source = model[it][C_JID]
if grp_source in helpers.special_groups and \
grp_source not in ('Not in Roster', 'Observers'):
# a transport or a minimized groupchat was dragged
# we can add it to other accounts but not move it to another group,
# see below
return
jid_source = data.decode('utf-8')
jid_source = data
c_source = gajim.contacts.get_contact_with_highest_priority(
account_source, jid_source)
# Get destination group
grp_dest = None
if type_dest == 'group':
grp_dest = model[iter_dest][C_JID].decode('utf-8')
grp_dest = model[iter_dest][C_JID]
elif type_dest in ('contact', 'agent'):
it = iter_dest
while model[it][C_TYPE] != 'group':
it = model.iter_parent(it)
grp_dest = model[it][C_JID].decode('utf-8')
grp_dest = model[it][C_JID]
if grp_dest in helpers.special_groups:
return
@ -5096,8 +5093,8 @@ class RosterWindow:
if not model[titer][C_JID] or not model[titer][C_ACCOUNT]:
# This can append when at the moment we add the row
return
jid = model[titer][C_JID].decode('utf-8')
account = model[titer][C_ACCOUNT].decode('utf-8')
jid = model[titer][C_JID]
account = model[titer][C_ACCOUNT]
self._set_contact_row_background_color(renderer, jid, account)
parent_iter = model.iter_parent(titer)
if model[parent_iter][C_TYPE] == 'contact':
@ -5145,8 +5142,8 @@ class RosterWindow:
if not model[titer][C_JID] or not model[titer][C_ACCOUNT]:
# This can append when at the moment we add the row
return
jid = model[titer][C_JID].decode('utf-8')
account = model[titer][C_ACCOUNT].decode('utf-8')
jid = model[titer][C_JID]
account = model[titer][C_ACCOUNT]
color = None
if type_ == 'groupchat':
ctrl = gajim.interface.minimized_controls[account].get(jid,
@ -5194,8 +5191,8 @@ class RosterWindow:
if not model[titer][C_JID] or not model[titer][C_ACCOUNT]:
# This can append at the moment we add the row
return
jid = model[titer][C_JID].decode('utf-8')
account = model[titer][C_ACCOUNT].decode('utf-8')
jid = model[titer][C_JID]
account = model[titer][C_ACCOUNT]
self._set_contact_row_background_color(renderer, jid, account)
def _fill_avatar_pixbuf_renderer(self, column, renderer, model, titer,
@ -5221,8 +5218,8 @@ class RosterWindow:
if not model[titer][C_JID] or not model[titer][C_ACCOUNT]:
# This can append at the moment we add the row
return
jid = model[titer][C_JID].decode('utf-8')
account = model[titer][C_ACCOUNT].decode('utf-8')
jid = model[titer][C_JID]
account = model[titer][C_ACCOUNT]
self._set_contact_row_background_color(renderer, jid, account)
else:
renderer.set_property('visible', False)
@ -5731,7 +5728,7 @@ class RosterWindow:
Make account's popup menu
"""
model = self.modelfilter
account = model[titer][C_ACCOUNT].decode('utf-8')
account = model[titer][C_ACCOUNT]
if account != 'all': # not in merged mode
menu = self.build_account_menu(account)
@ -5766,8 +5763,8 @@ class RosterWindow:
"""
model = self.modelfilter
path = model.get_path(titer)
group = model[titer][C_JID].decode('utf-8')
account = model[titer][C_ACCOUNT].decode('utf-8')
group = model[titer][C_JID]
account = model[titer][C_ACCOUNT]
list_ = [] # list of (jid, account) tuples
list_online = [] # list of (jid, account) tuples
@ -5927,8 +5924,8 @@ class RosterWindow:
Make contact's popup menu
"""
model = self.modelfilter
jid = model[titer][C_JID].decode('utf-8')
account = model[titer][C_ACCOUNT].decode('utf-8')
jid = model[titer][C_JID]
account = model[titer][C_ACCOUNT]
contact = gajim.contacts.get_contact_with_highest_priority(account, jid)
menu = gui_menu_builder.get_contact_menu(contact, account)
event_button = gtkgui_helpers.get_possible_button_event(event)
@ -5945,8 +5942,8 @@ class RosterWindow:
is_blocked = True
privacy_rules_supported = True
for titer in iters:
jid = model[titer][C_JID].decode('utf-8')
account = model[titer][C_ACCOUNT].decode('utf-8')
jid = model[titer][C_JID]
account = model[titer][C_ACCOUNT]
if gajim.connections[account].connected < 2:
one_account_offline = True
if not gajim.connections[account].privacy_rules_supported:
@ -6044,9 +6041,9 @@ class RosterWindow:
Make transport's popup menu
"""
model = self.modelfilter
jid = model[titer][C_JID].decode('utf-8')
jid = model[titer][C_JID]
path = model.get_path(titer)
account = model[titer][C_ACCOUNT].decode('utf-8')
account = model[titer][C_ACCOUNT]
contact = gajim.contacts.get_contact_with_highest_priority(account, jid)
menu = Gtk.Menu()
@ -6181,8 +6178,8 @@ class RosterWindow:
def make_groupchat_menu(self, event, titer):
model = self.modelfilter
jid = model[titer][C_JID].decode('utf-8')
account = model[titer][C_ACCOUNT].decode('utf-8')
jid = model[titer][C_JID]
account = model[titer][C_ACCOUNT]
contact = gajim.contacts.get_contact_with_highest_priority(account, jid)
menu = Gtk.Menu()

View File

@ -90,7 +90,7 @@ class ChatControlSession(stanza_session.EncryptedStanzaSession):
msg_to_log = obj.msgtxt
obj.msg_id = gajim.logger.write(log_type, obj.fjid,
msg_to_log, tim=obj.timestamp, subject=obj.subject)
except exceptions.PysqliteOperationalError, e:
except exceptions.PysqliteOperationalError as e:
gajim.nec.push_incoming_event(InformationEvent(None,
conn=self.conn, level='error', pri_txt=_('Disk Write Error'),
sec_txt=str(e)))
@ -423,7 +423,7 @@ class ChatControlSession(stanza_session.EncryptedStanzaSession):
'submit':
try:
self.archiving_accepted(form)
except exceptions.NegotiationError, details:
except exceptions.NegotiationError as details:
self.fail_bad_negotiation(details)
return
@ -452,7 +452,7 @@ class ChatControlSession(stanza_session.EncryptedStanzaSession):
try:
self.accept_e2e_alice(form, negotiated)
except exceptions.NegotiationError, details:
except exceptions.NegotiationError as details:
self.fail_bad_negotiation(details)
def reject_nondefault_options():
@ -476,7 +476,7 @@ class ChatControlSession(stanza_session.EncryptedStanzaSession):
else:
try:
self.accept_e2e_alice(form, negotiated)
except exceptions.NegotiationError, details:
except exceptions.NegotiationError as details:
self.fail_bad_negotiation(details)
return
@ -484,21 +484,21 @@ class ChatControlSession(stanza_session.EncryptedStanzaSession):
'result':
try:
self.we_accept_archiving(form)
except exceptions.NegotiationError, details:
except exceptions.NegotiationError as details:
self.fail_bad_negotiation(details)
return
elif self.status == 'responded-e2e' and form.getType() == 'result':
try:
self.accept_e2e_bob(form)
except exceptions.NegotiationError, details:
except exceptions.NegotiationError as details:
self.fail_bad_negotiation(details)
return
elif self.status == 'identified-alice' and form.getType() == 'result':
try:
self.final_steps_alice(form)
except exceptions.NegotiationError, details:
except exceptions.NegotiationError as details:
self.fail_bad_negotiation(details)
return

View File

@ -477,7 +477,7 @@ class StatusIcon:
def on_change_status_message_activate(self, widget):
model = gajim.interface.roster.status_combobox.get_model()
active = gajim.interface.roster.status_combobox.get_active()
status = model[active][2].decode('utf-8')
status = model[active][2]
def on_response(message, pep_dict):
if message is None: # None if user press Cancel
return

View File

@ -235,13 +235,10 @@ class StatusTable:
self.current_row + 1)
def get_status_info(self, resource, priority, show, status):
str_status = resource + ' (' + unicode(priority) + ')'
str_status = resource + ' (' + str(priority) + ')'
if status:
status = status.strip()
if status != '':
# make sure 'status' is unicode before we send to to reduce_chars
if isinstance(status, str):
status = unicode(status, encoding='utf-8')
# reduce to 100 chars, 1 line
status = helpers.reduce_chars_newlines(status, 100, 1)
str_status = GObject.markup_escape_text(str_status)
@ -301,10 +298,6 @@ class NotificationAreaTooltip(BaseTooltip, StatusTable):
file_path = os.path.join(helpers.get_iconset_path(iconset), '16x16')
for acct in accounts:
message = acct['message']
# before reducing the chars we should assure we send unicode, else
# there are possible pango TBs on 'set_markup'
if isinstance(message, str):
message = unicode(message, encoding = 'utf-8')
message = helpers.reduce_chars_newlines(message, 100, 1)
message = GObject.markup_escape_text(message)
if acct['name'] in gajim.con_types and \
@ -606,7 +599,7 @@ class RosterTooltip(NotificationAreaTooltip):
if num_resources == 1 and contact.resource:
properties.append((_('Resource: '),
GObject.markup_escape_text(contact.resource) +\
' (' + unicode(contact.priority) + ')'))
' (' + str(contact.priority) + ')'))
if self.account and prim_contact.sub and prim_contact.sub != 'both' and\
prim_contact.jid not in gajim.gc_connected[self.account]:
@ -644,9 +637,9 @@ class RosterTooltip(NotificationAreaTooltip):
'tooltip_idle_color')
cs += '%s</span>'
properties.append((str(), None))
idle_since = helpers.ensure_utf8_string(cs % _("Idle since %s"))
idle_since = cs % _("Idle since %s")
properties.append((idle_since % formatted, None))
idle_for = helpers.ensure_utf8_string(cs % _("Idle for %s"))
idle_for = cs % _("Idle for %s")
properties.append((idle_for % str(diff), None))
while properties:
@ -670,7 +663,7 @@ class RosterTooltip(NotificationAreaTooltip):
vcard_current_row + 1, Gtk.AttachOptions.EXPAND | \
Gtk.AttachOptions.FILL, vertical_fill, 0, 0)
else:
if isinstance(property_[0], (unicode, str)): # FIXME: rm unicode?
if isinstance(property_[0], str):
label.set_markup(property_[0])
label.set_line_wrap(True)
else:
@ -743,7 +736,7 @@ class FileTransfersTooltip(BaseTooltip):
if file_props.type_ == 'r':
type_ = _('Download')
actor = _('Sender: ')
sender = unicode(file_props.sender).split('/')[0]
sender = file_props.sender.split('/')[0]
name = gajim.contacts.get_first_contact_from_jid(
file_props.tt_account, sender).get_shown_name()
else:

View File

@ -61,7 +61,7 @@ def get_avatar_pixbuf_encoded_mime(photo):
img_encoded = photo['BINVAL']
avatar_encoded = img_encoded
try:
img_decoded = base64.decodestring(img_encoded)
img_decoded = base64.b64decode(img_encoded.encode('utf-8')).decode('utf-8')
except Exception:
pass
if img_decoded:
@ -408,10 +408,10 @@ class VcardWindow:
tt_text = _("There is no pending subscription request.")
eb.set_tooltip_text(tt_text)
resources = '%s (%s)' % (self.contact.resource, unicode(
self.contact.priority))
resources = '%s (%s)' % (self.contact.resource, str(
self.contact.priority))
uf_resources = self.contact.resource + _(' resource with priority ')\
+ unicode(self.contact.priority)
+ str(self.contact.priority)
if not self.contact.status:
self.contact.status = ''
@ -462,9 +462,9 @@ class VcardWindow:
for c in contact_list:
if c.resource != self.contact.resource:
resources += '\n%s (%s)' % (c.resource,
unicode(c.priority))
str(c.priority))
uf_resources += '\n' + c.resource + \
_(' resource with priority ') + unicode(c.priority)
_(' resource with priority ') + str(c.priority)
if c.show not in ('offline', 'error'):
GObject.idle_add(
gajim.connections[self.account].request_os_info, c.jid,
@ -584,10 +584,10 @@ class ZeroconfVcardWindow:
'</span></b>')
self.xml.get_object('local_jid_label').set_text(self.contact.jid)
resources = '%s (%s)' % (self.contact.resource, unicode(
self.contact.priority))
resources = '%s (%s)' % (self.contact.resource, str(
self.contact.priority))
uf_resources = self.contact.resource + _(' resource with priority ')\
+ unicode(self.contact.priority)
+ str(self.contact.priority)
if not self.contact.status:
self.contact.status = ''

View File

@ -46,7 +46,7 @@ class TestResolver(unittest.TestCase):
def testLibAsyncNSResolver(self):
self._reset()
if not resolver.USE_LIBASYNCNS:
print 'testLibAsyncResolver: libasyncns-python not installed'
print('testLibAsyncResolver: libasyncns-python not installed')
return
self.resolver = resolver.LibAsyncNSResolver()

View File

@ -186,13 +186,13 @@ class TestRosterWindowMetaContacts(TestRosterWindowRegrouped):
def test_connect_new_metacontact(self):
self.test_fill_roster_model()
jid = u'coolstuff@gajim.org'
jid = 'coolstuff@gajim.org'
contact = gajim.contacts.create_contact(jid, account1)
gajim.contacts.add_contact(account1, contact)
self.roster.add_contact(jid, account1)
self.roster.chg_contact_status(contact, 'offline', '', account1)
gajim.contacts.add_metacontact(account1, u'samejid@gajim.org',
gajim.contacts.add_metacontact(account1, 'samejid@gajim.org',
account1, jid)
self.roster.chg_contact_status(contact, 'online', '', account1)

View File

@ -132,7 +132,7 @@ class TestNonBlockingClient(unittest.TestCase):
self.assert_(self.connection.con)
features = self.client.Dispatcher.Stream.features
if not features.getTag('auth'):
print "Server doesn't support old authentication type, ignoring test"
print("Server doesn't support old authentication type, ignoring test")
else:
self.assert_(self.connection.auth=='old_auth',
msg='Unable to auth via old_auth')

View File

@ -72,7 +72,7 @@ class TestNonBlockingTCP(AbstractTransportTest):
ips = socket.getaddrinfo('gajim.org', 5222,
socket.AF_UNSPEC, socket.SOCK_STREAM)
ip = ips[0]
except socket.error, e:
except socket.error as e:
self.testcase.fail(msg=str(e))
self.socket = transports_nb.NonBlockingTCP(

Some files were not shown because too many files have changed in this diff Show More