Skip to content

Commit

Permalink
remove some dead codes
Browse files Browse the repository at this point in the history
  • Loading branch information
ilius committed Feb 23, 2024
1 parent 52a0517 commit f4d1e85
Show file tree
Hide file tree
Showing 14 changed files with 144 additions and 244 deletions.
31 changes: 0 additions & 31 deletions pyglossary/gregorian.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,37 +29,6 @@
name = "gregorian"
desc = "Gregorian"

monthName = (
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December",
)

monthNameAb = (
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec",
)


epoch = 1721426

options = ()
Expand Down
4 changes: 2 additions & 2 deletions pyglossary/json_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


def dataToPrettyJson(
data: "JsonEncodable",
data: JsonEncodable,
ensure_ascii: bool = False,
sort_keys: bool = False,
) -> str:
Expand All @@ -24,7 +24,7 @@ def dataToPrettyJson(
)


def jsonToData(st: "AnyStr") -> "JsonEncodable":
def jsonToData(st: "AnyStr") -> JsonEncodable:
return json.loads(st)


Expand Down
11 changes: 0 additions & 11 deletions pyglossary/plugins/appledict_bin/appledict_file_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,6 @@
APPLEDICT_FILE_OFFSET = 0x40
# addressing of AppleDict binary files always ignores first 0x40 bytes


def readIntAt(buffer: "io.BufferedIOBase", address: int) -> int:
buffer.seek(address)
return unpack("i", buffer.read(4))[0]


def readIntPair(buffer: "io.BufferedIOBase") -> "tuple[int, int]":
# to satisfy mymy, put them in vars with declared type
a: int
Expand All @@ -54,11 +48,6 @@ def read_x_bytes_as_word(buffer: "io.BufferedIOBase", x: int) -> str:
return buffer.read(x).decode("UTF-16LE")


def read_2_bytes(buffer: "io.BufferedIOBase", address: int) -> int:
buffer.seek(address)
return read_2_bytes_here(buffer)


