jusText 3.0.0__tar.gz → 3.0.1__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 (125) hide show
  1. {jusText-3.0.0 → justext-3.0.1}/CHANGELOG.rst +4 -0
  2. {jusText-3.0.0/jusText.egg-info → justext-3.0.1}/PKG-INFO +7 -4
  3. {jusText-3.0.0 → justext-3.0.1/jusText.egg-info}/PKG-INFO +7 -4
  4. {jusText-3.0.0 → justext-3.0.1}/jusText.egg-info/SOURCES.txt +8 -1
  5. {jusText-3.0.0 → justext-3.0.1}/jusText.egg-info/requires.txt +1 -1
  6. {jusText-3.0.0 → justext-3.0.1}/justext/__init__.py +1 -1
  7. {jusText-3.0.0 → justext-3.0.1}/setup.cfg +1 -1
  8. {jusText-3.0.0 → justext-3.0.1}/setup.py +2 -2
  9. justext-3.0.1/tests/test_classify_paragraphs.py +88 -0
  10. justext-3.0.1/tests/test_core.py +7 -0
  11. justext-3.0.1/tests/test_dom_utils.py +163 -0
  12. justext-3.0.1/tests/test_html_encoding.py +134 -0
  13. justext-3.0.1/tests/test_paths.py +81 -0
  14. justext-3.0.1/tests/test_sax.py +214 -0
  15. justext-3.0.1/tests/test_utils.py +94 -0
  16. {jusText-3.0.0 → justext-3.0.1}/LICENSE.rst +0 -0
  17. {jusText-3.0.0 → justext-3.0.1}/MANIFEST.in +0 -0
  18. {jusText-3.0.0 → justext-3.0.1}/README.rst +0 -0
  19. {jusText-3.0.0 → justext-3.0.1}/jusText.egg-info/dependency_links.txt +0 -0
  20. {jusText-3.0.0 → justext-3.0.1}/jusText.egg-info/top_level.txt +0 -0
  21. {jusText-3.0.0 → justext-3.0.1}/justext/__main__.py +0 -0
  22. {jusText-3.0.0 → justext-3.0.1}/justext/_compat.py +0 -0
  23. {jusText-3.0.0 → justext-3.0.1}/justext/core.py +0 -0
  24. {jusText-3.0.0 → justext-3.0.1}/justext/paragraph.py +0 -0
  25. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Afrikaans.txt +0 -0
  26. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Albanian.txt +0 -0
  27. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Arabic.txt +0 -0
  28. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Aragonese.txt +0 -0
  29. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Armenian.txt +0 -0
  30. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Aromanian.txt +0 -0
  31. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Asturian.txt +0 -0
  32. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Azerbaijani.txt +0 -0
  33. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Basque.txt +0 -0
  34. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Belarusian.txt +0 -0
  35. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Belarusian_Taraskievica.txt +0 -0
  36. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Bengali.txt +0 -0
  37. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Bishnupriya_Manipuri.txt +0 -0
  38. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Bosnian.txt +0 -0
  39. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Breton.txt +0 -0
  40. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Bulgarian.txt +0 -0
  41. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Catalan.txt +0 -0
  42. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Cebuano.txt +0 -0
  43. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Chuvash.txt +0 -0
  44. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Croatian.txt +0 -0
  45. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Czech.txt +0 -0
  46. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Danish.txt +0 -0
  47. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Dutch.txt +0 -0
  48. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/English.txt +0 -0
  49. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Esperanto.txt +0 -0
  50. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Estonian.txt +0 -0
  51. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Finnish.txt +0 -0
  52. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/French.txt +0 -0
  53. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Galician.txt +0 -0
  54. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Georgian.txt +0 -0
  55. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/German.txt +0 -0
  56. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Greek.txt +0 -0
  57. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Gujarati.txt +0 -0
  58. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Haitian.txt +0 -0
  59. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Hebrew.txt +0 -0
  60. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Hindi.txt +0 -0
  61. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Hungarian.txt +0 -0
  62. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Icelandic.txt +0 -0
  63. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Ido.txt +0 -0
  64. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Igbo.txt +0 -0
  65. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Indonesian.txt +0 -0
  66. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Irish.txt +0 -0
  67. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Italian.txt +0 -0
  68. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Javanese.txt +0 -0
  69. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Kannada.txt +0 -0
  70. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Kazakh.txt +0 -0
  71. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Korean.txt +0 -0
  72. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Kurdish.txt +0 -0
  73. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Kyrgyz.txt +0 -0
  74. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Latin.txt +0 -0
  75. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Latvian.txt +0 -0
  76. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Lithuanian.txt +0 -0
  77. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Lombard.txt +0 -0
  78. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Low_Saxon.txt +0 -0
  79. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Luxembourgish.txt +0 -0
  80. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Macedonian.txt +0 -0
  81. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Malay.txt +0 -0
  82. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Malayalam.txt +0 -0
  83. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Maltese.txt +0 -0
  84. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Marathi.txt +0 -0
  85. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Neapolitan.txt +0 -0
  86. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Nepali.txt +0 -0
  87. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Newar.txt +0 -0
  88. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Norwegian_Bokmal.txt +0 -0
  89. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Norwegian_Nynorsk.txt +0 -0
  90. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Occitan.txt +0 -0
  91. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Persian.txt +0 -0
  92. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Piedmontese.txt +0 -0
  93. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Polish.txt +0 -0
  94. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Portuguese.txt +0 -0
  95. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Quechua.txt +0 -0
  96. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Romanian.txt +0 -0
  97. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Russian.txt +0 -0
  98. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Samogitian.txt +0 -0
  99. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Serbian.txt +0 -0
  100. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Serbo_Croatian.txt +0 -0
  101. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Sicilian.txt +0 -0
  102. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Simple_English.txt +0 -0
  103. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Slovak.txt +0 -0
  104. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Slovenian.txt +0 -0
  105. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Spanish.txt +0 -0
  106. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Sundanese.txt +0 -0
  107. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Swahili.txt +0 -0
  108. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Swedish.txt +0 -0
  109. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Tagalog.txt +0 -0
  110. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Tamil.txt +0 -0
  111. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Telugu.txt +0 -0
  112. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Turkish.txt +0 -0
  113. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Turkmen.txt +0 -0
  114. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Ukrainian.txt +0 -0
  115. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Urdu.txt +0 -0
  116. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Uzbek.txt +0 -0
  117. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Vietnamese.txt +0 -0
  118. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Volapuk.txt +0 -0
  119. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Walloon.txt +0 -0
  120. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Waray_Waray.txt +0 -0
  121. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Welsh.txt +0 -0
  122. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/West_Frisian.txt +0 -0
  123. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Western_Panjabi.txt +0 -0
  124. {jusText-3.0.0 → justext-3.0.1}/justext/stoplists/Yoruba.txt +0 -0
  125. {jusText-3.0.0 → justext-3.0.1}/justext/utils.py +0 -0
