wikitextparser 0.56.3__tar.gz → 0.56.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {wikitextparser-0.56.3 → wikitextparser-0.56.4}/CHANGELOG.rst +5 -0
- {wikitextparser-0.56.3 → wikitextparser-0.56.4}/PKG-INFO +3 -2
- {wikitextparser-0.56.3 → wikitextparser-0.56.4}/docs/conf.py +1 -1
- {wikitextparser-0.56.3 → wikitextparser-0.56.4}/pyproject.toml +9 -1
- {wikitextparser-0.56.3 → wikitextparser-0.56.4}/wikitextparser/__init__.py +1 -1
- {wikitextparser-0.56.3 → wikitextparser-0.56.4}/wikitextparser/_argument.py +1 -1
- {wikitextparser-0.56.3 → wikitextparser-0.56.4}/wikitextparser/_cell.py +6 -6
- {wikitextparser-0.56.3 → wikitextparser-0.56.4}/wikitextparser/_config.py +1 -1
- {wikitextparser-0.56.3 → wikitextparser-0.56.4}/wikitextparser/_externallink.py +2 -2
- {wikitextparser-0.56.3 → wikitextparser-0.56.4}/wikitextparser/_section.py +3 -1
- {wikitextparser-0.56.3 → wikitextparser-0.56.4}/wikitextparser/_table.py +92 -32
- {wikitextparser-0.56.3 → wikitextparser-0.56.4}/wikitextparser/_template.py +13 -14
- {wikitextparser-0.56.3 → wikitextparser-0.56.4}/wikitextparser/_wikilist.py +4 -6
- {wikitextparser-0.56.3 → wikitextparser-0.56.4}/wikitextparser/_wikitext.py +10 -12
- {wikitextparser-0.56.3 → wikitextparser-0.56.4}/.coveragerc +0 -0
- {wikitextparser-0.56.3 → wikitextparser-0.56.4}/.github/workflows/tests.yml +0 -0
- {wikitextparser-0.56.3 → wikitextparser-0.56.4}/.gitignore +0 -0
- {wikitextparser-0.56.3 → wikitextparser-0.56.4}/.readthedocs.yaml +0 -0
- {wikitextparser-0.56.3 → wikitextparser-0.56.4}/.vscode/settings.json +0 -0
- {wikitextparser-0.56.3 → wikitextparser-0.56.4}/LICENSE.md +0 -0
- {wikitextparser-0.56.3 → wikitextparser-0.56.4}/README.rst +0 -0
- {wikitextparser-0.56.3 → wikitextparser-0.56.4}/docs/CHANGELOG.rst +0 -0
- {wikitextparser-0.56.3 → wikitextparser-0.56.4}/docs/Makefile +0 -0
- {wikitextparser-0.56.3 → wikitextparser-0.56.4}/docs/README.rst +0 -0
- {wikitextparser-0.56.3 → wikitextparser-0.56.4}/docs/index.rst +0 -0
- {wikitextparser-0.56.3 → wikitextparser-0.56.4}/docs/make.bat +0 -0
- {wikitextparser-0.56.3 → wikitextparser-0.56.4}/wikitextparser/_comment_bold_italic.py +0 -0
- {wikitextparser-0.56.3 → wikitextparser-0.56.4}/wikitextparser/_parameter.py +0 -0
- {wikitextparser-0.56.3 → wikitextparser-0.56.4}/wikitextparser/_parser_function.py +0 -0
- {wikitextparser-0.56.3 → wikitextparser-0.56.4}/wikitextparser/_spans.py +0 -0
- {wikitextparser-0.56.3 → wikitextparser-0.56.4}/wikitextparser/_tag.py +0 -0
- {wikitextparser-0.56.3 → wikitextparser-0.56.4}/wikitextparser/_wikilink.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: wikitextparser
|
|
3
|
-
Version: 0.56.
|
|
3
|
+
Version: 0.56.4
|
|
4
4
|
Summary: A simple parsing tool for MediaWiki's wikitext markup.
|
|
5
5
|
Keywords: MediaWiki,wikitext,parser
|
|
6
6
|
Author-email: 5j9 <5j9@users.noreply.github.com>
|
|
@@ -9,6 +9,7 @@ Description-Content-Type: text/x-rst
|
|
|
9
9
|
Classifier: Programming Language :: Python
|
|
10
10
|
Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
|
|
11
11
|
Classifier: Topic :: Text Processing
|
|
12
|
+
License-File: LICENSE.md
|
|
12
13
|
Requires-Dist: regex >= 2022.9.11
|
|
13
14
|
Requires-Dist: wcwidth
|
|
14
15
|
Requires-Dist: coverage ; extra == "dev"
|
|
@@ -50,13 +50,17 @@ line-length = 79
|
|
|
50
50
|
format.quote-style = 'single'
|
|
51
51
|
lint.isort.combine-as-imports = true
|
|
52
52
|
lint.extend-select = [
|
|
53
|
+
'W605', # invalid-escape-sequence
|
|
53
54
|
'FA', # flake8-future-annotations
|
|
54
55
|
'I', # isort
|
|
55
56
|
'UP', # pyupgrade
|
|
57
|
+
'RUF', # Ruff-specific rules (RUF)
|
|
56
58
|
]
|
|
57
59
|
lint.ignore = [
|
|
58
|
-
'UP027', # list comprehensions are faster than generator expressions
|
|
59
60
|
'E721', # Do not compare types, use `isinstance()`
|
|
61
|
+
'RUF001', # ambiguous-unicode-character-string
|
|
62
|
+
'RUF002', # ambiguous-unicode-character-docstring
|
|
63
|
+
'RUF003', # ambiguous-unicode-character-comment
|
|
60
64
|
]
|
|
61
65
|
|
|
62
66
|
[tool.pytest.ini_options]
|
|
@@ -70,3 +74,7 @@ reportUnnecessaryCast = "warning"
|
|
|
70
74
|
reportUnnecessaryContains = "warning"
|
|
71
75
|
reportUnnecessaryIsInstance = "warning"
|
|
72
76
|
reportUnnecessaryTypeIgnoreComment = true
|
|
77
|
+
reportInvalidStringEscapeSequence = false
|
|
78
|
+
reportConstantRedefinition = 'error'
|
|
79
|
+
reportTypeCommentUsage = 'warning'
|
|
80
|
+
reportUnnecessaryComparison = 'warning'
|
|
@@ -142,7 +142,7 @@ INLINE_NONHAEDER_CELL_MATCH = rc(
|
|
|
142
142
|
|
|
143
143
|
|
|
144
144
|
class Cell(SubWikiTextWithAttrs):
|
|
145
|
-
__slots__ = '
|
|
145
|
+
__slots__ = '_attrs_match_cache', '_header', '_match_cache'
|
|
146
146
|
|
|
147
147
|
def __init__(
|
|
148
148
|
self,
|
|
@@ -189,15 +189,15 @@ class Cell(SubWikiTextWithAttrs):
|
|
|
189
189
|
return cache_match # type: ignore
|
|
190
190
|
shadow = self._shadow
|
|
191
191
|
if shadow[0] == 10: # ord('\n')
|
|
192
|
-
m = NEWLINE_CELL_MATCH(shadow)
|
|
192
|
+
m: Match[bytes] = NEWLINE_CELL_MATCH(shadow) # type: ignore
|
|
193
193
|
self._header = m['sep'] == 33 # ord('!')
|
|
194
194
|
elif self._header:
|
|
195
|
-
m = INLINE_HAEDER_CELL_MATCH(shadow)
|
|
195
|
+
m = INLINE_HAEDER_CELL_MATCH(shadow) # type: ignore
|
|
196
196
|
else:
|
|
197
|
-
m = INLINE_NONHAEDER_CELL_MATCH(shadow)
|
|
197
|
+
m = INLINE_NONHAEDER_CELL_MATCH(shadow) # type: ignore
|
|
198
198
|
self._match_cache = m, string
|
|
199
199
|
self._attrs_match_cache = None, None
|
|
200
|
-
return m
|
|
200
|
+
return m
|
|
201
201
|
|
|
202
202
|
@property
|
|
203
203
|
def value(self) -> str:
|
|
@@ -246,7 +246,7 @@ class Cell(SubWikiTextWithAttrs):
|
|
|
246
246
|
attrs_start, attrs_end = cell_match.span('attrs')
|
|
247
247
|
if attrs_start != -1:
|
|
248
248
|
encoded_attr_name = attr_name.encode()
|
|
249
|
-
attrs_m = ATTRS_MATCH(shadow, attrs_start, attrs_end)
|
|
249
|
+
attrs_m: Match[bytes] = ATTRS_MATCH(shadow, attrs_start, attrs_end) # type: ignore
|
|
250
250
|
for i, n in enumerate(reversed(attrs_m.captures('attr_name'))):
|
|
251
251
|
if n == encoded_attr_name:
|
|
252
252
|
vs, ve = attrs_m.spans('attr_value')[-i - 1]
|
|
@@ -17,7 +17,7 @@ class ExternalLink(SubWikiText):
|
|
|
17
17
|
external links.
|
|
18
18
|
"""
|
|
19
19
|
if self(0) == '[':
|
|
20
|
-
return self(1, URL_MATCH(self._ext_link_shadow, 1).end())
|
|
20
|
+
return self(1, URL_MATCH(self._ext_link_shadow, 1).end()) # type: ignore
|
|
21
21
|
return self.string
|
|
22
22
|
|
|
23
23
|
@url.setter
|
|
@@ -38,7 +38,7 @@ class ExternalLink(SubWikiText):
|
|
|
38
38
|
"""
|
|
39
39
|
string = self.string
|
|
40
40
|
if string[0] == '[':
|
|
41
|
-
url_end = URL_MATCH(self._ext_link_shadow, 1).end()
|
|
41
|
+
url_end = URL_MATCH(self._ext_link_shadow, 1).end() # type: ignore
|
|
42
42
|
end_char = string[url_end]
|
|
43
43
|
if end_char == ']':
|
|
44
44
|
return None
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
+
from regex import Match
|
|
4
|
+
|
|
3
5
|
from ._wikitext import SubWikiText, rc
|
|
4
6
|
|
|
5
7
|
HEADER_MATCH = rc(rb'(={1,6})([^\n]+?)\1[ \t]*(\n|\Z)').match
|
|
@@ -37,7 +39,7 @@ class Section(SubWikiText):
|
|
|
37
39
|
|
|
38
40
|
@level.setter
|
|
39
41
|
def level(self, value: int) -> None:
|
|
40
|
-
m = self._header_match
|
|
42
|
+
m: Match[bytes] = self._header_match # type: ignore
|
|
41
43
|
level_diff = len(m[1]) - value
|
|
42
44
|
if level_diff == 0:
|
|
43
45
|
return
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
from bisect import insort_right
|
|
4
|
-
from
|
|
5
|
-
from typing import Any, TypeVar
|
|
4
|
+
from typing import Any, TypeVar, overload
|
|
6
5
|
|
|
7
6
|
from regex import DOTALL, VERBOSE
|
|
8
7
|
|
|
@@ -105,7 +104,7 @@ class Table(SubWikiTextWithAttrs):
|
|
|
105
104
|
return [[]]
|
|
106
105
|
# Start of the first row
|
|
107
106
|
match_table = []
|
|
108
|
-
pos = FIRST_NON_CAPTION_LINE(table_shadow, pos).start()
|
|
107
|
+
pos = FIRST_NON_CAPTION_LINE(table_shadow, pos).start() # type: ignore
|
|
109
108
|
rsp = _row_separator_increase(table_shadow, pos)
|
|
110
109
|
pos = -1
|
|
111
110
|
while pos != rsp:
|
|
@@ -114,7 +113,7 @@ class Table(SubWikiTextWithAttrs):
|
|
|
114
113
|
m = NEWLINE_CELL_MATCH(table_shadow, pos)
|
|
115
114
|
# Don't add a row if there are no new cells.
|
|
116
115
|
if m:
|
|
117
|
-
match_row
|
|
116
|
+
match_row: list[Any] = []
|
|
118
117
|
match_table.append(match_row)
|
|
119
118
|
while m is not None:
|
|
120
119
|
match_row.append(m)
|
|
@@ -132,18 +131,52 @@ class Table(SubWikiTextWithAttrs):
|
|
|
132
131
|
match_row.append(m)
|
|
133
132
|
pos = m.end()
|
|
134
133
|
m = INLINE_HAEDER_CELL_MATCH(table_shadow, pos)
|
|
135
|
-
pos = FIRST_NON_CAPTION_LINE(table_shadow, pos).start()
|
|
134
|
+
pos = FIRST_NON_CAPTION_LINE(table_shadow, pos).start() # type: ignore
|
|
136
135
|
m = NEWLINE_CELL_MATCH(table_shadow, pos)
|
|
137
136
|
rsp = _row_separator_increase(table_shadow, pos)
|
|
138
137
|
return match_table
|
|
139
138
|
|
|
139
|
+
@overload
|
|
140
140
|
def data(
|
|
141
|
+
self,
|
|
142
|
+
row: int,
|
|
143
|
+
column: int,
|
|
144
|
+
span: bool = ...,
|
|
145
|
+
strip: bool = ...,
|
|
146
|
+
) -> str | None: ...
|
|
147
|
+
|
|
148
|
+
@overload
|
|
149
|
+
def data(
|
|
150
|
+
self,
|
|
151
|
+
row: int,
|
|
152
|
+
column: None = ...,
|
|
153
|
+
span: bool = ...,
|
|
154
|
+
strip: bool = ...,
|
|
155
|
+
) -> list[str | None]: ...
|
|
156
|
+
|
|
157
|
+
@overload
|
|
158
|
+
def data(
|
|
159
|
+
self,
|
|
160
|
+
row: None = ...,
|
|
161
|
+
column: None = ...,
|
|
162
|
+
span: bool = ...,
|
|
163
|
+
strip: bool = ...,
|
|
164
|
+
) -> list[list[str | None]]: ...
|
|
165
|
+
@overload
|
|
166
|
+
def data(
|
|
167
|
+
self,
|
|
168
|
+
row: None = ...,
|
|
169
|
+
column: int = ...,
|
|
170
|
+
span: bool = ...,
|
|
171
|
+
strip: bool = ...,
|
|
172
|
+
) -> list[list[str | None]]: ...
|
|
173
|
+
def data( # type: ignore
|
|
141
174
|
self,
|
|
142
175
|
span: bool = True,
|
|
143
176
|
strip: bool = True,
|
|
144
|
-
row: int = None,
|
|
145
|
-
column: int = None,
|
|
146
|
-
) -> list[list[str]] | list[str] | str:
|
|
177
|
+
row: int | None = None,
|
|
178
|
+
column: int | None = None,
|
|
179
|
+
) -> list[list[str | None]] | list[str | None] | str | None:
|
|
147
180
|
"""Return a list containing lists of row values.
|
|
148
181
|
|
|
149
182
|
:param span: If true, calculate rows according to rowspans and colspans
|
|
@@ -161,10 +194,10 @@ class Table(SubWikiTextWithAttrs):
|
|
|
161
194
|
# Note string is only used for extracting data, matching is done over
|
|
162
195
|
# the shadow.
|
|
163
196
|
string = self.string
|
|
164
|
-
table_data
|
|
197
|
+
table_data: list[list[str | None]] = []
|
|
165
198
|
if strip:
|
|
166
199
|
for match_row in match_table:
|
|
167
|
-
row_data
|
|
200
|
+
row_data: list[str | None] = []
|
|
168
201
|
table_data.append(row_data)
|
|
169
202
|
for m in match_row:
|
|
170
203
|
# Spaces after the first newline can be meaningful
|
|
@@ -179,16 +212,16 @@ class Table(SubWikiTextWithAttrs):
|
|
|
179
212
|
row_data.append(string[s:e])
|
|
180
213
|
if table_data:
|
|
181
214
|
if span:
|
|
182
|
-
table_attrs
|
|
215
|
+
table_attrs: list[list[dict[bytes, bytes]]] = []
|
|
183
216
|
for match_row in match_table:
|
|
184
|
-
row_attrs
|
|
217
|
+
row_attrs: list[dict[bytes, bytes]] = []
|
|
185
218
|
table_attrs.append(row_attrs)
|
|
186
219
|
row_attrs_append = row_attrs.append
|
|
187
220
|
for m in match_row:
|
|
188
221
|
s, e = m.span('attrs')
|
|
189
222
|
captures = ATTRS_MATCH(
|
|
190
223
|
string.encode('ascii', 'replace'), s, e
|
|
191
|
-
).captures
|
|
224
|
+
).captures # type: ignore
|
|
192
225
|
row_attrs_append(
|
|
193
226
|
dict(
|
|
194
227
|
zip(
|
|
@@ -206,12 +239,40 @@ class Table(SubWikiTextWithAttrs):
|
|
|
206
239
|
return table_data[row]
|
|
207
240
|
return table_data[row][column]
|
|
208
241
|
|
|
242
|
+
@overload
|
|
243
|
+
def cells(
|
|
244
|
+
self,
|
|
245
|
+
row: int,
|
|
246
|
+
column: int,
|
|
247
|
+
span: bool = True,
|
|
248
|
+
) -> Cell | None: ...
|
|
249
|
+
@overload
|
|
250
|
+
def cells(
|
|
251
|
+
self,
|
|
252
|
+
row: int,
|
|
253
|
+
column: None = None,
|
|
254
|
+
span: bool = True,
|
|
255
|
+
) -> list[Cell | None]: ...
|
|
256
|
+
@overload
|
|
257
|
+
def cells(
|
|
258
|
+
self,
|
|
259
|
+
row: None = None,
|
|
260
|
+
column: int = 0,
|
|
261
|
+
span: bool = True,
|
|
262
|
+
) -> list[list[Cell | None]]: ...
|
|
263
|
+
@overload
|
|
264
|
+
def cells(
|
|
265
|
+
self,
|
|
266
|
+
row: None = None,
|
|
267
|
+
column: None = None,
|
|
268
|
+
span: bool = True,
|
|
269
|
+
) -> list[list[Cell | None]]: ...
|
|
209
270
|
def cells(
|
|
210
271
|
self,
|
|
211
|
-
row: int = None,
|
|
212
|
-
column: int = None,
|
|
272
|
+
row: int | None = None,
|
|
273
|
+
column: int | None = None,
|
|
213
274
|
span: bool = True,
|
|
214
|
-
) -> list[list[Cell]] | list[Cell] | Cell:
|
|
275
|
+
) -> list[list[Cell | None]] | list[Cell | None] | Cell | None:
|
|
215
276
|
"""Return a list of lists containing Cell objects.
|
|
216
277
|
|
|
217
278
|
:param span: If is True, rearrange the result according to colspan and
|
|
@@ -231,14 +292,14 @@ class Table(SubWikiTextWithAttrs):
|
|
|
231
292
|
type_ = id(tbl_span)
|
|
232
293
|
type_to_spans = self._type_to_spans
|
|
233
294
|
spans = type_to_spans.setdefault(type_, [])
|
|
234
|
-
table_cells
|
|
235
|
-
table_attrs
|
|
295
|
+
table_cells: list[list[Cell | None]] = []
|
|
296
|
+
table_attrs: list[list[dict[bytes, bytes]]] = []
|
|
236
297
|
attrs_match = None
|
|
237
298
|
for match_row in match_table:
|
|
238
|
-
row_cells
|
|
299
|
+
row_cells: list[Cell | None] = []
|
|
239
300
|
table_cells.append(row_cells)
|
|
240
301
|
if span:
|
|
241
|
-
row_attrs
|
|
302
|
+
row_attrs: list[dict[bytes, bytes]] = []
|
|
242
303
|
table_attrs.append(row_attrs)
|
|
243
304
|
row_attrs_append = row_attrs.append
|
|
244
305
|
for m in match_row:
|
|
@@ -251,9 +312,8 @@ class Table(SubWikiTextWithAttrs):
|
|
|
251
312
|
# Also ATTRS_MATCH should match against the cell string
|
|
252
313
|
# so that it can be used easily as cache later in Cells.
|
|
253
314
|
attrs_match = ATTRS_MATCH(shadow[ms:me], s - ms, e - ms)
|
|
254
|
-
captures = attrs_match.captures
|
|
255
|
-
#
|
|
256
|
-
row_attrs_append(
|
|
315
|
+
captures = attrs_match.captures # type: ignore
|
|
316
|
+
row_attrs_append( # type: ignore
|
|
257
317
|
dict(
|
|
258
318
|
zip(captures('attr_name'), captures('attr_value'))
|
|
259
319
|
)
|
|
@@ -341,7 +401,7 @@ class Table(SubWikiTextWithAttrs):
|
|
|
341
401
|
self[m.end('preattrs') : end] = attrs
|
|
342
402
|
|
|
343
403
|
@property
|
|
344
|
-
def row_attrs(self) -> list[dict]:
|
|
404
|
+
def row_attrs(self) -> list[dict[str, str]]:
|
|
345
405
|
"""Row attributes.
|
|
346
406
|
|
|
347
407
|
Use the setter of this property to set attributes for all rows.
|
|
@@ -353,7 +413,7 @@ class Table(SubWikiTextWithAttrs):
|
|
|
353
413
|
append = attrs.append
|
|
354
414
|
for row_match in FIND_ROWS(shadow):
|
|
355
415
|
s, e = row_match.span(1)
|
|
356
|
-
spans = ATTRS_MATCH(shadow, s, e).spans
|
|
416
|
+
spans = ATTRS_MATCH(shadow, s, e).spans # type: ignore
|
|
357
417
|
append(
|
|
358
418
|
{
|
|
359
419
|
string[ns:ne]: string[vs:ve]
|
|
@@ -365,7 +425,7 @@ class Table(SubWikiTextWithAttrs):
|
|
|
365
425
|
return attrs
|
|
366
426
|
|
|
367
427
|
@row_attrs.setter
|
|
368
|
-
def row_attrs(self, attrs: list[
|
|
428
|
+
def row_attrs(self, attrs: list[dict[str, str]]):
|
|
369
429
|
for row_match, attrs_dict in reversed(
|
|
370
430
|
[*zip(FIND_ROWS(self._table_shadow), attrs)]
|
|
371
431
|
):
|
|
@@ -383,8 +443,8 @@ class Table(SubWikiTextWithAttrs):
|
|
|
383
443
|
|
|
384
444
|
|
|
385
445
|
def _apply_attr_spans(
|
|
386
|
-
table_attrs: list[list[dict[
|
|
387
|
-
) -> list[list[T]]:
|
|
446
|
+
table_attrs: list[list[dict[bytes, bytes]]], table_data: list[list[T]]
|
|
447
|
+
) -> list[list[T | None]]:
|
|
388
448
|
"""Apply row and column spans and return table_data."""
|
|
389
449
|
# The following code is based on the table forming algorithm described
|
|
390
450
|
# at http://www.w3.org/TR/html5/tabular-data.html#processing-model-1
|
|
@@ -394,7 +454,7 @@ def _apply_attr_spans(
|
|
|
394
454
|
# 4
|
|
395
455
|
# The xwidth and yheight variables give the table's dimensions.
|
|
396
456
|
# The table is initially empty.
|
|
397
|
-
table
|
|
457
|
+
table: list[list[T | None]] = []
|
|
398
458
|
append_row = table.append
|
|
399
459
|
# Table.data won't call this function if table_data is empty.
|
|
400
460
|
# 5
|
|
@@ -511,11 +571,11 @@ def _row_separator_increase(shadow: bytearray, pos: int) -> int:
|
|
|
511
571
|
Also skips any semi-caption lines before and after the separator.
|
|
512
572
|
"""
|
|
513
573
|
# General format of row separators: r'\|-[^\n]*\n'
|
|
514
|
-
ncl = FIRST_NON_CAPTION_LINE(shadow, pos).start()
|
|
574
|
+
ncl = FIRST_NON_CAPTION_LINE(shadow, pos).start() # type: ignore
|
|
515
575
|
lsp = _lstrip_increase(shadow, ncl)
|
|
516
|
-
while shadow[lsp : lsp + 2] == b'|-':
|
|
576
|
+
while shadow[lsp : lsp + 2] == b'|-': # type: ignore
|
|
517
577
|
# We are on a row separator line.
|
|
518
578
|
pos = shadow.find(10, lsp + 2) # ord('\n')
|
|
519
|
-
pos = FIRST_NON_CAPTION_LINE(shadow, pos).start()
|
|
579
|
+
pos = FIRST_NON_CAPTION_LINE(shadow, pos).start() # type: ignore
|
|
520
580
|
lsp = _lstrip_increase(shadow, pos)
|
|
521
581
|
return pos
|
|
@@ -104,7 +104,7 @@ class Template(SubWikiTextWithArgs):
|
|
|
104
104
|
|
|
105
105
|
Also see `rm_dup_args_safe` function.
|
|
106
106
|
"""
|
|
107
|
-
names = set()
|
|
107
|
+
names = set()
|
|
108
108
|
for a in reversed(self.arguments):
|
|
109
109
|
name = a.name.strip(WS)
|
|
110
110
|
if name in names:
|
|
@@ -214,14 +214,14 @@ class Template(SubWikiTextWithArgs):
|
|
|
214
214
|
aname = arg.name
|
|
215
215
|
name_len = len(aname)
|
|
216
216
|
name_lengths.append(name_len)
|
|
217
|
-
before_names.append(STARTING_WS_MATCH(aname)[0])
|
|
217
|
+
before_names.append(STARTING_WS_MATCH(aname)[0]) # type: ignore
|
|
218
218
|
arg_value = arg.value
|
|
219
|
-
before_values.append(STARTING_WS_MATCH(arg_value)[0])
|
|
220
|
-
after_values.append(ENDING_WS_MATCH(arg_value)[0])
|
|
219
|
+
before_values.append(STARTING_WS_MATCH(arg_value)[0]) # type: ignore
|
|
220
|
+
after_values.append(ENDING_WS_MATCH(arg_value)[0]) # type: ignore
|
|
221
221
|
pre_name_ws_mode = mode(before_names)
|
|
222
222
|
name_length_mode = mode(name_lengths)
|
|
223
223
|
post_value_ws_mode = mode(
|
|
224
|
-
[SPACE_AFTER_SEARCH(self.string)[0]] + after_values[1:]
|
|
224
|
+
[SPACE_AFTER_SEARCH(self.string)[0]] + after_values[1:] # type: ignore
|
|
225
225
|
)
|
|
226
226
|
pre_value_ws_mode = mode(before_values)
|
|
227
227
|
else:
|
|
@@ -232,26 +232,25 @@ class Template(SubWikiTextWithArgs):
|
|
|
232
232
|
addstring = '|' + value
|
|
233
233
|
else:
|
|
234
234
|
if preserve_spacing:
|
|
235
|
-
# noinspection PyUnboundLocalVariable
|
|
236
235
|
addstring = (
|
|
237
236
|
'|'
|
|
238
|
-
+ (pre_name_ws_mode + name.strip(WS)).ljust(
|
|
239
|
-
name_length_mode
|
|
237
|
+
+ (pre_name_ws_mode + name.strip(WS)).ljust( # type: ignore
|
|
238
|
+
name_length_mode # type: ignore
|
|
240
239
|
)
|
|
241
240
|
+ '='
|
|
242
|
-
+ pre_value_ws_mode
|
|
241
|
+
+ pre_value_ws_mode # type: ignore
|
|
243
242
|
+ value
|
|
244
|
-
+ post_value_ws_mode
|
|
243
|
+
+ post_value_ws_mode # type: ignore
|
|
245
244
|
)
|
|
246
245
|
else:
|
|
247
246
|
addstring = '|' + name + '=' + value
|
|
248
247
|
# Place the addstring in the right position.
|
|
249
248
|
if before:
|
|
250
249
|
arg = get_arg(before, args)
|
|
251
|
-
arg.insert(0, addstring)
|
|
250
|
+
arg.insert(0, addstring) # type: ignore
|
|
252
251
|
elif after:
|
|
253
252
|
arg = get_arg(after, args)
|
|
254
|
-
arg.insert(len(arg.string), addstring)
|
|
253
|
+
arg.insert(len(arg.string), addstring) # type: ignore
|
|
255
254
|
else:
|
|
256
255
|
if args and not positional:
|
|
257
256
|
arg = args[0]
|
|
@@ -263,9 +262,9 @@ class Template(SubWikiTextWithArgs):
|
|
|
263
262
|
# noinspection PyUnboundLocalVariable
|
|
264
263
|
arg[0 : len(arg_string)] = (
|
|
265
264
|
arg.string.rstrip(WS)
|
|
266
|
-
+ post_value_ws_mode
|
|
265
|
+
+ post_value_ws_mode # type: ignore
|
|
267
266
|
+ addstring.rstrip(WS)
|
|
268
|
-
+ after_values[0]
|
|
267
|
+
+ after_values[0] # type: ignore
|
|
269
268
|
)
|
|
270
269
|
else:
|
|
271
270
|
arg.insert(len(arg_string), addstring)
|
|
@@ -9,13 +9,11 @@ from ._spans import TypeToSpans
|
|
|
9
9
|
from ._wikitext import EXTERNAL_LINK_FINDITER, SubWikiText
|
|
10
10
|
|
|
11
11
|
# See includes/parser/BlockLevelPass.php for how MW parses list blocks.
|
|
12
|
-
SUBLIST_PATTERN = (
|
|
13
|
-
|
|
14
|
-
)
|
|
15
|
-
SUBLIST_WITH_SECOND_PATTERN = ( # noqa
|
|
12
|
+
SUBLIST_PATTERN = rb'(?>^' rb'(?&pattern)' rb'[:;#*].*+' rb'(?>\n|\Z)' rb')*+'
|
|
13
|
+
SUBLIST_WITH_SECOND_PATTERN = (
|
|
16
14
|
rb'[*#;:].*+(?>\n|\Z)' rb'(?>' rb'(?&pattern)[*#;:].*+(?>\n|\Z)' rb')*+'
|
|
17
15
|
)
|
|
18
|
-
LIST_PATTERN_FORMAT = (
|
|
16
|
+
LIST_PATTERN_FORMAT = (
|
|
19
17
|
rb'(?<fullitem>^'
|
|
20
18
|
rb'(?<pattern>{pattern})'
|
|
21
19
|
rb'(?>'
|
|
@@ -38,7 +36,7 @@ LIST_PATTERN_FORMAT = ( # noqa
|
|
|
38
36
|
class WikiList(SubWikiText):
|
|
39
37
|
"""Class to represent ordered, unordered, and definition lists."""
|
|
40
38
|
|
|
41
|
-
__slots__ = '
|
|
39
|
+
__slots__ = '_match_cache', 'pattern'
|
|
42
40
|
|
|
43
41
|
def __init__(
|
|
44
42
|
self,
|
|
@@ -202,7 +202,7 @@ class WikiText:
|
|
|
202
202
|
# The following class attribute acts as a default value.
|
|
203
203
|
_type = 'WikiText'
|
|
204
204
|
|
|
205
|
-
__slots__ = '
|
|
205
|
+
__slots__ = '_lststr', '_span_data', '_type_to_spans'
|
|
206
206
|
|
|
207
207
|
def __init__(
|
|
208
208
|
self,
|
|
@@ -265,7 +265,7 @@ class WikiText:
|
|
|
265
265
|
return self.string
|
|
266
266
|
|
|
267
267
|
def __repr__(self) -> str:
|
|
268
|
-
return f'{type(self).__name__}({
|
|
268
|
+
return f'{type(self).__name__}({self.string!r})'
|
|
269
269
|
|
|
270
270
|
def __contains__(self, value: str | WikiText) -> bool:
|
|
271
271
|
"""Return True if parsed_wikitext is inside self. False otherwise.
|
|
@@ -307,9 +307,7 @@ class WikiText:
|
|
|
307
307
|
return self._lststr[0][self._span_data[1] + start]
|
|
308
308
|
s, e, _, _ = self._span_data
|
|
309
309
|
return self._lststr[0][
|
|
310
|
-
s
|
|
311
|
-
if start is None
|
|
312
|
-
else (s + start if start >= 0 else e + start) : e
|
|
310
|
+
(s + start if start >= 0 else e + start) : e
|
|
313
311
|
if stop is None
|
|
314
312
|
else (s + stop if stop >= 0 else e + stop) : step
|
|
315
313
|
]
|
|
@@ -663,7 +661,7 @@ class WikiText:
|
|
|
663
661
|
|
|
664
662
|
if callable(replace_templates):
|
|
665
663
|
for template in parsed.templates:
|
|
666
|
-
b, e = template._span_data[:2]
|
|
664
|
+
b, e = template._span_data[:2]
|
|
667
665
|
if lst[b] is None: # overwritten
|
|
668
666
|
continue
|
|
669
667
|
lst[b] = replace_templates(template)
|
|
@@ -699,7 +697,7 @@ class WikiText:
|
|
|
699
697
|
if replace_bolds_and_italics:
|
|
700
698
|
for i in parsed.get_bolds_and_italics():
|
|
701
699
|
b, e = i.span
|
|
702
|
-
ib, ie = i._match.span(1) #
|
|
700
|
+
ib, ie = i._match.span(1) # text span
|
|
703
701
|
remove(b, b + ib)
|
|
704
702
|
remove(b + ie, e)
|
|
705
703
|
if replace_parameters:
|
|
@@ -714,7 +712,7 @@ class WikiText:
|
|
|
714
712
|
if replace_tags:
|
|
715
713
|
for t in parsed.get_tags():
|
|
716
714
|
b, e = t.span
|
|
717
|
-
cb, ce = t._match.span('contents')
|
|
715
|
+
cb, ce = t._match.span('contents')
|
|
718
716
|
if cb != -1: # not a self-closing tag
|
|
719
717
|
remove(b, b + cb)
|
|
720
718
|
remove(b + ce, e)
|
|
@@ -725,23 +723,23 @@ class WikiText:
|
|
|
725
723
|
b, e = w.span
|
|
726
724
|
title = w.title
|
|
727
725
|
if title[:1] != ':' and (
|
|
728
|
-
title.partition(':')[2].rpartition('.')[2]
|
|
726
|
+
title.partition(':')[2].rpartition('.')[2].lower()
|
|
729
727
|
in KNOWN_FILE_EXTENSIONS
|
|
730
728
|
):
|
|
731
729
|
remove(b, e) # image
|
|
732
730
|
else:
|
|
733
|
-
tb, te = w._match.span(4) #
|
|
731
|
+
tb, te = w._match.span(4) # text span
|
|
734
732
|
if tb != -1:
|
|
735
733
|
remove(b, b + tb)
|
|
736
734
|
remove(b + te, e)
|
|
737
735
|
else:
|
|
738
|
-
tb, te = w._match.span(1) #
|
|
736
|
+
tb, te = w._match.span(1) # target span
|
|
739
737
|
remove(b, b + tb)
|
|
740
738
|
remove(b + te, e)
|
|
741
739
|
|
|
742
740
|
if callable(replace_tables):
|
|
743
741
|
for table in parsed.get_tables():
|
|
744
|
-
b, e = table._span_data[:2]
|
|
742
|
+
b, e = table._span_data[:2]
|
|
745
743
|
if lst[b] is None: # overwritten
|
|
746
744
|
continue
|
|
747
745
|
lst[b] = replace_tables(
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|