wikitextparser 0.55.9__tar.gz → 0.55.11__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.
Files changed (31) hide show
  1. {wikitextparser-0.55.9 → wikitextparser-0.55.11}/.github/workflows/tests.yml +5 -5
  2. {wikitextparser-0.55.9 → wikitextparser-0.55.11}/CHANGELOG.rst +9 -1
  3. {wikitextparser-0.55.9 → wikitextparser-0.55.11}/PKG-INFO +1 -1
  4. {wikitextparser-0.55.9 → wikitextparser-0.55.11}/pyproject.toml +3 -3
  5. {wikitextparser-0.55.9 → wikitextparser-0.55.11}/wikitextparser/__init__.py +1 -1
  6. {wikitextparser-0.55.9 → wikitextparser-0.55.11}/wikitextparser/_argument.py +0 -1
  7. {wikitextparser-0.55.9 → wikitextparser-0.55.11}/wikitextparser/_config.py +0 -1
  8. {wikitextparser-0.55.9 → wikitextparser-0.55.11}/wikitextparser/_parser_function.py +0 -1
  9. {wikitextparser-0.55.9 → wikitextparser-0.55.11}/wikitextparser/_spans.py +1 -0
  10. {wikitextparser-0.55.9 → wikitextparser-0.55.11}/wikitextparser/_table.py +3 -3
  11. {wikitextparser-0.55.9 → wikitextparser-0.55.11}/wikitextparser/_tag.py +0 -1
  12. {wikitextparser-0.55.9 → wikitextparser-0.55.11}/wikitextparser/_template.py +0 -1
  13. {wikitextparser-0.55.9 → wikitextparser-0.55.11}/wikitextparser/_wikilink.py +0 -1
  14. {wikitextparser-0.55.9 → wikitextparser-0.55.11}/wikitextparser/_wikilist.py +0 -1
  15. {wikitextparser-0.55.9 → wikitextparser-0.55.11}/wikitextparser/_wikitext.py +16 -14
  16. {wikitextparser-0.55.9 → wikitextparser-0.55.11}/.coveragerc +0 -0
  17. {wikitextparser-0.55.9 → wikitextparser-0.55.11}/.gitignore +0 -0
  18. {wikitextparser-0.55.9 → wikitextparser-0.55.11}/.readthedocs.yaml +0 -0
  19. {wikitextparser-0.55.9 → wikitextparser-0.55.11}/LICENSE.md +0 -0
  20. {wikitextparser-0.55.9 → wikitextparser-0.55.11}/README.rst +0 -0
  21. {wikitextparser-0.55.9 → wikitextparser-0.55.11}/docs/CHANGELOG.rst +0 -0
  22. {wikitextparser-0.55.9 → wikitextparser-0.55.11}/docs/Makefile +0 -0
  23. {wikitextparser-0.55.9 → wikitextparser-0.55.11}/docs/README.rst +0 -0
  24. {wikitextparser-0.55.9 → wikitextparser-0.55.11}/docs/conf.py +0 -0
  25. {wikitextparser-0.55.9 → wikitextparser-0.55.11}/docs/index.rst +0 -0
  26. {wikitextparser-0.55.9 → wikitextparser-0.55.11}/docs/make.bat +0 -0
  27. {wikitextparser-0.55.9 → wikitextparser-0.55.11}/wikitextparser/_cell.py +0 -0
  28. {wikitextparser-0.55.9 → wikitextparser-0.55.11}/wikitextparser/_comment_bold_italic.py +0 -0
  29. {wikitextparser-0.55.9 → wikitextparser-0.55.11}/wikitextparser/_externallink.py +0 -0
  30. {wikitextparser-0.55.9 → wikitextparser-0.55.11}/wikitextparser/_parameter.py +0 -0
  31. {wikitextparser-0.55.9 → wikitextparser-0.55.11}/wikitextparser/_section.py +0 -0
@@ -13,16 +13,16 @@ jobs:
13
13
  strategy:
14
14
  matrix:
15
15
  os: [ubuntu-latest, windows-latest, macos-latest]
16
- python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
16
+ python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
17
17
  env:
18
18
  OS: ${{ matrix.os }}
19
19
  PYTHON: ${{ matrix.python-version }}
20
20
  runs-on: ${{ matrix.os }}
21
21
  steps:
22
22
  - name: Checkout repo
23
- uses: actions/checkout@v3
23
+ uses: actions/checkout@v4
24
24
  - name: Set Up Python ${{ matrix.python-version }}
25
- uses: actions/setup-python@v4
25
+ uses: actions/setup-python@v5
26
26
  with:
27
27
  python-version: ${{ matrix.python-version }}
28
28
  - name: Display Python version
@@ -35,8 +35,8 @@ jobs:
35
35
  run: pytest --cov=wikitextparser tests --cov-report=xml --cov-fail-under=80
36
36
  - name: Upload coverage to Codecov
