Skip to main content

ALDashboard.validate_docx

Any

Callable

Dict

List

Optional

Set

Tuple

Union

Undefined

DebugUndefined

ChainableUndefined

missing

DocxTemplate

docx

Environment

BaseLoader

Extension

Token

exceptions

os

Path

re

shutil

tempfile

ET

_ETElement

urlopen

zipfile

LET

__all__

_SPECIAL_DOCXTPL_PREFIX_PATTERN

_SPECIAL_PARAGRAPH_TAG_PATTERN

_OOXML_TRANSITIONAL_NS_PREFIX

_OOXML_STRICT_NS_PREFIX

_OOXML_SCHEMA_DOWNLOADS

_OOXML_SCHEMA_CACHE: Dict[str, Any]

_MC_NS

_DCTERMS_NS

_is_markup_compat_false_positive

def _is_markup_compat_false_positive(err: Any) -> bool

Return True for known-valid OOXML patterns rejected by the raw schemas.

DAIndexError Objects

class DAIndexError(IndexError)

DAAttributeError Objects

class DAAttributeError(AttributeError)

nameerror_match

extract_missing_name

def extract_missing_name(the_error)

DAEnvironment Objects

class DAEnvironment(Environment)

from_string

def from_string(source, **kwargs)

getitem

def getitem(obj, argument)

getattr

def getattr(obj, attribute)

fix_quotes

def fix_quotes(match)

CallAndDebugUndefined Objects

class CallAndDebugUndefined(DebugUndefined)

Handles Jinja2 undefined errors by printing the name of the undefined variable. Extended to handle callable methods.

__call__

def __call__(*pargs, **kwargs)

__getattr__

def __getattr__(_: str) -> "CallAndDebugUndefined"

__getitem__

type: ignore

null_func: Callable

registered_jinja_filters: dict

builtin_jinja_filters

DAExtension Objects

class DAExtension(Extension)

parse

def parse(parser)

filter_stream

def filter_stream(stream)

_build_da_environment

def _build_da_environment() -> DAEnvironment

_normalize_jinja_source

def _normalize_jinja_source(source: str) -> str

_build_template_issue

def _build_template_issue(
code: str,
message: str,
exception: Optional[BaseException] = None) -> Dict[str, Any]

_is_nonblocking_template_assertion

def _is_nonblocking_template_assertion(message: str) -> bool

get_jinja_template_validation

def get_jinja_template_validation(source: str) -> Dict[str, Any]

Parse Jinja source and return blocking errors and non-blocking warnings.

The validation reuses the docx validator's custom environment so AssemblyLine's common filters behave the same here as they do during DOCX validation. Unknown filters/tests are returned as warnings so callers can warn without blocking a save.

get_jinja_errors

def get_jinja_errors(the_file: str) -> Optional[str]

Just try rendering the DOCX file as a Jinja2 template and catch any errors. Returns a string with the errors, if any.

_collect_paragraphs_from_table

def _collect_paragraphs_from_table(table: Any, collected: List[Any],
seen: Set[int]) -> None

_collect_paragraphs_from_container

def _collect_paragraphs_from_container(container: Any, collected: List[Any],
seen: Set[int]) -> None

_collect_docx_paragraphs

def _collect_docx_paragraphs(document: Any) -> List[Any]

_build_markup_warning

def _build_markup_warning(*,
code: str,
message: str,
paragraph: int,
paragraph_text: str,
match_text: Optional[str] = None) -> Dict[str, Any]

analyze_docx_template_markup

def analyze_docx_template_markup(
document: Union[docx.document.Document, str]) -> List[Dict[str, Any]]

Warn about likely-accidental docxtpl paragraph-tag usage patterns.

_discover_ooxml_schema_dir

def _discover_ooxml_schema_dir() -> Optional[str]

_directory_supports_writes

def _directory_supports_writes(path: Path) -> bool

_package_ooxml_schema_cache_dir

def _package_ooxml_schema_cache_dir() -> Path

_default_ooxml_schema_cache_dir

def _default_ooxml_schema_cache_dir() -> Path

_download_extract_nested_zip

def _download_extract_nested_zip(outer_url: str, nested_zip_name: str,
target_dir: Path) -> None

ensure_ooxml_schema_cache

def ensure_ooxml_schema_cache() -> Dict[str, str]

_local_name_from_root_tag

def _local_name_from_root_tag(tag: str) -> Tuple[str, str]

_get_schema_entry_for_part

def _get_schema_entry_for_part(part_name: str, root: LET._Element,
schema_dirs: Dict[str, str]) -> Optional[str]

_load_xmlschema

def _load_xmlschema(schema_path: str) -> Any

validate_docx_ooxml_schema

def validate_docx_ooxml_schema(the_file: str) -> Dict[str, Any]

Run strict XML checks and, when configured, OOXML schema validation.

_local_name

def _local_name(tag: str) -> str

_get_attr

def _get_attr(element: _ETElement, attr_name: str) -> Optional[str]

_note_hit

def _note_hit(hits: Dict[str, Set[str]],
code: str,
part_name: str,
evidence: Optional[str] = None) -> None

_scan_xml_part

def _scan_xml_part(part_name: str, content: bytes,
hits: Dict[str, Set[str]]) -> None

detect_docx_automation_features

def detect_docx_automation_features(the_file: str) -> Dict[str, Any]

Detect non-plain-text DOCX constructs that often come from Word-centric automation systems.

_is_page_number_docpart_sdt

def _is_page_number_docpart_sdt(sdt_element: _ETElement) -> bool

_is_allowed_simple_field

def _is_allowed_simple_field(instr: str) -> bool

_replace_element_with_children

def _replace_element_with_children(parent: _ETElement, index: int,
element: _ETElement,
children: List[_ETElement]) -> None

_replace_element_with_children_lxml

def _replace_element_with_children_lxml(parent: LET._Element, index: int,
element: LET._Element,
children: List[LET._Element]) -> None

_strip_controls_from_parent

def _strip_controls_from_parent(parent: _ETElement, counts: Dict[str,
int]) -> bool

_strip_controls_from_parent_lxml

def _strip_controls_from_parent_lxml(parent: LET._Element,
counts: Dict[str, int]) -> bool

strip_docx_problem_controls

def strip_docx_problem_controls(input_file: str,
output_file: str) -> Dict[str, Any]

Create a cleaned DOCX with risky SDTs and non-whitelisted simple fields removed.

Keeps page-number docpart SDTs and simple fields for page numbers/cross-references.