""" Stage 1 - turning an uploaded PDF into the exact kind of string the corpus was built from. Everything in the first block is **lifted verbatim from the EDA notebook that built the corpus** (`HARMLESS_Synthetic_Injected_PDFs_EDA/Final_project_V7_EDA.ipynb`, cells 88-90 and 107). That is not tidiness, it is the correctness argument for this whole Space: Part A's embedding index and Part B's F1 of 0.945 were both measured on `payload_window` strings produced by exactly this code. Extract the text even slightly differently and those published numbers stop describing this app. Do not "improve" anything above the `Triage` heading. """ import re import zlib import numpy as np # --------------------------------------------------------------------------------------------- # Verbatim from the corpus build - EDA cell 88 # --------------------------------------------------------------------------------------------- STREAM_RE = re.compile(rb"(stream\r?\n)(.*?)(endstream)", re.S) INJECTION_MARKERS = { "javascript_injection": [rb"/S\s*/JavaScript", rb"/JS\s*\("], "cross_site_scripting": [rb"