diff options
author | Georg Brandl <georg@python.org> | 2012-02-18 08:10:23 +0100 |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2012-02-18 08:10:23 +0100 |
commit | 71e66fec478560bd68e22e42dd16e27e12e74e84 (patch) | |
tree | b59bf5d36e8fadc5003f944aca36dd70b77b86c2 /pygments/lexers/sql.py | |
parent | e32c3acfd91c9c66d8c5a8468c5d29a358df8451 (diff) | |
download | pygments-71e66fec478560bd68e22e42dd16e27e12e74e84.tar.gz |
Closes #739: replace generator-send with custom class to work under 2.4.
Diffstat (limited to 'pygments/lexers/sql.py')
-rw-r--r-- | pygments/lexers/sql.py | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/pygments/lexers/sql.py b/pygments/lexers/sql.py index 61a08a3c..d5444fcb 100644 --- a/pygments/lexers/sql.py +++ b/pygments/lexers/sql.py @@ -239,14 +239,23 @@ re_message = re.compile( r'((?:DEBUG|INFO|NOTICE|WARNING|ERROR|' r'FATAL|HINT|DETAIL|CONTEXT|LINE [0-9]+):)(.*?\n)') -def lookahead(x): + +class lookahead(object): """Wrap an iterator and allow pushing back an item.""" - for i in x: - while 1: - i = yield i - if i is None: - break - yield i + def __init__(self, x): + self.iter = iter(x) + self._nextitem = None + def __iter__(self): + return self + def send(self, i): + self._nextitem = i + return i + def next(self): + if self._nextitem is not None: + ni = self._nextitem + self._nextitem = None + return ni + return self.iter.next() class PostgresConsoleLexer(Lexer): |