summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAarni Koskela <akx@iki.fi>2023-01-11 12:49:43 +0200
committerAarni Koskela <akx@iki.fi>2023-01-18 21:07:51 +0200
commit3fc318e6faf656c8da567281b3c5d3042e3ca010 (patch)
tree7a115a228deefa6c580eb3860e48995976338b20
parent6e02940868a73cbcf3cc86077fc83c7cb21a4780 (diff)
downloadbabel-3fc318e6faf656c8da567281b3c5d3042e3ca010.tar.gz
Ensure `path` is correctly bound for extract callback (flake8 B023)
-rw-r--r--babel/messages/frontend.py41
1 files changed, 22 insertions, 19 deletions
diff --git a/babel/messages/frontend.py b/babel/messages/frontend.py
index c7e921d..a18d00d 100644
--- a/babel/messages/frontend.py
+++ b/babel/messages/frontend.py
@@ -472,6 +472,27 @@ class extract_messages(Command):
else:
self.directory_filter = None
+ def _build_callback(self, path: str):
+ def callback(filename: str, method: str, options: dict):
+ if method == 'ignore':
+ return
+
+ # If we explicitly provide a full filepath, just use that.
+ # Otherwise, path will be the directory path and filename
+ # is the relative path from that dir to the file.
+ # So we can join those to get the full filepath.
+ if os.path.isfile(path):
+ filepath = path
+ else:
+ filepath = os.path.normpath(os.path.join(path, filename))
+
+ optstr = ''
+ if options:
+ opt_values = ", ".join(f'{k}="{v}"' for k, v in options.items())
+ optstr = f" ({opt_values})"
+ self.log.info('extracting messages from %s%s', filepath, optstr)
+ return callback
+
def run(self):
mappings = self._get_mappings()
with open(self.output_file, 'wb') as outfile:
@@ -483,25 +504,7 @@ class extract_messages(Command):
header_comment=(self.header_comment or DEFAULT_HEADER))
for path, method_map, options_map in mappings:
- def callback(filename, method, options):
- if method == 'ignore':
- return
-
- # If we explicitly provide a full filepath, just use that.
- # Otherwise, path will be the directory path and filename
- # is the relative path from that dir to the file.
- # So we can join those to get the full filepath.
- if os.path.isfile(path):
- filepath = path
- else:
- filepath = os.path.normpath(os.path.join(path, filename))
-
- optstr = ''
- if options:
- opt_values = ", ".join(f'{k}="{v}"' for k, v in options.items())
- optstr = f" ({opt_values})"
- self.log.info('extracting messages from %s%s', filepath, optstr)
-
+ callback = self._build_callback(path)
if os.path.isfile(path):
current_dir = os.getcwd()
extracted = check_and_call_extract_file(