def bleach(file):
    """
    Sanitizes given python module.

    :param file: Python module file.
    :type file: unicode
    :return: Definition success.
    :rtype: bool
    """

    LOGGER.info("{0} | Sanitizing '{1}' python module!".format(__name__, file))

    source_file = File(file)
    content = source_file.read()
    for pattern in STATEMENTS_SUBSTITUTE:
        matches = [match for match in re.finditer(pattern, content, re.DOTALL)]

        offset = 0
        for match in matches:
            if any(map(lambda x: x in match.group("bleach"), STATEMENT_IGNORE)):
                continue

            start, end = match.start("bleach"), match.end("bleach")
            substitution = "{0}{1}".format(STATEMENT_UPDATE_MESSAGE,
                                           re.sub("\n", "\n{0}".format(STATEMENT_UPDATE_MESSAGE),
                                                  match.group("bleach")))
            content = "".join((content[0: start + offset],
                               substitution,
                               content[end + offset:]))
            offset += len(substitution) - len(match.group("bleach"))

    source_file.content = [content]
    source_file.write()

    return True
def bleach ( file ) : LOGGER . info ( "{0} | Sanitizing '{1}' python module!" . format ( __name__ , file ) ) source_file = File ( file ) content = source_file . read ( ) for pattern in STATEMENTS_SUBSTITUTE : matches = [ match for match in re . finditer ( pattern , content , re . DOTALL ) ] offset = 0 for match in matches : if any ( map ( lambda x : x in match . group ( "bleach" ) , STATEMENT_IGNORE ) ) : continue start , end = match . start ( "bleach" ) , match . end ( "bleach" ) substitution = "{0}{1}" . format ( STATEMENT_UPDATE_MESSAGE , re . sub ( "\n" , "\n{0}" . format ( STATEMENT_UPDATE_MESSAGE ) , match . group ( "bleach" ) ) ) content = "" . join ( ( content [ 0 : start + offset ] , substitution , content [ end + offset : ] ) ) offset += len ( substitution ) - len ( match . group ( "bleach" ) ) source_file . content = [ content ] source_file . write ( ) return True
Sanitizes given python module.

    :param file: Python module file.
    :type file: unicode
    :return: Definition success.
    :rtype: bool