jusText 3.0.0__tar.gz → 3.0.2__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.2}/CHANGELOG.rst +8 -0
  2. {jusText-3.0.0/jusText.egg-info → justext-3.0.2}/PKG-INFO +24 -7
  3. {jusText-3.0.0 → justext-3.0.2}/README.rst +2 -2
  4. {jusText-3.0.0 → justext-3.0.2/jusText.egg-info}/PKG-INFO +24 -7
  5. {jusText-3.0.0 → justext-3.0.2}/jusText.egg-info/SOURCES.txt +8 -1
  6. {jusText-3.0.0 → justext-3.0.2}/jusText.egg-info/requires.txt +1 -1
  7. {jusText-3.0.0 → justext-3.0.2}/justext/__init__.py +1 -1
  8. {jusText-3.0.0 → justext-3.0.2}/justext/_compat.py +4 -4
  9. {jusText-3.0.0 → justext-3.0.2}/setup.cfg +1 -1
  10. {jusText-3.0.0 → justext-3.0.2}/setup.py +2 -2
  11. justext-3.0.2/tests/test_classify_paragraphs.py +88 -0
  12. justext-3.0.2/tests/test_core.py +7 -0
  13. justext-3.0.2/tests/test_dom_utils.py +163 -0
  14. justext-3.0.2/tests/test_html_encoding.py +134 -0
  15. justext-3.0.2/tests/test_paths.py +81 -0
  16. justext-3.0.2/tests/test_sax.py +214 -0
  17. justext-3.0.2/tests/test_utils.py +94 -0
  18. {jusText-3.0.0 → justext-3.0.2}/LICENSE.rst +0 -0
  19. {jusText-3.0.0 → justext-3.0.2}/MANIFEST.in +0 -0
  20. {jusText-3.0.0 → justext-3.0.2}/jusText.egg-info/dependency_links.txt +0 -0
  21. {jusText-3.0.0 → justext-3.0.2}/jusText.egg-info/top_level.txt +0 -0
  22. {jusText-3.0.0 → justext-3.0.2}/justext/__main__.py +0 -0
  23. {jusText-3.0.0 → justext-3.0.2}/justext/core.py +0 -0
  24. {jusText-3.0.0 → justext-3.0.2}/justext/paragraph.py +0 -0
  25. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Afrikaans.txt +0 -0
  26. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Albanian.txt +0 -0
  27. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Arabic.txt +0 -0
  28. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Aragonese.txt +0 -0
  29. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Armenian.txt +0 -0
  30. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Aromanian.txt +0 -0
  31. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Asturian.txt +0 -0
  32. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Azerbaijani.txt +0 -0
  33. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Basque.txt +0 -0
  34. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Belarusian.txt +0 -0
  35. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Belarusian_Taraskievica.txt +0 -0
  36. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Bengali.txt +0 -0
  37. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Bishnupriya_Manipuri.txt +0 -0
  38. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Bosnian.txt +0 -0
  39. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Breton.txt +0 -0
  40. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Bulgarian.txt +0 -0
  41. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Catalan.txt +0 -0
  42. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Cebuano.txt +0 -0
  43. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Chuvash.txt +0 -0
  44. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Croatian.txt +0 -0
  45. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Czech.txt +0 -0
  46. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Danish.txt +0 -0
  47. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Dutch.txt +0 -0
  48. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/English.txt +0 -0
  49. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Esperanto.txt +0 -0
  50. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Estonian.txt +0 -0
  51. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Finnish.txt +0 -0
  52. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/French.txt +0 -0
  53. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Galician.txt +0 -0
  54. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Georgian.txt +0 -0
  55. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/German.txt +0 -0
  56. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Greek.txt +0 -0
  57. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Gujarati.txt +0 -0
  58. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Haitian.txt +0 -0
  59. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Hebrew.txt +0 -0
  60. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Hindi.txt +0 -0
  61. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Hungarian.txt +0 -0
  62. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Icelandic.txt +0 -0
  63. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Ido.txt +0 -0
  64. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Igbo.txt +0 -0
  65. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Indonesian.txt +0 -0
  66. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Irish.txt +0 -0
  67. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Italian.txt +0 -0
  68. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Javanese.txt +0 -0
  69. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Kannada.txt +0 -0
  70. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Kazakh.txt +0 -0
  71. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Korean.txt +0 -0
  72. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Kurdish.txt +0 -0
  73. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Kyrgyz.txt +0 -0
  74. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Latin.txt +0 -0
  75. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Latvian.txt +0 -0
  76. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Lithuanian.txt +0 -0
  77. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Lombard.txt +0 -0
  78. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Low_Saxon.txt +0 -0
  79. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Luxembourgish.txt +0 -0
  80. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Macedonian.txt +0 -0
  81. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Malay.txt +0 -0
  82. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Malayalam.txt +0 -0
  83. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Maltese.txt +0 -0
  84. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Marathi.txt +0 -0
  85. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Neapolitan.txt +0 -0
  86. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Nepali.txt +0 -0
  87. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Newar.txt +0 -0
  88. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Norwegian_Bokmal.txt +0 -0
  89. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Norwegian_Nynorsk.txt +0 -0
  90. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Occitan.txt +0 -0
  91. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Persian.txt +0 -0
  92. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Piedmontese.txt +0 -0
  93. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Polish.txt +0 -0
  94. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Portuguese.txt +0 -0
  95. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Quechua.txt +0 -0
  96. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Romanian.txt +0 -0
  97. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Russian.txt +0 -0
  98. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Samogitian.txt +0 -0
  99. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Serbian.txt +0 -0
  100. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Serbo_Croatian.txt +0 -0
  101. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Sicilian.txt +0 -0
  102. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Simple_English.txt +0 -0
  103. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Slovak.txt +0 -0
  104. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Slovenian.txt +0 -0
  105. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Spanish.txt +0 -0
  106. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Sundanese.txt +0 -0
  107. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Swahili.txt +0 -0
  108. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Swedish.txt +0 -0
  109. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Tagalog.txt +0 -0
  110. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Tamil.txt +0 -0
  111. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Telugu.txt +0 -0
  112. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Turkish.txt +0 -0
  113. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Turkmen.txt +0 -0
  114. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Ukrainian.txt +0 -0
  115. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Urdu.txt +0 -0
  116. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Uzbek.txt +0 -0
  117. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Vietnamese.txt +0 -0
  118. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Volapuk.txt +0 -0
  119. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Walloon.txt +0 -0
  120. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Waray_Waray.txt +0 -0
  121. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Welsh.txt +0 -0
  122. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/West_Frisian.txt +0 -0
  123. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Western_Panjabi.txt +0 -0
  124. {jusText-3.0.0 → justext-3.0.2}/justext/stoplists/Yoruba.txt +0 -0
  125. {jusText-3.0.0 → justext-3.0.2}/justext/utils.py +0 -0
