massive refactoring to switch from camelCase to snake_case:
historically, Libervia (SàT before) was using camelCase as allowed by PEP8 when using a pre-PEP8 code, to use the same coding style as in Twisted. However, snake_case is more readable and it's better to follow PEP8 best practices, so it has been decided to move on full snake_case. Because Libervia has a huge codebase, this ended with a ugly mix of camelCase and snake_case. To fix that, this patch does a big refactoring by renaming every function and method (including bridge) that are not coming from Twisted or Wokkel, to use fully snake_case. This is a massive change, and may result in some bugs.
This commit is contained in:
parent
d50412c7f7
commit
6a6f15707a
1 changed files with 9945 additions and 9945 deletions
|
|
@ -77,30 +77,30 @@ class InvitationsPlugin(object):
|
|||
log.info(_("plugin Invitations initialization"))
|
||||
self.host = host
|
||||
self.invitations = persistent.LazyPersistentBinaryDict('invitations')
|
||||
host.bridge.addMethod("invitationCreate", ".plugin", in_sign='sasssssssssa{ss}s',
|
||||
host.bridge.add_method("invitation_create", ".plugin", in_sign='sasssssssssa{ss}s',
|
||||
out_sign='a{ss}',
|
||||
method=self._create,
|
||||
async_=True)
|
||||
host.bridge.addMethod("invitationGet", ".plugin", in_sign='s', out_sign='a{ss}',
|
||||
host.bridge.add_method("invitation_get", ".plugin", in_sign='s', out_sign='a{ss}',
|
||||
method=self.get,
|
||||
async_=True)
|
||||
host.bridge.addMethod("invitationDelete", ".plugin", in_sign='s', out_sign='',
|
||||
host.bridge.add_method("invitation_delete", ".plugin", in_sign='s', out_sign='',
|
||||
method=self._delete,
|
||||
async_=True)
|
||||
host.bridge.addMethod("invitationModify", ".plugin", in_sign='sa{ss}b',
|
||||
host.bridge.add_method("invitation_modify", ".plugin", in_sign='sa{ss}b',
|
||||
out_sign='',
|
||||
method=self._modify,
|
||||
async_=True)
|
||||
host.bridge.addMethod("invitationList", ".plugin", in_sign='s',
|
||||
host.bridge.add_method("invitation_list", ".plugin", in_sign='s',
|
||||
out_sign='a{sa{ss}}',
|
||||
method=self._list,
|
||||
async_=True)
|
||||
host.bridge.addMethod("invitationSimpleCreate", ".plugin", in_sign='sssss',
|
||||
host.bridge.add_method("invitation_simple_create", ".plugin", in_sign='sssss',
|
||||
out_sign='a{ss}',
|
||||
method=self._simpleCreate,
|
||||
method=self._simple_create,
|
||||
async_=True)
|
||||
|
||||
def checkExtra(self, extra):
|
||||
def check_extra(self, extra):
|
||||
if EXTRA_RESERVED.intersection(extra):
|
||||
raise ValueError(
|
||||
_("You can't use following key(s) in extra, they are reserved: {}")
|
||||
|
|
@ -132,7 +132,7 @@ class InvitationsPlugin(object):
|
|||
kwargs[key] = str(value)
|
||||
return defer.ensureDeferred(self.create(**kwargs))
|
||||
|
||||
async def getExistingInvitation(self, email: Optional[str]) -> Optional[dict]:
|
||||
async def get_existing_invitation(self, email: Optional[str]) -> Optional[dict]:
|
||||
"""Retrieve existing invitation with given email
|
||||
|
||||
@param email: check if any invitation exist with this email
|
||||
|
|
@ -151,7 +151,7 @@ class InvitationsPlugin(object):
|
|||
invitation[KEY_ID] = id_
|
||||
return invitation
|
||||
|
||||
async def _createAccountAndProfile(
|
||||
async def _create_account_and_profile(
|
||||
self,
|
||||
id_: str,
|
||||
kwargs: dict,
|
||||
|
|
@ -161,7 +161,7 @@ class InvitationsPlugin(object):
|
|||
## XMPP account creation
|
||||
password = kwargs.pop('password', None)
|
||||
if password is None:
|
||||
password = utils.generatePassword()
|
||||
password = utils.generate_password()
|
||||
assert password
|
||||
# XXX: password is here saved in clear in database
|
||||
# it is needed for invitation as the same password is used for profile
|
||||
|
|
@ -173,7 +173,7 @@ class InvitationsPlugin(object):
|
|||
|
||||
jid_ = kwargs.pop('jid_', None)
|
||||
if not jid_:
|
||||
domain = self.host.memory.getConfig(None, 'xmpp_domain')
|
||||
domain = self.host.memory.config_get(None, 'xmpp_domain')
|
||||
if not domain:
|
||||
# TODO: fallback to profile's domain
|
||||
raise ValueError(_("You need to specify xmpp_domain in sat.conf"))
|
||||
|
|
@ -186,7 +186,7 @@ class InvitationsPlugin(object):
|
|||
# we don't register account if there is no user as anonymous login is then
|
||||
# used
|
||||
try:
|
||||
await self.host.plugins['XEP-0077'].registerNewAccount(jid_, password)
|
||||
await self.host.plugins['XEP-0077'].register_new_account(jid_, password)
|
||||
except error.StanzaError as e:
|
||||
prefix = jid_.user
|
||||
idx = 0
|
||||
|
|
@ -197,7 +197,7 @@ class InvitationsPlugin(object):
|
|||
log.info(_("requested jid already exists, trying with {}".format(
|
||||
jid_.full())))
|
||||
try:
|
||||
await self.host.plugins['XEP-0077'].registerNewAccount(
|
||||
await self.host.plugins['XEP-0077'].register_new_account(
|
||||
jid_,
|
||||
password
|
||||
)
|
||||
|
|
@ -216,11 +216,11 @@ class InvitationsPlugin(object):
|
|||
uuid=id_
|
||||
)
|
||||
# profile creation should not fail as we generate unique name ourselves
|
||||
await self.host.memory.createProfile(guest_profile, password)
|
||||
await self.host.memory.startSession(password, guest_profile)
|
||||
await self.host.memory.setParam("JabberID", jid_.full(), "Connection",
|
||||
await self.host.memory.create_profile(guest_profile, password)
|
||||
await self.host.memory.start_session(password, guest_profile)
|
||||
await self.host.memory.param_set("JabberID", jid_.full(), "Connection",
|
||||
profile_key=guest_profile)
|
||||
await self.host.memory.setParam("Password", password, "Connection",
|
||||
await self.host.memory.param_set("Password", password, "Connection",
|
||||
profile_key=guest_profile)
|
||||
|
||||
async def create(self, **kwargs):
|
||||
|
|
@ -290,11 +290,11 @@ class InvitationsPlugin(object):
|
|||
_("You can't use following key(s) in both args and extra: {}").format(
|
||||
', '.join(set(kwargs).intersection(extra))))
|
||||
|
||||
self.checkExtra(extra)
|
||||
self.check_extra(extra)
|
||||
|
||||
email = kwargs.pop('email', None)
|
||||
|
||||
existing = await self.getExistingInvitation(email)
|
||||
existing = await self.get_existing_invitation(email)
|
||||
if existing is not None:
|
||||
log.info(f"There is already an invitation for {email!r}")
|
||||
extra.update(existing)
|
||||
|
|
@ -316,7 +316,7 @@ class InvitationsPlugin(object):
|
|||
id_ = existing[KEY_ID] if existing else str(shortuuid.uuid())
|
||||
|
||||
if existing is None:
|
||||
await self._createAccountAndProfile(id_, kwargs, extra)
|
||||
await self._create_account_and_profile(id_, kwargs, extra)
|
||||
|
||||
profile = kwargs.pop('profile', None)
|
||||
guest_profile = extra[KEY_GUEST_PROFILE]
|
||||
|
|
@ -333,8 +333,8 @@ class InvitationsPlugin(object):
|
|||
pass
|
||||
else:
|
||||
await self.host.connect(guest_profile, password)
|
||||
guest_client = self.host.getClient(guest_profile)
|
||||
await id_plugin.setIdentity(guest_client, {'nicknames': [name]})
|
||||
guest_client = self.host.get_client(guest_profile)
|
||||
await id_plugin.set_identity(guest_client, {'nicknames': [name]})
|
||||
await self.host.disconnect(guest_profile)
|
||||
|
||||
## email
|
||||
|
|
@ -370,7 +370,7 @@ class InvitationsPlugin(object):
|
|||
invite_url = url_template.format(**format_args)
|
||||
format_args['url'] = invite_url
|
||||
|
||||
await sat_email.sendEmail(
|
||||
await sat_email.send_email(
|
||||
self.host.memory.config,
|
||||
[email] + emails_extra,
|
||||
(kwargs.pop('message_subject', None) or DEFAULT_SUBJECT).format(
|
||||
|
|
@ -384,11 +384,11 @@ class InvitationsPlugin(object):
|
|||
# FIXME: a parameter to disable auto roster adding would be nice
|
||||
if profile is not None:
|
||||
try:
|
||||
client = self.host.getClient(profile)
|
||||
client = self.host.get_client(profile)
|
||||
except Exception as e:
|
||||
log.error(f"Can't get host profile: {profile}: {e}")
|
||||
else:
|
||||
await self.host.updateContact(client, jid_, name, ['guests'])
|
||||
await self.host.contact_update(client, jid_, name, ['guests'])
|
||||
|
||||
if kwargs:
|
||||
log.warning(_("Not all arguments have been consumed: {}").format(kwargs))
|
||||
|
|
@ -400,20 +400,20 @@ class InvitationsPlugin(object):
|
|||
|
||||
return extra
|
||||
|
||||
def _simpleCreate(self, invitee_email, invitee_name, url_template, extra_s, profile):
|
||||
client = self.host.getClient(profile)
|
||||
def _simple_create(self, invitee_email, invitee_name, url_template, extra_s, profile):
|
||||
client = self.host.get_client(profile)
|
||||
# FIXME: needed because python-dbus use a specific string class
|
||||
invitee_email = str(invitee_email)
|
||||
invitee_name = str(invitee_name)
|
||||
url_template = str(url_template)
|
||||
extra = data_format.deserialise(extra_s)
|
||||
d = defer.ensureDeferred(
|
||||
self.simpleCreate(client, invitee_email, invitee_name, url_template, extra)
|
||||
self.simple_create(client, invitee_email, invitee_name, url_template, extra)
|
||||
)
|
||||
d.addCallback(lambda data: {k: str(v) for k,v in data.items()})
|
||||
return d
|
||||
|
||||
async def simpleCreate(
|
||||
async def simple_create(
|
||||
self, client, invitee_email, invitee_name, url_template, extra):
|
||||
"""Simplified method to invite somebody by email"""
|
||||
return await self.create(
|
||||
|
|
@ -443,7 +443,7 @@ class InvitationsPlugin(object):
|
|||
password = data['password']
|
||||
try:
|
||||
await self.host.connect(guest_profile, password)
|
||||
guest_client = self.host.getClient(guest_profile)
|
||||
guest_client = self.host.get_client(guest_profile)
|
||||
# XXX: be extra careful to use guest_client and not client below, as this will
|
||||
# delete the associated XMPP account
|
||||
log.debug("deleting XMPP account")
|
||||
|
|
@ -453,7 +453,7 @@ class InvitationsPlugin(object):
|
|||
f"Can't delete {guest_profile}'s XMPP account, maybe it as already been "
|
||||
f"deleted: {e}")
|
||||
try:
|
||||
await self.host.memory.asyncDeleteProfile(guest_profile, True)
|
||||
await self.host.memory.profile_delete_async(guest_profile, True)
|
||||
except Exception as e:
|
||||
log.warning(f"Can't delete guest profile {guest_profile}: {e}")
|
||||
log.debug("removing guest data")
|
||||
|
|
@ -474,8 +474,8 @@ class InvitationsPlugin(object):
|
|||
else update them
|
||||
@raise KeyError: there is not invitation with this id_
|
||||
"""
|
||||
self.checkExtra(new_extra)
|
||||
def gotCurrentData(current_data):
|
||||
self.check_extra(new_extra)
|
||||
def got_current_data(current_data):
|
||||
if replace:
|
||||
new_data = new_extra
|
||||
for k in EXTRA_RESERVED:
|
||||
|
|
@ -500,7 +500,7 @@ class InvitationsPlugin(object):
|
|||
self.invitations[id_] = new_data
|
||||
|
||||
d = self.invitations[id_]
|
||||
d.addCallback(gotCurrentData)
|
||||
d.addCallback(got_current_data)
|
||||
return d
|
||||
|
||||
def _list(self, profile=C.PROF_KEY_NONE):
|
||||
|
|
|
|||
Loading…
Reference in a new issue