fix imports and many py3 changements

This commit is contained in:
Yann Leboulanger 2013-01-02 13:54:02 +01:00
parent d27591076f
commit 912f0e921d
60 changed files with 261 additions and 279 deletions

View File

@ -407,7 +407,7 @@ if dbus_support.supported:
return DBUS_DICT_SV() return DBUS_DICT_SV()
jid = self._get_real_jid(jid) 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: if cached_vcard:
return get_dbus_struct(cached_vcard) return get_dbus_struct(cached_vcard)

View File

@ -311,7 +311,6 @@ class AdvancedConfigurationWindow(object):
value = str(option) value = str(option)
except: except:
value = option value = option
value = helpers.ensure_utf8_string(value)
self.model.append(parent, [name, value, type_]) self.model.append(parent, [name, value, type_])
def visible_func(self, model, treeiter, data): def visible_func(self, model, treeiter, data):

View File

@ -1785,7 +1785,7 @@ class ChatControl(ChatControlBase):
pep = self.contact.pep pep = self.contact.pep
img = self._pep_images[pep_type] img = self._pep_images[pep_type]
if pep_type in pep: 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.set_tooltip_markup(pep[pep_type].asMarkupText())
img.show() img.show()
else: else:
@ -3020,7 +3020,7 @@ class ChatControl(ChatControlBase):
# It's why I set it transparent. # It's why I set it transparent.
image = self.xml.get_object('avatar_image') image = self.xml.get_object('avatar_image')
pixbuf = image.get_pixbuf() pixbuf = image.get_pixbuf()
pixbuf.fill(0xffffff00L) # RGBA pixbuf.fill(0xffffff00) # RGBA
image.queue_draw() image.queue_draw()
screen_w = Gdk.Screen.width() screen_w = Gdk.Screen.width()

View File

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

View File

@ -25,7 +25,7 @@ from inspect import getargspec, getdoc
from .dispatcher import Host, Container from .dispatcher import Host, Container
from .dispatcher import get_command, list_commands from .dispatcher import get_command, list_commands
from mmapping import parse_arguments, adapt_arguments from .mapping import parse_arguments, adapt_arguments
from .errors import DefinitionError, CommandError, NoCommandError from .errors import DefinitionError, CommandError, NoCommandError
class CommandHost(object): class CommandHost(object):
@ -153,7 +153,7 @@ class Command(object):
# Automatically set all the properties passed to a constructor # Automatically set all the properties passed to a constructor
# by the command decorator. # by the command decorator.
for key, value in properties.iteritems(): for key, value in properties.items():
setattr(self, key, value) setattr(self, key, value)
def __call__(self, *args, **kwargs): def __call__(self, *args, **kwargs):

View File

@ -35,7 +35,7 @@ commands as a frontend.
from subprocess import Popen, PIPE from subprocess import Popen, PIPE
from os.path import expanduser from os.path import expanduser
from glib import timeout_add from gi.repository import GObject
from ..framework import CommandContainer, command, doc from ..framework import CommandContainer, command, doc
from .hosts import * from .hosts import *
@ -64,7 +64,7 @@ class Execute(CommandContainer):
@classmethod @classmethod
def monitor(cls, processor, popen): def monitor(cls, processor, popen):
poller = cls.poller(processor, popen) poller = cls.poller(processor, popen)
timeout_add(cls.POLL_INTERVAL, poller.next) GObject.timeout_add(cls.POLL_INTERVAL, poller.next)
@classmethod @classmethod
def poller(cls, processor, popen): def poller(cls, processor, popen):

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. don't need to dig up the code itself to write basic commands.
""" """
from types import StringTypes
from traceback import print_exc from traceback import print_exc
from gi.repository import Pango from gi.repository import Pango
@ -98,7 +97,7 @@ class ChatCommandProcessor(CommandProcessor):
def command_postprocessor(self, command, name, arguments, args, kwargs, value): def command_postprocessor(self, command, name, arguments, args, kwargs, value):
# If command returns a string - print it to a user. A convenient # If command returns a string - print it to a user. A convenient
# and sufficient in most simple cases shortcut to a using echo. # 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) self.echo(value)
class CommandTools: class CommandTools:

View File

@ -23,7 +23,6 @@ according to the command properties.
""" """
import re import re
from types import BooleanType, UnicodeType
from operator import itemgetter from operator import itemgetter
from .errors import DefinitionError, CommandError from .errors import DefinitionError, CommandError
@ -62,7 +61,7 @@ def parse_arguments(arguments):
""" """
args, opts = [], [] 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. Check if given span intersects with any of options.
""" """
@ -71,7 +70,7 @@ def parse_arguments(arguments):
return True return True
return False 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. 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 # conflicted sectors. Remove any arguments that intersect with
# options. # options.
for arg, position in args[:]: for arg, position in args[:]:
if intersects_opts(position): if intersects_opts(*position):
args.remove((arg, position)) args.remove((arg, position))
# Primitive but sufficiently effective way of disposing of # Primitive but sufficiently effective way of disposing of
# conflicted sectors. Remove any options that intersect with # conflicted sectors. Remove any options that intersect with
# arguments. # arguments.
for key, value, position in opts[:]: for key, value, position in opts[:]:
if intersects_args(position): if intersects_args(*position):
opts.remove((key, value, position)) opts.remove((key, value, position))
return args, opts return args, opts
@ -207,7 +206,7 @@ def adapt_arguments(command, arguments, args, opts):
# corresponding optin has been given. # corresponding optin has been given.
if command.expand: if command.expand:
expanded = [] 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 letter = spec_key[0] if len(spec_key) > 1 else None
if letter and letter not in expanded: if letter and letter not in expanded:
for index, (key, value, position) in enumerate(opts): 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 # Detect switches and set their values accordingly. If any of them
# carries a value - append it to args. # carries a value - append it to args.
for index, (key, value, position) in enumerate(opts): 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) opts[index] = (key, True, position)
if value: if value:
args.append((value, position)) args.append((value, position))
@ -231,8 +230,8 @@ def adapt_arguments(command, arguments, args, opts):
# Stripping down position information supplied with arguments and # Stripping down position information supplied with arguments and
# options as it won't be needed again. # options as it won't be needed again.
args = map(lambda (arg, position): arg, args) args = map(lambda t: t[0], t[1])
opts = map(lambda (key, value, position): (key, value), opts) opts = map(lambda t: (t[0], t[1]), opts)
# If command has extra option enabled - collect all extra arguments # If command has extra option enabled - collect all extra arguments
# and pass them to a last positional argument command defines as a # and pass them to a last positional argument command defines as a
@ -265,8 +264,8 @@ def adapt_arguments(command, arguments, args, opts):
# Normally this does not happen unless overlapping is enabled. # Normally this does not happen unless overlapping is enabled.
for key, value in opts: for key, value in opts:
initial = norm_kwargs.get(key) initial = norm_kwargs.get(key)
if isinstance(initial, BooleanType): if isinstance(initial, bool):
if not isinstance(value, BooleanType): if not isinstance(value, bool):
raise CommandError("%s: Switch can not take an argument" % key, command) raise CommandError("%s: Switch can not take an argument" % key, command)
# Inject the source arguments as a string as a first argument, if # Inject the source arguments as a string as a first argument, if
@ -299,7 +298,7 @@ def generate_usage(command, complete=True):
letter = key[0] letter = key[0]
key = key.replace('_', '-') key = key.replace('_', '-')
if isinstance(value, BooleanType): if isinstance(value, bool):
value = str() value = str()
else: else:
value = '=%s' % value value = '=%s' % value

