3 pygments.formatters.other |
3 pygments.formatters.other |
4 ~~~~~~~~~~~~~~~~~~~~~~~~~ |
4 ~~~~~~~~~~~~~~~~~~~~~~~~~ |
5 |
5 |
6 Other formatters: NullFormatter, RawTokenFormatter. |
6 Other formatters: NullFormatter, RawTokenFormatter. |
7 |
7 |
8 :copyright: Copyright 2006-2019 by the Pygments team, see AUTHORS. |
8 :copyright: Copyright 2006-2020 by the Pygments team, see AUTHORS. |
9 :license: BSD, see LICENSE for details. |
9 :license: BSD, see LICENSE for details. |
10 """ |
10 """ |
11 |
11 |
12 from pygments.formatter import Formatter |
12 from pygments.formatter import Formatter |
13 from pygments.util import get_choice_opt |
13 from pygments.util import get_choice_opt |
117 for ttype, value in tokensource: |
117 for ttype, value in tokensource: |
118 write("%s\t%r\n" % (ttype, value)) |
118 write("%s\t%r\n" % (ttype, value)) |
119 flush() |
119 flush() |
120 |
120 |
121 |
121 |
122 TESTCASE_BEFORE = u'''\ |
122 TESTCASE_BEFORE = '''\ |
123 def testNeedsName(lexer): |
123 def testNeedsName(lexer): |
124 fragment = %r |
124 fragment = %r |
125 tokens = [ |
125 tokens = [ |
126 ''' |
126 ''' |
127 TESTCASE_AFTER = u'''\ |
127 TESTCASE_AFTER = '''\ |
128 ] |
128 ] |
129 assert list(lexer.get_tokens(fragment)) == tokens |
129 assert list(lexer.get_tokens(fragment)) == tokens |
130 ''' |
130 ''' |
131 |
131 |
132 |
132 |
150 outbuf = [] |
150 outbuf = [] |
151 for ttype, value in tokensource: |
151 for ttype, value in tokensource: |
152 rawbuf.append(value) |
152 rawbuf.append(value) |
153 outbuf.append('%s(%s, %r),\n' % (indentation, ttype, value)) |
153 outbuf.append('%s(%s, %r),\n' % (indentation, ttype, value)) |
154 |
154 |
155 before = TESTCASE_BEFORE % (u''.join(rawbuf),) |
155 before = TESTCASE_BEFORE % (''.join(rawbuf),) |
156 during = u''.join(outbuf) |
156 during = ''.join(outbuf) |
157 after = TESTCASE_AFTER |
157 after = TESTCASE_AFTER |
158 if self.encoding is None: |
158 if self.encoding is None: |
159 outfile.write(before + during + after) |
159 outfile.write(before + during + after) |
160 else: |
160 else: |
161 outfile.write(before.encode('utf-8')) |
161 outfile.write(before.encode('utf-8')) |