#!/usr/bin/env python3 """ Shared code for config validator examples. """ import pickle from pathlib import Path # The set of all valid (rule_id, event_type) pairs we'll encounter RULES = range(20) # 0-19 (small, bounded input space) EVENT_TYPES = range(20) # 0-19 EVENTS_FILE = Path(__file__).parent / "events.pkl" def validate_rule_slow(rule_id, event_type): """ Simulate an expensive validation check. In real life, this might query a database, parse XML, etc. """ total = 0 for i in range(50): total += (rule_id * event_type * i) % 997 return total % 2 == 0 def load_events(): """Load events from the pickle file.""" if not EVENTS_FILE.exists(): raise FileNotFoundError( f"Events file not found: {EVENTS_FILE}\n" "Run 'python3 generate_events.py' first." ) with open(EVENTS_FILE, "rb") as f: return pickle.load(f)