@@ -3,6 +3,10 @@
3
3
  Changelog for jusText
4
4
  =====================
5
5
 
6
+ 3.0.1 (2024-05-09)
7
+ ------------------
8
+ - *BUG FIX:* Fix issue with new version of lxml `#48 <https://github.com/miso-belica/jusText/pull/48>`_.
9
+
6
10
  3.0.0 (2021-10-21)
7
11
  ------------------
8
12
  - *INCOMPATIBLE CHANGE:* Dropped support for Python 3.4 and below.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: jusText
3
- Version: 3.0.0
3
+ Version: 3.0.1
4
4
  Summary: Heuristic based boilerplate removal tool
5
5
  Home-page: https://github.com/miso-belica/jusText
6
6
  Author: Jan Pomikálek
@@ -8,7 +8,6 @@ Author-email: jan.pomikalek@gmail.com
8
8
  Maintainer: Michal Belica
9
9
  Maintainer-email: miso.belica@gmail.com
10
10
  License: The BSD 2-Clause License
11
- Platform: UNKNOWN
12
11
  Classifier: Development Status :: 5 - Production/Stable
13
12
  Classifier: Intended Audience :: Developers
14
13
  Classifier: Natural Language :: English
@@ -30,6 +29,8 @@ Classifier: Topic :: Software Development :: Pre-processors
30
29
  Classifier: Topic :: Text Processing :: Filters
