Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Lib/tokenize.py

    r2 r391  
    2424
    2525__author__ = 'Ka-Ping Yee <ping@lfw.org>'
    26 __credits__ = \
    27     'GvR, ESR, Tim Peters, Thomas Wouters, Fred Drake, Skip Montanaro, Raymond Hettinger'
     26__credits__ = ('GvR, ESR, Tim Peters, Thomas Wouters, Fred Drake, '
     27               'Skip Montanaro, Raymond Hettinger')
    2828
    2929import string, re
     
    3131
    3232import token
    33 __all__ = [x for x in dir(token) if x[0] != '_'] + ["COMMENT", "tokenize",
    34           "generate_tokens", "NL", "untokenize"]
     33__all__ = [x for x in dir(token) if not x.startswith("_")]
     34__all__ += ["COMMENT", "tokenize", "generate_tokens", "NL", "untokenize"]
    3535del x
    3636del token
     
    7171# Tail end of """ string.
    7272Double3 = r'[^"\\]*(?:(?:\\.|"(?!""))[^"\\]*)*"""'
    73 Triple = group("[uU]?[rR]?'''", '[uU]?[rR]?"""')
     73Triple = group("[uUbB]?[rR]?'''", '[uUbB]?[rR]?"""')
    7474# Single-line ' or " string.
    75 String = group(r"[uU]?[rR]?'[^\n'\\]*(?:\\.[^\n'\\]*)*'",
    76                r'[uU]?[rR]?"[^\n"\\]*(?:\\.[^\n"\\]*)*"')
     75String = group(r"[uUbB]?[rR]?'[^\n'\\]*(?:\\.[^\n'\\]*)*'",
     76               r'[uUbB]?[rR]?"[^\n"\\]*(?:\\.[^\n"\\]*)*"')
    7777
    7878# Because of leftmost-then-longest match semantics, be sure to put the
     
    9292
    9393# First (or only) line of ' or " string.
    94 ContStr = group(r"[uU]?[rR]?'[^\n'\\]*(?:\\.[^\n'\\]*)*" +
     94ContStr = group(r"[uUbB]?[rR]?'[^\n'\\]*(?:\\.[^\n'\\]*)*" +
    9595                group("'", r'\\\r?\n'),
    96                 r'[uU]?[rR]?"[^\n"\\]*(?:\\.[^\n"\\]*)*' +
     96                r'[uUbB]?[rR]?"[^\n"\\]*(?:\\.[^\n"\\]*)*' +
    9797                group('"', r'\\\r?\n'))
    98 PseudoExtras = group(r'\\\r?\n', Comment, Triple)
     98PseudoExtras = group(r'\\\r?\n|\Z', Comment, Triple)
    9999PseudoToken = Whitespace + group(PseudoExtras, Number, Funny, ContStr, Name)
    100100
     
    289289        except StopIteration:
    290290            line = ''
    291         lnum = lnum + 1
     291        lnum += 1
    292292        pos, max = 0, len(line)
    293293
     
    317317            column = 0
    318318            while pos < max:                   # measure leading whitespace
    319                 if line[pos] == ' ': column = column + 1
    320                 elif line[pos] == '\t': column = (column/tabsize + 1)*tabsize
    321                 elif line[pos] == '\f': column = 0
    322                 else: break
    323                 pos = pos + 1
    324             if pos == max: break
     319                if line[pos] == ' ':
     320                    column += 1
     321                elif line[pos] == '\t':
     322                    column = (column//tabsize + 1)*tabsize
     323                elif line[pos] == '\f':
     324                    column = 0
     325                else:
     326                    break
     327                pos += 1
     328            if pos == max:
     329                break
    325330
    326331            if line[pos] in '#\r\n':           # skip comments or blank lines
     
    358363                start, end = pseudomatch.span(1)
    359364                spos, epos, pos = (lnum, start), (lnum, end), end
     365                if start == end:
     366                    continue
    360367                token, initial = line[start:end], line[start]
    361368
     
    398405                    continued = 1
    399406                else:
    400                     if initial in '([{': parenlev = parenlev + 1
    401                     elif initial in ')]}': parenlev = parenlev - 1
     407                    if initial in '([{':
     408                        parenlev += 1
     409                    elif initial in ')]}':
     410                        parenlev -= 1
    402411                    yield (OP, token, spos, epos, line)
    403412            else:
    404413                yield (ERRORTOKEN, line[pos],
    405414                           (lnum, pos), (lnum, pos+1), line)
    406                 pos = pos + 1
     415                pos += 1
    407416
    408417    for indent in indents[1:]:                 # pop remaining indent levels
     
    412421if __name__ == '__main__':                     # testing
    413422    import sys
    414     if len(sys.argv) > 1: tokenize(open(sys.argv[1]).readline)
    415     else: tokenize(sys.stdin.readline)
     423    if len(sys.argv) > 1:
     424        tokenize(open(sys.argv[1]).readline)
     425    else:
     426        tokenize(sys.stdin.readline)
Note: See TracChangeset for help on using the changeset viewer.