import re


def hasMetaRobotsNoindex(f) :
    """Checks whether an html file contains
    <meta name="robots" content="noindex"> or
    any equivalent directive including a noindex.
    Only checks head of html since required to be
    in the head if specified.

    Keyword arguments:
    f - Filename including path
    """
    with open(f,"r") as file :
        for line in file :
            # Check line for <meta name="robots" content="noindex">, etc
            if re.search("<meta\s+name.+robots.+content.+noindex", line) != None :
                return True
            # We can stop searching once no longer in head of file.
            # <meta name="robots"> directives required to be in head
            if "<body>" in line or "</head>" in line :
                return False
    return False