View File

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

View File

@ -38,7 +38,7 @@ import sqlite3 as sqlite
def create_log_db(): def create_log_db():
print(_('creating logs database')) print(_('creating logs database'))
con = sqlite.connect(logger.LOG_DB_PATH) 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() cur = con.cursor()
# create the tables # create the tables
# kind can be # kind can be
@ -86,7 +86,7 @@ def create_log_db():
def create_cache_db(): def create_cache_db():
print(_('creating cache database')) print(_('creating cache database'))
con = sqlite.connect(logger.CACHE_DB_PATH) 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 = con.cursor()
cur.executescript( cur.executescript(
''' '''
@ -177,7 +177,7 @@ def check_and_possibly_move_config():
vars['MY_ICONSETS_PATH'] = gajim.MY_ICONSETS_PATH vars['MY_ICONSETS_PATH'] = gajim.MY_ICONSETS_PATH
vars['MY_MOOD_ICONSETS_PATH'] = gajim.MY_MOOD_ICONSETS_PATH vars['MY_MOOD_ICONSETS_PATH'] = gajim.MY_MOOD_ICONSETS_PATH
vars['MY_ACTIVITY_ICONSETS_PATH'] = gajim.MY_ACTIVITY_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_DATA = configpaths.gajimpaths['MY_DATA']
MY_CONFIG = configpaths.gajimpaths['MY_CONFIG'] MY_CONFIG = configpaths.gajimpaths['MY_CONFIG']
MY_CACHE = configpaths.gajimpaths['MY_CACHE'] MY_CACHE = configpaths.gajimpaths['MY_CACHE']
@ -263,7 +263,7 @@ def check_and_possibly_create_paths():
VCARD_PATH = gajim.VCARD_PATH VCARD_PATH = gajim.VCARD_PATH
AVATAR_PATH = gajim.AVATAR_PATH AVATAR_PATH = gajim.AVATAR_PATH
import configpaths from common import configpaths
MY_DATA = configpaths.gajimpaths['MY_DATA'] MY_DATA = configpaths.gajimpaths['MY_DATA']
MY_CONFIG = configpaths.gajimpaths['MY_CONFIG'] MY_CONFIG = configpaths.gajimpaths['MY_CONFIG']
MY_CACHE = configpaths.gajimpaths['MY_CACHE'] MY_CACHE = configpaths.gajimpaths['MY_CACHE']
@ -364,4 +364,4 @@ def create_path(directory):
if os.path.exists(directory): if os.path.exists(directory):
return return
print(('creating %s directory') % directory) print(('creating %s directory') % directory)
os.mkdir(directory, 0700) os.mkdir(directory, 0o700)

View File

@ -363,7 +363,7 @@ class ConnectionCommands:
# buildReply don't copy the node attribute. Re-add it # buildReply don't copy the node attribute. Re-add it
q.setAttr('node', nbxmpp.NS_COMMANDS) 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)): if cmd.isVisibleFor(self.isSameJID(jid)):
q.addChild('item', { q.addChild('item', {
# TODO: find the jid # TODO: find the jid

View File

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

View File

@ -25,7 +25,7 @@
import os import os
import sys import sys
import tempfile import tempfile
import defs from common import defs
HAVE_XDG = True HAVE_XDG = True
try: try:
__import__(xdg) __import__(xdg)
@ -130,7 +130,7 @@ class ConfigPaths:
except KeyError: except KeyError:
return default return default
def iteritems(self): def items(self):
for key in self.paths.iterkeys(): for key in self.paths.iterkeys():
yield (key, self[key]) yield (key, self[key])

View File

@ -59,7 +59,7 @@ from common import gpg
from common import passwords from common import passwords
from common import exceptions from common import exceptions
from common import check_X509 from common import check_X509
from connection_handlers import * from common.connection_handlers import *
from nbxmpp import Smacks from nbxmpp import Smacks
from string import Template from string import Template

View File

@ -322,7 +322,7 @@ class ConnectionVcard:
os.remove(path) os.remove(path)
# create folder if needed # create folder if needed
if not os.path.isdir(path): if not os.path.isdir(path):
os.mkdir(path, 0700) os.mkdir(path, 0o700)
puny_nick = helpers.sanitize_filename(nick) puny_nick = helpers.sanitize_filename(nick)
path_to_file = os.path.join(gajim.VCARD_PATH, puny_jid, puny_nick) path_to_file = os.path.join(gajim.VCARD_PATH, puny_jid, puny_nick)
else: else:
@ -706,7 +706,7 @@ class ConnectionVcard:
puny_nick = helpers.sanitize_filename(resource) puny_nick = helpers.sanitize_filename(resource)
# create folder if needed # create folder if needed
if not os.path.isdir(begin_path): 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) begin_path = os.path.join(begin_path, puny_nick)
frm_jid += '/' + resource frm_jid += '/' + resource
if photo_decoded: if photo_decoded:

View File

@ -39,8 +39,6 @@ from nbxmpp.protocol import NS_CHATSTATES
from common.jingle_transport import JingleTransportSocks5 from common.jingle_transport import JingleTransportSocks5
from common.file_props import FilesProp from common.file_props import FilesProp
from . import gtkgui_helpers
import logging import logging
log = logging.getLogger('gajim.c.connection_handlers_events') log = logging.getLogger('gajim.c.connection_handlers_events')
@ -2181,8 +2179,6 @@ class NotificationEvent(nec.NetworkIncomingEvent):
self.popup_title = _('New Message from %(nickname)s') % \ self.popup_title = _('New Message from %(nickname)s') % \
{'nickname': nick} {'nickname': nick}
self.popup_image = gtkgui_helpers.get_icon_path(self.popup_image, 48)
if not gajim.config.get('notify_on_new_message') or \ if not gajim.config.get('notify_on_new_message') or \
not self.first_unread: not self.first_unread:
self.do_popup = False self.do_popup = False
@ -2237,6 +2233,28 @@ class NotificationEvent(nec.NetworkIncomingEvent):
self.do_popup = False 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): def handle_incoming_pres_event(self, pres_obj):
if gajim.jid_is_transport(pres_obj.jid): if gajim.jid_is_transport(pres_obj.jid):
return True return True
@ -2315,8 +2333,8 @@ class NotificationEvent(nec.NetworkIncomingEvent):
iconset = gajim.config.get('iconset') iconset = gajim.config.get('iconset')
img_path = os.path.join(helpers.get_iconset_path(iconset), img_path = os.path.join(helpers.get_iconset_path(iconset),
'48x48', show_image) '48x48', show_image)
self.popup_image = gtkgui_helpers.get_path_to_generic_or_avatar( self.popup_image = self.get_path_to_generic_or_avatar(img_path,
img_path, jid=self.jid, suffix=suffix) jid=self.jid, suffix=suffix)
self.popup_timeout = gajim.config.get('notification_timeout') self.popup_timeout = gajim.config.get('notification_timeout')

View File

@ -94,6 +94,8 @@ class Contact(CommonContact):
sub='', ask='', resource='', priority=0, keyID='', client_caps=None, sub='', ask='', resource='', priority=0, keyID='', client_caps=None,
our_chatstate=None, chatstate=None, last_status_time=None, msg_id=None, our_chatstate=None, chatstate=None, last_status_time=None, msg_id=None,
last_activity_time=None): last_activity_time=None):
if not isinstance(jid, str):
print('no str')
CommonContact.__init__(self, jid, account, resource, show, status, name, CommonContact.__init__(self, jid, account, resource, show, status, name,
our_chatstate, chatstate, client_caps=client_caps) our_chatstate, chatstate, client_caps=client_caps)
@ -494,7 +496,7 @@ class Contacts():
return self._contacts.keys() return self._contacts.keys()
def get_contacts_jid_list(self): 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()] contact[0].is_groupchat()]
def get_contact_from_full_jid(self, fjid): def get_contact_from_full_jid(self, fjid):