31
30
  Classifier: Topic :: Text Processing :: Markup :: HTML
32
31
  License-File: LICENSE.rst
32
+ Requires-Dist: lxml[html_clean]>=4.4.2
33
+ Requires-Dist: backports.functools-lru-cache; python_version < "3.2"
33
34
 
34
35
  .. _jusText: http://code.google.com/p/justext/
35
36
  .. _Python: http://www.python.org/
@@ -147,6 +148,10 @@ This software has been developed at the `Natural Language Processing Centre`_ of
147
148
  Changelog for jusText
148
149
  =====================
149
150
 
151
+ 3.0.1 (2024-05-09)
152
+ ------------------
153
+ - *BUG FIX:* Fix issue with new version of lxml `#48 <https://github.com/miso-belica/jusText/pull/48>`_.
154
+
150
155
  3.0.0 (2021-10-21)
151
156
  ------------------
152
157
  - *INCOMPATIBLE CHANGE:* Dropped support for Python 3.4 and below.
@@ -191,5 +196,3 @@ Changelog for jusText
191
196
  1.1.0 (2011-03-09)
192
197
  ------------------
193
198
  - First public release.
194
-
195
-
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: jusText
3
- Version: 3.0.0
3
+ Version: 3.0.1
4
4
  Summary: Heuristic based boilerplate removal tool
5
5
  Home-page: https://github.com/miso-belica/jusText
6
6
  Author: Jan Pomikálek
@@ -8,7 +8,6 @@ Author-email: jan.pomikalek@gmail.com
8
8
  Maintainer: Michal Belica
9
9
  Maintainer-email: miso.belica@gmail.com
10
10
  License: The BSD 2-Clause License
11
- Platform: UNKNOWN
12
11
  Classifier: Development Status :: 5 - Production/Stable
13
12
  Classifier: Intended Audience :: Developers
14
13
  Classifier: Natural Language :: English
@@ -30,6 +29,8 @@ Classifier: Topic :: Software Development :: Pre-processors
30
29
  Classifier: Topic :: Text Processing :: Filters
31
30
  Classifier: Topic :: Text Processing :: Markup :: HTML
32
31
  License-File: LICENSE.rst
32
+ Requires-Dist: lxml[html_clean]>=4.4.2
33
+ Requires-Dist: backports.functools-lru-cache; python_version < "3.2"
33
34
 
34
35
  .. _jusText: http://code.google.com/p/justext/
35
36
  .. _Python: http://www.python.org/
@@ -147,6 +148,10 @@ This software has been developed at the `Natural Language Processing Centre`_ of
147
148
  Changelog for jusText
148
149
  =====================
149
150
 
151
+ 3.0.1 (2024-05-09)
152
+ ------------------
153
+ - *BUG FIX:* Fix issue with new version of lxml `#48 <https://github.com/miso-belica/jusText/pull/48>`_.
154
+
150
155
  3.0.0 (2021-10-21)
151
156
  ------------------
152
157
  - *INCOMPATIBLE CHANGE:* Dropped support for Python 3.4 and below.
@@ -191,5 +196,3 @@ Changelog for jusText
191
196
  1.1.0 (2011-03-09)
192
197
  ------------------
193
198
  - First public release.
194
-
195
-
@@ -114,4 +114,11 @@ justext/stoplists/Waray_Waray.txt
114
114
  justext/stoplists/Welsh.txt
115
115
  justext/stoplists/West_Frisian.txt
116
116
  justext/stoplists/Western_Panjabi.txt
117
- justext/stoplists/Yoruba.txt
117
+ justext/stoplists/Yoruba.txt
118
+ tests/test_classify_paragraphs.py
119
+ tests/test_core.py
120
+ tests/test_dom_utils.py
121
+ tests/test_html_encoding.py
122
+ tests/test_paths.py
123
+ tests/test_sax.py
124
+ tests/test_utils.py
@@ -1,4 +1,4 @@
1
- lxml>=4.4.2
1
+ lxml[html_clean]>=4.4.2
2
2
 
3
3
  [:python_version < "3.2"]
4
4
  backports.functools-lru-cache
