Mercurial > libervia-backend
comparison sat/tools/utils.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 | 5a42c7842556 |
children |
comparison
equal
deleted
inserted
replaced
4036:c4464d7ae97b | 4037:524856bd7b19 |
---|---|
65 raise failure_ | 65 raise failure_ |
66 | 66 |
67 | 67 |
68 def partial(func, *fixed_args, **fixed_kwargs): | 68 def partial(func, *fixed_args, **fixed_kwargs): |
69 # FIXME: temporary hack to workaround the fact that inspect.getargspec is not working with functools.partial | 69 # FIXME: temporary hack to workaround the fact that inspect.getargspec is not working with functools.partial |
70 # making partial unusable with current D-bus module (in addMethod). | 70 # making partial unusable with current D-bus module (in add_method). |
71 # Should not be needed anywore once moved to Python 3 | 71 # Should not be needed anywore once moved to Python 3 |
72 | 72 |
73 ori_args = inspect.getargspec(func).args | 73 ori_args = inspect.getargspec(func).args |
74 func = functools.partial(func, *fixed_args, **fixed_kwargs) | 74 func = functools.partial(func, *fixed_args, **fixed_kwargs) |
75 if ori_args[0] == "self": | 75 if ori_args[0] == "self": |
91 ) | 91 ) |
92 | 92 |
93 return method | 93 return method |
94 | 94 |
95 | 95 |
96 def asDeferred(func, *args, **kwargs): | 96 def as_deferred(func, *args, **kwargs): |
97 """Call a method and return a Deferred | 97 """Call a method and return a Deferred |
98 | 98 |
99 the method can be a simple callable, a Deferred or a coroutine. | 99 the method can be a simple callable, a Deferred or a coroutine. |
100 It is similar to defer.maybeDeferred, but also handles coroutines | 100 It is similar to defer.maybeDeferred, but also handles coroutines |
101 """ | 101 """ |
182 dt = datetime.datetime.combine(d, datetime.datetime.min.time()) | 182 dt = datetime.datetime.combine(d, datetime.datetime.min.time()) |
183 | 183 |
184 return dt.timestamp() | 184 return dt.timestamp() |
185 | 185 |
186 | 186 |
187 def generatePassword(vocabulary=None, size=20): | 187 def generate_password(vocabulary=None, size=20): |
188 """Generate a password with random characters. | 188 """Generate a password with random characters. |
189 | 189 |
190 @param vocabulary(iterable): characters to use to create password | 190 @param vocabulary(iterable): characters to use to create password |
191 @param size(int): number of characters in the password to generate | 191 @param size(int): number of characters in the password to generate |
192 @return (unicode): generated password | 192 @return (unicode): generated password |
197 chr(i) for i in list(range(0x30, 0x3A)) + list(range(0x41, 0x5B)) + list(range(0x61, 0x7B)) | 197 chr(i) for i in list(range(0x30, 0x3A)) + list(range(0x41, 0x5B)) + list(range(0x61, 0x7B)) |
198 ] | 198 ] |
199 return "".join([random.choice(vocabulary) for i in range(15)]) | 199 return "".join([random.choice(vocabulary) for i in range(15)]) |
200 | 200 |
201 | 201 |
202 def getRepositoryData(module, as_string=True, is_path=False): | 202 def get_repository_data(module, as_string=True, is_path=False): |
203 """Retrieve info on current mecurial repository | 203 """Retrieve info on current mecurial repository |
204 | 204 |
205 Data is gotten by using the following methods, in order: | 205 Data is gotten by using the following methods, in order: |
206 - using "hg" executable | 206 - using "hg" executable |
207 - looking for a .hg/dirstate in parent directory of module (or in module/.hg if | 207 - looking for a .hg/dirstate in parent directory of module (or in module/.hg if |