Skip to content

Commit

Permalink
Merge pull request #3 from meerk40t/poboy-update
Browse files Browse the repository at this point in the history
Black + Isort: Subdivide Parts
  • Loading branch information
tatarize authored Apr 21, 2023
2 parents 8ef4b74 + bc0c4bf commit bf59dd5
Show file tree
Hide file tree
Showing 16 changed files with 2,114 additions and 2,073 deletions.
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from setuptools import setup

setup(
install_requires=[
"wxPython",
Expand Down
31 changes: 18 additions & 13 deletions src/babelmsg/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,21 @@
"""

import re

from cgi import parse_header
from collections import OrderedDict
from datetime import datetime, time as time_, timezone
from copy import copy
from datetime import datetime
from datetime import time as time_
from datetime import timezone
from difflib import get_close_matches
from email import message_from_string
from copy import copy

from .core import Locale, UnknownLocaleError
from .plurals import get_plural

__all__ = ["Message", "Catalog", "TranslationError"]

from .util import distinct, _cmp
from .util import _cmp, distinct

PYTHON_FORMAT = re.compile(
r"""
Expand All @@ -46,7 +47,7 @@ class Message(object):
def __init__(
self,
id,
string=u"",
string="",
locations=(),
flags=(),
auto_comments=(),
Expand Down Expand Up @@ -79,7 +80,7 @@ def __init__(
"""
self._id = id
if not string and self.pluralizable:
string = (u"", u"")
string = ("", "")
self._string = string
self.locations = list(distinct(locations))
self.flags = set(flags)
Expand Down Expand Up @@ -250,7 +251,7 @@ class TranslationError(Exception):
translations are encountered."""


DEFAULT_HEADER = u"""\
DEFAULT_HEADER = """\
# Translations template for PROJECT.
# Copyright (C) YEAR ORGANIZATION
# This file is distributed under the same license as the PROJECT project.
Expand Down Expand Up @@ -327,7 +328,7 @@ def __init__(
self.modified = False
self.filename = filename

self.new = OrderedDict() # Dictionary of new messages from template
self.new = OrderedDict() # Dictionary of new messages from template
self.orphans = OrderedDict() # Dictionary of orphaned events from messages
self.obsolete = OrderedDict() # Dictionary of obsolete messages

Expand Down Expand Up @@ -504,7 +505,7 @@ def _set_mime_headers(self, headers):
value = self._force_text(value, encoding=self.charset)
if name == "project-id-version":
parts = value.split(" ")
self.project = u" ".join(parts[:-1])
self.project = " ".join(parts[:-1])
self.version = parts[-1]
elif name == "report-msgid-bugs-to":
self.msgid_bugs_address = value
Expand Down Expand Up @@ -654,7 +655,9 @@ def __iter__(self):
flags = set()
if self.fuzzy:
flags |= {"fuzzy"}
yield Message(u"", "\n".join(buf), flags=flags, original_lines=self.original_header)
yield Message(
"", "\n".join(buf), flags=flags, original_lines=self.original_header
)
for key in self._messages:
yield self._messages[key]

Expand Down Expand Up @@ -923,7 +926,7 @@ def _merge(message, oldkey, newkey, fuzzy=False):
if not isinstance(message.string, (list, tuple)):
fuzzy = True
message.string = tuple(
[message.string] + ([u""] * (len(message.id) - 1))
[message.string] + ([""] * (len(message.id) - 1))
)
elif len(message.string) != self.num_plurals:
fuzzy = True
Expand All @@ -949,7 +952,10 @@ def _merge(message, oldkey, newkey, fuzzy=False):
else:
matchkey = key
matches = get_close_matches(
matchkey.lower().strip(), fuzzy_candidates.keys(), 1, cutoff=.85
matchkey.lower().strip(),
fuzzy_candidates.keys(),
1,
cutoff=0.85,
)
if matches:
newkey = matches[0]
Expand All @@ -967,7 +973,6 @@ def _merge(message, oldkey, newkey, fuzzy=False):
self.obsolete[msgid] = message
message.modified = True


if update_header_comment:
# Allow the updated catalog's header to be rewritten based on the
# template's header
Expand Down
3 changes: 1 addition & 2 deletions src/babelmsg/checkers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
:license: BSD, see LICENSE for more details.
"""

from .catalog import TranslationError, PYTHON_FORMAT

from .catalog import PYTHON_FORMAT, TranslationError

#: list of format chars that are compatible to each other
_string_format_compatibilities = [{"i", "d", "u"}, {"x", "X"}, {"f", "F", "g", "G"}]
Expand Down
3 changes: 1 addition & 2 deletions src/babelmsg/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import os


__all__ = [
"UnknownLocaleError",
"Locale",
Expand Down Expand Up @@ -367,7 +366,7 @@ def get_display_name(self, locale=None):
details.append(locale.variants.get(self.variant))
details = filter(None, details)
if details:
retval += " (%s)" % u", ".join(details)
retval += " (%s)" % ", ".join(details)
return retval

display_name = property(
Expand Down
30 changes: 14 additions & 16 deletions src/babelmsg/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@
"""

import os
from os.path import relpath
import sys
from tokenize import generate_tokens, COMMENT, NAME, OP, STRING

from .util import parse_encoding, parse_future_flags, pathmatch
from os.path import relpath
from textwrap import dedent
from tokenize import COMMENT, NAME, OP, STRING, generate_tokens

from .util import parse_encoding, parse_future_flags, pathmatch

GROUP_NAME = "babel.extractors"

Expand Down Expand Up @@ -143,13 +142,13 @@ def extract_from_dir(
if options_map is None:
options_map = {}

directories = [ os.path.join(dirname,item) for item in os.listdir(dirname)]
directories = [ item for item in directories if os.path.isdir(item)]
directories = [os.path.join(dirname, item) for item in os.listdir(dirname)]
directories = [item for item in directories if os.path.isdir(item)]

for directory in directories:
items = list(os.listdir(directory))
if "__init__.py" not in items:
continue # This is not a package.
continue # This is not a package.
items = [os.path.join(directory, item) for item in items]
for item in items:
if os.path.isdir(item):
Expand All @@ -158,19 +157,18 @@ def extract_from_dir(
if not os.path.basename(item).endswith(".py"):
continue
for message_tuple in check_and_call_extract_file(
item,
method_map,
options_map,
callback,
keywords,
comment_tags,
strip_comment_tags,
dirpath=dirname,
item,
method_map,
options_map,
callback,
keywords,
comment_tags,
strip_comment_tags,
dirpath=dirname,
):
yield message_tuple



def check_and_call_extract_file(
filepath,
method_map,
Expand Down
9 changes: 5 additions & 4 deletions src/babelmsg/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@
from collections import OrderedDict
from configparser import RawConfigParser
from datetime import datetime
from distutils import log as distutils_log
from distutils.cmd import Command as _Command
from distutils.errors import DistutilsOptionError, DistutilsSetupError
from io import StringIO
from locale import getpreferredencoding

from src.babelmsg.core import Locale, UnknownLocaleError

from .catalog import Catalog
from .extract import (
DEFAULT_KEYWORDS,
Expand All @@ -33,9 +37,6 @@
)
from .mofile import write_mo
from .pofile import read_po, write_po
from distutils import log as distutils_log
from distutils.cmd import Command as _Command
from distutils.errors import DistutilsOptionError, DistutilsSetupError


def listify_value(arg, split=None):
Expand Down Expand Up @@ -953,7 +954,7 @@ def run(self, argv=None):
identifiers = localedata.locale_identifiers()
longest = max([len(identifier) for identifier in identifiers])
identifiers.sort()
format = u"%%-%ds %%s" % (longest + 1)
format = "%%-%ds %%s" % (longest + 1)
for identifier in identifiers:
locale = Locale.parse(identifier)
output = format % (identifier, locale.english_name)
Expand Down
4 changes: 2 additions & 2 deletions src/babelmsg/jslexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
:copyright: (c) 2013-2021 by the Babel Team.
:license: BSD, see LICENSE for more details.
"""
from collections import namedtuple
import re
from collections import namedtuple

operators = sorted(
[
Expand Down Expand Up @@ -195,7 +195,7 @@ def unquote_string(string):
if pos < len(string):
add(string[pos:])

return u"".join(result)
return "".join(result)


def tokenize(source, jsx=True, dotted=True, template_string=True):
Expand Down
1 change: 0 additions & 1 deletion src/babelmsg/mofile.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

from .catalog import Catalog, Message


LE_MAGIC = 0x950412DE
BE_MAGIC = 0xDE120495

Expand Down
2 changes: 1 addition & 1 deletion src/babelmsg/plurals.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ def get_plural(locale):
>>> str(tup)
'nplurals=1; plural=0;'
"""
locale =str(locale)
locale = str(locale)
try:
tup = PLURALS[str(locale)]
except KeyError:
Expand Down
Loading

0 comments on commit bf59dd5

Please sign in to comment.