mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-01-22 10:53:03 -08:00
4468c3e4af
* Bump mako from 1.2.4 to 1.3.2 Bumps [mako](https://github.com/sqlalchemy/mako) from 1.2.4 to 1.3.2. - [Release notes](https://github.com/sqlalchemy/mako/releases) - [Changelog](https://github.com/sqlalchemy/mako/blob/main/CHANGES) - [Commits](https://github.com/sqlalchemy/mako/commits) --- updated-dependencies: - dependency-name: mako dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * Update mako==1.3.2 --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: JonnyWong16 <9099342+JonnyWong16@users.noreply.github.com> [skip ci]
58 lines
1.9 KiB
Python
58 lines
1.9 KiB
Python
# ext/linguaplugin.py
|
|
# Copyright 2006-2024 the Mako authors and contributors <see AUTHORS file>
|
|
#
|
|
# This module is part of Mako and is released under
|
|
# the MIT License: http://www.opensource.org/licenses/mit-license.php
|
|
|
|
import contextlib
|
|
import io
|
|
|
|
from lingua.extractors import Extractor
|
|
from lingua.extractors import get_extractor
|
|
from lingua.extractors import Message
|
|
|
|
from mako.ext.extract import MessageExtractor
|
|
|
|
|
|
class LinguaMakoExtractor(Extractor, MessageExtractor):
|
|
"""Mako templates"""
|
|
|
|
use_bytes = False
|
|
extensions = [".mako"]
|
|
default_config = {"encoding": "utf-8", "comment-tags": ""}
|
|
|
|
def __call__(self, filename, options, fileobj=None):
|
|
self.options = options
|
|
self.filename = filename
|
|
self.python_extractor = get_extractor("x.py")
|
|
if fileobj is None:
|
|
ctx = open(filename, "r")
|
|
else:
|
|
ctx = contextlib.nullcontext(fileobj)
|
|
with ctx as file_:
|
|
yield from self.process_file(file_)
|
|
|
|
def process_python(self, code, code_lineno, translator_strings):
|
|
source = code.getvalue().strip()
|
|
if source.endswith(":"):
|
|
if source in ("try:", "else:") or source.startswith("except"):
|
|
source = "" # Ignore try/except and else
|
|
elif source.startswith("elif"):
|
|
source = source[2:] # Replace "elif" with "if"
|
|
source += "pass"
|
|
code = io.StringIO(source)
|
|
for msg in self.python_extractor(
|
|
self.filename, self.options, code, code_lineno - 1
|
|
):
|
|
if translator_strings:
|
|
msg = Message(
|
|
msg.msgctxt,
|
|
msg.msgid,
|
|
msg.msgid_plural,
|
|
msg.flags,
|
|
" ".join(translator_strings + [msg.comment]),
|
|
msg.tcomment,
|
|
msg.location,
|
|
)
|
|
yield msg
|