Mercurial > libervia-backend
comparison sat/plugins/plugin_exp_lang_detect.py @ 4037:524856bd7b19
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.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 08 Apr 2023 13:54:42 +0200 |
parents | cdb7de398c85 |
children | c23cad65ae99 |
comparison
equal
deleted
inserted
replaced
4036:c4464d7ae97b | 4037:524856bd7b19 |
---|---|
63 | 63 |
64 class LangDetect(object): | 64 class LangDetect(object): |
65 def __init__(self, host): | 65 def __init__(self, host): |
66 log.info(_("Language detection plugin initialization")) | 66 log.info(_("Language detection plugin initialization")) |
67 self.host = host | 67 self.host = host |
68 host.memory.updateParams(PARAMS) | 68 host.memory.update_params(PARAMS) |
69 host.trigger.add("messageReceived", self.messageReceivedTrigger) | 69 host.trigger.add("messageReceived", self.message_received_trigger) |
70 host.trigger.add("sendMessage", self.MessageSendTrigger) | 70 host.trigger.add("sendMessage", self.message_send_trigger) |
71 | 71 |
72 def add_language(self, mess_data): | 72 def add_language(self, mess_data): |
73 message = mess_data["message"] | 73 message = mess_data["message"] |
74 if len(message) == 1 and list(message.keys())[0] == "": | 74 if len(message) == 1 and list(message.keys())[0] == "": |
75 msg = list(message.values())[0].strip() | 75 msg = list(message.values())[0].strip() |
76 if msg: | 76 if msg: |
77 lang = identifier.classify(msg)[0] | 77 lang = identifier.classify(msg)[0] |
78 mess_data["message"] = {lang: msg} | 78 mess_data["message"] = {lang: msg} |
79 return mess_data | 79 return mess_data |
80 | 80 |
81 def messageReceivedTrigger(self, client, message_elt, post_treat): | 81 def message_received_trigger(self, client, message_elt, post_treat): |
82 """ Check if source is linked and repeat message, else do nothing """ | 82 """ Check if source is linked and repeat message, else do nothing """ |
83 | 83 |
84 lang_detect = self.host.memory.getParamA( | 84 lang_detect = self.host.memory.param_get_a( |
85 NAME, CATEGORY, profile_key=client.profile | 85 NAME, CATEGORY, profile_key=client.profile |
86 ) | 86 ) |
87 if lang_detect: | 87 if lang_detect: |
88 post_treat.addCallback(self.add_language) | 88 post_treat.addCallback(self.add_language) |
89 return True | 89 return True |
90 | 90 |
91 def MessageSendTrigger(self, client, data, pre_xml_treatments, post_xml_treatments): | 91 def message_send_trigger(self, client, data, pre_xml_treatments, post_xml_treatments): |
92 lang_detect = self.host.memory.getParamA( | 92 lang_detect = self.host.memory.param_get_a( |
93 NAME, CATEGORY, profile_key=client.profile | 93 NAME, CATEGORY, profile_key=client.profile |
94 ) | 94 ) |
95 if lang_detect: | 95 if lang_detect: |
96 self.add_language(data) | 96 self.add_language(data) |
97 return True | 97 return True |