def read_2_bytes_here(buffer: "io.BufferedIOBase") -> int:
lower_byte = buffer.read(1)
higher_byte = buffer.read(1)
Expand Down
36 changes: 18 additions & 18 deletions pyglossary/plugins/appledict_bin/key_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,24 @@ class KeyData:
This class contains texts by which entry is searchable and other properties.
"""

keyword_data_id_xml = {
"DCSKeyword": "d:value",
# Search key -- if entered in search, this key will provide this definition.
"DCSHeadword": "d:title",
# Headword text that is displayed on the search result list.
# When the value is the same as d:value, it can be omitted.
# In that case, the value of the d:value is used also for the d:title.
"DCSAnchor": "d:anchor",
# Used to highlight a specific part in an entry.
# For example, it is used to highlight an idiomatic phrase explanation
# in an entry for a word.
"DCSYomiWord": "d:yomi",
# Used only in making Japanese dictionaries.
"DCSSortKey": "d:DCSSortKey",
# This value shows sorting (probably for non-english languages)
"DCSEntryTitle": "d:DCSEntryTitle",
# Headword displayed as article title
}
# keyword_data_id_xml = {
# "DCSKeyword": "d:value",
# # Search key -- if entered in search, this key will provide this definition.
# "DCSHeadword": "d:title",
# # Headword text that is displayed on the search result list.
# # When the value is the same as d:value, it can be omitted.
# # In that case, the value of the d:value is used also for the d:title.
# "DCSAnchor": "d:anchor",
# # Used to highlight a specific part in an entry.
# # For example, it is used to highlight an idiomatic phrase explanation
# # in an entry for a word.
# "DCSYomiWord": "d:yomi",
# # Used only in making Japanese dictionaries.
# "DCSSortKey": "d:DCSSortKey",
# # This value shows sorting (probably for non-english languages)
# "DCSEntryTitle": "d:DCSEntryTitle",
# # Headword displayed as article title
# }

__slots__ = [
"anchor",
Expand Down
10 changes: 5 additions & 5 deletions pyglossary/plugins/babylon_bgl/bgl_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ def replaceHtmlEntryCB(u_match: "re.Match") -> str:
return xml_escape(u_res, quotation=False)


def replaceDingbat(u_match: "re.Match") -> str:
r"""Replace chars \\u008c-\\u0095 with \\u2776-\\u277f."""
ch = u_match.group(0)
code = ch + 0x2776 - 0x8C
return chr(code)
# def replaceDingbat(u_match: "re.Match") -> str:
# r"""Replace chars \\u008c-\\u0095 with \\u2776-\\u277f."""
# ch = u_match.group(0)
# code = ch + 0x2776 - 0x8C
# return chr(code)


def escapeNewlinesCallback(u_match: "re.Match") -> str:
Expand Down
3 changes: 0 additions & 3 deletions pyglossary/plugins/cc_cedict/conv.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
import re
from typing import TYPE_CHECKING, cast

Expand All @@ -15,8 +14,6 @@

line_reg = re.compile(r"^([^ ]+) ([^ ]+) \[([^\]]+)\] /(.+)/$")

script_dir = os.path.dirname(__file__)

COLORS = {
"": "black",
"1": "red",
Expand Down
10 changes: 0 additions & 10 deletions pyglossary/plugins/stardict.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,16 +167,6 @@ def transformByInnerString(self, text: str) -> str:
...


class SupportsDunderLT(Protocol):
def __lt__(self, __other: Any) -> bool:
...


class SupportsDunderGT(Protocol):
def __gt__(self, __other: Any) -> bool:
...


T_SDListItem = TypeVar("T_SDListItem", contravariant=True)


Expand Down
83 changes: 0 additions & 83 deletions pyglossary/slob.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,24 +187,6 @@ def compress_new(x: bytes, m: CompressionModule = m) -> bytes:

MIME_TEXT = "text/plain"
MIME_HTML = "text/html"
MIME_CSS = "text/css"
MIME_JS = "application/javascript"

MIME_TYPES = {
"html": MIME_HTML,
"txt": MIME_TEXT,
"js": MIME_JS,
"css": MIME_CSS,
"json": "application/json",
"woff": "application/font-woff",
"svg": "image/svg+xml",
"png": "image/png",
"jpg": "image/jpeg",
"jpeg": "image/jpeg",
"gif": "image/gif",
"ttf": "application/x-font-ttf",
"otf": "application/x-font-opentype",
}


class FileFormatException(Exception):
Expand All @@ -227,10 +209,6 @@ class IncorrectFileSize(FileFormatException):
pass


class TagNotFound(Exception):
pass


@cache
def sortkey(
strength: int,
Expand Down Expand Up @@ -582,54 +560,6 @@ def write(self, data: bytes) -> int:
return self._file.write(data)


class StructReaderWriter(StructWriter):
def __init__(
self,
_file: "io.BufferedWriter",
reader: "StructReader",
encoding: "str | None" = None,
) -> None:
super().__init__(
_file=_file,
encoding=encoding,
)
self._reader = reader

def tell(self) -> int:
return self._file.tell()

def write(self, data: bytes) -> int:
return self._file.write(data)

def read_byte(self) -> int:
return self._reader.read_byte()

def read_tiny_text(self) -> str:
return self._reader.read_tiny_text()


def set_tag_value(filename: str, name: str, value: str) -> None:
with fopen(filename, "rb+") as _file:
_file.seek(len(MAGIC) + 16)
encoding = read_byte_string(_file, U_CHAR).decode(UTF8)
if encodings.search_function(encoding) is None:
raise UnknownEncoding(encoding)
reader = StructReaderWriter(
_file=_file,
reader=StructReader(_file, encoding=encoding),
encoding=encoding,
)
reader.read_tiny_text()
tag_count = reader.read_byte()
for _ in range(tag_count):
key = reader.read_tiny_text()
if key == name:
reader.write_tiny_text(value, editable=True)
return
reader.read_tiny_text()
raise TagNotFound(name)


def read_header(_file: "MultiFileReader") -> Header:
_file.seek(0)

Expand Down Expand Up @@ -825,19 +755,6 @@ def close(self) -> None:
self._g.close()


def find_parts(fname: str) -> "list[str]":
fname = os.path.expanduser(fname)
dirname = os.path.dirname(fname) or os.getcwd()
basename = os.path.basename(fname)
return sorted(
[
os.path.join(dirname, name)
for name in os.listdir(dirname)
if name.startswith(basename)
],
)


def open(*filenames: str) -> Slob:
return Slob(*filenames)

Expand Down
15 changes: 0 additions & 15 deletions pyglossary/text_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ def fixUtf8(st: "AnyStr") -> str:
pattern_t_us = re.compile(r"((?<!\\)(?:\\\\)*)\\t")
pattern_bar_us = re.compile(r"((?<!\\)(?:\\\\)*)\\\|")
pattern_bar_sp = re.compile(r"(?:(?<!\\)(?:\\\\)*)\|")
b_pattern_bar_us = re.compile(r"((?<!\\)(?:\\\\)*)\\\|".encode("ascii"))


def replaceStringTable(
Expand Down Expand Up @@ -138,12 +137,6 @@ def joinByBar(parts: "list[str]") -> "str":
return "|".join(escapeBar(part) for part in parts)


def unescapeBarBytes(st: bytes) -> bytes:
r"""Unscapes vertical bar (\|)."""
# str.replace is probably faster than re.sub
return b_pattern_bar_us.sub(b"\\1|", st).replace(b"\\\\", b"\\")


# return a message string describing the current exception
def excMessage() -> str:
i = sys.exc_info()
Expand All @@ -152,14 +145,6 @@ def excMessage() -> str:
return f"{i[0].__name__}: {i[1]}"


def formatHMS(h: int, m: int, s: int) -> str:
if h == 0:
if m == 0:
return f"{s:02d}"
return f"{m:02d}:{s:02d}"
return f"{h:02d}:{m:02d}:{s:02d}"


# ___________________________________________ #


Expand Down
24 changes: 24 additions & 0 deletions pyglossary/text_utils_extra.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
import re

b_pattern_bar_us = re.compile(r"((?<!\\)(?:\\\\)*)\\\|".encode("ascii"))

__all__ = [
"unescapeBarBytes",
"chBaseIntToStr",
"formatHMS",
]

def unescapeBarBytes(st: bytes) -> bytes:
r"""Unscapes vertical bar (\|)."""
# str.replace is probably faster than re.sub
return b_pattern_bar_us.sub(b"\\1|", st).replace(b"\\\\", b"\\")


def chBaseIntToStr(number: int, base: int) -> str:
"""Reverse function of int(str, base) and long(str, base)."""
import string
Expand All @@ -17,3 +33,11 @@ def chBaseIntToStr(number: int, base: int) -> str:
if number == 0:
return sign + result
return ""


def formatHMS(h: int, m: int, s: int) -> str:
if h == 0:
if m == 0:
return f"{s:02d}"
return f"{m:02d}:{s:02d}"
return f"{h:02d}:{m:02d}:{s:02d}"
23 changes: 0 additions & 23 deletions pyglossary/text_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,26 +248,3 @@ def writeTxt(
writer.finish()


def writeTabfile(
glos: "GlossaryType",
filename: str = "",
encoding: str = "utf-8",
resources: bool = True,
) -> "Generator[None, EntryType, None]":
from pyglossary.text_utils import escapeNTB

writer = TextGlossaryWriter(
glos,
entryFmt="{word}\t{defi}\n",
outInfoKeysAliasDict=None,
)
writer.setAttrs(
encoding=encoding,
wordEscapeFunc=escapeNTB,
defiEscapeFunc=escapeNTB,
ext=".txt",
resources=resources,
)
writer.open(filename)
yield from writer.write()
writer.finish()
Loading

0 comments on commit f4d1e85

Please sign in to comment.