Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
155 changes: 1 addition & 154 deletions language_tool_python/download_lt.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import requests
import tqdm

from ._compat import deprecated, toml_loads
from ._compat import toml_loads
from .exceptions import JavaError, PathError
from .safe_zip import SafeZipExtractor
from .utils import (
Expand Down Expand Up @@ -308,159 +308,6 @@ def confirm_java_compatibility(
raise SystemError(err)


@deprecated(
"This function is no longer used internally and will be removed in 4.0.",
stacklevel=2,
)
def get_common_prefix(z: zipfile.ZipFile) -> str | None:
"""Determine the common prefix of all file names in a zip archive.

:param z: A ZipFile object representing the zip archive.
:type z: zipfile.ZipFile
:return: The common prefix of all file names in the zip archive, or None if there
is no common prefix.
:rtype: str | None

.. deprecated:: 3.3.0
This function is no longer used internally and will be removed in 4.0.
"""
name_list = z.namelist()
if name_list and all(n.startswith(name_list[0]) for n in name_list[1:]):
return name_list[0]
return None


@deprecated(
"This function is no longer used internally and will be removed in 4.0.",
stacklevel=2,
)
def http_get(
url: str,
out_file: IO[bytes],
proxies: dict[str, str] | None = None,
) -> None:
""".. deprecated:: 3.3.0.

This function is no longer used internally and will be removed in 4.0.

:raises TimeoutError: If the download request times out.
:raises PathError: If the download fails or checksum validation fails.
"""
version_match = re.search(r"LanguageTool-(.+)\.zip", url)
if version_match:
version_start, version_end = version_match.span(1)
version_name = url[version_start:version_end]
else:
version_name = LTP_DOWNLOAD_VERSION

# Normalize snapshot-style version names (e.g. "6.8-SNAPSHOT", "latest-snapshot")
if version_name.lower().endswith("-snapshot"):
version_name = version_name[: -len("-snapshot")]
try:
local_lt = LocalLanguageTool.from_version_name(version_name)
except ValueError:
# Fallback to default behavior if the extracted version is not supported
local_lt = LocalLanguageTool.from_version_name(LTP_DOWNLOAD_VERSION)

with local_lt._get_remote_zip(out_file, proxies=proxies): # noqa: SLF001 # Accessing protected member temporarily for backward compatibility with the deprecated http_get function
pass


@deprecated(
"This function is no longer used internally and will be removed in 4.0.",
stacklevel=2,
)
def unzip_file(temp_file_name: str, directory_to_extract_to: Path) -> None:
"""Unzips a zip file to a specified directory.

:param temp_file_name: Path to the zip file to be extracted.
:type temp_file_name: str
:param directory_to_extract_to: The directory where the contents of the zip file
will be extracted.
:type directory_to_extract_to: Path
:raises PathError: If the ZIP archive or extraction destination is unsafe.

.. deprecated:: 3.3.0
This function is no longer used internally and will be removed in 4.0.
"""
logger.info("Unzipping %s to %s", temp_file_name, directory_to_extract_to)
with (
tempfile.TemporaryDirectory(dir=directory_to_extract_to.parent) as temp_dir,
zipfile.ZipFile(temp_file_name, "r") as zip_ref,
):
_SAFE_ZIP_EXTRACTOR.extractall(
zip_ref,
directory_to_extract_to,
work_dir=Path(temp_dir),
)


@deprecated(
"This function is no longer used internally and will be removed in 4.0.",
stacklevel=2,
)
def download_zip(url: str, directory: Path) -> None:
"""Download a ZIP file from the given URL and extract it to the specified directory.

:param url: The URL of the ZIP file to download.
:type url: str
:param directory: The directory where the ZIP file should be extracted.
:type directory: Path
:raises TimeoutError: If the download request times out.
:raises PathError: If the download fails or the ZIP extraction is unsafe.

.. deprecated:: 3.3.0
This function is no longer used internally and will be removed in 4.0.
"""
logger.info("Downloading from %s to %s", url, directory)
# Download file using a context manager.
with tempfile.NamedTemporaryFile(suffix=".zip", delete=False) as downloaded_file:
http_get(url, downloaded_file)
temp_name = downloaded_file.name
# Extract zip file to path.
unzip_file(temp_name, directory)
# Remove the temporary file.
Path(temp_name).unlink(missing_ok=True)


@deprecated(
(
"This function is no longer used internally and will be removed in 4.0.\n"
"Use instead language_tool_python.download_lt.LocalLanguageTool.download."
),
stacklevel=2,
)
def download_lt(language_tool_version: str = LTP_DOWNLOAD_VERSION) -> None:
"""Download and extract the specified version of LanguageTool.

This function checks for Java compatibility, and downloads the specified version of
LanguageTool if it is not already present.

:param language_tool_version: The version of LanguageTool to download. If not
specified, the default version defined by
LTP_DOWNLOAD_VERSION is used.
:type language_tool_version: str
:raises ValueError: If the specified version format is invalid.
:raises ModuleNotFoundError: If no Java installation is detected.
:raises SystemError: If the detected Java version is incompatible.
:raises TimeoutError: If the download request times out.
:raises PathError: If the version is unsupported, the download fails, checksum
validation fails, or ZIP extraction is unsafe.

.. deprecated:: 3.3.0
This function is no longer used internally and will be removed in 4.0.
"""
# Use the env var to the jar directory if it is defined
# otherwise look in the download directory
if os.environ.get(LTP_JAR_DIR_PATH_ENV_VAR):
return

local_lt = LocalLanguageTool.from_version_name(language_tool_version)

if local_lt not in local_lt.get_installed_versions():
local_lt.download()


@total_ordering
class LocalLanguageTool(ABC):
"""Abstract base class for managing local LanguageTool installations.
Expand Down
25 changes: 0 additions & 25 deletions language_tool_python/match.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
from functools import total_ordering
from typing import TYPE_CHECKING

from ._compat import deprecated
from .utils import SupportsFloat, SupportsInt

if TYPE_CHECKING:
from collections.abc import Iterator

Expand Down Expand Up @@ -61,28 +58,6 @@ def get_match_ordered_dict() -> OrderedDictType[str, type]:
)


@deprecated(
"This function is no longer used internally and will be removed in 4.0.",
stacklevel=2,
)
def auto_type(obj: SupportsInt | SupportsFloat | object) -> int | float | object:
"""Attempt to automatically convert the input object to an integer or float.

If the conversion to an integer fails, it tries to convert to a float. If both
conversions fail, it returns the original object.

:param obj: The object to be converted.
:type obj: SupportsInt | SupportsFloat | object
:return: The converted object as an integer, float, or the original object.
:rtype: int | float | object
"""
if isinstance(obj, SupportsInt):
return int(obj)
if isinstance(obj, SupportsFloat):
return float(obj)
return obj


def four_byte_char_positions(text: str) -> list[int]:
"""Identify positions of 4-byte encoded characters in a UTF-8 string.

Expand Down
Loading
Loading