Repository navigation
Expand file tree
/
Copy pathparser.py
More file actions
108 lines (98 loc) · 4.01 KB
/
Copy pathparser.py
File metadata and controls
108 lines (98 loc) · 4.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
"""
parser.py - Compatibility layer for legacy tests and imports.
Redirects to provider.py, renderer.py and utils.py.
"""
# Dual-context sibling imports (relative inside Anki's package load,
# absolute in the top-level test harness — see core.py for why).
if __package__:
from .provider import LocalSQLiteProvider, IndexingError
from .renderer import render_structured_content_node, render_yomitan_definition_html, render_yomitan_definition_text
from .utils import (
is_zip_dictionary,
is_directory_dictionary,
extract_clean_word,
extract_base_text,
parse_furigana_field,
find_dictionary_folders,
)
from .core import get_provider
else:
from provider import LocalSQLiteProvider, IndexingError
from renderer import render_structured_content_node, render_yomitan_definition_html, render_yomitan_definition_text
from utils import (
is_zip_dictionary,
is_directory_dictionary,
extract_clean_word,
extract_base_text,
parse_furigana_field,
find_dictionary_folders,
)
from core import get_provider
# Explicit re-export contract: these names are imported above ONLY so
# that legacy `parser.X` / `compredef_parser.X` attribute access keeps
# working (the regression suite leans on it heavily). Listing them in
# __all__ marks the re-exports as intentional (and silences F401).
__all__ = [
"LocalSQLiteProvider",
"IndexingError",
"render_structured_content_node",
"render_yomitan_definition_html",
"render_yomitan_definition_text",
"is_zip_dictionary",
"is_directory_dictionary",
"extract_clean_word",
"extract_base_text",
"parse_furigana_field",
"find_dictionary_folders",
"get_provider",
"RENDERER_VERSION",
"get_single_dictionary",
"SingleDictionary",
"install_dictionary",
"uninstall_dictionary",
"is_dictionary_installed",
]
RENDERER_VERSION = LocalSQLiteProvider.RENDERER_VERSION
def _get_db_path():
return get_provider().db_path
def get_single_dictionary(path):
# Legacy SingleDictionary object mock
class SingleDictionaryMock:
def __init__(self, p):
self.path = p
self.is_zip = is_zip_dictionary(p)
self.title = get_provider().get_title(p)
def is_indexed(self):
return get_provider().is_installed(self.path)
def entry_count(self):
return get_provider().get_entry_count(self.path)
def install(self, progress_cb=None, cancel_check=None, plain_text=None):
return get_provider().install(self.path, progress_cb, cancel_check, plain_text=plain_text)
def lookup(self, word, reading=""):
entries = get_provider().lookup_by_path(self.path, word, reading)
return [e.definition for e in entries]
def _compute_signature(self):
return get_provider()._compute_signature(self.path)
def index_is_current(self):
return get_provider().is_index_current(self.path)
def _iter_term_banks(self):
# For tests that spy on this method
return get_provider()._iter_term_banks(self.path)
return SingleDictionaryMock(path)
# Aliasing SingleDictionary to the Mock class for legacy tests
class SingleDictionary:
@staticmethod
def _iter_term_banks(_path_ignored): pass # stub (signature mirrors the
# instance method so monkeypatched spies keep working)
def install_dictionary(path, progress_cb=None, cancel_check=None, plain_text=None):
return get_provider().install(path, progress_cb, cancel_check, plain_text=plain_text)
def uninstall_dictionary(path):
get_provider().uninstall(path)
def is_dictionary_installed(path):
return get_provider().is_installed(path)
# Re-export for tests
_loaded_dicts = {} # Added for legacy test compatibility
_extract_base_text = extract_base_text
_INDEX_BATCH_SIZE = LocalSQLiteProvider._INDEX_BATCH_SIZE
# Note: if tests use 'import parser', they get this module.
# If they use 'from parser import ...', they get these functions.