View File

@ -34,7 +34,7 @@ import locale
from common import config from common import config
import nbxmpp import nbxmpp
from common import defs from common import defs
from common import ged from common import ged as ged_module
interface = None # The actual interface (the gtk one for the moment) interface = None # The actual interface (the gtk one for the moment)
thread_interface = None # Interface to run a thread and then a callback 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' connections = {} # 'account name': 'account (connection.Connection) instance'
ipython_window = None ipython_window = None
ged = common.ged.GlobalEventsDispatcher() # Global Events Dispatcher ged = ged_module.GlobalEventsDispatcher() # Global Events Dispatcher
nec = None # Network Events Controller nec = None # Network Events Controller
plugin_manager = None # Plugins Manager plugin_manager = None # Plugins Manager
log = logging.getLogger('gajim') log = logging.getLogger('gajim')
import logger logger = None
logger = logger.Logger() # init the logger
import configpaths from common import configpaths
gajimpaths = configpaths.gajimpaths gajimpaths = configpaths.gajimpaths
VCARD_PATH = gajimpaths['VCARD'] VCARD_PATH = gajimpaths['VCARD']
@ -84,8 +83,8 @@ else:
os_info = None # used to cache os information os_info = None # used to cache os information
from contacts import LegacyContactsAPI from common.contacts import LegacyContactsAPI
from events import Events from common.events import Events
gmail_domains = ['gmail.com', 'googlemail.com'] gmail_domains = ['gmail.com', 'googlemail.com']
@ -221,9 +220,6 @@ gajim_optional_features = {}
# Capabilities hash per account # Capabilities hash per account
caps_hash = {} caps_hash = {}
import caps_cache
caps_cache.initialize(logger)
global_id = 0 global_id = 0
def get_an_id(): def get_an_id():
global global_id global global_id

View File

@ -22,7 +22,7 @@
## along with Gajim. If not, see <http://www.gnu.org/licenses/>. ## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
## ##
from gajim import HAVE_GPG from common.gajim import HAVE_GPG
import os import os
if HAVE_GPG: if HAVE_GPG:

View File

