#!/usr/bin/env python3 """Build a fresh local review package. No network or credential access.""" import argparse import hashlib from html.parser import HTMLParser import json from pathlib import Path import re ALLOWED = {'title', 'author', 'digest', 'content', 'content_source_url', 'thumb_media_id'} class CheckHTML(HTMLParser): def __init__(self): super().__init__(convert_charrefs=True) self.errors = [] def handle_starttag(self, tag, attrs): if tag in {'script', 'iframe', 'object', 'embed', 'form', 'style', 'link', 'base'}: self.errors.append('unsupported active or external-style element') for key, value in attrs: value = value or '' if key.lower().startswith('on'): self.errors.append('event handler not allowed') if key in {'src', 'href'} and value and not value.lower().startswith(('https://', 'http://', '#')): self.errors.append('unresolved local asset or unsupported link scheme') if key == 'style' and re.search(r'url\s*\(|expression\s*\(|@import', value, re.I): self.errors.append('external or active CSS not supported') handle_startendtag = handle_starttag def prepare(data): if not isinstance(data, dict) or set(data) - ALLOWED: raise ValueError('expected article object with documented fields only') if not all(isinstance(v, str) for v in data.values()): raise ValueError('article values must be strings') if not data.get('title', '').strip() or not data.get('content', '').strip(): raise ValueError('title and content required') result = dict(data) result['content'] = re.sub(r'', '', result['content']) if '