[pypy-commit] pypy stmgc-c7: hg merge 9a6efa2d4493
arigo
noreply at buildbot.pypy.org
Tue Nov 11 18:52:00 CET 2014
Author: Armin Rigo <arigo at tunes.org>
Branch: stmgc-c7
Changeset: r74453:1565213578be
Date: 2014-11-11 18:44 +0100
http://bitbucket.org/pypy/pypy/changeset/1565213578be/
Log: hg merge 9a6efa2d4493
Merge default up to 7e7044080cc5; then additionally merge the
improve-gc-tracing-hooks branch.
diff too long, truncating to 2000 out of 74808 lines
diff --git a/LICENSE b/LICENSE
--- a/LICENSE
+++ b/LICENSE
@@ -3,8 +3,8 @@
Except when otherwise stated (look for LICENSE files in directories or
information at the beginning of each file) all software and documentation in
-the 'rpython', 'pypy', 'ctype_configure', 'dotviewer', 'demo', and 'lib_pypy'
-directories is licensed as follows:
+the 'rpython', 'pypy', 'ctype_configure', 'dotviewer', 'demo', 'lib_pypy',
+'py', and '_pytest' directories is licensed as follows:
The MIT License
@@ -35,280 +35,290 @@
the beginning of each file) the files in the 'pypy' directory are each
copyrighted by one or more of the following people and organizations:
- Armin Rigo
- Maciej Fijalkowski
- Carl Friedrich Bolz
- Antonio Cuni
- Amaury Forgeot d'Arc
- Samuele Pedroni
- Alex Gaynor
- Michael Hudson
- David Schneider
- Matti Picus
- Brian Kearns
- Philip Jenvey
- Holger Krekel
- Christian Tismer
- Hakan Ardo
- Benjamin Peterson
- Manuel Jacob
- Anders Chrigstrom
- Eric van Riet Paap
- Wim Lavrijsen
- Ronan Lamy
- Richard Emslie
- Alexander Schremmer
- Dan Villiom Podlaski Christiansen
- Lukas Diekmann
- Sven Hager
- Anders Lehmann
- Aurelien Campeas
- Niklaus Haldimann
- Camillo Bruni
- Laura Creighton
- Toon Verwaest
- Remi Meier
- Leonardo Santagada
- Seo Sanghyeon
- Romain Guillebert
- Justin Peel
- Ronny Pfannschmidt
- David Edelsohn
- Anders Hammarquist
- Jakub Gustak
- Guido Wesdorp
- Lawrence Oluyede
- Bartosz Skowron
- Daniel Roberts
- Niko Matsakis
- Adrien Di Mascio
- Alexander Hesse
- Ludovic Aubry
- Jacob Hallen
- Jason Creighton
- Alex Martelli
- Michal Bendowski
- Jan de Mooij
- stian
- Michael Foord
- Stephan Diehl
- Stefan Schwarzer
- Valentino Volonghi
- Tomek Meka
- Patrick Maupin
- Bob Ippolito
- Bruno Gola
- Jean-Paul Calderone
- Timo Paulssen
- Squeaky
- Alexandre Fayolle
- Simon Burton
- Marius Gedminas
- John Witulski
- Konstantin Lopuhin
- Greg Price
- Dario Bertini
- Mark Pearse
- Simon Cross
- Andreas Stührk
- Jean-Philippe St. Pierre
- Guido van Rossum
- Pavel Vinogradov
- Paweł Piotr Przeradowski
- Paul deGrandis
- Ilya Osadchiy
- Tobias Oberstein
- Adrian Kuhn
- Boris Feigin
- Stefano Rivera
- tav
- Taavi Burns
- Georg Brandl
- Bert Freudenberg
- Stian Andreassen
- Laurence Tratt
- Wanja Saatkamp
- Ivan Sichmann Freitas
- Gerald Klix
- Mike Blume
- Oscar Nierstrasz
- Stefan H. Muller
- Jeremy Thurgood
- Gregor Wegberg
- Rami Chowdhury
- Tobias Pape
- Edd Barrett
- David Malcolm
- Eugene Oden
- Henry Mason
- Preston Timmons
- Jeff Terrace
- David Ripton
- Dusty Phillips
- Lukas Renggli
- Guenter Jantzen
- Ned Batchelder
- Amit Regmi
- Ben Young
- Nicolas Chauvat
- Andrew Durdin
- Andrew Chambers
- Michael Schneider
- Nicholas Riley
- Jason Chu
- Igor Trindade Oliveira
- Rocco Moretti
- Gintautas Miliauskas
- Michael Twomey
- Lucian Branescu Mihaila
- Tim Felgentreff
- Tyler Wade
- Gabriel Lavoie
- Olivier Dormond
- Jared Grubb
- Karl Bartel
- Brian Dorsey
- Victor Stinner
- Andrews Medina
- Stuart Williams
- Jasper Schulz
- Christian Hudon
- Toby Watson
- Antoine Pitrou
- Aaron Iles
- Michael Cheng
- Justas Sadzevicius
- Mikael Schönenberg
- Gasper Zejn
- Neil Shepperd
- Elmo Mäntynen
- Jonathan David Riehl
- Stanislaw Halik
- Anders Qvist
- Chirag Jadwani
- Beatrice During
- Alex Perry
- Vincent Legoll
- Alan McIntyre
- Alexander Sedov
- Corbin Simpson
- Christopher Pope
- wenzhuman
- Christian Tismer
- Marc Abramowitz
- Dan Stromberg
- Stefano Parmesan
- Alexis Daboville
- Jens-Uwe Mager
- Carl Meyer
- Karl Ramm
- Pieter Zieschang
- Gabriel
- Lukas Vacek
- Andrew Dalke
- Sylvain Thenault
- Nathan Taylor
- Vladimir Kryachko
- Jacek Generowicz
- Alejandro J. Cura
- Jacob Oscarson
- Travis Francis Athougies
- Ryan Gonzalez
- Kristjan Valur Jonsson
- Sebastian Pawluś
- Neil Blakey-Milner
- anatoly techtonik
- Lutz Paelike
- Lucio Torre
- Lars Wassermann
- Henrik Vendelbo
- Dan Buch
- Miguel de Val Borro
- Artur Lisiecki
- Sergey Kishchenko
- Ignas Mikalajunas
- Christoph Gerum
- Martin Blais
- Lene Wagner
- Tomo Cocoa
- roberto at goyle
- Yury V. Zaytsev
- Anna Katrina Dominguez
- William Leslie
- Bobby Impollonia
- timo at eistee.fritz.box
- Andrew Thompson
- Ben Darnell
- Roberto De Ioris
- Juan Francisco Cantero Hurtado
- Godefroid Chappelle
- Joshua Gilbert
- Dan Colish
- Christopher Armstrong
- Michael Hudson-Doyle
- Anders Sigfridsson
- Yasir Suhail
- rafalgalczynski at gmail.com
- Floris Bruynooghe
- Laurens Van Houtven
- Akira Li
- Gustavo Niemeyer
- Stephan Busemann
- Rafał Gałczyński
- Yusei Tahara
- Christian Muirhead
- James Lan
- shoma hosaka
- Daniel Neuh?user
- Matthew Miller
- Buck Golemon
- Konrad Delong
- Dinu Gherman
- Chris Lambacher
- coolbutuseless at gmail.com
- Rodrigo Araújo
- w31rd0
- Jim Baker
- James Robert
- Armin Ronacher
- Brett Cannon
- yrttyr
- aliceinwire
- OlivierBlanvillain
- Zooko Wilcox-O Hearn
- Tomer Chachamu
- Christopher Groskopf
- Asmo Soinio
- Stefan Marr
- jiaaro
- opassembler.py
- Antony Lee
- Jim Hunziker
- Markus Unterwaditzer
- Even Wiik Thomassen
- jbs
- soareschen
- Kurt Griffiths
- Mike Bayer
- Flavio Percoco
- Kristoffer Kleine
- yasirs
- Michael Chermside
- Anna Ravencroft
- Julien Phalip
- Dan Loewenherz
+ Armin Rigo
+ Maciej Fijalkowski
+ Carl Friedrich Bolz
+ Antonio Cuni
+ Amaury Forgeot d'Arc
+ Samuele Pedroni
+ Alex Gaynor
+ Michael Hudson
+ David Schneider
+ Matti Picus
+ Brian Kearns
+ Philip Jenvey
+ Holger Krekel
+ Christian Tismer
+ Hakan Ardo
+ Benjamin Peterson
+ Manuel Jacob
+ Anders Chrigstrom
+ Eric van Riet Paap
+ Ronan Lamy
+ Wim Lavrijsen
+ Richard Emslie
+ Alexander Schremmer
+ Dan Villiom Podlaski Christiansen
+ Lukas Diekmann
+ Sven Hager
+ Anders Lehmann
+ Aurelien Campeas
+ Niklaus Haldimann
+ Remi Meier
+ Camillo Bruni
+ Laura Creighton
+ Toon Verwaest
+ Leonardo Santagada
+ Seo Sanghyeon
+ Romain Guillebert
+ Justin Peel
+ Ronny Pfannschmidt
+ David Edelsohn
+ Anders Hammarquist
+ Jakub Gustak
+ Guido Wesdorp
+ Lawrence Oluyede
+ Bartosz Skowron
+ Gregor Wegberg
+ Daniel Roberts
+ Niko Matsakis
+ Adrien Di Mascio
+ Alexander Hesse
+ Ludovic Aubry
+ Jacob Hallen
+ Jason Creighton
+ Alex Martelli
+ Michal Bendowski
+ Jan de Mooij
+ stian
+ Michael Foord
+ Stephan Diehl
+ Tyler Wade
+ Stefan Schwarzer
+ Valentino Volonghi
+ Tomek Meka
+ Patrick Maupin
+ Bob Ippolito
+ Bruno Gola
+ Jean-Paul Calderone
+ Timo Paulssen
+ Squeaky
+ Alexandre Fayolle
+ Simon Burton
+ Marius Gedminas
+ Martin Matusiak
+ Konstantin Lopuhin
+ John Witulski
+ Wenzhu Man
+ Greg Price
+ Dario Bertini
+ Mark Pearse
+ Simon Cross
+ Ivan Sichmann Freitas
+ Andreas Stührk
+ Jean-Philippe St. Pierre
+ Guido van Rossum
+ Pavel Vinogradov
+ Stefano Rivera
+ Paweł Piotr Przeradowski
+ Paul deGrandis
+ Ilya Osadchiy
+ Tobias Oberstein
+ Adrian Kuhn
+ Boris Feigin
+ tav
+ Taavi Burns
+ Georg Brandl
+ Laurence Tratt
+ Bert Freudenberg
+ Stian Andreassen
+ Wanja Saatkamp
+ Gerald Klix
+ Mike Blume
+ Oscar Nierstrasz
+ Stefan H. Muller
+ Edd Barrett
+ Jeremy Thurgood
+ Rami Chowdhury
+ Tobias Pape
+ David Malcolm
+ Eugene Oden
+ Henry Mason
+ Vasily Kuznetsov
+ Preston Timmons
+ Jeff Terrace
+ David Ripton
+ Dusty Phillips
+ Lukas Renggli
+ Guenter Jantzen
+ Ned Batchelder
+ Amit Regmi
+ Ben Young
+ Nicolas Chauvat
+ Andrew Durdin
+ Andrew Chambers
+ Michael Schneider
+ Nicholas Riley
+ Jason Chu
+ Igor Trindade Oliveira
+ Tim Felgentreff
+ Rocco Moretti
+ Gintautas Miliauskas
+ Michael Twomey
+ Lucian Branescu Mihaila
+ Gabriel Lavoie
+ Olivier Dormond
+ Jared Grubb
+ Karl Bartel
+ Brian Dorsey
+ Victor Stinner
+ Andrews Medina
+ Stuart Williams
+ Jasper Schulz
+ Christian Hudon
+ Toby Watson
+ Antoine Pitrou
+ Aaron Iles
+ Michael Cheng
+ Justas Sadzevicius
+ Gasper Zejn
+ anatoly techtonik
+ Neil Shepperd
+ Mikael Schönenberg
+ Elmo M?ntynen
+ Jonathan David Riehl
+ Stanislaw Halik
+ Anders Qvist
+ Corbin Simpson
+ Chirag Jadwani
+ Beatrice During
+ Alex Perry
+ Vincent Legoll
+ Alan McIntyre
+ Alexander Sedov
+ Christopher Pope
+ Christian Tismer
+ Marc Abramowitz
+ Dan Stromberg
+ Stefano Parmesan
+ Alexis Daboville
+ Jens-Uwe Mager
+ Carl Meyer
+ Karl Ramm
+ Pieter Zieschang
+ Sebastian Pawluś
+ Gabriel
+ Lukas Vacek
+ Andrew Dalke
+ Sylvain Thenault
+ Nathan Taylor
+ Vladimir Kryachko
+ Arjun Naik
+ Attila Gobi
+ Jacek Generowicz
+ Alejandro J. Cura
+ Jacob Oscarson
+ Travis Francis Athougies
+ Ryan Gonzalez
+ Ian Foote
+ Kristjan Valur Jonsson
+ Neil Blakey-Milner
+ Lutz Paelike
+ Lucio Torre
+ Lars Wassermann
+ Valentina Mukhamedzhanova
+ Henrik Vendelbo
+ Dan Buch
+ Miguel de Val Borro
+ Artur Lisiecki
+ Sergey Kishchenko
+ Yichao Yu
+ Ignas Mikalajunas
+ Christoph Gerum
+ Martin Blais
+ Lene Wagner
+ Tomo Cocoa
+ roberto at goyle
+ Yury V. Zaytsev
+ Anna Katrina Dominguez
+ William Leslie
+ Bobby Impollonia
+ timo at eistee.fritz.box
+ Andrew Thompson
+ Yusei Tahara
+ Ben Darnell
+ Roberto De Ioris
+ Juan Francisco Cantero Hurtado
+ Godefroid Chappelle
+ Joshua Gilbert
+ Dan Colish
+ Christopher Armstrong
+ Michael Hudson-Doyle
+ Anders Sigfridsson
+ Yasir Suhail
+ Jason Michalski
+ rafalgalczynski at gmail.com
+ Floris Bruynooghe
+ Laurens Van Houtven
+ Akira Li
+ Gustavo Niemeyer
+ Stephan Busemann
+ Rafał Gałczyński
+ Christian Muirhead
+ James Lan
+ shoma hosaka
+ Daniel Neuh?user
+ Matthew Miller
+ Buck Golemon
+ Konrad Delong
+ Dinu Gherman
+ Chris Lambacher
+ coolbutuseless at gmail.com
+ Rodrigo Araújo
+ Jim Baker
+ James Robert
+ Armin Ronacher
+ Brett Cannon
+ yrttyr
+ aliceinwire
+ OlivierBlanvillain
+ Zooko Wilcox-O Hearn
+ Tomer Chachamu
+ Christopher Groskopf
+ Asmo Soinio
+ Stefan Marr
+ jiaaro
+ Mads Kiilerich
+ opassembler.py
+ Antony Lee
+ Jim Hunziker
+ Markus Unterwaditzer
+ Even Wiik Thomassen
+ jbs
+ soareschen
+ Kurt Griffiths
+ Mike Bayer
+ Matthew Miller
+ Flavio Percoco
+ Kristoffer Kleine
+ yasirs
+ Michael Chermside
+ Anna Ravencroft
+ Dan Crosta
+ Julien Phalip
+ Dan Loewenherz
- Heinrich-Heine University, Germany
- Open End AB (formerly AB Strakt), Sweden
- merlinux GmbH, Germany
- tismerysoft GmbH, Germany
- Logilab Paris, France
- DFKI GmbH, Germany
- Impara, Germany
- Change Maker, Sweden
- University of California Berkeley, USA
- Google Inc.
- King's College London
+ Heinrich-Heine University, Germany
+ Open End AB (formerly AB Strakt), Sweden
+ merlinux GmbH, Germany
+ tismerysoft GmbH, Germany
+ Logilab Paris, France
+ DFKI GmbH, Germany
+ Impara, Germany
+ Change Maker, Sweden
+ University of California Berkeley, USA
+ Google Inc.
+ King's College London
The PyPy Logo as used by http://speed.pypy.org and others was created
by Samuel Reis and is distributed on terms of Creative Commons Share Alike
@@ -354,6 +364,46 @@
See the License for the specific language governing permissions and
limitations under the License.
-Detailled license information is contained in the NOTICE file in the
+Detailed license information is contained in the NOTICE file in the
directory.
+
+Licenses and Acknowledgements for Incorporated Software
+=======================================================
+
+This section is an incomplete, but growing list of licenses and
+acknowledgements for third-party software incorporated in the PyPy
+distribution.
+
+License for 'Tcl/Tk'
+--------------------
+
+This copy of PyPy contains library code that may, when used, result in
+the Tcl/Tk library to be loaded. PyPy also includes code that may be
+regarded as being a copy of some parts of the Tcl/Tk header files.
+You may see a copy of the License for Tcl/Tk in the file
+`lib_pypy/_tkinter/license.terms` included here.
+
+License for 'bzip2'
+-------------------
+
+This copy of PyPy may be linked (dynamically or statically) with the
+bzip2 library. You may see a copy of the License for bzip2/libbzip2 at
+
+ http://www.bzip.org/1.0.5/bzip2-manual-1.0.5.html
+
+License for 'openssl'
+---------------------
+
+This copy of PyPy may be linked (dynamically or statically) with the
+openssl library. You may see a copy of the License for OpenSSL at
+
+ https://www.openssl.org/source/license.html
+
+License for 'gdbm'
+------------------
+
+The gdbm module includes code from gdbm.h, which is distributed under
+the terms of the GPL license version 2 or any later version. Thus the
+gdbm module, provided in the file lib_pypy/gdbm.py, is redistributed
+under the terms of the GPL license as well.
diff --git a/_pytest/README-BEFORE-UPDATING b/_pytest/README-BEFORE-UPDATING
new file mode 100644
--- /dev/null
+++ b/_pytest/README-BEFORE-UPDATING
@@ -0,0 +1,17 @@
+This is PyPy's code of the pytest lib. We don't expect to upgrade it
+very often, but once we do:
+
+ WARNING!
+
+ WE HAVE MADE A FEW TWEAKS HERE!
+
+Please be sure that you don't just copy the newer version from
+upstream without checking the few changes that we did. This
+can be done like this:
+
+ cd <this directory>
+ hg log . -v | less
+
+then search for all " _pytest/" in that list to know which are the
+relevant checkins. (Look for the checkins that only edit one
+or two files in this directory.)
diff --git a/_pytest/resultlog.py b/_pytest/resultlog.py
--- a/_pytest/resultlog.py
+++ b/_pytest/resultlog.py
@@ -53,16 +53,24 @@
self.config = config
self.logfile = logfile # preferably line buffered
- def write_log_entry(self, testpath, lettercode, longrepr):
- py.builtin.print_("%s %s" % (lettercode, testpath), file=self.logfile)
+ def write_log_entry(self, testpath, lettercode, longrepr, sections=None):
+ _safeprint("%s %s" % (lettercode, testpath), file=self.logfile)
for line in longrepr.splitlines():
- py.builtin.print_(" %s" % line, file=self.logfile)
+ _safeprint(" %s" % line, file=self.logfile)
+ if sections is not None and (
+ lettercode in ('E', 'F')): # to limit the size of logs
+ for title, content in sections:
+ _safeprint(" ---------- %s ----------" % (title,),
+ file=self.logfile)
+ for line in content.splitlines():
+ _safeprint(" %s" % line, file=self.logfile)
def log_outcome(self, report, lettercode, longrepr):
testpath = getattr(report, 'nodeid', None)
if testpath is None:
testpath = report.fspath
- self.write_log_entry(testpath, lettercode, longrepr)
+ self.write_log_entry(testpath, lettercode, longrepr,
+ getattr(report, 'sections', None))
def pytest_runtest_logreport(self, report):
if report.when != "call" and report.passed:
@@ -98,3 +106,8 @@
if path is None:
path = "cwd:%s" % py.path.local()
self.write_log_entry(path, '!', str(excrepr))
+
+def _safeprint(s, file):
+ if isinstance(s, unicode):
+ s = s.encode('utf-8')
+ py.builtin.print_(s, file=file)
diff --git a/lib-python/2.7/CGIHTTPServer.py b/lib-python/2.7/CGIHTTPServer.py
--- a/lib-python/2.7/CGIHTTPServer.py
+++ b/lib-python/2.7/CGIHTTPServer.py
@@ -84,7 +84,7 @@
path begins with one of the strings in self.cgi_directories
(and the next character is a '/' or the end of the string).
"""
- collapsed_path = _url_collapse_path(self.path)
+ collapsed_path = _url_collapse_path(urllib.unquote(self.path))
dir_sep = collapsed_path.find('/', 1)
head, tail = collapsed_path[:dir_sep], collapsed_path[dir_sep+1:]
if head in self.cgi_directories:
diff --git a/lib-python/2.7/Cookie.py b/lib-python/2.7/Cookie.py
--- a/lib-python/2.7/Cookie.py
+++ b/lib-python/2.7/Cookie.py
@@ -1,6 +1,3 @@
-#!/usr/bin/env python
-#
-
####
# Copyright 2000 by Timothy O'Malley <timo at alum.mit.edu>
#
diff --git a/lib-python/2.7/HTMLParser.py b/lib-python/2.7/HTMLParser.py
--- a/lib-python/2.7/HTMLParser.py
+++ b/lib-python/2.7/HTMLParser.py
@@ -22,9 +22,12 @@
starttagopen = re.compile('<[a-zA-Z]')
piclose = re.compile('>')
commentclose = re.compile(r'--\s*>')
-tagfind = re.compile('([a-zA-Z][-.a-zA-Z0-9:_]*)(?:\s|/(?!>))*')
+
# see http://www.w3.org/TR/html5/tokenization.html#tag-open-state
# and http://www.w3.org/TR/html5/tokenization.html#tag-name-state
+# note: if you change tagfind/attrfind remember to update locatestarttagend too
+tagfind = re.compile('([a-zA-Z][^\t\n\r\f />\x00]*)(?:\s|/(?!>))*')
+# this regex is currently unused, but left for backward compatibility
tagfind_tolerant = re.compile('[a-zA-Z][^\t\n\r\f />\x00]*')
attrfind = re.compile(
@@ -32,7 +35,7 @@
r'(\'[^\']*\'|"[^"]*"|(?![\'"])[^>\s]*))?(?:\s|/(?!>))*')
locatestarttagend = re.compile(r"""
- <[a-zA-Z][-.a-zA-Z0-9:_]* # tag name
+ <[a-zA-Z][^\t\n\r\f />\x00]* # tag name
(?:[\s/]* # optional whitespace before attribute name
(?:(?<=['"\s/])[^\s/>][^\s/=>]* # attribute name
(?:\s*=+\s* # value indicator
@@ -192,9 +195,9 @@
i = self.updatepos(i, k)
continue
else:
- if ";" in rawdata[i:]: #bail by consuming &#
- self.handle_data(rawdata[0:2])
- i = self.updatepos(i, 2)
+ if ";" in rawdata[i:]: # bail by consuming '&#'
+ self.handle_data(rawdata[i:i+2])
+ i = self.updatepos(i, i+2)
break
elif startswith('&', i):
match = entityref.match(rawdata, i)
@@ -373,14 +376,14 @@
self.handle_data(rawdata[i:gtpos])
return gtpos
# find the name: w3.org/TR/html5/tokenization.html#tag-name-state
- namematch = tagfind_tolerant.match(rawdata, i+2)
+ namematch = tagfind.match(rawdata, i+2)
if not namematch:
# w3.org/TR/html5/tokenization.html#end-tag-open-state
if rawdata[i:i+3] == '</>':
return i+3
else:
return self.parse_bogus_comment(i)
- tagname = namematch.group().lower()
+ tagname = namematch.group(1).lower()
# consume and ignore other stuff between the name and the >
# Note: this is not 100% correct, since we might have things like
# </tag attr=">">, but looking for > after tha name should cover
diff --git a/lib-python/2.7/SimpleHTTPServer.py b/lib-python/2.7/SimpleHTTPServer.py
--- a/lib-python/2.7/SimpleHTTPServer.py
+++ b/lib-python/2.7/SimpleHTTPServer.py
@@ -43,8 +43,10 @@
"""Serve a GET request."""
f = self.send_head()
if f:
- self.copyfile(f, self.wfile)
- f.close()
+ try:
+ self.copyfile(f, self.wfile)
+ finally:
+ f.close()
def do_HEAD(self):
"""Serve a HEAD request."""
@@ -88,13 +90,17 @@
except IOError:
self.send_error(404, "File not found")
return None
- self.send_response(200)
- self.send_header("Content-type", ctype)
- fs = os.fstat(f.fileno())
- self.send_header("Content-Length", str(fs[6]))
- self.send_header("Last-Modified", self.date_time_string(fs.st_mtime))
- self.end_headers()
- return f
+ try:
+ self.send_response(200)
+ self.send_header("Content-type", ctype)
+ fs = os.fstat(f.fileno())
+ self.send_header("Content-Length", str(fs[6]))
+ self.send_header("Last-Modified", self.date_time_string(fs.st_mtime))
+ self.end_headers()
+ return f
+ except:
+ f.close()
+ raise
def list_directory(self, path):
"""Helper to produce a directory listing (absent index.html).
diff --git a/lib-python/2.7/SimpleXMLRPCServer.py b/lib-python/2.7/SimpleXMLRPCServer.py
--- a/lib-python/2.7/SimpleXMLRPCServer.py
+++ b/lib-python/2.7/SimpleXMLRPCServer.py
@@ -704,4 +704,5 @@
server = SimpleXMLRPCServer(("localhost", 8000))
server.register_function(pow)
server.register_function(lambda x,y: x+y, 'add')
+ server.register_multicall_functions()
server.serve_forever()
diff --git a/lib-python/2.7/SocketServer.py b/lib-python/2.7/SocketServer.py
--- a/lib-python/2.7/SocketServer.py
+++ b/lib-python/2.7/SocketServer.py
@@ -513,35 +513,37 @@
def collect_children(self):
"""Internal routine to wait for children that have exited."""
- if self.active_children is None: return
+ if self.active_children is None:
+ return
+
+ # If we're above the max number of children, wait and reap them until
+ # we go back below threshold. Note that we use waitpid(-1) below to be
+ # able to collect children in size(<defunct children>) syscalls instead
+ # of size(<children>): the downside is that this might reap children
+ # which we didn't spawn, which is why we only resort to this when we're
+ # above max_children.
while len(self.active_children) >= self.max_children:
- # XXX: This will wait for any child process, not just ones
- # spawned by this library. This could confuse other
- # libraries that expect to be able to wait for their own
- # children.
try:
- pid, status = os.waitpid(0, 0)
- except os.error:
- pid = None
- if pid not in self.active_children: continue
- self.active_children.remove(pid)
+ pid, _ = os.waitpid(-1, 0)
+ self.active_children.discard(pid)
+ except OSError as e:
+ if e.errno == errno.ECHILD:
+ # we don't have any children, we're done
+ self.active_children.clear()
+ elif e.errno != errno.EINTR:
+ break
- # XXX: This loop runs more system calls than it ought
- # to. There should be a way to put the active_children into a
- # process group and then use os.waitpid(-pgid) to wait for any
- # of that set, but I couldn't find a way to allocate pgids
- # that couldn't collide.
- for child in self.active_children:
+ # Now reap all defunct children.
+ for pid in self.active_children.copy():
try:
- pid, status = os.waitpid(child, os.WNOHANG)
- except os.error:
- pid = None
- if not pid: continue
- try:
- self.active_children.remove(pid)
- except ValueError, e:
- raise ValueError('%s. x=%d and list=%r' % (e.message, pid,
- self.active_children))
+ pid, _ = os.waitpid(pid, os.WNOHANG)
+ # if the child hasn't exited yet, pid will be 0 and ignored by
+ # discard() below
+ self.active_children.discard(pid)
+ except OSError as e:
+ if e.errno == errno.ECHILD:
+ # someone else reaped it
+ self.active_children.discard(pid)
def handle_timeout(self):
"""Wait for zombies after self.timeout seconds of inactivity.
@@ -557,8 +559,8 @@
if pid:
# Parent process
if self.active_children is None:
- self.active_children = []
- self.active_children.append(pid)
+ self.active_children = set()
+ self.active_children.add(pid)
self.close_request(request) #close handle in parent process
return
else:
diff --git a/lib-python/2.7/_MozillaCookieJar.py b/lib-python/2.7/_MozillaCookieJar.py
--- a/lib-python/2.7/_MozillaCookieJar.py
+++ b/lib-python/2.7/_MozillaCookieJar.py
@@ -39,7 +39,7 @@
magic_re = "#( Netscape)? HTTP Cookie File"
header = """\
# Netscape HTTP Cookie File
-# http://www.netscape.com/newsref/std/cookie_spec.html
+# http://curl.haxx.se/rfc/cookie_spec.html
# This is a generated file! Do not edit.
"""
diff --git a/lib-python/2.7/_abcoll.py b/lib-python/2.7/_abcoll.py
--- a/lib-python/2.7/_abcoll.py
+++ b/lib-python/2.7/_abcoll.py
@@ -165,12 +165,17 @@
def __gt__(self, other):
if not isinstance(other, Set):
return NotImplemented
- return other < self
+ return len(self) > len(other) and self.__ge__(other)
def __ge__(self, other):
if not isinstance(other, Set):
return NotImplemented
- return other <= self
+ if len(self) < len(other):
+ return False
+ for elem in other:
+ if elem not in self:
+ return False
+ return True
def __eq__(self, other):
if not isinstance(other, Set):
@@ -194,6 +199,8 @@
return NotImplemented
return self._from_iterable(value for value in other if value in self)
+ __rand__ = __and__
+
def isdisjoint(self, other):
'Return True if two sets have a null intersection.'
for value in other:
@@ -207,6 +214,8 @@
chain = (e for s in (self, other) for e in s)
return self._from_iterable(chain)
+ __ror__ = __or__
+
def __sub__(self, other):
if not isinstance(other, Set):
if not isinstance(other, Iterable):
@@ -215,6 +224,14 @@
return self._from_iterable(value for value in self
if value not in other)
+ def __rsub__(self, other):
+ if not isinstance(other, Set):
+ if not isinstance(other, Iterable):
+ return NotImplemented
+ other = self._from_iterable(other)
+ return self._from_iterable(value for value in other
+ if value not in self)
+
def __xor__(self, other):
if not isinstance(other, Set):
if not isinstance(other, Iterable):
@@ -222,6 +239,8 @@
other = self._from_iterable(other)
return (self - other) | (other - self)
+ __rxor__ = __xor__
+
# Sets are not hashable by default, but subclasses can change this
__hash__ = None
diff --git a/lib-python/2.7/_osx_support.py b/lib-python/2.7/_osx_support.py
--- a/lib-python/2.7/_osx_support.py
+++ b/lib-python/2.7/_osx_support.py
@@ -182,7 +182,7 @@
# Compiler is GCC, check if it is LLVM-GCC
data = _read_output("'%s' --version"
% (cc.replace("'", "'\"'\"'"),))
- if 'llvm-gcc' in data:
+ if data and 'llvm-gcc' in data:
# Found LLVM-GCC, fall back to clang
cc = _find_build_tool('clang')
@@ -450,8 +450,16 @@
# case and disallow installs.
cflags = _config_vars.get(_INITPRE+'CFLAGS',
_config_vars.get('CFLAGS', ''))
- if ((macrelease + '.') >= '10.4.' and
- '-arch' in cflags.strip()):
+ if macrelease:
+ try:
+ macrelease = tuple(int(i) for i in macrelease.split('.')[0:2])
+ except ValueError:
+ macrelease = (10, 0)
+ else:
+ # assume no universal support
+ macrelease = (10, 0)
+
+ if (macrelease >= (10, 4)) and '-arch' in cflags.strip():
# The universal build will build fat binaries, but not on
# systems before 10.4
diff --git a/lib-python/2.7/_pyio.py b/lib-python/2.7/_pyio.py
--- a/lib-python/2.7/_pyio.py
+++ b/lib-python/2.7/_pyio.py
@@ -192,38 +192,45 @@
(appending and "a" or "") +
(updating and "+" or ""),
closefd)
- line_buffering = False
- if buffering == 1 or buffering < 0 and raw.isatty():
- buffering = -1
- line_buffering = True
- if buffering < 0:
- buffering = DEFAULT_BUFFER_SIZE
- try:
- bs = os.fstat(raw.fileno()).st_blksize
- except (os.error, AttributeError):
- pass
+ result = raw
+ try:
+ line_buffering = False
+ if buffering == 1 or buffering < 0 and raw.isatty():
+ buffering = -1
+ line_buffering = True
+ if buffering < 0:
+ buffering = DEFAULT_BUFFER_SIZE
+ try:
+ bs = os.fstat(raw.fileno()).st_blksize
+ except (os.error, AttributeError):
+ pass
+ else:
+ if bs > 1:
+ buffering = bs
+ if buffering < 0:
+ raise ValueError("invalid buffering size")
+ if buffering == 0:
+ if binary:
+ return result
+ raise ValueError("can't have unbuffered text I/O")
+ if updating:
+ buffer = BufferedRandom(raw, buffering)
+ elif writing or appending:
+ buffer = BufferedWriter(raw, buffering)
+ elif reading:
+ buffer = BufferedReader(raw, buffering)
else:
- if bs > 1:
- buffering = bs
- if buffering < 0:
- raise ValueError("invalid buffering size")
- if buffering == 0:
+ raise ValueError("unknown mode: %r" % mode)
+ result = buffer
if binary:
- return raw
- raise ValueError("can't have unbuffered text I/O")
- if updating:
- buffer = BufferedRandom(raw, buffering)
- elif writing or appending:
- buffer = BufferedWriter(raw, buffering)
- elif reading:
- buffer = BufferedReader(raw, buffering)
- else:
- raise ValueError("unknown mode: %r" % mode)
- if binary:
- return buffer
- text = TextIOWrapper(buffer, encoding, errors, newline, line_buffering)
- text.mode = mode
- return text
+ return result
+ text = TextIOWrapper(buffer, encoding, errors, newline, line_buffering)
+ result = text
+ text.mode = mode
+ return result
+ except:
+ result.close()
+ raise
class DocDescriptor:
@@ -1997,7 +2004,13 @@
def getvalue(self):
self.flush()
- return self.buffer.getvalue().decode(self._encoding, self._errors)
+ decoder = self._decoder or self._get_decoder()
+ old_state = decoder.getstate()
+ decoder.reset()
+ try:
+ return decoder.decode(self.buffer.getvalue(), final=True)
+ finally:
+ decoder.setstate(old_state)
def __repr__(self):
# TextIOWrapper tells the encoding in its repr. In StringIO,
diff --git a/lib-python/2.7/_weakrefset.py b/lib-python/2.7/_weakrefset.py
--- a/lib-python/2.7/_weakrefset.py
+++ b/lib-python/2.7/_weakrefset.py
@@ -60,6 +60,8 @@
for itemref in self.data:
item = itemref()
if item is not None:
+ # Caveat: the iterator will keep a strong reference to
+ # `item` until it is resumed or closed.
yield item
def __len__(self):
diff --git a/lib-python/2.7/aifc.py b/lib-python/2.7/aifc.py
--- a/lib-python/2.7/aifc.py
+++ b/lib-python/2.7/aifc.py
@@ -778,7 +778,7 @@
def _ensure_header_written(self, datasize):
if not self._nframeswritten:
- if self._comptype in ('ULAW', 'ALAW'):
+ if self._comptype in ('ULAW', 'ulaw', 'ALAW', 'alaw'):
if not self._sampwidth:
self._sampwidth = 2
if self._sampwidth != 2:
@@ -844,7 +844,7 @@
if self._datalength & 1:
self._datalength = self._datalength + 1
if self._aifc:
- if self._comptype in ('ULAW', 'ALAW'):
+ if self._comptype in ('ULAW', 'ulaw', 'ALAW', 'alaw'):
self._datalength = self._datalength // 2
if self._datalength & 1:
self._datalength = self._datalength + 1
@@ -852,7 +852,10 @@
self._datalength = (self._datalength + 3) // 4
if self._datalength & 1:
self._datalength = self._datalength + 1
- self._form_length_pos = self._file.tell()
+ try:
+ self._form_length_pos = self._file.tell()
+ except (AttributeError, IOError):
+ self._form_length_pos = None
commlength = self._write_form_length(self._datalength)
if self._aifc:
self._file.write('AIFC')
@@ -864,7 +867,8 @@
self._file.write('COMM')
_write_ulong(self._file, commlength)
_write_short(self._file, self._nchannels)
- self._nframes_pos = self._file.tell()
+ if self._form_length_pos is not None:
+ self._nframes_pos = self._file.tell()
_write_ulong(self._file, self._nframes)
if self._comptype in ('ULAW', 'ulaw', 'ALAW', 'alaw', 'G722'):
_write_short(self._file, 8)
@@ -875,7 +879,8 @@
self._file.write(self._comptype)
_write_string(self._file, self._compname)
self._file.write('SSND')
- self._ssnd_length_pos = self._file.tell()
+ if self._form_length_pos is not None:
+ self._ssnd_length_pos = self._file.tell()
_write_ulong(self._file, self._datalength + 8)
_write_ulong(self._file, 0)
_write_ulong(self._file, 0)
diff --git a/lib-python/2.7/argparse.py b/lib-python/2.7/argparse.py
--- a/lib-python/2.7/argparse.py
+++ b/lib-python/2.7/argparse.py
@@ -168,6 +168,8 @@
self._prog = prog
self._indent_increment = indent_increment
self._max_help_position = max_help_position
+ self._max_help_position = min(max_help_position,
+ max(width - 20, indent_increment * 2))
self._width = width
self._current_indent = 0
@@ -339,7 +341,7 @@
else:
line_len = len(indent) - 1
for part in parts:
- if line_len + 1 + len(part) > text_width:
+ if line_len + 1 + len(part) > text_width and line:
lines.append(indent + ' '.join(line))
line = []
line_len = len(indent) - 1
@@ -478,7 +480,7 @@
def _format_text(self, text):
if '%(prog)' in text:
text = text % dict(prog=self._prog)
- text_width = self._width - self._current_indent
+ text_width = max(self._width - self._current_indent, 11)
indent = ' ' * self._current_indent
return self._fill_text(text, text_width, indent) + '\n\n'
@@ -486,7 +488,7 @@
# determine the required width and the entry label
help_position = min(self._action_max_length + 2,
self._max_help_position)
- help_width = self._width - help_position
+ help_width = max(self._width - help_position, 11)
action_width = help_position - self._current_indent - 2
action_header = self._format_action_invocation(action)
@@ -1155,9 +1157,13 @@
__hash__ = None
def __eq__(self, other):
+ if not isinstance(other, Namespace):
+ return NotImplemented
return vars(self) == vars(other)
def __ne__(self, other):
+ if not isinstance(other, Namespace):
+ return NotImplemented
return not (self == other)
def __contains__(self, key):
diff --git a/lib-python/2.7/bsddb/dbshelve.py b/lib-python/2.7/bsddb/dbshelve.py
--- a/lib-python/2.7/bsddb/dbshelve.py
+++ b/lib-python/2.7/bsddb/dbshelve.py
@@ -1,4 +1,3 @@
-#!/usr/bin/env python
#------------------------------------------------------------------------
# Copyright (c) 1997-2001 by Total Control Software
# All Rights Reserved
diff --git a/lib-python/2.7/bsddb/test/test_dbtables.py b/lib-python/2.7/bsddb/test/test_dbtables.py
--- a/lib-python/2.7/bsddb/test/test_dbtables.py
+++ b/lib-python/2.7/bsddb/test/test_dbtables.py
@@ -1,5 +1,3 @@
-#!/usr/bin/env python
-#
#-----------------------------------------------------------------------
# A test suite for the table interface built on bsddb.db
#-----------------------------------------------------------------------
diff --git a/lib-python/2.7/codecs.py b/lib-python/2.7/codecs.py
--- a/lib-python/2.7/codecs.py
+++ b/lib-python/2.7/codecs.py
@@ -456,15 +456,12 @@
# read until we get the required number of characters (if available)
while True:
- # can the request can be satisfied from the character buffer?
- if chars < 0:
- if size < 0:
- if self.charbuffer:
- break
- elif len(self.charbuffer) >= size:
+ # can the request be satisfied from the character buffer?
+ if chars >= 0:
+ if len(self.charbuffer) >= chars:
break
- else:
- if len(self.charbuffer) >= chars:
+ elif size >= 0:
+ if len(self.charbuffer) >= size:
break
# we need more data
if size < 0:
diff --git a/lib-python/2.7/collections.py b/lib-python/2.7/collections.py
--- a/lib-python/2.7/collections.py
+++ b/lib-python/2.7/collections.py
@@ -319,6 +319,7 @@
if isinstance(field_names, basestring):
field_names = field_names.replace(',', ' ').split()
field_names = map(str, field_names)
+ typename = str(typename)
if rename:
seen = set()
for index, name in enumerate(field_names):
@@ -331,6 +332,8 @@
field_names[index] = '_%d' % index
seen.add(name)
for name in [typename] + field_names:
+ if type(name) != str:
+ raise TypeError('Type names and field names must be strings')
if not all(c.isalnum() or c=='_' for c in name):
raise ValueError('Type names and field names can only contain '
'alphanumeric characters and underscores: %r' % name)
diff --git a/lib-python/2.7/csv.py b/lib-python/2.7/csv.py
--- a/lib-python/2.7/csv.py
+++ b/lib-python/2.7/csv.py
@@ -93,6 +93,10 @@
self.line_num = self.reader.line_num
return self._fieldnames
+ # Issue 20004: Because DictReader is a classic class, this setter is
+ # ignored. At this point in 2.7's lifecycle, it is too late to change the
+ # base class for fear of breaking working code. If you want to change
+ # fieldnames without overwriting the getter, set _fieldnames directly.
@fieldnames.setter
def fieldnames(self, value):
self._fieldnames = value
@@ -140,8 +144,8 @@
if self.extrasaction == "raise":
wrong_fields = [k for k in rowdict if k not in self.fieldnames]
if wrong_fields:
- raise ValueError("dict contains fields not in fieldnames: " +
- ", ".join(wrong_fields))
+ raise ValueError("dict contains fields not in fieldnames: "
+ + ", ".join([repr(x) for x in wrong_fields]))
return [rowdict.get(key, self.restval) for key in self.fieldnames]
def writerow(self, rowdict):
diff --git a/lib-python/2.7/ctypes/test/__init__.py b/lib-python/2.7/ctypes/test/__init__.py
--- a/lib-python/2.7/ctypes/test/__init__.py
+++ b/lib-python/2.7/ctypes/test/__init__.py
@@ -2,7 +2,15 @@
use_resources = []
-class ResourceDenied(Exception):
+import ctypes
+ctypes_symbols = dir(ctypes)
+
+def need_symbol(name):
+ return unittest.skipUnless(name in ctypes_symbols,
+ '{!r} is required'.format(name))
+
+
+class ResourceDenied(unittest.SkipTest):
"""Test skipped because it requested a disallowed resource.
This is raised when a test calls requires() for a resource that
diff --git a/lib-python/2.7/ctypes/test/test_arrays.py b/lib-python/2.7/ctypes/test/test_arrays.py
--- a/lib-python/2.7/ctypes/test/test_arrays.py
+++ b/lib-python/2.7/ctypes/test/test_arrays.py
@@ -2,6 +2,8 @@
from ctypes import *
from test.test_support import impl_detail
+from ctypes.test import need_symbol
+
formats = "bBhHiIlLqQfd"
# c_longdouble commented out for PyPy, look at the commend in test_longdouble
@@ -98,8 +100,8 @@
self.assertEqual(values, [1, 2, 3, 4, 5])
def test_classcache(self):
- self.assertTrue(not ARRAY(c_int, 3) is ARRAY(c_int, 4))
- self.assertTrue(ARRAY(c_int, 3) is ARRAY(c_int, 3))
+ self.assertIsNot(ARRAY(c_int, 3), ARRAY(c_int, 4))
+ self.assertIs(ARRAY(c_int, 3), ARRAY(c_int, 3))
def test_from_address(self):
# Failed with 0.9.8, reported by JUrner
@@ -112,20 +114,16 @@
self.assertEqual(sz[1:4:2], "o")
self.assertEqual(sz.value, "foo")
- try:
- create_unicode_buffer
- except NameError:
- pass
- else:
- def test_from_addressW(self):
- p = create_unicode_buffer("foo")
- sz = (c_wchar * 3).from_address(addressof(p))
- self.assertEqual(sz[:], "foo")
- self.assertEqual(sz[::], "foo")
- self.assertEqual(sz[::-1], "oof")
- self.assertEqual(sz[::3], "f")
- self.assertEqual(sz[1:4:2], "o")
- self.assertEqual(sz.value, "foo")
+ @need_symbol('create_unicode_buffer')
+ def test_from_addressW(self):
+ p = create_unicode_buffer("foo")
+ sz = (c_wchar * 3).from_address(addressof(p))
+ self.assertEqual(sz[:], "foo")
+ self.assertEqual(sz[::], "foo")
+ self.assertEqual(sz[::-1], "oof")
+ self.assertEqual(sz[::3], "f")
+ self.assertEqual(sz[1:4:2], "o")
+ self.assertEqual(sz.value, "foo")
def test_cache(self):
# Array types are cached internally in the _ctypes extension,
@@ -139,7 +137,7 @@
# Create a new array type based on it:
t1 = my_int * 1
t2 = my_int * 1
- self.assertTrue(t1 is t2)
+ self.assertIs(t1, t2)
if __name__ == '__main__':
unittest.main()
diff --git a/lib-python/2.7/ctypes/test/test_as_parameter.py b/lib-python/2.7/ctypes/test/test_as_parameter.py
--- a/lib-python/2.7/ctypes/test/test_as_parameter.py
+++ b/lib-python/2.7/ctypes/test/test_as_parameter.py
@@ -1,5 +1,6 @@
import unittest
from ctypes import *
+from ctypes.test import need_symbol
import _ctypes_test
dll = CDLL(_ctypes_test.__file__)
@@ -17,11 +18,8 @@
def wrap(self, param):
return param
+ @need_symbol('c_wchar')
def test_wchar_parm(self):
- try:
- c_wchar
- except NameError:
- return
f = dll._testfunc_i_bhilfd
f.argtypes = [c_byte, c_wchar, c_int, c_long, c_float, c_double]
result = f(self.wrap(1), self.wrap(u"x"), self.wrap(3), self.wrap(4), self.wrap(5.0), self.wrap(6.0))
@@ -134,7 +132,7 @@
f.argtypes = [c_longlong, MyCallback]
def callback(value):
- self.assertTrue(isinstance(value, (int, long)))
+ self.assertIsInstance(value, (int, long))
return value & 0x7FFFFFFF
cb = MyCallback(callback)
diff --git a/lib-python/2.7/ctypes/test/test_bitfields.py b/lib-python/2.7/ctypes/test/test_bitfields.py
--- a/lib-python/2.7/ctypes/test/test_bitfields.py
+++ b/lib-python/2.7/ctypes/test/test_bitfields.py
@@ -1,4 +1,5 @@
from ctypes import *
+from ctypes.test import need_symbol
import unittest
import os
@@ -131,15 +132,6 @@
self.assertEqual(result[0], TypeError)
self.assertIn('bit fields not allowed for type', result[1])
- try:
- c_wchar
- except NameError:
- pass
- else:
- result = self.fail_fields(("a", c_wchar, 1))
- self.assertEqual(result[0], TypeError)
- self.assertIn('bit fields not allowed for type', result[1])
-
class Dummy(Structure):
_fields_ = []
@@ -147,6 +139,12 @@
self.assertEqual(result[0], TypeError)
self.assertIn('bit fields not allowed for type', result[1])
+ @need_symbol('c_wchar')
+ def test_c_wchar(self):
+ result = self.fail_fields(("a", c_wchar, 1))
+ self.assertEqual(result,
+ (TypeError, 'bit fields not allowed for type c_wchar'))
+
def test_single_bitfield_size(self):
for c_typ in int_types:
result = self.fail_fields(("a", c_typ, -1))
@@ -213,7 +211,7 @@
class X(Structure):
_fields_ = [("a", c_byte, 4),
("b", c_int, 32)]
- self.assertEqual(sizeof(X), sizeof(c_int)*2)
+ self.assertEqual(sizeof(X), alignment(c_int)+sizeof(c_int))
def test_mixed_3(self):
class X(Structure):
@@ -246,7 +244,7 @@
_anonymous_ = ["_"]
_fields_ = [("_", X)]
- @unittest.skipUnless(hasattr(ctypes, "c_uint32"), "c_int32 is required")
+ @need_symbol('c_uint32')
def test_uint32(self):
class X(Structure):
_fields_ = [("a", c_uint32, 32)]
@@ -256,7 +254,7 @@
x.a = 0xFDCBA987
self.assertEqual(x.a, 0xFDCBA987)
- @unittest.skipUnless(hasattr(ctypes, "c_uint64"), "c_int64 is required")
+ @need_symbol('c_uint64')
def test_uint64(self):
class X(Structure):
_fields_ = [("a", c_uint64, 64)]
diff --git a/lib-python/2.7/ctypes/test/test_buffers.py b/lib-python/2.7/ctypes/test/test_buffers.py
--- a/lib-python/2.7/ctypes/test/test_buffers.py
+++ b/lib-python/2.7/ctypes/test/test_buffers.py
@@ -1,4 +1,5 @@
from ctypes import *
+from ctypes.test import need_symbol
import unittest
class StringBufferTestCase(unittest.TestCase):
@@ -7,12 +8,12 @@
b = create_string_buffer(32)
self.assertEqual(len(b), 32)
self.assertEqual(sizeof(b), 32 * sizeof(c_char))
- self.assertTrue(type(b[0]) is str)
+ self.assertIs(type(b[0]), str)
b = create_string_buffer("abc")
self.assertEqual(len(b), 4) # trailing nul char
self.assertEqual(sizeof(b), 4 * sizeof(c_char))
- self.assertTrue(type(b[0]) is str)
+ self.assertIs(type(b[0]), str)
self.assertEqual(b[0], "a")
self.assertEqual(b[:], "abc\0")
self.assertEqual(b[::], "abc\0")
@@ -36,39 +37,36 @@
self.assertEqual(b[::2], "ac")
self.assertEqual(b[::5], "a")
- try:
- c_wchar
- except NameError:
- pass
- else:
- def test_unicode_buffer(self):
- b = create_unicode_buffer(32)
- self.assertEqual(len(b), 32)
- self.assertEqual(sizeof(b), 32 * sizeof(c_wchar))
- self.assertTrue(type(b[0]) is unicode)
+ @need_symbol('c_wchar')
+ def test_unicode_buffer(self):
+ b = create_unicode_buffer(32)
+ self.assertEqual(len(b), 32)
+ self.assertEqual(sizeof(b), 32 * sizeof(c_wchar))
+ self.assertIs(type(b[0]), unicode)
- b = create_unicode_buffer(u"abc")
- self.assertEqual(len(b), 4) # trailing nul char
- self.assertEqual(sizeof(b), 4 * sizeof(c_wchar))
- self.assertTrue(type(b[0]) is unicode)
- self.assertEqual(b[0], u"a")
- self.assertEqual(b[:], "abc\0")
- self.assertEqual(b[::], "abc\0")
- self.assertEqual(b[::-1], "\0cba")
- self.assertEqual(b[::2], "ac")
- self.assertEqual(b[::5], "a")
+ b = create_unicode_buffer(u"abc")
+ self.assertEqual(len(b), 4) # trailing nul char
+ self.assertEqual(sizeof(b), 4 * sizeof(c_wchar))
+ self.assertIs(type(b[0]), unicode)
+ self.assertEqual(b[0], u"a")
+ self.assertEqual(b[:], "abc\0")
+ self.assertEqual(b[::], "abc\0")
+ self.assertEqual(b[::-1], "\0cba")
+ self.assertEqual(b[::2], "ac")
+ self.assertEqual(b[::5], "a")
- def test_unicode_conversion(self):
- b = create_unicode_buffer("abc")
- self.assertEqual(len(b), 4) # trailing nul char
- self.assertEqual(sizeof(b), 4 * sizeof(c_wchar))
- self.assertTrue(type(b[0]) is unicode)
- self.assertEqual(b[0], u"a")
- self.assertEqual(b[:], "abc\0")
- self.assertEqual(b[::], "abc\0")
- self.assertEqual(b[::-1], "\0cba")
- self.assertEqual(b[::2], "ac")
- self.assertEqual(b[::5], "a")
+ @need_symbol('c_wchar')
+ def test_unicode_conversion(self):
+ b = create_unicode_buffer("abc")
+ self.assertEqual(len(b), 4) # trailing nul char
+ self.assertEqual(sizeof(b), 4 * sizeof(c_wchar))
+ self.assertIs(type(b[0]), unicode)
+ self.assertEqual(b[0], u"a")
+ self.assertEqual(b[:], "abc\0")
+ self.assertEqual(b[::], "abc\0")
+ self.assertEqual(b[::-1], "\0cba")
+ self.assertEqual(b[::2], "ac")
+ self.assertEqual(b[::5], "a")
if __name__ == "__main__":
unittest.main()
diff --git a/lib-python/2.7/ctypes/test/test_byteswap.py b/lib-python/2.7/ctypes/test/test_byteswap.py
--- a/lib-python/2.7/ctypes/test/test_byteswap.py
+++ b/lib-python/2.7/ctypes/test/test_byteswap.py
@@ -15,7 +15,8 @@
# For Structures and Unions, these types are created on demand.
class Test(unittest.TestCase):
- def X_test(self):
+ @unittest.skip('test disabled')
+ def test_X(self):
print >> sys.stderr, sys.byteorder
for i in range(32):
bits = BITS()
@@ -25,11 +26,11 @@
@xfail
def test_endian_short(self):
if sys.byteorder == "little":
- self.assertTrue(c_short.__ctype_le__ is c_short)
- self.assertTrue(c_short.__ctype_be__.__ctype_le__ is c_short)
+ self.assertIs(c_short.__ctype_le__, c_short)
+ self.assertIs(c_short.__ctype_be__.__ctype_le__, c_short)
else:
- self.assertTrue(c_short.__ctype_be__ is c_short)
- self.assertTrue(c_short.__ctype_le__.__ctype_be__ is c_short)
+ self.assertIs(c_short.__ctype_be__, c_short)
+ self.assertIs(c_short.__ctype_le__.__ctype_be__, c_short)
s = c_short.__ctype_be__(0x1234)
self.assertEqual(bin(struct.pack(">h", 0x1234)), "1234")
self.assertEqual(bin(s), "1234")
@@ -53,11 +54,11 @@
@xfail
def test_endian_int(self):
if sys.byteorder == "little":
- self.assertTrue(c_int.__ctype_le__ is c_int)
- self.assertTrue(c_int.__ctype_be__.__ctype_le__ is c_int)
+ self.assertIs(c_int.__ctype_le__, c_int)
+ self.assertIs(c_int.__ctype_be__.__ctype_le__, c_int)
else:
- self.assertTrue(c_int.__ctype_be__ is c_int)
- self.assertTrue(c_int.__ctype_le__.__ctype_be__ is c_int)
+ self.assertIs(c_int.__ctype_be__, c_int)
+ self.assertIs(c_int.__ctype_le__.__ctype_be__, c_int)
s = c_int.__ctype_be__(0x12345678)
self.assertEqual(bin(struct.pack(">i", 0x12345678)), "12345678")
@@ -82,11 +83,11 @@
@xfail
def test_endian_longlong(self):
if sys.byteorder == "little":
- self.assertTrue(c_longlong.__ctype_le__ is c_longlong)
- self.assertTrue(c_longlong.__ctype_be__.__ctype_le__ is c_longlong)
+ self.assertIs(c_longlong.__ctype_le__, c_longlong)
+ self.assertIs(c_longlong.__ctype_be__.__ctype_le__, c_longlong)
else:
- self.assertTrue(c_longlong.__ctype_be__ is c_longlong)
- self.assertTrue(c_longlong.__ctype_le__.__ctype_be__ is c_longlong)
+ self.assertIs(c_longlong.__ctype_be__, c_longlong)
+ self.assertIs(c_longlong.__ctype_le__.__ctype_be__, c_longlong)
s = c_longlong.__ctype_be__(0x1234567890ABCDEF)
self.assertEqual(bin(struct.pack(">q", 0x1234567890ABCDEF)), "1234567890ABCDEF")
@@ -111,11 +112,11 @@
@xfail
def test_endian_float(self):
if sys.byteorder == "little":
- self.assertTrue(c_float.__ctype_le__ is c_float)
- self.assertTrue(c_float.__ctype_be__.__ctype_le__ is c_float)
+ self.assertIs(c_float.__ctype_le__, c_float)
+ self.assertIs(c_float.__ctype_be__.__ctype_le__, c_float)
else:
- self.assertTrue(c_float.__ctype_be__ is c_float)
- self.assertTrue(c_float.__ctype_le__.__ctype_be__ is c_float)
+ self.assertIs(c_float.__ctype_be__, c_float)
+ self.assertIs(c_float.__ctype_le__.__ctype_be__, c_float)
s = c_float(math.pi)
self.assertEqual(bin(struct.pack("f", math.pi)), bin(s))
# Hm, what's the precision of a float compared to a double?
@@ -130,11 +131,11 @@
@xfail
def test_endian_double(self):
if sys.byteorder == "little":
- self.assertTrue(c_double.__ctype_le__ is c_double)
- self.assertTrue(c_double.__ctype_be__.__ctype_le__ is c_double)
+ self.assertIs(c_double.__ctype_le__, c_double)
+ self.assertIs(c_double.__ctype_be__.__ctype_le__, c_double)
else:
- self.assertTrue(c_double.__ctype_be__ is c_double)
- self.assertTrue(c_double.__ctype_le__.__ctype_be__ is c_double)
+ self.assertIs(c_double.__ctype_be__, c_double)
+ self.assertIs(c_double.__ctype_le__.__ctype_be__, c_double)
s = c_double(math.pi)
self.assertEqual(s.value, math.pi)
self.assertEqual(bin(struct.pack("d", math.pi)), bin(s))
@@ -146,14 +147,14 @@
self.assertEqual(bin(struct.pack(">d", math.pi)), bin(s))
def test_endian_other(self):
- self.assertTrue(c_byte.__ctype_le__ is c_byte)
- self.assertTrue(c_byte.__ctype_be__ is c_byte)
+ self.assertIs(c_byte.__ctype_le__, c_byte)
+ self.assertIs(c_byte.__ctype_be__, c_byte)
- self.assertTrue(c_ubyte.__ctype_le__ is c_ubyte)
- self.assertTrue(c_ubyte.__ctype_be__ is c_ubyte)
+ self.assertIs(c_ubyte.__ctype_le__, c_ubyte)
+ self.assertIs(c_ubyte.__ctype_be__, c_ubyte)
- self.assertTrue(c_char.__ctype_le__ is c_char)
- self.assertTrue(c_char.__ctype_be__ is c_char)
+ self.assertIs(c_char.__ctype_le__, c_char)
+ self.assertIs(c_char.__ctype_be__, c_char)
@xfail
def test_struct_fields_1(self):
diff --git a/lib-python/2.7/ctypes/test/test_callbacks.py b/lib-python/2.7/ctypes/test/test_callbacks.py
--- a/lib-python/2.7/ctypes/test/test_callbacks.py
+++ b/lib-python/2.7/ctypes/test/test_callbacks.py
@@ -1,5 +1,6 @@
import unittest
from ctypes import *
+from ctypes.test import need_symbol
from ctypes.test import xfail
import _ctypes_test
@@ -95,9 +96,10 @@
# disabled: would now (correctly) raise a RuntimeWarning about
# a memory leak. A callback function cannot return a non-integral
# C type without causing a memory leak.
-## def test_char_p(self):
-## self.check_type(c_char_p, "abc")
-## self.check_type(c_char_p, "def")
+ @unittest.skip('test disabled')
+ def test_char_p(self):
+ self.check_type(c_char_p, "abc")
+ self.check_type(c_char_p, "def")
@xfail
def test_pyobject(self):
@@ -150,13 +152,12 @@
CFUNCTYPE(None)(lambda x=Nasty(): None)
-try:
- WINFUNCTYPE
-except NameError:
- pass
-else:
- class StdcallCallbacks(Callbacks):
+ at need_symbol('WINFUNCTYPE')
+class StdcallCallbacks(Callbacks):
+ try:
functype = WINFUNCTYPE
+ except NameError:
+ pass
################################################################
@@ -186,7 +187,7 @@
from ctypes.util import find_library
libc_path = find_library("c")
if not libc_path:
- return # cannot test
+ self.skipTest('could not find libc')
libc = CDLL(libc_path)
@CFUNCTYPE(c_int, POINTER(c_int), POINTER(c_int))
@@ -198,23 +199,19 @@
libc.qsort(array, len(array), sizeof(c_int), cmp_func)
self.assertEqual(array[:], [1, 5, 7, 33, 99])
- try:
- WINFUNCTYPE
- except NameError:
- pass
- else:
- def test_issue_8959_b(self):
- from ctypes.wintypes import BOOL, HWND, LPARAM
+ @need_symbol('WINFUNCTYPE')
+ def test_issue_8959_b(self):
+ from ctypes.wintypes import BOOL, HWND, LPARAM
+ global windowCount
+ windowCount = 0
+
+ @WINFUNCTYPE(BOOL, HWND, LPARAM)
+ def EnumWindowsCallbackFunc(hwnd, lParam):
global windowCount
- windowCount = 0
+ windowCount += 1
+ return True #Allow windows to keep enumerating
- @WINFUNCTYPE(BOOL, HWND, LPARAM)
- def EnumWindowsCallbackFunc(hwnd, lParam):
- global windowCount
- windowCount += 1
- return True #Allow windows to keep enumerating
-
- windll.user32.EnumWindows(EnumWindowsCallbackFunc, 0)
+ windll.user32.EnumWindows(EnumWindowsCallbackFunc, 0)
def test_callback_register_int(self):
# Issue #8275: buggy handling of callback args under Win64
diff --git a/lib-python/2.7/ctypes/test/test_cast.py b/lib-python/2.7/ctypes/test/test_cast.py
--- a/lib-python/2.7/ctypes/test/test_cast.py
+++ b/lib-python/2.7/ctypes/test/test_cast.py
@@ -1,4 +1,5 @@
from ctypes import *
+from ctypes.test import need_symbol
import unittest
import sys
@@ -38,14 +39,14 @@
p = cast(array, POINTER(c_char_p))
# array and p share a common _objects attribute
- self.assertTrue(p._objects is array._objects)
+ self.assertIs(p._objects, array._objects)
self.assertEqual(array._objects, {'0': "foo bar", id(array): array})
p[0] = "spam spam"
self.assertEqual(p._objects, {'0': "spam spam", id(array): array})
- self.assertTrue(array._objects is p._objects)
+ self.assertIs(array._objects, p._objects)
p[1] = "foo bar"
self.assertEqual(p._objects, {'1': 'foo bar', '0': "spam spam", id(array): array})
- self.assertTrue(array._objects is p._objects)
+ self.assertIs(array._objects, p._objects)
def test_other(self):
p = cast((c_int * 4)(1, 2, 3, 4), POINTER(c_int))
@@ -75,15 +76,11 @@
self.assertEqual(cast(cast(s, c_void_p), c_char_p).value,
"hiho")
- try:
- c_wchar_p
- except NameError:
- pass
- else:
- def test_wchar_p(self):
- s = c_wchar_p("hiho")
- self.assertEqual(cast(cast(s, c_void_p), c_wchar_p).value,
- "hiho")
+ @need_symbol('c_wchar_p')
+ def test_wchar_p(self):
+ s = c_wchar_p("hiho")
+ self.assertEqual(cast(cast(s, c_void_p), c_wchar_p).value,
+ "hiho")
if __name__ == "__main__":
unittest.main()
diff --git a/lib-python/2.7/ctypes/test/test_cfuncs.py b/lib-python/2.7/ctypes/test/test_cfuncs.py
--- a/lib-python/2.7/ctypes/test/test_cfuncs.py
+++ b/lib-python/2.7/ctypes/test/test_cfuncs.py
@@ -3,6 +3,7 @@
import unittest
from ctypes import *
+from ctypes.test import need_symbol
import _ctypes_test
from test.test_support import impl_detail
@@ -196,7 +197,7 @@
try:
WinDLL
except NameError:
- pass
+ def stdcall_dll(*_): pass
else:
class stdcall_dll(WinDLL):
def __getattr__(self, name):
@@ -206,9 +207,9 @@
setattr(self, name, func)
return func
- class stdcallCFunctions(CFunctions):
- _dll = stdcall_dll(_ctypes_test.__file__)
- pass
+ at need_symbol('WinDLL')
+class stdcallCFunctions(CFunctions):
+ _dll = stdcall_dll(_ctypes_test.__file__)
if __name__ == '__main__':
unittest.main()
diff --git a/lib-python/2.7/ctypes/test/test_checkretval.py b/lib-python/2.7/ctypes/test/test_checkretval.py
--- a/lib-python/2.7/ctypes/test/test_checkretval.py
+++ b/lib-python/2.7/ctypes/test/test_checkretval.py
@@ -1,6 +1,7 @@
import unittest
from ctypes import *
+from ctypes.test import need_symbol
class CHECKED(c_int):
def _check_retval_(value):
@@ -25,15 +26,11 @@
del dll._testfunc_p_p.restype
self.assertEqual(42, dll._testfunc_p_p(42))
- try:
- oledll
- except NameError:
- pass
- else:
- def test_oledll(self):
- self.assertRaises(WindowsError,
- oledll.oleaut32.CreateTypeLib2,
- 0, None, None)
+ @need_symbol('oledll')
+ def test_oledll(self):
+ self.assertRaises(WindowsError,
+ oledll.oleaut32.CreateTypeLib2,
+ 0, None, None)
if __name__ == "__main__":
unittest.main()
diff --git a/lib-python/2.7/ctypes/test/test_errcheck.py b/lib-python/2.7/ctypes/test/test_errcheck.py
deleted file mode 100644
--- a/lib-python/2.7/ctypes/test/test_errcheck.py
+++ /dev/null
@@ -1,19 +0,0 @@
-import sys
-from ctypes import *
-
-##class HMODULE(Structure):
-## _fields_ = [("value", c_void_p)]
-
-## def __repr__(self):
-## return "<HMODULE %s>" % self.value
-
-##windll.kernel32.GetModuleHandleA.restype = HMODULE
-
-##print windll.kernel32.GetModuleHandleA("python23.dll")
-##print hex(sys.dllhandle)
-
-##def nonzero(handle):
-## return (GetLastError(), handle)
-
-##windll.kernel32.GetModuleHandleA.errcheck = nonzero
-##print windll.kernel32.GetModuleHandleA("spam")
diff --git a/lib-python/2.7/ctypes/test/test_find.py b/lib-python/2.7/ctypes/test/test_find.py
--- a/lib-python/2.7/ctypes/test/test_find.py
+++ b/lib-python/2.7/ctypes/test/test_find.py
@@ -1,4 +1,5 @@
import unittest
+import os
import sys
from ctypes import *
from ctypes.util import find_library
@@ -40,43 +41,43 @@
except OSError:
pass
- if lib_gl:
- def test_gl(self):
- if self.gl:
- self.gl.glClearIndex
+ @unittest.skipUnless(lib_gl, 'lib_gl not available')
+ def test_gl(self):
+ if self.gl:
+ self.gl.glClearIndex
- if lib_glu:
- def test_glu(self):
- if self.glu:
- self.glu.gluBeginCurve
+ @unittest.skipUnless(lib_glu, 'lib_glu not available')
+ def test_glu(self):
+ if self.glu:
+ self.glu.gluBeginCurve
- if lib_gle:
- def test_gle(self):
- if self.gle:
- self.gle.gleGetJoinStyle
+ @unittest.skipUnless(lib_gle, 'lib_gle not available')
+ def test_gle(self):
+ if self.gle:
+ self.gle.gleGetJoinStyle
-##if os.name == "posix" and sys.platform != "darwin":
-
-## # On platforms where the default shared library suffix is '.so',
-## # at least some libraries can be loaded as attributes of the cdll
-## # object, since ctypes now tries loading the lib again
-## # with '.so' appended of the first try fails.
-## #
-## # Won't work for libc, unfortunately. OTOH, it isn't
-## # needed for libc since this is already mapped into the current
-## # process (?)
-## #
-## # On MAC OSX, it won't work either, because dlopen() needs a full path,
-## # and the default suffix is either none or '.dylib'.
-
-## class LoadLibs(unittest.TestCase):
-## def test_libm(self):
-## import math
-## libm = cdll.libm
-## sqrt = libm.sqrt
-## sqrt.argtypes = (c_double,)
-## sqrt.restype = c_double
-## self.assertEqual(sqrt(2), math.sqrt(2))
+# On platforms where the default shared library suffix is '.so',
+# at least some libraries can be loaded as attributes of the cdll
+# object, since ctypes now tries loading the lib again
+# with '.so' appended of the first try fails.
+#
+# Won't work for libc, unfortunately. OTOH, it isn't
+# needed for libc since this is already mapped into the current
+# process (?)
+#
+# On MAC OSX, it won't work either, because dlopen() needs a full path,
+# and the default suffix is either none or '.dylib'.
+ at unittest.skip('test disabled')
+ at unittest.skipUnless(os.name=="posix" and sys.platform != "darwin",
+ 'test not suitable for this platform')
+class LoadLibs(unittest.TestCase):
+ def test_libm(self):
+ import math
+ libm = cdll.libm
+ sqrt = libm.sqrt
+ sqrt.argtypes = (c_double,)
+ sqrt.restype = c_double
+ self.assertEqual(sqrt(2), math.sqrt(2))
if __name__ == "__main__":
unittest.main()
diff --git a/lib-python/2.7/ctypes/test/test_frombuffer.py b/lib-python/2.7/ctypes/test/test_frombuffer.py
--- a/lib-python/2.7/ctypes/test/test_frombuffer.py
+++ b/lib-python/2.7/ctypes/test/test_frombuffer.py
More information about the pypy-commit
mailing list