65 |
66 |
66 self.lines = text.count(os.linesep) |
67 self.lines = text.count(os.linesep) |
67 |
68 |
68 source = io.BytesIO(text.encode("utf-8")) |
69 source = io.BytesIO(text.encode("utf-8")) |
69 try: |
70 try: |
70 gen = tokenize.tokenize(source.readline) |
71 if sys.version_info[0] == 2: |
|
72 gen = tokenize.generate_tokens(source.readline) |
|
73 else: |
|
74 gen = tokenize.tokenize(source.readline) |
71 for toktype, toktext, start, end, line in gen: |
75 for toktype, toktext, start, end, line in gen: |
72 (srow, scol) = start |
76 (srow, scol) = start |
73 (erow, ecol) = end |
77 (erow, ecol) = end |
74 if toktype in [token.NEWLINE, tokenize.NL]: |
78 if toktype in [token.NEWLINE, tokenize.NL]: |
75 self.__addToken(toktype, os.linesep, srow, scol, line) |
79 self.__addToken(toktype, os.linesep, srow, scol, line) |