py3 unification of pyreadline/*.py files

This commit is contained in:
Jrgen Stenarson
2012-02-15 20:18:50 +01:00
parent 74ca9e108a
commit 0fb82959c2
5 changed files with 40 additions and 15 deletions
+2 -1
View File
@@ -1,7 +1,8 @@
from __future__ import print_function, unicode_literals, absolute_import
import sys, textwrap
from .py3k_compat import callable
rlmain = sys.modules["pyreadline.rlmain"]
rlmain = sys.modules["readline"]
rl = rlmain.rl
def get_doc(rl):
+11 -12
View File
@@ -6,17 +6,16 @@
# the file COPYING, distributed as part of this software.
#*****************************************************************************
from __future__ import print_function, unicode_literals, absolute_import
import cPickle
import logging
import logging.handlers
import SocketServer
import struct, socket
from .unicode_helper import ensure_unicode
try:
import msvcrt
except ImportError:
msvcrt = None
print "problem"
print("problem")
port = logging.handlers.DEFAULT_TCP_LOGGING_PORT
@@ -26,8 +25,8 @@ def check_key():
if msvcrt is None:
return False
else:
if msvcrt.kbhit() != 0:
q = msvcrt.getch()
if msvcrt.kbhit():
q = ensure_unicode(msvcrt.getch())
return q
return ""
@@ -35,9 +34,9 @@ def check_key():
singleline=False
def main():
print "Starting TCP logserver on port:", port
print "Press q to quit logserver", port
print "Press c to clear screen", port
print("Starting TCP logserver on port:", port)
print("Press q to quit logserver", port)
print("Press c to clear screen", port)
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.bind(("", port))
@@ -45,14 +44,14 @@ def main():
while 1:
try:
data, addr = s.recvfrom(100000)
print data,
print(data, end="")
except socket.timeout:
key = check_key().lower()
if "q" == key:
print "Quitting logserver"
print("Quitting logserver")
break
elif "c" == key:
print "\n" * 100
print("\n" * 100)
if __name__ == "__main__":
main()
+22
View File
@@ -0,0 +1,22 @@
from __future__ import print_function, unicode_literals, absolute_import
import sys
if sys.version_info[0] >= 3:
import collections
PY3 = True
def callable(x):
return isinstance(x, collections.Callable)
def execfile(fname, glob, loc=None):
loc = loc if (loc is not None) else glob
exec(compile(open(fname).read(), fname, 'exec'), glob, loc)
unicode = str
bytes = bytes
else:
PY3 = False
callable = callable
execfile = execfile
bytes = str
unicode = unicode
+2 -1
View File
@@ -12,6 +12,7 @@ import sys,os,re,time
from glob import glob
from . import release
from .py3k_compat import callable, execfile
import pyreadline.lineeditor.lineobj as lineobj
import pyreadline.lineeditor.history as history
@@ -404,7 +405,7 @@ class BaseReadline(object):
if os.path.isfile(inputrcpath):
try:
execfile(inputrcpath, loc, loc)
except Exception,x:
except Exception as x:
raise
import traceback
print("Error reading .pyinputrc", file=sys.stderr)
+3 -1
View File
@@ -5,9 +5,10 @@
# Distributed under the terms of the BSD License. The full license is in
# the file COPYING, distributed as part of this software.
#*****************************************************************************
from __future__ import print_function, unicode_literals, absolute_import
import sys
from .py3k_compat import unicode, bytes
try:
pyreadline_codepage = sys.stdout.encoding
except AttributeError:
@@ -32,6 +33,7 @@ def ensure_unicode(text):
return text.decode("ascii", "replace")
return text
def ensure_str(text):
"""Convert unicode to str using pyreadline_codepage"""
if isinstance(text, unicode):