pgn_read/core/parser.py
def read_games(self, source, size=10000000):
        """Extract games from file-like source or string.

        Yield Game, or subclass, instance when match is game termination token.
        The final yield is the instance as it is when source exhausted.

        source - file-like object from which to read pgn text
        size - number of characters to read in each read() call

        """
        despatch_table = self.despatch_table
        error_despatch_table = self.error_despatch_table
        game_class = self._game_class
        residue = ''
        for pgntext in self._read_pgn(source, size):

            # The previous chunk of pgntext may have ended with an incomplete
            # game, with or without errors.
            if residue:
                pgntext = residue + pgntext
                residue = ''
            residue_start_on_error_at_pgntext_end = None

            game = game_class()
            for match in self._rules.finditer(pgntext):
                if game.state is not None:
                    if match.lastindex == IFG_END_TAG:

                        # A PGN Tag in an error sequence starts a new game
                        # except when the sequence starts with a comment, '{',
                        # or reserved, '<', sequence for which a matching '}'
                        # or '>' has not been found.  Chunking the input is
                        # likely to make this happen, even in the absence of
                        # PGN errors, until sufficient text has been read to
                        # resolve the problem.  '{[A"a"]}' is allowed as a
                        # comment in PGN.
                        if game._text[game.state][0] in UNTERMINATED:
                            game.append_token_after_error(match)
                            continue

                        residue_start_on_error_at_pgntext_end = match.start()
                        yield game
                        game = game_class()
                        despatch_table[match.lastindex](game, match)

                    # '--' moves in the main line cause rest of game moves to
                    # be wrapped in a {Error} comment.  The game termination
                    # is processed here.  It is an error sequence in the sense
                    # that the game is not valid, but the generated PGN is
                    # valid.
                    elif match.lastindex == IFG_GAME_TERMINATION:
                        residue_start_on_error_at_pgntext_end = match.end()
                        error_despatch_table[match.lastindex](game, match)
                        if len(game._ravstack) > 1:
                            game.set_game_error()
                        yield game
                        game = game_class()

                    else:
                        error_despatch_table[match.lastindex](game, match)
                elif match.lastindex == IFG_OTHER_WITH_NON_NEWLINE_WHITESPACE:
                    despatch_table[match.lastindex](game, match)
                elif match.lastindex == IFG_GAME_TERMINATION:
                    residue_start_on_error_at_pgntext_end = match.end()
                    despatch_table[match.lastindex](game, match)
                    if len(game._ravstack) > 1:
                        game.set_game_error()
                    yield game
                    game = game_class()
                else:
                    despatch_table[match.lastindex](game, match)

            # The final game in pgntext is likely incomplete when processing
            # large PGN files: retry the game after reading the next chunk of
            # the input file.
            # The test on len(pgntext) prevents a sequence of legal movetext
            # which is not preceded by any PGN Tags, in the final game in the
            # final pgntext, causing duplication of the movetext in self._text.
            if residue_start_on_error_at_pgntext_end is None:
                if len(pgntext):
                    game.set_game_error()
                residue = pgntext
            else:
                residue = pgntext[
                    residue_start_on_error_at_pgntext_end:]

        # The final game in the input has an error, or has no error but no game
        # termination marker either.
        if game._text:
            game.set_game_error()
            yield game
Extract games from file-like source or string.

        Yield Game, or subclass, instance when match is game termination token.
        The final yield is the instance as it is when source exhausted.

        source - file-like object from which to read pgn text
        size - number of characters to read in each read() call

        
Extract games from file-like source or string.
Yield Game, or subclass, instance when match is game termination token.
The final yield is the instance as it is when source exhausted.

