32
32
setdefaultencoding ('utf8' )
33
33
34
34
35
- TIMEOUT = 10
35
+ TIMEOUT = 30
36
36
37
37
38
38
def register (client , username , password , name , email ):
@@ -42,11 +42,11 @@ def register(client, username, password, name, email):
42
42
iq ['register' ]['password' ] = password
43
43
iq ['register' ]['name' ] = name
44
44
iq ['register' ]['email' ] = email
45
- iq .send (now = True ) # , timeout=TIMEOUT)
45
+ iq .send (now = True , timeout = TIMEOUT )
46
46
47
47
48
48
def registration_wrapper (client , function , logger_success , logger_error ,
49
- use_client , args , kwargs ):
49
+ args , kwargs ):
50
50
51
51
connected = client .connect (reattempt = False )
52
52
@@ -58,16 +58,14 @@ def registration_wrapper(client, function, logger_success, logger_error,
58
58
59
59
success = False
60
60
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 )
67
62
except IqError as e :
68
- logger .error (logger_error % e . iq [ 'error' ][ 'text' ] )
63
+ logger .error (logger_error , client . boundjid . bare )
69
64
except IqTimeout :
70
65
logger .error ("No response from server." )
66
+ else :
67
+ logger .info (logger_success , client .boundjid )
68
+ success = True
71
69
finally :
72
70
client .disconnect ()
73
71
return success
@@ -77,13 +75,12 @@ def register_account(jid, password, name='', email=''):
77
75
client = sleekxmpp .ClientXMPP (jid , password )
78
76
client .register_plugin ('xep_0077' ) # In-band Registration
79
77
80
- registration_wrapper (
78
+ return registration_wrapper (
81
79
client = client ,
82
80
function = register ,
83
81
logger_success = "Account created for %s!" ,
84
82
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 ),
87
84
kwargs = {}
88
85
)
89
86
@@ -92,12 +89,11 @@ def change_password(jid, old_password, new_password):
92
89
client = sleekxmpp .ClientXMPP (jid , old_password )
93
90
client .register_plugin ('xep_0077' ) # In-band Registration
94
91
95
- registration_wrapper (
92
+ return registration_wrapper (
96
93
client = client ,
97
94
function = client ['xep_0077' ].change_password ,
98
95
logger_success = "Password changed for %s!" ,
99
96
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 ),
102
98
kwargs = dict (timeout = TIMEOUT )
103
99
)
0 commit comments