rclpython: only python3 now
This commit is contained in:
parent
38fb735447
commit
0f6b5911d5
@ -32,11 +32,8 @@ __author__ = 'J
|
|||||||
|
|
||||||
# Imports
|
# Imports
|
||||||
import cgi, string, sys
|
import cgi, string, sys
|
||||||
PY2 = sys.version < '3'
|
import html
|
||||||
if PY2:
|
import io
|
||||||
import cStringIO
|
|
||||||
else:
|
|
||||||
import io
|
|
||||||
import keyword, token, tokenize
|
import keyword, token, tokenize
|
||||||
|
|
||||||
def makebytes(data):
|
def makebytes(data):
|
||||||
@ -142,18 +139,12 @@ class Parser:
|
|||||||
|
|
||||||
# parse the source and write it
|
# parse the source and write it
|
||||||
self.pos = 0
|
self.pos = 0
|
||||||
if PY2:
|
text = io.BytesIO(self.raw)
|
||||||
text = cStringIO.StringIO(self.raw)
|
|
||||||
else:
|
|
||||||
text = io.BytesIO(self.raw)
|
|
||||||
self.out.write(makebytes(self.stylesheet))
|
self.out.write(makebytes(self.stylesheet))
|
||||||
self.out.write(b'<pre class="code">\n')
|
self.out.write(b'<pre class="code">\n')
|
||||||
try:
|
try:
|
||||||
if PY2:
|
for a,b,c,d,e in tokenize.tokenize(text.readline):
|
||||||
tokenize.tokenize(text.readline, self)
|
self(a,b,c,d,e)
|
||||||
else:
|
|
||||||
for a,b,c,d,e in tokenize.tokenize(text.readline):
|
|
||||||
self(a,b,c,d,e)
|
|
||||||
except tokenize.TokenError as ex:
|
except tokenize.TokenError as ex:
|
||||||
msg = ex[0]
|
msg = ex[0]
|
||||||
line = ex[1][0]
|
line = ex[1][0]
|
||||||
@ -205,7 +196,7 @@ class Parser:
|
|||||||
|
|
||||||
# send text
|
# send text
|
||||||
self.out.write(makebytes('<span class="%s">' % (css_class,)))
|
self.out.write(makebytes('<span class="%s">' % (css_class,)))
|
||||||
self.out.write(makebytes(cgi.escape(toktext)))
|
self.out.write(makebytes(html.escape(toktext)))
|
||||||
self.out.write(b'</span>')
|
self.out.write(b'</span>')
|
||||||
|
|
||||||
|
|
||||||
@ -249,10 +240,7 @@ def colorize_file(file=None, outstream=sys.stdout, standalone=True):
|
|||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
import os
|
import os
|
||||||
if PY2:
|
out = sys.stdout.buffer
|
||||||
out = sys.stdout
|
|
||||||
else:
|
|
||||||
out = sys.stdout.buffer
|
|
||||||
if os.environ.get('PATH_TRANSLATED'):
|
if os.environ.get('PATH_TRANSLATED'):
|
||||||
filepath = os.environ.get('PATH_TRANSLATED')
|
filepath = os.environ.get('PATH_TRANSLATED')
|
||||||
print('Content-Type: text/html; charset="iso-8859-1"\n')
|
print('Content-Type: text/html; charset="iso-8859-1"\n')
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user