# exams/utils/pdf_helpers.py

def v(obj, name, default=0):
    """
    Safe extractor for dicts and objects
    """
    if obj is None:
        return default
    if isinstance(obj, dict):
        return obj.get(name, default)
    return getattr(obj, name, default)


def safe_pct(part, total, digits=2):
    if not total:
        return 0
    return round((part / total) * 100, digits)

class AttrDict(dict):
    """Dictionary that supports dot notation"""
    def __getattr__(self, key):
        try:
            return self[key]
        except KeyError:
            raise AttributeError(key)

