Welcome to mirror list, hosted at ThFree Co, Russian Federation.

dev.gajim.org/gajim/gajim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/GnuPG.py4
-rw-r--r--src/common/GnuPGInterface.py194
-rw-r--r--src/common/atom.py6
-rw-r--r--src/common/caps.py2
-rw-r--r--src/common/check_paths.py14
-rw-r--r--src/common/commands.py8
-rw-r--r--src/common/config.py8
-rw-r--r--src/common/connection.py2
-rw-r--r--src/common/connection_handlers.py22
-rw-r--r--src/common/contacts.py12
-rw-r--r--src/common/crypto.py2
-rw-r--r--src/common/dataforms.py6
-rw-r--r--src/common/dbus_support.py8
-rw-r--r--src/common/gajim.py2
-rw-r--r--src/common/helpers.py36
-rw-r--r--src/common/i18n.py4
-rw-r--r--src/common/logger.py8
-rw-r--r--src/common/nslookup.py70
-rw-r--r--src/common/optparser.py22
-rw-r--r--src/common/proxy65_manager.py20
-rw-r--r--src/common/rst_xhtml_generator.py4
-rw-r--r--src/common/xmpp/__init__.py4
-rw-r--r--src/common/xmpp/auth.py2
-rw-r--r--src/common/xmpp/auth_nb.py94
-rw-r--r--src/common/xmpp/browser.py6
-rw-r--r--src/common/xmpp/client.py14
-rw-r--r--src/common/xmpp/client_nb.py120
-rw-r--r--src/common/xmpp/commands.py64
-rw-r--r--src/common/xmpp/debug.py58
-rw-r--r--src/common/xmpp/dispatcher.py6
-rw-r--r--src/common/xmpp/dispatcher_nb.py102
-rw-r--r--src/common/xmpp/features.py4
-rw-r--r--src/common/xmpp/features_nb.py46
-rw-r--r--src/common/xmpp/filetransfer.py4
-rw-r--r--src/common/xmpp/idlequeue.py56
-rw-r--r--src/common/xmpp/protocol.py10
-rw-r--r--src/common/xmpp/roster.py6
-rw-r--r--src/common/xmpp/roster_nb.py12
-rw-r--r--src/common/xmpp/session.py4
-rw-r--r--src/common/xmpp/simplexml.py38
-rw-r--r--src/common/xmpp/transports_nb.py128
-rw-r--r--src/common/xmpp_stringprep.py8
-rw-r--r--src/common/zeroconf/connection_handlers_zeroconf.py2
-rw-r--r--src/common/zeroconf/roster_zeroconf.py18
-rw-r--r--src/common/zeroconf/zeroconf_avahi.py62
-rw-r--r--src/common/zeroconf/zeroconf_bonjour.py50
46 files changed, 686 insertions, 686 deletions
diff --git a/src/common/GnuPG.py b/src/common/GnuPG.py
index 82f96dd4c..ce2853768 100644
--- a/src/common/GnuPG.py
+++ b/src/common/GnuPG.py
@@ -108,7 +108,7 @@ if gajim.HAVE_GPG:
enc = self._addHeaderFooter(str_, 'MESSAGE')
proc.handles['stdin'].write(enc)
proc.handles['stdin'].close()
-
+
output = proc.handles['stdout'].read()
proc.handles['stdout'].close()
@@ -166,7 +166,7 @@ if gajim.HAVE_GPG:
try: proc.wait()
except IOError: pass
-
+
keyid = ''
if 'GOODSIG' in resp:
keyid = resp['GOODSIG'].split()[0]
diff --git a/src/common/GnuPGInterface.py b/src/common/GnuPGInterface.py
index c026d6d6c..d91f776e3 100644
--- a/src/common/GnuPGInterface.py
+++ b/src/common/GnuPGInterface.py
@@ -39,15 +39,15 @@ Process object, which contains the filehandles to talk to GnuPG with.
Example code:
>>> import GnuPGInterface
->>>
+>>>
>>> plaintext = "Three blind mice"
>>> passphrase = "This is the passphrase"
->>>
+>>>
>>> gnupg = GnuPGInterface.GnuPG()
>>> gnupg.options.armor = 1
>>> gnupg.options.meta_interactive = 0
>>> gnupg.options.extra_args.append('--no-secmem-warning')
->>>
+>>>
>>> # Normally we might specify something in
>>> # gnupg.options.recipients, like
>>> # gnupg.options.recipients = [ '0xABCD1234', 'bob@foo.bar' ]
@@ -55,39 +55,39 @@ Example code:
>>> # If you are doing standard, public-key encryption, using
>>> # --encrypt, you will need to specify recipients before
>>> # calling gnupg.run()
->>>
+>>>
>>> # First we'll encrypt the test_text input symmetrically
>>> p1 = gnupg.run(['--symmetric'],
... create_fhs=['stdin', 'stdout', 'passphrase'])
->>>
+>>>
>>> p1.handles['passphrase'].write(passphrase)
>>> p1.handles['passphrase'].close()
->>>
+>>>
>>> p1.handles['stdin'].write(plaintext)
>>> p1.handles['stdin'].close()
->>>
+>>>
>>> ciphertext = p1.handles['stdout'].read()
>>> p1.handles['stdout'].close()
->>>
+>>>
>>> # process cleanup
>>> p1.wait()
->>>
+>>>
>>> # Now we'll decrypt what we just encrypted it,
>>> # using the convience method to get the
>>> # passphrase to GnuPG
>>> gnupg.passphrase = passphrase
->>>
+>>>
>>> p2 = gnupg.run(['--decrypt'], create_fhs=['stdin', 'stdout'])
->>>
+>>>
>>> p2.handles['stdin'].write(ciphertext)
>>> p2.handles['stdin'].close()
->>>
+>>>
>>> decrypted_plaintext = p2.handles['stdout'].read()
>>> p2.handles['stdout'].close()
->>>
+>>>
>>> # process cleanup
>>> p2.wait()
->>>
+>>>
>>> # Our decrypted plaintext:
>>> decrypted_plaintext
'Three blind mice'
@@ -99,10 +99,10 @@ Example code:
>>>
>>> ##################################################
>>> # Now let's trying using run()'s attach_fhs paramter
->>>
+>>>
>>> # we're assuming we're running on a unix...
>>> input = open('/etc/motd')
->>>
+>>>
>>> p1 = gnupg.run(['--symmetric'], create_fhs=['stdout'],
... attach_fhs={'stdin': input})
>>>
@@ -111,26 +111,26 @@ Example code:
>>>
>>> # process cleanup
>>> p1.wait()
->>>
+>>>
>>> # Now let's run the output through GnuPG
>>> # We'll write the output to a temporary file,
>>> import tempfile
>>> temp = tempfile.TemporaryFile()
->>>
+>>>
>>> p2 = gnupg.run(['--decrypt'], create_fhs=['stdin'],
... attach_fhs={'stdout': temp})
->>>
+>>>
>>> # give GnuPG our encrypted stuff from the first run
>>> p2.handles['stdin'].write(ciphertext)
>>> p2.handles['stdin'].close()
->>>
+>>>
>>> # process cleanup
>>> p2.wait()
->>>
+>>>
>>> # rewind the tempfile and see what GnuPG gave us
>>> temp.seek(0)
>>> decrypted_plaintext = temp.read()
->>>
+>>>
>>> # compare what GnuPG decrypted with our original input
>>> input.seek(0)
>>> input_data = input.read()
@@ -150,7 +150,7 @@ so that it has an encrypt_string() method that returns
ciphertext.
>>> import GnuPGInterface
->>>
+>>>
>>> class MyGnuPG(GnuPGInterface.GnuPG):
...
... def __init__(self):
@@ -164,12 +164,12 @@ ciphertext.
...
... def encrypt_string(self, string, recipients):
... gnupg.options.recipients = recipients # a list!
-...
+...
... proc = gnupg.run(['--encrypt'], create_fhs=['stdin', 'stdout'])
-...
+...
... proc.handles['stdin'].write(string)
... proc.handles['stdin'].close()
-...
+...
... output = proc.handles['stdout'].read()
... proc.handles['stdout'].close()
...
@@ -194,10 +194,10 @@ Here is an example of generating a key:
>>> # but we capture logger to surpress the dry-run command.
>>> # We also have to capture stdout since otherwise doctest complains;
>>> # Normally you can let stdout through when generating a key.
->>>
+>>>
>>> proc = gnupg.run(['--gen-key'], create_fhs=['stdin', 'stdout',
... 'logger'])
->>>
+>>>
>>> proc.handles['stdin'].write('''Key-Type: DSA
... Key-Length: 1024
... # We are only testing syntax this time, so dry-run
@@ -212,12 +212,12 @@ Here is an example of generating a key:
... %pubring foo.pub
... %secring foo.sec
... ''')
->>>
+>>>
>>> proc.handles['stdin'].close()
->>>
+>>>
>>> report = proc.handles['logger'].read()
>>> proc.handles['logger'].close()
->>>
+>>>
>>> proc.wait()
"""
@@ -250,21 +250,21 @@ _fd_options = { 'passphrase': '--passphrase-fd',
class GnuPG:
"""Class instances represent GnuPG.
-
+
Instance attributes of a GnuPG object are:
-
+
* call -- string to call GnuPG with. Defaults to "gpg"
* passphrase -- Since it is a common operation
to pass in a passphrase to GnuPG,
and working with the passphrase filehandle mechanism directly
can be mundane, if set, the passphrase attribute
- works in a special manner. If the passphrase attribute is set,
+ works in a special manner. If the passphrase attribute is set,
and no passphrase file object is sent in to run(),
then GnuPG instnace will take care of sending the passphrase to
GnuPG, the executable instead of having the user sent it in manually.
-
- * options -- Object of type GnuPGInterface.Options.
+
+ * options -- Object of type GnuPGInterface.Options.
Attribute-setting in options determines
the command-line options used when calling GnuPG.
"""
@@ -273,14 +273,14 @@ class GnuPG:
self.call = 'gpg'
self.passphrase = None
self.options = Options()
-
+
def run(self, gnupg_commands, args=None, create_fhs=None, attach_fhs=None):
"""Calls GnuPG with the list of string commands gnupg_commands,
complete with prefixing dashes.
For example, gnupg_commands could be
'["--sign", "--encrypt"]'
Returns a GnuPGInterface.Process object.
-
+
args is an optional list of GnuPG command arguments (not options),
such as keyID's to export, filenames to process, etc.
@@ -289,7 +289,7 @@ class GnuPG:
'handles' attribute. The generated filehandles can be used
to communicate with GnuPG via standard input, standard output,
the status-fd, passphrase-fd, etc.
-
+
Valid GnuPG filehandle names are:
* stdin
* stdout
@@ -298,10 +298,10 @@ class GnuPG:
* passphase
* command
* logger
-
+
The purpose of each filehandle is described in the GnuPG
documentation.
-
+
attach_fhs is an optional dictionary with GnuPG filehandle
names mapping to opened files. GnuPG will read or write
to the file accordingly. For example, if 'my_file' is an
@@ -309,21 +309,21 @@ class GnuPG:
will read its standard input from my_file. This is useful
if you want GnuPG to read/write to/from an existing file.
For instance:
-
+
f = open("encrypted.gpg")
gnupg.run(["--decrypt"], attach_fhs={'stdin': f})
Using attach_fhs also helps avoid system buffering
issues that can arise when using create_fhs, which
can cause the process to deadlock.
-
+
If not mentioned in create_fhs or attach_fhs,
GnuPG filehandles which are a std* (stdin, stdout, stderr)
are defaulted to the running process' version of handle.
Otherwise, that type of handle is simply not used when calling GnuPG.
For example, if you do not care about getting data from GnuPG's
status filehandle, simply do not specify it.
-
+
run() returns a Process() object which has a 'handles'
which is a dictionary mapping from the handle name
(such as 'stdin' or 'stdout') to the respective
@@ -331,47 +331,47 @@ class GnuPG:
For instance, if the call was
process = gnupg.run(["--decrypt"], stdin=1)
-
+
after run returns 'process.handles["stdin"]'
is a FileObject connected to GnuPG's standard input,
and can be written to.
"""
-
+
if args is None: args = []
if create_fhs is None: create_fhs = []
if attach_fhs is None: attach_fhs = {}
-
+
for std in _stds:
if std not in attach_fhs \
and std not in create_fhs:
attach_fhs.setdefault(std, getattr(sys, std))
-
+
handle_passphrase = 0
-
+
if self.passphrase is not None \
and 'passphrase' not in attach_fhs \
and 'passphrase' not in create_fhs:
handle_passphrase = 1
create_fhs.append('passphrase')
-
+
process = self._attach_fork_exec(gnupg_commands, args,
create_fhs, attach_fhs)
-
+
if handle_passphrase:
passphrase_fh = process.handles['passphrase']
passphrase_fh.write( self.passphrase )
passphrase_fh.close()
del process.handles['passphrase']
-
+
return process
-
-
+
+
def _attach_fork_exec(self, gnupg_commands, args, create_fhs, attach_fhs):
"""This is like run(), but without the passphrase-helping
(note that run() calls this)."""
-
+
process = Process()
-
+
for fh_name in create_fhs + attach_fhs.keys():
if fh_name not in _fd_modes:
raise KeyError, \
@@ -393,26 +393,26 @@ class GnuPG:
# if we are writing
if _fd_modes[fh_name] == 'w': pipe = (pipe[1], pipe[0])
process._pipes[fh_name] = Pipe(pipe[0], pipe[1], 0)
-
+
for fh_name, fh in attach_fhs.items():
process._pipes[fh_name] = Pipe(fh.fileno(), fh.fileno(), 1)
-
+
process.pid = os.fork()
-
+
if process.pid == 0: self._as_child(process, gnupg_commands, args)
return self._as_parent(process)
-
-
+
+
def _as_parent(self, process):
"""Stuff run after forking in parent"""
for k, p in process._pipes.items():
if not p.direct:
os.close(p.child)
process.handles[k] = os.fdopen(p.parent, _fd_modes[k])
-
+
# user doesn't need these
del process._pipes
-
+
return process
@@ -422,27 +422,27 @@ class GnuPG:
for std in _stds:
p = process._pipes[std]
os.dup2( p.child, getattr(sys, "__%s__" % std).fileno() )
-
+
for k, p in process._pipes.items():
if p.direct and k not in _stds:
# we want the fh to stay open after execing
fcntl.fcntl( p.child, fcntl.F_SETFD, 0 )
-
+
fd_args = []
-
+
for k, p in process._pipes.items():
# set command-line options for non-standard fds
if k not in _stds:
fd_args.extend([ _fd_options[k], "%d" % p.child ])
-
+
if not p.direct: os.close(p.parent)
-
+
command = [ self.call ] + fd_args + self.options.get_args() \
+ gnupg_commands + args
os.execvp( command[0], command )
-
+
class Pipe:
"""simple struct holding stuff about pipes we use"""
def __init__(self, parent, child, direct):
@@ -456,14 +456,14 @@ class Options:
This class is responsible for determining command-line arguments
which are based on options. It can be said that a GnuPG
object has-a Options object in its options attribute.
-
+
Attributes which correlate directly to GnuPG options:
-
+
Each option here defaults to false or None, and is described in
GnuPG documentation.
-
+
Booleans (set these attributes to booleans)
-
+
* armor
* no_greeting
* no_verbose
@@ -475,54 +475,54 @@ class Options:
* force_v3_sigs
* no_options
* textmode
-
+
Strings (set these attributes to strings)
-
+
* homedir
* default_key
* comment
* compress_algo
* options
-
+
Lists (set these attributes to lists)
-
+
* recipients (***NOTE*** plural of 'recipient')
* encrypt_to
-
+
Meta options
-
+
Meta options are options provided by this module that do
not correlate directly to any GnuPG option by name,
but are rather bundle of options used to accomplish
a specific goal, such as obtaining compatibility with PGP 5.
The actual arguments each of these reflects may change with time. Each
defaults to false unless otherwise specified.
-
+
meta_pgp_5_compatible -- If true, arguments are generated to try
to be compatible with PGP 5.x.
-
+
meta_pgp_2_compatible -- If true, arguments are generated to try
to be compatible with PGP 2.x.
-
+
meta_interactive -- If false, arguments are generated to try to
help the using program use GnuPG in a non-interactive
environment, such as CGI scripts. Default is true.
-
+
extra_args -- Extra option arguments may be passed in
via the attribute extra_args, a list.
>>> import GnuPGInterface
- >>>
+ >>>
>>> gnupg = GnuPGInterface.GnuPG()
>>> gnupg.options.armor = 1
>>> gnupg.options.recipients = ['Alice', 'Bob']
>>> gnupg.options.extra_args = ['--no-secmem-warning']
- >>>
+ >>>
>>> # no need for users to call this normally; just for show here
>>> gnupg.options.get_args()
['--armor', '--recipient', 'Alice', '--recipient', 'Bob', '--no-secmem-warning']
"""
-
+
def __init__(self):
# booleans
self.armor = 0
@@ -553,13 +553,13 @@ class Options:
# lists
self.encrypt_to = []
self.recipients = []
-
+
# miscellaneous arguments
self.extra_args = []
-
+
def get_args( self ):
"""Generate a list of GnuPG arguments based upon attributes."""
-
+
return self.get_meta_args() + self.get_standard_args() + self.extra_args
def get_standard_args( self ):
@@ -575,7 +575,7 @@ class Options:
args.extend( [ '--compress-algo', self.compress_algo ] )
if self.default_key is not None:
args.extend( [ '--default-key', self.default_key ] )
-
+
if self.no_options: args.append( '--no-options' )
if self.armor: args.append( '--armor' )
if self.textmode: args.append( '--textmode' )
@@ -591,7 +591,7 @@ class Options:
for r in self.recipients: args.extend( [ '--recipient', r ] )
for r in self.encrypt_to: args.extend( [ '--encrypt-to', r ] )
-
+
return args
def get_meta_args( self ):
@@ -610,26 +610,26 @@ class Options:
class Process:
"""Objects of this class encompass properties of a GnuPG
process spawned by GnuPG.run().
-
+
# gnupg is a GnuPG object
process = gnupg.run( [ '--decrypt' ], stdout = 1 )
out = process.handles['stdout'].read()
...
os.waitpid( process.pid, 0 )
-
+
Data Attributes
-
+
handles -- This is a map of filehandle-names to
the file handles, if any, that were requested via run() and hence
are connected to the running GnuPG process. Valid names
of this map are only those handles that were requested.
-
+
pid -- The PID of the spawned GnuPG process.
Useful to know, since once should call
os.waitpid() to clean up the process, especially
if multiple calls are made to run().
"""
-
+
def __init__(self):
self._pipes = {}
self.handles = {}
@@ -639,7 +639,7 @@ class Process:
def wait(self):
"""Wait on the process to exit, allowing for child cleanup.
Will raise an IOError if the process exits non-zero."""
-
+
e = os.waitpid(self.pid, 0)[1]
if e != 0:
raise IOError, "GnuPG exited non-zero, with code %d" % (e << 8)
diff --git a/src/common/atom.py b/src/common/atom.py
index 1b1f9f0b4..1476cfd44 100644
--- a/src/common/atom.py
+++ b/src/common/atom.py
@@ -88,7 +88,7 @@ class OldEntry(xmpp.Node, object):
source_feed = self.getTag('feed').getTagData('title')
else:
source_feed = None
-
+
if main_feed is not None and source_feed is not None:
return u'%s: %s' % (main_feed, source_feed)
@@ -99,7 +99,7 @@ class OldEntry(xmpp.Node, object):
else:
return u''
- feed_title = property(get_feed_title, None, None,
+ feed_title = property(get_feed_title, None, None,
''' Title of feed. It is built from entry''s original feed title and title of feed
which delivered this entry. ''')
@@ -151,7 +151,7 @@ class OldEntry(xmpp.Node, object):
return date
- updated = property(get_updated, None, None,
+ updated = property(get_updated, None, None,
''' Last significant modification time. ''')
feed_tagline = u''
diff --git a/src/common/caps.py b/src/common/caps.py
index 0d955e224..00c88b02d 100644
--- a/src/common/caps.py
+++ b/src/common/caps.py
@@ -239,7 +239,7 @@ class ConnectionCaps(object):
if contact is None:
# TODO: a way to put contact not-in-roster
# into Contacts
- return
+ return
# get the caps element
caps = presence.getTag('c')
diff --git a/src/common/check_paths.py b/src/common/check_paths.py
index 7ddf6c735..8b24cccb9 100644
--- a/src/common/check_paths.py
+++ b/src/common/check_paths.py
@@ -42,7 +42,7 @@ except ImportError:
def create_log_db():
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
cur = con.cursor()
# create the tables
@@ -61,19 +61,19 @@ def create_log_db():
jid TEXT UNIQUE,
type INTEGER
);
-
+
CREATE TABLE unread_messages(
message_id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
jid_id INTEGER
);
-
+
CREATE INDEX idx_unread_messages_jid_id ON unread_messages (jid_id);
-
+
CREATE TABLE transports_cache (
transport TEXT UNIQUE,
type INTEGER
);
-
+
CREATE TABLE logs(
log_line_id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
jid_id INTEGER,
@@ -84,7 +84,7 @@ def create_log_db():
message TEXT,
subject TEXT
);
-
+
CREATE INDEX idx_logs_jid_id_kind ON logs (jid_id, kind);
CREATE TABLE caps_cache (
@@ -137,7 +137,7 @@ def check_and_possibly_create_paths():
print _('%s is a directory but should be a file') % LOG_DB_PATH
print _('Gajim will now exit')
sys.exit()
-
+
else: # dot_gajim doesn't exist
if dot_gajim: # is '' on win9x so avoid that
create_path(dot_gajim)
diff --git a/src/common/commands.py b/src/common/commands.py
index 73f9d521e..dec1b4018 100644
--- a/src/common/commands.py
+++ b/src/common/commands.py
@@ -36,7 +36,7 @@ class AdHocCommand:
def isVisibleFor(samejid):
''' This returns True if that command should be visible and invokable
for others.
- samejid - True when command is invoked by an entity with the same bare
+ samejid - True when command is invoked by an entity with the same bare
jid.'''
return True
@@ -88,7 +88,7 @@ class ChangeStatusCommand(AdHocCommand):
# first query...
response, cmd = self.buildResponse(request, defaultaction = 'execute',
actions = ['execute'])
-
+
cmd.addChild(node = dataforms.SimpleDataForm(
title = _('Change status'),
instructions = _('Set the presence type and description'),
@@ -113,7 +113,7 @@ class ChangeStatusCommand(AdHocCommand):
# for next invocation
self.execute = self.changestatus
-
+
return True # keep the session
def changestatus(self, request):
@@ -193,7 +193,7 @@ class LeaveGroupchatsCommand(AdHocCommand):
if not len(options):
response, cmd = self.buildResponse(request, status = 'completed')
cmd.addChild('note', {}, _('You have not joined a groupchat.'))
-
+
self.connection.connection.send(response)
return False
diff --git a/src/common/config.py b/src/common/config.py
index 95e5fa763..33447822a 100644
--- a/src/common/config.py
+++ b/src/common/config.py
@@ -191,7 +191,7 @@ class Config:
'noconfirm_close_muc_rooms': [opt_str, '', _('Never ask before closing group chat tab/window in this space separated list of group chat jids.')],
'notify_on_file_complete': [opt_bool, True],
'file_transfers_port': [opt_int, 28011],
- 'ft_add_hosts_to_send': [opt_str, '', _('Comma separated list of hosts that we send, in addition of local interfaces, for File Transfer in case of address translation/port forwarding.')],
+ 'ft_add_hosts_to_send': [opt_str, '', _('Comma separated list of hosts that we send, in addition of local interfaces, for File Transfer in case of address translation/port forwarding.')],
'conversation_font': [opt_str, ''],
'use_kib_mib': [opt_bool, False, _('IEC standard says KiB = 1024 bytes, KB = 1000 bytes.')],
'notify_on_all_muc_messages': [opt_bool, False],
@@ -557,7 +557,7 @@ class Config:
if optname not in self.__options:
return None
return self.__options[optname][OPT_VAL]
-
+
def get_desc(self, optname):
if optname not in self.__options:
return None
@@ -574,7 +574,7 @@ class Config:
if typename not in self.__options_per_key:
# raise RuntimeError, 'option %s does not exist' % typename
return
-
+
opt = self.__options_per_key[typename]
if name in opt[1]:
# we already have added group name before
@@ -589,7 +589,7 @@ class Config:
opt = self.__options_per_key[typename]
if subname is None:
del opt[1][name]
- # if subname is specified, delete the item in the group.
+ # if subname is specified, delete the item in the group.
elif subname in opt[1][name]:
del opt[1][name][subname]
diff --git a/src/common/connection.py b/src/common/connection.py
index 9aa9aa3bc..0393201d5 100644
--- a/src/common/connection.py
+++ b/src/common/connection.py
@@ -1542,7 +1542,7 @@ class Connection(ConnectionHandlers):
# Not in special table, get it from messages DB
last_log = gajim.logger.get_last_date_that_has_logs(room_jid,
is_room = True)
- # Create self.last_history_time[room_jid] even if not logging,
+ # Create self.last_history_time[room_jid] even if not logging,
# could be used in connection_handlers
if last_log is None:
last_log = 0
diff --git a/src/common/connection_handlers.py b/src/common/connection_handlers.py
index 24d3e4072..f316fa671 100644
--- a/src/common/connection_handlers.py
+++ b/src/common/connection_handlers.py
@@ -331,7 +331,7 @@ class ConnectionBytestream:
return
def _connect_error(self, to, _id, sid, code = 404):
- ''' cb, when there is an error establishing BS connection, or
+ ''' cb, when there is an error establishing BS connection, or
when connection is rejected'''
if not self.connection or self.connected < 2:
return
@@ -1471,7 +1471,7 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco,
'password': conf.getTagData('password'),
'nick': conf.getTagData('nick'),
'print_status': print_status}
-
+
self.bookmarks.append(bm)
self.dispatch('BOOKMARKS', self.bookmarks)
@@ -1501,7 +1501,7 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco,
groups.append(group.getData())
self.dispatch('ROSTER_INFO', (jid, name, sub, ask, groups))
raise common.xmpp.NodeProcessed
-
+
def _VersionCB(self, con, iq_obj):
gajim.log.debug('VersionCB')
if not self.connection or self.connected < 2:
@@ -1526,7 +1526,7 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco,
qp.attrs['seconds'] = '0'
else:
qp.attrs['seconds'] = idle.getIdleSec()
-
+
self.connection.send(iq_obj)
raise common.xmpp.NodeProcessed
@@ -2256,7 +2256,7 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco,
if reason:
users_dict[jid]['reason'] = reason
- self.dispatch('GC_AFFILIATION', (helpers.get_full_jid_from_iq(iq_obj),
+ self.dispatch('GC_AFFILIATION', (helpers.get_full_jid_from_iq(iq_obj),
users_dict))
def _MucErrorCB(self, con, iq_obj):
@@ -2294,13 +2294,13 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco,
if not self.connection:
return
self.connection.getRoster(self._on_roster_set)
- self.discoverItems(gajim.config.get_per('accounts', self.name,
+ self.discoverItems(gajim.config.get_per('accounts', self.name,
'hostname'), id_prefix='p')
- self.discoverInfo(gajim.config.get_per('accounts', self.name,
+ self.discoverInfo(gajim.config.get_per('accounts', self.name,
'hostname'), id_prefix='p')
if gajim.config.get_per('accounts', self.name, 'use_ft_proxies'):
self.discover_ft_proxies()
-
+
def discover_ft_proxies(self):
cfg_proxies = gajim.config.get_per('accounts', self.name,
'file_transfer_proxies')
@@ -2310,7 +2310,7 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco,
proxies = map(lambda e:e.strip(), cfg_proxies.split(','))
for proxy in proxies:
gajim.proxy65_manager.resolve(proxy, self.connection, our_jid)
-
+
def _on_roster_set(self, roster):
raw_roster = roster.getRaw()
roster = {}
@@ -2398,7 +2398,7 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco,
# Inform GUI we just signed in
self.dispatch('SIGNED_IN', ())
self.continue_connect_info = None
-
+
def request_gmail_notifications(self):
if not self.connection or self.connected < 2:
return
@@ -2421,7 +2421,7 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco,
query.setNamespace(common.xmpp.NS_GMAILNOTIFY)
self.connection.send(iq)
-
+
def _search_fields_received(self, con, iq_obj):
jid = jid = helpers.get_jid_from_iq(iq_obj)
tag = iq_obj.getTag('query', namespace = common.xmpp.NS_SEARCH)
diff --git a/src/common/contacts.py b/src/common/contacts.py
index f09b8e0c1..51a29b3c2 100644
--- a/src/common/contacts.py
+++ b/src/common/contacts.py
@@ -197,7 +197,7 @@ class Contacts:
caps_hash_method=None, caps_hash=None, our_chatstate=None,
chatstate=None, last_status_time=None, composing_xep=None,
mood={}, tune={}, activity={}):
-
+
# We don't want duplicated group values
groups_unique = []
for group in groups:
@@ -210,7 +210,7 @@ class Contacts:
caps_hash=caps_hash, our_chatstate=our_chatstate, chatstate=chatstate,
last_status_time=last_status_time, composing_xep=composing_xep,
mood=mood, tune=tune, activity=activity)
-
+
def copy_contact(self, contact):
return self.create_contact(jid=contact.jid, name=contact.name,
groups=contact.groups, show=contact.show, status=contact.status,
@@ -272,7 +272,7 @@ class Contacts:
return self._contacts[account][jid]
else:
return []
-
+
def get_contact(self, account, jid, resource=None):
### WARNING ###
# This function returns a *RANDOM* resource if resource = None!
@@ -437,7 +437,7 @@ class Contacts:
nearby_family = [data for data in family
if account in accounts]
bb_data = self.get_metacontacts_big_brother(nearby_family)
- if bb_data['jid'] == jid and bb_data['account'] == account:
+ if bb_data['jid'] == jid and bb_data['account'] == account:
return True
return False
@@ -484,7 +484,7 @@ class Contacts:
# is not in our roster
if not contact1:
if contact2:
- return -1 # prefer the known contact
+ return -1 # prefer the known contact
else:
show1 = 0
priority1 = 0
@@ -578,7 +578,7 @@ class Contacts:
role='', affiliation='', jid='', resource=''):
return GC_Contact(room_jid, name, show, status, role, affiliation, jid,
resource)
-
+
def add_gc_contact(self, account, gc_contact):
# No such account before ?
if account not in self._gc_contacts:
diff --git a/src/common/crypto.py b/src/common/crypto.py
index b9d90151e..17a010976 100644
--- a/src/common/crypto.py
+++ b/src/common/crypto.py
@@ -90,7 +90,7 @@ def srand(bottom, top):
return (decode_mpi(random_bytes(bytes)) % (top - bottom)) + bottom
# a faster version of (base ** exp) % mod
-# taken from <http://lists.danga.com/pipermail/yadis/2005-September/001445.html>
+# taken from <http://lists.danga.com/pipermail/yadis/2005-September/001445.html>
def powmod(base, exp, mod):
square = base % mod
result = 1
diff --git a/src/common/dataforms.py b/src/common/dataforms.py
index 6aa71d431..34faae66e 100644
--- a/src/common/dataforms.py
+++ b/src/common/dataforms.py
@@ -129,7 +129,7 @@ class DataField(ExtendedNode):
assert isinstance(value, basestring)
self.setAttr('type', value)
return locals()
-
+
@nested_property
def var():
'''Field identifier.'''
@@ -274,7 +274,7 @@ class ListMultiField(ListField):
for element in self.getTags('value'):
self.delChild(element)
return locals()
-
+
def iter_values(self):
for element in self.getTags('value'):
yield element.getData()
@@ -412,7 +412,7 @@ class SimpleDataForm(DataForm, DataRecord):
def __init__(self, type_=None, title=None, instructions=None, fields=None, extend=None):
DataForm.__init__(self, type_=type_, title=title, instructions=instructions, extend=extend)
DataRecord.__init__(self, fields=fields, extend=self, associated=self)
-
+
def get_purged(self):
c = SimpleDataForm(extend=self)
del c.title
diff --git a/src/common/dbus_support.py b/src/common/dbus_support.py
index 77f965e1e..4ceacde39 100644
--- a/src/common/dbus_support.py
+++ b/src/common/dbus_support.py
@@ -51,7 +51,7 @@ class SystemBus:
'''A Singleton for the DBus SystemBus'''
def __init__(self):
self.system_bus = None
-
+
def SystemBus(self):
if not supported:
raise exceptions.DbusNotSupported
@@ -84,7 +84,7 @@ class SessionBus:
'''A Singleton for the D-Bus SessionBus'''
def __init__(self):
self.session_bus = None
-
+
def SessionBus(self):
if not supported:
raise exceptions.DbusNotSupported
@@ -112,7 +112,7 @@ class SessionBus:
session_bus = SessionBus()
def get_interface(interface, path):
- '''Returns an interface on the current SessionBus. If the interface isn\'t
+ '''Returns an interface on the current SessionBus. If the interface isn\'t
running, it tries to start it first.'''
if not supported:
return None
@@ -148,7 +148,7 @@ def get_notifications_interface():
if supported:
class MissingArgument(dbus.DBusException):
_dbus_error_name = _GAJIM_ERROR_IFACE + '.MissingArgument'
-
+
class InvalidArgument(dbus.DBusException):
'''Raised when one of the provided arguments is invalid.'''
_dbus_error_name = _GAJIM_ERROR_IFACE + '.InvalidArgument'
diff --git a/src/common/gajim.py b/src/common/gajim.py
index 8819e8243..b46c47a1d 100644
--- a/src/common/gajim.py
+++ b/src/common/gajim.py
@@ -166,7 +166,7 @@ except ImportError:
HAVE_GPG = True
try:
- import GnuPGInterface
+ import GnuPGInterface
except ImportError:
HAVE_GPG = False
else:
diff --git a/src/common/helpers.py b/src/common/helpers.py
index 1cc0d41a3..3183e9982 100644
--- a/src/common/helpers.py
+++ b/src/common/helpers.py
@@ -350,10 +350,10 @@ def get_uf_role(role, plural = False):
else:
role_name = _('Visitor')
return role_name
-
+
def get_uf_affiliation(affiliation):
'''Get a nice and translated affilition for muc'''
- if affiliation == 'none':
+ if affiliation == 'none':
affiliation_name = Q_('?Group Chat Contact Affiliation:None')
elif affiliation == 'owner':
affiliation_name = _('Owner')
@@ -593,7 +593,7 @@ def get_global_status():
status = gajim.connections[account].status
return status
-def statuses_unified():
+def statuses_unified():
'''testing if all statuses are the same.'''
reference = None
for account in gajim.connections:
@@ -765,7 +765,7 @@ def get_random_string_16():
char_sequence = map(lambda e:chr(e), rng)
from random import sample
return ''.join(sample(char_sequence, 16))
-
+
def get_os_info():
if os.name == 'nt':
ver = os.sys.getwindowsversion()
@@ -790,9 +790,9 @@ def get_os_info():
full_path_to_executable = is_in_path(executable, return_abs_path = True)
if full_path_to_executable:
command = executable + params
- p = subprocess.Popen([command], shell=True, stdin=subprocess.PIPE,
- stdout=subprocess.PIPE, close_fds=True)
- p.wait()
+ p = subprocess.Popen([command], shell=True, stdin=subprocess.PIPE,
+ stdout=subprocess.PIPE, close_fds=True)
+ p.wait()
output = temp_failure_retry(p.stdout.readline).strip()
# some distros put n/a in places, so remove those
output = output.replace('n/a', '').replace('N/A', '')
@@ -832,7 +832,7 @@ def get_os_info():
return 'N/A'
def sanitize_filename(filename):
- '''makes sure the filename we will write does contain only acceptable and
+ '''makes sure the filename we will write does contain only acceptable and
latin characters, and is not too long (in that case hash it)'''
# 48 is the limit
if len(filename) > 48:
@@ -845,7 +845,7 @@ def sanitize_filename(filename):
filename = filename.replace('?', '_').replace(':', '_')\
.replace('\\', '_').replace('"', "'").replace('|', '_')\
.replace('*', '_').replace('<', '_').replace('>', '_')
-
+
return filename
def allow_showing_notification(account, type_ = 'notify_on_new_message',
@@ -952,7 +952,7 @@ def get_account_status(account):
return status
def get_notification_icon_tooltip_dict():
- '''returns a dict of the form {acct: {'show': show, 'message': message,
+ '''returns a dict of the form {acct: {'show': show, 'message': message,
'event_lines': [list of text lines to show in tooltip]}'''
# How many events must there be before they're shown summarized, not per-user
max_ungrouped_events = 10
@@ -1000,7 +1000,7 @@ def get_notification_icon_tooltip_dict():
else:
text += _(' from %s') % (jid)
account['event_lines'].append(text)
-
+
# Display unseen events numbers, if any
if total_non_messages > 0:
if total_non_messages > max_ungrouped_events:
@@ -1044,7 +1044,7 @@ def get_notification_icon_tooltip_text():
# If there is only one account, its status is shown on the first line.
if show_more_accounts:
text = _('Gajim')
- else:
+ else:
text = _('Gajim - %s') % (get_account_status(accounts[0]))
# Gather and display events. (With accounts, when there are more.)
@@ -1081,7 +1081,7 @@ def get_accounts_info():
message = message.strip()
if message != '':
single_line += ': ' + message
- accounts.append({'name': account, 'status_line': single_line,
+ accounts.append({'name': account, 'status_line': single_line,
'show': status, 'message': message})
return accounts
@@ -1150,13 +1150,13 @@ def prepare_and_validate_gpg_keyID(account, jid, keyID):
'''Returns an eight char long keyID that can be used with for GPG encryption with this contact.
If the given keyID is None, return UNKNOWN; if the key does not match the assigned key
XXXXXXXXMISMATCH is returned. If the key is trusted and not yet assigned, assign it'''
- if gajim.connections[account].USE_GPG:
+ if gajim.connections[account].USE_GPG:
if keyID and len(keyID) == 16:
keyID = keyID[8:]
-
+
attached_keys = gajim.config.get_per('accounts', account,
'attached_gpg_keys').split()
-
+
if jid in attached_keys and keyID:
attachedkeyID = attached_keys[attached_keys.index(jid) + 1]
if attachedkeyID != keyID:
@@ -1165,7 +1165,7 @@ def prepare_and_validate_gpg_keyID(account, jid, keyID):
elif jid in attached_keys:
# An unsigned presence, just use the assigned key
keyID = attached_keys[attached_keys.index(jid) + 1]
- elif keyID:
+ elif keyID:
public_keys = gajim.connections[account].ask_gpg_keys()
# Assign the corresponding key, if we have it in our keyring
if keyID in public_keys:
@@ -1208,7 +1208,7 @@ def sort_dataforms_func(d1, d2):
def compute_caps_hash(identities, features, dataforms=[], hash_method='sha-1'):
'''Compute caps hash according to XEP-0115, V1.5
-
+
dataforms are xmpp.DataForms objects as common.dataforms don't allow several
values without a field type list-multi'''
S = ''
diff --git a/src/common/i18n.py b/src/common/i18n.py
index b4c02ac41..04d45d833 100644
--- a/src/common/i18n.py
+++ b/src/common/i18n.py
@@ -58,7 +58,7 @@ def Q_(s):
# so we must use as:
# s = Q_('?vcard:Unknown')
# widget.set_text(s)
- # Q_() removes the ?vcard:
+ # Q_() removes the ?vcard:
# but gettext while parsing the file detects ?vcard:Unknown as a whole string.
# translator can either put the ?vcard: part or no (easier for him or her to no)
# nothing fails
@@ -70,7 +70,7 @@ def Q_(s):
def ngettext(s_sing, s_plural, n, replace_sing = None, replace_plural = None):
'''use as:
i18n.ngettext('leave room %s', 'leave rooms %s', len(rooms), 'a', 'a, b, c')
-
+
in other words this is a hack to ngettext() to support %s %d etc..
'''
text = _translation.ungettext(s_sing, s_plural, n)
diff --git a/src/common/logger.py b/src/common/logger.py
index 5a2c24c15..943b42777 100644
--- a/src/common/logger.py
+++ b/src/common/logger.py
@@ -176,8 +176,8 @@ class Logger:
pm (so higly unlikely) and if we fail we do not go chaos
(user will see the first pm as if it was message in room's public chat)
and after that all okay'''
-
- if jid.find('/') > -1:
+
+ if jid.find('/') > -1:
possible_room_jid = jid.split('/', 1)[1]
return self.jid_is_room_jid(possible_room_jid)
else:
@@ -336,7 +336,7 @@ class Logger:
try:
self.cur.execute(sql, values)
except sqlite.DatabaseError:
- raise exceptions.DatabaseMalformed
+ raise exceptions.DatabaseMalformed
except sqlite.OperationalError, e:
raise exceptions.PysqliteOperationalError(str(e))
message_id = None
@@ -373,7 +373,7 @@ class Logger:
for message in results:
msg_id = message[0]
# here we get infos for that message, and related jid from jids table
- # do NOT change order of SELECTed things, unless you change function(s)
+ # do NOT change order of SELECTed things, unless you change function(s)
# that called this function
self.cur.execute('''
SELECT logs.log_line_id, logs.message, logs.time, logs.subject,
diff --git a/src/common/nslookup.py b/src/common/nslookup.py
index 748b8aca8..943eca1ed 100644
--- a/src/common/nslookup.py
+++ b/src/common/nslookup.py
@@ -43,22 +43,22 @@ class Resolver:
def __init__(self, idlequeue):
self.idlequeue = idlequeue
# dict {host : list of srv records}
- self.resolved_hosts = {}
+ self.resolved_hosts = {}
# dict {host : list of callbacks}
- self.handlers = {}
-
+ self.handlers = {}
+
def parse_srv_result(self, fqdn, result):
- ''' parse the output of nslookup command and return list of
+ ''' parse the output of nslookup command and return list of
properties: 'host', 'port','weight', 'priority' corresponding to the found
srv hosts '''
if os.name == 'nt':
return self._parse_srv_result_nt(fqdn, result)
elif os.name == 'posix':
return self._parse_srv_result_posix(fqdn, result)
-
+
def _parse_srv_result_nt(self, fqdn, result):
# output from win32 nslookup command
- if not result:
+ if not result:
return []
hosts = []
lines = result.replace('\r','').split('\n')
@@ -78,7 +78,7 @@ class Resolver:
hosts.append(current_host)
current_host = None
continue
- prop_type = res[0].strip()
+ prop_type = res[0].strip()
prop_value = res[1].strip()
if prop_type.find('prio') > -1:
try:
@@ -104,11 +104,11 @@ class Resolver:
hosts.append(current_host)
current_host = None
return hosts
-
+
def _parse_srv_result_posix(self, fqdn, result):
# typical output of bind-tools nslookup command:
# _xmpp-client._tcp.jabber.org service = 30 30 5222 jabber.org.
- if not result:
+ if not result:
return []
ufqdn = helpers.ascii_to_idn(fqdn) # Unicode domain name
hosts = []
@@ -144,11 +144,11 @@ class Resolver:
hosts.append({'host': host, 'port': port,'weight': weight,
'prio': prio})
return hosts
-
+
def _on_ready(self, host, result):
# nslookup finished, parse the result and call the handlers
result_list = self.parse_srv_result(host, result)
-
+
# practically it is impossible to be the opposite, but who knows :)
if host not in self.resolved_hosts:
self.resolved_hosts[host] = result_list
@@ -156,14 +156,14 @@ class Resolver:
for callback in self.handlers[host]:
callback(host, result_list)
del(self.handlers[host])
-
+
def start_resolve(self, host):
''' spawn new nslookup process and start waiting for results '''
ns = NsLookup(self._on_ready, host)
ns.set_idlequeue(self.idlequeue)
ns.commandtimeout = 10
ns.start()
-
+
def resolve(self, host, on_ready):
if not host:
# empty host, return empty list of srv records
@@ -175,7 +175,7 @@ class Resolver:
return
if host in self.handlers:
# host is about to be resolved by another connection,
- # attach our callback
+ # attach our callback
self.handlers[host].append(on_ready)
else:
# host has never been resolved, start now
@@ -187,29 +187,29 @@ class IdleCommand(IdleObject):
def __init__(self, on_result):
# how long (sec.) to wait for result ( 0 - forever )
# it is a class var, instead of a constant and we can override it.
- self.commandtimeout = 0
+ self.commandtimeout = 0
# when we have some kind of result (valid, ot not) we call this handler
self.result_handler = on_result
# if it is True, we can safetely execute the command
self.canexecute = True
self.idlequeue = None
self.result = ''
-
+
def set_idlequeue(self, idlequeue):
self.idlequeue = idlequeue
-
+
def _return_result(self):
if self.result_handler:
self.result_handler(self.result)
self.result_handler = None
-
+
def _compose_command_args(self):
return ['echo', 'da']
-
+
def _compose_command_line(self):
''' return one line representation of command and its arguments '''
return ' '.join(self._compose_command_args())
-
+
def wait_child(self):
if self.pipe.poll() is None:
# result timeout
@@ -235,16 +235,16 @@ class IdleCommand(IdleObject):
self._start_nt()
elif os.name == 'posix':
self._start_posix()
-
+
def _start_nt(self):
- # if gajim is started from noninteraactive shells stdin is closed and
+ # if gajim is started from noninteraactive shells stdin is closed and
# cannot be forwarded, so we have to keep it open
- self.pipe = Popen(self._compose_command_args(), stdout=PIPE,
+ self.pipe = Popen(self._compose_command_args(), stdout=PIPE,
bufsize = 1024, shell = True, stderr = STDOUT, stdin = PIPE)
if self.commandtimeout >= 0:
self.endtime = self.idlequeue.current_time() + self.commandtimeout
self.idlequeue.set_alarm(self.wait_child, 0.1)
-
+
def _start_posix(self):
self.pipe = os.popen(self._compose_command_line())
self.fd = self.pipe.fileno()
@@ -252,19 +252,19 @@ class IdleCommand(IdleObject):
self.idlequeue.plug_idle(self, False, True)
if self.commandtimeout >= 0:
self.idlequeue.set_read_timeout(self.fd, self.commandtimeout)
-
+
def end(self):
self.idlequeue.unplug_idle(self.fd)
try:
self.pipe.close()
except Exception:
pass
-
+
def pollend(self):
self.idlequeue.remove_timeout(self.fd)
self.end()
self._return_result()
-
+
def pollin(self):
try:
res = self.pipe.read()
@@ -274,15 +274,15 @@ class IdleCommand(IdleObject):
return self.pollend()
else:
self.result += res
-
+
def read_timeout(self):
self.end()
self._return_result()
-
+
class NsLookup(IdleCommand):
def __init__(self, on_result, host='_xmpp-client', type_ = 'srv'):
IdleCommand.__init__(self, on_result)
- self.commandtimeout = 10
+ self.commandtimeout = 10
self.host = host.lower()
self.type = type_.lower()
if not host_pattern.match(self.host):
@@ -294,15 +294,15 @@ class NsLookup(IdleCommand):
print >> sys.stderr, 'Invalid querytype: %s' % self.type
self.canexecute = False
return
-
+
def _compose_command_args(self):
return ['nslookup', '-type=' + self.type , self.host]
-
+
def _return_result(self):
if self.result_handler:
self.result_handler(self.host, self.result)
self.result_handler = None
-
+
# below lines is on how to use API and assist in testing
if __name__ == '__main__':
if os.name == 'posix':
@@ -312,9 +312,9 @@ if __name__ == '__main__':
# testing Resolver class
import gobject
import gtk
-
+
resolver = Resolver(idlequeue)
-
+
def clicked(widget):
host = text_view.get_text()
def on_result(host, result_array):
diff --git a/src/common/optparser.py b/src/common/optparser.py
index 9b9ccd467..ce6b56d2f 100644
--- a/src/common/optparser.py
+++ b/src/common/optparser.py
@@ -106,7 +106,7 @@ class OptionsParser:
s += p + '.'
s += opt
fd.write(s + ' = ' + value + '\n')
-
+
def write(self):
(base_dir, filename) = os.path.split(self.__filename)
self.__tempfile = os.path.join(base_dir, '.' + filename)
@@ -192,7 +192,7 @@ class OptionsParser:
gajim.config.set('version', new_version)
gajim.capscache.load_from_db()
-
+
def update_config_x_to_09(self):
# Var name that changed:
# avatar_width /height -> chat_avatar_width / height
@@ -212,7 +212,7 @@ class OptionsParser:
d = ['accounttextcolor', 'accountbgcolor', 'accountfont',
'accountfontattrs', 'grouptextcolor', 'groupbgcolor', 'groupfont',
'groupfontattrs', 'contacttextcolor', 'contactbgcolor', 'contactfont',
- 'contactfontattrs', 'bannertextcolor', 'bannerbgcolor', 'bannerfont',
+ 'contactfontattrs', 'bannertextcolor', 'bannerbgcolor', 'bannerfont',
'bannerfontattrs']
for theme_name in (_('grocery'), _('default')):
if theme_name not in gajim.config.get_per('themes'):
@@ -281,15 +281,15 @@ class OptionsParser:
if 'always_compact_view_gc' in self.old_values and \
self.old_values['always_compact_view_gc'] != 'False':
gajim.config.set('always_hide_groupchat_buttons', True)
-
+
for account in gajim.config.get_per('accounts'):
proxies_str = gajim.config.get_per('accounts', account,
'file_transfer_proxies')
proxies = proxies_str.split(',')
for i in range(0, len(proxies)):
proxies[i] = proxies[i].strip()
- for wrong_proxy in ('proxy65.jabber.autocom.pl',
- 'proxy65.jabber.ccc.de'):
+ for wrong_proxy in ('proxy65.jabber.autocom.pl',
+ 'proxy65.jabber.ccc.de'):
if wrong_proxy in proxies:
proxies.remove(wrong_proxy)
if not 'transfer.jabber.freenet.de' in proxies:
@@ -380,9 +380,9 @@ class OptionsParser:
cur.close() # remove this in 2007 [pysqlite old versions need this]
con.close()
gajim.config.set('version', '0.10.1.5')
-
+
def update_config_to_01016(self):
- '''#2494 : Now we play gc_received_message sound even if
+ '''#2494 : Now we play gc_received_message sound even if
notify_on_all_muc_messages is false. Keep precedent behaviour.'''
if 'notify_on_all_muc_messages' in self.old_values and \
self.old_values['notify_on_all_muc_messages'] == 'False' and \
@@ -419,7 +419,7 @@ class OptionsParser:
gajim.config.set('ft_add_hosts_to_send',
self.old_values['ft_override_host_to_send'])
gajim.config.set('version', '0.11.0.2')
-
+
def update_config_to_01111(self):
'''always_hide_chatbuttons -> compact_view'''
if 'always_hide_groupchat_buttons' in self.old_values and \
@@ -464,7 +464,7 @@ class OptionsParser:
d = ['accounttextcolor', 'accountbgcolor', 'accountfont',
'accountfontattrs', 'grouptextcolor', 'groupbgcolor', 'groupfont',
'groupfontattrs', 'contacttextcolor', 'contactbgcolor', 'contactfont',
- 'contactfontattrs', 'bannertextcolor', 'bannerbgcolor', 'bannerfont',
+ 'contactfontattrs', 'bannertextcolor', 'bannerbgcolor', 'bannerfont',
'bannerfontattrs']
theme_name = _('default')
if theme_name not in gajim.config.get_per('themes'):
@@ -481,7 +481,7 @@ class OptionsParser:
for o in d:
gajim.config.set_per('themes', theme_name, o, theme[d.index(o)])
gajim.config.set('version', '0.11.1.4')
-
+
def update_config_to_01115(self):
# copy&pasted from update_config_to_01013, possibly 'FIXME see #2812' applies too
back = os.getcwd()
diff --git a/src/common/proxy65_manager.py b/src/common/proxy65_manager.py
index 652bc6e55..8056a46e2 100644
--- a/src/common/proxy65_manager.py
+++ b/src/common/proxy65_manager.py
@@ -20,7 +20,7 @@
## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
##
-import socket
+import socket
import struct
import errno
@@ -39,9 +39,9 @@ S_FINISHED = 4
CONNECT_TIMEOUT = 20
class Proxy65Manager:
- ''' keep records for file transfer proxies. Each time account
- establishes a connection to its server call proxy65manger.resolve(proxy)
- for every proxy that is convigured within the account. The class takes
+ ''' keep records for file transfer proxies. Each time account
+ establishes a connection to its server call proxy65manger.resolve(proxy)
+ for every proxy that is convigured within the account. The class takes
care to resolve and test each proxy only once.'''
def __init__(self, idlequeue):
# dict {proxy: proxy properties}
@@ -111,9 +111,9 @@ class ProxyResolver:
# self.sid, self.sender_jid, self._on_receiver_success,
# self._on_connect_failure)
#self.receiver_tester.connect()
-
+
def _on_receiver_success(self):
- self.host_tester = HostTester(self.host, self.port, self.jid,
+ self.host_tester = HostTester(self.host, self.port, self.jid,
self.sid, self.sender_jid, self._on_connect_success,
self._on_connect_failure)
self.host_tester.connect()
@@ -252,7 +252,7 @@ class HostTester(Socks5, IdleObject):
self.idlequeue.remove_timeout(self.fd)
if self.state == 2:
self.idlequeue.set_read_timeout(self.fd, CONNECT_TIMEOUT)
- # begin negotiation. on success 'address' != 0
+ # begin negotiation. on success 'address' != 0
buff = self.receive()
if buff == '':
# end connection
@@ -296,7 +296,7 @@ class HostTester(Socks5, IdleObject):
self.buff = ''
self.state = 1 # connected
self.idlequeue.plug_idle(self, True, False)
- return
+ return
class ReceiverTester(Socks5, IdleObject):
''' fake proxy tester. '''
@@ -356,7 +356,7 @@ class ReceiverTester(Socks5, IdleObject):
self.idlequeue.remove_timeout(self.fd)
if self.state in (2, 3):
self.idlequeue.set_read_timeout(self.fd, CONNECT_TIMEOUT)
- # begin negotiation. on success 'address' != 0
+ # begin negotiation. on success 'address' != 0
buff = self.receive()
if buff == '':
# end connection
@@ -408,6 +408,6 @@ class ReceiverTester(Socks5, IdleObject):
self.buff = ''
self.state = 1 # connected
self.idlequeue.plug_idle(self, True, False)
- return
+ return
# vim: se ts=3:
diff --git a/src/common/rst_xhtml_generator.py b/src/common/rst_xhtml_generator.py
index c65387d15..8f57bb698 100644
--- a/src/common/rst_xhtml_generator.py
+++ b/src/common/rst_xhtml_generator.py
@@ -57,7 +57,7 @@ else:
interpret_url:
this, modulo the validated text, will be added to it
validator:
- should return the validated text, or raise ValueError
+ should return the validated text, or raise ValueError
'''
def uri_reference_role(role, rawtext, text, lineno, inliner,
options={}, content=[]):
@@ -143,7 +143,7 @@ else:
def create_xhtml(text):
return Generator.create_xhtml(text)
-
+
if __name__ == '__main__':
print "test 1\n", Generator.create_xhtml("""
diff --git a/src/common/xmpp/__init__.py b/src/common/xmpp/__init__.py
index 1bc3ff027..07d4d237b 100644
--- a/src/common/xmpp/__init__.py
+++ b/src/common/xmpp/__init__.py
@@ -14,8 +14,8 @@ features - different stuff that didn't worths separating into modules
browser - DISCO server framework. Allows to build dynamic disco tree.
filetransfer - Currently contains only IBB stuff. Can be used for bot-to-bot transfers.
-Most of the classes that is defined in all these modules is an ancestors of
-class PlugIn so they share a single set of methods allowing you to compile
+Most of the classes that is defined in all these modules is an ancestors of
+class PlugIn so they share a single set of methods allowing you to compile
a featured XMPP client. For every instance of PlugIn class the 'owner' is the class
in what the plug was plugged. While plugging in such instance usually sets some
methods of owner to it's own ones for easy access. All session specific info stored
diff --git a/src/common/xmpp/auth.py b/src/common/xmpp/auth.py
index 04d7fd60c..b76d1c1d6 100644
--- a/src/common/xmpp/auth.py
+++ b/src/common/xmpp/auth.py
@@ -208,7 +208,7 @@ class SASL(PlugIn):
node=Node('response',attrs={'xmlns':NS_SASL},payload=[base64.encodestring(sasl_data[:-1]).replace('\r','').replace('\n','')])
self._owner.send(node.__str__())
elif 'rspauth' in chal: self._owner.send(Node('response',attrs={'xmlns':NS_SASL}).__str__())
- else:
+ else:
self.startsasl='failure'
self.DEBUG('Failed SASL authentification: unknown challenge','error')
raise NodeProcessed
diff --git a/src/common/xmpp/auth_nb.py b/src/common/xmpp/auth_nb.py
index 034cb9a6f..495913c2c 100644
--- a/src/common/xmpp/auth_nb.py
+++ b/src/common/xmpp/auth_nb.py
@@ -50,7 +50,7 @@ def challenge_splitter(data):
keyword, value = '', ''
dict_ = {}
arr = None
-
+
expecting = X_KEYWORD
for iter_ in range(len(data) + 1):
end = False
@@ -104,12 +104,12 @@ class SASL(PlugIn):
self.on_sasl = on_sasl
self.realm = None
def plugin(self,owner):
- if 'version' not in self._owner.Dispatcher.Stream._document_attrs:
+ if 'version' not in self._owner.Dispatcher.Stream._document_attrs:
self.startsasl='not-supported'
elif self._owner.Dispatcher.Stream.features:
- try:
+ try:
self.FeaturesHandler(self._owner.Dispatcher, self._owner.Dispatcher.Stream.features)
- except NodeProcessed:
+ except NodeProcessed:
pass
else: self.startsasl=None
@@ -117,12 +117,12 @@ class SASL(PlugIn):
''' Start authentication. Result can be obtained via "SASL.startsasl" attribute and will be
either "success" or "failure". Note that successfull auth will take at least
two Dispatcher.Process() calls. '''
- if self.startsasl:
+ if self.startsasl:
pass
elif self._owner.Dispatcher.Stream.features:
- try:
+ try:
self.FeaturesHandler(self._owner.Dispatcher, self._owner.Dispatcher.Stream.features)
- except NodeProcessed:
+ except NodeProcessed:
pass
else: self._owner.RegisterHandler('features', self.FeaturesHandler, xmlns=NS_STREAMS)
@@ -164,9 +164,9 @@ class SASL(PlugIn):
self.mechanism = 'DIGEST-MD5'
elif 'PLAIN' in self.mecs:
self.mecs.remove('PLAIN')
- sasl_data='%s\x00%s\x00%s' % (self.username+'@' + self._owner.Server,
+ sasl_data='%s\x00%s\x00%s' % (self.username+'@' + self._owner.Server,
self.username, self.password)
- node=Node('auth', attrs={'xmlns':NS_SASL,'mechanism':'PLAIN'},
+ node=Node('auth', attrs={'xmlns':NS_SASL,'mechanism':'PLAIN'},
payload=[base64.encodestring(sasl_data).replace('\n','')])
self.mechanism = 'PLAIN'
else:
@@ -179,13 +179,13 @@ class SASL(PlugIn):
def SASLHandler(self, conn, challenge):
''' Perform next SASL auth step. Used internally. '''
- if challenge.getNamespace() != NS_SASL:
+ if challenge.getNamespace() != NS_SASL:
return
if challenge.getName() == 'failure':
self.startsasl = 'failure'
- try:
+ try:
reason = challenge.getChildren()[0]
- except Exception:
+ except Exception:
reason = challenge
self.DEBUG('Failed SASL authentification: %s' % reason, 'error')
if len(self.mecs) > 0:
@@ -244,7 +244,7 @@ class SASL(PlugIn):
resp['nc'] = ('00000001')
resp['qop'] = 'auth'
resp['digest-uri'] = 'xmpp/'+self._owner.Server
- A1=C([H(C([resp['username'], resp['realm'], self.password])),
+ A1=C([H(C([resp['username'], resp['realm'], self.password])),
resp['nonce'], resp['cnonce']])
A2=C(['AUTHENTICATE',resp['digest-uri']])
response= HH(C([HH(A1), resp['nonce'], resp['nc'], resp['cnonce'],
@@ -253,25 +253,25 @@ class SASL(PlugIn):
resp['charset'] = 'utf-8'
sasl_data=''
for key in ('charset', 'username', 'realm', 'nonce', 'nc', 'cnonce', 'digest-uri', 'response', 'qop'):
- if key in ['nc','qop','response','charset']:
+ if key in ['nc','qop','response','charset']:
sasl_data += "%s=%s," % (key,resp[key])
- else:
+ else:
sasl_data += '%s="%s",' % (key,resp[key])
########################################3333
- node=Node('response', attrs={'xmlns':NS_SASL},
+ node=Node('response', attrs={'xmlns':NS_SASL},
payload=[base64.encodestring(sasl_data[:-1]).replace('\r','').replace('\n','')])
self._owner.send(node.__str__())
- elif 'rspauth' in chal:
+ elif 'rspauth' in chal:
self._owner.send(Node('response', attrs={'xmlns':NS_SASL}).__str__())
- else:
+ else:
self.startsasl='failure'
self.DEBUG('Failed SASL authentification: unknown challenge', 'error')
if self.on_sasl :
self.on_sasl ()
raise NodeProcessed
-
+
class NonBlockingNonSASL(PlugIn):
- ''' Implements old Non-SASL (JEP-0078) authentication used
+ ''' Implements old Non-SASL (JEP-0078) authentication used
in jabberd1.4 and transport authentication.
'''
def __init__(self, user, password, resource, on_auth):
@@ -286,15 +286,15 @@ class NonBlockingNonSASL(PlugIn):
def plugin(self, owner):
''' Determine the best auth method (digest/0k/plain) and use it for auth.
Returns used method name on success. Used internally. '''
- if not self.resource:
+ if not self.resource:
return self.authComponent(owner)
self.DEBUG('Querying server about possible auth methods', 'start')
- self.owner = owner
-
+ self.owner = owner
+
owner.Dispatcher.SendAndWaitForResponse(
Iq('get', NS_AUTH, payload=[Node('username', payload=[self.user])]), func=self._on_username
)
-
+
def _on_username(self, resp):
if not isResultNode(resp):
self.DEBUG('No result node arrived! Aborting...','error')
@@ -306,9 +306,9 @@ class NonBlockingNonSASL(PlugIn):
if query.getTag('digest'):
self.DEBUG("Performing digest authentication",'ok')
- query.setTagData('digest',
+ query.setTagData('digest',
sha.new(self.owner.Dispatcher.Stream._document_attrs['id']+self.password).hexdigest())
- if query.getTag('password'):
+ if query.getTag('password'):
query.delChild('password')
self._method='digest'
elif query.getTag('token'):
@@ -330,7 +330,7 @@ class NonBlockingNonSASL(PlugIn):
query.setTagData('password',self.password)
self._method='plain'
resp=self.owner.Dispatcher.SendAndWaitForResponse(iq, func=self._on_auth)
-
+
def _on_auth(self, resp):
if isResultNode(resp):
self.DEBUG('Sucessfully authenticated with remove host.','ok')
@@ -348,7 +348,7 @@ class NonBlockingNonSASL(PlugIn):
payload=[sha.new(owner.Dispatcher.Stream._document_attrs['id']+self.password).hexdigest()]))
owner.RegisterHandler('handshake', self.handshakeHandler, xmlns=NS_COMPONENT_ACCEPT)
self._owner.onreceive(self._on_auth_component)
-
+
def _on_auth_component(self, data):
''' called when we receive some response, after we send the handshake '''
if data:
@@ -358,25 +358,25 @@ class NonBlockingNonSASL(PlugIn):
return
self._owner.onreceive(None)
self._owner._registered_name=self.user
- if self.handshake+1:
+ if self.handshake+1:
return self.on_auth('ok')
self.on_auth(None)
def handshakeHandler(self,disp,stanza):
''' Handler for registering in dispatcher for accepting transport authentication. '''
- if stanza.getName() == 'handshake':
+ if stanza.getName() == 'handshake':
self.handshake=1
- else:
+ else:
self.handshake=-1
-
+
class NonBlockingBind(Bind):
''' Bind some JID to the current connection to allow router know of our location.'''
def plugin(self, owner):
''' Start resource binding, if allowed at this time. Used internally. '''
if self._owner.Dispatcher.Stream.features:
- try:
+ try:
self.FeaturesHandler(self._owner.Dispatcher, self._owner.Dispatcher.Stream.features)
- except NodeProcessed:
+ except NodeProcessed:
pass
else: self._owner.RegisterHandler('features', self.FeaturesHandler, xmlns=NS_STREAMS)
@@ -388,15 +388,15 @@ class NonBlockingBind(Bind):
''' Perform binding. Use provided resource name or random (if not provided). '''
self.on_bound = on_bound
self._resource = resource
- if self._resource:
+ if self._resource:
self._resource = [Node('resource', payload=[self._resource])]
- else:
+ else:
self._resource = []
-
+
self._owner.onreceive(None)
self._owner.Dispatcher.SendAndWaitForResponse(
Protocol('iq',typ='set',
- payload=[Node('bind', attrs={'xmlns':NS_BIND}, payload=self._resource)]),
+ payload=[Node('bind', attrs={'xmlns':NS_BIND}, payload=self._resource)]),
func=self._on_bound)
def _on_bound(self, resp):
if isResultNode(resp):
@@ -405,7 +405,7 @@ class NonBlockingBind(Bind):
jid=JID(resp.getTag('bind').getTagData('jid'))
self._owner.User=jid.getNode()
self._owner.Resource=jid.getResource()
- self._owner.SendAndWaitForResponse(Protocol('iq', typ='set',
+ self._owner.SendAndWaitForResponse(Protocol('iq', typ='set',
payload=[Node('session', attrs={'xmlns':NS_SESSION})]), func=self._on_session)
elif resp:
self.DEBUG('Binding failed: %s.' % resp.getTag('error'),'error')
@@ -413,7 +413,7 @@ class NonBlockingBind(Bind):
else:
self.DEBUG('Binding failed: timeout expired.', 'error')
self.on_bound(None)
-
+
def _on_session(self, resp):
self._owner.onreceive(None)
if isResultNode(resp):
@@ -435,15 +435,15 @@ class NonBlockingBind(Bind):
self.on_bound(None)
class NBComponentBind(ComponentBind):
- ''' ComponentBind some JID to the current connection to allow
+ ''' ComponentBind some JID to the current connection to allow
router know of our location.
'''
def plugin(self,owner):
''' Start resource binding, if allowed at this time. Used internally. '''
if self._owner.Dispatcher.Stream.features:
- try:
+ try:
self.FeaturesHandler(self._owner.Dispatcher, self._owner.Dispatcher.Stream.features)
- except NodeProcessed:
+ except NodeProcessed:
pass
else:
self._owner.RegisterHandler('features', self.FeaturesHandler, xmlns=NS_STREAMS)
@@ -453,14 +453,14 @@ class NBComponentBind(ComponentBind):
''' Remove ComponentBind handler from owner's dispatcher. Used internally. '''
if self.needsUnregister:
self._owner.UnregisterHandler('features', self.FeaturesHandler, xmlns=NS_STREAMS)
-
+
def Bind(self, domain = None, on_bind = None):
''' Perform binding. Use provided domain name (if not provided). '''
def wrapper(resp):
self._on_bound(resp, domain)
self._owner.onreceive(wrapper)
self.on_bind = on_bind
-
+
def _on_bound(self, resp, domain=None):
if resp:
self.Dispatcher.ProcessNonBlocking(resp)
@@ -468,9 +468,9 @@ class NBComponentBind(ComponentBind):
return
self._owner.onreceive(None)
self._owner.SendAndWaitForResponse(
- Protocol('bind', attrs={'name':domain}, xmlns=NS_COMPONENT_1),
+ Protocol('bind', attrs={'name':domain}, xmlns=NS_COMPONENT_1),
func=self._on_bind_reponse)
-
+
def _on_bind_reponse(self, resp):
if resp and resp.getAttr('error'):
self.DEBUG('Binding failed: %s.' % resp.getAttr('error'), 'error')
diff --git a/src/common/xmpp/browser.py b/src/common/xmpp/browser.py
index 0a3d78f55..04fa649b6 100644
--- a/src/common/xmpp/browser.py
+++ b/src/common/xmpp/browser.py
@@ -128,7 +128,7 @@ class Browser(PlugIn):
as handler of some disco tree branch.
If you do not specify the node this handler will be used for all queried nodes.
If you do not specify the jid this handler will be used for all queried JIDs.
-
+
Usage:
cl.Browser.setDiscoHandler(someDict,node,jid)
or
@@ -147,8 +147,8 @@ class Browser(PlugIn):
{'category':'category1','type':'type1','name':'name1'},
{'category':'category2','type':'type2','name':'name2'},
{'category':'category3','type':'type3','name':'name3'},
- ],
- 'features':['feature1','feature2','feature3','feature4'],
+ ],
+ 'features':['feature1','feature2','feature3','feature4'],
'xdata':DataForm
}
}
diff --git a/src/common/xmpp/client.py b/src/common/xmpp/client.py
index cbed92364..c3c0aab46 100644
--- a/src/common/xmpp/client.py
+++ b/src/common/xmpp/client.py
@@ -71,7 +71,7 @@ class PlugIn:
owner.__dict__[method.__name__]=method
owner.__dict__[self.__class__.__name__]=self
if 'plugin' in self.__class__.__dict__: return self.plugin(owner)
-
+
def PlugOut(self):
""" Unregister all our staff from main instance and detach from it. """
self.DEBUG('Plugging %s out of %s.'%(self,self._owner),'stop')
@@ -93,7 +93,7 @@ class CommonClient:
""" Caches server name and (optionally) port to connect to. "debug" parameter specifies
the debug IDs that will go into debug output. You can either specifiy an "include"
or "exclude" list. The latter is done via adding "always" pseudo-ID to the list.
- Full list: ['nodebuilder', 'dispatcher', 'gen_auth', 'SASL_auth', 'bind', 'socket',
+ Full list: ['nodebuilder', 'dispatcher', 'gen_auth', 'SASL_auth', 'bind', 'socket',
'CONNECTproxy', 'TLS', 'roster', 'browser', 'ibb'] . """
if self.__class__.__name__=='Client': self.Namespace,self.DBG='jabber:client',DBG_CLIENT
elif self.__class__.__name__=='Component': self.Namespace,self.DBG=dispatcher.NS_COMPONENT_ACCEPT,DBG_COMPONENT
@@ -161,7 +161,7 @@ class CommonClient:
return self.connected
def get_peerhost(self):
- ''' get the ip address of the account, from which is made connection
+ ''' get the ip address of the account, from which is made connection
to the server , (e.g. me).
We will create listening socket on the same ip '''
if hasattr(self, 'Connection'):
@@ -174,7 +174,7 @@ class CommonClient:
if proxy: socket=transports.HTTPPROXYsocket(proxy,server,use_srv)
else: socket=transports.TCPsocket(server,use_srv)
connected=socket.PlugIn(self)
- if not connected:
+ if not connected:
socket.PlugOut()
return
self._Server,self._Proxy=server,proxy
@@ -196,7 +196,7 @@ class Client(CommonClient):
""" Example client class, based on CommonClient. """
def connect(self,server=None,proxy=None,secure=None,use_srv=True):
""" Connect to jabber server. If you want to specify different ip/port to connect to you can
- pass it as tuple as first parameter. If there is HTTP proxy between you and server
+ pass it as tuple as first parameter. If there is HTTP proxy between you and server
specify it's address and credentials (if needed) in the second argument.
If you want ssl/tls support to be discovered and enable automatically - leave third argument as None. (ssl will be autodetected only if port is 5223 or 443)
If you want to force SSL start (i.e. if port 5223 or 443 is remapped to some non-standard port) then set it to 1.
@@ -265,7 +265,7 @@ class Component(CommonClient):
Jabberd1.4 and Ejabberd use the default namespace then for all client messages.
Jabberd2 uses jabber:client.
'server' argument is a server name that you are connecting to (f.e. "localhost").
- 'port' can be specified if 'server' resolves to correct IP. If it is not then you'll need to specify IP
+ 'port' can be specified if 'server' resolves to correct IP. If it is not then you'll need to specify IP
and port while calling "connect()"."""
CommonClient.__init__(self,server,port=port,debug=debug)
self.typ=typ
@@ -274,7 +274,7 @@ class Component(CommonClient):
self.domains=domains
else:
self.domains=[server]
-
+
def connect(self,server=None,proxy=None):
""" This will connect to the server, and if the features tag is found then set
the namespace to be jabber:client as that is required for jabberd2.
diff --git a/src/common/xmpp/client_nb.py b/src/common/xmpp/client_nb.py
index a47f9eea2..d9a4a8bef 100644
--- a/src/common/xmpp/client_nb.py
+++ b/src/common/xmpp/client_nb.py
@@ -28,28 +28,28 @@ from client import *
class NBCommonClient(CommonClient):
''' Base for Client and Component classes.'''
- def __init__(self, server, port=5222, debug=['always', 'nodebuilder'], caller=None,
+ def __init__(self, server, port=5222, debug=['always', 'nodebuilder'], caller=None,
on_connect=None, on_proxy_failure=None, on_connect_failure=None):
''' Caches server name and (optionally) port to connect to. "debug" parameter specifies
the debug IDs that will go into debug output. You can either specifiy an "include"
or "exclude" list. The latter is done via adding "always" pseudo-ID to the list.
- Full list: ['nodebuilder', 'dispatcher', 'gen_auth', 'SASL_auth', 'bind', 'socket',
+ Full list: ['nodebuilder', 'dispatcher', 'gen_auth', 'SASL_auth', 'bind', 'socket',
'CONNECTproxy', 'TLS', 'roster', 'browser', 'ibb'] . '''
-
- if isinstance(self, NonBlockingClient):
+
+ if isinstance(self, NonBlockingClient):
self.Namespace, self.DBG = 'jabber:client', DBG_CLIENT
- elif isinstance(self, NBCommonClient):
+ elif isinstance(self, NBCommonClient):
self.Namespace, self.DBG = dispatcher_nb.NS_COMPONENT_ACCEPT, DBG_COMPONENT
-
+
self.defaultNamespace = self.Namespace
self.disconnect_handlers = []
self.Server = server
self.Port = port
-
+
# Who initiated this client
# Used to register the EventDispatcher
self._caller = caller
- if debug and not isinstance(debug, list):
+ if debug and not isinstance(debug, list):
debug = ['always', 'nodebuilder']
self._DEBUG = Debug.Debug(debug)
self.DEBUG = self._DEBUG.Show
@@ -64,10 +64,10 @@ class NBCommonClient(CommonClient):
self.on_connect = on_connect
self.on_proxy_failure = on_proxy_failure
self.on_connect_failure = on_connect_failure
-
+
def set_idlequeue(self, idlequeue):
self.idlequeue = idlequeue
-
+
def disconnected(self):
''' Called on disconnection. Calls disconnect handlers and cleans things up. '''
self.connected=''
@@ -90,15 +90,15 @@ class NBCommonClient(CommonClient):
self.NBSOCKS5PROXYsocket.PlugOut()
if 'NonBlockingTcp' in self.__dict__:
self.NonBlockingTcp.PlugOut()
-
+
def reconnectAndReauth(self):
''' Just disconnect. We do reconnecting in connection.py '''
self.disconnect()
- return ''
+ return ''
def connect(self,server=None,proxy=None, ssl=None, on_stream_start = None):
''' Make a tcp/ip connection, protect it with tls/ssl if possible and start XMPP stream. '''
- if not server:
+ if not server:
server = (self.Server, self.Port)
self._Server, self._Proxy, self._Ssl = server , proxy, ssl
self.on_stream_start = on_stream_start
@@ -117,22 +117,22 @@ class NBCommonClient(CommonClient):
self.socket = transports_nb.NBHTTPPROXYsocket(self._on_connected,
self._on_proxy_failure, self._on_connected_failure, proxy,
server)
- else:
+ else:
self.connected = 'tcp'
- self.socket = transports_nb.NonBlockingTcp(self._on_connected,
+ self.socket = transports_nb.NonBlockingTcp(self._on_connected,
self._on_connected_failure, server)
self.socket.PlugIn(self)
return True
-
+
def get_attrs(self, on_stream_start):
self.on_stream_start = on_stream_start
self.onreceive(self._on_receive_document_attrs)
- def _on_proxy_failure(self, reason):
+ def _on_proxy_failure(self, reason):
if self.on_proxy_failure:
self.on_proxy_failure(reason)
- def _on_connected_failure(self, retry = None):
+ def _on_connected_failure(self, retry = None):
if self.socket:
self.socket.disconnect()
if self.on_connect_failure:
@@ -143,7 +143,7 @@ class NBCommonClient(CommonClient):
# in nonblocking mode, and this handler is actually called
# as soon as connection is initiated, NOT when connection
# succeeds, as the name suggests.
- # # connect succeeded, so no need of this callback anymore
+ # # connect succeeded, so no need of this callback anymore
# self.on_connect_failure = None
self.connected = 'tcp'
if self._Ssl:
@@ -153,7 +153,7 @@ class NBCommonClient(CommonClient):
self.connected = 'ssl'
self.onreceive(self._on_receive_document_attrs)
dispatcher_nb.Dispatcher().PlugIn(self)
-
+
def _on_receive_document_attrs(self, data):
if data:
self.Dispatcher.ProcessNonBlocking(data)
@@ -169,11 +169,11 @@ class NBCommonClient(CommonClient):
self.on_stream_start()
self.on_stream_start = None
return True
-
+
def _on_receive_stream_features(self, data):
if data:
self.Dispatcher.ProcessNonBlocking(data)
- if not self.Dispatcher.Stream.features:
+ if not self.Dispatcher.Stream.features:
return
# pass # If we get version 1.0 stream the features tag MUST BE presented
self.onreceive(None)
@@ -181,12 +181,12 @@ class NBCommonClient(CommonClient):
self.on_stream_start()
self.on_stream_start = None
return True
-
+
class NonBlockingClient(NBCommonClient):
''' Example client class, based on CommonClient. '''
def connect(self,server=None,proxy=None,secure=None,use_srv=True):
''' Connect to jabber server. If you want to specify different ip/port to connect to you can
- pass it as tuple as first parameter. If there is HTTP proxy between you and server
+ pass it as tuple as first parameter. If there is HTTP proxy between you and server
specify it's address and credentials (if needed) in the second argument.
If you want ssl/tls support to be discovered and enable automatically - leave third argument as None. (ssl will be autodetected only if port is 5223 or 443)
If you want to force SSL start (i.e. if port 5223 or 443 is remapped to some non-standard port) then set it to 1.
@@ -195,18 +195,18 @@ class NonBlockingClient(NBCommonClient):
Returns '' or 'tcp' or 'tls', depending on the result.'''
self.__secure = secure
self.Connection = None
- NBCommonClient.connect(self, server = server, proxy = proxy, ssl = secure,
- on_stream_start = self._on_tcp_stream_start)
+ NBCommonClient.connect(self, server = server, proxy = proxy, ssl = secure,
+ on_stream_start = self._on_tcp_stream_start)
return self.connected
-
-
+
+
def _is_connected(self):
self.onreceive(None)
if self.on_connect:
self.on_connect(self, self.connected)
self.on_connect_failure = None
self.on_connect = None
-
+
def _on_tcp_stream_start(self):
if not self.connected or self.__secure is not None and not self.__secure:
self._is_connected()
@@ -217,12 +217,12 @@ class NonBlockingClient(NBCommonClient):
if not self.Connection: # ssl error, stream is closed
return True
if 'version' not in self.Dispatcher.Stream._document_attrs or \
- not self.Dispatcher.Stream._document_attrs['version']=='1.0':
+ not self.Dispatcher.Stream._document_attrs['version']=='1.0':
self._is_connected()
return
- if not self.Dispatcher.Stream.features.getTag('starttls'):
+ if not self.Dispatcher.Stream.features.getTag('starttls'):
self._is_connected()
- return
+ return
self.onreceive(self._on_receive_starttls)
def _on_receive_starttls(self, data):
@@ -231,7 +231,7 @@ class NonBlockingClient(NBCommonClient):
if not self.NonBlockingTLS.starttls:
return
self.onreceive(None)
- if not hasattr(self, 'NonBlockingTLS') or self.NonBlockingTLS.starttls != 'success':
+ if not hasattr(self, 'NonBlockingTLS') or self.NonBlockingTLS.starttls != 'success':
self.event('tls_failed')
self._is_connected()
return
@@ -239,7 +239,7 @@ class NonBlockingClient(NBCommonClient):
self.onreceive(None)
self._is_connected()
return True
-
+
def auth(self, user, password, resource = '', sasl = 1, on_auth = None):
''' Authenticate connnection and bind resource. If resource is not provided
random one or library name used. '''
@@ -247,7 +247,7 @@ class NonBlockingClient(NBCommonClient):
self.on_auth = on_auth
self.get_attrs(self._on_doc_attrs)
return
-
+
def _on_old_auth(self, res):
if res:
self.connected += '+old_auth'
@@ -256,27 +256,27 @@ class NonBlockingClient(NBCommonClient):
self.on_auth(self, None)
def _on_doc_attrs(self):
- if self._sasl:
+ if self._sasl:
auth_nb.SASL(self._User, self._Password, self._on_start_sasl).PlugIn(self)
if not self._sasl or self.SASL.startsasl == 'not-supported':
- if not self._Resource:
+ if not self._Resource:
self._Resource = 'xmpppy'
auth_nb.NonBlockingNonSASL(self._User, self._Password, self._Resource, self._on_old_auth).PlugIn(self)
return
self.onreceive(self._on_start_sasl)
self.SASL.auth()
return True
-
+
def _on_start_sasl(self, data=None):
if data:
self.Dispatcher.ProcessNonBlocking(data)
- if 'SASL' not in self.__dict__:
- # SASL is pluged out, possible disconnect
+ if 'SASL' not in self.__dict__:
+ # SASL is pluged out, possible disconnect
return
- if self.SASL.startsasl == 'in-process':
+ if self.SASL.startsasl == 'in-process':
return
self.onreceive(None)
- if self.SASL.startsasl == 'failure':
+ if self.SASL.startsasl == 'failure':
# wrong user/pass, stop auth
self.connected = None
self._on_sasl_auth(None)
@@ -285,16 +285,16 @@ class NonBlockingClient(NBCommonClient):
auth_nb.NonBlockingBind().PlugIn(self)
self.onreceive(self._on_auth_bind)
return True
-
+
def _on_auth_bind(self, data):
if data:
self.Dispatcher.ProcessNonBlocking(data)
if not hasattr(self, 'NonBlockingBind') or self.NonBlockingBind.bound is \
- None:
+ None:
return
self.NonBlockingBind.NonBlockingBind(self._Resource, self._on_sasl_auth)
return True
-
+
def _on_sasl_auth(self, res):
self.onreceive(None)
if res:
@@ -302,10 +302,10 @@ class NonBlockingClient(NBCommonClient):
self.on_auth(self, 'sasl')
else:
self.on_auth(self, None)
-
+
def initRoster(self):
''' Plug in the roster. '''
- if 'NonBlockingRoster' not in self.__dict__:
+ if 'NonBlockingRoster' not in self.__dict__:
roster_nb.NonBlockingRoster().PlugIn(self)
def getRoster(self, on_ready = None):
@@ -330,7 +330,7 @@ class Component(NBCommonClient):
Jabberd1.4 and Ejabberd use the default namespace then for all client messages.
Jabberd2 uses jabber:client.
'server' argument is a server name that you are connecting to (f.e. "localhost").
- 'port' can be specified if 'server' resolves to correct IP. If it is not then you'll need to specify IP
+ 'port' can be specified if 'server' resolves to correct IP. If it is not then you'll need to specify IP
and port while calling "connect()".'''
NBCommonClient.__init__(self, server, port=port, debug=debug)
self.typ = typ
@@ -341,7 +341,7 @@ class Component(NBCommonClient):
self.domains=[server]
self.on_connect_component = on_connect
self.on_connect_failure = on_connect_failure
-
+
def connect(self, server=None, proxy=None):
''' This will connect to the server, and if the features tag is found then set
the namespace to be jabber:client as that is required for jabberd2.
@@ -349,9 +349,9 @@ class Component(NBCommonClient):
if self.component:
self.Namespace=auth.NS_COMPONENT_1
self.Server=server[0]
- NBCommonClient.connect(self, server=server, proxy=proxy,
+ NBCommonClient.connect(self, server=server, proxy=proxy,
on_connect = self._on_connect, on_connect_failure = self.on_connect_failure)
-
+
def _on_connect(self):
if self.typ=='jabberd2' or not self.typ and self.Dispatcher.Stream.features is not None:
self.defaultNamespace=auth.NS_CLIENT
@@ -365,9 +365,9 @@ class Component(NBCommonClient):
''' Authenticate component "name" with password "password".'''
self._User, self._Password, self._Resource=name, password,''
try:
- if self.component:
+ if self.component:
sasl=1
- if sasl:
+ if sasl:
auth.SASL(name,password).PlugIn(self)
if not sasl or self.SASL.startsasl=='not-supported':
if auth.NonSASL(name,password,'').PlugIn(self):
@@ -378,11 +378,11 @@ class Component(NBCommonClient):
self.onreceive(self._on_auth_component)
except Exception:
self.DEBUG(self.DBG,"Failed to authenticate %s" % name,'error')
-
+
def _on_auth_component(self, data):
if data:
self.Dispatcher.ProcessNonBlocking(data)
- if self.SASL.startsasl == 'in-process':
+ if self.SASL.startsasl == 'in-process':
return
if self.SASL.startsasl =='success':
if self.component:
@@ -392,18 +392,18 @@ class Component(NBCommonClient):
self.connected += '+sasl'
else:
raise auth.NotAuthorized(self.SASL.startsasl)
-
+
def _on_component_bind(self, data):
if data:
self.Dispatcher.ProcessNonBlocking(data)
- if self.NBComponentBind.bound is None:
+ if self.NBComponentBind.bound is None:
return
-
+
for domain in self.domains:
self.NBComponentBind.Bind(domain, _on_component_bound)
-
+
def _on_component_bound(self, resp):
self.NBComponentBind.PlugOut()
-
+
# vim: se ts=3:
diff --git a/src/common/xmpp/commands.py b/src/common/xmpp/commands.py
index 1eb105978..6feee02f0 100644
--- a/src/common/xmpp/commands.py
+++ b/src/common/xmpp/commands.py
@@ -19,13 +19,13 @@
There are 3 classes here, a command processor Commands like the Browser, and a command template plugin Command, and an example command.
To use this module:
-
+
Instansiate the module with the parent transport and disco browser manager as parameters.
'Plug in' commands using the command template.
The command feature must be added to existing disco replies where neccessary.
-
+
What it supplies:
-
+
Automatic command registration with the disco browser manager.
Automatic listing of commands in the public command list.
A means of handling requests, by redirection though the command manager.
@@ -39,9 +39,9 @@ DBG_COMMANDS = 'commands'
class Commands(PlugIn):
"""Commands is an ancestor of PlugIn and can be attached to any session.
-
- The commands class provides a lookup and browse mechnism. It follows the same priciple of the Browser class, for Service Discovery to provide the list of commands, it adds the 'list' disco type to your existing disco handler function.
-
+
+ The commands class provides a lookup and browse mechnism. It follows the same priciple of the Browser class, for Service Discovery to provide the list of commands, it adds the 'list' disco type to your existing disco handler function.
+
How it works:
The commands are added into the existing Browser on the correct nodes. When the command list is built the supplied discovery handler function needs to have a 'list' option in type. This then gets enumerated, all results returned as None are ignored.
The command executed is then called using it's Execute method. All session management is handled by the command itself.
@@ -53,7 +53,7 @@ class Commands(PlugIn):
self._exported_methods=[]
self._handlers={'':{}}
self._browser = browser
-
+
def plugin(self, owner):
"""Makes handlers within the session"""
# Plug into the session and the disco manager
@@ -61,15 +61,15 @@ class Commands(PlugIn):
owner.RegisterHandler('iq',self._CommandHandler,typ='set',ns=NS_COMMANDS)
owner.RegisterHandler('iq',self._CommandHandler,typ='get',ns=NS_COMMANDS)
self._browser.setDiscoHandler(self._DiscoHandler,node=NS_COMMANDS,jid='')
- owner.debug_flags.append(DBG_COMMANDS)
-
+ owner.debug_flags.append(DBG_COMMANDS)
+
def plugout(self):
"""Removes handlers from the session"""
# unPlug from the session and the disco manager
self._owner.UnregisterHandler('iq',self._CommandHandler,ns=NS_COMMANDS)
for jid in self._handlers:
self._browser.delDiscoHandler(self._DiscoHandler,node=NS_COMMANDS,jid=jid)
-
+
def _CommandHandler(self,conn,request):
"""The internal method to process the routing of command execution requests"""
# This is the command handler itself.
@@ -93,7 +93,7 @@ class Commands(PlugIn):
else:
conn.send(Error(request,ERR_ITEM_NOT_FOUND))
raise NodeProcessed
-
+
def _DiscoHandler(self,conn,request,typ):
"""The internal method to process service discovery requests"""
# This is the disco manager handler.
@@ -130,7 +130,7 @@ class Commands(PlugIn):
raise NodeProcessed
elif typ == 'info':
return {'ids':[{'category':'automation','type':'command-list'}],'features':[]}
-
+
def addCommand(self,name,cmddisco,cmdexecute,jid=''):
"""The method to call if adding a new command to the session, the requred parameters of cmddisco and cmdexecute are the methods to enable that command to be executed"""
# This command takes a command object and the name of the command for registration
@@ -146,7 +146,7 @@ class Commands(PlugIn):
self._handlers[jid][name]={'disco':cmddisco,'execute':cmdexecute}
# Need to add disco stuff here
self._browser.setDiscoHandler(cmddisco,node=name,jid=jid)
-
+
def delCommand(self,name,jid=''):
"""Removed command from the session"""
# This command takes a command object and the name used for registration
@@ -162,7 +162,7 @@ class Commands(PlugIn):
command = self.getCommand(name,jid)['disco']
del self._handlers[jid][name]
self._browser.delDiscoHandler(command,node=name,jid=jid)
-
+
def getCommand(self,name,jid=''):
"""Returns the command tuple"""
# This gets the command object with name
@@ -174,19 +174,19 @@ class Commands(PlugIn):
raise NameError,'Command not found'
else:
return self._handlers[jid][name]
-
+
class Command_Handler_Prototype(PlugIn):
- """This is a prototype command handler, as each command uses a disco method
- and execute method you can implement it any way you like, however this is
- my first attempt at making a generic handler that you can hang process
+ """This is a prototype command handler, as each command uses a disco method
+ and execute method you can implement it any way you like, however this is
+ my first attempt at making a generic handler that you can hang process
stages on too. There is an example command below.
-
+
The parameters are as follows:
name : the name of the command within the jabber environment
description : the natural language description
discofeatures : the features supported by the command
initial : the initial command in the from of {'execute':commandname}
-
+
All stages set the 'actions' dictionary for each session to represent the possible options available.
"""
name = 'examplecommand'
@@ -203,14 +203,14 @@ class Command_Handler_Prototype(PlugIn):
# Disco information for command list pre-formatted as a tuple
self.discoinfo = {'ids':[{'category':'automation','type':'command-node','name':self.description}],'features': self.discofeatures}
self._jid = jid
-
+
def plugin(self,owner):
"""Plug command into the commands class"""
# The owner in this instance is the Command Processor
self._commands = owner
self._owner = owner._owner
self._commands.addCommand(self.name,self._DiscoHandler,self.Execute,jid=self._jid)
-
+
def plugout(self):
"""Remove command from the commands class"""
self._commands.delCommand(name,self._jid)
@@ -219,7 +219,7 @@ class Command_Handler_Prototype(PlugIn):
"""Returns an id for the command session"""
self.count = self.count+1
return 'cmd-%s-%d'%(self.name,self.count)
-
+
def Execute(self,conn,request):
"""The method that handles all the commands, and routes them to the correct method for that stage."""
# New request or old?
@@ -254,7 +254,7 @@ class Command_Handler_Prototype(PlugIn):
else:
# New session
self.initial[action](conn,request)
-
+
def _DiscoHandler(self,conn,request,type_):
"""The handler for discovery events"""
if type_ == 'list':
@@ -263,9 +263,9 @@ class Command_Handler_Prototype(PlugIn):
return []
elif type_ == 'info':
return self.discoinfo
-
+
class TestCommand(Command_Handler_Prototype):
- """ Example class. You should read source if you wish to understate how it works.
+ """ Example class. You should read source if you wish to understate how it works.
Generally, it presents a "master" that giudes user through to calculate something.
"""
name = 'testcommand'
@@ -275,7 +275,7 @@ class TestCommand(Command_Handler_Prototype):
Command_Handler_Prototype.__init__(self,jid)
self.pi = 3.14
self.initial = {'execute':self.cmdFirstStage}
-
+
def cmdFirstStage(self,conn,request):
""" Determine """
# This is the only place this should be repeated as all other stages should have SessionIDs
@@ -300,7 +300,7 @@ class TestCommand(Command_Handler_Prototype):
sessions[request.getTagAttr('command','sessionid')]['actions']={'cancel':self.cmdCancel,None:self.cmdThirdStage,'previous':cmdFirstStage}
# The form generation is split out to another method as it may be called by cmdThirdStage
self.cmdSecondStageReply(conn,request)
-
+
def cmdSecondStageReply(self,conn,request):
reply = request.buildReply('result')
form = DataForm(title = 'Enter the radius', data=['Enter the radius of the circle (numbers only)',DataField(label='Radius',name='radius',typ='text-single')])
@@ -308,7 +308,7 @@ class TestCommand(Command_Handler_Prototype):
reply.addChild(name='command',attrs={'xmlns':NS_COMMAND,'node':request.getTagAttr('command','node'),'sessionid':request.getTagAttr('command','sessionid'),'status':'executing'},payload=replypayload)
self._owner.send(reply)
raise NodeProcessed
-
+
def cmdThirdStage(self,conn,request):
form = DataForm(node = result.getTag(name='command').getTag(name='x',namespace=NS_DATA))
try:
@@ -324,13 +324,13 @@ class TestCommand(Command_Handler_Prototype):
reply.addChild(name='command',attrs={'xmlns':NS_COMMAND,'node':request.getTagAttr('command','node'),'sessionid':request.getTagAttr('command','sessionid'),'status':'completed'},payload=form)
self._owner.send(reply)
raise NodeProcessed
-
+
def cmdCancel(self,conn,request):
reply = request.buildReply('result')
reply.addChild(name='command',attrs={'xmlns':NS_COMMAND,'node':request.getTagAttr('command','node'),'sessionid':request.getTagAttr('command','sessionid'),'status':'cancelled'})
self._owner.send(reply)
del self.sessions[request.getTagAttr('command','sessionid')]
-
-
+
+
# vim: se ts=3:
diff --git a/src/common/xmpp/debug.py b/src/common/xmpp/debug.py
index 769f09f19..4107ec895 100644
--- a/src/common/xmpp/debug.py
+++ b/src/common/xmpp/debug.py
@@ -1,4 +1,4 @@
-## debug.py
+## debug.py
##
## Copyright (C) 2003 Jacob Lundqvist
##
@@ -19,7 +19,7 @@ Other modules can always define extra debug flags for local usage, as long as
they make sure they append them to debug_flags
Also its always a good thing to prefix local flags with something, to reduce risk
-of coliding flags. Nothing breaks if two flags would be identical, but it might
+of coliding flags. Nothing breaks if two flags would be identical, but it might
activate unintended debugging.
flags can be numeric, but that makes analysing harder, on creation its
@@ -104,12 +104,12 @@ class NoDebug:
pass
def active_set( self, active_flags = None ):
return 0
-
+
LINE_FEED = '\n'
-class Debug:
+class Debug:
def __init__( self,
#
# active_flags are those that will trigger output
@@ -128,7 +128,7 @@ class Debug:
prefix = 'DEBUG: ',
sufix = '\n',
#
- # If you want unix style timestamps,
+ # If you want unix style timestamps,
# 0 disables timestamps
# 1 before prefix, good when prefix is a string
# 2 after prefix, good when prefix is a color
@@ -138,8 +138,8 @@ class Debug:
# flag_show should normaly be of, but can be turned on to get a
# good view of what flags are actually used for calls,
# if it is not None, it should be a string
- # flags for current call will be displayed
- # with flag_show as separator
+ # flags for current call will be displayed
+ # with flag_show as separator
# recomended values vould be '-' or ':', but any string goes
#
flag_show = None,
@@ -153,14 +153,14 @@ class Debug:
# default is to show welcome if any flags are active
welcome = -1
):
-
+
self.debug_flags = []
if welcome == -1:
if active_flags and len(active_flags):
welcome = 1
else:
welcome = 0
-
+
self._remove_dupe_flags()
if log_file:
if isinstance(log_file, str):
@@ -173,7 +173,7 @@ class Debug:
self._fh = log_file
else:
self._fh = sys.stdout
-
+
if time_stamp not in (0,1,2):
raise Exception('Invalid time_stamp param "%s"' % str(time_stamp))
self.prefix = prefix
@@ -206,18 +206,18 @@ class Debug:
flag can be of folowing types:
None - this msg will always be shown if any debugging is on
flag - will be shown if flag is active
- (flag1,flag2,,,) - will be shown if any of the given flags
+ (flag1,flag2,,,) - will be shown if any of the given flags
are active
if prefix / sufix are not given, default ones from init will be used
-
+
lf = -1 means strip linefeed if pressent
lf = 1 means add linefeed if not pressent
"""
-
+
if self.validate_flags:
self._validate_flag( flag )
-
+
if not self.is_active(flag):
return
if prefix:
@@ -241,7 +241,7 @@ class Debug:
)
else:
output = pre
-
+
if self.flag_show:
if flag:
output = '%s%s%s' % ( output, flag, self.flag_show )
@@ -271,7 +271,7 @@ class Debug:
s=s+c
self._fh.write( '%s%s%s' % ( pre, s, suf ))
self._fh.flush()
-
+
def active_set( self, active_flags = None ):
"returns 1 if any flags where actually set, otherwise 0."
r = 0
@@ -285,7 +285,7 @@ class Debug:
if t not in self.debug_flags:
print 'Invalid debugflag given', t
ok_flags.append( t )
-
+
self.active = ok_flags
r = 1
else:
@@ -298,7 +298,7 @@ class Debug:
self.show( '*** please correct your param!' )
self.show( '*** due to this, full debuging is enabled' )
self.active = self.debug_flags
-
+
for f in flags:
s = f.strip()
ok_flags.append( s )
@@ -306,15 +306,15 @@ class Debug:
self._remove_dupe_flags()
return r
-
+
def active_get( self ):
"returns currently active flags."
return self.active
-
-
+
+
def _as_one_list( self, items ):
""" init param might contain nested lists, typically from group flags.
-
+
This code organises lst and remves dupes
"""
if not isinstance(items, (list, tuple)):
@@ -323,15 +323,15 @@ class Debug:
for l in items:
if isinstance(l, list):
lst2 = self._as_one_list( l )
- for l2 in lst2:
+ for l2 in lst2:
self._append_unique_str(r, l2 )
elif l is None:
continue
else:
self._append_unique_str(r, l )
return r
-
-
+
+
def _append_unique_str( self, lst, item ):
"""filter out any dupes."""
if not isinstance(item, str):
@@ -342,7 +342,7 @@ class Debug:
lst.append( item )
return lst
-
+
def _validate_flag( self, flags ):
'verify that flag is defined.'
if flags:
@@ -353,7 +353,7 @@ class Debug:
def _remove_dupe_flags( self ):
"""
- if multiple instances of Debug is used in same app,
+ if multiple instances of Debug is used in same app,
some flags might be created multiple time, filter out dupes
"""
unique_flags = []
@@ -371,12 +371,12 @@ class Debug:
if not colors_enabled: prefixcolor=''
elif flag in self.colors: prefixcolor=self.colors[flag]
else: prefixcolor=color_none
-
+
if prefix=='error':
_exception = sys.exc_info()
if _exception[0]:
msg=msg+'\n'+''.join(traceback.format_exception(_exception[0], _exception[1], _exception[2])).rstrip()
-
+
prefix= self.prefix+prefixcolor+(flag+' '*12)[:12]+' '+(prefix+' '*6)[:6]
self.show(msg, flag, prefix)
diff --git a/src/common/xmpp/dispatcher.py b/src/common/xmpp/dispatcher.py
index 364207a2b..1fd7a6495 100644
--- a/src/common/xmpp/dispatcher.py
+++ b/src/common/xmpp/dispatcher.py
@@ -17,7 +17,7 @@
"""
Main xmpppy mechanism. Provides library with methods to assign different handlers
to different XMPP stanzas.
-Contains one tunable attribute: DefaultTimeout (25 seconds by default). It defines time that
+Contains one tunable attribute: DefaultTimeout (25 seconds by default). It defines time that
Dispatcher.SendAndWaitForResponce method will wait for reply stanza before giving up.
"""
@@ -135,7 +135,7 @@ class Dispatcher(PlugIn):
raise _pendingException[0], _pendingException[1], _pendingException[2]
return len(data)
return '0' # It means that nothing is received but link is alive.
-
+
def RegisterNamespace(self,xmlns,order='info'):
""" Creates internal structures for newly registered namespace.
You can register handlers for this namespace afterwards. By default one namespace
@@ -235,7 +235,7 @@ class Dispatcher(PlugIn):
def Event(self,realm,event,data):
""" Raise some event. Takes three arguments:
- 1) "realm" - scope of event. Usually a namespace.
+ 1) "realm" - scope of event. Usually a namespace.
2) "event" - the event itself. F.e. "SUCESSFULL SEND".
3) data that comes along with event. Depends on event."""
if self._eventHandler: self._eventHandler(realm,event,data)
diff --git a/src/common/xmpp/dispatcher_nb.py b/src/common/xmpp/dispatcher_nb.py
index c5f0fe90a..7e9e5df48 100644
--- a/src/common/xmpp/dispatcher_nb.py
+++ b/src/common/xmpp/dispatcher_nb.py
@@ -19,7 +19,7 @@
'''
Main xmpppy mechanism. Provides library with methods to assign different handlers
to different XMPP stanzas.
-Contains one tunable attribute: DefaultTimeout (25 seconds by default). It defines time that
+Contains one tunable attribute: DefaultTimeout (25 seconds by default). It defines time that
Dispatcher.SendAndWaitForResponce method will wait for reply stanza before giving up.
'''
@@ -59,7 +59,7 @@ class Dispatcher(PlugIn):
''' Return set of user-registered callbacks in it's internal format.
Used within the library to carry user handlers set over Dispatcher replugins. '''
return self.handlers
-
+
def restoreHandlers(self, handlers):
''' Restores user-registered callbacks structure from dump previously obtained via dumpHandlers.
Used within the library to carry user handlers set over Dispatcher replugins. '''
@@ -76,7 +76,7 @@ class Dispatcher(PlugIn):
self.RegisterDefaultHandler(self.returnStanzaHandler)
self.RegisterEventHandler(self._owner._caller._event_dispatcher)
self.on_responses = {}
-
+
def plugin(self, owner):
''' Plug the Dispatcher instance into Client class instance and send initial stream header. Used internally.'''
self._init()
@@ -87,7 +87,7 @@ class Dispatcher(PlugIn):
self._owner.StreamInit()
else:
self.StreamInit()
-
+
def plugout(self):
''' Prepares instance to be destructed. '''
self.Stream.dispatch = None
@@ -126,7 +126,7 @@ class Dispatcher(PlugIn):
1) length of processed data if some data were processed;
2) '0' string if no data were processed but link is alive;
3) 0 (zero) if underlying connection is closed.'''
- for handler in self._cycleHandlers:
+ for handler in self._cycleHandlers:
handler(self)
if len(self._pendingExceptions) > 0:
_pendingException = self._pendingExceptions.pop()
@@ -150,7 +150,7 @@ class Dispatcher(PlugIn):
raise _pendingException[0], _pendingException[1], _pendingException[2]
if len(data) == 0: return '0'
return len(data)
-
+
def RegisterNamespace(self, xmlns, order='info'):
''' Creates internal structures for newly registered namespace.
You can register handlers for this namespace afterwards. By default one namespace
@@ -191,46 +191,46 @@ class Dispatcher(PlugIn):
will be called first nevertheless.
"system" - call handler even if NodeProcessed Exception were raised already.
'''
- if not xmlns:
+ if not xmlns:
xmlns=self._owner.defaultNamespace
- self.DEBUG('Registering handler %s for "%s" type->%s ns->%s(%s)' %
+ self.DEBUG('Registering handler %s for "%s" type->%s ns->%s(%s)' %
(handler, name, typ, ns, xmlns), 'info')
- if not typ and not ns:
+ if not typ and not ns:
typ='default'
- if xmlns not in self.handlers:
+ if xmlns not in self.handlers:
self.RegisterNamespace(xmlns,'warn')
- if name not in self.handlers[xmlns]:
+ if name not in self.handlers[xmlns]:
self.RegisterProtocol(name,Protocol,xmlns,'warn')
- if typ+ns not in self.handlers[xmlns][name]:
+ if typ+ns not in self.handlers[xmlns][name]:
self.handlers[xmlns][name][typ+ns]=[]
- if makefirst:
+ if makefirst:
self.handlers[xmlns][name][typ+ns].insert(0,{'func':handler,'system':system})
- else:
+ else:
self.handlers[xmlns][name][typ+ns].append({'func':handler,'system':system})
def RegisterHandlerOnce(self,name,handler,typ='',ns='',xmlns=None,makefirst=0, system=0):
''' Unregister handler after first call (not implemented yet). '''
- if not xmlns:
+ if not xmlns:
xmlns=self._owner.defaultNamespace
self.RegisterHandler(name, handler, typ, ns, xmlns, makefirst, system)
def UnregisterHandler(self, name, handler, typ='', ns='', xmlns=None):
''' Unregister handler. "typ" and "ns" must be specified exactly the same as with registering.'''
- if not xmlns:
+ if not xmlns:
xmlns=self._owner.defaultNamespace
- if not typ and not ns:
+ if not typ and not ns:
typ='default'
if xmlns not in self.handlers:
return
- if name not in self.handlers[xmlns]:
+ if name not in self.handlers[xmlns]:
return
- if typ+ns not in self.handlers[xmlns][name]:
+ if typ+ns not in self.handlers[xmlns][name]:
return
for pack in self.handlers[xmlns][name][typ+ns]:
- if pack['func'] == handler:
- try:
+ if pack['func'] == handler:
+ try:
self.handlers[xmlns][name][typ+ns].remove(pack)
- except ValueError:
+ except ValueError:
pass
def RegisterDefaultHandler(self,handler):
@@ -251,29 +251,29 @@ class Dispatcher(PlugIn):
name,text='error',error.getData()
for tag in error.getChildren():
if tag.getNamespace()==NS_XMPP_STREAMS:
- if tag.getName()=='text':
+ if tag.getName()=='text':
text=tag.getData()
- else:
+ else:
name=tag.getName()
- if name in stream_exceptions.keys():
+ if name in stream_exceptions.keys():
exc=stream_exceptions[name]
- else:
+ else:
exc=StreamError
raise exc((name,text))
def RegisterCycleHandler(self, handler):
''' Register handler that will be called on every Dispatcher.Process() call. '''
- if handler not in self._cycleHandlers:
+ if handler not in self._cycleHandlers:
self._cycleHandlers.append(handler)
def UnregisterCycleHandler(self, handler):
''' Unregister handler that will is called on every Dispatcher.Process() call.'''
- if handler in self._cycleHandlers:
+ if handler in self._cycleHandlers:
self._cycleHandlers.remove(handler)
-
+
def Event(self, realm, event, data):
''' Raise some event. Takes three arguments:
- 1) "realm" - scope of event. Usually a namespace.
+ 1) "realm" - scope of event. Usually a namespace.
2) "event" - the event itself. F.e. "SUCESSFULL SEND".
3) data that comes along with event. Depends on event.'''
if self._eventHandler: self._eventHandler(realm,event,data)
@@ -281,7 +281,7 @@ class Dispatcher(PlugIn):
def dispatch(self, stanza, session=None, direct=0):
''' Main procedure that performs XMPP stanza recognition and calling apppropriate handlers for it.
Called internally. '''
- if not session:
+ if not session:
session = self
session.Stream._mini_dom = None
name = stanza.getName()
@@ -302,10 +302,10 @@ class Dispatcher(PlugIn):
pass
else:
raise UnsupportedStanzaType(name)
-
- if name=='features':
+
+ if name=='features':
session.Stream.features=stanza
-
+
xmlns=stanza.getNamespace()
if xmlns not in self.handlers:
self.DEBUG("Unknown namespace: " + xmlns, 'warn')
@@ -316,38 +316,38 @@ class Dispatcher(PlugIn):
else:
self.DEBUG("Got %s/%s stanza" % (xmlns, name), 'ok')
- if stanza.__class__.__name__=='Node':
+ if stanza.__class__.__name__=='Node':
stanza=self.handlers[xmlns][name][type](node=stanza)
-
+
typ=stanza.getType()
if not typ: typ=''
stanza.props=stanza.getProperties()
ID=stanza.getID()
-
+
session.DEBUG("Dispatching %s stanza with type->%s props->%s id->%s"%(name,typ,stanza.props,ID),'ok')
list_=['default'] # we will use all handlers:
if typ in self.handlers[xmlns][name]: list_.append(typ) # from very common...
for prop in stanza.props:
if prop in self.handlers[xmlns][name]: list_.append(prop)
if typ and typ+prop in self.handlers[xmlns][name]: list_.append(typ+prop) # ...to very particular
-
+
chain=self.handlers[xmlns]['default']['default']
for key in list_:
if key: chain = chain + self.handlers[xmlns][name][key]
-
+
if ID in session._expected:
user=0
if isinstance(session._expected[ID], tuple):
cb,args = session._expected[ID]
session.DEBUG("Expected stanza arrived. Callback %s(%s) found!" % (cb, args), 'ok')
- try:
+ try:
cb(session,stanza,**args)
except Exception, typ:
if typ.__class__.__name__ !='NodeProcessed': raise
else:
session.DEBUG("Expected stanza arrived!",'ok')
session._expected[ID]=stanza
- else:
+ else:
user=1
for handler in chain:
if user or handler['system']:
@@ -358,9 +358,9 @@ class Dispatcher(PlugIn):
self._pendingExceptions.insert(0, sys.exc_info())
return
user=0
- if user and self._defaultHandler:
+ if user and self._defaultHandler:
self._defaultHandler(session, stanza)
-
+
def WaitForData(self, data):
if data is None:
return
@@ -382,10 +382,10 @@ class Dispatcher(PlugIn):
else:
resp(self._owner, self._expected[self._witid], **args)
del self._expected[i]
-
+
def SendAndWaitForResponse(self, stanza, timeout=None, func=None, args=None):
''' Put stanza on the wire and wait for recipient's response to it. '''
- if timeout is None:
+ if timeout is None:
timeout = DEFAULT_TIMEOUT_SECONDS
self._witid = self.send(stanza)
if func:
@@ -395,27 +395,27 @@ class Dispatcher(PlugIn):
self._owner.onreceive(self.WaitForData)
self._expected[self._witid] = None
return self._witid
-
+
def SendAndCallForResponse(self, stanza, func=None, args=None):
''' Put stanza on the wire and call back when recipient replies.
Additional callback arguments can be specified in args. '''
self.SendAndWaitForResponse(stanza, 0, func, args)
-
+
def send(self, stanza, is_message = False, now = False):
''' Serialise stanza and put it on the wire. Assign an unique ID to it before send.
Returns assigned ID.'''
if isinstance(stanza, basestring):
return self._owner.Connection.send(stanza, now = now)
- if not isinstance(stanza, Protocol):
+ if not isinstance(stanza, Protocol):
_ID=None
elif not stanza.getID():
global ID
ID+=1
_ID=repr(ID)
stanza.setID(_ID)
- else:
+ else:
_ID=stanza.getID()
- if self._owner._registered_name and not stanza.getAttr('from'):
+ if self._owner._registered_name and not stanza.getAttr('from'):
stanza.setAttr('from', self._owner._registered_name)
if self._owner._component and stanza.getName() != 'bind':
to=self._owner.Server
@@ -433,7 +433,7 @@ class Dispatcher(PlugIn):
else:
self._owner.Connection.send(stanza, now = now)
return _ID
-
+
def disconnect(self):
''' Send a stream terminator. '''
self._owner.Connection.send('</stream:stream>')
diff --git a/src/common/xmpp/features.py b/src/common/xmpp/features.py
index 4cee5d6f6..4aac70218 100644
--- a/src/common/xmpp/features.py
+++ b/src/common/xmpp/features.py
@@ -1,4 +1,4 @@
-## features.py
+## features.py
##
## Copyright (C) 2003-2004 Alexey "Snake" Nezhdanov
##
@@ -82,7 +82,7 @@ def discoverInfo(disp,jid,node=None):
def getRegInfo(disp,host,info={},sync=True):
""" Gets registration form from remote host.
You can pre-fill the info dictionary.
- F.e. if you are requesting info on registering user joey than specify
+ F.e. if you are requesting info on registering user joey than specify
info as {'username':'joey'}. See JEP-0077 for details.
'disp' must be connected dispatcher instance."""
iq=Iq('get',NS_REGISTER,to=host)
diff --git a/src/common/xmpp/features_nb.py b/src/common/xmpp/features_nb.py
index bf83ac961..5c7b93229 100644
--- a/src/common/xmpp/features_nb.py
+++ b/src/common/xmpp/features_nb.py
@@ -1,4 +1,4 @@
-## features.py
+## features.py
##
## Copyright (C) 2003-2004 Alexey "Snake" Nezhdanov
## Copyright (C) 2007 Julien Pivotto <roidelapluie@gmail.com>
@@ -20,7 +20,7 @@ from protocol import *
def _on_default_response(disp, iq, cb):
def _on_response(resp):
- if isResultNode(resp):
+ if isResultNode(resp):
if cb:
cb(1)
elif cb:
@@ -33,22 +33,22 @@ def _discover(disp, ns, jid, node = None, fb2b=0, fb2a=1, cb=None):
and if it doesnt support browse (or fb2b is not true) fall back to agents protocol
(if gb2a is true). Returns obtained info. Used internally. """
iq=Iq(to=jid, typ='get', queryNS=ns)
- if node:
+ if node:
iq.setQuerynode(node)
def _on_resp1(resp):
- if fb2b and not isResultNode(resp):
+ if fb2b and not isResultNode(resp):
# Fallback to browse
- disp.SendAndCallForResponse(Iq(to=jid,typ='get',queryNS=NS_BROWSE), _on_resp2)
+ disp.SendAndCallForResponse(Iq(to=jid,typ='get',queryNS=NS_BROWSE), _on_resp2)
else:
_on_resp2('')
def _on_resp2(resp):
- if fb2a and not isResultNode(resp):
+ if fb2a and not isResultNode(resp):
# Fallback to agents
- disp.SendAndCallForResponse(Iq(to=jid,typ='get',queryNS=NS_AGENTS), _on_result)
+ disp.SendAndCallForResponse(Iq(to=jid,typ='get',queryNS=NS_AGENTS), _on_result)
else:
_on_result('')
def _on_result(resp):
- if isResultNode(resp):
+ if isResultNode(resp):
if cb:
cb(resp.getQueryPayload())
elif cb:
@@ -65,7 +65,7 @@ def discoverItems(disp,jid,node=None, cb=None):
def _on_response(result_array):
ret=[]
for result in result_array:
- if result.getName()=='agent' and result.getTag('name'):
+ if result.getName()=='agent' and result.getTag('name'):
result.setAttr('name', result.getTagData('name'))
ret.append(result.attrs)
if cb:
@@ -82,39 +82,39 @@ def discoverInfo(disp,jid,node=None, cb=None):
def _on_response(result):
identities , features = [] , []
for i in result:
- if i.getName()=='identity':
+ if i.getName()=='identity':
identities.append(i.attrs)
- elif i.getName()=='feature':
+ elif i.getName()=='feature':
features.append(i.getAttr('var'))
elif i.getName()=='agent':
- if i.getTag('name'):
+ if i.getTag('name'):
i.setAttr('name',i.getTagData('name'))
- if i.getTag('description'):
+ if i.getTag('description'):
i.setAttr('name',i.getTagData('description'))
identities.append(i.attrs)
- if i.getTag('groupchat'):
+ if i.getTag('groupchat'):
features.append(NS_GROUPCHAT)
- if i.getTag('register'):
+ if i.getTag('register'):
features.append(NS_REGISTER)
- if i.getTag('search'):
+ if i.getTag('search'):
features.append(NS_SEARCH)
if cb:
cb(identities , features)
_discover(disp, NS_DISCO_INFO, jid, node, _on_response)
-
+
### Registration ### jabber:iq:register ### JEP-0077 ###########################
def getRegInfo(disp, host, info={}, sync=True):
""" Gets registration form from remote host.
You can pre-fill the info dictionary.
- F.e. if you are requesting info on registering user joey than specify
+ F.e. if you are requesting info on registering user joey than specify
info as {'username':'joey'}. See JEP-0077 for details.
'disp' must be connected dispatcher instance."""
iq=Iq('get',NS_REGISTER,to=host)
- for i in info.keys():
+ for i in info.keys():
iq.setTagData(i,info[i])
if sync:
disp.SendAndCallForResponse(iq, lambda resp: _ReceivedRegInfo(disp.Dispatcher,resp, host))
- else:
+ else:
disp.SendAndCallForResponse(iq, _ReceivedRegInfo, {'agent': host })
def _ReceivedRegInfo(con, resp, agent):
@@ -208,7 +208,7 @@ def getPrivacyList(disp, listname):
""" Requests specific privacy list listname. Returns list of XML nodes (rules)
taken from the server responce."""
def _on_response(resp):
- if not isResultNode(resp):
+ if not isResultNode(resp):
disp.Event(NS_PRIVACY, PRIVACY_LIST_RECEIVED, (False))
return
disp.Event(NS_PRIVACY, PRIVACY_LIST_RECEIVED, (resp))
@@ -218,9 +218,9 @@ def getPrivacyList(disp, listname):
def setActivePrivacyList(disp, listname=None, typ='active', cb=None):
""" Switches privacy list 'listname' to specified type.
By default the type is 'active'. Returns true on success."""
- if listname:
+ if listname:
attrs={'name':listname}
- else:
+ else:
attrs={}
iq = Iq('set',NS_PRIVACY,payload=[Node(typ,attrs)])
_on_default_response(disp, iq, cb)
diff --git a/src/common/xmpp/filetransfer.py b/src/common/xmpp/filetransfer.py
index 6afefe3e3..d0359d3ec 100644
--- a/src/common/xmpp/filetransfer.py
+++ b/src/common/xmpp/filetransfer.py
@@ -1,4 +1,4 @@
-## filetransfer.py
+## filetransfer.py
##
## Copyright (C) 2004 Alexey "Snake" Nezhdanov
##
@@ -28,7 +28,7 @@ class IBB(PlugIn):
""" IBB used to transfer small-sized data chunk over estabilished xmpp connection.
Data is split into small blocks (by default 3000 bytes each), encoded as base 64
and sent to another entity that compiles these blocks back into the data chunk.
- This is very inefficiend but should work under any circumstances. Note that
+ This is very inefficiend but should work under any circumstances. Note that
using IBB normally should be the last resort.
"""
def __init__(self):
diff --git a/src/common/xmpp/idlequeue.py b/src/common/xmpp/idlequeue.py
index e8453c430..b26079097 100644
--- a/src/common/xmpp/idlequeue.py
+++ b/src/common/xmpp/idlequeue.py
@@ -19,42 +19,42 @@ class IdleObject:
'''
def __init__(self):
self.fd = -1
-
+
def pollend(self):
''' called on stream failure '''
pass
-
+
def pollin(self):
''' called on new read event '''
pass
-
+
def pollout(self):
''' called on new write event (connect in sockets is a pollout) '''
pass
-
+
def read_timeout(self, fd):
''' called when timeout has happend '''
pass
-
+
class IdleQueue:
def __init__(self):
self.queue = {}
-
+
# when there is a timeout it executes obj.read_timeout()
# timeout is not removed automatically!
self.read_timeouts = {}
-
+
# cb, which are executed after XX sec., alarms are removed automatically
self.alarms = {}
self.init_idle()
-
+
def init_idle(self):
self.selector = select.poll()
-
+
def remove_timeout(self, fd):
if fd in self.read_timeouts:
del(self.read_timeouts[fd])
-
+
def set_alarm(self, alarm_cb, seconds):
''' set up a new alarm, to be called after alarm_cb sec. '''
alarm_time = self.current_time() + seconds
@@ -63,13 +63,13 @@ class IdleQueue:
self.alarms[alarm_time].append(alarm_cb)
else:
self.alarms[alarm_time] = [alarm_cb]
-
+
def set_read_timeout(self, fd, seconds):
- ''' set a new timeout, if it is not removed after 'seconds',
+ ''' set a new timeout, if it is not removed after 'seconds',
then obj.read_timeout() will be called '''
timeout = self.current_time() + seconds
self.read_timeouts[fd] = timeout
-
+
def check_time_events(self):
current_time = self.current_time()
for fd, timeout in self.read_timeouts.items():
@@ -86,7 +86,7 @@ class IdleQueue:
for cb in self.alarms[alarm_time]:
cb()
del(self.alarms[alarm_time])
-
+
def plug_idle(self, obj, writable = True, readable = True):
if obj.fd == -1:
return
@@ -105,43 +105,43 @@ class IdleQueue:
# when we paused a FT, we expect only a close event
flags = 16
self.add_idle(obj.fd, flags)
-
+
def add_idle(self, fd, flags):
self.selector.register(fd, flags)
-
+
def unplug_idle(self, fd):
if fd in self.queue:
del(self.queue[fd])
self.remove_idle(fd)
-
+
def current_time(self):
from time import time
return time()
-
+
def remove_idle(self, fd):
self.selector.unregister(fd)
-
+
def process_events(self, fd, flags):
obj = self.queue.get(fd)
if obj is None:
self.unplug_idle(fd)
return False
-
+
if flags & 3: # waiting read event
obj.pollin()
return True
-
+
elif flags & 4: # waiting write event
obj.pollout()
return True
-
+
elif flags & 16: # closed channel
# io error, don't expect more events
self.remove_timeout(obj.fd)
self.unplug_idle(obj.fd)
obj.pollend()
return False
-
+
def process(self):
if not self.queue:
# check for timeouts/alert also when there are no active fds
@@ -159,7 +159,7 @@ class IdleQueue:
return True
class SelectIdleQueue(IdleQueue):
- '''
+ '''
Extends IdleQueue to use select.select() for polling
This class exisists for the sake of gtk2.8 on windows, which
doesn't seem to support io_add_watch properly (yet)
@@ -171,7 +171,7 @@ class SelectIdleQueue(IdleQueue):
self.read_fds = {}
self.write_fds = {}
self.error_fds = {}
-
+
def add_idle(self, fd, flags):
''' this method is called when we plug a new idle object.
Remove descriptor to read/write/error lists, according flags
@@ -181,7 +181,7 @@ class SelectIdleQueue(IdleQueue):
if flags & 4:
self.write_fds[fd] = fd
self.error_fds[fd] = fd
-
+
def remove_idle(self, fd):
''' this method is called when we unplug a new idle object.
Remove descriptor from read/write/error lists
@@ -192,13 +192,13 @@ class SelectIdleQueue(IdleQueue):
del(self.write_fds[fd])
if fd in self.error_fds:
del(self.error_fds[fd])
-
+
def process(self):
if not self.write_fds and not self.read_fds:
self.check_time_events()
return True
try:
- waiting_descriptors = select.select(self.read_fds.keys(),
+ waiting_descriptors = select.select(self.read_fds.keys(),
self.write_fds.keys(), self.error_fds.keys(), 0)
except select.error, e:
waiting_descriptors = ((),(),())
diff --git a/src/common/xmpp/protocol.py b/src/common/xmpp/protocol.py
index eb9c3136f..00ad39983 100644
--- a/src/common/xmpp/protocol.py
+++ b/src/common/xmpp/protocol.py
@@ -1,4 +1,4 @@
-## protocol.py
+## protocol.py
##
## Copyright (C) 2003-2005 Alexey "Snake" Nezhdanov
##
@@ -15,7 +15,7 @@
# $Id: protocol.py,v 1.52 2006/01/09 22:08:57 normanr Exp $
"""
-Protocol module contains tools that is needed for processing of
+Protocol module contains tools that is needed for processing of
xmpp-related data structures.
"""
@@ -162,7 +162,7 @@ remote-server-timeout -- 504 -- wait -- A remote server or service specified as
resource-constraint -- 500 -- wait -- The server or recipient lacks the system resources necessary to service the request.
service-unavailable -- 503 -- cancel -- The server or recipient does not currently provide the requested service.
subscription-required -- 407 -- auth -- The requesting entity is not authorized to access the requested service because a subscription is required.
-undefined-condition -- 500 -- --
+undefined-condition -- 500 -- -- Undefined Condition
unexpected-request -- 400 -- wait -- The recipient or server understood the request but was not expecting it at this time (e.g., the request was out of order)."""
sasl_error_conditions="""
aborted -- -- -- The receiving entity acknowledges an <abort/> element sent by the initiating entity; sent in reply to the <abort/> element.
@@ -559,7 +559,7 @@ class Presence(Protocol):
attrs.append(child.getAttr('code'))
return attrs
-class Iq(Protocol):
+class Iq(Protocol):
""" XMPP Iq object - get/set dialog mechanism. """
def __init__(self, typ=None, queryNS=None, attrs={}, to=None, frm=None, payload=[], xmlns=NS_CLIENT, node=None):
""" Create Iq object. You can specify type, query namespace
@@ -638,7 +638,7 @@ class Error(Protocol):
class DataField(Node):
""" This class is used in the DataForm class to describe the single data item.
- If you are working with jabber:x:data (XEP-0004, XEP-0068, XEP-0122)
+ If you are working with jabber:x:data (XEP-0004, XEP-0068, XEP-0122)
then you will need to work with instances of this class. """
def __init__(self,name=None,value=None,typ=None,required=0,desc=None,options=[],node=None):
""" Create new data field of specified name,value and type.
diff --git a/src/common/xmpp/roster.py b/src/common/xmpp/roster.py
index 2161470b6..8f151fc36 100644
--- a/src/common/xmpp/roster.py
+++ b/src/common/xmpp/roster.py
@@ -24,7 +24,7 @@ from client import PlugIn
class Roster(PlugIn):
""" Defines a plenty of methods that will allow you to manage roster.
- Also automatically track presences from remote JIDs taking into
+ Also automatically track presences from remote JIDs taking into
account that every JID can have multiple resources connected. Does not
currently support 'error' presences.
You can also use mapping interface for access to the internal representation of
@@ -48,7 +48,7 @@ class Roster(PlugIn):
if request: self.Request()
def Request(self,force=0):
- """ Request roster from server if it were not yet requested
+ """ Request roster from server if it were not yet requested
(or if the 'force' argument is set). """
if self.set is None: self.set=0
elif not force: return
@@ -187,7 +187,7 @@ class Roster(PlugIn):
""" Authorise JID 'jid'. Works only if these JID requested auth previously. """
self._owner.send(Presence(jid,'subscribed'))
def Unauthorize(self,jid):
- """ Unauthorise JID 'jid'. Use for declining authorisation request
+ """ Unauthorise JID 'jid'. Use for declining authorisation request
or for removing existing authorization. """
self._owner.send(Presence(jid,'unsubscribed'))
def getRaw(self):
diff --git a/src/common/xmpp/roster_nb.py b/src/common/xmpp/roster_nb.py
index ee1d297e2..4b373ec7e 100644
--- a/src/common/xmpp/roster_nb.py
+++ b/src/common/xmpp/roster_nb.py
@@ -32,23 +32,23 @@ class NonBlockingRoster(Roster):
self._owner.RegisterHandler('iq', self.RosterIqHandler, 'result', NS_ROSTER, makefirst = 1)
self._owner.RegisterHandler('iq', self.RosterIqHandler, 'set', NS_ROSTER)
self._owner.RegisterHandler('presence', self.PresenceHandler)
- if request:
+ if request:
self.Request()
-
+
def _on_roster_set(self, data):
if data:
self._owner.Dispatcher.ProcessNonBlocking(data)
- if not self.set:
- return
+ if not self.set:
+ return
self._owner.onreceive(None)
if self.on_ready:
self.on_ready(self)
self.on_ready = None
return True
-
+
def getRoster(self, on_ready=None):
''' Requests roster from server if neccessary and returns self. '''
- if not self.set:
+ if not self.set:
self.on_ready = on_ready
self._owner.onreceive(self._on_roster_set)
return
diff --git a/src/common/xmpp/session.py b/src/common/xmpp/session.py
index aa19d1d62..40df45eaa 100644
--- a/src/common/xmpp/session.py
+++ b/src/common/xmpp/session.py
@@ -46,7 +46,7 @@ SESSION_CLOSED =5
class Session:
"""
- The Session class instance is used for storing all session-related info like
+ The Session class instance is used for storing all session-related info like
credentials, socket/xml stream/session state flags, roster items (in case of
client type connection) etc.
Session object have no means of discovering is any info is ready to be read.
@@ -341,7 +341,7 @@ class Session:
def set_session_state(self,newstate):
""" Change the session state.
Session starts with SESSION_NOT_AUTHED state
- and then comes through
+ and then comes through
SESSION_AUTHED, SESSION_BOUND, SESSION_OPENED and SESSION_CLOSED states.
"""
if self._session_state<newstate:
diff --git a/src/common/xmpp/simplexml.py b/src/common/xmpp/simplexml.py
index 7e10185f6..97370cc25 100644
--- a/src/common/xmpp/simplexml.py
+++ b/src/common/xmpp/simplexml.py
@@ -53,14 +53,14 @@ class Node(object):
""" Takes "tag" argument as the name of node (prepended by namespace, if needed and separated from it
by a space), attrs dictionary as the set of arguments, payload list as the set of textual strings
and child nodes that this node carries within itself and "parent" argument that is another node
- that this one will be the child of. Also the __init__ can be provided with "node" argument that is
+ that this one will be the child of. Also the __init__ can be provided with "node" argument that is
either a text string containing exactly one node or another Node instance to begin with. If both
"node" and other arguments is provided then the node initially created as replica of "node"
provided and then modified to be compliant with other arguments."""
if node:
- if self.FORCE_NODE_RECREATION and isinstance(node, Node):
+ if self.FORCE_NODE_RECREATION and isinstance(node, Node):
node=str(node)
- if not isinstance(node, Node):
+ if not isinstance(node, Node):
node=NodeBuilder(node,self)
node_built = True
else:
@@ -94,7 +94,7 @@ class Node(object):
for i in payload:
if isinstance(i, Node): self.addChild(node=i)
else: self.data.append(ustr(i))
-
+
def lookup_nsp(self,pfx=''):
ns = self.nsd.get(pfx,None)
if ns is None:
@@ -119,7 +119,7 @@ class Node(object):
val = ustr(self.attrs[key])
s = s + ' %s="%s"' % ( key, XMLescape(val) )
s = s + ">"
- cnt = 0
+ cnt = 0
if self.kids:
if fancy: s = s + "\n"
for a in self.kids:
@@ -196,7 +196,7 @@ class Node(object):
try: ret.append(self.kids[i])
except IndexError: pass
return ret
- def getTag(self, name, attrs={}, namespace=None):
+ def getTag(self, name, attrs={}, namespace=None):
""" Filters all child nodes using specified arguments as filter.
Returns the first found or None if not found. """
return self.getTags(name, attrs, namespace, one=1)
@@ -224,7 +224,7 @@ class Node(object):
else: nodes.append(node)
if one and nodes: return nodes[0]
if not one: return nodes
-
+
def iterTags(self, name, attrs={}, namespace=None):
""" Iterate over all children using specified arguments as filter. """
for node in self.kids:
@@ -248,8 +248,8 @@ class Node(object):
def setNamespace(self, namespace):
""" Changes the node namespace. """
self.namespace=namespace
- def setParent(self, node):
- """ Sets node's parent to "node". WARNING: do not checks if the parent already present
+ def setParent(self, node):
+ """ Sets node's parent to "node". WARNING: do not checks if the parent already present
and not removes the node from the list of childs of previous parent. """
self.parent = node
def setPayload(self,payload,add=0):
@@ -320,7 +320,7 @@ DBG_NODEBUILDER = 'nodebuilder'
class NodeBuilder:
""" Builds a Node class minidom from data parsed to it. This class used for two purposes:
1. Creation an XML Node from a textual representation. F.e. reading a config file. See an XML2Node method.
- 2. Handling an incoming XML stream. This is done by mangling
+ 2. Handling an incoming XML stream. This is done by mangling
the __dispatch_depth parameter and redefining the dispatch method.
You do not need to use this class directly if you do not designing your own XML handler."""
def __init__(self,data=None,initial_node=None):
@@ -331,7 +331,7 @@ class NodeBuilder:
"data" (if provided) feeded to parser immidiatedly after instance init.
"""
self.DEBUG(DBG_NODEBUILDER, "Preparing to handle incoming XML stream.", 'start')
-
+
self._parser = xml.parsers.expat.ParserCreate()
self._parser.StartElementHandler = self.starttag
self._parser.EndElementHandler = self.endtag
@@ -339,7 +339,7 @@ class NodeBuilder:
self._parser.CharacterDataHandler = self.handle_cdata
self._parser.buffer_text = True
self.Parse = self._parser.Parse
-
+
self.__depth = 0
self.__last_depth = 0
self.__max_depth = 0
@@ -352,13 +352,13 @@ class NodeBuilder:
self.data_buffer = None
if data:
self._parser.Parse(data,1)
-
+
def check_data_buffer(self):
if self.data_buffer:
self._ptr.data.append(''.join(self.data_buffer))
del self.data_buffer[:]
self.data_buffer = None
-
+
def destroy(self):
""" Method used to allow class instance to be garbage-collected. """
self.check_data_buffer()
@@ -373,9 +373,9 @@ class NodeBuilder:
self._inc_depth()
self.DEBUG(DBG_NODEBUILDER, "DEPTH -> %i , tag -> %s, attrs -> %s" % (self.__depth, tag, repr(attrs)), 'down')
if self.__depth == self._dispatch_depth:
- if not self._mini_dom :
+ if not self._mini_dom :
self._mini_dom = Node(tag=tag, attrs=attrs, nsp = self._document_nsp, node_built=True)
- else:
+ else:
Node.__init__(self._mini_dom,tag=tag, attrs=attrs, nsp = self._document_nsp, node_built=True)
self._ptr = self._mini_dom
elif self.__depth > self._dispatch_depth:
@@ -398,7 +398,7 @@ class NodeBuilder:
except ValueError, e:
self._document_attrs = None
raise ValueError(str(e))
- if not self.last_is_data and self._ptr.parent:
+ if not self.last_is_data and self._ptr.parent:
self._ptr.parent.data.append('')
self.last_is_data = 0
def endtag(self, tag ):
@@ -414,7 +414,7 @@ class NodeBuilder:
self._dec_depth()
self.last_is_data = 0
if self.__depth == 0: self.stream_footer_received()
-
+
def handle_cdata(self, data):
if self.last_is_data:
if self.data_buffer:
@@ -422,7 +422,7 @@ class NodeBuilder:
elif self._ptr:
self.data_buffer = [data]
self.last_is_data = 1
-
+
def handle_namespace_start(self, prefix, uri):
"""XML Parser callback. Used internally"""
self.check_data_buffer()
diff --git a/src/common/xmpp/transports_nb.py b/src/common/xmpp/transports_nb.py
index 5414fc956..500e55a97 100644
--- a/src/common/xmpp/transports_nb.py
+++ b/src/common/xmpp/transports_nb.py
@@ -1,6 +1,6 @@
## transports_nb.py
## based on transports.py
-##
+##
## Copyright (C) 2003-2004 Alexey "Snake" Nezhdanov
## modified by Dimitur Kirov <dkirov@gmail.com>
##
@@ -22,7 +22,7 @@ from simplexml import ustr
from client import PlugIn
from idlequeue import IdleObject
from protocol import *
-from transports import *
+from transports import *
import sys
import os
@@ -53,7 +53,7 @@ except ImportError:
print >> sys.stderr, "PyOpenSSL not found, falling back to Python builtin SSL objects (insecure)."
print >> sys.stderr, "=" * 79
-# timeout to connect to the server socket, it doesn't include auth
+# timeout to connect to the server socket, it doesn't include auth
CONNECT_TIMEOUT_SECONDS = 30
# how long to wait for a disconnect to complete
@@ -240,14 +240,14 @@ class NonBlockingTcp(PlugIn, IdleObject):
''' This class can be used instead of transports.Tcp in threadless implementations '''
def __init__(self, on_connect = None, on_connect_failure = None, server=None, use_srv = True):
''' Cache connection point 'server'. 'server' is the tuple of (host, port)
- absolutely the same as standard tcp socket uses.
+ absolutely the same as standard tcp socket uses.
on_connect - called when we connect to the socket
on_connect_failure - called if there was error connecting to socket
'''
IdleObject.__init__(self)
PlugIn.__init__(self)
self.DBG_LINE='socket'
- self._exported_methods=[self.send, self.disconnect, self.onreceive, self.set_send_timeout,
+ self._exported_methods=[self.send, self.disconnect, self.onreceive, self.set_send_timeout,
self.start_disconnect, self.set_timeout, self.remove_timeout]
self._server = server
self._hostfqdn = server[0]
@@ -256,43 +256,43 @@ class NonBlockingTcp(PlugIn, IdleObject):
self.on_receive = None
self.on_disconnect = None
self.printed_error = False
-
+
# 0 - not connected
# 1 - connected
# -1 - about to disconnect (when we wait for final events to complete)
# -2 - disconnected
self.state = 0
-
- # queue with messages to be send
+
+ # queue with messages to be send
self.sendqueue = []
-
+
# bytes remained from the last send message
self.sendbuff = ''
-
+
# time to wait for SOME stanza to come and then send keepalive
self.sendtimeout = 0
-
+
# in case we want to something different than sending keepalives
self.on_timeout = None
-
+
# writable, readable - keep state of the last pluged flags
# This prevents replug of same object with the same flags
self.writable = True
self.readable = False
self.ais = None
-
+
def plugin(self, owner):
''' Fire up connection. Return non-empty string on success.
Also registers self.disconnected method in the owner's dispatcher.
Called internally. '''
self.idlequeue = owner.idlequeue
self.printed_error = False
- if not self._server:
+ if not self._server:
self._server=(self._owner.Server,5222)
if self.connect(self._server) is False:
return False
return True
-
+
def read_timeout(self):
if self.state == 0:
self.idlequeue.unplug_idle(self.fd)
@@ -307,7 +307,7 @@ class NonBlockingTcp(PlugIn, IdleObject):
''' Try to establish connection. '''
if not server:
server=self._server
- else:
+ else:
self._server = server
self._hostfqdn = self._server[0]
self.printed_error = False
@@ -338,23 +338,23 @@ class NonBlockingTcp(PlugIn, IdleObject):
writable = False
if self.writable != writable or self.readable != readable:
self.idlequeue.plug_idle(self, writable, readable)
-
+
def pollout(self):
if self.state == 0:
self._do_connect()
return
self._do_send()
-
+
def plugout(self):
''' Disconnect from the remote server and unregister self.disconnected method from
the owner's dispatcher. '''
self.disconnect()
self._owner.Connection = None
self._owner = None
-
+
def pollin(self):
- self._do_receive()
-
+ self._do_receive()
+
def pollend(self, retry=False):
if not self.printed_error:
self.printed_error = True
@@ -366,13 +366,13 @@ class NonBlockingTcp(PlugIn, IdleObject):
self.disconnect()
if conn_failure_cb:
conn_failure_cb(retry)
-
+
def disconnect(self):
if self.state == -2: # already disconnected
return
self.state = -2
self.sendqueue = None
- self.remove_timeout()
+ self.remove_timeout()
try:
self._owner.disconnected()
except Exception:
@@ -394,12 +394,12 @@ class NonBlockingTcp(PlugIn, IdleObject):
if self.on_disconnect:
self.on_disconnect()
self.on_connect_failure = None
-
+
def end_disconnect(self):
''' force disconnect only if we are still trying to disconnect '''
if self.state == -1:
self.disconnect()
-
+
def start_disconnect(self, to_send, on_disconnect):
self.on_disconnect = on_disconnect
@@ -412,19 +412,19 @@ class NonBlockingTcp(PlugIn, IdleObject):
self.send('</stream:stream>')
self.state = -1 # about to disconnect
self.idlequeue.set_alarm(self.end_disconnect, DISCONNECT_TIMEOUT_SECONDS)
-
+
def set_timeout(self, timeout):
if self.state >= 0 and self.fd > 0:
self.idlequeue.set_read_timeout(self.fd, timeout)
-
+
def remove_timeout(self):
if self.fd:
self.idlequeue.remove_timeout(self.fd)
-
+
def onreceive(self, recv_handler):
''' Sets the on_receive callback. Do not confuse it with
on_receive() method, which is the callback itself.
-
+
If recv_handler==None, it tries to set that callback assuming that
our owner also has a Dispatcher object plugged in, to its
ProcessNonBlocking method.'''
@@ -438,7 +438,7 @@ class NonBlockingTcp(PlugIn, IdleObject):
# make sure this cb is not overriden by recursive calls
if not recv_handler(None) and _tmp == self.on_receive:
self.on_receive = recv_handler
-
+
def _do_receive(self, errors_only=False):
''' Reads all pending incoming data. Calls owner's disconnected() method if appropriate.'''
ERR_DISCONN = -2 # Misc error signifying that we got disconnected
@@ -446,7 +446,7 @@ class NonBlockingTcp(PlugIn, IdleObject):
received = None
errnum = 0
errtxt = 'No Error Set'
- try:
+ try:
# get as many bites, as possible, but not more than RECV_BUFSIZE
received = self._recv(RECV_BUFSIZE)
except (socket.error, socket.herror, socket.gaierror), e:
@@ -515,7 +515,7 @@ class NonBlockingTcp(PlugIn, IdleObject):
if self.on_connect_failure:
self.on_connect_failure()
return True
-
+
def _do_send(self):
if not self.sendbuff:
if not self.sendqueue:
@@ -532,12 +532,12 @@ class NonBlockingTcp(PlugIn, IdleObject):
self._on_send()
self.disconnect()
return
- # we are not waiting for write
+ # we are not waiting for write
self._plug_idle()
self._on_send()
except socket.error, e:
if e[0] == socket.SSL_ERROR_WANT_WRITE:
- return True
+ return True
log.error("_do_send:", exc_info=True)
#traceback.print_exc()
if self.state < 0:
@@ -563,7 +563,7 @@ class NonBlockingTcp(PlugIn, IdleObject):
self._server=ai[4]
except socket.error, e:
errnum, errstr = e
-
+
# Ignore "Socket already connected".
# FIXME: This happens when we switch an already
# connected socket to SSL (STARTTLS). Instead of
@@ -614,16 +614,16 @@ class NonBlockingTcp(PlugIn, IdleObject):
self.on_connect = None
def send(self, raw_data, now = False):
- '''Append raw_data to the queue of messages to be send.
+ '''Append raw_data to the queue of messages to be send.
If supplied data is unicode string, encode it to utf-8.
'''
if self.state <= 0:
return
r = raw_data
- if isinstance(r, unicode):
+ if isinstance(r, unicode):
r = r.encode('utf-8')
- elif not isinstance(r, str):
+ elif not isinstance(r, str):
r = ustr(r).encode('utf-8')
if now:
self.sendqueue.insert(0, r)
@@ -639,25 +639,25 @@ class NonBlockingTcp(PlugIn, IdleObject):
if hasattr(self._owner, 'Dispatcher'):
self._owner.Dispatcher.Event('', DATA_SENT, self.sent_data)
self.sent_data = None
-
+
def _on_send_failure(self):
self.DEBUG("Socket error while sending data",'error')
self._owner.disconnected()
self.sent_data = None
-
+
def set_send_timeout(self, timeout, on_timeout):
self.sendtimeout = timeout
if self.sendtimeout > 0:
self.on_timeout = on_timeout
else:
self.on_timeout = None
-
+
def renew_send_timeout(self):
if self.on_timeout and self.sendtimeout > 0:
self.set_timeout(self.sendtimeout)
else:
self.remove_timeout()
-
+
def getHost(self):
''' Return the 'host' value that is connection is [will be] made to.'''
return self._server[0]
@@ -682,10 +682,10 @@ class NonBlockingTLS(PlugIn):
''' TLS connection used to encrypts already estabilished tcp connection.'''
# from ssl.h (partial extract)
- ssl_h_bits = { "SSL_ST_CONNECT": 0x1000, "SSL_ST_ACCEPT": 0x2000,
- "SSL_CB_LOOP": 0x01, "SSL_CB_EXIT": 0x02,
- "SSL_CB_READ": 0x04, "SSL_CB_WRITE": 0x08,
- "SSL_CB_ALERT": 0x4000,
+ ssl_h_bits = { "SSL_ST_CONNECT": 0x1000, "SSL_ST_ACCEPT": 0x2000,
+ "SSL_CB_LOOP": 0x01, "SSL_CB_EXIT": 0x02,
+ "SSL_CB_READ": 0x04, "SSL_CB_WRITE": 0x08,
+ "SSL_CB_ALERT": 0x4000,
"SSL_CB_HANDSHAKE_START": 0x10, "SSL_CB_HANDSHAKE_DONE": 0x20}
def PlugIn(self, owner, now=0, on_tls_start = None):
@@ -693,7 +693,7 @@ class NonBlockingTLS(PlugIn):
If 'now' in false then starts encryption as soon as TLS feature is
declared by the server (if it were already declared - it is ok).
'''
- if 'NonBlockingTLS' in owner.__dict__:
+ if 'NonBlockingTLS' in owner.__dict__:
return # Already enabled.
PlugIn.PlugIn(self, owner)
self.DBG_LINE = DBG_NONBLOCKINGTLS
@@ -710,14 +710,14 @@ class NonBlockingTLS(PlugIn):
self.tls_start()
return res
if self._owner.Dispatcher.Stream.features:
- try:
+ try:
self.FeaturesHandler(self._owner.Dispatcher, self._owner.Dispatcher.Stream.features)
- except NodeProcessed:
+ except NodeProcessed:
pass
- else:
+ else:
self._owner.RegisterHandlerOnce('features',self.FeaturesHandler, xmlns=NS_STREAMS)
self.starttls = None
-
+
def plugout(self,now=0):
''' Unregisters TLS handler's from owner's dispatcher. Take note that encription
can not be stopped once started. You can only break the connection and start over.'''
@@ -731,7 +731,7 @@ class NonBlockingTLS(PlugIn):
if self.on_tls_start:
self.on_tls_start()
self.on_tls_start = None
-
+
def FeaturesHandler(self, conn, feats):
''' Used to analyse server <features/> tag for TLS support.
If TLS is supported starts the encryption negotiation. Used internally '''
@@ -868,7 +868,7 @@ class NonBlockingTLS(PlugIn):
def StartTLSHandler(self, conn, starttls):
''' Handle server reply if TLS is allowed to process. Behaves accordingly.
Used internally.'''
- if starttls.getNamespace() != NS_TLS:
+ if starttls.getNamespace() != NS_TLS:
return
self.starttls = starttls.getName()
if self.starttls == 'failure':
@@ -890,15 +890,15 @@ class NBHTTPPROXYsocket(NonBlockingTcp):
''' This class can be used instead of transports.HTTPPROXYsocket
HTTP (CONNECT) proxy connection class. Uses TCPsocket as the base class
redefines only connect method. Allows to use HTTP proxies like squid with
- (optionally) simple authentication (using login and password).
-
+ (optionally) simple authentication (using login and password).
+
'''
def __init__(self, on_connect =None, on_proxy_failure=None, on_connect_failure = None,proxy = None,server = None,use_srv=True):
''' Caches proxy and target addresses.
'proxy' argument is a dictionary with mandatory keys 'host' and 'port' (proxy address)
and optional keys 'user' and 'password' to use for authentication.
'server' argument is a tuple of host and port - just like TCPsocket uses. '''
- self.on_connect_proxy = on_connect
+ self.on_connect_proxy = on_connect
self.on_proxy_failure = on_proxy_failure
self.on_connect_failure = on_connect_failure
NonBlockingTcp.__init__(self, self._on_tcp_connect, on_connect_failure, server, use_srv)
@@ -916,7 +916,7 @@ class NBHTTPPROXYsocket(NonBlockingTcp):
(if were specified while creating instance). Instructs proxy to make
connection to the target server. Returns non-empty sting on success. '''
NonBlockingTcp.connect(self, (self.proxy['host'], self.proxy['port']))
-
+
def _on_tcp_connect(self):
self.DEBUG('Proxy server contacted, performing authentification','start')
connector = ['CONNECT %s:%s HTTP/1.0'%self.server,
@@ -931,14 +931,14 @@ class NBHTTPPROXYsocket(NonBlockingTcp):
connector.append('\r\n')
self.onreceive(self._on_headers_sent)
self.send('\r\n'.join(connector))
-
+
def _on_headers_sent(self, reply):
if reply is None:
return
self.reply = reply.replace('\r', '')
- try:
+ try:
proto, code, desc = reply.split('\n')[0].split(' ', 2)
- except Exception:
+ except Exception:
log.error("_on_headers_sent:", exc_info=True)
#traceback.print_exc()
self.on_proxy_failure('Invalid proxy reply')
@@ -951,7 +951,7 @@ class NBHTTPPROXYsocket(NonBlockingTcp):
if len(reply) != 2:
pass
self.onreceive(self._on_proxy_auth)
-
+
def _on_proxy_auth(self, reply):
if self.reply.find('\n\n') == -1:
if reply is None:
@@ -972,7 +972,7 @@ class NBHTTPPROXYsocket(NonBlockingTcp):
class NBSOCKS5PROXYsocket(NonBlockingTcp):
'''SOCKS5 proxy connection class. Uses TCPsocket as the base class
redefines only connect method. Allows to use SOCKS5 proxies with
- (optionally) simple authentication (only USERNAME/PASSWORD auth).
+ (optionally) simple authentication (only USERNAME/PASSWORD auth).
'''
def __init__(self, on_connect = None, on_proxy_failure = None,
on_connect_failure = None, proxy = None, server = None, use_srv = True):
@@ -981,7 +981,7 @@ class NBSOCKS5PROXYsocket(NonBlockingTcp):
(proxy address) and optional keys 'user' and 'password' to use for
authentication. 'server' argument is a tuple of host and port -
just like TCPsocket uses. '''
- self.on_connect_proxy = on_connect
+ self.on_connect_proxy = on_connect
self.on_proxy_failure = on_proxy_failure
self.on_connect_failure = on_connect_failure
NonBlockingTcp.__init__(self, self._on_tcp_connect, on_connect_failure,
@@ -1003,7 +1003,7 @@ class NBSOCKS5PROXYsocket(NonBlockingTcp):
connection to the target server. Returns non-empty sting on success.
'''
NonBlockingTcp.connect(self, (self.proxy['host'], self.proxy['port']))
-
+
def _on_tcp_connect(self):
self.DEBUG('Proxy server contacted, performing authentification', 'start')
if 'user' in self.proxy and 'password' in self.proxy:
diff --git a/src/common/xmpp_stringprep.py b/src/common/xmpp_stringprep.py
index eb587dbca..b2715df0c 100644
--- a/src/common/xmpp_stringprep.py
+++ b/src/common/xmpp_stringprep.py
@@ -87,7 +87,7 @@ class MappingTableFromFunction:
self.map = map_table_function
class EmptyMappingTable:
-
+
__implements__ = IMappingTable
def __init__(self, in_table_function):
@@ -145,7 +145,7 @@ class Profile:
for c in string:
if stringprep.in_table_a1(c):
raise UnicodeError, "Unassigned code point %s" % repr(c)
-
+
def check_bidirectionals(self, string):
found_LCat = False
found_RandALCat = False
@@ -229,12 +229,12 @@ if crippled:
prohibiteds=[LookupTable([u' ', u'"', u'&', u"'", u'/',
u':', u'<', u'>', u'@'])],
check_unassigneds=False,
- check_bidi=False)
+ check_bidi=False)
resourceprep = Profile(normalize=False,
check_unassigneds=False,
check_bidi=False)
-
+
else:
C_11 = LookupTableFromFunction(stringprep.in_table_c11)
C_12 = LookupTableFromFunction(stringprep.in_table_c12)
diff --git a/src/common/zeroconf/connection_handlers_zeroconf.py b/src/common/zeroconf/connection_handlers_zeroconf.py
index 3c5f48234..f2de68687 100644
--- a/src/common/zeroconf/connection_handlers_zeroconf.py
+++ b/src/common/zeroconf/connection_handlers_zeroconf.py
@@ -6,7 +6,7 @@
## - Nikos Kouremenos <nkour@jabber.org>
## - Dimitur Kirov <dkirov@gmail.com>
## - Travis Shirk <travis@pobox.com>
-## - Stefan Bethge <stefan@lanpartei.de>
+## - Stefan Bethge <stefan@lanpartei.de>
##
## This file is part of Gajim.
##
diff --git a/src/common/zeroconf/roster_zeroconf.py b/src/common/zeroconf/roster_zeroconf.py
index 62e122e80..38808b06b 100644
--- a/src/common/zeroconf/roster_zeroconf.py
+++ b/src/common/zeroconf/roster_zeroconf.py
@@ -49,7 +49,7 @@ class Roster:
diffs[key] = self._data[key]['status']
#print 'roster_zeroconf.py: diffs:' + str(diffs)
return diffs
-
+
def setItem(self, jid, name='', groups=''):
#print 'roster_zeroconf.py: setItem %s' % jid
contact = self.zeroconf.get_contact(jid)
@@ -80,7 +80,7 @@ class Roster:
self._data[jid]['name'] = nm
else:
self._data[jid]['name'] = jid
- if status == 'avail':
+ if status == 'avail':
status = 'online'
self._data[jid]['txt_dict'] = txt_dict
if 'msg' not in self._data[jid]['txt_dict']:
@@ -92,7 +92,7 @@ class Roster:
#print 'roster_zeroconf.py: delItem %s' % jid
if jid in self._data:
del self._data[jid]
-
+
def getItem(self, jid):
#print 'roster_zeroconf.py: getItem: %s' % jid
if jid in self._data:
@@ -101,16 +101,16 @@ class Roster:
def __getitem__(self, jid):
#print 'roster_zeroconf.py: __getitem__'
return self._data[jid]
-
+
def getItems(self):
#print 'roster_zeroconf.py: getItems'
# Return list of all [bare] JIDs that the roster currently tracks.
return self._data.keys()
-
+
def keys(self):
#print 'roster_zeroconf.py: keys'
return self._data.keys()
-
+
def getRaw(self):
#print 'roster_zeroconf.py: getRaw'
return self._data
@@ -118,7 +118,7 @@ class Roster:
def getResources(self, jid):
#print 'roster_zeroconf.py: getResources(%s)' % jid
return {}
-
+
def getGroups(self, jid):
return self._data[jid]['groups']
@@ -147,10 +147,10 @@ class Roster:
def Subscribe(self, jid):
pass
-
+
def Unsubscribe(self, jid):
pass
-
+
def Authorize(self, jid):
pass
diff --git a/src/common/zeroconf/zeroconf_avahi.py b/src/common/zeroconf/zeroconf_avahi.py
index c0cfc9ab6..16aea5a18 100644
--- a/src/common/zeroconf/zeroconf_avahi.py
+++ b/src/common/zeroconf/zeroconf_avahi.py
@@ -27,24 +27,24 @@ except ImportError, e:
from common.zeroconf.zeroconf import C_BARE_NAME, C_INTERFACE, C_PROTOCOL, C_DOMAIN
class Zeroconf:
- def __init__(self, new_serviceCB, remove_serviceCB, name_conflictCB,
+ def __init__(self, new_serviceCB, remove_serviceCB, name_conflictCB,
disconnected_CB, error_CB, name, host, port):
self.avahi = None
self.domain = None # specific domain to browse
- self.stype = '_presence._tcp'
- self.port = port # listening port that gets announced
+ self.stype = '_presence._tcp'
+ self.port = port # listening port that gets announced
self.username = name
self.host = host
self.txt = {} # service data
-
- #XXX these CBs should be set to None when we destroy the object
- # (go offline), because they create a circular reference
+
+ #XXX these CBs should be set to None when we destroy the object
+ # (go offline), because they create a circular reference
self.new_serviceCB = new_serviceCB
self.remove_serviceCB = remove_serviceCB
self.name_conflictCB = name_conflictCB
self.disconnected_CB = disconnected_CB
self.error_CB = error_CB
-
+
self.service_browser = None
self.domain_browser = None
self.bus = None
@@ -60,10 +60,10 @@ class Zeroconf:
def entrygroup_commit_error_CB(self, err):
# left blank for possible later usage
pass
-
+
def error_callback1(self, err):
gajim.log.debug('Error while resolving: ' + str(err))
-
+
def error_callback(self, err):
gajim.log.debug(str(err))
# timeouts are non-critical
@@ -75,7 +75,7 @@ class Zeroconf:
gajim.log.debug('Found service %s in domain %s on %i.%i.' % (name, domain, interface, protocol))
if not self.connected:
return
-
+
# synchronous resolving
self.server.ResolveService( int(interface), int(protocol), name, stype, \
domain, self.avahi.PROTO_UNSPEC, dbus.UInt32(0), \
@@ -93,13 +93,13 @@ class Zeroconf:
return
def new_service_type(self, interface, protocol, stype, domain, flags):
- # Are we already browsing this domain for this type?
+ # Are we already browsing this domain for this type?
if self.service_browser:
return
object_path = self.server.ServiceBrowserNew(interface, protocol, \
stype, domain, dbus.UInt32(0))
-
+
self.service_browser = dbus.Interface(self.bus.get_object(self.avahi.DBUS_NAME, \
object_path) , self.avahi.DBUS_INTERFACE_SERVICE_BROWSER)
self.service_browser.connect_to_signal('ItemNew', self.new_service_callback)
@@ -109,7 +109,7 @@ class Zeroconf:
def new_domain_callback(self,interface, protocol, domain, flags):
if domain != "local":
self.browse_domain(interface, protocol, domain)
-
+
def txt_array_to_dict(self, txt_array):
txt_dict = {}
for els in txt_array:
@@ -131,8 +131,8 @@ class Zeroconf:
val = ''
txt_dict[key] = val.decode('utf-8')
return txt_dict
-
- def service_resolved_callback(self, interface, protocol, name, stype, domain, host, aprotocol, address, port, txt, flags):
+
+ def service_resolved_callback(self, interface, protocol, name, stype, domain, host, aprotocol, address, port, txt, flags):
gajim.log.debug('Service data for service %s in domain %s on %i.%i:'
% (name, domain, interface, protocol))
gajim.log.debug('Host %s (%s), port %i, TXT data: %s' % (host, address, port,
@@ -142,10 +142,10 @@ class Zeroconf:
bare_name = name
if name.find('@') == -1:
name = name + '@' + name
-
+
# we don't want to see ourselves in the list
if name != self.name:
- self.contacts[name] = (name, domain, interface, protocol, host, address, port,
+ self.contacts[name] = (name, domain, interface, protocol, host, address, port,
bare_name, txt)
self.new_serviceCB(name)
else:
@@ -230,14 +230,14 @@ class Zeroconf:
# create an EntryGroup for publishing
self.entrygroup = dbus.Interface(self.bus.get_object(self.avahi.DBUS_NAME, self.server.EntryGroupNew()), self.avahi.DBUS_INTERFACE_ENTRY_GROUP)
self.entrygroup.connect_to_signal('StateChanged', self.entrygroup_state_changed_callback)
-
+
txt = {}
-
+
#remove empty keys
for key,val in self.txt.iteritems():
if val:
txt[key] = val
-
+
txt['port.p2pj'] = self.port
txt['version'] = 1
txt['txtvers'] = 1
@@ -256,16 +256,16 @@ class Zeroconf:
'', dbus.UInt16(self.port), self.avahi_txt(),
reply_handler=self.service_added_callback,
error_handler=self.service_add_fail_callback)
-
- self.entrygroup.Commit(reply_handler=self.service_committed_callback,
+
+ self.entrygroup.Commit(reply_handler=self.service_committed_callback,
error_handler=self.entrygroup_commit_error_CB)
return True
-
+
except dbus.DBusException, e:
gajim.log.debug(str(e))
return False
-
+
def announce(self):
if not self.connected:
return False
@@ -288,7 +288,7 @@ class Zeroconf:
self.entrygroup._obj = None
self.entrygroup = None
self.announced = False
-
+
return True
else:
return False
@@ -318,8 +318,8 @@ class Zeroconf:
return True
try:
self.bus = dbus.SystemBus()
- self.bus.add_signal_receiver(self.avahi_dbus_connect_cb,
- "NameOwnerChanged", "org.freedesktop.DBus",
+ self.bus.add_signal_receiver(self.avahi_dbus_connect_cb,
+ "NameOwnerChanged", "org.freedesktop.DBus",
arg0="org.freedesktop.Avahi")
except Exception, e:
# System bus is not present
@@ -345,7 +345,7 @@ class Zeroconf:
try:
self.server = dbus.Interface(self.bus.get_object(self.avahi.DBUS_NAME, \
self.avahi.DBUS_PATH_SERVER), self.avahi.DBUS_INTERFACE_SERVER)
- self.server.connect_to_signal('StateChanged',
+ self.server.connect_to_signal('StateChanged',
self.server_state_changed_callback)
except Exception, e:
# Avahi service is not present
@@ -359,7 +359,7 @@ class Zeroconf:
self.name = self.username + '@' + self.host # service name
if not self.connect_avahi():
return False
-
+
self.connected = True
# start browsing
if self.domain is None:
@@ -375,7 +375,7 @@ class Zeroconf:
self.domain_browser.connect_to_signal('Failure', self.error_callback)
else:
self.browse_domain(self.avahi.IF_UNSPEC, self.avahi.PROTO_UNSPEC, self.domain)
-
+
return True
def disconnect(self):
@@ -414,7 +414,7 @@ class Zeroconf:
if not jid in self.contacts:
return None
return self.contacts[jid]
-
+
def update_txt(self, show = None):
if show:
self.txt['status'] = self.replace_show(show)
diff --git a/src/common/zeroconf/zeroconf_bonjour.py b/src/common/zeroconf/zeroconf_bonjour.py
index b46f82523..4fa9fc013 100644
--- a/src/common/zeroconf/zeroconf_bonjour.py
+++ b/src/common/zeroconf/zeroconf_bonjour.py
@@ -31,23 +31,23 @@ except ImportError, e:
resolve_timeout = 1
class Zeroconf:
- def __init__(self, new_serviceCB, remove_serviceCB, name_conflictCB,
+ def __init__(self, new_serviceCB, remove_serviceCB, name_conflictCB,
disconnected_CB, error_CB, name, host, port):
self.domain = None # specific domain to browse
- self.stype = '_presence._tcp'
- self.port = port # listening port that gets announced
+ self.stype = '_presence._tcp'
+ self.port = port # listening port that gets announced
self.username = name
self.host = host
self.txt = pybonjour.TXTRecord() # service data
-
- # XXX these CBs should be set to None when we destroy the object
- # (go offline), because they create a circular reference
+
+ # XXX these CBs should be set to None when we destroy the object
+ # (go offline), because they create a circular reference
self.new_serviceCB = new_serviceCB
self.remove_serviceCB = remove_serviceCB
self.name_conflictCB = name_conflictCB
self.disconnected_CB = disconnected_CB
self.error_CB = error_CB
-
+
self.contacts = {} # all current local contacts with data
self.connected = False
self.announced = False
@@ -64,7 +64,7 @@ class Zeroconf:
if not (flags & pybonjour.kDNSServiceFlagsAdd):
self.remove_service_callback(serviceName)
return
-
+
# asynchronous resolving
resolve_sdRef = pybonjour.DNSServiceResolve(0, interfaceIndex, serviceName, regtype, replyDomain, self.service_resolved_callback)
@@ -100,9 +100,9 @@ class Zeroconf:
items = pybonjour.TXTRecord.parse(txt)._items
return dict((v[0], v[1]) for v in items.values())
- def service_resolved_callback(self, sdRef, flags, interfaceIndex, errorCode, fullname,
+ def service_resolved_callback(self, sdRef, flags, interfaceIndex, errorCode, fullname,
hosttarget, port, txtRecord):
-
+
# TODO: do proper decoding...
escaping= {
r'\.': '.',
@@ -114,7 +114,7 @@ class Zeroconf:
result = re.split('(?<!\\\\)\.', fullname)
name = result[0]
protocol, domain = result[2:4]
-
+
# Replace the escaped values
for src, trg in escaping.items():
name = name.replace(src, trg)
@@ -126,11 +126,11 @@ class Zeroconf:
if not self.connected:
return
-
+
bare_name = name
if '@' not in name:
name = name + '@' + name
-
+
# we don't want to see ourselves in the list
if name != self.name:
self.contacts[name] = (name, domain, interfaceIndex, protocol, hosttarget, hosttarget, port, bare_name, txtRecord)
@@ -146,10 +146,10 @@ class Zeroconf:
self.resolved.append(True)
# different handler when resolving all contacts
- def service_resolved_all_callback(self, sdRef, flags, interfaceIndex, errorCode, fullname, hosttarget, port, txtRecord):
+ def service_resolved_all_callback(self, sdRef, flags, interfaceIndex, errorCode, fullname, hosttarget, port, txtRecord):
if not self.connected:
return
-
+
escaping= {
r'\.': '.',
r'\032': ' ',
@@ -157,7 +157,7 @@ class Zeroconf:
}
name, stype, protocol, domain, dummy = fullname.split('.')
-
+
# Replace the escaped values
for src, trg in escaping.items():
name = name.replace(src, trg)
@@ -165,7 +165,7 @@ class Zeroconf:
bare_name = name
if name.find('@') == -1:
name = name + '@' + name
-
+
# we don't want to see ourselves in the list
if name != self.name:
self.contacts[name] = (name, domain, interfaceIndex, protocol, hosttarget, hosttarget, port, bare_name, txtRecord)
@@ -201,12 +201,12 @@ class Zeroconf:
def create_service(self):
txt = {}
-
+
#remove empty keys
for key,val in self.txt:
if val:
txt[key] = val
-
+
txt['port.p2pj'] = self.port
txt['version'] = 1
txt['txtvers'] = 1
@@ -218,7 +218,7 @@ class Zeroconf:
txt['status'] = 'avail'
self.txt = pybonjour.TXTRecord(txt, strict=True)
-
+
try:
sdRef = pybonjour.DNSServiceRegister(name = self.name,
regtype = self.stype, port = self.port, txtRecord = self.txt,
@@ -257,7 +257,7 @@ class Zeroconf:
self.name = self.username + '@' + self.host # service name
self.connected = True
-
+
# start browsing
if self.domain is None:
# Explicitly browse .local
@@ -268,7 +268,7 @@ class Zeroconf:
else:
self.browse_domain(self.domain)
-
+
return True
def disconnect(self):
@@ -276,8 +276,8 @@ class Zeroconf:
self.connected = False
self.browse_sdRef.close()
self.remove_announce()
-
-
+
+
def browse_domain(self, domain=None):
gajim.log.debug('starting to browse')
try:
@@ -320,7 +320,7 @@ class Zeroconf:
if not jid in self.contacts:
return None
return self.contacts[jid]
-
+
def update_txt(self, show = None):
if show:
self.txt['status'] = self.replace_show(show)