Commit 069bddbb authored by Yann Leboulanger's avatar Yann Leboulanger

remove call to unicode()

parent 414e3493
......@@ -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(
......@@ -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)
......
......@@ -2505,7 +2505,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')
......
......@@ -32,7 +32,7 @@ over the process.
"""
from types import NoneType
from tools import remove
from .tools import remove
COMMANDS = {}
CONTAINERS = {}
......
......@@ -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 mmapping import parse_arguments, adapt_arguments
from .errors import DefinitionError, CommandError, NoCommandError
class CommandHost(object):
"""
......
......@@ -35,7 +35,7 @@ detected.
"""
from ..framework import CommandContainer, command, doc
from hosts import *
from .hosts import *
class CustomCommonCommands(CommandContainer):
"""
......
......@@ -38,7 +38,7 @@ from os.path import expanduser
from glib import timeout_add
from ..framework import CommandContainer, command, doc
from hosts import *
from .hosts import *
class Execute(CommandContainer):
AUTOMATIC = True
......
......@@ -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.
......
......@@ -26,7 +26,7 @@ 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.
......@@ -269,12 +269,6 @@ def adapt_arguments(command, arguments, args, opts):
if not isinstance(value, BooleanType):
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:
......
......@@ -29,7 +29,7 @@ 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
......
......@@ -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')
......
......@@ -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':
......
......@@ -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:
......
......@@ -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
......
......@@ -39,7 +39,7 @@ from nbxmpp.protocol import NS_CHATSTATES
from common.jingle_transport import JingleTransportSocks5
from common.file_props import FilesProp
import gtkgui_helpers
from . import gtkgui_helpers
import logging
log = logging.getLogger('gajim.c.connection_handlers_events')
......@@ -1169,7 +1169,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 +1985,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 +2032,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',
......
......@@ -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
......@@ -345,7 +345,7 @@ 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 ''
......
......@@ -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
interface = None # The actual interface (the gtk one for the moment)
thread_interface = None # Interface to run a thread and then a callback
......@@ -280,13 +280,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):
......
......@@ -26,7 +26,7 @@ from 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):
......
......@@ -42,7 +42,7 @@ import select
import base64
import hashlib
import shlex
import caps_cache
from common import caps_cache
import socket
import time
......@@ -159,7 +159,7 @@ def prep(user, server, resource):
raise InvalidFormat, _('Username must be between 1 and 1023 chars')
try:
from nbxmpp.stringprepare import nodeprep
user = nodeprep.prepare(unicode(user)).encode('utf-8')
user = nodeprep.prepare(user)
except UnicodeError:
raise InvalidFormat, _('Invalid character in username.')
else:
......@@ -170,7 +170,7 @@ def prep(user, server, resource):
raise InvalidFormat, _('Server must be between 1 and 1023 chars')
try:
from nbxmpp.stringprepare import nameprep
server = nameprep.prepare(unicode(server)).encode('utf-8')
server = nameprep.prepare(server)
except UnicodeError:
raise InvalidFormat, _('Invalid character in hostname.')
else:
......@@ -181,7 +181,7 @@ def prep(user, server, resource):
raise InvalidFormat, _('Resource must be between 1 and 1023 chars')
try:
from nbxmpp.stringprepare import resourceprep
resource = resourceprep.prepare(unicode(resource)).encode('utf-8')
resource = resourceprep.prepare(resource)
except UnicodeError:
raise InvalidFormat, _('Invalid character in resource.')
else:
......@@ -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
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
@wrapped_ensure_utf8_string
def escape_text(text):
return GObject.markup_escape_text(text)
GObject.markup_escape_text = escape_text
#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
#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
#@wrapped_ensure_utf8_string
#def escape_text(text):
#return GObject.markup_escape_text(text)
#GObject.markup_escape_text = escape_text
def get_windows_reg_env(varname, default=''):
"""
......@@ -645,13 +645,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')
......@@ -675,7 +675,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):
"""
......@@ -901,13 +901,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()))
return parse_jid(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)
......
......@@ -24,7 +24,7 @@
import locale
import gettext
import os
import defs
from common import defs
import unicodedata
def paragraph_direction_mark(text):
......@@ -61,7 +61,7 @@ if os.name == 'nt':
if lang:
os.environ['LANG'] = lang
gettext.install(APP, DIR, unicode=False)
gettext.install(APP, DIR)
if gettext._translations:
_translation = gettext._translations.values()[0]
else:
......
......@@ -158,7 +158,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
......
......@@ -46,7 +46,7 @@ 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'),
......
......@@ -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=StringIO(str(data))).read().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()
......
......@@ -19,7 +19,7 @@
##
import logging
import i18n
from common import i18n
def parseLogLevel(arg):
"""
......
......@@ -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:
......
......@@ -87,19 +87,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')
......
......@@ -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
......@@ -983,7 +983,7 @@ class ConnectionIBBytestream(ConnectionBytestream):
class ConnectionSocks5BytestreamZeroconf(ConnectionSocks5Bytestream):
def _ft_get_from(self, iq_obj):
return unicode(iq_obj.getFrom())