file-like object from which to read pgn text
size - number of characters to read in each read() call
Extract games from file - like source or string . Yield Game or subclass instance when match is game termination token . The final yield is the instance as it is when source exhausted . file - like object from which to read pgn text size - number of characters to read in each read () call
def read_games(self, source, size=10000000):
        despatch_table = self.despatch_table
        error_despatch_table = self.error_despatch_table
        game_class = self._game_class
        residue = ''
        for pgntext in self._read_pgn(source, size):
            if residue:
                pgntext = residue + pgntext
                residue = ''
            residue_start_on_error_at_pgntext_end = None
            game = game_class()
            for match in self._rules.finditer(pgntext):
                if game.state is not None:
                    if match.lastindex == IFG_END_TAG:
                        if game._text[game.state][0] in UNTERMINATED:
                            game.append_token_after_error(match)
                            continue
                        residue_start_on_error_at_pgntext_end = match.start()
                        yield game
                        game = game_class()
                        despatch_table[match.lastindex](game, match)
                    elif match.lastindex == IFG_GAME_TERMINATION:
                        residue_start_on_error_at_pgntext_end = match.end()
                        error_despatch_table[match.lastindex](game, match)
                        if len(game._ravstack) > 1:
                            game.set_game_error()
                        yield game
                        game = game_class()
                    else:
                        error_despatch_table[match.lastindex](game, match)
                elif match.lastindex == IFG_OTHER_WITH_NON_NEWLINE_WHITESPACE:
                    despatch_table[match.lastindex](game, match)
                elif match.lastindex == IFG_GAME_TERMINATION:
                    residue_start_on_error_at_pgntext_end = match.end()
                    despatch_table[match.lastindex](game, match)
                    if len(game._ravstack) > 1:
                        game.set_game_error()
                    yield game
                    game = game_class()
                else:
                    despatch_table[match.lastindex](game, match)
            if residue_start_on_error_at_pgntext_end is None:
                if len(pgntext):
                    game.set_game_error()
                residue = pgntext
            else:
                residue = pgntext[
                    residue_start_on_error_at_pgntext_end:]
        if game._text:
            game.set_game_error()
            yield game
def read_games ( self , source , size = 10000000 ) : despatch_table = self . despatch_table error_despatch_table = self . error_despatch_table game_class = self . _game_class residue = '' for pgntext in self . _read_pgn ( source , size ) : if residue : pgntext = residue + pgntext residue = '' residue_start_on_error_at_pgntext_end = None game = game_class ( ) for match in self . _rules . finditer ( pgntext ) : if game . state is not None : if match . lastindex == IFG_END_TAG : if game . _text [ game . state ] [ 0 ] in UNTERMINATED : game . append_token_after_error ( match ) continue residue_start_on_error_at_pgntext_end = match . start ( ) yield game game = game_class ( ) despatch_table [ match . lastindex ] ( game , match ) elif match . lastindex == IFG_GAME_TERMINATION : residue_start_on_error_at_pgntext_end = match . end ( ) error_despatch_table [ match . lastindex ] ( game , match ) if len ( game . _ravstack ) > 1 : game . set_game_error ( ) yield game game = game_class ( ) else : error_despatch_table [ match . lastindex ] ( game , match ) elif match . lastindex == IFG_OTHER_WITH_NON_NEWLINE_WHITESPACE : despatch_table [ match . lastindex ] ( game , match ) elif match . lastindex == IFG_GAME_TERMINATION : residue_start_on_error_at_pgntext_end = match . end ( ) despatch_table [ match . lastindex ] ( game , match ) if len ( game . _ravstack ) > 1 : game . set_game_error ( ) yield game game = game_class ( ) else : despatch_table [ match . lastindex ] ( game , match ) if residue_start_on_error_at_pgntext_end is None : if len ( pgntext ) : game . set_game_error ( ) residue = pgntext else : residue = pgntext [ residue_start_on_error_at_pgntext_end : ] if game . _text : game . set_game_error ( ) yield game
Extract games from file-like source or string.
Extract games from file - like source or string .
"""Extract games from file-like source or string.

        Yield Game, or subclass, instance when match is game termination token.
        The final yield is the instance as it is when source exhausted.

        source - file-like object from which to read pgn text
        size - number of characters to read in each read() call

        """ # The previous chunk of pgntext may have ended with an incomplete # game, with or without errors. # A PGN Tag in an error sequence starts a new game # except when the sequence starts with a comment, '{', # or reserved, '<', sequence for which a matching '}' # or '>' has not been found.  Chunking the input is # likely to make this happen, even in the absence of # PGN errors, until sufficient text has been read to # resolve the problem.  '{[A"a"]}' is allowed as a # comment in PGN. # '--' moves in the main line cause rest of game moves to # be wrapped in a {Error} comment.  The game termination # is processed here.  It is an error sequence in the sense # that the game is not valid, but the generated PGN is # valid. # The final game in pgntext is likely incomplete when processing # large PGN files: retry the game after reading the next chunk of # the input file. # The test on len(pgntext) prevents a sequence of legal movetext # which is not preceded by any PGN Tags, in the final game in the # final pgntext, causing duplication of the movetext in self._text. # The final game in the input has an error, or has no error but no game # termination marker either.
self
source
size