<commit_before>"""
Module for generating section headings
"""

import tempfile
from pathlib import Path
from mako.template import Template

from npc import util

def get_sectioner(key, heading_level, prefs):
    """
    Helper to get the right built-in sectioner object

    Creates a new sectioner object based on `key`. The special key 'last' will
    get a LastInitialSectioner, otherwise you'll get a TagSectioner.

    Args:
        key (str): Tag name or special word to use for the sectioner.
        heading_level (int): Level of heading this sectioner is for. Stored for
            use in templates.
        prefs (Settings): Settings object used to look up templates and tag name
            translations.

    Returns:
        A BaseSectioner sub-object depending on the key given.
    """
    if key == 'last':
        return LastInitialSectioner(heading_level, prefs)
    else:
        return TagSectioner(key, heading_level, prefs)

class BaseSectioner:
    """
    Core sectioner logic. This is an abstract class and cannot function on its
    own. Extend it to make your own sectioners.

    Each BaseSectioner holds a temporary directory object open until removal.
    This is used to cache the Mako template.

    To get the current text of the object, use `current_text`.
    """
    def __init__(self, heading_level, prefs):
        """
        Create a sectioner object.
<commit_msg>Add note on intended usage pattern<commit_after>"""
Module for generating section headings
"""

import tempfile
from pathlib import Path
from mako.template import Template

from npc import util

def get_sectioner(key, heading_level, prefs):
    """
    Helper to get the right built-in sectioner object

    Creates a new sectioner object based on `key`. The special key 'last' will
    get a LastInitialSectioner, otherwise you'll get a TagSectioner.

    Args:
        key (str): Tag name or special word to use for the sectioner.
        heading_level (int): Level of heading this sectioner is for. Stored for
            use in templates.
        prefs (Settings): Settings object used to look up templates and tag name
            translations.

    Returns:
        A BaseSectioner sub-object depending on the key given.
    """
    if key == 'last':
        return LastInitialSectioner(heading_level, prefs)
    else:
        return TagSectioner(key, heading_level, prefs)

class BaseSectioner:
    """
    Core sectioner logic. This is an abstract class and cannot function on its
    own. Extend it to make your own sectioners.

    Each BaseSectioner holds a temporary directory object open until removal.
    This is used to cache the Mako template.

    To get the current text of the object, use `current_text`.

    The intended way to use a sectioner object is to first check if its value
    would change for a character using `would_change()`. If it would, then call
    `update_text()` and store or write the output of `render_template()`.
    """
    def __init__(self, heading_level, prefs):
        """
        Create a sectioner object.

{'fraction_non_alphanumeric': 0.060378590078328985, 'fraction_numerical': 0.0, 'mean_word_length': 2.934531450577664, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3489174', 'n_tokens_mistral': 811, 'n_tokens_neox': 795, 'n_words': 387}