ability to have a random string in the resource

This commit is contained in:
Yann Leboulanger 2017-01-04 13:13:55 +01:00
parent 2b1b461e90
commit 65362358a9
2 changed files with 5 additions and 3 deletions

View File

@ -325,7 +325,7 @@ class Config:
'client_cert_encrypted': [ opt_bool, False, '', False ],
'savepass': [ opt_bool, False ],
'password': [ opt_str, '' ],
'resource': [ opt_str, 'gajim', '', True ],
'resource': [ opt_str, 'gajim.$rand', '', True ],
'priority': [ opt_int, 5, '', True ],
'adjust_priority_with_status': [ opt_bool, True, _('Priority will change automatically according to your status. Priorities are defined in autopriority_* options.') ],
'autopriority_online': [ opt_int, 50],

View File

@ -36,7 +36,7 @@ import os
import random
import socket
import operator
import string
import time
import locale
import hmac
@ -182,8 +182,10 @@ class CommonConnection:
resource = gajim.config.get_per('accounts', self.name, 'resource')
# All valid resource substitution strings should be added to this hash.
if resource:
rand = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(8))
resource = Template(resource).safe_substitute({
'hostname': socket.gethostname()
'hostname': socket.gethostname(),
'rand': rand
})
return resource