@@ -3,6 +3,14 @@
3
3
  Changelog for jusText
4
4
  =====================
5
5
 
6
+ 3.0.2 (2025-02-25)
7
+ ------------------
8
+ - *BUG FIX:* Handle urllib imports in Python 2 and 3 correctly `#51 <https://github.com/miso-belica/jusText/pull/51>`_.
9
+
10
+ 3.0.1 (2024-05-09)
11
+ ------------------
12
+ - *BUG FIX:* Fix issue with new version of lxml `#48 <https://github.com/miso-belica/jusText/pull/48>`_.
13
+
6
14
  3.0.0 (2021-10-21)
7
15
  ------------------
8
16
  - *INCOMPATIBLE CHANGE:* Dropped support for Python 3.4 and below.
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: jusText
3
- Version: 3.0.0
3
+ Version: 3.0.2
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,18 @@ 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"
34
+ Dynamic: author
35
+ Dynamic: author-email
36
+ Dynamic: classifier
37
+ Dynamic: description
38
+ Dynamic: home-page
39
+ Dynamic: license
40
+ Dynamic: maintainer
41
+ Dynamic: maintainer-email
42
+ Dynamic: requires-dist
43
+ Dynamic: summary
33
44
 
34
45
  .. _jusText: http://code.google.com/p/justext/
35
46
  .. _Python: http://www.python.org/
@@ -37,8 +48,8 @@ License-File: LICENSE.rst
37
48
 
38
49
  jusText
39
50
  =======
40
- .. image:: https://api.travis-ci.org/miso-belica/jusText.png?branch=master
41
- :target: https://travis-ci.org/miso-belica/jusText
51
+ .. image:: https://github.com/miso-belica/jusText/actions/workflows/run-tests.yml/badge.svg
52
+ :target: https://github.com/miso-belica/jusText/actions/workflows/run-tests.yml
42
53
 
43
54
  Program jusText is a tool for removing boilerplate content, such as navigation
44
55
  links, headers, and footers from HTML pages. It is