@@ -12,4 +12,4 @@ from .utils import get_stoplists, get_stoplist
12
12
  from .core import justext
13
13
 
14
14
 
15
- __version__ = "3.0.0"
15
+ __version__ = "3.0.1"
@@ -1,5 +1,5 @@
1
1
  [bumpversion]
2
- current_version = 3.0.0
2
+ current_version = 3.0.1
3
3
  commit = true
4
4
  tag = false
5
5
 
@@ -21,7 +21,7 @@ with open("README.rst") as readme:
21
21
 
22
22
  setup(
23
23
  name="jusText",
24
- version="3.0.0",
24
+ version="3.0.1",
25
25
  description="Heuristic based boilerplate removal tool",
26
26
  long_description=long_description,
27
27
  author="Jan Pomikálek",
@@ -31,7 +31,7 @@ setup(
31
31
  url="https://github.com/miso-belica/jusText",
32
32
  license="The BSD 2-Clause License",
33
33
  install_requires=[
34
- 'lxml >= 4.4.2',
34
+ 'lxml[html_clean] >= 4.4.2',
35
35
  'backports.functools-lru-cache; python_version < "3.2"'
36
36
  ],
37
37
  tests_require=[
@@ -0,0 +1,88 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ from __future__ import absolute_import
4
+ from __future__ import division, print_function, unicode_literals
5
+
6
+ from justext.core import PathInfo, classify_paragraphs
7
+ from justext.paragraph import Paragraph
8
+
9
+
10
+ class TestClassifyParagraphs():
11
+
12
+ def _paragraph(self, **kwargs):
13
+ path = PathInfo().append("body").append("p")
14
+ paragraph = Paragraph(path)
15
+
16
+ for n, v in kwargs.items():
17
+ if n == "text":
18
+ paragraph.append_text(v)
19
+ else:
20
+ setattr(paragraph, n, v)
21
+
22
+ return paragraph
23
+
24
+ def test_max_link_density(self):
25
+ paragraphs = [
26
+ self._paragraph(text="0123456789"*2, chars_count_in_links=0),
27
+ self._paragraph(text="0123456789"*2, chars_count_in_links=20),
28
+ self._paragraph(text="0123456789"*8, chars_count_in_links=40),
29
+ self._paragraph(text="0123456789"*8, chars_count_in_links=39),
30
+ self._paragraph(text="0123456789"*8, chars_count_in_links=41),
31
+ ]
32
+
33
+ classify_paragraphs(paragraphs, (), max_link_density=0.5)
34
+
35
+ assert paragraphs[0].cf_class == "short"
36
+ assert paragraphs[1].cf_class == "bad"
37
+ assert paragraphs[2].cf_class == "bad"
38
+ assert paragraphs[3].cf_class == "bad"
39
+ assert paragraphs[4].cf_class == "bad"
40
+
41
+ def test_length_low(self):
42
+ paragraphs = [
43
+ self._paragraph(text="0 1 2 3 4 5 6 7 8 9"*2, chars_count_in_links=0),
44
+ self._paragraph(text="0 1 2 3 4 5 6 7 8 9"*2, chars_count_in_links=20),
45
+ ]
46
+
47
+ classify_paragraphs(paragraphs, (), max_link_density=1, length_low=1000)
48
+
49
+ assert paragraphs[0].cf_class == "short"
50
+ assert paragraphs[1].cf_class == "bad"
51
+
52
+ def test_stopwords_high(self):
53
+ paragraphs = [
54
+ self._paragraph(text="0 1 2 3 4 5 6 7 8 9"),
55
+ self._paragraph(text="0 1 2 3 4 5 6 7 8 9"*2),
56
+ ]
57
+
58
+ classify_paragraphs(
59
+ paragraphs,
60
+ ("0",),
61
+ max_link_density=1,
62
+ length_low=0,
63
+ stopwords_high=0,
64
+ length_high=20
65
+ )
66
+
67
+ assert paragraphs[0].cf_class == "neargood"
68
+ assert paragraphs[1].cf_class == "good"
69
+
70
+ def test_stopwords_low(self):
71
+ paragraphs = [
72
+ self._paragraph(text="0 0 0 0 1 2 3 4 5 6 7 8 9"),
73
+ self._paragraph(text="0 1 2 3 4 5 6 7 8 9"),
74
+ self._paragraph(text="1 2 3 4 5 6 7 8 9"),
75
+ ]
76
+
77
+ classify_paragraphs(
78
+ paragraphs,
79
+ ("0", "1",),
80
+ max_link_density=1,
81
+ length_low=0,
82
+ stopwords_high=1000,
83
+ stopwords_low=0.2
84
+ )
85
+
86
+ assert paragraphs[0].cf_class == "neargood"
87
+ assert paragraphs[1].cf_class == "neargood"
88
+ assert paragraphs[2].cf_class == "bad"
@@ -0,0 +1,7 @@
1
+ import justext
2
+
3
+
4
+ def test_words_should_be_split_by_br_tag():
5
+ paragraphs = justext.justext('abc<br/>def becoming abcdef', justext.get_stoplist("English"))
6
+
7
+ assert [p.text for p in paragraphs] == ["abc def becoming abcdef"]
@@ -0,0 +1,163 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ from __future__ import absolute_import
4
+ from __future__ import division, print_function, unicode_literals
5
+
6
+ import lxml.etree
7
+ import pytest
8
+
9
+ from lxml import html
10
+ from justext.core import preprocessor, html_to_dom
11
+
12
+
13
+ def test_remove_comments():
14
+ dom = html.fromstring(
15
+ '<html><!-- comment --><body>'
16
+ '<h1>Header</h1>'
17
+ '<!-- comment --> text'
18
+ '<p>footer'
19
+ '</body></html>'
20
+ )
21
+
22
+ expected = '<html><!-- comment --><body><h1>Header</h1><!-- comment --> text<p>footer</p></body></html>'
23
+ returned = html.tostring(dom).decode("utf8")
24
+ assert expected == returned
25
+
26
+ dom = preprocessor(dom)
27
+
28
+ expected = '<html><body><h1>Header</h1> text<p>footer</p></body></html>'
29
+ returned = html.tostring(dom).decode("utf8")
30
+ assert expected == returned
31
+
32
+
33
+ def test_remove_head_tag():
34
+ html_string = (
35
+ '<html><head><title>Title</title></head><body>'
36
+ '<h1>Header</h1>'
37
+ '<p><span>text</span></p>'
38
+ '<p>footer <em>like</em> a boss</p>'
39
+ '</body></html>'
40
+ )
41
+
42
+ dom = html.fromstring(html_string)
43
+ returned = html.tostring(dom).decode("utf8")
44
+ assert html_string == returned
45
+
46
+ dom = preprocessor(dom)
47
+ returned = html.tostring(dom).decode("utf8")
48
+ expected = (
49
+ '<html><body>'
50
+ '<h1>Header</h1>'
51
+ '<p><span>text</span></p>'
52
+ '<p>footer <em>like</em> a boss</p>'
53
+ '</body></html>'
54
+ )
55
+ assert expected == returned
56
+
57
+
58
+ def test_preprocess_simple_unicode_string():
59
+ html_string = (
60
+ '<html><head><title>Title</title></head><body>'
61
+ '<h1>Header</h1>'
62
+ '<p>pre<span>text</span>post<em>emph</em>popost</p>'
63
+ '<p>footer <em>like</em> a boss</p>'
64
+ '</body></html>'
65
+ )
66
+
67
+ dom = preprocessor(html_to_dom(html_string))
68
+ returned = html.tostring(dom).decode("utf8")
69
+ expected = (
70
+ '<html><body>'
71
+ '<h1>Header</h1>'
72
+ '<p>pre<span>text</span>post<em>emph</em>popost</p>'
73
+ '<p>footer <em>like</em> a boss</p>'
74
+ '</body></html>'
75
+ )
76
+ assert expected == returned
77
+
78
+
79
+ def test_preprocess_simple_bytes_string():
80
+ html_string = (
81
+ b'<html><head><title>Title</title></head><body>'
82
+ b'<h1>Header</h1>'
83
+ b'<p>pre<span>text</span>post<em>emph</em>popost</p>'
84
+ b'<p>footer <em>like</em> a boss</p>'
85
+ b' <!-- abcdefgh -->\n'
86
+ b'</body></html>'
87
+ )
88
+
89
+ dom = preprocessor(html_to_dom(html_string))
90
+ returned = html.tostring(dom).decode("utf8")
91
+ expected = (
92
+ '<html><body>'
93
+ '<h1>Header</h1>'
94
+ '<p>pre<span>text</span>post<em>emph</em>popost</p>'
95
+ '<p>footer <em>like</em> a boss</p>'
96
+ ' \n'
97
+ '</body></html>'
98
+ )
99
+ assert expected == returned
100
+
101
+
102
+ def test_preprocess_simple_unicode_xhtml_string_with_declaration():
103
+ html_string = (
104
+ '<?xml version="1.0" encoding="windows-1250"?>'
105
+ '<!DOCTYPE html>'
106
+ '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="sk" lang="sk">'
107
+ '<head>'
108
+ '<title>Hello World</title>'
109
+ '<meta http-equiv="imagetoolbar" content="no" />'
110
+ '<meta http-equiv="Content-Type" content="text/html; charset=windows-1250" />'
111
+ '</head>'
112
+ '<body id="index">'
113
+ '</body>'
114
+ '</html>'
115
+ )
116
+
117
+ dom = preprocessor(html_to_dom(html_string))
118
+ returned = html.tostring(dom).decode("utf8")
119
+ expected = (
120
+ '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="sk" lang="sk">'
121
+ '<body id="index">'
122
+ '</body>'
123
+ '</html>'
124
+ )
125
+ assert expected == returned
126
+
127
+
128
+ def test_preprocess_simple_bytes_xhtml_string_with_declaration():
129
+ html_string = (
130
+ b'<?xml version="1.0" encoding="windows-1250"?>'
131
+ b'<!DOCTYPE html>'
132
+ b'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="sk" lang="sk">'
133
+ b'<head>'
134
+ b'<title>Hello World</title>'
135
+ b'<meta http-equiv="imagetoolbar" content="no" />'
136
+ b'<meta http-equiv="Content-Type" content="text/html; charset=windows-1250" />'
137
+ b'</head>'
138
+ b'<body id="index">'
139
+ b'</body>'
140
+ b'</html>'
141
+ )
142
+
143
+ dom = preprocessor(html_to_dom(html_string))
144
+ returned = html.tostring(dom).decode("utf8")
145
+ expected = (
146
+ '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="sk" lang="sk">'
147
+ '<body id="index">'
148
+ '</body>'
149
+ '</html>'
150
+ )
151
+ assert expected == returned
152
+
153
+
154
+ def test_lxml_do_not_hold_context_from_previous_parsing():
155
+ """
156
+ https://github.com/miso-belica/jusText/issues/17
157
+ """
158
+ html_to_dom("<justext></justext>")
159
+
160
+ with pytest.raises(lxml.etree.ParserError) as e:
161
+ html_to_dom("")
162
+
163
+ assert "justext" not in str(e.value)
@@ -0,0 +1,134 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ from __future__ import absolute_import
4
+ from __future__ import division, print_function, unicode_literals
5
+
6
+ import unittest
7
+ import pytest
8
+
9
+ from justext.core import JustextError, decode_html
10
+
11
+
12
+ class TestHtmlEncoding(unittest.TestCase):
13
+
14
+ def assert_strings_equal(self, s1, s2):
15
+ assert type(s1) == type(s2)
16
+ assert s1 == s2
17
+
18
+ def test_unicode(self):
19
+ html = "ľščťžýáíéäňúô Ł€"
20
+ decoded_html = decode_html(html)
21
+
22
+ self.assert_strings_equal(html, decoded_html)
23
+
24
+ def test_utf8_bytes(self):
25
+ html = "ľščťžýáíéäňúô Ł€"
26
+ decoded_html = decode_html(html.encode("utf8"))
27
+
28
+ self.assert_strings_equal(html, decoded_html)
29
+
30
+ def test_meta_detection_1(self):
31
+ html = '<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2"/> ľščťžäňôě'
32
+ decoded_html = decode_html(html.encode("iso-8859-2"))
33
+
34
+ self.assert_strings_equal(html, decoded_html)
35
+
36
+ def test_meta_detection_2(self):
37
+ html = '<meta content=text/html; charset=iso-8859-2 http-equiv="Content-Type"/> ľščťžäňôě'
38
+ decoded_html = decode_html(html.encode("iso-8859-2"))
39
+
40
+ self.assert_strings_equal(html, decoded_html)
41
+
42
+ def test_meta_detection_3(self):
43
+ html = '<meta content=\'text/html; charset=iso-8859-2\' http-equiv="Content-Type"/> ľščťžäňôě'
44
+ decoded_html = decode_html(html.encode("iso-8859-2"))
45
+
46
+ self.assert_strings_equal(html, decoded_html)
47
+
48
+ def test_meta_detection_4(self):
49
+ html = '<meta charset=iso-8859-2/> ľščťžäňôě'
50
+ decoded_html = decode_html(html.encode("iso-8859-2"))
51
+
52
+ self.assert_strings_equal(html, decoded_html)
53
+
54
+ def test_meta_detection_5(self):
55
+ html = '<meta charset="iso-8859-2"/> ľščťžäňôě'
56
+ decoded_html = decode_html(html.encode("iso-8859-2"))
57
+
58
+ self.assert_strings_equal(html, decoded_html)
59
+
60
+ def test_meta_detection_6(self):
61
+ html = '<meta charset=iso-8859-2/> ľščťžäňôě'
62
+ decoded_html = decode_html(html.encode("iso-8859-2"))
63
+
64
+ self.assert_strings_equal(html, decoded_html)
65
+
66
+ def test_meta_detection_7(self):
67
+ html = '<meta charset=iso-8859-2> ľščťžäňôě'
68
+ decoded_html = decode_html(html.encode("iso-8859-2"))
69
+
70
+ self.assert_strings_equal(html, decoded_html)
71
+
72
+ def test_meta_detection_8(self):
73
+ html = '<meta charset=iso-8859-2> ľščťžäňôě'
74
+ decoded_html = decode_html(html.encode("iso-8859-2"))
75
+
76
+ self.assert_strings_equal(html, decoded_html)
77
+
78
+ def test_meta_detection_9(self):
79
+ html = '<meta content=text/html; charset=iso-8859-2 http-equiv="Content-Type"/> ľščťžäňôě'
80
+ decoded_html = decode_html(html.encode("iso-8859-2"))
81
+
82
+ self.assert_strings_equal(html, decoded_html)
83
+
84
+ def test_meta_detection_charset_outside_1(self):
85
+ html = '<meta charset="iso-8859-2"/> charset="iso-fake-29" ľščťžäňôě'
86
+ decoded_html = decode_html(html.encode("iso-8859-2"))
87
+
88
+ self.assert_strings_equal(html, decoded_html)
89
+
90
+ def test_meta_detection_charset_outside_2(self):
91
+ html = '<meta content=text/html; charset=iso-8859-2 http-equiv="Content-Type"/> charset="iso-fake-29" ľščťžäňôě'
92
+ decoded_html = decode_html(html.encode("iso-8859-2"))
93
+
94
+ self.assert_strings_equal(html, decoded_html)
95
+
96
+ def test_meta_detection_charset_outside_3(self):
97
+ html = '<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=ISO-8859-2"> charset="iso-fake-29" ľščťžäňôě'
98
+ decoded_html = decode_html(html.encode("iso-8859-2"))
99
+
100
+ self.assert_strings_equal(html, decoded_html)
101
+
102
+ def test_unknown_encoding_in_strict_mode(self):
103
+ html = 'ľščťžäňôě'
104
+ with pytest.raises(JustextError):
105
+ decode_html(html.encode("iso-8859-2"), errors='strict')
106
+
107
+ def test_unknown_encoding_with_default_error_handler(self):
108
+ html = 'ľščťžäňôě'
109
+ decoded = decode_html(html.encode("iso-8859-2"), default_encoding="iso-8859-2")
110
+ self.assertEqual(decoded, html)
111
+
112
+ def test_default_encoding(self):
113
+ html = 'ľščťžäňôě'
114
+ decoded_html = decode_html(html.encode("iso-8859-2"), default_encoding="iso-8859-2")
115
+
116
+ self.assert_strings_equal(html, decoded_html)
117
+
118
+ def test_given_encoding(self):
119
+ html = 'ľščťžäňôě'
120
+ decoded_html = decode_html(html.encode("iso-8859-2"), encoding="iso-8859-2")
121
+
122
+ self.assert_strings_equal(html, decoded_html)
123
+
124
+ def test_given_wrong_encoding(self):
125
+ html = 'ľščťžäňôě'
126
+ decoded_html = decode_html(html.encode("iso-8859-2"), encoding="ASCII")
127
+
128
+ self.assert_strings_equal("\ufffd" * len(html), decoded_html)
129
+
130
+ def test_fake_encoding_in_meta(self):
131
+ html = '<meta charset="iso-fake-2"/> ľščťžäňôě'
132
+
133
+ with pytest.raises(JustextError):
134
+ decode_html(html.encode("iso-8859-2"), errors='strict')
@@ -0,0 +1,81 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ from __future__ import absolute_import
4
+ from __future__ import division, print_function, unicode_literals
5
+
6
+ from justext.core import PathInfo
7
+
8
+ import unittest
9
+
10
+
11
+ class TestPathInfo(unittest.TestCase):
12
+ def test_empty_path(self):
13
+ path = PathInfo()
14
+
15
+ self.assertEqual(path.dom, "")
16
+ self.assertEqual(path.xpath, "/")
17
+
18
+ def test_path_with_root_only(self):
19
+ path = PathInfo().append("html")
20
+
21
+ self.assertEqual(path.dom, "html")
22
+ self.assertEqual(path.xpath, "/html[1]")
23
+
24
+ def test_path_with_more_elements(self):
25
+ path = PathInfo().append("html").append("body").append("header").append("h1")
26
+
27
+ self.assertEqual(path.dom, "html.body.header.h1")
28
+ self.assertEqual(path.xpath, "/html[1]/body[1]/header[1]/h1[1]")
29
+
30
+ def test_contains_multiple_tags_with_the_same_name(self):
31
+ path = PathInfo().append("html").append("body").append("div")
32
+
33
+ self.assertEqual(path.dom, "html.body.div")
34
+ self.assertEqual(path.xpath, "/html[1]/body[1]/div[1]")
35
+
36
+ path.pop().append("div")
37
+
38
+ self.assertEqual(path.dom, "html.body.div")
39
+ self.assertEqual(path.xpath, "/html[1]/body[1]/div[2]")
40
+
41
+ def test_more_elements_in_tag(self):
42
+ path = PathInfo().append("html").append("body").append("div")
43
+
44
+ self.assertEqual(path.dom, "html.body.div")
45
+ self.assertEqual(path.xpath, "/html[1]/body[1]/div[1]")
46
+
47
+ path.pop()
48
+
49
+ self.assertEqual(path.dom, "html.body")
50
+ self.assertEqual(path.xpath, "/html[1]/body[1]")
51
+
52
+ path.append("span")
53
+
54
+ self.assertEqual(path.dom, "html.body.span")
55
+ self.assertEqual(path.xpath, "/html[1]/body[1]/span[1]")
56
+
57
+ path.pop()
58
+
59
+ self.assertEqual(path.dom, "html.body")
60
+ self.assertEqual(path.xpath, "/html[1]/body[1]")
61
+
62
+ path.append("pre")
63
+
64
+ self.assertEqual(path.dom, "html.body.pre")
65
+ self.assertEqual(path.xpath, "/html[1]/body[1]/pre[1]")
66
+
67
+ def test_removing_element(self):
68
+ path = PathInfo().append("html").append("body")
69
+ path.append("div").append("a").pop()
70
+
71
+ self.assertEqual(path.dom, "html.body.div")
72
+ self.assertEqual(path.xpath, "/html[1]/body[1]/div[1]")
73
+
74
+ path.pop()
75
+
76
+ self.assertEqual(path.dom, "html.body")
77
+ self.assertEqual(path.xpath, "/html[1]/body[1]")
78
+
79
+ def test_pop_on_empty_path_raises_exception(self):
80
+ path = PathInfo()
81
+ self.assertRaises(IndexError, path.pop)