(lualines, filename=None)
Processes #include lines.

    Args:
        lualines: An iterable of lines of Lua code, as P8SCII bytestrings.
        filename: The filename of the input cart.

    Yields:
        Each line of Lua code, with #include lines processed.
Processes #include lines.
Processes #include lines .
def process_includes(lualines, filename=None):
    """Processes #include lines.

    Args:
        lualines: An iterable of lines of Lua code, as P8SCII bytestrings.
        filename: The filename of the input cart.

    Yields:
        Each line of Lua code, with #include lines processed.
    """
    root_path = get_root_include_path(filename)
    for line in lualines:
        m = INCLUDE_LINE_RE.match(line)
        if not m:
            yield line
            continue

        # (Only assert filename if there's an #include.)
        assert root_path is not None

        inc_path_b, inc_extension_b, inc_tab_b = m.groups()
        inc_path = str(inc_path_b, encoding='utf-8')
        inc_extension = str(inc_extension_b, encoding='utf-8')
        inc_tab = None
        if inc_tab_b:
            inc_tab_str = str(inc_tab_b, encoding='utf-8')
            inc_tab = int(inc_tab_str[1:])
        inc_full_path = os.path.abspath(
            os.path.normpath(
                os.path.join(
                    os.path.dirname(filename), inc_path + inc_extension)))
        if not inc_full_path.startswith(root_path):
            raise P8IncludeOutsideOfAllowedDirectory()
        if not os.path.isfile(inc_full_path):
            raise P8IncludeNotFound()

        if inc_extension == '.p8' or inc_extension == '.p8.png':
            p8_fmt_cls = (
                P8Formatter if inc_extension == '.p8'
                else P8PNGFormatter)
            with open(inc_full_path, 'rb') as fh:
                inc_game = p8_fmt_cls.from_file(
                    fh, filename=inc_full_path, do_includes=False)
                for line in lines_for_tab(inc_game.lua.to_lines(), inc_tab):
                    yield line
        else:
            with open(inc_full_path, 'rb') as fh:
                for line in fh:
                    yield line
def process_includes ( lualines , filename = None ) : root_path = get_root_include_path ( filename ) for line in lualines : m = INCLUDE_LINE_RE . match ( line ) if not m : yield line continue # (Only assert filename if there's an #include.) assert root_path is not None inc_path_b , inc_extension_b , inc_tab_b = m . groups ( ) inc_path = str ( inc_path_b , encoding = 'utf-8' ) inc_extension = str ( inc_extension_b , encoding = 'utf-8' ) inc_tab = None if inc_tab_b : inc_tab_str = str ( inc_tab_b , encoding = 'utf-8' ) inc_tab = int ( inc_tab_str [ 1 : ] ) inc_full_path = os . path . abspath ( os . path . normpath ( os . path . join ( os . path . dirname ( filename ) , inc_path + inc_extension ) ) ) if not inc_full_path . startswith ( root_path ) : raise P8IncludeOutsideOfAllowedDirectory ( ) if not os . path . isfile ( inc_full_path ) : raise P8IncludeNotFound ( ) if inc_extension == '.p8' or inc_extension == '.p8.png' : p8_fmt_cls = ( P8Formatter if inc_extension == '.p8' else P8PNGFormatter ) with open ( inc_full_path , 'rb' ) as fh : inc_game = p8_fmt_cls . from_file ( fh , filename = inc_full_path , do_includes = False ) for line in lines_for_tab ( inc_game . lua . to_lines ( ) , inc_tab ) : yield line else : with open ( inc_full_path , 'rb' ) as fh : for line in fh : yield line