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:
Goffi 2023-04-08 13:54:42 +02:00
commit 6a6f15707a

View file

@ -61,7 +61,7 @@ class BlogImportPlugin(object):
OPT_DEFAULTS = {OPT_UPLOAD_IMAGES: True, OPT_IGNORE_TLS: False}
def __init__(self, host):
log.info(_("plugin Blog Import initialization"))
log.info(_("plugin Blog import initialization"))
self.host = host
self._u = host.plugins["UPLOAD"]
self._p = host.plugins["XEP-0060"]
@ -69,10 +69,10 @@ class BlogImportPlugin(object):
self._s = self.host.plugins["TEXT_SYNTAXES"]
host.plugins["IMPORT"].initialize(self, "blog")
def importItem(
def import_item(
self, client, item_import_data, session, options, return_data, service, node
):
"""importItem specialized for blog import
"""import_item specialized for blog import
@param item_import_data(dict):
* mandatory keys:
@ -116,7 +116,7 @@ class BlogImportPlugin(object):
except KeyError:
pass
else:
new_uri = return_data[URL_REDIRECT_PREFIX + old_uri] = self._p.getNodeURI(
new_uri = return_data[URL_REDIRECT_PREFIX + old_uri] = self._p.get_node_uri(
service if service is not None else client.jid.userhostJID(),
node or self._m.namespace,
item_id,
@ -126,14 +126,14 @@ class BlogImportPlugin(object):
return mb_data
@defer.inlineCallbacks
def importSubItems(self, client, item_import_data, mb_data, session, options):
def import_sub_items(self, client, item_import_data, mb_data, session, options):
# comments data
if len(item_import_data["comments"]) != 1:
raise NotImplementedError("can't manage multiple comment links")
allow_comments = C.bool(mb_data.get("allow_comments", C.BOOL_FALSE))
if allow_comments:
comments_service = yield self._m.getCommentsService(client)
comments_node = self._m.getCommentsNode(mb_data["id"])
comments_service = yield self._m.get_comments_service(client)
comments_node = self._m.get_comments_node(mb_data["id"])
mb_data["comments_service"] = comments_service.full()
mb_data["comments_node"] = comments_node
recurse_kwargs = {
@ -149,7 +149,7 @@ class BlogImportPlugin(object):
)
defer.returnValue(None)
def publishItem(self, client, mb_data, service, node, session):
def publish_item(self, client, mb_data, service, node, session):
log.debug(
"uploading item [{id}]: {title}".format(
id=mb_data["id"], title=mb_data.get("title", "")
@ -158,7 +158,7 @@ class BlogImportPlugin(object):
return self._m.send(client, mb_data, service, node)
@defer.inlineCallbacks
def itemFilters(self, client, mb_data, session, options):
def item_filters(self, client, mb_data, session, options):
"""Apply filters according to options
modify mb_data in place
@ -188,7 +188,7 @@ class BlogImportPlugin(object):
)
# we convert rich syntax to XHTML here, so we can handle filters easily
converted = yield self._s.convert(
rich, self._s.getCurrentSyntax(client.profile), safe=False
rich, self._s.get_current_syntax(client.profile), safe=False
)
mb_data["{}_xhtml".format(prefix)] = converted
del mb_data["{}_rich".format(prefix)]
@ -220,7 +220,7 @@ class BlogImportPlugin(object):
)
except domish.ParserError:
# we clean the xml and try again our luck
cleaned = yield self._s.cleanXHTML(mb_data["content_xhtml"])
cleaned = yield self._s.clean_xhtml(mb_data["content_xhtml"])
top_elt = xml_tools.ElementParser()(cleaned, namespace=C.NS_XHTML)
opt_host = options.get(OPT_HOST)
if opt_host:
@ -239,8 +239,8 @@ class BlogImportPlugin(object):
tmp_dir = tempfile.mkdtemp()
try:
# TODO: would be nice to also update the hyperlinks to these images, e.g. when you have <a href="{url}"><img src="{url}"></a>
for img_elt in xml_tools.findAll(top_elt, names=["img"]):
yield self.imgFilters(client, img_elt, options, opt_host, tmp_dir)
for img_elt in xml_tools.find_all(top_elt, names=["img"]):
yield self.img_filters(client, img_elt, options, opt_host, tmp_dir)
finally:
os.rmdir(tmp_dir) # XXX: tmp_dir should be empty, or something went wrong
@ -248,7 +248,7 @@ class BlogImportPlugin(object):
mb_data["content_xhtml"] = top_elt.toXml()
@defer.inlineCallbacks
def imgFilters(self, client, img_elt, options, opt_host, tmp_dir):
def img_filters(self, client, img_elt, options, opt_host, tmp_dir):
"""Filters handling images
url without host are fixed (if possible)