import re


def is_initializer_script(tag):
    """
    Find the inline `script` that initializes the system and replace it wholesale
    We look for a script with:

        - no `src` attribute
        - `window.onload =` in the script string
        - `SwaggerUIBundle(` being constructed

    These heuristics might have to change if `swagger-ui-dist` updates the
    underlying source code.
    """

    if tag.name != 'script':
        return False

    if tag.has_attr('src'):
        return False

    text = tag.get_text()
    if not re.search(r'window\.onload\s*=', text):
        return False

    if not re.search(r'SwaggerUIBundle\s*\(', text):
        return False

    return True