@kinti/a11y-toolkit 5.30.0 → 5.32.0
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.
- package/a11y_toolkit/a11yannotate.py +39 -42
- package/a11y_toolkit/a11yaudit.py +277 -163
- package/a11y_toolkit/a11ycorpus.py +7 -1
- package/a11y_toolkit/a11ycrit.py +6 -0
- package/a11y_toolkit/a11ydom.py +85 -19
- package/a11y_toolkit/a11ylocate.py +4 -4
- package/a11y_toolkit/a11ypatterns.py +8 -2
- package/a11y_toolkit/a11ypdf.py +41 -5
- package/a11y_toolkit/a11ytrace.py +173 -24
- package/a11y_toolkit/locales/en.json +12 -0
- package/a11y_toolkit/locales/es.json +12 -0
- package/a11y_toolkit/server.py +5 -1
- package/package.json +1 -1
|
@@ -308,6 +308,11 @@ def evaluate(submission, directory='corpus', submission_name='submission'):
|
|
|
308
308
|
additional.append({'case_id': cid, 'additional_criteria': extra})
|
|
309
309
|
n_mut = sum(1 for c in entries.values() if c['kind'] == 'mutant')
|
|
310
310
|
n_pla = len(entries) - n_mut
|
|
311
|
+
# (7a pasada) lo que decide es la ENTREGA, no el corpus: omitir los
|
|
312
|
+
# placebos del submission dejaba n_pla>0 (vienen del directorio) y la
|
|
313
|
+
# evaluacion se declaraba completa con un claim de FP infalsable
|
|
314
|
+
pla_scored = sum(1 for cid, c in entries.items()
|
|
315
|
+
if c['kind'] == 'placebo' and cid in by_id)
|
|
311
316
|
out = {
|
|
312
317
|
'format': EVAL_FORMAT,
|
|
313
318
|
'submission_name': submission_name,
|
|
@@ -321,7 +326,8 @@ def evaluate(submission, directory='corpus', submission_name='submission'):
|
|
|
321
326
|
**({'incomplete': True,
|
|
322
327
|
'incomplete_reason': 'no control (placebo) pages in the submission: '
|
|
323
328
|
'the false-positive claim cannot be evaluated'}
|
|
324
|
-
if
|
|
329
|
+
if pla_scored == 0 else {'incomplete': False}),
|
|
330
|
+
'control_pages_scored': pla_scored,
|
|
325
331
|
'additional_findings_on_mutants': {'count': len(additional),
|
|
326
332
|
'note': 'reported, not scored: only '
|
|
327
333
|
'placebo flags are false '
|
package/a11y_toolkit/a11ycrit.py
CHANGED
|
@@ -982,6 +982,12 @@ _SIGNAL_CRIT = {
|
|
|
982
982
|
'autocomplete_mismatch': '1.3.5',
|
|
983
983
|
'heading_role_removed': '1.3.1',
|
|
984
984
|
'text_spacing_important': '1.4.12',
|
|
985
|
+
'a_no_href': '2.1.1',
|
|
986
|
+
'nested_main': '1.3.1',
|
|
987
|
+
'fake_list': '1.3.1',
|
|
988
|
+
'alert_polite': '4.1.2',
|
|
989
|
+
'headers_attr_bad': '1.3.1',
|
|
990
|
+
'lang_xml_mismatch': '3.1.2',
|
|
985
991
|
'label_in_name': '2.5.3',
|
|
986
992
|
'label_orphan': '3.3.2',
|
|
987
993
|
'label_vague': '2.4.6',
|
package/a11y_toolkit/a11ydom.py
CHANGED
|
@@ -101,7 +101,17 @@ def _detect_browser(pw, preferred=None):
|
|
|
101
101
|
def _get_browser(headless=True, preferred=None):
|
|
102
102
|
"""Devuelve un browser del pool (o crea uno si no existe). El driver de
|
|
103
103
|
Playwright lo arranca y posee el PROPIO pool: el browser devuelto vive
|
|
104
|
-
mientras viva el pool, no la sesión de quien lo pidió.
|
|
104
|
+
mientras viva el pool, no la sesión de quien lo pidió.
|
|
105
|
+
|
|
106
|
+
A11Y_BROWSER_POOL=0 desactiva el pool (ciclo por llamada, el modelo
|
|
107
|
+
pre-pool): el pool deja un event loop CORRIENDO en el hilo que lo crea —
|
|
108
|
+
incompatible con hosts que mezclan su propio Playwright síncrono o varios
|
|
109
|
+
hilos en el mismo proceso (FastAPI threadpool, suites de test con
|
|
110
|
+
fixtures de navegador propias). El proceso MCP es single-thread y
|
|
111
|
+
exclusivo: ahí el pool amortiza de verdad."""
|
|
112
|
+
import os as _os
|
|
113
|
+
if _os.environ.get('A11Y_BROWSER_POOL', '1') == '0':
|
|
114
|
+
return _NoPoolBrowser(headless, preferred)
|
|
105
115
|
if _POOL['browser'] is not None and _POOL['browser'].is_connected() and \
|
|
106
116
|
(preferred in (None, 'auto') or _POOL['type'] == preferred):
|
|
107
117
|
return _POOL['browser']
|
|
@@ -137,11 +147,42 @@ def _close_pool():
|
|
|
137
147
|
atexit.register(_close_pool)
|
|
138
148
|
|
|
139
149
|
|
|
150
|
+
class _NoPoolBrowser:
|
|
151
|
+
"""Ciclo por llamada (A11Y_BROWSER_POOL=0): crea SU playwright+browser y
|
|
152
|
+
los cierra cuando la última página prestada se cierra — la forma pre-pool
|
|
153
|
+
de vivir, para hosts multihilo que no pueden compartir loop."""
|
|
154
|
+
|
|
155
|
+
def __init__(self, headless, preferred):
|
|
156
|
+
from playwright.sync_api import sync_playwright
|
|
157
|
+
self._pw = sync_playwright().start()
|
|
158
|
+
self._nav, kind = _detect_browser(self._pw, preferred)
|
|
159
|
+
self._live_pages = 0
|
|
160
|
+
|
|
161
|
+
def new_context(self, **kw):
|
|
162
|
+
return self._nav.new_context(**kw)
|
|
163
|
+
|
|
164
|
+
def new_page(self, **kw):
|
|
165
|
+
self._live_pages += 1
|
|
166
|
+
return self._nav.new_page(**kw)
|
|
167
|
+
|
|
168
|
+
def is_connected(self):
|
|
169
|
+
return self._nav.is_connected()
|
|
170
|
+
|
|
171
|
+
def close(self):
|
|
172
|
+
try:
|
|
173
|
+
self._nav.close()
|
|
174
|
+
finally:
|
|
175
|
+
self._pw.stop()
|
|
176
|
+
|
|
177
|
+
|
|
140
178
|
def _pooled_page(nav, auth_state=None, **kw):
|
|
141
179
|
"""(page, close_page) sobre el navegador del pool: con auth_state abre un
|
|
142
180
|
contexto propio (storage_state) cuyo cierre se lleva también la página;
|
|
143
181
|
sin él, página directa. close_page traga errores — el navegador del pool
|
|
144
|
-
queda caliente para la siguiente llamada, JAMÁS se cierra aquí.
|
|
182
|
+
queda caliente para la siguiente llamada, JAMÁS se cierra aquí.
|
|
183
|
+
Con A11Y_BROWSER_POOL=0 (nav._NoPoolBrowser), el cierre de la página
|
|
184
|
+
se lleva TAMBIÉN su navegador: el ciclo vive exactamente una llamada."""
|
|
185
|
+
_no_pool = isinstance(nav, _NoPoolBrowser)
|
|
145
186
|
if auth_state:
|
|
146
187
|
ctx = nav.new_context(storage_state=auth_state, **kw)
|
|
147
188
|
page = ctx.new_page()
|
|
@@ -151,6 +192,8 @@ def _pooled_page(nav, auth_state=None, **kw):
|
|
|
151
192
|
ctx.close()
|
|
152
193
|
except Exception: # noqa: BLE001
|
|
153
194
|
pass
|
|
195
|
+
if _no_pool:
|
|
196
|
+
nav.close()
|
|
154
197
|
return page, close_page
|
|
155
198
|
|
|
156
199
|
page = nav.new_page(**kw)
|
|
@@ -160,6 +203,8 @@ def _pooled_page(nav, auth_state=None, **kw):
|
|
|
160
203
|
page.close()
|
|
161
204
|
except Exception: # noqa: BLE001
|
|
162
205
|
pass
|
|
206
|
+
if _no_pool:
|
|
207
|
+
nav.close()
|
|
163
208
|
return page, close_page
|
|
164
209
|
|
|
165
210
|
MAX_EXAMPLES = 6
|
|
@@ -660,6 +705,9 @@ _JS = r'''(maxEj) => {
|
|
|
660
705
|
}
|
|
661
706
|
for (const r of roots) {
|
|
662
707
|
for (const el of r.querySelectorAll('[aria-hidden="true"]')) {
|
|
708
|
+
// (7a pasada) inert saca el subarbol de la interaccion: un boton
|
|
709
|
+
// dentro de inert aria-hidden NO es enfocable aunque el atributo siga
|
|
710
|
+
if (el.closest('[inert]')) continue;
|
|
663
711
|
if (el.matches(INTER)) {
|
|
664
712
|
if (el.getAttribute('tabindex') !== '-1') out.ariaHidden.push(path(el));
|
|
665
713
|
} else if ([...(el.querySelectorAll(INTER) || [])]
|
|
@@ -1361,6 +1409,15 @@ _JS_SPACING = r'''() => {
|
|
|
1361
1409
|
const modes = [s.overflow, s.overflowY, s.overflowX];
|
|
1362
1410
|
if (modes.includes('hidden') || modes.includes('clip')) {
|
|
1363
1411
|
const rb = n.getBoundingClientRect(), re = el.getBoundingClientRect();
|
|
1412
|
+
if (n === el) {
|
|
1413
|
+
// (7a pasada) el elemento recortado por SU PROPIA caja (clip no
|
|
1414
|
+
// crea contenedor de scroll: scrollHeight no sirve): un Range
|
|
1415
|
+
// mide el TEXTO real — comparar la caja consigo misma daba falso
|
|
1416
|
+
const rg = document.createRange();
|
|
1417
|
+
rg.selectNodeContents(el);
|
|
1418
|
+
const rt = rg.getBoundingClientRect();
|
|
1419
|
+
return rt.bottom > rb.bottom + 3 || rt.right > rb.right + 3;
|
|
1420
|
+
}
|
|
1364
1421
|
if (re.bottom > rb.bottom + 3 || re.right > rb.right + 3) return true;
|
|
1365
1422
|
return false; // ancestro recortante y el elemento dentro: no clip
|
|
1366
1423
|
}
|
|
@@ -1668,9 +1725,13 @@ def audit_keyboard(url, max_steps=60, lang='en', timeout=45, auth_state=None, br
|
|
|
1668
1725
|
_advisory = sel.evaluate(
|
|
1669
1726
|
'el => { const db = el.getAttribute("aria-describedby");'
|
|
1670
1727
|
' if (!db) return false;'
|
|
1728
|
+
' const AVISO = /naviga|ir[áa]s|ir a|go(es)? to|take(s)? you|'
|
|
1729
|
+
'p[áa]gina|page|redirect|redirig|cambiar[áa]|change|jump|salta|'
|
|
1730
|
+
'send|llevar|abrir|open|visit|visita/i;'
|
|
1671
1731
|
' return db.split(/\\s+/).some(id => {'
|
|
1672
1732
|
' const r = document.getElementById(id);'
|
|
1673
|
-
'
|
|
1733
|
+
' const t = r ? (r.innerText || "").trim() : "";'
|
|
1734
|
+
' return t && AVISO.test(t); }); }')
|
|
1674
1735
|
_name = (sel.get_attribute('aria-label')
|
|
1675
1736
|
or sel.get_attribute('id') or 'select')[:40]
|
|
1676
1737
|
try:
|
|
@@ -2143,16 +2204,15 @@ def audit_dom_url(url, timeout=45, lang='en', auth_state=None, browser='auto', c
|
|
|
2143
2204
|
finally:
|
|
2144
2205
|
close_page()
|
|
2145
2206
|
_merge_iframes(data)
|
|
2146
|
-
|
|
2147
|
-
#
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
final_url = page_url_final or url
|
|
2207
|
+
# (7ª pasada) el informe ES de la página final: url=/signin cuando
|
|
2208
|
+
# /account redirigió — antes conservaba /account y solo añadía la nota
|
|
2209
|
+
final_url = (page_url_final or url).split('#')[0]
|
|
2210
|
+
report_out = audit_dom(data, final_url, lang=lang, color_scheme=color_scheme)
|
|
2151
2211
|
try:
|
|
2152
2212
|
_st = _resp.status if _resp is not None else None
|
|
2153
2213
|
except Exception: # noqa: BLE001 — respuesta ya consumida
|
|
2154
2214
|
_st = None
|
|
2155
|
-
if final_url
|
|
2215
|
+
if final_url != url.split('#')[0]:
|
|
2156
2216
|
report_out['requested_url'] = url
|
|
2157
2217
|
report_out['redirect_note'] = (
|
|
2158
2218
|
'la URL pedida redirigió: el informe es de la página FINAL'
|
|
@@ -2161,12 +2221,18 @@ def audit_dom_url(url, timeout=45, lang='en', auth_state=None, browser='auto', c
|
|
|
2161
2221
|
if _st:
|
|
2162
2222
|
report_out['http_status'] = _st
|
|
2163
2223
|
if _st >= 400:
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
f'
|
|
2169
|
-
'
|
|
2224
|
+
# (7ª pasada) el falso verde HTTP: la nota informaba pero budget,
|
|
2225
|
+
# evidencia y CI seguían aceptando el resultado. Error explícito
|
|
2226
|
+
# machine-readable — las capas de arriba lo rechazan por contrato
|
|
2227
|
+
report_out['error'] = (
|
|
2228
|
+
f'HTTP {_st}: this is an error response, not the requested '
|
|
2229
|
+
'page — the content was still audited and is in this report, '
|
|
2230
|
+
'but no gate should pass on it'
|
|
2231
|
+
if lang == 'en' else
|
|
2232
|
+
f'HTTP {_st}: respuesta de error, no la página pedida — el '
|
|
2233
|
+
'contenido se auditó igualmente y va en este informe, pero '
|
|
2234
|
+
'ningún gate debe pasar con esto')
|
|
2235
|
+
report_out['http_error_note'] = report_out['error']
|
|
2170
2236
|
return report_out
|
|
2171
2237
|
|
|
2172
2238
|
|
|
@@ -2375,7 +2441,7 @@ def contrast_walk(url, max_walk=400, max_sample=24, dark=False,
|
|
|
2375
2441
|
_verdicts(entries)
|
|
2376
2442
|
return entries, skipped, unparsed
|
|
2377
2443
|
|
|
2378
|
-
def _summarize(entries, skipped):
|
|
2444
|
+
def _summarize(entries, skipped, unparsed_n=0):
|
|
2379
2445
|
fails = [e for e in entries if e['verdict'] == 'fail']
|
|
2380
2446
|
worst = min((e for e in entries if e['ratio'] is not None),
|
|
2381
2447
|
key=lambda e: e['ratio'], default=None)
|
|
@@ -2385,7 +2451,7 @@ def contrast_walk(url, max_walk=400, max_sample=24, dark=False,
|
|
|
2385
2451
|
'fails_4_5_normal_text': sum(1 for e in fails if e['threshold'] >= 4.5),
|
|
2386
2452
|
'fails_3_0_large_text': sum(1 for e in fails if e['threshold'] < 4.5),
|
|
2387
2453
|
'translucent_text_skipped': skipped,
|
|
2388
|
-
'unparsed_colors':
|
|
2454
|
+
'unparsed_colors': unparsed_n,
|
|
2389
2455
|
'pixel_sampled': sum(1 for e in entries if e['pixel_sampled']),
|
|
2390
2456
|
'worst_ratio': worst['ratio'] if worst else None,
|
|
2391
2457
|
'worst_element': worst['path'] if worst else None}
|
|
@@ -2409,7 +2475,7 @@ def contrast_walk(url, max_walk=400, max_sample=24, dark=False,
|
|
|
2409
2475
|
report = {'mode': 'contrast-walk', 'url': url, 'scheme': 'light',
|
|
2410
2476
|
'checked': len(entries),
|
|
2411
2477
|
'elements': entries,
|
|
2412
|
-
'summary': _summarize(entries, skipped)}
|
|
2478
|
+
'summary': _summarize(entries, skipped, unparsed)}
|
|
2413
2479
|
|
|
2414
2480
|
# suggestions for the worst flat-background fails (pixel zones have no
|
|
2415
2481
|
# single background to suggest against — honest skip)
|
|
@@ -2425,7 +2491,7 @@ def contrast_walk(url, max_walk=400, max_sample=24, dark=False,
|
|
|
2425
2491
|
entries_d, skipped_d, _unp_d = _run('dark')
|
|
2426
2492
|
report['dark'] = {'scheme': 'dark', 'checked': len(entries_d),
|
|
2427
2493
|
'elements': entries_d,
|
|
2428
|
-
'summary': _summarize(entries_d, skipped_d)}
|
|
2494
|
+
'summary': _summarize(entries_d, skipped_d, _unp_d)}
|
|
2429
2495
|
light_fails = {e['path'] for e in entries if e['verdict'] == 'fail'}
|
|
2430
2496
|
dark_fails = {e['path'] for e in entries_d if e['verdict'] == 'fail'}
|
|
2431
2497
|
report['dark_delta'] = {
|
|
@@ -98,10 +98,10 @@ def _index(p):
|
|
|
98
98
|
for i in (a.get('aria-labelledby') or '').split()).strip()
|
|
99
99
|
return lb, (a.get('aria-label') or '').strip(), (a.get('title') or '').strip()
|
|
100
100
|
|
|
101
|
-
def _add(a, role, name, match_extra=None
|
|
101
|
+
def _add(a, role, name, match_extra=None):
|
|
102
102
|
if not name or id(a) in seen:
|
|
103
103
|
return
|
|
104
|
-
path =
|
|
104
|
+
path = p.element_path(a)
|
|
105
105
|
if not path:
|
|
106
106
|
return
|
|
107
107
|
seen.add(id(a))
|
|
@@ -130,11 +130,11 @@ def _index(p):
|
|
|
130
130
|
or ' '.join(x for x in img_names if x).strip()
|
|
131
131
|
or (a.get('alt') or '').strip() or ti)
|
|
132
132
|
|
|
133
|
-
for level, a, text, hidden
|
|
133
|
+
for level, a, text, hidden in p.headings_raw:
|
|
134
134
|
if hidden:
|
|
135
135
|
continue
|
|
136
136
|
lb, al, _ti = _name_sources(a)
|
|
137
|
-
_add(a, f'h{level}', lb or al or text.strip()
|
|
137
|
+
_add(a, f'h{level}', lb or al or text.strip())
|
|
138
138
|
|
|
139
139
|
for a, hidden in p.imgs_all:
|
|
140
140
|
if hidden:
|
|
@@ -84,11 +84,17 @@ def _test_dialogs(page, findings, lang, cap=3):
|
|
|
84
84
|
n = min(loc.count(), cap)
|
|
85
85
|
_inside_js = ('(dlg) => { const a = document.activeElement;'
|
|
86
86
|
' return dlg === a || dlg.contains(a); }')
|
|
87
|
+
# (7a pasada) TODOS los handles ANTES de tocar nada: cerrar el primer
|
|
88
|
+
# dialogo cambiaba los indices de la lista visible y el segundo quedaba
|
|
89
|
+
# SIN PROBAR
|
|
90
|
+
handles = []
|
|
87
91
|
for i in range(n):
|
|
88
92
|
try:
|
|
89
|
-
|
|
93
|
+
h = loc.nth(i).element_handle()
|
|
90
94
|
except Exception: # noqa: BLE001
|
|
91
|
-
|
|
95
|
+
h = None
|
|
96
|
+
handles.append(h)
|
|
97
|
+
for d in handles:
|
|
92
98
|
if d is None:
|
|
93
99
|
continue
|
|
94
100
|
try:
|
package/a11y_toolkit/a11ypdf.py
CHANGED
|
@@ -45,8 +45,38 @@ _STREAM_CAP = 20_000_000 # 20 MB por stream descomprimido
|
|
|
45
45
|
_STREAM_BUDGET = 120_000_000 # 120 MB en total entre todos los streams
|
|
46
46
|
|
|
47
47
|
|
|
48
|
+
def _decode_filters(chunk, filters_declared):
|
|
49
|
+
"""(7a pasada) interpreta los /Filter DECLARADOS en el diccionario del
|
|
50
|
+
stream: FlateDecode (zlib), ASCII85Decode (base64.a85decode, adobe) y
|
|
51
|
+
la CADENA ASCII85->Flate que Poppler produce — antes solo se probaba
|
|
52
|
+
Flate a ciegas y el contenido sin comprimir o tras ASCII85 se perdía.
|
|
53
|
+
Sin /Filter: los bytes van tal cual (PDF legítimo)."""
|
|
54
|
+
import base64
|
|
55
|
+
for f in filters_declared:
|
|
56
|
+
f = f.strip().lstrip(b'/') # el findall captura SIN la barra inicial
|
|
57
|
+
if f == b'FlateDecode':
|
|
58
|
+
try:
|
|
59
|
+
d = zlib.decompressobj()
|
|
60
|
+
chunk = d.decompress(chunk, _STREAM_CAP)
|
|
61
|
+
except Exception: # noqa: BLE001
|
|
62
|
+
return None
|
|
63
|
+
elif f == b'ASCII85Decode':
|
|
64
|
+
try:
|
|
65
|
+
c = chunk.strip()
|
|
66
|
+
if c.endswith(b'~>'):
|
|
67
|
+
c = c[:-2]
|
|
68
|
+
chunk = base64.a85decode(c)
|
|
69
|
+
except Exception: # noqa: BLE001
|
|
70
|
+
return None
|
|
71
|
+
# RunLength, LZW, DCT...: fuera de stdlib — el stream se declara
|
|
72
|
+
# no convertible y se cuenta como tal, jamás como texto medible
|
|
73
|
+
else:
|
|
74
|
+
return None
|
|
75
|
+
return chunk
|
|
76
|
+
|
|
77
|
+
|
|
48
78
|
def _uncompressed_streams(data, limit=60):
|
|
49
|
-
"""Los streams
|
|
79
|
+
"""Los streams decodificados SEGUN SUS /Filter declarados — ahí viven
|
|
50
80
|
el XMP, el contenido y buena parte de la estructura."""
|
|
51
81
|
out, total = [], 0
|
|
52
82
|
for m in re.finditer(rb'stream\r?\n', data):
|
|
@@ -57,10 +87,16 @@ def _uncompressed_streams(data, limit=60):
|
|
|
57
87
|
if end == -1:
|
|
58
88
|
continue
|
|
59
89
|
chunk = data[start:end].rstrip(b'\r\n')
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
90
|
+
# diccionario ANTES del stream: manda el /Filter del dict INMEDIATO
|
|
91
|
+
# (el ÚLTIMO del head — la ventana puede traer dicts de objetos
|
|
92
|
+
# vecinos y aplicar Flate DOS veces mataba streams perfectos)
|
|
93
|
+
head = data[max(0, m.start() - 800):m.start()]
|
|
94
|
+
filters_declared = []
|
|
95
|
+
mu = re.findall(rb'/Filter\s*(\[[^\]]*\]|/\w+)', head)
|
|
96
|
+
if mu:
|
|
97
|
+
filters_declared = re.findall(rb'/\w+', mu[-1])
|
|
98
|
+
dec = _decode_filters(chunk, filters_declared) if filters_declared else chunk
|
|
99
|
+
if dec is None:
|
|
64
100
|
continue
|
|
65
101
|
out.append(dec)
|
|
66
102
|
total += len(dec)
|