@ -35,7 +35,7 @@ import locale
import os import os
import subprocess import subprocess
import urllib import urllib
import urllib2 import urllib
import webbrowser import webbrowser
import errno import errno
import select import select
@ -50,8 +50,8 @@ from gi.repository import GObject
from encodings.punycode import punycode_encode from encodings.punycode import punycode_encode
from string import Template from string import Template
from i18n import Q_ from common.i18n import Q_
from i18n import ngettext from common.i18n import ngettext
try: try:
import winsound # windows-only built-in module for playing wav import winsound # windows-only built-in module for playing wav
@ -122,7 +122,7 @@ def idn_to_ascii(host):
labels = idna.dots.split(host) labels = idna.dots.split(host)
converted_labels = [] converted_labels = []
for label in labels: for label in labels:
converted_labels.append(idna.ToASCII(label)) converted_labels.append(idna.ToASCII(label).decode('utf-8'))
return ".".join(converted_labels) return ".".join(converted_labels)
def ascii_to_idn(host): def ascii_to_idn(host):
@ -146,7 +146,7 @@ def parse_resource(resource):
from nbxmpp.stringprepare import resourceprep from nbxmpp.stringprepare import resourceprep
return resourceprep.prepare(resource) return resourceprep.prepare(resource)
except UnicodeError: except UnicodeError:
raise InvalidFormat, 'Invalid character in resource.' raise InvalidFormat('Invalid character in resource.')
def prep(user, server, 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 #http://svn.twistedmatrix.com/cvs/trunk/twisted/words/protocols/jabber/jid.py
if user is not None: if user is not None:
if len(user) < 1 or len(user) > 1023: 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: try:
from nbxmpp.stringprepare import nodeprep from nbxmpp.stringprepare import nodeprep
user = nodeprep.prepare(user) user = nodeprep.prepare(user)
except UnicodeError: except UnicodeError:
raise InvalidFormat, _('Invalid character in username.') raise InvalidFormat(_('Invalid character in username.'))
else: else:
user = None user = None
if server is not None: if server is not None:
if len(server) < 1 or len(server) > 1023: 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: try:
from nbxmpp.stringprepare import nameprep from nbxmpp.stringprepare import nameprep
server = nameprep.prepare(server) server = nameprep.prepare(server)
except UnicodeError: except UnicodeError:
raise InvalidFormat, _('Invalid character in hostname.') raise InvalidFormat(_('Invalid character in hostname.'))
else: else:
raise InvalidFormat, _('Server address required.') raise InvalidFormat(_('Server address required.'))
if resource is not None: if resource is not None:
if len(resource) < 1 or len(resource) > 1023: 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: try:
from nbxmpp.stringprepare import resourceprep from nbxmpp.stringprepare import resourceprep
resource = resourceprep.prepare(resource) resource = resourceprep.prepare(resource)
except UnicodeError: except UnicodeError:
raise InvalidFormat, _('Invalid character in resource.') raise InvalidFormat(_('Invalid character in resource.'))
else: else:
resource = None resource = None
@ -493,7 +493,7 @@ def get_windows_reg_env(varname, default=''):
'AppData' = %USERPROFILE%\Application Data (also an ENV) 'AppData' = %USERPROFILE%\Application Data (also an ENV)
'Desktop' = %USERPROFILE%\Desktop 'Desktop' = %USERPROFILE%\Desktop
'Favorites' = %USERPROFILE%\Favorites 'Favorites' = %USERPROFILE%\Favorites
'NetHood' = %USERPROFILE%\NetHood 'NetHood' = %USERPROFILE%\ NetHood
'Personal' = D:\My Documents (PATH TO MY DOCUMENTS) 'Personal' = D:\My Documents (PATH TO MY DOCUMENTS)
'PrintHood' = %USERPROFILE%\PrintHood 'PrintHood' = %USERPROFILE%\PrintHood
'Programs' = %USERPROFILE%\Start Menu\Programs 'Programs' = %USERPROFILE%\Start Menu\Programs
@ -555,7 +555,8 @@ def sanitize_filename(filename):
hash = hashlib.md5(filename) hash = hashlib.md5(filename)
filename = base64.b64encode(hash.digest()) 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('/', '_') filename = filename.replace('/', '_')
if os.name == 'nt': if os.name == 'nt':
filename = filename.replace('?', '_').replace(':', '_')\ filename = filename.replace('?', '_').replace(':', '_')\
@ -634,10 +635,10 @@ def datetime_tuple(timestamp):
# import gajim only when needed (after decode_string is defined) see #4764 # import gajim only when needed (after decode_string is defined) see #4764
import gajim from common import gajim
if gajim.HAVE_PYCURL: if gajim.HAVE_PYCURL:
import pycurl import pycurl
from cStringIO import StringIO from io import StringIO
def convert_bytes(string): def convert_bytes(string):
suffix = '' suffix = ''
@ -1462,9 +1463,9 @@ def _get_img_direct(attrs):
# Wait maximum 5s for connection # Wait maximum 5s for connection
socket.setdefaulttimeout(5) socket.setdefaulttimeout(5)
try: try:
req = urllib2.Request(attrs['src']) req = urllib.request.Request(attrs['src'])
req.add_header('User-Agent', 'Gajim ' + gajim.version) req.add_header('User-Agent', 'Gajim ' + gajim.version)
f = urllib2.urlopen(req) f = urllib.request.urlopen(req)
except Exception as ex: except Exception as ex:
log.debug('Error loading image %s ' % attrs['src'] + str(ex)) log.debug('Error loading image %s ' % attrs['src'] + str(ex))
pixbuf = None pixbuf = None

View File

@ -63,7 +63,7 @@ if os.name == 'nt':
gettext.install(APP, DIR) gettext.install(APP, DIR)
if gettext._translations: if gettext._translations:
_translation = gettext._translations.values()[0] _translation = list(gettext._translations.values())[0]
else: else:
_translation = gettext.NullTranslations() _translation = gettext.NullTranslations()

View File

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

View File

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

View File

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

View File

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

View File

@ -21,14 +21,15 @@ from gi.repository import GObject
import socket import socket
import nbxmpp import nbxmpp
import farstream, gst import farstream
import gst
from glib import GError from glib import GError
import gajim from common import gajim
from jingle_transport import JingleTransportICEUDP from common.jingle_transport import JingleTransportICEUDP
from jingle_content import contents, JingleContent, JingleContentSetupException from common.jingle_content import contents, JingleContent, JingleContentSetupException
from connection_handlers_events import InformationEvent from common.connection_handlers_events import InformationEvent
import logging import logging

View File

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

View File

@ -296,7 +296,7 @@ class JingleTransportSocks5(JingleTransport):
cid = host['candidate_id'] cid = host['candidate_id']
break break
if cid is None: if cid is None:
raise Exception, 'cid is missing' raise Exception('cid is missing')
activated.setAttr('cid', cid) activated.setAttr('cid', cid)
transport.addChild(node=activated) transport.addChild(node=activated)
content.addChild(node=transport) content.addChild(node=transport)

View File

@ -20,7 +20,6 @@ import os
import nbxmpp import nbxmpp
import logging import logging
import common
from common import gajim from common import gajim
log = logging.getLogger('gajim.c.jingle_xtls') log = logging.getLogger('gajim.c.jingle_xtls')
@ -201,7 +200,7 @@ def createCertRequest(pkey, digest="md5", **name):
req.sign(pkey, digest) req.sign(pkey, digest)
return req 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. Generate a certificate given a certificate request.
@ -235,7 +234,7 @@ def make_certs(filepath, CN):
""" """
key = createKeyPair(TYPE_RSA, 1024) key = createKeyPair(TYPE_RSA, 1024)
req = createCertRequest(key, CN=CN) 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( open(filepath + '.pkey', 'w').write(crypto.dump_privatekey(
crypto.FILETYPE_PEM, key)) crypto.FILETYPE_PEM, key))
open(filepath + '.cert', 'w').write(crypto.dump_certificate( open(filepath + '.cert', 'w').write(crypto.dump_certificate(

View File

@ -33,16 +33,16 @@ import sys
import time import time
import datetime import datetime
from gzip import GzipFile from gzip import GzipFile
from cStringIO import StringIO from io import BytesIO
from gi.repository import GObject from gi.repository import GObject
import exceptions from common import exceptions
import gajim from common import gajim
import ged from common import ged
import sqlite3 as sqlite import sqlite3 as sqlite
import configpaths from common import configpaths
LOG_DB_PATH = configpaths.gajimpaths['LOG_DB'] LOG_DB_PATH = configpaths.gajimpaths['LOG_DB']
LOG_DB_FOLDER, LOG_DB_FILE = os.path.split(LOG_DB_PATH) LOG_DB_FOLDER, LOG_DB_FILE = os.path.split(LOG_DB_PATH)
CACHE_DB_PATH = configpaths.gajimpaths['CACHE_DB'] CACHE_DB_PATH = configpaths.gajimpaths['CACHE_DB']
@ -884,7 +884,7 @@ class Logger:
# ..., 'FEAT', feature1, feature2, ...).join(' ')) # ..., 'FEAT', feature1, feature2, ...).join(' '))
# NOTE: if there's a need to do more gzip, put that to a function # NOTE: if there's a need to do more gzip, put that to a function
try: try:
data = GzipFile(fileobj=StringIO(str(data))).read().split('\0') data = GzipFile(fileobj=BytesIO(data)).read().decode('utf-8').split('\0')
except IOError: except IOError:
# This data is corrupted. It probably contains non-ascii chars # This data is corrupted. It probably contains non-ascii chars
to_be_removed.append((hash_method, hash_)) to_be_removed.append((hash_method, hash_))
@ -1046,8 +1046,8 @@ class Logger:
FROM roster_entry re, jids j FROM roster_entry re, jids j
WHERE re.account_jid_id=? AND j.jid_id=re.jid_id''', (account_jid_id,)) 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: for jid, jid_id, name, subscription, ask in self.cur:
jid = jid.encode('utf-8') jid = jid
name = name.encode('utf-8') name = name
data[jid] = {} data[jid] = {}
if name: if name:
data[jid]['name'] = name data[jid]['name'] = name
@ -1071,7 +1071,7 @@ class Logger:
WHERE account_jid_id=? AND jid_id=?''', WHERE account_jid_id=? AND jid_id=?''',
(account_jid_id, data[jid]['id'])) (account_jid_id, data[jid]['id']))
for (group_name,) in self.cur: for (group_name,) in self.cur:
group_name = group_name.encode('utf-8') group_name = group_name
data[jid]['groups'].append(group_name) data[jid]['groups'].append(group_name)
del data[jid]['id'] del data[jid]['id']

View File

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

View File

@ -36,7 +36,7 @@ from common import helpers
from common import caps_cache from common import caps_cache
import sqlite3 as sqlite import sqlite3 as sqlite
import logger from common import logger
class OptionsParser: class OptionsParser:
def __init__(self, filename): def __init__(self, filename):
@ -60,10 +60,6 @@ class OptionsParser:
regex = re.compile(r"(?P<optname>[^.]+)(?:(?:\.(?P<key>.+))?\.(?P<subname>[^.]+))?\s=\s(?P<value>.*)") regex = re.compile(r"(?P<optname>[^.]+)(?:(?:\.(?P<key>.+))?\.(?P<subname>[^.]+))?\s=\s(?P<value>.*)")
for line in fd: for line in fd:
try:
line = helpers.ensure_utf8_string(line)
except UnicodeDecodeError:
line = line.decode(locale.getpreferredencoding())
optname, key, subname, value = regex.match(line).groups() optname, key, subname, value = regex.match(line).groups()
if key is None: if key is None:
self.old_values[optname] = value self.old_values[optname] = value
@ -122,7 +118,7 @@ class OptionsParser:
os.rename(self.__tempfile, self.__filename) os.rename(self.__tempfile, self.__filename)
except IOError as e: except IOError as e:
return str(e) return str(e)
os.chmod(self.__filename, 0600) os.chmod(self.__filename, 0o600)
def update_config(self, old_version, new_version): def update_config(self, old_version, new_version):
old_version_list = old_version.split('.') # convert '0.x.y' to (0, x, y) old_version_list = old_version.split('.') # convert '0.x.y' to (0, x, y)

View File

@ -225,8 +225,6 @@ from common import helpers
import nbxmpp import nbxmpp
from common import gajim from common import gajim
import gtkgui_helpers
class AbstractPEP(object): class AbstractPEP(object):
@ -269,10 +267,6 @@ class AbstractPEP(object):
else: else:
acc.pep[self.type_] = self acc.pep[self.type_] = self
def asPixbufIcon(self):
'''SHOULD be implemented by subclasses'''
return None
def asMarkupText(self): def asMarkupText(self):
'''SHOULD be implemented by subclasses''' '''SHOULD be implemented by subclasses'''
return '' return ''
@ -300,13 +294,6 @@ class UserMoodPEP(AbstractPEP):
retracted = items.getTag('retract') or not 'mood' in mood_dict retracted = items.getTag('retract') or not 'mood' in mood_dict
return (mood_dict, retracted) 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): def asMarkupText(self):
assert not self._retracted assert not self._retracted
untranslated_mood = self._pep_specific_data['mood'] untranslated_mood = self._pep_specific_data['mood']
@ -346,11 +333,6 @@ class UserTunePEP(AbstractPEP):
'title' in tune_dict) 'title' in tune_dict)
return (tune_dict, retracted) 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): def asMarkupText(self):
assert not self._retracted assert not self._retracted
tune = self._pep_specific_data tune = self._pep_specific_data
@ -396,24 +378,6 @@ class UserActivityPEP(AbstractPEP):
retracted = items.getTag('retract') or not 'activity' in activity_dict retracted = items.getTag('retract') or not 'activity' in activity_dict
return (activity_dict, retracted) 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): def asMarkupText(self):
assert not self._retracted assert not self._retracted
pep = self._pep_specific_data pep = self._pep_specific_data
@ -491,10 +455,6 @@ class UserLocationPEP(AbstractPEP):
con = gajim.connections[account].location_info = \ con = gajim.connections[account].location_info = \
self._pep_specific_data 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): def asMarkupText(self):
assert not self._retracted assert not self._retracted
location = self._pep_specific_data location = self._pep_specific_data

View File

@ -898,7 +898,7 @@ class ConnectionIBBytestream(ConnectionBytestream):
else: else:
if not data: if not data:
err = nbxmpp.ERR_BAD_REQUEST err = nbxmpp.ERR_BAD_REQUEST
elif seq <> file_props.seq: elif seq != file_props.seq:
err = nbxmpp.ERR_UNEXPECTED_REQUEST err = nbxmpp.ERR_UNEXPECTED_REQUEST
else: else:
log.debug('Successfull receive sid->%s %s+%s bytes' % (sid, log.debug('Successfull receive sid->%s %s+%s bytes' % (sid,

View File

@ -29,7 +29,7 @@ log = logging.getLogger('gajim.c.proxy65_manager')
import nbxmpp import nbxmpp
from common import gajim from common import gajim
from common import helpers from common import helpers
from socks5 import Socks5 from common.socks5 import Socks5
from nbxmpp.idlequeue import IdleObject from nbxmpp.idlequeue import IdleObject
from common.file_props import FilesProp from common.file_props import FilesProp

View File

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

View File

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

View File

@ -33,9 +33,9 @@ from errno import EISCONN
from errno import EINPROGRESS from errno import EINPROGRESS
from errno import EAFNOSUPPORT from errno import EAFNOSUPPORT
from nbxmpp.idlequeue import IdleObject from nbxmpp.idlequeue import IdleObject
from file_props import FilesProp from common.file_props import FilesProp
from common import gajim from common import gajim
import jingle_xtls from common import jingle_xtls
if jingle_xtls.PYOPENSSL_PRESENT: if jingle_xtls.PYOPENSSL_PRESENT:
import OpenSSL import OpenSSL
import logging import logging
@ -535,7 +535,7 @@ class Socks5:
self.file_props.received_len = self.size self.file_props.received_len = self.size
except IOError as e: except IOError as e:
self.close_file() self.close_file()
raise IOError, e raise IOError(str(e))
def close_file(self): def close_file(self):
if self.file: if self.file:

View File

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

View File

@ -46,7 +46,7 @@ from common import gajim
from common import ged from common import ged
from common.zeroconf import client_zeroconf from common.zeroconf import client_zeroconf
from common.zeroconf import zeroconf from common.zeroconf import zeroconf
from connection_handlers_zeroconf import * from common.zeroconf.connection_handlers_zeroconf import *
from common.connection_handlers_events import * from common.connection_handlers_events import *
import locale import locale

View File

@ -239,7 +239,7 @@ class Zeroconf:
txt = {} txt = {}
# remove empty keys # remove empty keys
for key, val in self.txt.iteritems(): for key, val in self.txt.items():
if val: if val:
txt[key] = val txt[key] = val

View File

@ -455,8 +455,8 @@ class PreferencesWindow:
else: else:
config = gajim.config.get(opt_name + '_device') config = gajim.config.get(opt_name + '_device')
for index, (name, value) in enumerate(sorted(device_dict.\ for index, (name, value) in enumerate(sorted(device_dict.items(),
iteritems(), key=key)): key=key)):
model.append((name, value)) model.append((name, value))
if config == value: if config == value:
combobox.set_active(index) combobox.set_active(index)

View File

@ -38,7 +38,7 @@ import os
import tooltips import tooltips
import dialogs import dialogs
import locale import locale
import Queue import queue
import urllib import urllib
import gtkgui_helpers import gtkgui_helpers
@ -335,7 +335,7 @@ class ConversationTextview(GObject.GObject):
# One mark at the begining then 2 marks between each lines # One mark at the begining then 2 marks between each lines
size = gajim.config.get('max_conversation_lines') size = gajim.config.get('max_conversation_lines')
size = 2 * size - 1 size = 2 * size - 1
self.marks_queue = Queue.Queue(size) self.marks_queue = queue.Queue(size)
self.allow_focus_out_line = True self.allow_focus_out_line = True
# holds a mark at the end of --- line # holds a mark at the end of --- line
@ -709,7 +709,7 @@ class ConversationTextview(GObject.GObject):
buffer_.delete(start, end) buffer_.delete(start, end)
size = gajim.config.get('max_conversation_lines') size = gajim.config.get('max_conversation_lines')
size = 2 * size - 1 size = 2 * size - 1
self.marks_queue = Queue.Queue(size) self.marks_queue = queue.Queue(size)
self.focus_out_end_mark = None self.focus_out_end_mark = None
self.just_cleared = True self.just_cleared = True
@ -1171,7 +1171,7 @@ class ConversationTextview(GObject.GObject):
all_tags = [(ttt.lookup(t) if isinstance(t, str) else t) for t in all_tags] 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) buffer_.insert_with_tags(end_iter, special_text, *all_tags)
if 'url' in 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('-'): if not puny_text.endswith('-'):
end_iter = buffer_.get_end_iter() end_iter = buffer_.get_end_iter()
buffer_.insert(end_iter, " (%s)" % puny_text) buffer_.insert(end_iter, " (%s)" % puny_text)

View File

@ -1297,13 +1297,12 @@ class AboutDialog:
if thanks_file_path: if thanks_file_path:
authors.append('\n' + _('THANKS:')) 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_splitted = text.split('\n')
text = '\n'.join(text_splitted[:-2]) # remove one english sentence text = '\n'.join(text_splitted[:-2]) # remove one english sentence
# and add it manually as translatable # and add it manually as translatable
text += helpers.ensure_utf8_string('\n%s\n' % _('Last but not ' text += '\n%s\n' % _('Last but not least, we would like to '
'least, we would like to thank all the package maintainers.' 'thank all the package maintainers.')
))
authors.append(text) authors.append(text)
dlg.set_authors(authors) dlg.set_authors(authors)
@ -2322,13 +2321,13 @@ class JoinGroupchatWindow:
if room_jid != '' and room_jid in gajim.gc_connected[account] and\ if room_jid != '' and room_jid in gajim.gc_connected[account] and\
gajim.gc_connected[account][room_jid]: gajim.gc_connected[account][room_jid]:
ErrorDialog(_('You are already in group chat %s') % 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 == '': if nick == '':
nick = gajim.nicks[account] nick = gajim.nicks[account]
if gajim.connections[account].connected < 2: if gajim.connections[account].connected < 2:
ErrorDialog(_('You are not connected to the server'), ErrorDialog(_('You are not connected to the server'),
_('You can not join a group chat unless you are connected.')) _('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') self.xml = gtkgui_helpers.get_gtk_builder('join_groupchat_window.ui')
@ -2565,7 +2564,7 @@ class SynchroniseSelectAccountDialog:
if not account or gajim.connections[account].connected < 2: if not account or gajim.connections[account].connected < 2:
ErrorDialog(_('You are not connected to the server'), ErrorDialog(_('You are not connected to the server'),
_('Without a connection, you can not synchronise your contacts.')) _('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.account = account
self.xml = gtkgui_helpers.get_gtk_builder('synchronise_select_account_dialog.ui') self.xml = gtkgui_helpers.get_gtk_builder('synchronise_select_account_dialog.ui')
self.dialog = self.xml.get_object('synchronise_select_account_dialog') self.dialog = self.xml.get_object('synchronise_select_account_dialog')
@ -2754,7 +2753,7 @@ class ChangePasswordDialog:
if not account or gajim.connections[account].connected < 2: if not account or gajim.connections[account].connected < 2:
ErrorDialog(_('You are not connected to the server'), ErrorDialog(_('You are not connected to the server'),
_('Without a connection, you can not change your password.')) _('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.account = account
self.on_response = on_response self.on_response = on_response
self.xml = gtkgui_helpers.get_gtk_builder('change_password_dialog.ui') self.xml = gtkgui_helpers.get_gtk_builder('change_password_dialog.ui')

View File

@ -223,7 +223,7 @@ class Closure(object):
self.removeargs = removeargs self.removeargs = removeargs
if isinstance(cb, types.MethodType): if isinstance(cb, types.MethodType):
self.meth_self = weakref.ref(cb.im_self, self._remove) self.meth_self = weakref.ref(cb.im_self, self._remove)
self.meth_name = cb.func_name self.meth_name = cb.__name__
elif callable(cb): elif callable(cb):
self.meth_self = None self.meth_self = None
self.cb = weakref.ref(cb, self._remove) self.cb = weakref.ref(cb, self._remove)
@ -515,7 +515,7 @@ class ServiceDiscoveryWindow(object):
if gajim.connections[account].connected < 2: if gajim.connections[account].connected < 2:
dialogs.ErrorDialog(_('You are not connected to the server'), dialogs.ErrorDialog(_('You are not connected to the server'),
_('Without a connection, you can not browse available services')) _('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. # Get a ServicesCache object.
try: try:

View File

@ -219,6 +219,10 @@ except exceptions.DatabaseMalformed:
'http://trac.gajim.org/wiki/DatabaseBackup) or remove it (all history ' 'http://trac.gajim.org/wiki/DatabaseBackup) or remove it (all history '
'will be lost).') % common.logger.LOG_DB_PATH 'will be lost).') % common.logger.LOG_DB_PATH
else: else:
from common import logger
gajim.logger = logger.Logger()
from common import caps_cache
caps_cache.initialize(gajim.logger)
from common import dbus_support from common import dbus_support
if dbus_support.supported: if dbus_support.supported:
from music_track_listener import MusicTrackListener from music_track_listener import MusicTrackListener

View File

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

View File

@ -41,6 +41,7 @@ log = logging.getLogger('gajim.gtkgui_helpers')
from common import i18n from common import i18n
from common import gajim from common import gajim
from common import pep
gtk_icon_theme = Gtk.IconTheme.get_default() gtk_icon_theme = Gtk.IconTheme.get_default()
gtk_icon_theme.append_search_path(gajim.ICONS_DIR) gtk_icon_theme.append_search_path(gajim.ICONS_DIR)
@ -384,7 +385,7 @@ def get_abspath_for_script(scriptname, want_type = False):
script += '\nexec python -OOt gajim.py $0 $@\n' script += '\nexec python -OOt gajim.py $0 $@\n'
f.write(script) f.write(script)
f.close() f.close()
os.chmod(path_to_script, 0700) os.chmod(path_to_script, 0o700)
except OSError: # do not traceback (could be a permission problem) except OSError: # do not traceback (could be a permission problem)
#we talk about a file here #we talk about a file here
s = _('Could not write to %s. Session Management support will ' s = _('Could not write to %s. Session Management support will '
@ -607,7 +608,7 @@ def get_avatar_pixbuf_from_cache(fjid, use_local=True):
if not os.path.isfile(path): if not os.path.isfile(path):
return 'ask' 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) is_groupchat_contact)
if not vcard_dict: # This can happen if cached vcard is too old if not vcard_dict: # This can happen if cached vcard is too old
return 'ask' return 'ask'
@ -645,28 +646,6 @@ def make_pixbuf_grayscale(pixbuf):
pixbuf.saturate_and_pixelate(pixbuf2, 0.0, False) pixbuf.saturate_and_pixelate(pixbuf2, 0.0, False)
return pixbuf2 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): def decode_filechooser_file_paths(file_paths):
""" """
Decode as UTF-8 under Windows and ask sys.getfilesystemencoding() in POSIX Decode as UTF-8 under Windows and ask sys.getfilesystemencoding() in POSIX
@ -974,6 +953,38 @@ def load_activity_icon(category, activity = None):
icon_list = _load_icon_list([activity], path) icon_list = _load_icon_list([activity], path)
return icon_list[activity] 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(): def load_icons_meta():
""" """
Load and return - AND + small icons to put on top left of an icon for meta Load and return - AND + small icons to put on top left of an icon for meta

View File

@ -68,7 +68,7 @@ from groupchat_control import PrivateChatControl
from atom_window import AtomWindow from atom_window import AtomWindow
from session import ChatControlSession from session import ChatControlSession
import common.sleepy from common import sleepy
from nbxmpp import idlequeue from nbxmpp import idlequeue
from nbxmpp import Hashes from nbxmpp import Hashes
@ -93,7 +93,7 @@ import config
from threading import Thread from threading import Thread
from common import ged from common import ged
gajimpaths = common.configpaths.gajimpaths from common.configpaths import gajimpaths
config_filename = gajimpaths['CONFIG_FILE'] config_filename = gajimpaths['CONFIG_FILE']
from common import optparser from common import optparser
@ -1111,11 +1111,11 @@ class Interface:
# Ask offline status in 1 minute so w'are sure we got all online # Ask offline status in 1 minute so w'are sure we got all online
# presences # presences
GObject.timeout_add_seconds(60, self.ask_offline_status, account) 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 # we go online or free for chat, so we activate auto status
gajim.sleeper_state[account] = 'online' gajim.sleeper_state[account] = 'online'
elif not ((state == common.sleepy.STATE_AWAY and connected == 4) or \ elif not ((state == sleepy.STATE_AWAY and connected == 4) or \
(state == common.sleepy.STATE_XA and connected == 5)): (state == sleepy.STATE_XA and connected == 5)):
# If we are autoaway/xa and come back after a disconnection, do # If we are autoaway/xa and come back after a disconnection, do
# nothing # nothing
# Else disable autoaway # Else disable autoaway
@ -1568,7 +1568,7 @@ class Interface:
This is part of rewriting whole events handling system to use GED. 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: for event_handler in event_handlers:
prio = ged.GUI1 prio = ged.GUI1
if type(event_handler) == tuple: if type(event_handler) == tuple:
@ -2341,14 +2341,14 @@ class Interface:
if account not in gajim.sleeper_state or \ if account not in gajim.sleeper_state or \
not gajim.sleeper_state[account]: not gajim.sleeper_state[account]:
continue continue
if state == common.sleepy.STATE_AWAKE and \ if state == sleepy.STATE_AWAKE and \
gajim.sleeper_state[account] in ('autoaway', 'autoxa'): gajim.sleeper_state[account] in ('autoaway', 'autoxa'):
# we go online # we go online
self.roster.send_status(account, 'online', self.roster.send_status(account, 'online',
gajim.status_before_autoaway[account]) gajim.status_before_autoaway[account])
gajim.status_before_autoaway[account] = '' gajim.status_before_autoaway[account] = ''
gajim.sleeper_state[account] = 'online' 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.sleeper_state[account] == 'online' and \
gajim.config.get('autoaway'): gajim.config.get('autoaway'):
# we save out online status # we save out online status
@ -2368,7 +2368,7 @@ class Interface:
self.roster.send_status(account, 'away', auto_message, self.roster.send_status(account, 'away', auto_message,
auto=True) auto=True)
gajim.sleeper_state[account] = 'autoaway' 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', gajim.sleeper_state[account] in ('online', 'autoaway',
'autoaway-forced') and gajim.config.get('autoxa'): 'autoaway-forced') and gajim.config.get('autoxa'):
# we go extended away [we pass True to auto param] # we go extended away [we pass True to auto param]
@ -2912,7 +2912,7 @@ class Interface:
self.show_vcard_when_connect = [] 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('autoawaytime') * 60, # make minutes to seconds
gajim.config.get('autoxatime') * 60) gajim.config.get('autoxatime') * 60)

View File

@ -42,8 +42,8 @@ from gi.repository import Gdk
from gi.repository import GdkPixbuf from gi.repository import GdkPixbuf
import xml.sax, xml.sax.handler import xml.sax, xml.sax.handler
import re import re
from cStringIO import StringIO from io import StringIO
import urllib2 import urllib
import operator import operator
if __name__ == '__main__': if __name__ == '__main__':
@ -491,9 +491,10 @@ class HtmlHandler(xml.sax.handler.ContentHandler):
tag.title = title tag.title = title
return tag 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. '''Callback function called after the function helpers.download_image.
''' '''
mem, alt = output
self._process_img(attrs, (mem, alt, img_mark)) self._process_img(attrs, (mem, alt, img_mark))
def _process_img(self, attrs, loaded=None): 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 # The "data" URL scheme http://tools.ietf.org/html/rfc2397
import base64 import base64
img = attrs['src'].split(',')[1] 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: elif loaded is not None:
(mem, alt, replace_mark) = loaded (mem, alt, replace_mark) = loaded
update = True update = True

View File

@ -156,6 +156,9 @@ class Notification:
def _nec_notification(self, obj): def _nec_notification(self, obj):
if obj.do_popup: 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, popup(obj.popup_event_type, obj.jid, obj.conn.name,
obj.popup_msg_type, path_to_image=obj.popup_image, obj.popup_msg_type, path_to_image=obj.popup_image,
title=obj.popup_title, text=obj.popup_text, title=obj.popup_title, text=obj.popup_text,

View File

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

View File

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

View File

@ -196,7 +196,7 @@ class GajimPlugin(object):
def deactivate(self): def deactivate(self):
pass pass
import cPickle import pickle
class GajimPluginConfig(): class GajimPluginConfig():
@log_calls('GajimPluginConfig') @log_calls('GajimPluginConfig')
@ -242,7 +242,7 @@ class GajimPluginConfig():
@log_calls('GajimPluginConfig') @log_calls('GajimPluginConfig')
def save(self): def save(self):
fd = open(self.FILE_PATH, 'wb') fd = open(self.FILE_PATH, 'wb')
cPickle.dump(self.data, fd) pickle.dump(self.data, fd)
fd.close() fd.close()
@log_calls('GajimPluginConfig') @log_calls('GajimPluginConfig')
@ -250,14 +250,14 @@ class GajimPluginConfig():
if os.path.isfile(self.FILE_PATH): if os.path.isfile(self.FILE_PATH):
fd = open(self.FILE_PATH, 'rb') fd = open(self.FILE_PATH, 'rb')
try: try:
self.data = cPickle.load(fd) self.data = pickle.load(fd)
fd.close() fd.close()
except: except:
fd.close() fd.close()
try: try:
import shelve import shelve
s = shelve.open(self.FILE_PATH) s = shelve.open(self.FILE_PATH)
for (k, v) in s.iteritems(): for (k, v) in s.items():
self.data[k] = v self.data[k] = v
if not isinstance(self.data, dict): if not isinstance(self.data, dict):
raise GajimPluginException raise GajimPluginException

View File

@ -31,7 +31,7 @@ import sys
import fnmatch import fnmatch
import zipfile import zipfile
from shutil import rmtree from shutil import rmtree
import ConfigParser import configparser
from common import gajim from common import gajim
from common import nec from common import nec
@ -258,14 +258,14 @@ class PluginManager(object):
handlers[0](*args) handlers[0](*args)
def _register_events_handlers_in_ged(self, plugin): 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] priority = handler[0]
handler_function = handler[1] handler_function = handler[1]
gajim.ged.register_event_handler(event_name, priority, gajim.ged.register_event_handler(event_name, priority,
handler_function) handler_function)
def _remove_events_handler_from_ged(self, plugin): 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] priority = handler[0]
handler_function = handler[1] handler_function = handler[1]
gajim.ged.remove_event_handler(event_name, priority, gajim.ged.remove_event_handler(event_name, priority,
@ -312,7 +312,7 @@ class PluginManager(object):
# remove GUI extension points handlers (provided by plug-in) from # remove GUI extension points handlers (provided by plug-in) from
# handlers list # handlers list
for gui_extpoint_name, gui_extpoint_handlers in \ 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( self.gui_extension_points_handlers[gui_extpoint_name].remove(
gui_extpoint_handlers) gui_extpoint_handlers)
@ -320,7 +320,7 @@ class PluginManager(object):
# cleaning up method that must be provided by plug-in developer # cleaning up method that must be provided by plug-in developer
# for each handled GUI extension point) # for each handled GUI extension point)
for gui_extpoint_name, gui_extpoint_handlers in \ 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: if gui_extpoint_name in self.gui_extension_points:
for gui_extension_point_args in self.gui_extension_points[ for gui_extension_point_args in self.gui_extension_points[
gui_extpoint_name]: gui_extpoint_name]:
@ -344,14 +344,14 @@ class PluginManager(object):
@log_calls('PluginManager') @log_calls('PluginManager')
def _add_gui_extension_points_handlers_from_plugin(self, plugin): def _add_gui_extension_points_handlers_from_plugin(self, plugin):
for gui_extpoint_name, gui_extpoint_handlers in \ 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, self.gui_extension_points_handlers.setdefault(gui_extpoint_name,
[]).append(gui_extpoint_handlers) []).append(gui_extpoint_handlers)
@log_calls('PluginManager') @log_calls('PluginManager')
def _handle_all_gui_extension_points_with_plugin(self, plugin): def _handle_all_gui_extension_points_with_plugin(self, plugin):
for gui_extpoint_name, gui_extpoint_handlers in \ 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: if gui_extpoint_name in self.gui_extension_points:
for gui_extension_point_args in self.gui_extension_points[ for gui_extension_point_args in self.gui_extension_points[
gui_extpoint_name]: gui_extpoint_name]:
@ -407,7 +407,7 @@ class PluginManager(object):
''' '''
from plugins.plugins_i18n import _ from plugins.plugins_i18n import _
plugins_found = [] plugins_found = []
conf = ConfigParser.ConfigParser() conf = configparser.ConfigParser()
fields = ('name', 'short_name', 'version', 'description', 'authors', fields = ('name', 'short_name', 'version', 'description', 'authors',
'homepage') 'homepage')
if not os.path.isdir(path): if not os.path.isdir(path):
@ -471,7 +471,7 @@ class PluginManager(object):
conf.readfp(open(manifest_path, 'r')) conf.readfp(open(manifest_path, 'r'))
for option in fields: for option in fields:
if conf.get('info', option) is '': if conf.get('info', option) is '':
raise ConfigParser.NoOptionError, 'field empty' raise configparser.NoOptionError('field empty')
setattr(module_attr, option, conf.get('info', option)) setattr(module_attr, option, conf.get('info', option))
conf.remove_section('info') conf.remove_section('info')
@ -483,15 +483,15 @@ class PluginManager(object):
module_attr._ = _ module_attr._ = _
except AttributeError as type_error: except AttributeError as type_error:
pass pass
except ConfigParser.NoOptionError as type_error: except configparser.NoOptionError as type_error:
# all fields are required # all fields are required
log.debug('%s : %s' % (module_attr_name, log.debug('%s : %s' % (module_attr_name,
'wrong manifest file. all fields are required!')) 'wrong manifest file. all fields are required!'))
except ConfigParser.NoSectionError as type_error: except configparser.NoSectionError as type_error:
# info section are required # info section are required
log.debug('%s : %s' % (module_attr_name, log.debug('%s : %s' % (module_attr_name,
'wrong manifest file. info section are required!')) 'wrong manifest file. info section are required!'))
except ConfigParser.MissingSectionHeaderError as type_error: except configparser.MissingSectionHeaderError as type_error:
# info section are required # info section are required
log.debug('%s : %s' % (module_attr_name, log.debug('%s : %s' % (module_attr_name,
'wrong manifest file. section are required!')) 'wrong manifest file. section are required!'))

View File

@ -619,7 +619,7 @@ class SignalObject(dbus.service.Object):
raise dbus_support.MissingArgument() raise dbus_support.MissingArgument()
jid = self._get_real_jid(jid) 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: if cached_vcard:
return get_dbus_struct(cached_vcard) return get_dbus_struct(cached_vcard)

View File

@ -1062,28 +1062,28 @@ class RosterWindow:
pep_dict = gajim.connections[account].pep pep_dict = gajim.connections[account].pep
if gajim.config.get('show_mood_in_roster') and 'mood' in pep_dict: if gajim.config.get('show_mood_in_roster') and 'mood' in pep_dict:
self.model[child_iter][C_MOOD_PIXBUF] = pep_dict['mood'].\ self.model[child_iter][C_MOOD_PIXBUF] = \
asPixbufIcon() gtkgui_helpers.get_pep_as_pixbuf(pep_dict['mood'])
else: else:
self.model[child_iter][C_MOOD_PIXBUF] = empty_pixbuf self.model[child_iter][C_MOOD_PIXBUF] = empty_pixbuf
if gajim.config.get('show_activity_in_roster') and 'activity' in \ if gajim.config.get('show_activity_in_roster') and 'activity' in \
pep_dict: pep_dict:
self.model[child_iter][C_ACTIVITY_PIXBUF] = pep_dict['activity'].\ self.model[child_iter][C_ACTIVITY_PIXBUF] = \
asPixbufIcon() gtkgui_helpers.get_pep_as_pixbuf(pep_dict['activity'])
else: else:
self.model[child_iter][C_ACTIVITY_PIXBUF] = empty_pixbuf self.model[child_iter][C_ACTIVITY_PIXBUF] = empty_pixbuf
if gajim.config.get('show_tunes_in_roster') and 'tune' in pep_dict: if gajim.config.get('show_tunes_in_roster') and 'tune' in pep_dict:
self.model[child_iter][C_TUNE_PIXBUF] = pep_dict['tune'].\ self.model[child_iter][C_TUNE_PIXBUF] = \
asPixbufIcon() gtkgui_helpers.get_pep_as_pixbuf(pep_dict['tune'])
else: else:
self.model[child_iter][C_TUNE_PIXBUF] = empty_pixbuf self.model[child_iter][C_TUNE_PIXBUF] = empty_pixbuf
if gajim.config.get('show_location_in_roster') and 'location' in \ if gajim.config.get('show_location_in_roster') and 'location' in \
pep_dict: pep_dict:
self.model[child_iter][C_LOCATION_PIXBUF] = pep_dict['location'].\ self.model[child_iter][C_LOCATION_PIXBUF] = \
asPixbufIcon() gtkgui_helpers.get_pep_as_pixbuf(pep_dict['location'])
else: else:
self.model[child_iter][C_LOCATION_PIXBUF] = empty_pixbuf self.model[child_iter][C_LOCATION_PIXBUF] = empty_pixbuf
@ -1340,7 +1340,7 @@ class RosterWindow:
if not contact: if not contact:
contact = gajim.contacts.get_contact(account, jid) contact = gajim.contacts.get_contact(account, jid)
if pep_type in contact.pep: if pep_type in contact.pep:
pixbuf = contact.pep[pep_type].asPixbufIcon() pixbuf = gtkgui_helpers.get_pep_as_pixbuf(contact.pep[pep_type])
else: else:
pixbuf = empty_pixbuf pixbuf = empty_pixbuf
for child_iter in iters: for child_iter in iters:

View File

@ -637,9 +637,9 @@ class RosterTooltip(NotificationAreaTooltip):
'tooltip_idle_color') 'tooltip_idle_color')
cs += '%s</span>' cs += '%s</span>'
properties.append((str(), None)) 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)) 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)) properties.append((idle_for % str(diff), None))
while properties: while properties:

