Author: Brian Kearns <[email protected]>
Branch:
Changeset: r62268:9d25b203f026
Date: 2013-03-09 00:13 -0500
http://bitbucket.org/pypy/pypy/changeset/9d25b203f026/
Log: backport some lib_pypy fixes/modernizations from py3k
diff --git a/lib_pypy/_md5.py b/lib_pypy/_md5.py
--- a/lib_pypy/_md5.py
+++ b/lib_pypy/_md5.py
@@ -316,7 +316,7 @@
else:
padLen = 120 - index
- padding = ['\200'] + ['\000'] * 63
+ padding = [b'\200'] + [b'\000'] * 63
self.update(padding[:padLen])
# Append length (before padding).
diff --git a/lib_pypy/_pypy_interact.py b/lib_pypy/_pypy_interact.py
--- a/lib_pypy/_pypy_interact.py
+++ b/lib_pypy/_pypy_interact.py
@@ -4,7 +4,7 @@
import os
-def interactive_console(mainmodule=None):
+def interactive_console(mainmodule=None, quiet=False):
# set sys.{ps1,ps2} just before invoking the interactive interpreter. This
# mimics what CPython does in pythonrun.c
if not hasattr(sys, 'ps1'):
@@ -12,17 +12,18 @@
if not hasattr(sys, 'ps2'):
sys.ps2 = '.... '
#
- try:
- from _pypy_irc_topic import some_topic
- text = "And now for something completely different: ``%s''" % (
- some_topic(),)
- while len(text) >= 80:
- i = text[:80].rfind(' ')
- print text[:i]
- text = text[i+1:]
- print text
- except ImportError:
- pass
+ if not quiet:
+ try:
+ from _pypy_irc_topic import some_topic
+ text = "And now for something completely different: ``%s''" % (
+ some_topic(),)
+ while len(text) >= 80:
+ i = text[:80].rfind(' ')
+ print(text[:i])
+ text = text[i+1:]
+ print(text)
+ except ImportError:
+ pass
#
try:
if not os.isatty(sys.stdin.fileno()):
diff --git a/lib_pypy/_pypy_irc_topic.py b/lib_pypy/_pypy_irc_topic.py
--- a/lib_pypy/_pypy_irc_topic.py
+++ b/lib_pypy/_pypy_irc_topic.py
@@ -167,7 +167,25 @@
"vg'f yvxryl grzcbenel hagvy sberire" nevtb
"""
+from string import ascii_uppercase, ascii_lowercase
+
+def rot13(data):
+ """ A simple rot-13 encoder since `str.encode('rot13')` was removed from
+ Python as of version 3.0. It rotates both uppercase and lowercase
letters individually.
+ """
+ total = []
+ for char in data:
+ if char in ascii_uppercase:
+ index = (ascii_uppercase.find(char) + 13) % 26
+ total.append(ascii_uppercase[index])
+ elif char in ascii_lowercase:
+ index = (ascii_lowercase.find(char) + 13) % 26
+ total.append(ascii_lowercase[index])
+ else:
+ total.append(char)
+ return "".join(total)
+
def some_topic():
import time
lines = __doc__.splitlines()
- return lines[int(time.time()) % len(lines)].decode('rot13')
+ return rot13(lines[int(time.time()) % len(lines)])
diff --git a/lib_pypy/_structseq.py b/lib_pypy/_structseq.py
--- a/lib_pypy/_structseq.py
+++ b/lib_pypy/_structseq.py
@@ -43,8 +43,7 @@
field.__name__ = name
dict['n_fields'] = len(fields_by_index)
- extra_fields = fields_by_index.items()
- extra_fields.sort()
+ extra_fields = sorted(fields_by_index.iteritems())
n_sequence_fields = 0
while extra_fields and extra_fields[0][0] == n_sequence_fields:
extra_fields.pop(0)
diff --git a/lib_pypy/pwd.py b/lib_pypy/pwd.py
--- a/lib_pypy/pwd.py
+++ b/lib_pypy/pwd.py
@@ -167,10 +167,10 @@
from os import getuid
uid = getuid()
pw = getpwuid(uid)
- print "uid %s: %s" % (pw.pw_uid, pw)
+ print("uid %s: %s" % (pw.pw_uid, pw))
name = pw.pw_name
- print "name %r: %s" % (name, getpwnam(name))
- print "All:"
+ print("name %r: %s" % (name, getpwnam(name)))
+ print("All:")
for pw in getpwall():
- print pw
+ print(pw)
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit