ThirdParty/Pygments/pygments/lexers/special.py

changeset 12
1d8dd9706f46
parent 0
de9c2efb9d02
child 684
2f29a0b6e1c7
equal deleted inserted replaced
11:b0996e4a289e 12:1d8dd9706f46
8 :copyright: Copyright 2006-2009 by the Pygments team, see AUTHORS. 8 :copyright: Copyright 2006-2009 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 import re 12 import re
13 import cStringIO 13 import io
14 14
15 from pygments.lexer import Lexer 15 from pygments.lexer import Lexer
16 from pygments.token import Token, Error, Text 16 from pygments.token import Token, Error, Text
17 from pygments.util import get_choice_opt, b 17 from pygments.util import get_choice_opt, b
18 18
58 self.compress = get_choice_opt(options, 'compress', 58 self.compress = get_choice_opt(options, 'compress',
59 ['', 'none', 'gz', 'bz2'], '') 59 ['', 'none', 'gz', 'bz2'], '')
60 Lexer.__init__(self, **options) 60 Lexer.__init__(self, **options)
61 61
62 def get_tokens(self, text): 62 def get_tokens(self, text):
63 if isinstance(text, unicode): 63 if isinstance(text, str):
64 # raw token stream never has any non-ASCII characters 64 # raw token stream never has any non-ASCII characters
65 text = text.encode('ascii') 65 text = text.encode('ascii')
66 if self.compress == 'gz': 66 if self.compress == 'gz':
67 import gzip 67 import gzip
68 gzipfile = gzip.GzipFile('', 'rb', 9, cStringIO.StringIO(text)) 68 gzipfile = gzip.GzipFile('', 'rb', 9, io.StringIO(text))
69 text = gzipfile.read() 69 text = gzipfile.read()
70 elif self.compress == 'bz2': 70 elif self.compress == 'bz2':
71 import bz2 71 import bz2
72 text = bz2.decompress(text) 72 text = bz2.decompress(text)
73 73

eric ide

mercurial