View File

@ -212,7 +212,7 @@ class MockCall:
elif isinstance(n, str): elif isinstance(n, str):
return self.kwparams[n] return self.kwparams[n]
else: else:
raise IndexError, 'illegal index type for getParam' raise IndexError('illegal index type for getParam')
def getNumParams(self): def getNumParams(self):
return len(self.params) return len(self.params)

View File

@ -135,8 +135,8 @@ class TestJingle(unittest.TestCase):
self.dispatcher.RegisterHandler('iq', self.con._JingleCB, 'set' self.dispatcher.RegisterHandler('iq', self.con._JingleCB, 'set'
, common.xmpp.NS_JINGLE) , common.xmpp.NS_JINGLE)
self.dispatcher.ProcessNonBlocking(session_init) self.dispatcher.ProcessNonBlocking(session_init)
session = self.con._sessions.values()[0] # The only session we have session = list(self.con._sessions.values())[0] # The only session we have
jft = session.contents.values()[0] # jingleFT object jft = list(session.contents.values())[0] # jingleFT object
jft.file_props = self.recieve_file # We plug file_props manually jft.file_props = self.recieve_file # We plug file_props manually
# The user accepts to recieve the file # The user accepts to recieve the file
# we have to manually simulate this behavior # we have to manually simulate this behavior