wpiformat/wpiformat/licenseupdate.py
def __try_regex(self, lines, last_year, license_template):
        """Try finding license with regex of license template.

        Keyword arguments:
        lines -- lines of file
        last_year -- last year in copyright range
        license_template -- license_template string

        Returns:
        Tuple of whether license was found, first year in copyright range, and
        file contents after license.
        """
        linesep = super().get_linesep(lines)

        # Convert the license template to a regex
        license_rgxstr = "^" + linesep.join(license_template)
        license_rgxstr = license_rgxstr.replace("*", r"\*").replace(
            ".", r"\.").replace("(", r"\(").replace(")", r"\)").replace(
                "{year}",
                r"(?P<year>[0-9]+)(-[0-9]+)?").replace("{padding}", "[ ]*")
        license_rgx = regex.compile(license_rgxstr, regex.M)

        first_year = last_year

        # Compare license
        match = license_rgx.search(lines)
        if match:
            try:
                first_year = match.group("year")
            except IndexError:
                pass

            # If comment at beginning of file is non-empty license, update it
            return True, first_year, linesep + lines[match.end():].lstrip()
        else:
            return False, first_year, lines
Try finding license with regex of license template.

        Keyword arguments:
        lines -- lines of file
        last_year -- last year in copyright range
        license_template -- license_template string

        Returns:
        Tuple of whether license was found, first year in copyright range, and
        file contents after license.
        
Try finding license with regex of license template.
Try finding license with regex of license template .
def __try_regex(self, lines, last_year, license_template):
        linesep = super().get_linesep(lines)
        license_rgxstr = "^" + linesep.join(license_template)
        license_rgxstr = license_rgxstr.replace("*", r"\*").replace(
            ".", r"\.").replace("(", r"\(").replace(")", r"\)").replace(
                "{year}",
                r"(?P<year>[0-9]+)(-[0-9]+)?").replace("{padding}", "[ ]*")
        license_rgx = regex.compile(license_rgxstr, regex.M)
        first_year = last_year
        match = license_rgx.search(lines)
        if match:
            try:
                first_year = match.group("year")
            except IndexError:
                pass
            return True, first_year, linesep + lines[match.end():].lstrip()
        else:
            return False, first_year, lines
def __try_regex ( self , lines , last_year , license_template ) : linesep = super ( ) . get_linesep ( lines ) license_rgxstr = "^" + linesep . join ( license_template ) license_rgxstr = license_rgxstr . replace ( "*" , r"\*" ) . replace ( "." , r"\." ) . replace ( "(" , r"\(" ) . replace ( ")" , r"\)" ) . replace ( "{year}" , r"(?P<year>[0-9]+)(-[0-9]+)?" ) . replace ( "{padding}" , "[ ]*" ) license_rgx = regex . compile ( license_rgxstr , regex . M ) first_year = last_year match = license_rgx . search ( lines ) if match : try : first_year = match . group ( "year" ) except IndexError : pass return True , first_year , linesep + lines [ match . end ( ) : ] . lstrip ( ) else : return False , first_year , lines
Try finding license with regex of license template.
Try finding license with regex of license template .
"""Try finding license with regex of license template.

        Keyword arguments:
        lines -- lines of file
        last_year -- last year in copyright range
        license_template -- license_template string

        Returns:
        Tuple of whether license was found, first year in copyright range, and
        file contents after license.
        """ # Convert the license template to a regex # Compare license # If comment at beginning of file is non-empty license, update it
None
self
lines
last_year
license_template