37
37
  # https://github.com/codecov/codecov-action
38
- uses: codecov/codecov-action@v3
38
+ uses: codecov/codecov-action@v4
39
39
  with:
40
40
  files: ./coverage.xml
41
41
  env_vars: OS,PYTHON
42
- fail_ci_if_error: false
42
+ token: ${{ secrets.CODECOV_TOKEN }}
@@ -1,6 +1,14 @@
1
+ v0.55.11
2
+ --------
3
+ * Performance improvements in ``__setitem__``/``__delitem__`` and ``pformat``/``plain_text`` methods. (#131)
4
+
5
+ v0.55.10
6
+ --------
7
+ * Fixed a bug in ``plain_text`` causing ``IndexError`` when using a custom function to replace ``templates``/``parser_functions``.
8
+
1
9
  v0.55.9
2
10
  -------
3
- - Fixed a bug in plain text not detecting images with multiple dots correctly. (#129)
11
+ - Fixed a bug in ``plain_text`` not detecting images with multiple dots correctly. (#129)
4
12
 
5
13
  v0.55.8
6
14
  -------
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: wikitextparser
3
- Version: 0.55.9
3
+ Version: 0.55.11
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>
@@ -48,12 +48,12 @@ exclude = ['tests/', 'doc/', 'dev/']
48
48
  [tool.ruff]
49
49
  line-length = 79
50
50
  format.quote-style = 'single'
51
- isort.combine-as-imports = true
52
- extend-select = [
51
+ lint.isort.combine-as-imports = true
52
+ lint.extend-select = [
53
53
  'I', # isort
54
54
  'UP', # pyupgrade
55
55
  ]
56
- ignore = [
56
+ lint.ignore = [
57
57
  'UP027', # list comprehensions are faster than generator expressions
58
58
  'E721', # Do not compare types, use `isinstance()`
59
59
  ]
@@ -1,5 +1,5 @@
1
1
  # Scheme: [N!]N(.N)*[{a|b|rc}N][.postN][.devN]
2
- __version__ = '0.55.9'
2
+ __version__ = '0.55.11'
3
3
 
4
4
  from . import _wikitext
5
5
  from ._argument import Argument # noqa: F401
@@ -13,7 +13,6 @@ ARG_SHADOW_FULLMATCH = rc(
13
13
 
14
14
 
15
15
  class Argument(SubWikiText):
16
-
17
16
  """Create a new Argument Object.
18
17
 
19
18
  Note that in MediaWiki documentation `arguments` are (also) called
@@ -1,6 +1,5 @@
1
1
  """Utilities to override default configurations."""
2
2
 
3
-
4
3
  from collections import defaultdict as _defaultdict
5
4
  from typing import Iterable as _Iterable
6
5
 
@@ -11,7 +11,6 @@ PF_NAME_ARGS_FULLMATCH = rc(
11
11
 
12
12
 
13
13
  class SubWikiTextWithArgs(SubWikiText):
14
-
15
14
  """Define common attributes for `Template` and `ParserFunction`."""
16
15
 
17
16
  __slots__ = ()
@@ -1,4 +1,5 @@
1
1
  """Define the functions required for parsing wikitext into spans."""
2
+
2
3
  from functools import partial
3
4
  from typing import Callable, Dict, Optional
4
5
 
@@ -296,9 +296,9 @@ class Table(SubWikiTextWithAttrs):
296
296
  m = CAPTION_MATCH(shadow)
297
297
  if m:
298
298
  s = m.end('attrs')
299
- self[
300
- s if s != -1 else m.end('preattrs') : m.end('caption')
301
- ] = newcaption
299
+ self[s if s != -1 else m.end('preattrs') : m.end('caption')] = (
300
+ newcaption
301
+ )
302
302
  return
303
303
  # There is no caption. Create one.
304
304
  h, s, t = shadow.partition(b'\n')
@@ -45,7 +45,6 @@ TAG_FULLMATCH = rc(
45
45
 
46
46
 
47
47
  class SubWikiTextWithAttrs(SubWikiText):
48
-
49
48
  """Define a class for SubWikiText objects that have attributes.
50
49
 
51
50
  Any class that is going to inherit from SubWikiTextWithAttrs should provide
@@ -18,7 +18,6 @@ T = TypeVar('T')
18
18
 
19
19
 
20
20
  class Template(SubWikiTextWithArgs):
21
-
22
21
  """Convert strings to Template objects.
23
22
 
24
23
  The string should start with {{ and end with }}.
@@ -1,6 +1,5 @@
1
1
  """Define the WikiLink class."""
2
2
 
3
-
4
3
  from typing import List, Optional, Tuple
5
4
 
6
5
  from regex import DOTALL
@@ -33,7 +33,6 @@ LIST_PATTERN_FORMAT = ( # noqa
33
33
 
34
34
 
35
35
  class WikiList(SubWikiText):
36
-
37
36
  """Class to represent ordered, unordered, and definition lists."""
38
37
 
39
38
  __slots__ = 'pattern', '_match_cache'
@@ -488,6 +488,7 @@ class WikiText:
488
488
  # Note: The following algorithm won't work correctly if spans
489
489
  # are not sorted.
490
490
  # Note: No span should be removed from _type_to_spans.
491
+ rmlength = rmstop - rmstart
491
492
  for spans in self._type_to_spans.values():
492
493
  i = len(spans) - 1
493
494
  while i >= 0:
@@ -495,7 +496,6 @@ class WikiText:
495
496
  s, e, _, b = span = spans[i]
496
497
  if rmstop <= s:
497
498
  # rmstart <= rmstop <= s <= e
498
- rmlength = rmstop - rmstart
499
499
  # todo
500
500
  span[:] = s - rmlength, e - rmlength, None, None
501
501
  i -= 1
@@ -508,7 +508,7 @@ class WikiText:
508
508
  if rmstop < e:
509
509
  # rmstart < s <= rmstop < e
510
510
  # todo: update byte_array instead
511
- span[:] = rmstart, e + rmstart - rmstop, None, None
511
+ span[:] = rmstart, e - rmlength, None, None
512
512
  i -= 1
513
513
  if i < 0:
514
514
  break
@@ -531,7 +531,7 @@ class WikiText:
531
531
  s, e, _, _ = span = spans[i]
532
532
  continue
533
533
  # s <= rmstart <= rmstop <= e
534
- span[1] -= rmstop - rmstart
534
+ span[1] -= rmlength
535
535
  span[2] = None
536
536
  # todo: update bytearray instead
537
537
  span[3] = None
@@ -626,7 +626,9 @@ class WikiText:
626
626
  return {
627
627
  type_: [
628
628
  [s - ss, e - ss, m, ba[:] if ba is not None else None]
629
- for s, e, m, ba in spans[bisect_left(spans, [ss]) :]
629
+ for s, e, m, ba in spans[
630
+ bisect_left(spans, [ss]) : bisect_left(spans, [se])
631
+ ]
630
632
  if e <= se
631
633
  ]
632
634
  for type_, spans in self._type_to_spans.items()
@@ -677,7 +679,7 @@ class WikiText:
677
679
  remove(b, e)
678
680
 
679
681
  if callable(replace_templates):
680
- for template in self.templates:
682
+ for template in parsed.templates:
681
683
  b, e = template._span_data[:2] # noqa
682
684
  if lst[b] is None: # overwritten
683
685
  continue
@@ -688,7 +690,7 @@ class WikiText:
688
690
  remove(b, e)
689
691
 
690
692
  if callable(replace_parser_functions):
691
- for pf in self.parser_functions:
693
+ for pf in parsed.parser_functions:
692
694
  b, e = pf._span_data[:2]
693
695
  if lst[b] is None: # already overwritten
694
696
  continue
@@ -1022,8 +1024,8 @@ class WikiText:
1022
1024
  odd_bold_italics = False
1023
1025
  shadow_copy = self._shadow[:]
1024
1026
  append_match = bold_matches.append
1025
- for match in BOLD_ITALIC_FINDITER(shadow_copy):
1026
- if match[4] is not None: # newline or string end
1027
+ for m in BOLD_ITALIC_FINDITER(shadow_copy):
1028
+ if m[4] is not None: # newline or string end
1027
1029
  if (
1028
1030
  odd_italics is True
1029
1031
  and (len(bold_matches) + odd_bold_italics) % 2
@@ -1053,17 +1055,17 @@ class WikiText:
1053
1055
  bold_matches.clear()
1054
1056
  odd_italics = False
1055
1057
  continue
1056
- if match[2] is None: # italic
1058
+ if m[2] is None: # italic
1057
1059
  odd_italics ^= True
1058
1060
  continue
1059
- if match[3] is None: # bold
1060
- s, e = match.span(1)
1061
+ if m[3] is None: # bold
1062
+ s, e = m.span(1)
1061
1063
  if s != e: # four apostrophes, hide the first one
1062
1064
  shadow_copy[s] = 95 # _
1063
- append_match(match)
1065
+ append_match(m)
1064
1066
  continue
1065
1067
  # bold-italic
1066
- s, e = match.span(1)
1068
+ s, e = m.span(1)
1067
1069
  es = e - s
1068
1070
  if es: # more than 5 apostrophes, hide the previous ones
1069
1071
  shadow_copy[s:e] = b'_' * es
@@ -1338,7 +1340,7 @@ class WikiText:
1338
1340
 
1339
1341
  if level is not None:
1340
1342
  section_spans = compress(
1341
- section_spans, [l == level for l in levels]
1343
+ section_spans, [lvl == level for lvl in levels]
1342
1344
  )
1343
1345
 
1344
1346
  return self._section_spans_to_sections(section_spans, shadow)