Author: Matti Picus <[email protected]>
Branch: win32-fixes4
Changeset: r70331:bc9fdf95881a
Date: 2014-03-30 01:10 +0300
http://bitbucket.org/pypy/pypy/changeset/bc9fdf95881a/
Log: merge default into branch
diff --git a/lib-python/2.7/test/test_httpservers.py
b/lib-python/2.7/test/test_httpservers.py
--- a/lib-python/2.7/test/test_httpservers.py
+++ b/lib-python/2.7/test/test_httpservers.py
@@ -335,6 +335,7 @@
response = self.request(self.tempdir_name + '/')
self.check_status_and_reason(response, 404)
os.chmod(self.tempdir, 0755)
+ f.close()
def test_head(self):
response = self.request(
diff --git a/lib_pypy/_testcapi.py b/lib_pypy/_testcapi.py
--- a/lib_pypy/_testcapi.py
+++ b/lib_pypy/_testcapi.py
@@ -6,8 +6,10 @@
raise ImportError("No module named '_testcapi'")
def get_hashed_dir(cfile):
+ with open(cfile,'r') as fid:
+ content = fid.read()
# from cffi's Verifier()
- key = '\x00'.join([sys.version[:3], cfile])
+ key = '\x00'.join([sys.version[:3], content])
if sys.version_info >= (3,):
key = key.encode('utf-8')
k1 = hex(binascii.crc32(key[0::2]) & 0xffffffff)
@@ -20,7 +22,8 @@
return output_dir
cfile = '_testcapimodule.c'
-output_dir = get_hashed_dir(cfile)
+thisdir = os.path.dirname(__file__)
+output_dir = get_hashed_dir(os.path.join(thisdir, cfile))
try:
fp, filename, description = imp.find_module('_testcapi', path=[output_dir])
diff --git a/pypy/doc/garbage_collection.rst b/pypy/doc/garbage_collection.rst
--- a/pypy/doc/garbage_collection.rst
+++ b/pypy/doc/garbage_collection.rst
@@ -14,7 +14,7 @@
The present document describes the specific garbage collectors that we
wrote in our framework.
-.. _`EU-report on this topic`:
http://codespeak.net/pypy/extradoc/eu-report/D07.1_Massive_Parallelism_and_Translation_Aspects-2007-02-28.pdf
+.. _`EU-report on this topic`:
https://bitbucket.org/pypy/extradoc/raw/tip/eu-report/D07.1_Massive_Parallelism_and_Translation_Aspects-2007-02-28.pdf
Garbage collectors currently written for the GC framework
diff --git a/pypy/module/test_lib_pypy/test_testcapi.py
b/pypy/module/test_lib_pypy/test_testcapi.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/test_lib_pypy/test_testcapi.py
@@ -0,0 +1,15 @@
+import py, sys
+
+if '__pypy__' not in sys.builtin_module_names:
+ py.test.skip('pypy only test')
+
+from lib_pypy import _testcapi #make sure _testcapi is built
+
+def test_get_hashed_dir():
+ import sys
+ # This should not compile _testcapi, so the output is empty
+ script = "import _testcapi; assert 'get_hashed_dir' in dir(_testcapi)"
+ output = py.process.cmdexec('''"%s" -c "%s"''' %
+ (sys.executable, script))
+ assert output == ''
+
diff --git a/rpython/flowspace/objspace.py b/rpython/flowspace/objspace.py
--- a/rpython/flowspace/objspace.py
+++ b/rpython/flowspace/objspace.py
@@ -16,7 +16,13 @@
if func.func_doc and func.func_doc.lstrip().startswith('NOT_RPYTHON'):
raise ValueError("%r is tagged as NOT_RPYTHON" % (func,))
if func.func_code.co_cellvars:
- raise ValueError("RPython functions cannot create closures")
+ raise ValueError(
+"""RPython functions cannot create closures
+Possible casues:
+ Function is inner function
+ Function uses generator expressions
+ Lambda expressions
+in %r""" % (func,))
if not (func.func_code.co_flags & CO_NEWLOCALS):
raise ValueError("The code object for a RPython function should have "
"the flag CO_NEWLOCALS set.")
diff --git a/rpython/rlib/rsre/rsre_re.py b/rpython/rlib/rsre/rsre_re.py
--- a/rpython/rlib/rsre/rsre_re.py
+++ b/rpython/rlib/rsre/rsre_re.py
@@ -1,12 +1,15 @@
"""
-Testing code. This is not used in a PyPy translation.
-It exports the same interface as the Python 're' module.
+This is not used in a PyPy translation, but it can be used
+in RPython code. It exports the same interface as the
+Python 're' module. You can call the functions at the start
+of the module (expect the ones with NOT_RPYTHON for now).
+They must be called with a *constant* pattern string.
"""
import re, sys
from rpython.rlib.rsre import rsre_core, rsre_char
from rpython.rlib.rsre.rpy import get_code as _get_code
from rpython.rlib.unicodedata import unicodedb
-from rpython.rlib.objectmodel import specialize
+from rpython.rlib.objectmodel import specialize, we_are_translated
rsre_char.set_unicode_db(unicodedb)
@@ -18,24 +21,31 @@
X = VERBOSE = re.X # ignore whitespace and comments
[email protected]_location()
def match(pattern, string, flags=0):
return compile(pattern, flags).match(string)
[email protected]_location()
def search(pattern, string, flags=0):
return compile(pattern, flags).search(string)
[email protected]_location()
def findall(pattern, string, flags=0):
return compile(pattern, flags).findall(string)
[email protected]_location()
def finditer(pattern, string, flags=0):
return compile(pattern, flags).finditer(string)
def sub(pattern, repl, string, count=0):
+ "NOT_RPYTHON"
return compile(pattern).sub(repl, string, count)
def subn(pattern, repl, string, count=0):
+ "NOT_RPYTHON"
return compile(pattern).subn(repl, string, count)
[email protected]_location()
def split(pattern, string, maxsplit=0):
return compile(pattern).split(string, maxsplit)
@@ -71,18 +81,30 @@
def findall(self, string, pos=0, endpos=sys.maxint):
matchlist = []
- for match in self.finditer(string, pos, endpos):
+ scanner = self.scanner(string, pos, endpos)
+ while True:
+ match = scanner.search()
+ if match is None:
+ break
if self.groups == 0 or self.groups == 1:
item = match.group(self.groups)
else:
+ assert False, ("findall() not supported if there is more "
+ "than one group: not valid RPython")
item = match.groups("")
matchlist.append(item)
return matchlist
def finditer(self, string, pos=0, endpos=sys.maxint):
- return iter(self.scanner(string, pos, endpos).search, None)
+ scanner = self.scanner(string, pos, endpos)
+ while True:
+ match = scanner.search()
+ if match is None:
+ break
+ yield match
def subn(self, repl, string, count=0):
+ "NOT_RPYTHON"
filter = repl
if not callable(repl) and "\\" in repl:
# handle non-literal strings; hand it over to the template compiler
@@ -130,6 +152,7 @@
return item, n
def sub(self, repl, string, count=0):
+ "NOT_RPYTHON"
item, n = self.subn(repl, string, count)
return item
@@ -212,7 +235,9 @@
grp = self.group(i)
if grp is None: grp = default
grps.append(grp)
- return tuple(grps)
+ if not we_are_translated():
+ grps = tuple(grps) # xxx mostly to make tests happy
+ return grps
def groupdict(self, default=None):
d = {}
diff --git a/rpython/rlib/rsre/test/test_re.py
b/rpython/rlib/rsre/test/test_re.py
--- a/rpython/rlib/rsre/test/test_re.py
+++ b/rpython/rlib/rsre/test/test_re.py
@@ -191,11 +191,15 @@
assert re.findall(":+", "abc") == []
assert re.findall(":+", "a:b::c:::d") == [":", "::", ":::"]
assert re.findall("(:+)", "a:b::c:::d") == [":", "::", ":::"]
+
+ def test_re_findall_2(self):
+ py.test.skip("findall() returning groups is not RPython")
assert re.findall("(:)(:*)", "a:b::c:::d") == [(":", ""),
(":", ":"),
(":", "::")]
def test_bug_117612(self):
+ py.test.skip("findall() returning groups is not RPython")
assert re.findall(r"(a|(b))", "aba") == (
[("a", ""),("b", "b"),("a", "")])
diff --git a/rpython/rlib/rsre/test/test_zinterp.py
b/rpython/rlib/rsre/test/test_zinterp.py
--- a/rpython/rlib/rsre/test/test_zinterp.py
+++ b/rpython/rlib/rsre/test/test_zinterp.py
@@ -35,3 +35,23 @@
return int("aaaaaa" == g.group(0))
assert interpret(f, [3]) == 1
assert interpret(f, [0]) == 3
+
+def test_translates():
+ from rpython.rlib.rsre import rsre_re
+ def f(i):
+ if i:
+ s = "aaaaaa"
+ else:
+ s = "caaaaa"
+ print rsre_re.match("(a|b)aa", s)
+ print rsre_re.match("a{4}", s)
+ print rsre_re.search("(a|b)aa", s)
+ print rsre_re.search("a{4}", s)
+ for x in rsre_re.findall("(a|b)a", s): print x
+ for x in rsre_re.findall("a{2}", s): print x
+ for x in rsre_re.finditer("(a|b)a", s): print x
+ for x in rsre_re.finditer("a{2}", s): print x
+ for x in rsre_re.split("(a|b)a", s): print x
+ for x in rsre_re.split("a{2}", s): print x
+ return 0
+ interpret(f, [3]) # assert does not crash
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit