|
23 | 23 | import requests |
24 | 24 | import tqdm |
25 | 25 |
|
26 | | -from ._compat import deprecated, toml_loads |
| 26 | +from ._compat import toml_loads |
27 | 27 | from .exceptions import JavaError, PathError |
28 | 28 | from .safe_zip import SafeZipExtractor |
29 | 29 | from .utils import ( |
@@ -308,159 +308,6 @@ def confirm_java_compatibility( |
308 | 308 | raise SystemError(err) |
309 | 309 |
|
310 | 310 |
|
311 | | -@deprecated( |
312 | | - "This function is no longer used internally and will be removed in 4.0.", |
313 | | - stacklevel=2, |
314 | | -) |
315 | | -def get_common_prefix(z: zipfile.ZipFile) -> str | None: |
316 | | - """Determine the common prefix of all file names in a zip archive. |
317 | | -
|
318 | | - :param z: A ZipFile object representing the zip archive. |
319 | | - :type z: zipfile.ZipFile |
320 | | - :return: The common prefix of all file names in the zip archive, or None if there |
321 | | - is no common prefix. |
322 | | - :rtype: str | None |
323 | | -
|
324 | | - .. deprecated:: 3.3.0 |
325 | | - This function is no longer used internally and will be removed in 4.0. |
326 | | - """ |
327 | | - name_list = z.namelist() |
328 | | - if name_list and all(n.startswith(name_list[0]) for n in name_list[1:]): |
329 | | - return name_list[0] |
330 | | - return None |
331 | | - |
332 | | - |
333 | | -@deprecated( |
334 | | - "This function is no longer used internally and will be removed in 4.0.", |
335 | | - stacklevel=2, |
336 | | -) |
337 | | -def http_get( |
338 | | - url: str, |
339 | | - out_file: IO[bytes], |
340 | | - proxies: dict[str, str] | None = None, |
341 | | -) -> None: |
342 | | - """.. deprecated:: 3.3.0. |
343 | | -
|
344 | | - This function is no longer used internally and will be removed in 4.0. |
345 | | -
|
346 | | - :raises TimeoutError: If the download request times out. |
347 | | - :raises PathError: If the download fails or checksum validation fails. |
348 | | - """ |
349 | | - version_match = re.search(r"LanguageTool-(.+)\.zip", url) |
350 | | - if version_match: |
351 | | - version_start, version_end = version_match.span(1) |
352 | | - version_name = url[version_start:version_end] |
353 | | - else: |
354 | | - version_name = LTP_DOWNLOAD_VERSION |
355 | | - |
356 | | - # Normalize snapshot-style version names (e.g. "6.8-SNAPSHOT", "latest-snapshot") |
357 | | - if version_name.lower().endswith("-snapshot"): |
358 | | - version_name = version_name[: -len("-snapshot")] |
359 | | - try: |
360 | | - local_lt = LocalLanguageTool.from_version_name(version_name) |
361 | | - except ValueError: |
362 | | - # Fallback to default behavior if the extracted version is not supported |
363 | | - local_lt = LocalLanguageTool.from_version_name(LTP_DOWNLOAD_VERSION) |
364 | | - |
365 | | - 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 |
366 | | - pass |
367 | | - |
368 | | - |
369 | | -@deprecated( |
370 | | - "This function is no longer used internally and will be removed in 4.0.", |
371 | | - stacklevel=2, |
372 | | -) |
373 | | -def unzip_file(temp_file_name: str, directory_to_extract_to: Path) -> None: |
374 | | - """Unzips a zip file to a specified directory. |
375 | | -
|
376 | | - :param temp_file_name: Path to the zip file to be extracted. |
377 | | - :type temp_file_name: str |
378 | | - :param directory_to_extract_to: The directory where the contents of the zip file |
379 | | - will be extracted. |
380 | | - :type directory_to_extract_to: Path |
381 | | - :raises PathError: If the ZIP archive or extraction destination is unsafe. |
382 | | -
|
383 | | - .. deprecated:: 3.3.0 |
384 | | - This function is no longer used internally and will be removed in 4.0. |
385 | | - """ |
386 | | - logger.info("Unzipping %s to %s", temp_file_name, directory_to_extract_to) |
387 | | - with ( |
388 | | - tempfile.TemporaryDirectory(dir=directory_to_extract_to.parent) as temp_dir, |
389 | | - zipfile.ZipFile(temp_file_name, "r") as zip_ref, |
390 | | - ): |
391 | | - _SAFE_ZIP_EXTRACTOR.extractall( |
392 | | - zip_ref, |
393 | | - directory_to_extract_to, |
394 | | - work_dir=Path(temp_dir), |
395 | | - ) |
396 | | - |
397 | | - |
398 | | -@deprecated( |
399 | | - "This function is no longer used internally and will be removed in 4.0.", |
400 | | - stacklevel=2, |
401 | | -) |
402 | | -def download_zip(url: str, directory: Path) -> None: |
403 | | - """Download a ZIP file from the given URL and extract it to the specified directory. |
404 | | -
|
405 | | - :param url: The URL of the ZIP file to download. |
406 | | - :type url: str |
407 | | - :param directory: The directory where the ZIP file should be extracted. |
408 | | - :type directory: Path |
409 | | - :raises TimeoutError: If the download request times out. |
410 | | - :raises PathError: If the download fails or the ZIP extraction is unsafe. |
411 | | -
|
412 | | - .. deprecated:: 3.3.0 |
413 | | - This function is no longer used internally and will be removed in 4.0. |
414 | | - """ |
415 | | - logger.info("Downloading from %s to %s", url, directory) |
416 | | - # Download file using a context manager. |
417 | | - with tempfile.NamedTemporaryFile(suffix=".zip", delete=False) as downloaded_file: |
418 | | - http_get(url, downloaded_file) |
419 | | - temp_name = downloaded_file.name |
420 | | - # Extract zip file to path. |
421 | | - unzip_file(temp_name, directory) |
422 | | - # Remove the temporary file. |
423 | | - Path(temp_name).unlink(missing_ok=True) |
424 | | - |
425 | | - |
426 | | -@deprecated( |
427 | | - ( |
428 | | - "This function is no longer used internally and will be removed in 4.0.\n" |
429 | | - "Use instead language_tool_python.download_lt.LocalLanguageTool.download." |
430 | | - ), |
431 | | - stacklevel=2, |
432 | | -) |
433 | | -def download_lt(language_tool_version: str = LTP_DOWNLOAD_VERSION) -> None: |
434 | | - """Download and extract the specified version of LanguageTool. |
435 | | -
|
436 | | - This function checks for Java compatibility, and downloads the specified version of |
437 | | - LanguageTool if it is not already present. |
438 | | -
|
439 | | - :param language_tool_version: The version of LanguageTool to download. If not |
440 | | - specified, the default version defined by |
441 | | - LTP_DOWNLOAD_VERSION is used. |
442 | | - :type language_tool_version: str |
443 | | - :raises ValueError: If the specified version format is invalid. |
444 | | - :raises ModuleNotFoundError: If no Java installation is detected. |
445 | | - :raises SystemError: If the detected Java version is incompatible. |
446 | | - :raises TimeoutError: If the download request times out. |
447 | | - :raises PathError: If the version is unsupported, the download fails, checksum |
448 | | - validation fails, or ZIP extraction is unsafe. |
449 | | -
|
450 | | - .. deprecated:: 3.3.0 |
451 | | - This function is no longer used internally and will be removed in 4.0. |
452 | | - """ |
453 | | - # Use the env var to the jar directory if it is defined |
454 | | - # otherwise look in the download directory |
455 | | - if os.environ.get(LTP_JAR_DIR_PATH_ENV_VAR): |
456 | | - return |
457 | | - |
458 | | - local_lt = LocalLanguageTool.from_version_name(language_tool_version) |
459 | | - |
460 | | - if local_lt not in local_lt.get_installed_versions(): |
461 | | - local_lt.download() |
462 | | - |
463 | | - |
464 | 311 | @total_ordering |
465 | 312 | class LocalLanguageTool(ABC): |
466 | 313 | """Abstract base class for managing local LanguageTool installations. |
|
0 commit comments