webcode-tk 1.2.4__tar.gz → 1.2.6__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.
- {webcode_tk-1.2.4 → webcode_tk-1.2.6}/PKG-INFO +2 -1
- {webcode_tk-1.2.4 → webcode_tk-1.2.6}/pyproject.toml +2 -1
- {webcode_tk-1.2.4 → webcode_tk-1.2.6}/webcode_tk/__init__.py +1 -1
- {webcode_tk-1.2.4 → webcode_tk-1.2.6}/webcode_tk/color_tools.py +1 -1
- {webcode_tk-1.2.4 → webcode_tk-1.2.6}/webcode_tk/contrast_tools.py +19 -6
- {webcode_tk-1.2.4 → webcode_tk-1.2.6}/webcode_tk/validator_tools.py +46 -2
- {webcode_tk-1.2.4 → webcode_tk-1.2.6}/LICENSE.rst +0 -0
- {webcode_tk-1.2.4 → webcode_tk-1.2.6}/README.rst +0 -0
- {webcode_tk-1.2.4 → webcode_tk-1.2.6}/webcode_tk/animation_tools.py +0 -0
- {webcode_tk-1.2.4 → webcode_tk-1.2.6}/webcode_tk/cascade_tools.py +0 -0
- {webcode_tk-1.2.4 → webcode_tk-1.2.6}/webcode_tk/color_keywords.py +0 -0
- {webcode_tk-1.2.4 → webcode_tk-1.2.6}/webcode_tk/css_tools.py +0 -0
- {webcode_tk-1.2.4 → webcode_tk-1.2.6}/webcode_tk/font_tools.py +0 -0
- {webcode_tk-1.2.4 → webcode_tk-1.2.6}/webcode_tk/html_tools.py +0 -0
- {webcode_tk-1.2.4 → webcode_tk-1.2.6}/webcode_tk/sample_report.json +0 -0
- {webcode_tk-1.2.4 → webcode_tk-1.2.6}/webcode_tk/utils.py +0 -0
- {webcode_tk-1.2.4 → webcode_tk-1.2.6}/webcode_tk/ux_tools.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: webcode-tk
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.6
|
|
4
4
|
Summary:
|
|
5
5
|
License: MIT
|
|
6
6
|
License-File: LICENSE.rst
|
|
@@ -23,6 +23,7 @@ Requires-Dist: lxml (>=6.0.0,<7.0.0)
|
|
|
23
23
|
Requires-Dist: mechanicalsoup (>=1.4.0,<2.0.0)
|
|
24
24
|
Requires-Dist: nltk (>=3.8.1,<4.0.0)
|
|
25
25
|
Requires-Dist: py-readability-metrics (>=1.4.5,<2.0.0)
|
|
26
|
+
Requires-Dist: pytest-mock (>=3.15.1,<4.0.0)
|
|
26
27
|
Requires-Dist: requests (>=2.28.1,<3.0.0)
|
|
27
28
|
Requires-Dist: textatistic (>=0.0.1,<0.0.2)
|
|
28
29
|
Requires-Dist: tinycss2 (>=1.4.0,<2.0.0)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "webcode-tk"
|
|
3
|
-
version = "1.2.
|
|
3
|
+
version = "1.2.6"
|
|
4
4
|
description = ""
|
|
5
5
|
authors = ["hundredvisionsguy <cwinikka@gmail.com>"]
|
|
6
6
|
keywords = ["html", "validation", "css", ]
|
|
@@ -26,6 +26,7 @@ nltk = "^3.8.1"
|
|
|
26
26
|
tinycss2 = "^1.4.0"
|
|
27
27
|
lxml = "^6.0.0"
|
|
28
28
|
mechanicalsoup = "^1.4.0"
|
|
29
|
+
pytest-mock = "^3.15.1"
|
|
29
30
|
|
|
30
31
|
[tool.poetry.dev-dependencies]
|
|
31
32
|
pytest = "*"
|
|
@@ -409,7 +409,7 @@ def hex_to_decimal(c: str) -> int:
|
|
|
409
409
|
msg += "2 digits"
|
|
410
410
|
raise ValueError(msg)
|
|
411
411
|
if c[0].lower() not in hex_map.keys():
|
|
412
|
-
raise ValueError(f"The value
|
|
412
|
+
raise ValueError(f"The value {repr(c)} is not a valid hex code.")
|
|
413
413
|
c = c.lower()
|
|
414
414
|
ones = hex_map[c[1]]
|
|
415
415
|
sixteens = hex_map[c[0]] * 16
|
|
@@ -169,9 +169,20 @@ def generate_contrast_report(
|
|
|
169
169
|
else:
|
|
170
170
|
report.extend(errors)
|
|
171
171
|
else:
|
|
172
|
-
|
|
172
|
+
# Check for global selectors (html, *, or body) and calculate
|
|
173
|
+
# contrast
|
|
174
|
+
global_color_result = css_tools.get_global_color_report(
|
|
175
|
+
project_path
|
|
176
|
+
)
|
|
177
|
+
if isinstance(global_color_result, list):
|
|
178
|
+
for result in global_color_result:
|
|
179
|
+
if "fail" in result:
|
|
180
|
+
if file in result:
|
|
181
|
+
error_msg = result.split(file)[1]
|
|
182
|
+
msg = f"fail: in {file}, {error_msg.strip()}"
|
|
183
|
+
else:
|
|
184
|
+
msg = f"pass: {file} passes color contrast."
|
|
173
185
|
report.append(msg)
|
|
174
|
-
|
|
175
186
|
return report
|
|
176
187
|
|
|
177
188
|
|
|
@@ -194,7 +205,7 @@ def analyze_contrast(project_folder: str) -> list[dict]:
|
|
|
194
205
|
|
|
195
206
|
# Analyze CSS Files
|
|
196
207
|
for html_doc in parsed_html_docs:
|
|
197
|
-
doc_results = analyze_css(html_doc, css_files)
|
|
208
|
+
doc_results = analyze_css(html_doc, css_files, project_folder)
|
|
198
209
|
project_contrast_results.extend(doc_results)
|
|
199
210
|
return project_contrast_results
|
|
200
211
|
|
|
@@ -368,7 +379,9 @@ def append_style_data(
|
|
|
368
379
|
css_source[html_file].append(data)
|
|
369
380
|
|
|
370
381
|
|
|
371
|
-
def analyze_css(
|
|
382
|
+
def analyze_css(
|
|
383
|
+
html_doc: dict, css_files: list[dict], project_path=""
|
|
384
|
+
) -> list[dict]:
|
|
372
385
|
"""
|
|
373
386
|
Analyzes CSS application and color contrast for a single HTML document.
|
|
374
387
|
|
|
@@ -452,7 +465,6 @@ def analyze_css(html_doc: dict, css_files: list[dict]) -> list[dict]:
|
|
|
452
465
|
"warning_impact": warning["impact"],
|
|
453
466
|
}
|
|
454
467
|
doc_results.append(warning_result)
|
|
455
|
-
|
|
456
468
|
return doc_results
|
|
457
469
|
|
|
458
470
|
|
|
@@ -1613,5 +1625,6 @@ def element_name_or_default(property_data: dict) -> str:
|
|
|
1613
1625
|
|
|
1614
1626
|
if __name__ == "__main__":
|
|
1615
1627
|
project_path = "tests/test_files/large_project/"
|
|
1616
|
-
|
|
1628
|
+
project_path = "tests/test_files/contrast_tool_test/"
|
|
1629
|
+
contrast_results = generate_contrast_report(project_path, "AAA")
|
|
1617
1630
|
print(contrast_results)
|
|
@@ -96,11 +96,16 @@ def get_markup_validity(file_path: str) -> list:
|
|
|
96
96
|
headers = {
|
|
97
97
|
"content-type": "text/html; charset=utf-8",
|
|
98
98
|
"Accept-Charset": "UTF-8",
|
|
99
|
+
"User-Agent": "python-requests/2.32.5",
|
|
99
100
|
}
|
|
100
101
|
|
|
101
102
|
r = requests.post(w3cURL, data=payload, headers=headers)
|
|
102
|
-
|
|
103
|
-
|
|
103
|
+
try:
|
|
104
|
+
errors = r.json()
|
|
105
|
+
errors = errors.get("messages")
|
|
106
|
+
except Exception:
|
|
107
|
+
# We need to use the web browser
|
|
108
|
+
errors = get_validation_by_browser(file_path)
|
|
104
109
|
|
|
105
110
|
# raise the alarm if the response code is not 200
|
|
106
111
|
if r.status_code != 200:
|
|
@@ -220,6 +225,45 @@ def is_css_valid(validator_results):
|
|
|
220
225
|
return bool(soup.find(id="congrats"))
|
|
221
226
|
|
|
222
227
|
|
|
228
|
+
def get_validation_by_browser(file_path: str) -> list:
|
|
229
|
+
"""Validates HTML using the browser.
|
|
230
|
+
|
|
231
|
+
This function will get the HTML code by file and use the mechanical
|
|
232
|
+
soup browser to get validator results as a ResultSet.
|
|
233
|
+
|
|
234
|
+
Args:
|
|
235
|
+
css_code: CSS code in the form of a string.
|
|
236
|
+
|
|
237
|
+
Returns:
|
|
238
|
+
results: A ResultSet of Tag objects.
|
|
239
|
+
"""
|
|
240
|
+
# Get HTML code from file path
|
|
241
|
+
html_code = clerk.file_to_string(file_path)
|
|
242
|
+
try:
|
|
243
|
+
response = browser.open("https://validator.w3.org/")
|
|
244
|
+
if not response.ok:
|
|
245
|
+
response = browser.open("https://validator.w3.org/nu/#textarea")
|
|
246
|
+
browser.select_form("form")
|
|
247
|
+
browser["doc"] = html_code
|
|
248
|
+
browser.submit_selected()
|
|
249
|
+
results = browser.get_current_page().select("div#results")
|
|
250
|
+
else:
|
|
251
|
+
browser.select_form("#validate-by-input form")
|
|
252
|
+
browser["fragment"] = html_code
|
|
253
|
+
browser.submit_selected()
|
|
254
|
+
results = browser.get_current_page().select("div#results")
|
|
255
|
+
except Exception:
|
|
256
|
+
# Convert the file "no_css_connection.html" into a soup tag object
|
|
257
|
+
no_connection_code = (
|
|
258
|
+
"<h1>Sorry, but we could not make a connection</h1>"
|
|
259
|
+
)
|
|
260
|
+
no_connection_code += "<h2>Please try later</h2>"
|
|
261
|
+
soup = BeautifulSoup(no_connection_code, "lxml")
|
|
262
|
+
# Convert string to result set
|
|
263
|
+
results = soup.contents
|
|
264
|
+
return results
|
|
265
|
+
|
|
266
|
+
|
|
223
267
|
def validate_css(css_code: str) -> bs4.ResultSet:
|
|
224
268
|
"""Validates CSS and returns the results from the css-validator.
|
|
225
269
|
|
|
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
|