@@ -147,6 +158,14 @@ This software has been developed at the `Natural Language Processing Centre`_ of
147
158
  Changelog for jusText
148
159
  =====================
149
160
 
161
+ 3.0.2 (2025-02-25)
162
+ ------------------
163
+ - *BUG FIX:* Handle urllib imports in Python 2 and 3 correctly `#51 <https://github.com/miso-belica/jusText/pull/51>`_.
164
+
165
+ 3.0.1 (2024-05-09)
166
+ ------------------
167
+ - *BUG FIX:* Fix issue with new version of lxml `#48 <https://github.com/miso-belica/jusText/pull/48>`_.
168
+
150
169
  3.0.0 (2021-10-21)
151
170
  ------------------
152
171
  - *INCOMPATIBLE CHANGE:* Dropped support for Python 3.4 and below.
@@ -191,5 +210,3 @@ Changelog for jusText
191
210
  1.1.0 (2011-03-09)
192
211
  ------------------
193
212
  - First public release.
194
-
195
-
@@ -4,8 +4,8 @@
4
4
 
5
5
  jusText
6
6
  =======
7
- .. image:: https://api.travis-ci.org/miso-belica/jusText.png?branch=master
8
- :target: https://travis-ci.org/miso-belica/jusText
7
+ .. image:: https://github.com/miso-belica/jusText/actions/workflows/run-tests.yml/badge.svg
8
+ :target: https://github.com/miso-belica/jusText/actions/workflows/run-tests.yml
9
9
 
10
10
  Program jusText is a tool for removing boilerplate content, such as navigation
11
11
  links, headers, and footers from HTML pages. It is
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: jusText
3
- Version: 3.0.0
3
+ Version: 3.0.2
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,18 @@ 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"
34
+ Dynamic: author
35
+ Dynamic: author-email
36
+ Dynamic: classifier
37
+ Dynamic: description
38
+ Dynamic: home-page
39
+ Dynamic: license
40
+ Dynamic: maintainer
41
+ Dynamic: maintainer-email
42
+ Dynamic: requires-dist
43
+ Dynamic: summary
33
44
 
34
45
  .. _jusText: http://code.google.com/p/justext/
35
46
  .. _Python: http://www.python.org/
@@ -37,8 +48,8 @@ License-File: LICENSE.rst
37
48
 
38
49
  jusText
39
50
  =======
40
- .. image:: https://api.travis-ci.org/miso-belica/jusText.png?branch=master
41
- :target: https://travis-ci.org/miso-belica/jusText
51
+ .. image:: https://github.com/miso-belica/jusText/actions/workflows/run-tests.yml/badge.svg
52
+ :target: https://github.com/miso-belica/jusText/actions/workflows/run-tests.yml
42
53
 
43
54
  Program jusText is a tool for removing boilerplate content, such as navigation
44
55
  links, headers, and footers from HTML pages. It is
@@ -147,6 +158,14 @@ This software has been developed at the `Natural Language Processing Centre`_ of
147
158
  Changelog for jusText
148
159
  =====================
149
160
 
161
+ 3.0.2 (2025-02-25)
162
+ ------------------
163
+ - *BUG FIX:* Handle urllib imports in Python 2 and 3 correctly `#51 <https://github.com/miso-belica/jusText/pull/51>`_.
164
+
165
+ 3.0.1 (2024-05-09)
166
+ ------------------
167
+ - *BUG FIX:* Fix issue with new version of lxml `#48 <https://github.com/miso-belica/jusText/pull/48>`_.
168
+
150
169
  3.0.0 (2021-10-21)
151
170
  ------------------
152
171
  - *INCOMPATIBLE CHANGE:* Dropped support for Python 3.4 and below.
@@ -191,5 +210,3 @@ Changelog for jusText
191
210
  1.1.0 (2011-03-09)
192
211
  ------------------
193
212
  - 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.2"
@@ -18,12 +18,12 @@ else:
18
18
  string_types = (bytes, unicode,)
19
19
 
20
20
 
21
- try:
22
- import urllib2 as urllib
23
- URLError = urllib.URLError
24
- except ImportError:
21
+ if PY3:
25
22
  import urllib.request as urllib
26
23
  from urllib.error import URLError
24
+ else:
25
+ import urllib2 as urllib
26
+ URLError = urllib.URLError
27
27
 
28
28
 
29
29
  try:
@@ -1,5 +1,5 @@
1
1
  [bumpversion]
2
- current_version = 3.0.0
2
+ current_version = 3.0.2
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.2",
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')