Skip to content

Commit df51d78

Browse files
committed
More refactoring of xmpp module
1 parent 0569cb6 commit df51d78

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

conversejs/xmpp.py

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
setdefaultencoding('utf8')
3333

3434

35-
TIMEOUT = 10
35+
TIMEOUT = 30
3636

3737

3838
def register(client, username, password, name, email):
@@ -42,11 +42,11 @@ def register(client, username, password, name, email):
4242
iq['register']['password'] = password
4343
iq['register']['name'] = name
4444
iq['register']['email'] = email
45-
iq.send(now=True) #, timeout=TIMEOUT)
45+
iq.send(now=True, timeout=TIMEOUT)
4646

4747

4848
def registration_wrapper(client, function, logger_success, logger_error,
49-
use_client, args, kwargs):
49+
args, kwargs):
5050

5151
connected = client.connect(reattempt=False)
5252

@@ -58,16 +58,14 @@ def registration_wrapper(client, function, logger_success, logger_error,
5858

5959
success = False
6060
try:
61-
if use_client:
62-
function(client, *args, **kwargs)
63-
else:
64-
function(*args, **kwargs)
65-
logger.info(logger_success % client.boundjid)
66-
success = True
61+
function(*args, **kwargs)
6762
except IqError as e:
68-
logger.error(logger_error % e.iq['error']['text'])
63+
logger.error(logger_error, client.boundjid.bare)
6964
except IqTimeout:
7065
logger.error("No response from server.")
66+
else:
67+
logger.info(logger_success, client.boundjid)
68+
success = True
7169
finally:
7270
client.disconnect()
7371
return success
@@ -77,13 +75,12 @@ def register_account(jid, password, name='', email=''):
7775
client = sleekxmpp.ClientXMPP(jid, password)
7876
client.register_plugin('xep_0077') # In-band Registration
7977

80-
registration_wrapper(
78+
return registration_wrapper(
8179
client=client,
8280
function=register,
8381
logger_success="Account created for %s!",
8482
logger_error="Could not register account: %s",
85-
use_client=True,
86-
args=[client.boundjid.user, password, name, email],
83+
args=(client, client.boundjid.user, password, name, email),
8784
kwargs={}
8885
)
8986

@@ -92,12 +89,11 @@ def change_password(jid, old_password, new_password):
9289
client = sleekxmpp.ClientXMPP(jid, old_password)
9390
client.register_plugin('xep_0077') # In-band Registration
9491

95-
registration_wrapper(
92+
return registration_wrapper(
9693
client=client,
9794
function=client['xep_0077'].change_password,
9895
logger_success="Password changed for %s!",
9996
logger_error="Could not change password for account: %s",
100-
use_client=False,
101-
args=[new_password, client.boundjid.server, client.boundjid.bare],
97+
args=(new_password, client.boundjid.server, client.boundjid.bare),
10298
kwargs=dict(timeout=TIMEOUT)
10399
)

0 commit comments

Comments
 (0)