--- python2.7-2.7.orig/debian/idle.desktop.in +++ python2.7-2.7/debian/idle.desktop.in @@ -0,0 +1,9 @@ +[Desktop Entry] +Name=IDLE (using Python-@VER@) +Comment=Integrated Development Environment for Python (using Python-@VER@) +Exec=/usr/bin/idle-@PVER@ -n +Icon=/usr/share/pixmaps/@PVER@.xpm +Terminal=false +Type=Application +Categories=Application;Development; +StartupNotify=true --- python2.7-2.7.orig/debian/PVER.desktop.in +++ python2.7-2.7/debian/PVER.desktop.in @@ -0,0 +1,10 @@ +[Desktop Entry] +Name=Python (v@VER@) +Comment=Python Interpreter (v@VER@) +Exec=/usr/bin/@PVER@ +Icon=/usr/share/pixmaps/@PVER@.xpm +Terminal=true +Type=Application +Categories=Development; +StartupNotify=true +NoDisplay=true --- python2.7-2.7.orig/debian/README.Debian.in +++ python2.7-2.7/debian/README.Debian.in @@ -0,0 +1,8 @@ +The documentation for this package is in /usr/share/doc/@PVER@/. + +A draft of the "Debian Python Policy" can be found in + + /usr/share/doc/python + +Sometime it will be moved to /usr/share/doc/debian-policy in the +debian-policy package. --- python2.7-2.7.orig/debian/PVER.overrides.in +++ python2.7-2.7/debian/PVER.overrides.in @@ -0,0 +1,11 @@ +# idlelib images +@PVER@ binary: image-file-in-usr-lib + +# yes, we have to +@PVER@ binary: depends-on-python-minimal + +@PVER@ binary: desktop-command-not-in-package +@PVER@ binary: menu-command-not-in-package + +# license file referred by the standard library +@PVER@ binary: extra-license-file --- python2.7-2.7.orig/debian/FAQ.html +++ python2.7-2.7/debian/FAQ.html @@ -0,0 +1,8997 @@ + + +The Whole Python FAQ + + + +

The Whole Python FAQ

+Last changed on Wed Feb 12 21:31:08 2003 CET + +

(Entries marked with ** were changed within the last 24 hours; +entries marked with * were changed within the last 7 days.) +

+ +

+


+

1. General information and availability

+ + +

+


+

2. Python in the real world

+ + +

+


+

3. Building Python and Other Known Bugs

+ + +

+


+

4. Programming in Python

+ + +

+


+

5. Extending Python

+ + +

+


+

6. Python's design

+ + +

+


+

7. Using Python on non-UNIX platforms

+ + +

+


+

8. Python on Windows

+ + +
+

1. General information and availability

+ +
+

1.1. What is Python?

+Python is an interpreted, interactive, object-oriented programming +language. It incorporates modules, exceptions, dynamic typing, very +high level dynamic data types, and classes. Python combines +remarkable power with very clear syntax. It has interfaces to many +system calls and libraries, as well as to various window systems, and +is extensible in C or C++. It is also usable as an extension language +for applications that need a programmable interface. Finally, Python +is portable: it runs on many brands of UNIX, on the Mac, and on PCs +under MS-DOS, Windows, Windows NT, and OS/2. +

+To find out more, the best thing to do is to start reading the +tutorial from the documentation set (see a few questions further +down). +

+See also question 1.17 (what is Python good for). +

+ +Edit this entry / +Log info + +/ Last changed on Mon May 26 16:05:18 1997 by +GvR +

+ +


+

1.2. Why is it called Python?

+Apart from being a computer scientist, I'm also a fan of "Monty +Python's Flying Circus" (a BBC comedy series from the seventies, in +the -- unlikely -- case you didn't know). It occurred to me one day +that I needed a name that was short, unique, and slightly mysterious. +And I happened to be reading some scripts from the series at the +time... So then I decided to call my language Python. +

+By now I don't care any more whether you use a Python, some other +snake, a foot or 16-ton weight, or a wood rat as a logo for Python! +

+ +Edit this entry / +Log info + +/ Last changed on Thu Aug 24 00:50:41 2000 by +GvR +

+ +


+

1.3. How do I obtain a copy of the Python source?

+The latest Python source distribution is always available from +python.org, at http://www.python.org/download. The latest development sources can be obtained via anonymous CVS from SourceForge, at http://www.sf.net/projects/python . +

+The source distribution is a gzipped tar file containing the complete C source, LaTeX +documentation, Python library modules, example programs, and several +useful pieces of freely distributable software. This will compile and +run out of the box on most UNIX platforms. (See section 7 for +non-UNIX information.) +

+Older versions of Python are also available from python.org. +

+ +Edit this entry / +Log info + +/ Last changed on Tue Apr 9 17:06:16 2002 by +A.M. Kuchling +

+ +


+

1.4. How do I get documentation on Python?

+All documentation is available on-line, starting at http://www.python.org/doc/. +

+The LaTeX source for the documentation is part of the source +distribution. If you don't have LaTeX, the latest Python +documentation set is available, in various formats like postscript +and html, by anonymous ftp - visit the above URL for links to the +current versions. +

+PostScript for a high-level description of Python is in the file nluug-paper.ps +(a separate file on the ftp site). +

+ +Edit this entry / +Log info + +/ Last changed on Wed Jan 21 12:02:55 1998 by +Ken Manheimer +

+ +


+

1.5. Are there other ftp sites that mirror the Python distribution?

+The following anonymous ftp sites keep mirrors of the Python +distribution: +

+USA: +

+

+        ftp://ftp.python.org/pub/python/
+        ftp://gatekeeper.dec.com/pub/plan/python/
+        ftp://ftp.uu.net/languages/python/
+        ftp://ftp.wustl.edu/graphics/graphics/sgi-stuff/python/
+        ftp://ftp.sterling.com/programming/languages/python/
+        ftp://uiarchive.cso.uiuc.edu/pub/lang/python/
+        ftp://ftp.pht.com/mirrors/python/python/
+	ftp://ftp.cdrom.com/pub/python/
+
+Europe: +

+

+        ftp://ftp.cwi.nl/pub/python/
+        ftp://ftp.funet.fi/pub/languages/python/
+        ftp://ftp.sunet.se/pub/lang/python/
+        ftp://unix.hensa.ac.uk/mirrors/uunet/languages/python/
+        ftp://ftp.lip6.fr/pub/python/
+        ftp://sunsite.cnlab-switch.ch/mirror/python/
+        ftp://ftp.informatik.tu-muenchen.de/pub/comp/programming/languages/python/
+
+Australia: +

+

+        ftp://ftp.dstc.edu.au/pub/python/
+
+

+ +Edit this entry / +Log info + +/ Last changed on Wed Mar 24 09:20:49 1999 by +A.M. Kuchling +

+ +


+

1.6. Is there a newsgroup or mailing list devoted to Python?

+There is a newsgroup, comp.lang.python, +and a mailing list. The newsgroup and mailing list are gatewayed into +each other -- if you can read news it's unnecessary to subscribe to +the mailing list. To subscribe to the mailing list +(python-list@python.org) visit its Mailman webpage at +http://www.python.org/mailman/listinfo/python-list +

+More info about the newsgroup and mailing list, and about other lists, +can be found at +http://www.python.org/psa/MailingLists.html. +

+Archives of the newsgroup are kept by Deja News and accessible +through the "Python newsgroup search" web page, +http://www.python.org/search/search_news.html. +This page also contains pointer to other archival collections. +

+ +Edit this entry / +Log info + +/ Last changed on Wed Jun 23 09:29:36 1999 by +GvR +

+ +


+

1.7. Is there a WWW page devoted to Python?

+Yes, http://www.python.org/ is the official Python home page. +

+ +Edit this entry / +Log info + +/ Last changed on Fri May 23 14:42:59 1997 by +Ken Manheimer +

+ +


+

1.8. Is the Python documentation available on the WWW?

+Yes. Python 2.0 documentation is available from +http://www.pythonlabs.com/tech/python2.0/doc/ and from +http://www.python.org/doc/. Note that most documentation +is available for on-line browsing as well as for downloading. +

+ +Edit this entry / +Log info + +/ Last changed on Tue Jan 2 03:14:08 2001 by +Moshe Zadka +

+ +


+

1.9. Are there any books on Python?

+Yes, many, and more are being published. See +the python.org Wiki at http://www.python.org/cgi-bin/moinmoin/PythonBooks for a list. +

+You can also search online bookstores for "Python" +(and filter out the Monty Python references; or +perhaps search for "Python" and "language"). +

+ +Edit this entry / +Log info + +/ Last changed on Mon Aug 5 19:08:49 2002 by +amk +

+ +


+

1.10. Are there any published articles about Python that I can reference?

+If you can't reference the web site, and you don't want to reference the books +(see previous question), there are several articles on Python that you could +reference. +

+Most publications about Python are collected on the Python web site: +

+

+    http://www.python.org/doc/Publications.html
+
+It is no longer recommended to reference this +very old article by Python's author: +

+

+    Guido van Rossum and Jelke de Boer, "Interactively Testing Remote
+    Servers Using the Python Programming Language", CWI Quarterly, Volume
+    4, Issue 4 (December 1991), Amsterdam, pp 283-303.
+
+

+ +Edit this entry / +Log info + +/ Last changed on Sat Jul 4 20:52:31 1998 by +GvR +

+ +


+

1.11. Are there short introductory papers or talks on Python?

+There are several - you can find links to some of them collected at +http://www.python.org/doc/Hints.html#intros. +

+ +Edit this entry / +Log info + +/ Last changed on Fri May 23 15:04:05 1997 by +Ken Manheimer +

+ +


+

1.12. How does the Python version numbering scheme work?

+Python versions are numbered A.B.C or A.B. A is the major version +number -- it is only incremented for really major changes in the +language. B is the minor version number, incremented for less +earth-shattering changes. C is the micro-level -- it is +incremented for each bugfix release. See PEP 6 for more information +about bugfix releases. +

+Not all releases have bugfix releases. +Note that in the past (ending with 1.5.2), +micro releases have added significant changes; +in fact the changeover from 0.9.9 to 1.0.0 was the first time +that either A or B changed! +

+Alpha, beta and release candidate versions have an additional suffixes. +The suffix for an alpha version is "aN" for some small number N, the +suffix for a beta version is "bN" for some small number N, and the +suffix for a release candidate version is "cN" for some small number N. +

+Note that (for instance) all versions labeled 2.0aN precede the +versions labeled 2.0bN, which precede versions labeled 2.0cN, and +those precede 2.0. +

+As a rule, no changes are made between release candidates and the final +release unless there are show-stopper bugs. +

+You may also find version numbers with a "+" suffix, e.g. "2.2+". +These are unreleased versions, built directly from the CVS trunk. +

+See also the documentation for sys.version, sys.hexversion, and +sys.version_info. +

+ +Edit this entry / +Log info + +/ Last changed on Mon Jan 14 06:34:17 2002 by +GvR +

+ +


+

1.13. How do I get a beta test version of Python?

+All releases, including alphas, betas and release candidates, are announced on +comp.lang.python and comp.lang.python.announce newsgroups, +which are gatewayed into the python-list@python.org and +python-announce@python.org. In addition, all these announcements appear on +the Python home page, at http://www.python.org. +

+You can also access the development version of Python through CVS. See http://sourceforge.net/cvs/?group_id=5470 for details. If you're not familiar with CVS, documents like http://linux.oreillynet.com/pub/a/linux/2002/01/03/cvs_intro.html +provide an introduction. +

+ +Edit this entry / +Log info + +/ Last changed on Mon Jun 3 00:57:08 2002 by +Neal Norwitz +

+ +


+

1.14. Are there copyright restrictions on the use of Python?

+Hardly. You can do anything you want with the source, as long as +you leave the copyrights in, and display those copyrights in any +documentation about Python that you produce. Also, don't use the +author's institute's name in publicity without prior written +permission, and don't hold them responsible for anything (read the +actual copyright for a precise legal wording). +

+In particular, if you honor the copyright rules, it's OK to use Python +for commercial use, to sell copies of Python in source or binary form, +or to sell products that enhance Python or incorporate Python (or part +of it) in some form. I would still like to know about all commercial +use of Python! +

+ +Edit this entry / +Log info +

+ +


+

1.15. Why was Python created in the first place?

+Here's a very brief summary of what got me started: +

+I had extensive experience with implementing an interpreted language +in the ABC group at CWI, and from working with this group I had +learned a lot about language design. This is the origin of many +Python features, including the use of indentation for statement +grouping and the inclusion of very-high-level data types (although the +details are all different in Python). +

+I had a number of gripes about the ABC language, but also liked many +of its features. It was impossible to extend the ABC language (or its +implementation) to remedy my complaints -- in fact its lack of +extensibility was one of its biggest problems. +I had some experience with using Modula-2+ and talked with the +designers of Modula-3 (and read the M3 report). M3 is the origin of +the syntax and semantics used for exceptions, and some other Python +features. +

+I was working in the Amoeba distributed operating system group at +CWI. We needed a better way to do system administration than by +writing either C programs or Bourne shell scripts, since Amoeba had +its own system call interface which wasn't easily accessible from the +Bourne shell. My experience with error handling in Amoeba made me +acutely aware of the importance of exceptions as a programming +language feature. +

+It occurred to me that a scripting language with a syntax like ABC +but with access to the Amoeba system calls would fill the need. I +realized that it would be foolish to write an Amoeba-specific +language, so I decided that I needed a language that was generally +extensible. +

+During the 1989 Christmas holidays, I had a lot of time on my hand, +so I decided to give it a try. During the next year, while still +mostly working on it in my own time, Python was used in the Amoeba +project with increasing success, and the feedback from colleagues made +me add many early improvements. +

+In February 1991, after just over a year of development, I decided +to post to USENET. The rest is in the Misc/HISTORY file. +

+ +Edit this entry / +Log info + +/ Last changed on Fri May 23 00:06:23 1997 by +GvR +

+ +


+

1.16. Do I have to like "Monty Python's Flying Circus"?

+No, but it helps. Pythonistas like the occasional reference to SPAM, +and of course, nobody expects the Spanish Inquisition +

+The two main reasons to use Python are: +

+

+ - Portable
+ - Easy to learn
+
+The three main reasons to use Python are: +

+

+ - Portable
+ - Easy to learn
+ - Powerful standard library
+
+(And nice red uniforms.) +

+And remember, there is no rule six. +

+ +Edit this entry / +Log info + +/ Last changed on Wed May 28 10:39:21 1997 by +GvR +

+ +


+

1.17. What is Python good for?

+Python is used in many situations where a great deal of dynamism, +ease of use, power, and flexibility are required. +

+In the area of basic text +manipulation core Python (without any non-core extensions) is easier +to use and is roughly as fast as just about any language, and this makes Python +good for many system administration type tasks and for CGI programming +and other application areas that manipulate text and strings and such. +

+When augmented with +standard extensions (such as PIL, COM, Numeric, oracledb, kjbuckets, +tkinter, win32api, etc.) +or special purpose extensions (that you write, perhaps using helper tools such +as SWIG, or using object protocols such as ILU/CORBA or COM) Python +becomes a very convenient "glue" or "steering" +language that helps make heterogeneous collections of unrelated +software packages work together. +For example by combining Numeric with oracledb you can help your +SQL database do statistical analysis, or even Fourier transforms. +One of the features that makes Python excel in the "glue language" role +is Python's simple, usable, and powerful C language runtime API. +

+Many developers also use Python extensively as a graphical user +interface development aide. +

+ +Edit this entry / +Log info + +/ Last changed on Sat May 24 10:13:11 1997 by +Aaron Watters +

+ +


+

1.18. Can I use the FAQ Wizard software to maintain my own FAQ?

+Sure. It's in Tools/faqwiz/ of the python source tree. +

+ +Edit this entry / +Log info + +/ Last changed on Fri Mar 29 06:50:32 2002 by +Aahz +

+ +


+

1.19. Which editor has good support for editing Python source code?

+On Unix, the first choice is Emacs/XEmacs. There's an elaborate +mode for editing Python code, which is available from the Python +source distribution (Misc/python-mode.el). It's also bundled +with XEmacs (we're still working on legal details to make it possible +to bundle it with FSF Emacs). And it has its own web page: +

+

+    http://www.python.org/emacs/python-mode/index.html
+
+There are many other choices, for Unix, Windows or Macintosh. +Richard Jones compiled a table from postings on the Python newsgroup: +

+

+    http://www.bofh.asn.au/~richard/editors.html
+
+See also FAQ question 7.10 for some more Mac and Win options. +

+ +Edit this entry / +Log info + +/ Last changed on Mon Jun 15 23:21:04 1998 by +Gvr +

+ +


+

1.20. I've never programmed before. Is there a Python tutorial?

+There are several, and at least one book. +All information for beginning Python programmers is collected here: +

+

+    http://www.python.org/doc/Newbies.html
+
+

+ +Edit this entry / +Log info + +/ Last changed on Wed Sep 5 05:34:07 2001 by +GvR +

+ +


+

1.21. Where in the world is www.python.org located?

+It's currently in Amsterdam, graciously hosted by XS4ALL: +

+

+    http://www.xs4all.nl
+
+Thanks to Thomas Wouters for setting this up!!!! +

+ +Edit this entry / +Log info + +/ Last changed on Fri Aug 3 21:49:27 2001 by +GvR +

+ +


+

2. Python in the real world

+ +
+

2.1. How many people are using Python?

+Certainly thousands, and quite probably tens of thousands of users. +More are seeing the light each day. The comp.lang.python newsgroup is +very active, but overall there is no accurate estimate of the number of subscribers or Python users. +

+Jacek Artymiak has created a Python Users Counter; you can see the +current count by visiting +http://www.wszechnica.safenet.pl/cgi-bin/checkpythonuserscounter.py +(this will not increment the counter; use the link there if you haven't +added yourself already). Most Python users appear not to have registered themselves. +

+ +Edit this entry / +Log info + +/ Last changed on Thu Feb 21 23:29:18 2002 by +GvR +

+ +


+

2.2. Have any significant projects been done in Python?

+At CWI (the former home of Python), we have written a 20,000 line +authoring environment for transportable hypermedia presentations, a +5,000 line multimedia teleconferencing tool, as well as many many +smaller programs. +

+At CNRI (Python's new home), we have written two large applications: +Grail, a fully featured web browser (see +http://grail.cnri.reston.va.us), +and the Knowbot Operating Environment, +a distributed environment for mobile code. +

+The University of Virginia uses Python to control a virtual reality +engine. See http://alice.cs.cmu.edu. +

+The ILU project at Xerox PARC can generate Python glue for ILU +interfaces. See ftp://ftp.parc.xerox.com/pub/ilu/ilu.html. ILU +is a free CORBA compliant ORB which supplies distributed object +connectivity to a host of platforms using a host of languages. +

+Mark Hammond and Greg Stein and others are interfacing Python to +Microsoft's COM and ActiveX architectures. This means, among other +things, that Python may be used in active server pages or as a COM +controller (for example to automatically extract from or insert information +into Excel or MSAccess or any other COM aware application). +Mark claims Python can even be a ActiveX scripting host (which +means you could embed JScript inside a Python application, if you +had a strange sense of humor). Python/AX/COM is distributed as part +of the PythonWin distribution. +

+The University of California, Irvine uses a student administration +system called TELE-Vision written entirely in Python. Contact: Ray +Price rlprice@uci.edu. +

+The Melbourne Cricket Ground (MCG) in Australia (a 100,000+ person venue) +has it's scoreboard system written largely in Python on MS Windows. +Python expressions are used to create almost every scoring entry that +appears on the board. The move to Python/C++ away from exclusive C++ +has provided a level of functionality that would simply not have been +viable otherwise. +

+See also the next question. +

+Note: this FAQ entry is really old. +See http://www.python.org/psa/Users.html for a more recent list. +

+ +Edit this entry / +Log info + +/ Last changed on Wed Oct 25 13:24:15 2000 by +GvR +

+ +


+

2.3. Are there any commercial projects going on using Python?

+Yes, there's lots of commercial activity using Python. See +http://www.python.org/psa/Users.html for a list. +

+ +Edit this entry / +Log info + +/ Last changed on Wed Oct 14 18:17:33 1998 by +ken +

+ +


+

2.4. How stable is Python?

+Very stable. New, stable releases have been coming out roughly every 3 to 12 months since 1991, and this seems likely to continue. +

+With the introduction of retrospective "bugfix" releases the stability of the language implementations can be, and is being, improved independently of the new features offered by more recent major or minor releases. Bugfix releases, indicated by a third component of the version number, only fix known problems and do not gratuitously introduce new and possibly incompatible features or modified library functionality. +

+Release 2.2 got its first bugfix on April 10, 2002. The new version +number is now 2.2.1. The 2.1 release, at 2.1.3, can probably be +considered the "most stable" platform because it has been bugfixed +twice. +

+ +Edit this entry / +Log info + +/ Last changed on Tue Jul 23 10:20:04 2002 by +Jens Kubieziel +

+ +


+

2.5. What new developments are expected for Python in the future?

+See http://www.python.org/peps/ for the Python Enhancement +Proposals (PEPs). PEPs are design +documents +describing a suggested new feature for Python, providing +a concise technical specification and a rationale. +

+Also, follow the discussions on the python-dev mailing list. +

+ +Edit this entry / +Log info + +/ Last changed on Tue Apr 9 17:09:51 2002 by +A.M. Kuchling +

+ +


+

2.6. Is it reasonable to propose incompatible changes to Python?

+In general, no. There are already millions of lines of Python code +around the world, so any changes in the language that invalidates more +than a very small fraction of existing programs has to be frowned +upon. Even if you can provide a conversion program, there still is +the problem of updating all documentation. Providing a gradual +upgrade path is the only way if a feature has to be changed. +

+See http://www.python.org/peps/pep-0005.html for the proposed +mechanism for creating backwards-incompatibilities. +

+ +Edit this entry / +Log info + +/ Last changed on Mon Apr 1 22:13:47 2002 by +Fred Drake +

+ +


+

2.7. What is the future of Python?

+Please see http://www.python.org/peps/ for proposals of future +activities. One of the PEPs (Python Enhancement Proposals) deals +with the PEP process and PEP format -- see +http://www.python.org/peps/pep-0001.html if you want to +submit a PEP. In http://www.python.org/peps/pep-0042.html there +is a list of wishlists the Python Development team plans to tackle. +

+ +Edit this entry / +Log info + +/ Last changed on Mon Apr 1 22:15:46 2002 by +Fred Drake +

+ +


+

2.8. What was the PSA, anyway?

+The Python Software Activity was +created by a number of Python aficionados who want Python to be more +than the product and responsibility of a single individual. +The PSA was not an independent organization, but lived +under the umbrealla of CNRI. +

+The PSA has been superseded by the Python Software Foundation, +an independent non-profit organization. The PSF's home page +is at http://www.python.org/psf/. +

+Some pages created by the PSA still live at +http://www.python.org/psa/ +

+ +Edit this entry / +Log info + +/ Last changed on Thu Jul 25 18:19:44 2002 by +GvR +

+ +


+

2.9. Deleted

+

+

+ +Edit this entry / +Log info + +/ Last changed on Tue Jan 2 02:51:30 2001 by +Moshe Zadka +

+ +


+

2.10. Deleted

+

+

+ +Edit this entry / +Log info + +/ Last changed on Tue Jan 2 02:52:19 2001 by +Moshe Zadka +

+ +


+

2.11. Is Python Y2K (Year 2000) Compliant?

+As of January, 2001 no major problems have been reported and Y2K +compliance seems to be a non-issue. +

+Since Python is available free of charge, there are no absolute +guarantees. If there are unforeseen problems, liability is the +user's rather than the developers', and there is nobody you can sue for damages. +

+Python does few +date manipulations, and what it does is all based on the Unix +representation for time (even on non-Unix systems) which uses seconds +since 1970 and won't overflow until 2038. +

+ +Edit this entry / +Log info + +/ Last changed on Mon Jan 8 17:19:32 2001 by +Steve Holden +

+ +


+

2.12. Is Python a good language in a class for beginning programmers?

+Yes. This long answer attempts to address any concerns you might +have with teaching Python as a programmer's first language. +(If you want to discuss Python's use in education, then +you may be interested in joining the edu-sig mailinglist. +See http://www.python.org/sigs/edu-sig/ ) +

+It is still common to start students with a procedural +(subset of a) statically typed language such as Pascal, C, or +a subset of C++ or Java. I think that students may be better +served by learning Python as their first language. Python has +a very simple and consistent syntax and a large standard library. +Most importantly, using Python in a beginning programming course +permits students to concentrate on important programming skills, +such as problem decomposition and data type design. +

+With Python, students can be quickly introduced to basic concepts +such as loops and procedures. They can even probably work with +user-defined objects in their very first course. They could +implement a tree structure as nested Python lists, for example. +They could be introduced to objects in their first course if +desired. For a student who has never programmed before, using +a statically typed language seems unnatural. It presents +additional complexity that the student must master and slows +the pace of the course. The students are trying to learn to +think like a computer, decompose problems, design consistent +interfaces, and encapsulate data. While learning to use a +statically typed language is important, it is not necessarily the +best topic to address in the students' first programming course. +

+Many other aspects of Python make it a good first language. +Python has a large standard library (like Java) so that +students can be assigned programming projects very early in the +course that do something. Assignments aren't restricted to the +standard four-function calculator and check balancing programs. +By using the standard library, students can gain the satisfaction +of working on realistic applications as they learn the fundamentals +of programming. Using the standard library also teaches students +about code reuse. +

+Python's interactive interpreter also enables students to +test language features while they're programming. They can keep +a window with the interpreter running while they enter their +programs' source in another window. If they can't remember the +methods for a list, they can do something like this: +

+

+ >>> L = []
+ >>> dir(L)
+ ['append', 'count', 'extend', 'index', 'insert', 'pop', 'remove',
+ 'reverse', 'sort']
+ >>> print L.append.__doc__
+ L.append(object) -- append object to end
+ >>> L.append(1)
+ >>> L
+ [1]
+
+With the interpreter, documentation is never far from the +student as he's programming. +

+There are also good IDEs for Python. Guido van Rossum's IDLE +is a cross-platform IDE for Python that is written in Python +using Tk. There is also a Windows specific IDE called PythonWin. +Emacs users will be happy to know that there is a very good Python +mode for Emacs. All of these programming environments provide +syntax highlighting, auto-indenting, and access to the interactive +interpreter while coding. For more information about IDEs, see XXX. +

+If your department is currently using Pascal because it was +designed to be a teaching language, then you'll be happy to +know that Guido van Rossum designed Python to be simple to +teach to everyone but powerful enough to implement real world +applications. Python makes a good language for first time +programmers because that was one of Python's design goals. +There are papers at http://www.python.org/doc/essays/ on the Python website +by Python's creator explaining his objectives for the language. +One that may interest you is titled "Computer Programming for Everybody" +http://www.python.org/doc/essays/cp4e.html +

+If you're seriously considering Python as a language for your +school, Guido van Rossum may even be willing to correspond with +you about how the language would fit in your curriculum. +See http://www.python.org/doc/FAQ.html#2.2 for examples of +Python's use in the "real world." +

+While Python, its source code, and its IDEs are freely +available, this consideration should not rule +out other languages. There are other free languages (Java, +free C compilers), and many companies are willing to waive some +or all of their fees for student programming tools if it +guarantees that a whole graduating class will know how to +use their tools. That is, if one of the requirements for +the language that will be taught is that it be freely +available, then Python qualifies, but this requirement +does not preclude other languages. +

+While Python jobs may not be as prevalent as C/C++/Java jobs, +teachers should not worry about teaching students critical job +skills in their first course. The skills that win students a +job are those they learn in their senior classes and internships. +Their first programming courses are there to lay a solid +foundation in programming fundamentals. The primary question +in choosing the language for such a course should be which +language permits the students to learn this material without +hindering or limiting them. +

+Another argument for Python is that there are many tasks for +which something like C++ is overkill. That's where languages +like Python, Perl, Tcl, and Visual Basic thrive. It's critical +for students to know something about these languages. (Every +employer for whom I've worked used at least one such language.) +Of the languages listed above, Python probably makes the best +language in a programming curriculum since its syntax is simple, +consistent, and not unlike other languages (C/C++/Java) that +are probably in the curriculum. By starting students with +Python, a department simultaneously lays the foundations for +other programming courses and introduces students to the type +of language that is often used as a "glue" language. As an +added bonus, Python can be used to interface with Microsoft's +COM components (thanks to Mark Hammond). There is also Jython, +a Java implementation of the Python interpreter, that can be +used to connect Java components. +

+If you currently start students with Pascal or C/C++ or Java, +you may be worried they will have trouble learning a statically +typed language after starting with Python. I think that this +fear most often stems from the fact that the teacher started +with a statically typed language, and we tend to like to teach +others in the same way we were taught. In reality, the +transition from Python to one of these other languages is +quite simple. +

+To motivate a statically typed language such as C++, begin the +course by explaining that unlike Python, their first language, +C++ is compiled to a machine dependent executable. Explain +that the point is to make a very fast executable. To permit +the compiler to make optimizations, programmers must help it +by specifying the "types" of variables. By restricting each +variable to a specific type, the compiler can reduce the +book-keeping it has to do to permit dynamic types. The compiler +also has to resolve references at compile time. Thus, the +language gains speed by sacrificing some of Python's dynamic +features. Then again, the C++ compiler provides type safety +and catches many bugs at compile time instead of run time (a +critical consideration for many commercial applications). C++ +is also designed for very large programs where one may want to +guarantee that others don't touch an object's implementation. +C++ provides very strong language features to separate an object's +implementation from its interface. Explain why this separation +is a good thing. +

+The first day of a C++ course could then be a whirlwind introduction +to what C++ requires and provides. The point here is that after +a semester or two of Python, students are hopefully competent +programmers. They know how to handle loops and write procedures. +They've also worked with objects, thought about the benefits of +consistent interfaces, and used the technique of subclassing to +specialize behavior. Thus, a whirlwind introduction to C++ could +show them how objects and subclassing looks in C++. The +potentially difficult concepts of object-oriented design were +taught without the additional obstacles presented by a language +such as C++ or Java. When learning one of these languages, +the students would already understand the "road map." They +understand objects; they would just be learning how objects +fit in a statically typed languages. Language requirements +and compiler errors that seem unnatural to beginning programmers +make sense in this new context. Many students will find it +helpful to be able to write a fast prototype of their algorithms +in Python. Thus, they can test and debug their ideas before +they attempt to write the code in the new language, saving the +effort of working with C++ types for when they've discovered a +working solution for their assignments. When they get annoyed +with the rigidity of types, they'll be happy to learn about +containers and templates to regain some of the lost flexibility +Python afforded them. Students may also gain an appreciation +for the fact that no language is best for every task. They'll +see that C++ is faster, but they'll know that they can gain +flexibility and development speed with a Python when execution +speed isn't critical. +

+If you have any concerns that weren't addressed here, try +posting to the Python newsgroup. Others there have done some +work with using Python as an instructional tool. Good luck. +We'd love to hear about it if you choose Python for your course. +

+ +Edit this entry / +Log info + +/ Last changed on Mon Dec 2 19:32:35 2002 by +Bill Sconce +

+ +


+

3. Building Python and Other Known Bugs

+ +
+

3.1. Is there a test set?

+Sure. You can run it after building with "make test", or you can +run it manually with this command at the Python prompt: +

+

+ import test.autotest
+
+In Python 1.4 or earlier, use +

+

+ import autotest
+
+The test set doesn't test all features of Python, +but it goes a long way to confirm that Python is actually working. +

+NOTE: if "make test" fails, don't just mail the output to the +newsgroup -- this doesn't give enough information to debug the +problem. Instead, find out which test fails, and run that test +manually from an interactive interpreter. For example, if +"make test" reports that test_spam fails, try this interactively: +

+

+ import test.test_spam
+
+This generally produces more verbose output which can be diagnosed +to debug the problem. If you find a bug in Python or the libraries, or in the tests, please report this in the Python bug tracker at SourceForge: +

+http://sourceforge.net/tracker/?func=add&group_id=5470&atid=105470 +

+ +Edit this entry / +Log info + +/ Last changed on Fri Apr 27 10:29:36 2001 by +Fred Drake +

+ +


+

3.2. When running the test set, I get complaints about floating point operations, but when playing with floating point operations I cannot find anything wrong with them.

+The test set makes occasional unwarranted assumptions about the +semantics of C floating point operations. Until someone donates a +better floating point test set, you will have to comment out the +offending floating point tests and execute similar tests manually. +

+ +Edit this entry / +Log info +

+ +


+

3.3. Link errors after rerunning the configure script.

+It is generally necessary to run "make clean" after a configuration +change. +

+ +Edit this entry / +Log info +

+ +


+

3.4. The python interpreter complains about options passed to a script (after the script name).

+You are probably linking with GNU getopt, e.g. through -liberty. +Don't. The reason for the complaint is that GNU getopt, unlike System +V getopt and other getopt implementations, doesn't consider a +non-option to be the end of the option list. A quick (and compatible) +fix for scripts is to add "--" to the interpreter, like this: +

+

+        #! /usr/local/bin/python --
+
+You can also use this interactively: +

+

+        python -- script.py [options]
+
+Note that a working getopt implementation is provided in the Python +distribution (in Python/getopt.c) but not automatically used. +

+ +Edit this entry / +Log info +

+ +


+

3.5. When building on the SGI, make tries to run python to create glmodule.c, but python hasn't been built or installed yet.

+Comment out the line mentioning glmodule.c in Setup and build a +python without gl first; install it or make sure it is in your $PATH, +then edit the Setup file again to turn on the gl module, and make +again. You don't need to do "make clean"; you do need to run "make +Makefile" in the Modules subdirectory (or just run "make" at the +toplevel). +

+ +Edit this entry / +Log info +

+ +


+

3.6. I use VPATH but some targets are built in the source directory.

+On some systems (e.g. Sun), if the target already exists in the +source directory, it is created there instead of in the build +directory. This is usually because you have previously built without +VPATH. Try running "make clobber" in the source directory. +

+ +Edit this entry / +Log info +

+ +


+

3.7. Trouble building or linking with the GNU readline library.

+You can use the GNU readline library to improve the interactive user +interface: this gives you line editing and command history when +calling python interactively. Its sources are distributed with +Python (at least for 2.0). Uncomment the line +

+#readline readline.c -lreadline -ltermcap +

+in Modules/Setup. The configuration option --with-readline +is no longer supported, at least in Python 2.0. Some hints on +building and using the readline library: +On SGI IRIX 5, you may have to add the following +to rldefs.h: +

+

+        #ifndef sigmask
+        #define sigmask(sig) (1L << ((sig)-1))
+        #endif
+
+On some systems, you will have to add #include "rldefs.h" to the +top of several source files, and if you use the VPATH feature, you +will have to add dependencies of the form foo.o: foo.c to the +Makefile for several values of foo. +The readline library requires use of the termcap library. A +known problem with this is that it contains entry points which +cause conflicts with the STDWIN and SGI GL libraries. The STDWIN +conflict can be solved by adding a line saying '#define werase w_erase' to the +stdwin.h file (in the STDWIN distribution, subdirectory H). The +GL conflict has been solved in the Python configure script by a +hack that forces use of the static version of the termcap library. +Check the newsgroup gnu.bash.bug news:gnu.bash.bug for +specific problems with the readline library (I don't read this group +but I've been told that it is the place for readline bugs). +

+ +Edit this entry / +Log info + +/ Last changed on Sat Dec 2 18:23:48 2000 by +Issac Trotts +

+ +


+

3.8. Trouble with socket I/O on older Linux 1.x versions.

+Once you've built Python, use it to run the regen script in the +Lib/plat-linux2 directory. Apparently the files as distributed don't match the system headers on some Linux versions. +

+Note that this FAQ entry only applies to Linux kernel versions 1.x.y; +these are hardly around any more. +

+ +Edit this entry / +Log info + +/ Last changed on Tue Jul 30 20:05:52 2002 by +Jens Kubieziel +

+ +


+

3.9. Trouble with prototypes on Ultrix.

+Ultrix cc seems broken -- use gcc, or edit config.h to #undef +HAVE_PROTOTYPES. +

+ +Edit this entry / +Log info +

+ +


+

3.10. Other trouble building Python on platform X.

+Please submit the details to the SourceForge bug tracker: +

+

+  http://sourceforge.net/tracker/?group_id=5470&atid=105470
+
+and we'll look +into it. Please provide as many details as possible. In particular, +if you don't tell us what type of computer and what operating system +(and version) you are using it will be difficult for us to figure out +what is the matter. If you have compilation output logs, +please use file uploads -- don't paste everything in the message box. +

+In many cases, we won't have access to the same hardware or operating system version, so please, if you have a SourceForge account, log in before filing your report, or if you don't have an account, include an email address at which we can reach you for further questions. Logging in to SourceForge first will also cause SourceForge to send you updates as we act on your report. +

+ +Edit this entry / +Log info + +/ Last changed on Fri Apr 27 10:53:18 2001 by +Fred Drake +

+ +


+

3.11. How to configure dynamic loading on Linux.

+This is now automatic as long as your Linux version uses the ELF +object format (all recent Linuxes do). +

+ +Edit this entry / +Log info +

+ +


+

3.12. I can't get shared modules to work on Linux 2.0 (Slackware96)?

+This is a bug in the Slackware96 release. The fix is simple: Make sure +that there is a link from /lib/libdl.so to /lib/libdl.so.1 so that the +following links are setup: /lib/libdl.so -> /lib/libdl.so.1 +/lib/libdl.so.1 -> /lib/libdl.so.1.7.14 You may have to rerun the +configure script, after rm'ing the config.cache file, before you +attempt to rebuild python after this fix. +

+ +Edit this entry / +Log info + +/ Last changed on Wed May 21 15:45:03 1997 by +GvR +

+ +


+

3.13. Trouble when making modules shared on Linux.

+This happens when you have built Python for static linking and then +enable +
+  *shared*
+
+in the Setup file. Shared library code must be +compiled with "-fpic". If a .o file for the module already exist that +was compiled for static linking, you must remove it or do "make clean" +in the Modules directory. +

+ +Edit this entry / +Log info + +/ Last changed on Fri May 23 13:42:30 1997 by +GvR +

+ +


+

3.14. [deleted]

+[ancient information on threads on linux (when thread support +was not standard) used to be here] +

+ +Edit this entry / +Log info + +/ Last changed on Sun Jun 2 17:27:13 2002 by +Erno Kuusela +

+ +


+

3.15. Errors when linking with a shared library containing C++ code.

+Link the main Python binary with C++. Change the definition of +LINKCC in Modules/Makefile to be your C++ compiler. You may have to +edit config.c slightly to make it compilable with C++. +

+ +Edit this entry / +Log info +

+ +


+

3.16. Deleted

+

+

+ +Edit this entry / +Log info + +/ Last changed on Tue Sep 11 16:02:22 2001 by +GvR +

+ +


+

3.17. Deleted.

+

+

+ +Edit this entry / +Log info + +/ Last changed on Tue Sep 11 15:54:57 2001 by +GvR +

+ +


+

3.18. Compilation or link errors for the _tkinter module

+Most likely, there's a version mismatch between the Tcl/Tk header +files (tcl.h and tk.h) and the Tcl/Tk libraries you are using e.g. +"-ltk8.0" and "-ltcl8.0" arguments for _tkinter in the Setup file). +It is possible to install several versions of the Tcl/Tk libraries, +but there can only be one version of the tcl.h and tk.h header +files. If the library doesn't match the header, you'll get +problems, either when linking the module, or when importing it. +Fortunately, the version number is clearly stated in each file, +so this is easy to find. Reinstalling and using the latest +version usually fixes the problem. +

+(Also note that when compiling unpatched Python 1.5.1 against +Tcl/Tk 7.6/4.2 or older, you get an error on Tcl_Finalize. See +the 1.5.1 patch page at http://www.python.org/1.5/patches-1.5.1/.) +

+ +Edit this entry / +Log info + +/ Last changed on Thu Jun 11 00:49:14 1998 by +Gvr +

+ +


+

3.19. I configured and built Python for Tcl/Tk but "import Tkinter" fails.

+Most likely, you forgot to enable the line in Setup that says +"TKPATH=:$(DESTLIB)/tkinter". +

+ +Edit this entry / +Log info +

+ +


+

3.20. [deleted]

+[ancient information on a gcc+tkinter bug on alpha was here] +

+ +Edit this entry / +Log info + +/ Last changed on Mon Jun 3 16:46:23 2002 by +Erno Kuusela +

+ +


+

3.21. Several common system calls are missing from the posix module.

+Most likely, all test compilations run by the configure script +are failing for some reason or another. Have a look in config.log to +see what could be the reason. A common reason is specifying a +directory to the --with-readline option that doesn't contain the +libreadline.a file. +

+ +Edit this entry / +Log info +

+ +


+

3.22. ImportError: No module named string, on MS Windows.

+Most likely, your PYTHONPATH environment variable should be set to +something like: +

+set PYTHONPATH=c:\python;c:\python\lib;c:\python\scripts +

+(assuming Python was installed in c:\python) +

+ +Edit this entry / +Log info +

+ +


+

3.23. Core dump on SGI when using the gl module.

+There are conflicts between entry points in the termcap and curses +libraries and an entry point in the GL library. There's a hack of a +fix for the termcap library if it's needed for the GNU readline +library, but it doesn't work when you're using curses. Concluding, +you can't build a Python binary containing both the curses and gl +modules. +

+ +Edit this entry / +Log info +

+ +


+

3.24. "Initializer not a constant" while building DLL on MS-Windows

+Static type object initializers in extension modules may cause compiles to +fail with an error message like "initializer not a constant". +Fredrik Lundh <Fredrik.Lundh@image.combitech.se> explains: +

+This shows up when building DLL under MSVC. There's two ways to +address this: either compile the module as C++, or change your code to +something like: +

+

+  statichere PyTypeObject bstreamtype = {
+      PyObject_HEAD_INIT(NULL) /* must be set by init function */
+      0,
+      "bstream",
+      sizeof(bstreamobject),
+
+
+  ...
+
+
+  void
+  initbstream()
+  {
+      /* Patch object type */
+      bstreamtype.ob_type = &PyType_Type;
+      Py_InitModule("bstream", functions);
+      ...
+  }
+
+

+ +Edit this entry / +Log info + +/ Last changed on Sun May 25 14:58:05 1997 by +Aaron Watters +

+ +


+

3.25. Output directed to a pipe or file disappears on Linux.

+Some people have reported that when they run their script +interactively, it runs great, but that when they redirect it +to a pipe or file, no output appears. +

+

+    % python script.py
+    ...some output...
+    % python script.py >file
+    % cat file
+    % # no output
+    % python script.py | cat
+    % # no output
+    %
+
+This was a bug in Linux kernel. It is fixed and should not appear anymore. So most Linux users are not affected by this. +

+If redirection doesn't work on your Linux system, check what shell you are using. Shells like (t)csh doesn't support redirection. +

+ +Edit this entry / +Log info + +/ Last changed on Thu Jan 16 13:38:30 2003 by +Jens Kubieziel +

+ +


+

3.26. [deleted]

+[ancient libc/linux problem was here] +

+ +Edit this entry / +Log info + +/ Last changed on Mon Jun 3 16:48:08 2002 by +Erno Kuusela +

+ +


+

3.27. [deleted]

+[ancient linux + threads + tk problem was described here] +

+ +Edit this entry / +Log info + +/ Last changed on Mon Jun 3 16:49:08 2002 by +Erno Kuusela +

+ +


+

3.28. How can I test if Tkinter is working?

+Try the following: +

+

+  python
+  >>> import _tkinter
+  >>> import Tkinter
+  >>> Tkinter._test()
+
+This should pop up a window with two buttons, +one "Click me" and one "Quit". +

+If the first statement (import _tkinter) fails, your Python +installation probably has not been configured to support Tcl/Tk. +On Unix, if you have installed Tcl/Tk, you have to rebuild Python +after editing the Modules/Setup file to enable the _tkinter module +and the TKPATH environment variable. +

+It is also possible to get complaints about Tcl/Tk version +number mismatches or missing TCL_LIBRARY or TK_LIBRARY +environment variables. These have to do with Tcl/Tk installation +problems. +

+A common problem is to have installed versions of tcl.h and tk.h +that don't match the installed version of the Tcl/Tk libraries; +this usually results in linker errors or (when using dynamic +loading) complaints about missing symbols during loading +the shared library. +

+ +Edit this entry / +Log info + +/ Last changed on Thu Aug 28 17:01:46 1997 by +Guido van Rossum +

+ +


+

3.29. Is there a way to get the interactive mode of the python interpreter to perform function/variable name completion?

+(From a posting by Guido van Rossum) +

+On Unix, if you have enabled the readline module (i.e. if Emacs-style +command line editing and bash-style history works for you), you can +add this by importing the undocumented standard library module +"rlcompleter". When completing a simple identifier, it +completes keywords, built-ins and globals in __main__; when completing +NAME.NAME..., it evaluates (!) the expression up to the last dot and +completes its attributes. +

+This way, you can do "import string", type "string.", hit the +completion key twice, and see the list of names defined by the +string module. +

+Tip: to use the tab key as the completion key, call +

+

+    readline.parse_and_bind("tab: complete")
+
+You can put this in a ~/.pythonrc file, and set the PYTHONSTARTUP +environment variable to ~/.pythonrc. This will cause the completion to be enabled +whenever you run Python interactively. +

+Notes (see the docstring for rlcompleter.py for more information): +

+* The evaluation of the NAME.NAME... form may cause arbitrary +application defined code to be executed if an object with a +__getattr__ hook is found. Since it is the responsibility of the +application (or the user) to enable this feature, I consider this an +acceptable risk. More complicated expressions (e.g. function calls or +indexing operations) are not evaluated. +

+* GNU readline is also used by the built-in functions input() and +raw_input(), and thus these also benefit/suffer from the complete +features. Clearly an interactive application can benefit by +specifying its own completer function and using raw_input() for all +its input. +

+* When stdin is not a tty device, GNU readline is never +used, and this module (and the readline module) are silently inactive. +

+ +Edit this entry / +Log info + +/ Last changed on Fri Jun 12 09:55:24 1998 by +A.M. Kuchling +

+ +


+

3.30. Why is the Python interpreter not built as a shared library?

+(This is a Unix question; on Mac and Windows, it is a shared +library.) +

+It's just a nightmare to get this to work on all different platforms. +Shared library portability is a pain. And yes, I know about GNU libtool +-- but it requires me to use its conventions for filenames etc, and it +would require a complete and utter rewrite of all the makefile and +config tools I'm currently using. +

+In practice, few applications embed Python -- it's much more common to +have Python extensions, which already are shared libraries. Also, +serious embedders often want total control over which Python version +and configuration they use so they wouldn't want to use a standard +shared library anyway. So while the motivation of saving space +when lots of apps embed Python is nice in theory, I +doubt that it will save much in practice. (Hence the low priority I +give to making a shared library.) +

+For Linux systems, the simplest method of producing libpython1.5.so seems to +be (originally from the Minotaur project web page, +http://www.equi4.com/minotaur/minotaur.html): +

+

+  make distclean 
+  ./configure 
+  make OPT="-fpic -O2" 
+  mkdir .extract 
+  (cd .extract; ar xv ../libpython1.5.a) 
+  gcc -shared -o libpython1.5.so .extract/*.o 
+  rm -rf .extract
+
+In Python 2.3 this will be supported by the standard build routine +(at least on Linux) with --enable-shared. Note however that there +is little advantage, and it slows down Python because of the need +for PIC code and the extra cost at startup time to find the library. +

+ +Edit this entry / +Log info + +/ Last changed on Thu May 30 13:36:55 2002 by +GvR +

+ +


+

3.31. Build with GCC on Solaris 2.6 (SunOS 5.6) fails

+If you have upgraded Solaris 2.5 or 2.5.1 to Solaris 2.6, +but you have not upgraded +your GCC installation, the compile may fail, e.g. like this: +

+

+ In file included from /usr/include/sys/stream.h:26,
+                  from /usr/include/netinet/in.h:38,
+                  from /usr/include/netdb.h:96,
+                  from ./socketmodule.c:121:
+ /usr/include/sys/model.h:32: #error "No DATAMODEL_NATIVE specified"
+
+Solution: rebuild GCC for Solaris 2.6. +You might be able to simply re-run fixincludes, but +people have had mixed success with doing that. +

+ +Edit this entry / +Log info + +/ Last changed on Wed Oct 21 11:18:46 1998 by +GvR +

+ +


+

3.32. Running "make clean" seems to leave problematic files that cause subsequent builds to fail.

+Use "make clobber" instead. +

+Use "make clean" to reduce the size of the source/build directory +after you're happy with your build and installation. +If you have already tried to build python and you'd like to start +over, you should use "make clobber". It does a "make clean" and also +removes files such as the partially built Python library from a previous build. +

+ +Edit this entry / +Log info + +/ Last changed on Thu Jun 24 20:39:26 1999 by +TAB +

+ +


+

3.33. Submitting bug reports and patches

+To report a bug or submit a patch, please use the relevant service +from the Python project at SourceForge. +

+Bugs: http://sourceforge.net/tracker/?group_id=5470&atid=105470 +

+Patches: http://sourceforge.net/tracker/?group_id=5470&atid=305470 +

+If you have a SourceForge account, please log in before submitting your bug report; this will make it easier for us to contact you regarding your report in the event we have follow-up questions. It will also enable SourceForge to send you update information as we act on your bug. If you do not have a SourceForge account, please consider leaving your name and email address as part of the report. +

+ +Edit this entry / +Log info + +/ Last changed on Fri Apr 27 10:58:26 2001 by +Fred Drake +

+ +


+

3.34. I can't load shared libraries under Python 1.5.2, Solaris 7, and gcc 2.95.2

+When trying to load shared libraries, you may see errors like: +ImportError: ld.so.1: python: fatal: relocation error: file /usr/local/lib/python1.5/site-packages/Perp/util/du_SweepUtilc.so: +
+ symbol PyExc_RuntimeError: referenced symbol not found
+
+

+There is a problem with the configure script for Python 1.5.2 +under Solaris 7 with gcc 2.95 . configure should set the make variable +LINKFORSHARED=-Xlinker -export-dynamic +

+

+in Modules/Makefile, +

+Manually add this line to the Modules/Makefile. +This builds a Python executable that can load shared library extensions (xxx.so) . +

+ +Edit this entry / +Log info + +/ Last changed on Mon Feb 19 10:37:05 2001 by +GvR +

+ +


+

3.35. In the regression test, test___all__ fails for the profile module. What's wrong?

+If you have been using the profile module, and have properly calibrated a copy of the module as described in the documentation for the profiler: +

+http://www.python.org/doc/current/lib/profile-calibration.html +

+then it is possible that the regression test "test___all__" will fail if you run the regression test manually rather than using "make test" in the Python source directory. This will happen if you have set your PYTHONPATH environment variable to include the directory containing your calibrated profile module. You have probably calibrated the profiler using an older version of the profile module which does not define the __all__ value, added to the module as of Python 2.1. +

+The problem can be fixed by removing the old calibrated version of the profile module and using the latest version to do a fresh calibration. In general, you will need to re-calibrate for each version of Python anyway, since the performance characteristics can change in subtle ways that impact profiling. +

+ +Edit this entry / +Log info + +/ Last changed on Fri Apr 27 10:44:10 2001 by +Fred Drake +

+ +


+

3.36. relocations remain against allocatable but non-writable sections

+This linker error occurs on Solaris if you attempt to build an extension module which incorporates position-dependent (non-PIC) code. A common source of problems is that a static library (.a file), such as libreadline.a or libcrypto.a is linked with the extension module. The error specifically occurs when using gcc as the compiler, but /usr/ccs/bin/ld as the linker. +

+The following solutions and work-arounds are known: +

+1. Rebuild the libraries (libreadline, libcrypto) with -fPIC (-KPIC if using the system compiler). This is recommended; all object files in a shared library should be position-independent. +

+2. Statically link the extension module and its libraries into the Python interpreter, by editing Modules/Setup. +

+3. Use GNU ld instead of /usr/ccs/bin/ld; GNU ld will accept non-PIC code in shared libraries (and mark the section writable) +

+4. Pass -mimpure-text to GCC when linking the module. This will force gcc to not pass -z text to ld; in turn, ld will make all text sections writable. +

+Options 3 and 4 are not recommended, since the ability to share code across processes is lost. +

+ +Edit this entry / +Log info + +/ Last changed on Tue Jan 29 12:05:11 2002 by +Martin v. Löwis +

+ +


+

4. Programming in Python

+ +
+

4.1. Is there a source code level debugger with breakpoints, step, etc.?

+Yes. +

+Module pdb is a rudimentary but adequate console-mode debugger for Python. It is part of the standard Python library, and is documented in the Library Reference Manual. (You can also write your own debugger by using the code for pdb as an example.) +

+The IDLE interactive development environment, which is part of the standard Python distribution (normally available in Tools/idle), includes a graphical debugger. There is documentation for the IDLE debugger at http://www.python.org/idle/doc/idle2.html#Debugger +

+Pythonwin is a Python IDE that includes a GUI debugger based on bdb. The Pythonwin debugger colors breakpoints and has quite a few cool features (including debugging non-Pythonwin programs). A reference can be found at http://www.python.org/ftp/python/pythonwin/pwindex.html +More recent versions of PythonWin are available as a part of the ActivePython distribution (see http://www.activestate.com/Products/ActivePython/index.html). +

+Pydb is a version of the standard Python debugger pdb, modified for use with DDD (Data Display Debugger), a popular graphical debugger front end. Pydb can be found at http://packages.debian.org/unstable/devel/pydb.html +and DDD can be found at http://www.gnu.org/software/ddd/ +

+There are a number of commmercial Python IDEs that include graphical debuggers. They include: +

+

+ * Wing IDE (http://wingide.com/) 
+ * Komodo IDE (http://www.activestate.com/Products/Komodo/)
+
+

+ +Edit this entry / +Log info + +/ Last changed on Tue Jan 28 01:43:41 2003 by +Stephen Ferg +

+ +


+

4.2. Can I create an object class with some methods implemented in C and others in Python (e.g. through inheritance)? (Also phrased as: Can I use a built-in type as base class?)

+In Python 2.2, you can inherit from builtin classes such as int, list, dict, etc. +

+In previous versions of Python, you can easily create a Python class which serves as a wrapper around a built-in object, e.g. (for dictionaries): +

+

+        # A user-defined class behaving almost identical
+        # to a built-in dictionary.
+        class UserDict:
+                def __init__(self): self.data = {}
+                def __repr__(self): return repr(self.data)
+                def __cmp__(self, dict):
+                        if type(dict) == type(self.data):
+                                return cmp(self.data, dict)
+                        else:
+                                return cmp(self.data, dict.data)
+                def __len__(self): return len(self.data)
+                def __getitem__(self, key): return self.data[key]
+                def __setitem__(self, key, item): self.data[key] = item
+                def __delitem__(self, key): del self.data[key]
+                def keys(self): return self.data.keys()
+                def items(self): return self.data.items()
+                def values(self): return self.data.values()
+                def has_key(self, key): return self.data.has_key(key)
+
+A2. See Jim Fulton's ExtensionClass for an example of a mechanism +which allows you to have superclasses which you can inherit from in +Python -- that way you can have some methods from a C superclass (call +it a mixin) and some methods from either a Python superclass or your +subclass. ExtensionClass is distributed as a part of Zope (see +http://www.zope.org), but will be phased out with Zope 3, since +Zope 3 uses Python 2.2 or later which supports direct inheritance +from built-in types. Here's a link to the original paper about +ExtensionClass: +http://debian.acm.ndsu.nodak.edu/doc/python-extclass/ExtensionClass.html +

+A3. The Boost Python Library (BPL, http://www.boost.org/libs/python/doc/index.html) +provides a way of doing this from C++ (i.e. you can inherit from an +extension class written in C++ using the BPL). +

+ +Edit this entry / +Log info + +/ Last changed on Tue May 28 21:09:52 2002 by +GvR +

+ +


+

4.3. Is there a curses/termcap package for Python?

+The standard Python source distribution comes with a curses module in +the Modules/ subdirectory, though it's not compiled by default (note +that this is not available in the Windows distribution -- there is +no curses module for Windows). +

+In Python versions before 2.0 the module only supported plain curses; +you couldn't use ncurses features like colors with it (though it would +link with ncurses). +

+In Python 2.0, the curses module has been greatly extended, starting +from Oliver Andrich's enhanced version, to provide many additional +functions from ncurses and SYSV curses, such as colour, alternative +character set support, pads, and mouse support. This means the +module is no longer compatible with operating systems that only +have BSD curses, but there don't seem to be any currently +maintained OSes that fall into this category. +

+ +Edit this entry / +Log info + +/ Last changed on Sun Jun 23 20:24:06 2002 by +Tim Peters +

+ +


+

4.4. Is there an equivalent to C's onexit() in Python?

+For Python 2.0: The new atexit module provides a register function that +is similar to C's onexit. See the Library Reference for details. For +2.0 you should not assign to sys.exitfunc! +

+For Python 1.5.2: You need to import sys and assign a function to +sys.exitfunc, it will be called when your program exits, is +killed by an unhandled exception, or (on UNIX) receives a +SIGHUP or SIGTERM signal. +

+ +Edit this entry / +Log info + +/ Last changed on Thu Dec 28 12:14:55 2000 by +Bjorn Pettersen +

+ +


+

4.5. [deleted]

+[python used to lack nested scopes, it was explained here] +

+ +Edit this entry / +Log info + +/ Last changed on Thu Mar 21 05:18:22 2002 by +Erno Kuusela +

+ +


+

4.6. How do I iterate over a sequence in reverse order?

+If it is a list, the fastest solution is +

+

+        list.reverse()
+        try:
+                for x in list:
+                        "do something with x"
+        finally:
+                list.reverse()
+
+This has the disadvantage that while you are in the loop, the list +is temporarily reversed. If you don't like this, you can make a copy. +This appears expensive but is actually faster than other solutions: +

+

+        rev = list[:]
+        rev.reverse()
+        for x in rev:
+                <do something with x>
+
+If it's not a list, a more general but slower solution is: +

+

+        for i in range(len(sequence)-1, -1, -1):
+                x = sequence[i]
+                <do something with x>
+
+A more elegant solution, is to define a class which acts as a sequence +and yields the elements in reverse order (solution due to Steve +Majewski): +

+

+        class Rev:
+                def __init__(self, seq):
+                        self.forw = seq
+                def __len__(self):
+                        return len(self.forw)
+                def __getitem__(self, i):
+                        return self.forw[-(i + 1)]
+
+You can now simply write: +

+

+        for x in Rev(list):
+                <do something with x>
+
+Unfortunately, this solution is slowest of all, due to the method +call overhead... +

+ +Edit this entry / +Log info + +/ Last changed on Sun May 25 21:10:50 1997 by +GvR +

+ +


+

4.7. My program is too slow. How do I speed it up?

+That's a tough one, in general. There are many tricks to speed up +Python code; I would consider rewriting parts in C only as a last +resort. One thing to notice is that function and (especially) method +calls are rather expensive; if you have designed a purely OO interface +with lots of tiny functions that don't do much more than get or set an +instance variable or call another method, you may consider using a +more direct way, e.g. directly accessing instance variables. Also see +the standard module "profile" (described in the Library Reference +manual) which makes it possible to find out where +your program is spending most of its time (if you have some patience +-- the profiling itself can slow your program down by an order of +magnitude). +

+Remember that many standard optimization heuristics you +may know from other programming experience may well apply +to Python. For example it may be faster to send output to output +devices using larger writes rather than smaller ones in order to +avoid the overhead of kernel system calls. Thus CGI scripts +that write all output in "one shot" may be notably faster than +those that write lots of small pieces of output. +

+Also, be sure to use "aggregate" operations where appropriate. +For example the "slicing" feature allows programs to chop up +lists and other sequence objects in a single tick of the interpreter +mainloop using highly optimized C implementations. Thus to +get the same effect as +

+

+  L2 = []
+  for i in range[3]:
+       L2.append(L1[i])
+
+it is much shorter and far faster to use +

+

+  L2 = list(L1[:3]) # "list" is redundant if L1 is a list.
+
+Note that the map() function, particularly used with +builtin methods or builtin functions can be a convenient +accelerator. For example to pair the elements of two +lists together: +

+

+  >>> map(None, [1,2,3], [4,5,6])
+  [(1, 4), (2, 5), (3, 6)]
+
+or to compute a number of sines: +

+

+  >>> map( math.sin, (1,2,3,4))
+  [0.841470984808, 0.909297426826, 0.14112000806,   -0.756802495308]
+
+The map operation completes very quickly in such cases. +

+Other examples of aggregate operations include the join and split +methods of string objects. For example if s1..s7 are large (10K+) strings then +"".join([s1,s2,s3,s4,s5,s6,s7]) may be far faster than +the more obvious s1+s2+s3+s4+s5+s6+s7, since the "summation" +will compute many subexpressions, whereas join does all +copying in one pass. For manipulating strings also consider the +regular expression libraries and the "substitution" operations +String % tuple and String % dictionary. Also be sure to use +the list.sort builtin method to do sorting, and see FAQ's 4.51 +and 4.59 for examples of moderately advanced usage -- list.sort beats +other techniques for sorting in all but the most extreme +circumstances. +

+There are many other aggregate operations +available in the standard libraries and in contributed libraries +and extensions. +

+Another common trick is to "push loops into functions or methods." +For example suppose you have a program that runs slowly and you +use the profiler (profile.run) to determine that a Python function ff +is being called lots of times. If you notice that ff +

+

+   def ff(x):
+       ...do something with x computing result...
+       return result
+
+tends to be called in loops like (A) +

+

+   list = map(ff, oldlist)
+
+or (B) +

+

+   for x in sequence:
+       value = ff(x)
+       ...do something with value...
+
+then you can often eliminate function call overhead by rewriting +ff to +

+

+   def ffseq(seq):
+       resultseq = []
+       for x in seq:
+           ...do something with x computing result...
+           resultseq.append(result)
+       return resultseq
+
+and rewrite (A) to +

+

+    list = ffseq(oldlist)
+
+and (B) to +

+

+    for value in ffseq(sequence):
+        ...do something with value...
+
+Other single calls ff(x) translate to ffseq([x])[0] with little +penalty. Of course this technique is not always appropriate +and there are other variants, which you can figure out. +

+You can gain some performance by explicitly storing the results of +a function or method lookup into a local variable. A loop like +

+

+    for key in token:
+        dict[key] = dict.get(key, 0) + 1
+
+resolves dict.get every iteration. If the method isn't going to +change, a faster implementation is +

+

+    dict_get = dict.get  # look up the method once
+    for key in token:
+        dict[key] = dict_get(key, 0) + 1
+
+Default arguments can be used to determine values once, at +compile time instead of at run time. This can only be done for +functions or objects which will not be changed during program +execution, such as replacing +

+

+    def degree_sin(deg):
+        return math.sin(deg * math.pi / 180.0)
+
+with +

+

+    def degree_sin(deg, factor = math.pi/180.0, sin = math.sin):
+        return sin(deg * factor)
+
+Because this trick uses default arguments for terms which should +not be changed, it should only be used when you are not concerned +with presenting a possibly confusing API to your users. +

+

+For an anecdote related to optimization, see +

+

+	http://www.python.org/doc/essays/list2str.html
+
+

+ +Edit this entry / +Log info + +/ Last changed on Mon Jun 3 01:03:54 2002 by +Neal Norwitz +

+ +


+

4.8. When I have imported a module, then edit it, and import it again (into the same Python process), the changes don't seem to take place. What is going on?

+For reasons of efficiency as well as consistency, Python only reads +the module file on the first time a module is imported. (Otherwise a +program consisting of many modules, each of which imports the same +basic module, would read the basic module over and over again.) To +force rereading of a changed module, do this: +

+

+        import modname
+        reload(modname)
+
+Warning: this technique is not 100% fool-proof. In particular, +modules containing statements like +

+

+        from modname import some_objects
+
+will continue to work with the old version of the imported objects. +

+ +Edit this entry / +Log info +

+ +


+

4.9. How do I find the current module name?

+A module can find out its own module name by looking at the +(predefined) global variable __name__. If this has the value +'__main__' you are running as a script. +

+ +Edit this entry / +Log info +

+ +


+

4.10. I have a module in which I want to execute some extra code when it is run as a script. How do I find out whether I am running as a script?

+See the previous question. E.g. if you put the following on the +last line of your module, main() is called only when your module is +running as a script: +

+

+        if __name__ == '__main__': main()
+
+

+ +Edit this entry / +Log info +

+ +


+

4.11. I try to run a program from the Demo directory but it fails with ImportError: No module named ...; what gives?

+This is probably an optional module (written in C!) which hasn't +been configured on your system. This especially happens with modules +like "Tkinter", "stdwin", "gl", "Xt" or "Xm". For Tkinter, STDWIN and +many other modules, see Modules/Setup.in for info on how to add these +modules to your Python, if it is possible at all. Sometimes you will +have to ftp and build another package first (e.g. Tcl and Tk for Tkinter). +Sometimes the module only works on specific platforms (e.g. gl only works +on SGI machines). +

+NOTE: if the complaint is about "Tkinter" (upper case T) and you have +already configured module "tkinter" (lower case t), the solution is +not to rename tkinter to Tkinter or vice versa. There is probably +something wrong with your module search path. Check out the value of +sys.path. +

+For X-related modules (Xt and Xm) you will have to do more work: they +are currently not part of the standard Python distribution. You will +have to ftp the Extensions tar file, i.e. +ftp://ftp.python.org/pub/python/src/X-extension.tar.gz and follow +the instructions there. +

+ +Edit this entry / +Log info + +/ Last changed on Wed Feb 12 21:31:08 2003 by +Jens Kubieziel +

+ +


+

4.12. [deleted]

+[stdwin (long dead windowing library) entry deleted] +

+ +Edit this entry / +Log info + +/ Last changed on Thu Mar 21 08:30:13 2002 by +Erno Kuusela +

+ +


+

4.13. What GUI toolkits exist for Python?

+Depending on what platform(s) you are aiming at, there are several. +

+Currently supported solutions: +

+Cross-platform: +

+Tk: +

+There's a neat object-oriented interface to the Tcl/Tk widget set, +called Tkinter. It is part of the standard Python distribution and +well-supported -- all you need to do is build and install Tcl/Tk and +enable the _tkinter module and the TKPATH definition in Modules/Setup +when building Python. This is probably the easiest to install and +use, and the most complete widget set. It is also very likely that in +the future the standard Python GUI API will be based on or at least +look very much like the Tkinter interface. For more info about Tk, +including pointers to the source, see the Tcl/Tk home page at +http://www.scriptics.com. Tcl/Tk is now fully +portable to the Mac and Windows platforms (NT and 95 only); you need +Python 1.4beta3 or later and Tk 4.1patch1 or later. +

+wxWindows: +

+There's an interface to wxWindows called wxPython. wxWindows is a +portable GUI class library written in C++. It supports GTK, Motif, +MS-Windows and Mac as targets. Ports to other platforms are being +contemplated or have already had some work done on them. wxWindows +preserves the look and feel of the underlying graphics toolkit, and +there is quite a rich widget set and collection of GDI classes. +See the wxWindows page at http://www.wxwindows.org/ for more details. +wxPython is a python extension module that wraps many of the wxWindows +C++ classes, and is quickly gaining popularity amongst Python +developers. You can get wxPython as part of the source or CVS +distribution of wxWindows, or directly from its home page at +http://alldunn.com/wxPython/. +

+Gtk+: +

+PyGtk bindings for the Gtk+ Toolkit by James Henstridge exist; see ftp://ftp.daa.com.au/pub/james/python/. Note that there are two incompatible bindings. If you are using Gtk+ 1.2.x you should get the 0.6.x PyGtk bindings from +

+

+    ftp://ftp.gtk.org/pub/python/v1.2
+
+If you plan to use Gtk+ 2.0 with Python (highly recommended if you are just starting with Gtk), get the most recent distribution from +

+

+    ftp://ftp.gtk.org/pub/python/v2.0
+
+If you are adventurous, you can also check out the source from the Gnome CVS repository. Set your CVS directory to :pserver:anonymous@anoncvs.gnome.org:/cvs/gnome and check the gnome-python module out from the repository. +

+Other: +

+There are also bindings available for the Qt toolkit (PyQt), and for KDE (PyKDE); see http://www.thekompany.com/projects/pykde/. +

+For OpenGL bindings, see http://starship.python.net/~da/PyOpenGL. +

+Platform specific: +

+The Mac port has a rich and ever-growing set of modules that support +the native Mac toolbox calls. See the documentation that comes with +the Mac port. See ftp://ftp.python.org/pub/python/mac. Support +by Jack Jansen jack@cwi.nl. +

+Pythonwin by Mark Hammond (MHammond@skippinet.com.au) +includes an interface to the Microsoft Foundation +Classes and a Python programming environment using it that's written +mostly in Python. See http://www.python.org/windows/. +

+There's an object-oriented GUI based on the Microsoft Foundation +Classes model called WPY, supported by Jim Ahlstrom jim@interet.com. +Programs written in WPY run unchanged and with native look and feel on +Windows NT/95, Windows 3.1 (using win32s), and on Unix (using Tk). +Source and binaries for Windows and Linux are available in +ftp://ftp.python.org/pub/python/wpy/. +

+Obsolete or minority solutions: +

+There's an interface to X11, including the Athena and Motif widget +sets (and a few individual widgets, like Mosaic's HTML widget and +SGI's GL widget) available from +ftp://ftp.python.org/pub/python/src/X-extension.tar.gz. +Support by Sjoerd Mullender sjoerd@cwi.nl. +

+On top of the X11 interface there's the vpApp +toolkit by Per Spilling, now also maintained by Sjoerd Mullender +sjoerd@cwi.nl. See ftp://ftp.cwi.nl/pub/sjoerd/vpApp.tar.gz. +

+For SGI IRIX only, there are unsupported interfaces to the complete +GL (Graphics Library -- low level but very good 3D capabilities) as +well as to FORMS (a buttons-and-sliders-etc package built on top of GL +by Mark Overmars -- ftp'able from +ftp://ftp.cs.ruu.nl/pub/SGI/FORMS/). This is probably also +becoming obsolete, as OpenGL takes over (see above). +

+There's an interface to STDWIN, a platform-independent low-level +windowing interface for Mac and X11. This is totally unsupported and +rapidly becoming obsolete. The STDWIN sources are at +ftp://ftp.cwi.nl/pub/stdwin/. +

+There is an interface to WAFE, a Tcl interface to the X11 +Motif and Athena widget sets. WAFE is at +http://www.wu-wien.ac.at/wafe/wafe.html. +

+ +Edit this entry / +Log info + +/ Last changed on Mon May 13 21:40:39 2002 by +Skip Montanaro +

+ +


+

4.14. Are there any interfaces to database packages in Python?

+Yes! See the Database Topic Guide at +http://www.python.org/topics/database/ for details. +

+ +Edit this entry / +Log info + +/ Last changed on Tue Jan 4 20:12:19 2000 by +Barney Warplug +

+ +


+

4.15. Is it possible to write obfuscated one-liners in Python?

+Yes. See the following three examples, due to Ulf Bartelt: +

+

+        # Primes < 1000
+        print filter(None,map(lambda y:y*reduce(lambda x,y:x*y!=0,
+        map(lambda x,y=y:y%x,range(2,int(pow(y,0.5)+1))),1),range(2,1000)))
+
+
+        # First 10 Fibonacci numbers
+        print map(lambda x,f=lambda x,f:(x<=1) or (f(x-1,f)+f(x-2,f)): f(x,f),
+        range(10))
+
+
+        # Mandelbrot set
+        print (lambda Ru,Ro,Iu,Io,IM,Sx,Sy:reduce(lambda x,y:x+y,map(lambda y,
+        Iu=Iu,Io=Io,Ru=Ru,Ro=Ro,Sy=Sy,L=lambda yc,Iu=Iu,Io=Io,Ru=Ru,Ro=Ro,i=IM,
+        Sx=Sx,Sy=Sy:reduce(lambda x,y:x+y,map(lambda x,xc=Ru,yc=yc,Ru=Ru,Ro=Ro,
+        i=i,Sx=Sx,F=lambda xc,yc,x,y,k,f=lambda xc,yc,x,y,k,f:(k<=0)or (x*x+y*y
+        >=4.0) or 1+f(xc,yc,x*x-y*y+xc,2.0*x*y+yc,k-1,f):f(xc,yc,x,y,k,f):chr(
+        64+F(Ru+x*(Ro-Ru)/Sx,yc,0,0,i)),range(Sx))):L(Iu+y*(Io-Iu)/Sy),range(Sy
+        ))))(-2.1, 0.7, -1.2, 1.2, 30, 80, 24)
+        #    \___ ___/  \___ ___/  |   |   |__ lines on screen
+        #        V          V      |   |______ columns on screen
+        #        |          |      |__________ maximum of "iterations"
+        #        |          |_________________ range on y axis
+        #        |____________________________ range on x axis
+
+Don't try this at home, kids! +

+ +Edit this entry / +Log info + +/ Last changed on Wed May 21 15:48:33 1997 by +GvR +

+ +


+

4.16. Is there an equivalent of C's "?:" ternary operator?

+Not directly. In many cases you can mimic a?b:c with "a and b or +c", but there's a flaw: if b is zero (or empty, or None -- anything +that tests false) then c will be selected instead. In many cases you +can prove by looking at the code that this can't happen (e.g. because +b is a constant or has a type that can never be false), but in general +this can be a problem. +

+Tim Peters (who wishes it was Steve Majewski) suggested the following +solution: (a and [b] or [c])[0]. Because [b] is a singleton list it +is never false, so the wrong path is never taken; then applying [0] to +the whole thing gets the b or c that you really wanted. Ugly, but it +gets you there in the rare cases where it is really inconvenient to +rewrite your code using 'if'. +

+As a last resort it is possible to implement the "?:" operator as a function: +

+

+    def q(cond,on_true,on_false):
+        from inspect import isfunction
+
+
+        if cond:
+            if not isfunction(on_true): return on_true
+            else: return apply(on_true)
+        else:
+            if not isfunction(on_false): return on_false 
+            else: return apply(on_false)
+
+In most cases you'll pass b and c directly: q(a,b,c). To avoid evaluating b +or c when they shouldn't be, encapsulate them +within a lambda function, e.g.: q(a,lambda: b, lambda: c). +

+

+

+It has been asked why Python has no if-then-else expression, +since most language have one; it is a frequently requested feature. +

+There are several possible answers: just as many languages do +just fine without one; it can easily lead to less readable code; +no sufficiently "Pythonic" syntax has been discovered; a search +of the standard library found remarkably few places where using an +if-then-else expression would make the code more understandable. +

+Nevertheless, in an effort to decide once and for all whether +an if-then-else expression should be added to the language, +PEP 308 (http://www.python.org/peps/pep-0308.html) has been +put forward, proposing a specific syntax. The community can +now vote on this issue. +

+ +Edit this entry / +Log info + +/ Last changed on Fri Feb 7 19:41:13 2003 by +David Goodger +

+ +


+

4.17. My class defines __del__ but it is not called when I delete the object.

+There are several possible reasons for this. +

+The del statement does not necessarily call __del__ -- it simply +decrements the object's reference count, and if this reaches zero +__del__ is called. +

+If your data structures contain circular links (e.g. a tree where +each child has a parent pointer and each parent has a list of +children) the reference counts will never go back to zero. You'll +have to define an explicit close() method which removes those +pointers. Please don't ever call __del__ directly -- __del__ should +call close() and close() should make sure that it can be called more +than once for the same object. +

+If the object has ever been a local variable (or argument, which is +really the same thing) to a function that caught an expression in an +except clause, chances are that a reference to the object still exists +in that function's stack frame as contained in the stack trace. +Normally, deleting (better: assigning None to) sys.exc_traceback will +take care of this. If a stack was printed for an unhandled +exception in an interactive interpreter, delete sys.last_traceback +instead. +

+There is code that deletes all objects when the interpreter exits, +but it is not called if your Python has been configured to support +threads (because other threads may still be active). You can define +your own cleanup function using sys.exitfunc (see question 4.4). +

+Finally, if your __del__ method raises an exception, a warning message is printed to sys.stderr. +

+

+Starting with Python 2.0, a garbage collector periodically reclaims the space used by most cycles with no external references. (See the "gc" module documentation for details.) There are, however, pathological cases where it can be expected to fail. Moreover, the garbage collector runs some time after the last reference to your data structure vanishes, so your __del__ method may be called at an inconvenient and random time. This is inconvenient if you're trying to reproduce a problem. Worse, the order in which object's __del__ methods are executed is arbitrary. +

+Another way to avoid cyclical references is to use the "weakref" module, which allows you to point to objects without incrementing their reference count. Tree data structures, for instance, should use weak references for their parent and sibling pointers (if they need them!). +

+Question 6.14 is intended to explain the new garbage collection algorithm. +

+ +Edit this entry / +Log info + +/ Last changed on Mon Jun 10 15:27:28 2002 by +Matthias Urlichs +

+ +


+

4.18. How do I change the shell environment for programs called using os.popen() or os.system()? Changing os.environ doesn't work.

+You must be using either a version of python before 1.4, or on a +(rare) system that doesn't have the putenv() library function. +

+Before Python 1.4, modifying the environment passed to subshells was +left out of the interpreter because there seemed to be no +well-established portable way to do it (in particular, some systems, +have putenv(), others have setenv(), and some have none at all). As +of Python 1.4, almost all Unix systems do have putenv(), and so does +the Win32 API, and thus the os module was modified so that changes to +os.environ are trapped and the corresponding putenv() call is made. +

+ +Edit this entry / +Log info +

+ +


+

4.19. What is a class?

+A class is the particular object type created by executing +a class statement. Class objects are used as templates, to create +instance objects, which embody both the data structure +(attributes) and program routines (methods) specific to a datatype. +

+A class can be based on one or more other classes, called its base +class(es). It then inherits the attributes and methods of its base classes. This allows an object model to be successively refined +by inheritance. +

+The term "classic class" is used to refer to the original +class implementation in Python. One problem with classic +classes is their inability to use the built-in data types +(such as list and dictionary) as base classes. Starting +with Python 2.2 an attempt is in progress to unify user-defined +classes and built-in types. It is now possible to declare classes +that inherit from built-in types. +

+ +Edit this entry / +Log info + +/ Last changed on Mon May 27 01:31:21 2002 by +Steve Holden +

+ +


+

4.20. What is a method?

+A method is a function that you normally call as +x.name(arguments...) for some object x. The term is used for methods +of classes and class instances as well as for methods of built-in +objects. (The latter have a completely different implementation and +only share the way their calls look in Python code.) Methods of +classes (and class instances) are defined as functions inside the +class definition. +

+ +Edit this entry / +Log info +

+ +


+

4.21. What is self?

+Self is merely a conventional name for the first argument of a +method -- i.e. a function defined inside a class definition. A method +defined as meth(self, a, b, c) should be called as x.meth(a, b, c) for +some instance x of the class in which the definition occurs; +the called method will think it is called as meth(x, a, b, c). +

+ +Edit this entry / +Log info +

+ +


+

4.22. What is an unbound method?

+An unbound method is a method defined in a class that is not yet +bound to an instance. You get an unbound method if you ask for a +class attribute that happens to be a function. You get a bound method +if you ask for an instance attribute. A bound method knows which +instance it belongs to and calling it supplies the instance automatically; +an unbound method only knows which class it wants for its first +argument (a derived class is also OK). Calling an unbound method +doesn't "magically" derive the first argument from the context -- you +have to provide it explicitly. +

+Trivia note regarding bound methods: each reference to a bound +method of a particular object creates a bound method object. If you +have two such references (a = inst.meth; b = inst.meth), they will +compare equal (a == b) but are not the same (a is not b). +

+ +Edit this entry / +Log info + +/ Last changed on Wed May 6 18:07:25 1998 by +Clarence Gardner +

+ +


+

4.23. How do I call a method defined in a base class from a derived class that overrides it?

+If your class definition starts with "class Derived(Base): ..." +then you can call method meth defined in Base (or one of Base's base +classes) as Base.meth(self, arguments...). Here, Base.meth is an +unbound method (see previous question). +

+ +Edit this entry / +Log info +

+ +


+

4.24. How do I call a method from a base class without using the name of the base class?

+DON'T DO THIS. REALLY. I MEAN IT. It appears that you could call +self.__class__.__bases__[0].meth(self, arguments...) but this fails when +a doubly-derived method is derived from your class: for its instances, +self.__class__.__bases__[0] is your class, not its base class -- so +(assuming you are doing this from within Derived.meth) you would start +a recursive call. +

+Often when you want to do this you are forgetting that classes +are first class in Python. You can "point to" the class you want +to delegate an operation to either at the instance or at the +subclass level. For example if you want to use a "glorp" +operation of a superclass you can point to the right superclass +to use. +

+

+  class subclass(superclass1, superclass2, superclass3):
+      delegate_glorp = superclass2
+      ...
+      def glorp(self, arg1, arg2):
+            ... subclass specific stuff ...
+            self.delegate_glorp.glorp(self, arg1, arg2)
+       ...
+
+
+  class subsubclass(subclass):
+       delegate_glorp = superclass3
+       ...
+
+Note, however that setting delegate_glorp to subclass in +subsubclass would cause an infinite recursion on subclass.delegate_glorp. Careful! Maybe you are getting too fancy for your own good. Consider simplifying the design (?). +

+ +Edit this entry / +Log info + +/ Last changed on Mon Jul 28 13:58:22 1997 by +aaron watters +

+ +


+

4.25. How can I organize my code to make it easier to change the base class?

+You could define an alias for the base class, assign the real base +class to it before your class definition, and use the alias throughout +your class. Then all you have to change is the value assigned to the +alias. Incidentally, this trick is also handy if you want to decide +dynamically (e.g. depending on availability of resources) which base +class to use. Example: +

+

+        BaseAlias = <real base class>
+        class Derived(BaseAlias):
+                def meth(self):
+                        BaseAlias.meth(self)
+                        ...
+
+

+ +Edit this entry / +Log info + +/ Last changed on Wed May 21 15:49:57 1997 by +GvR +

+ +


+

4.26. How can I find the methods or attributes of an object?

+This depends on the object type. +

+For an instance x of a user-defined class, instance attributes are +found in the dictionary x.__dict__, and methods and attributes defined +by its class are found in x.__class__.__bases__[i].__dict__ (for i in +range(len(x.__class__.__bases__))). You'll have to walk the tree of +base classes to find all class methods and attributes. +

+Many, but not all built-in types define a list of their method names +in x.__methods__, and if they have data attributes, their names may be +found in x.__members__. However this is only a convention. +

+For more information, read the source of the standard (but +undocumented) module newdir. +

+ +Edit this entry / +Log info +

+ +


+

4.27. I can't seem to use os.read() on a pipe created with os.popen().

+os.read() is a low-level function which takes a file descriptor (a +small integer). os.popen() creates a high-level file object -- the +same type used for sys.std{in,out,err} and returned by the builtin +open() function. Thus, to read n bytes from a pipe p created with +os.popen(), you need to use p.read(n). +

+ +Edit this entry / +Log info +

+ +


+

4.28. How can I create a stand-alone binary from a Python script?

+Even though there are Python compilers being developed, +you probably don't need a real compiler, if all you want +is a stand-alone program. There are three solutions to that. +

+One is to use the freeze tool, which is included in the Python +source tree as Tools/freeze. It converts Python byte +code to C arrays. Using a C compiler, you can embed all +your modules into a new program, which is then linked +with the standard Python modules. +

+It works by scanning your source recursively for import statements +(in both forms) and looking for the modules in the standard Python path +as well as in the source directory (for built-in modules). It then +1 the modules written in Python to C code (array initializers +that can be turned into code objects using the marshal module) and +creates a custom-made config file that only contains those built-in +modules which are actually used in the program. It then compiles the +generated C code and links it with the rest of the Python interpreter +to form a self-contained binary which acts exactly like your script. +

+(Hint: the freeze program only works if your script's filename ends in +".py".) +

+There are several utilities which may be helpful. The first is Gordon McMillan's installer at +

+

+    http://www.mcmillan-inc.com/install1.html
+
+which works on Windows, Linux and at least some forms of Unix. +

+Another is Thomas Heller's py2exe (Windows only) at +

+

+    http://starship.python.net/crew/theller/py2exe/
+
+A third is Christian Tismer's SQFREEZE +(http://starship.python.net/crew/pirx/) which appends the byte code +to a specially-prepared Python interpreter, which +will find the byte code in executable. +

+A fourth is Fredrik Lundh's Squeeze +(http://www.pythonware.com/products/python/squeeze/). +

+ +Edit this entry / +Log info + +/ Last changed on Wed Jun 19 14:01:30 2002 by +Gordon McMillan +

+ +


+

4.29. What WWW tools are there for Python?

+See the chapters titled "Internet Protocols and Support" and +"Internet Data Handling" in the Library Reference +Manual. Python is full of good things which will help you build server-side and client-side web systems. +

+A summary of available frameworks is maintained by Paul Boddie at +

+

+    http://thor.prohosting.com/~pboddie/Python/web_modules.html
+
+Cameron Laird maintains a useful set of pages about Python web technologies at +

+

+   http://starbase.neosoft.com/~claird/comp.lang.python/web_python.html/
+
+There was a web browser written in Python, called Grail -- +see http://sourceforge.net/project/grail/. This project has been terminated; http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/grail/grail/README gives more details. +

+ +Edit this entry / +Log info + +/ Last changed on Mon Nov 11 22:48:25 2002 by +GvR +

+ +


+

4.30. How do I run a subprocess with pipes connected to both input and output?

+Use the standard popen2 module. For example: +

+

+	import popen2
+	fromchild, tochild = popen2.popen2("command")
+	tochild.write("input\n")
+	tochild.flush()
+	output = fromchild.readline()
+
+Warning: in general, it is unwise to +do this, because you can easily cause a deadlock where your +process is blocked waiting for output from the child, while the child +is blocked waiting for input from you. This can be caused +because the parent expects the child to output more text than it does, +or it can be caused by data being stuck in stdio buffers due to lack +of flushing. The Python parent can of course explicitly flush the data +it sends to the child before it reads any output, but if the child is +a naive C program it can easily have been written to never explicitly +flush its output, even if it is interactive, since flushing is +normally automatic. +

+Note that a deadlock is also possible if you use popen3 to read +stdout and stderr. If one of the two is too large for the internal +buffer (increasing the buffersize does not help) and you read() +the other one first, there is a deadlock, too. +

+Note on a bug in popen2: unless your program calls wait() +or waitpid(), finished child processes are never removed, +and eventually calls to popen2 will fail because of a limit on +the number of child processes. Calling os.waitpid with the +os.WNOHANG option can prevent this; a good place to insert such +a call would be before calling popen2 again. +

+Another way to produce a deadlock: Call a wait() and there is +still more output from the program than what fits into the +internal buffers. +

+In many cases, all you really need is to run some data through a +command and get the result back. Unless the data is infinite in size, +the easiest (and often the most efficient!) way to do this is to write +it to a temporary file and run the command with that temporary file as +input. The standard module tempfile exports a function mktemp() which +generates unique temporary file names. +

+

+ import tempfile
+ import os
+ class Popen3:
+    """
+    This is a deadlock-save version of popen, that returns
+    an object with errorlevel, out (a string) and err (a string).
+    (capturestderr may not work under windows.)
+    Example: print Popen3('grep spam','\n\nhere spam\n\n').out
+    """
+    def __init__(self,command,input=None,capturestderr=None):
+        outfile=tempfile.mktemp()
+        command="( %s ) > %s" % (command,outfile)
+        if input:
+            infile=tempfile.mktemp()
+            open(infile,"w").write(input)
+            command=command+" <"+infile
+        if capturestderr:
+            errfile=tempfile.mktemp()
+            command=command+" 2>"+errfile
+        self.errorlevel=os.system(command) >> 8
+        self.out=open(outfile,"r").read()
+        os.remove(outfile)
+        if input:
+            os.remove(infile)
+        if capturestderr:
+            self.err=open(errfile,"r").read()
+            os.remove(errfile)
+
+Note that many interactive programs (e.g. vi) don't work well with +pipes substituted for standard input and output. You will have to use +pseudo ttys ("ptys") instead of pipes. There is some undocumented +code to use these in the library module pty.py -- I'm afraid you're on +your own here. +

+A different answer is a Python interface to Don Libes' "expect" +library. A Python extension that interfaces to expect is called "expy" +and available from +http://expectpy.sourceforge.net/. +

+A pure Python solution that works like expect is pexpect of Noah Spurrier. +A beta version is available from +http://pexpect.sourceforge.net/ +

+ +Edit this entry / +Log info + +/ Last changed on Tue Sep 3 16:31:31 2002 by +Tobias Polzin +

+ +


+

4.31. How do I call a function if I have the arguments in a tuple?

+Use the built-in function apply(). For instance, +

+

+    func(1, 2, 3)
+
+is equivalent to +

+

+    args = (1, 2, 3)
+    apply(func, args)
+
+Note that func(args) is not the same -- it calls func() with exactly +one argument, the tuple args, instead of three arguments, the integers +1, 2 and 3. +

+In Python 2.0, you can also use extended call syntax: +

+f(*args) is equivalent to apply(f, args) +

+ +Edit this entry / +Log info + +/ Last changed on Tue Jan 2 03:42:50 2001 by +Moshe Zadka +

+ +


+

4.32. How do I enable font-lock-mode for Python in Emacs?

+If you are using XEmacs 19.14 or later, any XEmacs 20, FSF Emacs 19.34 +or any Emacs 20, font-lock should work automatically for you if you +are using the latest python-mode.el. +

+If you are using an older version of XEmacs or Emacs you will need +to put this in your .emacs file: +

+

+        (defun my-python-mode-hook ()
+          (setq font-lock-keywords python-font-lock-keywords)
+          (font-lock-mode 1))
+        (add-hook 'python-mode-hook 'my-python-mode-hook)
+
+

+ +Edit this entry / +Log info + +/ Last changed on Mon Apr 6 16:18:46 1998 by +Barry Warsaw +

+ +


+

4.33. Is there a scanf() or sscanf() equivalent?

+Not as such. +

+For simple input parsing, the easiest approach is usually to split +the line into whitespace-delimited words using string.split(), and to +convert decimal strings to numeric values using int(), +long() or float(). (Python's int() is 32-bit and its +long() is arbitrary precision.) string.split supports an optional +"sep" parameter which is useful if the line uses something other +than whitespace as a delimiter. +

+For more complicated input parsing, regular expressions (see module re) +are better suited and more powerful than C's sscanf(). +

+There's a contributed module that emulates sscanf(), by Steve Clift; +see contrib/Misc/sscanfmodule.c of the ftp site: +

+

+    http://www.python.org/ftp/python/contrib-09-Dec-1999/Misc/
+
+

+ +Edit this entry / +Log info + +/ Last changed on Mon Jun 3 01:07:51 2002 by +Neal Norwitz +

+ +


+

4.34. Can I have Tk events handled while waiting for I/O?

+Yes, and you don't even need threads! But you'll have to +restructure your I/O code a bit. Tk has the equivalent of Xt's +XtAddInput() call, which allows you to register a callback function +which will be called from the Tk mainloop when I/O is possible on a +file descriptor. Here's what you need: +

+

+        from Tkinter import tkinter
+        tkinter.createfilehandler(file, mask, callback)
+
+The file may be a Python file or socket object (actually, anything +with a fileno() method), or an integer file descriptor. The mask is +one of the constants tkinter.READABLE or tkinter.WRITABLE. The +callback is called as follows: +

+

+        callback(file, mask)
+
+You must unregister the callback when you're done, using +

+

+        tkinter.deletefilehandler(file)
+
+Note: since you don't know *how many bytes* are available for reading, +you can't use the Python file object's read or readline methods, since +these will insist on reading a predefined number of bytes. For +sockets, the recv() or recvfrom() methods will work fine; for other +files, use os.read(file.fileno(), maxbytecount). +

+ +Edit this entry / +Log info +

+ +


+

4.35. How do I write a function with output parameters (call by reference)?

+[Mark Lutz] The thing to remember is that arguments are passed by +assignment in Python. Since assignment just creates references to +objects, there's no alias between an argument name in the caller and +callee, and so no call-by-reference per se. But you can simulate it +in a number of ways: +

+1) By using global variables; but you probably shouldn't :-) +

+2) By passing a mutable (changeable in-place) object: +

+

+      def func1(a):
+          a[0] = 'new-value'     # 'a' references a mutable list
+          a[1] = a[1] + 1        # changes a shared object
+
+
+      args = ['old-value', 99]
+      func1(args)
+      print args[0], args[1]     # output: new-value 100
+
+3) By returning a tuple, holding the final values of arguments: +

+

+      def func2(a, b):
+          a = 'new-value'        # a and b are local names
+          b = b + 1              # assigned to new objects
+          return a, b            # return new values
+
+
+      x, y = 'old-value', 99
+      x, y = func2(x, y)
+      print x, y                 # output: new-value 100
+
+4) And other ideas that fall-out from Python's object model. For instance, it might be clearer to pass in a mutable dictionary: +

+

+      def func3(args):
+          args['a'] = 'new-value'     # args is a mutable dictionary
+          args['b'] = args['b'] + 1   # change it in-place
+
+
+      args = {'a':' old-value', 'b': 99}
+      func3(args)
+      print args['a'], args['b']
+
+5) Or bundle-up values in a class instance: +

+

+      class callByRef:
+          def __init__(self, **args):
+              for (key, value) in args.items():
+                  setattr(self, key, value)
+
+
+      def func4(args):
+          args.a = 'new-value'        # args is a mutable callByRef
+          args.b = args.b + 1         # change object in-place
+
+
+      args = callByRef(a='old-value', b=99)
+      func4(args)
+      print args.a, args.b
+
+
+   But there's probably no good reason to get this complicated :-).
+
+[Python's author favors solution 3 in most cases.] +

+ +Edit this entry / +Log info + +/ Last changed on Sun Jun 8 23:49:46 1997 by +David Ascher +

+ +


+

4.36. Please explain the rules for local and global variables in Python.

+[Ken Manheimer] In Python, procedure variables are implicitly +global, unless they are assigned anywhere within the block. +In that case +they are implicitly local, and you need to explicitly declare them as +'global'. +

+Though a bit surprising at first, a moment's consideration explains +this. On one hand, requirement of 'global' for assigned vars provides +a bar against unintended side-effects. On the other hand, if global +were required for all global references, you'd be using global all the +time. Eg, you'd have to declare as global every reference to a +builtin function, or to a component of an imported module. This +clutter would defeat the usefulness of the 'global' declaration for +identifying side-effects. +

+ +Edit this entry / +Log info + +/ Last changed on Fri Aug 28 09:53:27 1998 by +GvR +

+ +


+

4.37. How can I have modules that mutually import each other?

+Suppose you have the following modules: +

+foo.py: +

+

+	from bar import bar_var
+	foo_var=1
+
+bar.py: +

+

+	from foo import foo_var
+	bar_var=2
+
+The problem is that the above is processed by the interpreter thus: +

+

+	main imports foo
+	Empty globals for foo are created
+	foo is compiled and starts executing
+	foo imports bar
+	Empty globals for bar are created
+	bar is compiled and starts executing
+	bar imports foo (which is a no-op since there already is a module named foo)
+	bar.foo_var = foo.foo_var
+	...
+
+The last step fails, because Python isn't done with interpreting foo yet and the global symbol dict for foo is still empty. +

+The same thing happens when you use "import foo", and then try to access "foo.one" in global code. +

+

+There are (at least) three possible workarounds for this problem. +

+Guido van Rossum recommends to avoid all uses of "from <module> import ..." (so everything from an imported module is referenced as <module>.<name>) and to place all code inside functions. Initializations of global variables and class variables should use constants or built-in functions only. +

+

+Jim Roskind suggests the following order in each module: +

+

+ exports (globals, functions, and classes that don't need imported base classes)
+ import statements
+ active code (including globals that are initialized from imported values).
+
+Python's author doesn't like this approach much because the imports +appear in a strange place, but has to admit that it works. +

+

+

+Matthias Urlichs recommends to restructure your code so that the recursive import is not necessary in the first place. +

+

+These solutions are not mutually exclusive. +

+ +Edit this entry / +Log info + +/ Last changed on Mon Jun 3 06:52:51 2002 by +Matthias Urlichs +

+ +


+

4.38. How do I copy an object in Python?

+Try copy.copy() or copy.deepcopy() for the general case. Not all objects can be copied, but most can. +

+Dictionaries have a copy method. Sequences can be copied by slicing: +

+ new_l = l[:]
+
+

+ +Edit this entry / +Log info + +/ Last changed on Thu Mar 21 05:40:26 2002 by +Erno Kuusela +

+ +


+

4.39. How to implement persistent objects in Python? (Persistent == automatically saved to and restored from disk.)

+The library module "pickle" now solves this in a very general way +(though you still can't store things like open files, sockets or +windows), and the library module "shelve" uses pickle and (g)dbm to +create persistent mappings containing arbitrary Python objects. +For possibly better performance also look for the latest version +of the relatively recent cPickle module. +

+A more awkward way of doing things is to use pickle's little sister, +marshal. The marshal module provides very fast ways to store +noncircular basic Python types to files and strings, and back again. +Although marshal does not do fancy things like store instances or +handle shared references properly, it does run extremely fast. For +example loading a half megabyte of data may take less than a +third of a second (on some machines). This often beats doing +something more complex and general such as using gdbm with +pickle/shelve. +

+ +Edit this entry / +Log info + +/ Last changed on Sun Jun 8 22:59:00 1997 by +David Ascher +

+ +


+

4.40. I try to use __spam and I get an error about _SomeClassName__spam.

+Variables with double leading underscore are "mangled" to provide a +simple but effective way to define class private variables. See the +chapter "New in Release 1.4" in the Python Tutorial. +

+ +Edit this entry / +Log info +

+ +


+

4.41. How do I delete a file? And other file questions.

+Use os.remove(filename) or os.unlink(filename); for documentation, +see the posix section of the library manual. They are the same, +unlink() is simply the Unix name for this function. In earlier +versions of Python, only os.unlink() was available. +

+To remove a directory, use os.rmdir(); use os.mkdir() to create one. +

+To rename a file, use os.rename(). +

+To truncate a file, open it using f = open(filename, "r+"), and use +f.truncate(offset); offset defaults to the current seek position. +(The "r+" mode opens the file for reading and writing.) +There's also os.ftruncate(fd, offset) for files opened with os.open() +-- for advanced Unix hacks only. +

+The shutil module also contains a number of functions to work on files +including copyfile, copytree, and rmtree amongst others. +

+ +Edit this entry / +Log info + +/ Last changed on Thu Dec 28 12:30:01 2000 by +Bjorn Pettersen +

+ +


+

4.42. How to modify urllib or httplib to support HTTP/1.1?

+Recent versions of Python (2.0 and onwards) support HTTP/1.1 natively. +

+ +Edit this entry / +Log info + +/ Last changed on Tue Jan 2 02:56:56 2001 by +Moshe Zadka +

+ +


+

4.43. Unexplicable syntax errors in compile() or exec.

+When a statement suite (as opposed to an expression) is compiled by +compile(), exec or execfile(), it must end in a newline. In some +cases, when the source ends in an indented block it appears that at +least two newlines are required. +

+ +Edit this entry / +Log info +

+ +


+

4.44. How do I convert a string to a number?

+For integers, use the built-in int() function, e.g. int('144') == 144. Similarly, long() converts from string to long integer, e.g. long('144') == 144L; and float() to floating-point, e.g. float('144') == 144.0. +

+Note that these are restricted to decimal interpretation, so +that int('0144') == 144 and int('0x144') raises ValueError. For Python +2.0 int takes the base to convert from as a second optional argument, so +int('0x144', 16) == 324. +

+For greater flexibility, or before Python 1.5, import the module +string and use the string.atoi() function for integers, +string.atol() for long integers, or string.atof() for +floating-point. E.g., +string.atoi('100', 16) == string.atoi('0x100', 0) == 256. +See the library reference manual section for the string module for +more details. +

+While you could use the built-in function eval() instead of +any of those, this is not recommended, because someone could pass you +a Python expression that might have unwanted side effects (like +reformatting your disk). It also has the effect of interpreting numbers +as Python expressions, so that e.g. eval('09') gives a syntax error +since Python regards numbers starting with '0' as octal (base 8). +

+ +Edit this entry / +Log info + +/ Last changed on Thu Dec 28 12:37:34 2000 by +Bjorn Pettersen +

+ +


+

4.45. How do I convert a number to a string?

+To convert, e.g., the number 144 to the string '144', use the +built-in function repr() or the backquote notation (these are +equivalent). If you want a hexadecimal or octal representation, use +the built-in functions hex() or oct(), respectively. For fancy +formatting, use the % operator on strings, just like C printf formats, +e.g. "%04d" % 144 yields '0144' and "%.3f" % (1/3.0) yields '0.333'. +See the library reference manual for details. +

+ +Edit this entry / +Log info +

+ +


+

4.46. How do I copy a file?

+There's the shutil module which contains a copyfile() +function that implements a copy loop; +it isn't good enough for the Macintosh, though: +it doesn't copy the resource fork and Finder info. +

+ +Edit this entry / +Log info + +/ Last changed on Tue Jan 2 02:59:40 2001 by +Moshe Zadka +

+ +


+

4.47. How do I check if an object is an instance of a given class or of a subclass of it?

+If you are developing the classes from scratch it might be better to +program in a more proper object-oriented style -- instead of doing a different +thing based on class membership, why not use a method and define the +method differently in different classes? +

+However, there are some legitimate situations +where you need to test for class membership. +

+In Python 1.5, you can use the built-in function isinstance(obj, cls). +

+The following approaches can be used with earlier Python versions: +

+An unobvious method is to raise the object +as an exception and to try to catch the exception with the class you're +testing for: +

+

+	def is_instance_of(the_instance, the_class):
+	    try:
+		raise the_instance
+	    except the_class:
+		return 1
+	    except:
+		return 0
+
+This technique can be used to distinguish "subclassness" +from a collection of classes as well +

+

+                try:
+                              raise the_instance
+                except Audible:
+                              the_instance.play(largo)
+                except Visual:
+                              the_instance.display(gaudy)
+                except Olfactory:
+                              sniff(the_instance)
+                except:
+                              raise ValueError, "dunno what to do with this!"
+
+This uses the fact that exception catching tests for class or subclass +membership. +

+A different approach is to test for the presence of a class attribute that +is presumably unique for the given class. For instance: +

+

+	class MyClass:
+	    ThisIsMyClass = 1
+	    ...
+
+
+	def is_a_MyClass(the_instance):
+	    return hasattr(the_instance, 'ThisIsMyClass')
+
+This version is easier to inline, and probably faster (inlined it +is definitely faster). The disadvantage is that someone else could cheat: +

+

+	class IntruderClass:
+	    ThisIsMyClass = 1    # Masquerade as MyClass
+	    ...
+
+but this may be seen as a feature (anyway, there are plenty of other ways +to cheat in Python). Another disadvantage is that the class must be +prepared for the membership test. If you do not "control the +source code" for the class it may not be advisable to modify the +class to support testability. +

+ +Edit this entry / +Log info + +/ Last changed on Fri Jan 2 15:16:04 1998 by +GvR +

+ +


+

4.48. What is delegation?

+Delegation refers to an object oriented technique Python programmers +may implement with particular ease. Consider the following: +

+

+  from string import upper
+
+
+  class UpperOut:
+        def __init__(self, outfile):
+              self.__outfile = outfile
+        def write(self, str):
+              self.__outfile.write( upper(str) )
+        def __getattr__(self, name):
+              return getattr(self.__outfile, name)
+
+Here the UpperOut class redefines the write method +to convert the argument string to upper case before +calling the underlying self.__outfile.write method, but +all other methods are delegated to the underlying +self.__outfile object. The delegation is accomplished +via the "magic" __getattr__ method. Please see the +language reference for more information on the use +of this method. +

+Note that for more general cases delegation can +get trickier. Particularly when attributes must be set +as well as gotten the class must define a __settattr__ +method too, and it must do so carefully. +

+The basic implementation of __setattr__ is roughly +equivalent to the following: +

+

+   class X:
+        ...
+        def __setattr__(self, name, value):
+             self.__dict__[name] = value
+        ...
+
+Most __setattr__ implementations must modify +self.__dict__ to store local state for self without +causing an infinite recursion. +

+ +Edit this entry / +Log info + +/ Last changed on Wed Aug 13 07:11:24 1997 by +aaron watters +

+ +


+

4.49. How do I test a Python program or component.

+We presume for the purposes of this question you are interested +in standalone testing, rather than testing your components inside +a testing framework. The best-known testing framework for Python +is the PyUnit module, maintained at +

+

+    http://pyunit.sourceforge.net/
+
+For standalone testing, it helps to write the program so that +it may be easily tested by using good modular design. +In particular your program +should have almost all functionality encapsulated in either functions +or class methods -- and this sometimes has the surprising and +delightful effect of making the program run faster (because +local variable accesses are faster than global accesses). +Furthermore the program should avoid depending on mutating +global variables, since this makes testing much more difficult to do. +

+The "global main logic" of your program may be as simple +as +

+

+  if __name__=="__main__":
+       main_logic()
+
+at the bottom of the main module of your program. +

+Once your program is organized as a tractable collection +of functions and class behaviours you should write test +functions that exercise the behaviours. A test suite +can be associated with each module which automates +a sequence of tests. This sounds like a lot of work, but +since Python is so terse and flexible it's surprisingly easy. +You can make coding much more pleasant and fun by +writing your test functions in parallel with the "production +code", since this makes it easy to find bugs and even +design flaws earlier. +

+"Support modules" that are not intended to be the main +module of a program may include a "test script interpretation" +which invokes a self test of the module. +

+

+   if __name__ == "__main__":
+      self_test()
+
+Even programs that interact with complex external +interfaces may be tested when the external interfaces are +unavailable by using "fake" interfaces implemented in +Python. For an example of a "fake" interface, the following +class defines (part of) a "fake" file interface: +

+

+ import string
+ testdata = "just a random sequence of characters"
+
+
+ class FakeInputFile:
+   data = testdata
+   position = 0
+   closed = 0
+
+
+   def read(self, n=None):
+       self.testclosed()
+       p = self.position
+       if n is None:
+          result= self.data[p:]
+       else:
+          result= self.data[p: p+n]
+       self.position = p + len(result)
+       return result
+
+
+   def seek(self, n, m=0):
+       self.testclosed()
+       last = len(self.data)
+       p = self.position
+       if m==0: 
+          final=n
+       elif m==1:
+          final=n+p
+       elif m==2:
+          final=len(self.data)+n
+       else:
+          raise ValueError, "bad m"
+       if final<0:
+          raise IOError, "negative seek"
+       self.position = final
+
+
+   def isatty(self):
+       return 0
+
+
+   def tell(self):
+       return self.position
+
+
+   def close(self):
+       self.closed = 1
+
+
+   def testclosed(self):
+       if self.closed:
+          raise IOError, "file closed"
+
+Try f=FakeInputFile() and test out its operations. +

+ +Edit this entry / +Log info + +/ Last changed on Mon Jun 3 01:12:10 2002 by +Neal Norwitz +

+ +


+

4.50. My multidimensional list (array) is broken! What gives?

+You probably tried to make a multidimensional array like this. +

+

+   A = [[None] * 2] * 3
+
+This makes a list containing 3 references to the same list of length +two. Changes to one row will show in all rows, which is probably not +what you want. The following works much better: +

+

+   A = [None]*3
+   for i in range(3):
+        A[i] = [None] * 2
+
+This generates a list containing 3 different lists of length two. +

+If you feel weird, you can also do it in the following way: +

+

+   w, h = 2, 3
+   A = map(lambda i,w=w: [None] * w, range(h))
+
+For Python 2.0 the above can be spelled using a list comprehension: +

+

+   w,h = 2,3
+   A = [ [None]*w for i in range(h) ]
+
+

+ +Edit this entry / +Log info + +/ Last changed on Thu Dec 28 12:18:35 2000 by +Bjorn Pettersen +

+ +


+

4.51. I want to do a complicated sort: can you do a Schwartzian Transform in Python?

+Yes, and in Python you only have to write it once: +

+

+ def st(List, Metric):
+     def pairing(element, M = Metric):
+           return (M(element), element)
+     paired = map(pairing, List)
+     paired.sort()
+     return map(stripit, paired)
+
+
+ def stripit(pair):
+     return pair[1]
+
+This technique, attributed to Randal Schwartz, sorts the elements +of a list by a metric which maps each element to its "sort value". +For example, if L is a list of string then +

+

+   import string
+   Usorted = st(L, string.upper)
+
+
+   def intfield(s):
+         return string.atoi( string.strip(s[10:15] ) )
+
+
+   Isorted = st(L, intfield)
+
+Usorted gives the elements of L sorted as if they were upper +case, and Isorted gives the elements of L sorted by the integer +values that appear in the string slices starting at position 10 +and ending at position 15. In Python 2.0 this can be done more +naturally with list comprehensions: +

+

+  tmp1 = [ (x.upper(), x) for x in L ] # Schwartzian transform
+  tmp1.sort()
+  Usorted = [ x[1] for x in tmp1 ]
+
+
+  tmp2 = [ (int(s[10:15]), s) for s in L ] # Schwartzian transform
+  tmp2.sort()
+  Isorted = [ x[1] for x in tmp2 ]
+
+

+Note that Isorted may also be computed by +

+

+   def Icmp(s1, s2):
+         return cmp( intfield(s1), intfield(s2) )
+
+
+   Isorted = L[:]
+   Isorted.sort(Icmp)
+
+but since this method computes intfield many times for each +element of L, it is slower than the Schwartzian Transform. +

+ +Edit this entry / +Log info + +/ Last changed on Sat Jun 1 19:18:46 2002 by +Neal Norwitz +

+ +


+

4.52. How to convert between tuples and lists?

+The function tuple(seq) converts any sequence into a tuple with +the same items in the same order. +For example, tuple([1, 2, 3]) yields (1, 2, 3) and tuple('abc') +yields ('a', 'b', 'c'). If the argument is +a tuple, it does not make a copy but returns the same object, so +it is cheap to call tuple() when you aren't sure that an object +is already a tuple. +

+The function list(seq) converts any sequence into a list with +the same items in the same order. +For example, list((1, 2, 3)) yields [1, 2, 3] and list('abc') +yields ['a', 'b', 'c']. If the argument is a list, +it makes a copy just like seq[:] would. +

+ +Edit this entry / +Log info + +/ Last changed on Sun Jun 14 14:18:53 1998 by +Tim Peters +

+ +


+

4.53. Files retrieved with urllib contain leading garbage that looks like email headers.

+Extremely old versions of Python supplied libraries which +did not support HTTP/1.1; the vanilla httplib in Python 1.4 +only recognized HTTP/1.0. In Python 2.0 full HTTP/1.1 support is included. +

+ +Edit this entry / +Log info + +/ Last changed on Mon Jan 8 17:26:18 2001 by +Steve Holden +

+ +


+

4.54. How do I get a list of all instances of a given class?

+Python does not keep track of all instances of a class (or of a +built-in type). +

+You can program the class's constructor to keep track of all +instances, but unless you're very clever, this has the disadvantage +that the instances never get deleted,because your list of all +instances keeps a reference to them. +

+(The trick is to regularly inspect the reference counts of the +instances you've retained, and if the reference count is below a +certain level, remove it from the list. Determining that level is +tricky -- it's definitely larger than 1.) +

+ +Edit this entry / +Log info + +/ Last changed on Tue May 27 23:52:16 1997 by +GvR +

+ +


+

4.55. A regular expression fails with regex.error: match failure.

+This is usually caused by too much backtracking; the regular +expression engine has a fixed size stack which holds at most 4000 +backtrack points. Every character matched by e.g. ".*" accounts for a +backtrack point, so even a simple search like +

+

+  regex.match('.*x',"x"*5000)
+
+will fail. +

+This is fixed in the re module introduced with +Python 1.5; consult the Library Reference section on re for more information. +

+ +Edit this entry / +Log info + +/ Last changed on Thu Jul 30 12:35:49 1998 by +A.M. Kuchling +

+ +


+

4.56. I can't get signal handlers to work.

+The most common problem is that the signal handler is declared +with the wrong argument list. It is called as +

+

+	handler(signum, frame)
+
+so it should be declared with two arguments: +

+

+	def handler(signum, frame):
+		...
+
+

+ +Edit this entry / +Log info + +/ Last changed on Wed May 28 09:29:08 1997 by +GvR +

+ +


+

4.57. I can't use a global variable in a function? Help!

+Did you do something like this? +

+

+   x = 1 # make a global
+
+
+   def f():
+         print x # try to print the global
+         ...
+         for j in range(100):
+              if q>3:
+                 x=4
+
+Any variable assigned in a function is local to that function. +unless it is specifically declared global. Since a value is bound +to x as the last statement of the function body, the compiler +assumes that x is local. Consequently the "print x" +attempts to print an uninitialized local variable and will +trigger a NameError. +

+In such cases the solution is to insert an explicit global +declaration at the start of the function, making it +

+

+

+   def f():
+         global x
+         print x # try to print the global
+         ...
+         for j in range(100):
+              if q>3:
+                 x=4
+
+

+In this case, all references to x are interpreted as references +to the x from the module namespace. +

+ +Edit this entry / +Log info + +/ Last changed on Mon Feb 12 15:52:12 2001 by +Steve Holden +

+ +


+

4.58. What's a negative index? Why doesn't list.insert() use them?

+Python sequences are indexed with positive numbers and +negative numbers. For positive numbers 0 is the first index +1 is the second index and so forth. For negative indices -1 +is the last index and -2 is the pentultimate (next to last) index +and so forth. Think of seq[-n] as the same as seq[len(seq)-n]. +

+Using negative indices can be very convenient. For example +if the string Line ends in a newline then Line[:-1] is all of Line except +the newline. +

+Sadly the list builtin method L.insert does not observe negative +indices. This feature could be considered a mistake but since +existing programs depend on this feature it may stay around +forever. L.insert for negative indices inserts at the start of the +list. To get "proper" negative index behaviour use L[n:n] = [x] +in place of the insert method. +

+ +Edit this entry / +Log info + +/ Last changed on Wed Aug 13 07:03:18 1997 by +aaron watters +

+ +


+

4.59. How can I sort one list by values from another list?

+You can sort lists of tuples. +

+

+  >>> list1 = ["what", "I'm", "sorting", "by"]
+  >>> list2 = ["something", "else", "to", "sort"]
+  >>> pairs = map(None, list1, list2)
+  >>> pairs
+  [('what', 'something'), ("I'm", 'else'), ('sorting', 'to'), ('by', 'sort')]
+  >>> pairs.sort()
+  >>> pairs
+  [("I'm", 'else'), ('by', 'sort'), ('sorting', 'to'), ('what', 'something')]
+  >>> result = pairs[:]
+  >>> for i in xrange(len(result)): result[i] = result[i][1]
+  ...
+  >>> result
+  ['else', 'sort', 'to', 'something']
+
+And if you didn't understand the question, please see the +example above ;c). Note that "I'm" sorts before "by" because +uppercase "I" comes before lowercase "b" in the ascii order. +Also see 4.51. +

+In Python 2.0 this can be done like: +

+

+ >>> list1 = ["what", "I'm", "sorting", "by"]
+ >>> list2 = ["something", "else", "to", "sort"]
+ >>> pairs = zip(list1, list2)
+ >>> pairs
+ [('what', 'something'), ("I'm", 'else'), ('sorting', 'to'), ('by', 'sort')]
+ >>> pairs.sort()
+ >>> result = [ x[1] for x in pairs ]
+ >>> result
+ ['else', 'sort', 'to', 'something']
+
+[Followup] +

+Someone asked, why not this for the last steps: +

+

+  result = []
+  for p in pairs: result.append(p[1])
+
+This is much more legible. However, a quick test shows that +it is almost twice as slow for long lists. Why? First of all, +the append() operation has to reallocate memory, and while it +uses some tricks to avoid doing that each time, it still has +to do it occasionally, and apparently that costs quite a bit. +Second, the expression "result.append" requires an extra +attribute lookup. The attribute lookup could be done away +with by rewriting as follows: +

+

+  result = []
+  append = result.append
+  for p in pairs: append(p[1])
+
+which gains back some speed, but is still considerably slower +than the original solution, and hardly less convoluted. +

+ +Edit this entry / +Log info + +/ Last changed on Thu Dec 28 12:56:35 2000 by +Bjorn Pettersen +

+ +


+

4.60. Why doesn't dir() work on builtin types like files and lists?

+It does starting with Python 1.5. +

+Using 1.4, you can find out which methods a given object supports +by looking at its __methods__ attribute: +

+

+    >>> List = []
+    >>> List.__methods__
+    ['append', 'count', 'index', 'insert', 'remove', 'reverse', 'sort']
+
+

+ +Edit this entry / +Log info + +/ Last changed on Thu Sep 16 14:56:42 1999 by +Skip Montanaro +

+ +


+

4.61. How can I mimic CGI form submission (METHOD=POST)?

+I would like to retrieve web pages that are the result of POSTing a +form. Is there existing code that would let me do this easily? +

+Yes. Here's a simple example that uses httplib. +

+

+    #!/usr/local/bin/python
+
+
+    import httplib, sys, time
+
+
+    ### build the query string
+    qs = "First=Josephine&MI=Q&Last=Public"
+
+
+    ### connect and send the server a path
+    httpobj = httplib.HTTP('www.some-server.out-there', 80)
+    httpobj.putrequest('POST', '/cgi-bin/some-cgi-script')
+    ### now generate the rest of the HTTP headers...
+    httpobj.putheader('Accept', '*/*')
+    httpobj.putheader('Connection', 'Keep-Alive')
+    httpobj.putheader('Content-type', 'application/x-www-form-urlencoded')
+    httpobj.putheader('Content-length', '%d' % len(qs))
+    httpobj.endheaders()
+    httpobj.send(qs)
+    ### find out what the server said in response...
+    reply, msg, hdrs = httpobj.getreply()
+    if reply != 200:
+	sys.stdout.write(httpobj.getfile().read())
+
+Note that in general for "url encoded posts" (the default) query strings must be "quoted" to, for example, change equals signs and spaces to an encoded form when they occur in name or value. Use urllib.quote to perform this quoting. For example to send name="Guy Steele, Jr.": +

+

+   >>> from urllib import quote
+   >>> x = quote("Guy Steele, Jr.")
+   >>> x
+   'Guy%20Steele,%20Jr.'
+   >>> query_string = "name="+x
+   >>> query_string
+   'name=Guy%20Steele,%20Jr.'
+
+

+ +Edit this entry / +Log info + +/ Last changed on Mon Jun 21 03:47:07 1999 by +TAB +

+ +


+

4.62. If my program crashes with a bsddb (or anydbm) database open, it gets corrupted. How come?

+Databases opened for write access with the bsddb module (and often by +the anydbm module, since it will preferentially use bsddb) must +explicitly be closed using the close method of the database. The +underlying libdb package caches database contents which need to be +converted to on-disk form and written, unlike regular open files which +already have the on-disk bits in the kernel's write buffer, where they +can just be dumped by the kernel with the program exits. +

+If you have initialized a new bsddb database but not written anything to +it before the program crashes, you will often wind up with a zero-length +file and encounter an exception the next time the file is opened. +

+ +Edit this entry / +Log info + +/ Last changed on Mon Jun 3 01:15:01 2002 by +Neal Norwitz +

+ +


+

4.63. How do I make a Python script executable on Unix?

+You need to do two things: the script file's mode must be executable +(include the 'x' bit), and the first line must begin with #! +followed by the pathname for the Python interpreter. +

+The first is done by executing 'chmod +x scriptfile' or perhaps +'chmod 755 scriptfile'. +

+The second can be done in a number of way. The most straightforward +way is to write +

+

+  #!/usr/local/bin/python
+
+as the very first line of your file - or whatever the pathname is +where the python interpreter is installed on your platform. +

+If you would like the script to be independent of where the python +interpreter lives, you can use the "env" program. On almost all +platforms, the following will work, assuming the python interpreter +is in a directory on the user's $PATH: +

+

+  #! /usr/bin/env python
+
+Note -- *don't* do this for CGI scripts. The $PATH variable for +CGI scripts is often very minimal, so you need to use the actual +absolute pathname of the interpreter. +

+Occasionally, a user's environment is so full that the /usr/bin/env +program fails; or there's no env program at all. +In that case, you can try the following hack (due to Alex Rezinsky): +

+

+  #! /bin/sh
+  """:"
+  exec python $0 ${1+"$@"}
+  """
+
+The disadvantage is that this defines the script's __doc__ string. +However, you can fix that by adding +

+

+  __doc__ = """...Whatever..."""
+
+

+ +Edit this entry / +Log info + +/ Last changed on Mon Jan 15 09:19:16 2001 by +Neal Norwitz +

+ +


+

4.64. How do you remove duplicates from a list?

+See the Python Cookbook for a long discussion of many cool ways: +

+

+    http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52560
+
+Generally, if you don't mind reordering the List +

+

+   if List:
+      List.sort()
+      last = List[-1]
+      for i in range(len(List)-2, -1, -1):
+          if last==List[i]: del List[i]
+          else: last=List[i]
+
+If all elements of the list may be used as +dictionary keys (ie, they are all hashable) +this is often faster +

+

+   d = {}
+   for x in List: d[x]=x
+   List = d.values()
+
+Also, for extremely large lists you might +consider more optimal alternatives to the first one. +The second one is pretty good whenever it can +be used. +

+ +Edit this entry / +Log info + +/ Last changed on Fri May 24 21:56:33 2002 by +Tim Peters +

+ +


+

4.65. Are there any known year 2000 problems in Python?

+I am not aware of year 2000 deficiencies in Python 1.5. Python does +very few date calculations and for what it does, it relies on the C +library functions. Python generally represent times either as seconds +since 1970 or as a tuple (year, month, day, ...) where the year is +expressed with four digits, which makes Y2K bugs unlikely. So as long +as your C library is okay, Python should be okay. Of course, I cannot +vouch for your Python code! +

+Given the nature of freely available software, I have to add that this statement is not +legally binding. The Python copyright notice contains the following +disclaimer: +

+

+  STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
+  REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
+  MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
+  CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
+  DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+  PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+  TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+  PERFORMANCE OF THIS SOFTWARE.
+
+The good news is that if you encounter a problem, you have full +source available to track it down and fix it! +

+ +Edit this entry / +Log info + +/ Last changed on Fri Apr 10 14:59:31 1998 by +GvR +

+ +


+

4.66. I want a version of map that applies a method to a sequence of objects! Help!

+Get fancy! +

+

+  def method_map(objects, method, arguments):
+       """method_map([a,b], "flog", (1,2)) gives [a.flog(1,2), b.flog(1,2)]"""
+       nobjects = len(objects)
+       methods = map(getattr, objects, [method]*nobjects)
+       return map(apply, methods, [arguments]*nobjects)
+
+It's generally a good idea to get to know the mysteries of map and apply +and getattr and the other dynamic features of Python. +

+ +Edit this entry / +Log info + +/ Last changed on Mon Jan 5 14:21:14 1998 by +Aaron Watters +

+ +


+

4.67. How do I generate random numbers in Python?

+The standard library module "random" implements a random number +generator. Usage is simple: +

+

+    import random
+
+
+    random.random()
+
+This returns a random floating point number in the range [0, 1). +

+There are also many other specialized generators in this module, such +as +

+

+    randrange(a, b) chooses an integer in the range [a, b)
+    uniform(a, b) chooses a floating point number in the range [a, b)
+    normalvariate(mean, sdev) sample from normal (Gaussian) distribution
+
+Some higher-level functions operate on sequences directly, such as +

+

+    choice(S) chooses random element from a given sequence
+    shuffle(L) shuffles a list in-place, i.e. permutes it randomly
+
+There's also a class, Random, which you can instantiate +to create independent multiple random number generators. +

+All this is documented in the library reference manual. Note that +the module "whrandom" is obsolete. +

+ +Edit this entry / +Log info + +/ Last changed on Mon Jun 3 01:16:51 2002 by +Neal Norwitz +

+ +


+

4.68. How do I access the serial (RS232) port?

+There's a Windows serial communication module (for communication +over RS 232 serial ports) at +

+

+  ftp://ftp.python.org/pub/python/contrib/sio-151.zip
+  http://www.python.org/ftp/python/contrib/sio-151.zip
+
+For DOS, try Hans Nowak's Python-DX, which supports this, at: +

+

+  http://www.cuci.nl/~hnowak/
+
+For Unix, see a usenet post by Mitch Chapman: +

+

+  http://groups.google.com/groups?selm=34A04430.CF9@ohioee.com
+
+For Win32, POSIX(Linux, BSD, *), Jython, Chris': +

+

+  http://pyserial.sourceforge.net
+
+

+ +Edit this entry / +Log info + +/ Last changed on Tue Jul 2 21:11:07 2002 by +Chris Liechti +

+ +


+

4.69. Images on Tk-Buttons don't work in Py15?

+They do work, but you must keep your own reference to the image +object now. More verbosely, you must make sure that, say, a global +variable or a class attribute refers to the object. +

+Quoting Fredrik Lundh from the mailinglist: +

+

+  Well, the Tk button widget keeps a reference to the internal
+  photoimage object, but Tkinter does not.  So when the last
+  Python reference goes away, Tkinter tells Tk to release the
+  photoimage.  But since the image is in use by a widget, Tk
+  doesn't destroy it.  Not completely.  It just blanks the image,
+  making it completely transparent...
+
+
+  And yes, there was a bug in the keyword argument handling
+  in 1.4 that kept an extra reference around in some cases.  And
+  when Guido fixed that bug in 1.5, he broke quite a few Tkinter
+  programs...
+
+

+ +Edit this entry / +Log info + +/ Last changed on Tue Feb 3 11:31:03 1998 by +Case Roole +

+ +


+

4.70. Where is the math.py (socket.py, regex.py, etc.) source file?

+If you can't find a source file for a module it may be a builtin +or dynamically loaded module implemented in C, C++ or other +compiled language. In this case you may not have the source +file or it may be something like mathmodule.c, somewhere in +a C source directory (not on the Python Path). +

+Fredrik Lundh (fredrik@pythonware.com) explains (on the python-list): +

+There are (at least) three kinds of modules in Python: +1) modules written in Python (.py); +2) modules written in C and dynamically loaded (.dll, .pyd, .so, .sl, etc); +3) modules written in C and linked with the interpreter; to get a list +of these, type: +

+

+    import sys
+    print sys.builtin_module_names
+
+

+ +Edit this entry / +Log info + +/ Last changed on Tue Feb 3 13:55:33 1998 by +Aaron Watters +

+ +


+

4.71. How do I send mail from a Python script?

+The standard library module smtplib does this. +Here's a very simple interactive mail +sender that uses it. This method will work on any host that +supports an SMTP listener. +

+

+    import sys, smtplib
+
+
+    fromaddr = raw_input("From: ")
+    toaddrs  = raw_input("To: ").split(',')
+    print "Enter message, end with ^D:"
+    msg = ''
+    while 1:
+        line = sys.stdin.readline()
+        if not line:
+            break
+        msg = msg + line
+
+
+    # The actual mail send
+    server = smtplib.SMTP('localhost')
+    server.sendmail(fromaddr, toaddrs, msg)
+    server.quit()
+
+If the local host doesn't have an SMTP listener, you need to find one. The simple method is to ask the user. Alternately, you can use the DNS system to find the mail gateway(s) responsible for the source address. +

+A Unix-only alternative uses sendmail. The location of the +sendmail program varies between systems; sometimes it is +/usr/lib/sendmail, sometime /usr/sbin/sendmail. The sendmail manual +page will help you out. Here's some sample code: +

+

+  SENDMAIL = "/usr/sbin/sendmail" # sendmail location
+  import os
+  p = os.popen("%s -t -i" % SENDMAIL, "w")
+  p.write("To: cary@ratatosk.org\n")
+  p.write("Subject: test\n")
+  p.write("\n") # blank line separating headers from body
+  p.write("Some text\n")
+  p.write("some more text\n")
+  sts = p.close()
+  if sts != 0:
+      print "Sendmail exit status", sts
+
+

+ +Edit this entry / +Log info + +/ Last changed on Mon Jun 3 07:05:12 2002 by +Matthias Urlichs +

+ +


+

4.72. How do I avoid blocking in connect() of a socket?

+The select module is widely known to help with asynchronous +I/O on sockets once they are connected. However, it is less +than common knowledge how to avoid blocking on the initial +connect() call. Jeremy Hylton has the following advice (slightly +edited): +

+To prevent the TCP connect from blocking, you can set the socket to +non-blocking mode. Then when you do the connect(), you will either +connect immediately (unlikely) or get an exception that contains the +errno. errno.EINPROGRESS indicates that the connection is in +progress, but hasn't finished yet. Different OSes will return +different errnos, so you're going to have to check. I can tell you +that different versions of Solaris return different errno values. +

+In Python 1.5 and later, you can use connect_ex() to avoid +creating an exception. It will just return the errno value. +

+To poll, you can call connect_ex() again later -- 0 or errno.EISCONN +indicate that you're connected -- or you can pass this socket to +select (checking to see if it is writeable). +

+ +Edit this entry / +Log info + +/ Last changed on Tue Feb 24 21:30:45 1998 by +GvR +

+ +


+

4.73. How do I specify hexadecimal and octal integers?

+To specify an octal digit, precede the octal value with a zero. For example, +to set the variable "a" to the octal value "10" (8 in decimal), type: +

+

+    >>> a = 010
+
+To verify that this works, you can type "a" and hit enter while in the +interpreter, which will cause Python to spit out the current value of "a" +in decimal: +

+

+    >>> a
+    8
+
+Hexadecimal is just as easy. Simply precede the hexadecimal number with a +zero, and then a lower or uppercase "x". Hexadecimal digits can be specified +in lower or uppercase. For example, in the Python interpreter: +

+

+    >>> a = 0xa5
+    >>> a
+    165
+    >>> b = 0XB2
+    >>> b
+    178
+
+

+ +Edit this entry / +Log info + +/ Last changed on Tue Mar 3 12:53:16 1998 by +GvR +

+ +


+

4.74. How to get a single keypress at a time?

+For Windows, see question 8.2. Here is an answer for Unix (see also 4.94). +

+There are several solutions; some involve using curses, which is a +pretty big thing to learn. Here's a solution without curses, due +to Andrew Kuchling (adapted from code to do a PGP-style +randomness pool): +

+

+        import termios, sys, os
+        fd = sys.stdin.fileno()
+        old = termios.tcgetattr(fd)
+        new = termios.tcgetattr(fd)
+        new[3] = new[3] & ~termios.ICANON & ~termios.ECHO
+        new[6][termios.VMIN] = 1
+        new[6][termios.VTIME] = 0
+        termios.tcsetattr(fd, termios.TCSANOW, new)
+        s = ''    # We'll save the characters typed and add them to the pool.
+        try:
+            while 1:
+                c = os.read(fd, 1)
+                print "Got character", `c`
+                s = s+c
+        finally:
+            termios.tcsetattr(fd, termios.TCSAFLUSH, old)
+
+You need the termios module for any of this to work, and I've only +tried it on Linux, though it should work elsewhere. It turns off +stdin's echoing and disables canonical mode, and then reads a +character at a time from stdin, noting the time after each keystroke. +

+ +Edit this entry / +Log info + +/ Last changed on Thu Oct 24 00:36:56 2002 by +chris +

+ +


+

4.75. How can I overload constructors (or methods) in Python?

+(This actually applies to all methods, but somehow the question +usually comes up first in the context of constructors.) +

+Where in C++ you'd write +

+

+    class C {
+        C() { cout << "No arguments\n"; }
+        C(int i) { cout << "Argument is " << i << "\n"; }
+    }
+
+in Python you have to write a single constructor that catches all +cases using default arguments. For example: +

+

+    class C:
+        def __init__(self, i=None):
+            if i is None:
+                print "No arguments"
+            else:
+                print "Argument is", i
+
+This is not entirely equivalent, but close enough in practice. +

+You could also try a variable-length argument list, e.g. +

+

+        def __init__(self, *args):
+            ....
+
+The same approach works for all method definitions. +

+ +Edit this entry / +Log info + +/ Last changed on Mon Apr 20 11:55:55 1998 by +GvR +

+ +


+

4.76. How do I pass keyword arguments from one method to another?

+Use apply. For example: +

+

+    class Account:
+        def __init__(self, **kw):
+            self.accountType = kw.get('accountType')
+            self.balance = kw.get('balance')
+
+
+    class CheckingAccount(Account):
+        def __init__(self, **kw):
+            kw['accountType'] = 'checking'
+            apply(Account.__init__, (self,), kw)
+
+
+    myAccount = CheckingAccount(balance=100.00)
+
+In Python 2.0 you can call it directly using the new ** syntax: +

+

+    class CheckingAccount(Account):
+        def __init__(self, **kw):
+            kw['accountType'] = 'checking'
+            Account.__init__(self, **kw)
+
+or more generally: +

+

+ >>> def f(x, *y, **z):
+ ...  print x,y,z
+ ...
+ >>> Y = [1,2,3]
+ >>> Z = {'foo':3,'bar':None}
+ >>> f('hello', *Y, **Z)
+ hello (1, 2, 3) {'foo': 3, 'bar': None}
+
+

+ +Edit this entry / +Log info + +/ Last changed on Thu Dec 28 13:04:01 2000 by +Bjorn Pettersen +

+ +


+

4.77. What module should I use to help with generating HTML?

+Check out HTMLgen written by Robin Friedrich. It's a class library +of objects corresponding to all the HTML 3.2 markup tags. It's used +when you are writing in Python and wish to synthesize HTML pages for +generating a web or for CGI forms, etc. +

+It can be found in the FTP contrib area on python.org or on the +Starship. Use the search engines there to locate the latest version. +

+It might also be useful to consider DocumentTemplate, which offers clear +separation between Python code and HTML code. DocumentTemplate is part +of the Bobo objects publishing system (http:/www.digicool.com/releases) +but can be used independantly of course! +

+ +Edit this entry / +Log info + +/ Last changed on Fri Aug 28 09:54:58 1998 by +GvR +

+ +


+

4.78. How do I create documentation from doc strings?

+Use gendoc, by Daniel Larson. See +

+http://starship.python.net/crew/danilo/ +

+It can create HTML from the doc strings in your Python source code. +

+ +Edit this entry / +Log info + +/ Last changed on Mon Oct 7 17:15:51 2002 by +Phil Rittenhouse +

+ +


+

4.79. How do I read (or write) binary data?

+For complex data formats, it's best to use +use the struct module. It's documented in the library reference. +It allows you to take a string read from a file containing binary +data (usually numbers) and convert it to Python objects; and vice +versa. +

+For example, the following code reads two 2-byte integers +and one 4-byte integer in big-endian format from a file: +

+

+  import struct
+
+
+  f = open(filename, "rb")  # Open in binary mode for portability
+  s = f.read(8)
+  x, y, z = struct.unpack(">hhl", s)
+
+The '>' in the format string forces bin-endian data; the letter +'h' reads one "short integer" (2 bytes), and 'l' reads one +"long integer" (4 bytes) from the string. +

+For data that is more regular (e.g. a homogeneous list of ints or +floats), you can also use the array module, also documented +in the library reference. +

+ +Edit this entry / +Log info + +/ Last changed on Wed Oct 7 09:16:45 1998 by +GvR +

+ +


+

4.80. I can't get key bindings to work in Tkinter

+An oft-heard complaint is that event handlers bound to events +with the bind() method don't get handled even when the appropriate +key is pressed. +

+The most common cause is that the widget to which the binding applies +doesn't have "keyboard focus". Check out the Tk documentation +for the focus command. Usually a widget is given the keyboard +focus by clicking in it (but not for labels; see the taketocus +option). +

+ +Edit this entry / +Log info + +/ Last changed on Fri Jun 12 09:37:33 1998 by +GvR +

+ +


+

4.81. "import crypt" fails

+[Unix] +

+Starting with Python 1.5, the crypt module is disabled by default. +In order to enable it, you must go into the Python source tree and +edit the file Modules/Setup to enable it (remove a '#' sign in +front of the line starting with '#crypt'). Then rebuild. +You may also have to add the string '-lcrypt' to that same line. +

+ +Edit this entry / +Log info + +/ Last changed on Wed Aug 5 08:57:09 1998 by +GvR +

+ +


+

4.82. Are there coding standards or a style guide for Python programs?

+Yes, Guido has written the "Python Style Guide". See +http://www.python.org/doc/essays/styleguide.html +

+ +Edit this entry / +Log info + +/ Last changed on Tue Sep 29 09:50:27 1998 by +Joseph VanAndel +

+ +


+

4.83. How do I freeze Tkinter applications?

+Freeze is a tool to create stand-alone applications (see 4.28). +

+When freezing Tkinter applications, the applications will not be +truly stand-alone, as the application will still need the tcl and +tk libraries. +

+One solution is to ship the application with the tcl and tk libraries, +and point to them at run-time using the TCL_LIBRARY and TK_LIBRARY +environment variables. +

+To get truly stand-alone applications, the Tcl scripts that form +the library have to be integrated into the application as well. One +tool supporting that is SAM (stand-alone modules), which is part +of the Tix distribution (http://tix.mne.com). Build Tix with SAM +enabled, perform the appropriate call to Tclsam_init etc inside +Python's Modules/tkappinit.c, and link with libtclsam +and libtksam (you might include the Tix libraries as well). +

+ +Edit this entry / +Log info + +/ Last changed on Wed Jan 20 17:35:01 1999 by +Martin v. Löwis +

+ +


+

4.84. How do I create static class data and static class methods?

+[Tim Peters, tim_one@email.msn.com] +

+Static data (in the sense of C++ or Java) is easy; static methods (again in the sense of C++ or Java) are not supported directly. +

+STATIC DATA +

+For example, +

+

+    class C:
+        count = 0   # number of times C.__init__ called
+
+
+        def __init__(self):
+            C.count = C.count + 1
+
+
+        def getcount(self):
+            return C.count  # or return self.count
+
+c.count also refers to C.count for any c such that isinstance(c, C) holds, unless overridden by c itself or by some class on the base-class search path from c.__class__ back to C. +

+Caution: within a method of C, +

+

+    self.count = 42
+
+creates a new and unrelated instance vrbl named "count" in self's own dict. So rebinding of a class-static data name needs the +

+

+    C.count = 314
+
+form whether inside a method or not. +

+

+STATIC METHODS +

+Static methods (as opposed to static data) are unnatural in Python, because +

+

+    C.getcount
+
+returns an unbound method object, which can't be invoked without supplying an instance of C as the first argument. +

+The intended way to get the effect of a static method is via a module-level function: +

+

+    def getcount():
+        return C.count
+
+If your code is structured so as to define one class (or tightly related class hierarchy) per module, this supplies the desired encapsulation. +

+Several tortured schemes for faking static methods can be found by searching DejaNews. Most people feel such cures are worse than the disease. Perhaps the least obnoxious is due to Pekka Pessi (mailto:ppessi@hut.fi): +

+

+    # helper class to disguise function objects
+    class _static:
+        def __init__(self, f):
+            self.__call__ = f
+
+
+    class C:
+        count = 0
+
+
+        def __init__(self):
+            C.count = C.count + 1
+
+
+        def getcount():
+            return C.count
+        getcount = _static(getcount)
+
+
+        def sum(x, y):
+            return x + y
+        sum = _static(sum)
+
+
+    C(); C()
+    c = C()
+    print C.getcount()  # prints 3
+    print c.getcount()  # prints 3
+    print C.sum(27, 15) # prints 42
+
+

+ +Edit this entry / +Log info + +/ Last changed on Thu Jan 21 21:35:38 1999 by +Tim Peters +

+ +


+

4.85. __import__('x.y.z') returns <module 'x'>; how do I get z?

+Try +

+

+   __import__('x.y.z').y.z
+
+For more realistic situations, you may have to do something like +

+

+   m = __import__(s)
+   for i in string.split(s, ".")[1:]:
+       m = getattr(m, i)
+
+

+ +Edit this entry / +Log info + +/ Last changed on Thu Jan 28 11:01:43 1999 by +GvR +

+ +


+

4.86. Basic thread wisdom

+Please note that there is no way to take advantage of +multiprocessor hardware using the Python thread model. The interpreter +uses a global interpreter lock (GIL), +which does not allow multiple threads to be concurrently active. +

+If you write a simple test program like this: +

+

+  import thread
+  def run(name, n):
+      for i in range(n): print name, i
+  for i in range(10):
+      thread.start_new(run, (i, 100))
+
+none of the threads seem to run! The reason is that as soon as +the main thread exits, all threads are killed. +

+A simple fix is to add a sleep to the end of the program, +sufficiently long for all threads to finish: +

+

+  import thread, time
+  def run(name, n):
+      for i in range(n): print name, i
+  for i in range(10):
+      thread.start_new(run, (i, 100))
+  time.sleep(10) # <----------------------------!
+
+But now (on many platforms) the threads don't run in parallel, +but appear to run sequentially, one at a time! The reason is +that the OS thread scheduler doesn't start a new thread until +the previous thread is blocked. +

+A simple fix is to add a tiny sleep to the start of the run +function: +

+

+  import thread, time
+  def run(name, n):
+      time.sleep(0.001) # <---------------------!
+      for i in range(n): print name, i
+  for i in range(10):
+      thread.start_new(run, (i, 100))
+  time.sleep(10)
+
+Some more hints: +

+Instead of using a time.sleep() call at the end, it's +better to use some kind of semaphore mechanism. One idea is to +use a the Queue module to create a queue object, let each thread +append a token to the queue when it finishes, and let the main +thread read as many tokens from the queue as there are threads. +

+Use the threading module instead of the thread module. It's part +of Python since version 1.5.1. It takes care of all these details, +and has many other nice features too! +

+ +Edit this entry / +Log info + +/ Last changed on Fri Feb 7 16:21:55 2003 by +GvR +

+ +


+

4.87. Why doesn't closing sys.stdout (stdin, stderr) really close it?

+Python file objects are a high-level layer of abstraction on top of C streams, which in turn are a medium-level layer of abstraction on top of (among other things) low-level C file descriptors. +

+For most file objects f you create in Python via the builtin "open" function, f.close() marks the Python file object as being closed from Python's point of view, and also arranges to close the underlying C stream. This happens automatically too, in f's destructor, when f becomes garbage. +

+But stdin, stdout and stderr are treated specially by Python, because of the special status also given to them by C: doing +

+

+    sys.stdout.close() # ditto for stdin and stderr
+
+marks the Python-level file object as being closed, but does not close the associated C stream (provided sys.stdout is still bound to its default value, which is the stream C also calls "stdout"). +

+To close the underlying C stream for one of these three, you should first be sure that's what you really want to do (e.g., you may confuse the heck out of extension modules trying to do I/O). If it is, use os.close: +

+

+    os.close(0)   # close C's stdin stream
+    os.close(1)   # close C's stdout stream
+    os.close(2)   # close C's stderr stream
+
+

+ +Edit this entry / +Log info + +/ Last changed on Sat Apr 17 02:22:35 1999 by +Tim Peters +

+ +


+

4.88. What kinds of global value mutation are thread-safe?

+[adapted from c.l.py responses by Gordon McMillan & GvR] +

+A global interpreter lock (GIL) is used internally to ensure that only one thread runs in the Python VM at a time. In general, Python offers to switch among threads only between bytecode instructions (how frequently it offers to switch can be set via sys.setcheckinterval). Each bytecode instruction-- and all the C implementation code reached from it --is therefore atomic. +

+In theory, this means an exact accounting requires an exact understanding of the PVM bytecode implementation. In practice, it means that operations on shared vrbls of builtin data types (ints, lists, dicts, etc) that "look atomic" really are. +

+For example, these are atomic (L, L1, L2 are lists, D, D1, D2 are dicts, x, y +are objects, i, j are ints): +

+

+    L.append(x)
+    L1.extend(L2)
+    x = L[i]
+    x = L.pop()
+    L1[i:j] = L2
+    L.sort()
+    x = y
+    x.field = y
+    D[x] = y
+    D1.update(D2)
+    D.keys()
+
+These aren't: +

+

+    i = i+1
+    L.append(L[-1])
+    L[i] = L[j]
+    D[x] = D[x] + 1
+
+Note: operations that replace other objects may invoke those other objects' __del__ method when their reference count reaches zero, and that can affect things. This is especially true for the mass updates to dictionaries and lists. When in doubt, use a mutex! +

+ +Edit this entry / +Log info + +/ Last changed on Fri Feb 7 16:21:03 2003 by +GvR +

+ +


+

4.89. How do I modify a string in place?

+Strings are immutable (see question 6.2) so you cannot modify a string +directly. If you need an object with this ability, try converting the +string to a list or take a look at the array module. +

+

+    >>> s = "Hello, world"
+    >>> a = list(s)
+    >>> print a
+    ['H', 'e', 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd']
+    >>> a[7:] = list("there!")
+    >>> import string
+    >>> print string.join(a, '')
+    'Hello, there!'
+
+
+    >>> import array
+    >>> a = array.array('c', s)
+    >>> print a
+    array('c', 'Hello, world')
+    >>> a[0] = 'y' ; print a
+    array('c', 'yello world')
+    >>> a.tostring()
+    'yello, world'
+
+

+ +Edit this entry / +Log info + +/ Last changed on Tue May 18 01:22:47 1999 by +Andrew Dalke +

+ +


+

4.90. How to pass on keyword/optional parameters/arguments

+Q: How can I pass on optional or keyword parameters from one function to another? +

+

+	def f1(a, *b, **c):
+		...
+
+A: In Python 2.0 and above: +

+

+	def f2(x, *y, **z):
+		...
+		z['width']='14.3c'
+		...
+		f1(x, *y, **z)
+
+
+   Note: y can be any sequence (e.g., list or tuple) and z must be a dict.
+
+

+A: For versions prior to 2.0, use 'apply', like: +

+

+	def f2(x, *y, **z):
+		...
+		z['width']='14.3c'
+		...
+		apply(f1, (x,)+y, z)
+
+

+ +Edit this entry / +Log info + +/ Last changed on Mon Jun 3 07:20:56 2002 by +Matthias Urlichs +

+ +


+

4.91. How can I get a dictionary to display its keys in a consistent order?

+In general, dictionaries store their keys in an unpredictable order, +so the display order of a dictionary's elements will be similarly +unpredictable. +(See +Question 6.12 +to understand why this is so.) +

+This can be frustrating if you want to save a printable version to a +file, make some changes and then compare it with some other printed +dictionary. If you have such needs you can subclass UserDict.UserDict +to create a SortedDict class that prints itself in a predictable order. +Here's one simpleminded implementation of such a class: +

+

+  import UserDict, string
+
+
+  class SortedDict(UserDict.UserDict):
+    def __repr__(self):
+      result = []
+      append = result.append
+      keys = self.data.keys()
+      keys.sort()
+      for k in keys:
+        append("%s: %s" % (`k`, `self.data[k]`))
+      return "{%s}" % string.join(result, ", ")
+
+
+    ___str__ = __repr__
+
+

+This will work for many common situations you might encounter, though +it's far from a perfect solution. (It won't have any effect on the +pprint module and does not transparently handle values that are or +contain dictionaries. +

+ +Edit this entry / +Log info + +/ Last changed on Thu Sep 16 17:31:06 1999 by +Skip Montanaro +

+ +


+

4.92. Is there a Python tutorial?

+Yes. See question 1.20 at +http://www.python.org/doc/FAQ.html#1.20 +

+ +Edit this entry / +Log info + +/ Last changed on Sat Dec 4 16:04:00 1999 by +TAB +

+ +


+

4.93. Deleted

+See 4.28 +

+ +Edit this entry / +Log info + +/ Last changed on Tue May 28 20:40:37 2002 by +GvR +

+ +


+

4.94. How do I get a single keypress without blocking?

+There are several solutions; some involve using curses, which is a +pretty big thing to learn. Here's a solution without curses. (see also 4.74, for Windows, see question 8.2) +

+

+  import termios, fcntl, sys, os
+  fd = sys.stdin.fileno()
+
+
+  oldterm = termios.tcgetattr(fd)
+  newattr = termios.tcgetattr(fd)
+  newattr[3] = newattr[3] & ~termios.ICANON & ~termios.ECHO
+  termios.tcsetattr(fd, termios.TCSANOW, newattr)
+
+
+  oldflags = fcntl.fcntl(fd, fcntl.F_GETFL)
+  fcntl.fcntl(fd, fcntl.F_SETFL, oldflags | os.O_NONBLOCK)
+
+
+  try:
+      while 1:
+          try:
+              c = sys.stdin.read(1)
+              print "Got character", `c`
+          except IOError: pass
+  finally:
+      termios.tcsetattr(fd, termios.TCSAFLUSH, oldterm)
+      fcntl.fcntl(fd, fcntl.F_SETFL, oldflags)
+
+

+You need the termios and the fcntl module for any of this to work, +and I've only tried it on Linux, though it should work elsewhere. +

+In this code, characters are read and printed one at a time. +

+termios.tcsetattr() turns off stdin's echoing and disables canonical +mode. fcntl.fnctl() is used to obtain stdin's file descriptor flags +and modify them for non-blocking mode. Since reading stdin when it is +empty results in an IOError, this error is caught and ignored. +

+ +Edit this entry / +Log info + +/ Last changed on Thu Oct 24 00:39:06 2002 by +chris +

+ +


+

4.95. Is there an equivalent to Perl chomp()? (Remove trailing newline from string)

+There are two partial substitutes. If you want to remove all trailing +whitespace, use the method string.rstrip(). Otherwise, if there is only +one line in the string, use string.splitlines()[0]. +

+

+ -----------------------------------------------------------------------
+
+
+ rstrip() is too greedy, it strips all trailing white spaces.
+ splitlines() takes ControlM as line boundary.
+ Consider these strings as input:
+   "python python    \r\n"
+   "python\rpython\r\n"
+   "python python   \r\r\r\n"
+ The results from rstrip()/splitlines() are perhaps not what we want.
+
+
+ It seems re can perform this task.
+
+

+

+ #!/usr/bin/python 
+ # requires python2                                                             
+
+
+ import re, os, StringIO
+
+
+ lines=StringIO.StringIO(
+   "The Python Programming Language\r\n"
+   "The Python Programming Language \r \r \r\r\n"
+   "The\rProgramming\rLanguage\r\n"
+   "The\rProgramming\rLanguage\r\r\r\r\n"
+   "The\r\rProgramming\r\rLanguage\r\r\r\r\n"
+ )
+
+
+ ln=re.compile("(?:[\r]?\n|\r)$") # dos:\r\n, unix:\n, mac:\r, others: unknown
+ # os.linesep does not work if someone ftps(in binary mode) a dos/mac text file
+ # to your unix box
+ #ln=re.compile(os.linesep + "$")
+
+
+ while 1:
+   s=lines.readline()
+   if not s: break
+   print "1.(%s)" % `s.rstrip()`
+   print "2.(%s)" % `ln.sub( "", s, 1)`
+   print "3.(%s)" % `s.splitlines()[0]`
+   print "4.(%s)" % `s.splitlines()`
+   print
+
+
+ lines.close()
+
+

+ +Edit this entry / +Log info + +/ Last changed on Wed Aug 8 09:51:34 2001 by +Crystal +

+ +


+

4.96. Why is join() a string method when I'm really joining the elements of a (list, tuple, sequence)?

+Strings became much more like other standard types starting in release 1.6, when methods were added which give the same functionality that has always been available using the functions of the string module. These new methods have been widely accepted, but the one which appears to make (some) programmers feel uncomfortable is: +

+

+    ", ".join(['1', '2', '4', '8', '16'])
+
+which gives the result +

+

+    "1, 2, 4, 8, 16"
+
+There are two usual arguments against this usage. +

+The first runs along the lines of: "It looks really ugly using a method of a string literal (string constant)", to which the answer is that it might, but a string literal is just a fixed value. If the methods are to be allowed on names bound to strings there is no logical reason to make them unavailable on literals. Get over it! +

+The second objection is typically cast as: "I am really telling a sequence to join its members together with a string constant". Sadly, you aren't. For some reason there seems to be much less difficulty with having split() as a string method, since in that case it is easy to see that +

+

+    "1, 2, 4, 8, 16".split(", ")
+
+is an instruction to a string literal to return the substrings delimited by the given separator (or, by default, arbitrary runs of white space). In this case a Unicode string returns a list of Unicode strings, an ASCII string returns a list of ASCII strings, and everyone is happy. +

+join() is a string method because in using it you are telling the separator string to iterate over an arbitrary sequence, forming string representations of each of the elements, and inserting itself between the elements' representations. This method can be used with any argument which obeys the rules for sequence objects, inluding any new classes you might define yourself. +

+Because this is a string method it can work for Unicode strings as well as plain ASCII strings. If join() were a method of the sequence types then the sequence types would have to decide which type of string to return depending on the type of the separator. +

+If none of these arguments persuade you, then for the moment you can continue to use the join() function from the string module, which allows you to write +

+

+    string.join(['1', '2', '4', '8', '16'], ", ")
+
+You will just have to try and forget that the string module actually uses the syntax you are compaining about to implement the syntax you prefer! +

+ +Edit this entry / +Log info + +/ Last changed on Fri Aug 2 15:51:58 2002 by +Steve Holden +

+ +


+

4.97. How can my code discover the name of an object?

+Generally speaking, it can't, because objects don't really have names. The assignment statement does not store the assigned value in the name but a reference to it. Essentially, assignment creates a binding of a name to a value. The same is true of def and class statements, but in that case the value is a callable. Consider the following code: +

+

+    class A:
+        pass
+
+
+    B = A
+
+
+    a = B()
+    b = a
+    print b
+    <__main__.A instance at 016D07CC>
+    print a
+    <__main__.A instance at 016D07CC>
+
+

+Arguably the class has a name: even though it is bound to two names and invoked through the name B the created instance is still reported as an instance of class A. However, it is impossible to say whether the instance's name is a or b, since both names are bound to the same value. +

+Generally speaking it should not be necessary for your code to "know the names" of particular values. Unless you are deliberately writing introspective programs, this is usually an indication that a change of approach might be beneficial. +

+ +Edit this entry / +Log info + +/ Last changed on Thu Mar 8 03:53:39 2001 by +Steve Holden +

+ +


+

4.98. Why are floating point calculations so inaccurate?

+The development version of the Python Tutorial now contains an Appendix with more info: +
+    http://www.python.org/doc/current/tut/node14.html
+
+People are often very surprised by results like this: +

+

+ >>> 1.2-1.0
+ 0.199999999999999996
+
+And think it is a bug in Python. It's not. It's a problem caused by +the internal representation of a floating point number. A floating point +number is stored as a fixed number of binary digits. +

+In decimal math, there are many numbers that can't be represented +with a fixed number of decimal digits, i.e. +1/3 = 0.3333333333....... +

+In the binary case, 1/2 = 0.1, 1/4 = 0.01, 1/8 = 0.001, etc. There are +a lot of numbers that can't be represented. The digits are cut off at +some point. +

+Since Python 1.6, a floating point's repr() function prints as many +digits are necessary to make eval(repr(f)) == f true for any float f. +The str() function prints the more sensible number that was probably +intended: +

+

+ >>> 0.2
+ 0.20000000000000001
+ >>> print 0.2
+ 0.2
+
+Again, this has nothing to do with Python, but with the way the +underlying C platform handles floating points, and ultimately with +the inaccuracy you'll always have when writing down numbers of fixed +number of digit strings. +

+One of the consequences of this is that it is dangerous to compare +the result of some computation to a float with == ! +Tiny inaccuracies may mean that == fails. +

+Instead try something like this: +

+

+ epsilon = 0.0000000000001 # Tiny allowed error
+ expected_result = 0.4
+
+
+ if expected_result-epsilon <= computation() <= expected_result+epsilon:
+    ...
+
+

+ +Edit this entry / +Log info + +/ Last changed on Mon Apr 1 22:18:47 2002 by +Fred Drake +

+ +


+

4.99. I tried to open Berkeley DB file, but bsddb produces bsddb.error: (22, 'Invalid argument'). Help! How can I restore my data?

+Don't panic! Your data are probably intact. The most frequent cause +for the error is that you tried to open an earlier Berkeley DB file +with a later version of the Berkeley DB library. +

+Many Linux systems now have all three versions of Berkeley DB +available. If you are migrating from version 1 to a newer version use +db_dump185 to dump a plain text version of the database. +If you are migrating from version 2 to version 3 use db2_dump to create +a plain text version of the database. In either case, use db_load to +create a new native database for the latest version installed on your +computer. If you have version 3 of Berkeley DB installed, you should +be able to use db2_load to create a native version 2 database. +

+You should probably move away from Berkeley DB version 1 files because +the hash file code contains known bugs that can corrupt your data. +

+ +Edit this entry / +Log info + +/ Last changed on Wed Aug 29 16:04:29 2001 by +Skip Montanaro +

+ +


+

4.100. What are the "best practices" for using import in a module?

+First, the standard modules are great. Use them! The standard Python library is large and varied. Using modules can save you time and effort and will reduce maintainenance cost of your code. (Other programs are dedicated to supporting and fixing bugs in the standard Python modules. Coworkers may also be familiar with themodules that you use, reducing the amount of time it takes them to understand your code.) +

+The rest of this answer is largely a matter of personal preference, but here's what some newsgroup posters said (thanks to all who responded) +

+In general, don't use +

+ from modulename import *
+
+Doing so clutters the importer's namespace. Some avoid this idiom even with the few modules that were designed to be imported in this manner. (Modules designed in this manner include Tkinter, thread, and wxPython.) +

+Import modules at the top of a file, one module per line. Doing so makes it clear what other modules your code requires and avoids questions of whether the module name is in scope. Using one import per line makes it easy to add and delete module imports. +

+Move imports into a local scope (such as at the top of a function definition) if there are a lot of imports, and you're trying to avoid the cost (lots of initialization time) of many imports. This technique is especially helpful if many of the imports are unnecessary depending on how the program executes. You may also want to move imports into a function if the modules are only ever used in that function. Note that loading a module the first time may be expensive (because of the one time initialization of the module) but that loading a module multiple times is virtually free (a couple of dictionary lookups). Even if the module name has gone out of scope, the module is probably available in sys.modules. Thus, there isn't really anything wrong with putting no imports at the module level (if they aren't needed) and putting all of the imports at the function level. +

+It is sometimes necessary to move imports to a function or class to avoid problems with circular imports. Gordon says: +

+ Circular imports are fine where both modules use the "import <module>"
+ form of import. They fail when the 2nd module wants to grab a name
+ out of the first ("from module import name") and the import is at
+ the top level. That's because names in the 1st are not yet available,
+ (the first module is busy importing the 2nd).  
+
+In this case, if the 2nd module is only used in one function, then the import can easily be moved into that function. By the time the import is called, the first module will have finished initializing, and the second module can do its import. +

+It may also be necessary to move imports out of the top level of code +if some of the modules are platform-specific. In that case, it may not even be possible to import all of the modules at the top of the file. In this case, importing the correct modules in the corresponding platform-specific code is a good option. +

+If only instances of a specific class uses a module, then it is reasonable to import the module in the class's __init__ method and then assign the module to an instance variable so that the module is always available (via that instance variable) during the life of the object. Note that to delay an import until the class is instantiated, the import must be inside a method. Putting the import inside the class but outside of any method still causes the import to occur when the module is initialized. +

+ +Edit this entry / +Log info + +/ Last changed on Sat Aug 4 04:44:47 2001 by +TAB +

+ +


+

4.101. Is there a tool to help find bugs or perform static analysis?

+Yes. PyChecker is a static analysis tool for finding bugs +in Python source code as well as warning about code complexity +and style. +

+You can get PyChecker from: http://pychecker.sf.net. +

+ +Edit this entry / +Log info + +/ Last changed on Fri Aug 10 15:42:11 2001 by +Neal +

+ +


+

4.102. UnicodeError: ASCII [decoding,encoding] error: ordinal not in range(128)

+This error indicates that your Python installation can handle +only 7-bit ASCII strings. There are a couple ways to fix or +workaround the problem. +

+If your programs must handle data in arbitary character set encodings, the environment the application runs in will generally identify the encoding of the data it is handing you. You need to convert the input to Unicode data using that encoding. For instance, a program that handles email or web input will typically find character set encoding information in Content-Type headers. This can then be used to properly convert input data to Unicode. Assuming the string referred to by "value" is encoded as UTF-8: +

+

+    value = unicode(value, "utf-8")
+
+will return a Unicode object. If the data is not correctly encoded as UTF-8, the above call will raise a UnicodeError. +

+If you only want strings coverted to Unicode which have non-ASCII data, you can try converting them first assuming an ASCII encoding, and then generate Unicode objects if that fails: +

+

+    try:
+        x = unicode(value, "ascii")
+    except UnicodeError:
+        value = unicode(value, "utf-8")
+    else:
+        # value was valid ASCII data
+        pass
+
+

+If you normally use a character set encoding other than US-ASCII and only need to handle data in that encoding, the simplest way to fix the problem may be simply to set the encoding in sitecustomize.py. The following code is just a modified version of the encoding setup code from site.py with the relevant lines uncommented. +

+

+    # Set the string encoding used by the Unicode implementation.
+    # The default is 'ascii'
+    encoding = "ascii" # <= CHANGE THIS if you wish
+
+
+    # Enable to support locale aware default string encodings.
+    import locale
+    loc = locale.getdefaultlocale()
+    if loc[1]:
+        encoding = loc[1]
+    if encoding != "ascii":
+        import sys
+        sys.setdefaultencoding(encoding)
+
+

+Also note that on Windows, there is an encoding known as "mbcs", which uses an encoding specific to your current locale. In many cases, and particularly when working with COM, this may be an appropriate default encoding to use. +

+ +Edit this entry / +Log info + +/ Last changed on Sat Apr 13 04:45:41 2002 by +Skip Montanaro +

+ +


+

4.103. Using strings to call functions/methods

+There are various techniques: +

+* Use a dictionary pre-loaded with strings and functions. The primary +advantage of this technique is that the strings do not need to match the +names of the functions. This is also the primary technique used to +emulate a case construct: +

+

+    def a():
+        pass
+
+
+    def b():
+        pass
+
+
+    dispatch = {'go': a, 'stop': b}  # Note lack of parens for funcs
+
+
+    dispatch[get_input()]()  # Note trailing parens to call function
+
+* Use the built-in function getattr(): +

+

+    import foo
+    getattr(foo, 'bar')()
+
+Note that getattr() works on any object, including classes, class +instances, modules, and so on. +

+This is used in several places in the standard library, like +this: +

+

+    class Foo:
+        def do_foo(self):
+            ...
+
+
+        def do_bar(self):
+            ...
+
+
+     f = getattr(foo_instance, 'do_' + opname)
+     f()
+
+

+* Use locals() or eval() to resolve the function name: +

+def myFunc(): +

+    print "hello"
+
+fname = "myFunc" +

+f = locals()[fname] +f() +

+f = eval(fname) +f() +

+Note: Using eval() can be dangerous. If you don't have absolute control +over the contents of the string, all sorts of things could happen... +

+ +Edit this entry / +Log info + +/ Last changed on Thu Mar 21 08:14:58 2002 by +Erno Kuusela +

+ +


+

4.104. How fast are exceptions?

+A try/except block is extremely efficient. Actually executing an +exception is expensive. In older versions of Python (prior to 2.0), it +was common to code this idiom: +

+

+    try:
+        value = dict[key]
+    except KeyError:
+        dict[key] = getvalue(key)
+        value = dict[key]
+
+This idiom only made sense when you expected the dict to have the key +95% of the time or more; other times, you coded it like this: +

+

+    if dict.has_key(key):
+        value = dict[key]
+    else:
+        dict[key] = getvalue(key)
+        value = dict[key]
+
+In Python 2.0 and higher, of course, you can code this as +

+

+    value = dict.setdefault(key, getvalue(key))
+
+However this evaluates getvalue(key) always, regardless of whether it's needed or not. So if it's slow or has a side effect you should use one of the above variants. +

+ +Edit this entry / +Log info + +/ Last changed on Mon Dec 9 10:12:30 2002 by +Yeti +

+ +


+

4.105. Sharing global variables across modules

+The canonical way to share information across modules within a single +program is to create a special module (often called config or cfg). +Just import the config module in all modules of your application; the +module then becomes available as a global name. Because there is only +one instance of each module, any changes made to the module object get +reflected everywhere. For example: +

+config.py: +

+

+    pass
+
+mod.py: +

+

+    import config
+    config.x = 1
+
+main.py: +

+

+    import config
+    import mod
+    print config.x
+
+Note that using a module is also the basis for implementing the +Singleton design pattern, for the same reason. +

+ +Edit this entry / +Log info + +/ Last changed on Tue Apr 23 23:07:19 2002 by +Aahz +

+ +


+

4.106. Why is cPickle so slow?

+Use the binary option. We'd like to make that the default, but it would +break backward compatibility: +

+

+    largeString = 'z' * (100 * 1024)
+    myPickle = cPickle.dumps(largeString, 1)
+
+

+ +Edit this entry / +Log info + +/ Last changed on Thu Aug 22 19:54:25 2002 by +Aahz +

+ +


+

4.107. When importing module XXX, why do I get "undefined symbol: PyUnicodeUCS2_..." ?

+You are using a version of Python that uses a 4-byte representation for +Unicode characters, but the extension module you are importing (possibly +indirectly) was compiled using a Python that uses a 2-byte representation +for Unicode characters (the default). +

+If instead the name of the undefined symbol starts with PyUnicodeUCS4_, +the problem is the same by the relationship is reversed: Python was +built using 2-byte Unicode characters, and the extension module was +compiled using a Python with 4-byte Unicode characters. +

+This can easily occur when using pre-built extension packages. RedHat +Linux 7.x, in particular, provides a "python2" binary that is compiled +with 4-byte Unicode. This only causes the link failure if the extension +uses any of the PyUnicode_*() functions. It is also a problem if if an +extension uses any of the Unicode-related format specifiers for +Py_BuildValue (or similar) or parameter-specifications for +PyArg_ParseTuple(). +

+You can check the size of the Unicode character a Python interpreter is +using by checking the value of sys.maxunicode: +

+

+  >>> import sys
+  >>> if sys.maxunicode > 65535:
+  ...     print 'UCS4 build'
+  ... else:
+  ...     print 'UCS2 build'
+
+The only way to solve this problem is to use extension modules compiled +with a Python binary built using the same size for Unicode characters. +

+ +Edit this entry / +Log info + +/ Last changed on Tue Aug 27 15:00:17 2002 by +Fred Drake +

+ +


+

4.108. How do I create a .pyc file?

+QUESTION: +

+I have a module and I wish to generate a .pyc file. +How do I do it? Everything I read says that generation of a .pyc file is +"automatic", but I'm not getting anywhere. +

+

+ANSWER: +

+When a module is imported for the first time (or when the source is more +recent than the current compiled file) a .pyc file containing the compiled code should be created in the +same directory as the .py file. +

+One reason that a .pyc file may not be created is permissions problems with the directory. This can happen, for example, if you develop as one user but run as another, such as if you are testing with a web server. +

+However, in most cases, that's not the problem. +

+Creation of a .pyc file is "automatic" if you are importing a module and Python has the +ability (permissions, free space, etc...) to write the compiled module +back to the directory. But note that running Python on a top level script is not considered an +import and so no .pyc will be created automatically. For example, if you have a top-level module abc.py that imports another module xyz.py, when you run abc, xyz.pyc will be created since xyz is imported, but no abc.pyc file will be created since abc isn't imported. +

+If you need to create abc.pyc -- that is, to create a .pyc file for a +module that is not imported -- you can. (Look up +the py_compile and compileall modules in the Library Reference.) +

+You can manually compile any module using the "py_compile" module. One +way is to use the compile() function in that module interactively: +

+

+    >>> import py_compile
+    >>> py_compile.compile('abc.py')
+
+This will write the .pyc to the same location as abc.py (or you +can override that with the optional parameter cfile). +

+You can also automatically compile all files in a directory or +directories using the "compileall" module, which can also be run +straight from the command line. +

+You can do it from the shell (or DOS) prompt by entering: +

+       python compile.py abc.py
+
+or +
+       python compile.py *
+
+Or you can write a script to do it on a list of filenames that you enter. +

+

+     import sys
+     from py_compile import compile
+
+
+     if len(sys.argv) <= 1:
+        sys.exit(1)
+
+
+     for file in sys.argv[1:]:
+        compile(file)
+
+ACKNOWLEDGMENTS: +

+Steve Holden, David Bolen, Rich Somerfield, Oleg Broytmann, Steve Ferg +

+ +Edit this entry / +Log info + +/ Last changed on Wed Feb 12 15:58:25 2003 by +Stephen Ferg +

+ +


+

5. Extending Python

+ +
+

5.1. Can I create my own functions in C?

+Yes, you can create built-in modules containing functions, +variables, exceptions and even new types in C. This is explained in +the document "Extending and Embedding the Python Interpreter" (http://www.python.org/doc/current/ext/ext.html). Also read the chapter +on dynamic loading. +

+There's more information on this in each of the Python books: +Programming Python, Internet Programming with Python, and Das Python-Buch +(in German). +

+ +Edit this entry / +Log info + +/ Last changed on Mon Dec 10 05:18:57 2001 by +Fred L. Drake, Jr. +

+ +


+

5.2. Can I create my own functions in C++?

+Yes, using the C-compatibility features found in C++. Basically +you place extern "C" { ... } around the Python include files and put +extern "C" before each function that is going to be called by the +Python interpreter. Global or static C++ objects with constructors +are probably not a good idea. +

+ +Edit this entry / +Log info +

+ +


+

5.3. How can I execute arbitrary Python statements from C?

+The highest-level function to do this is PyRun_SimpleString() which takes +a single string argument which is executed in the context of module +__main__ and returns 0 for success and -1 when an exception occurred +(including SyntaxError). If you want more control, use PyRun_String(); +see the source for PyRun_SimpleString() in Python/pythonrun.c. +

+ +Edit this entry / +Log info + +/ Last changed on Fri May 23 20:08:14 1997 by +Bill Tutt +

+ +


+

5.4. How can I evaluate an arbitrary Python expression from C?

+Call the function PyRun_String() from the previous question with the +start symbol eval_input (Py_eval_input starting with 1.5a1); it +parses an expression, evaluates it and returns its value. +

+ +Edit this entry / +Log info + +/ Last changed on Wed May 21 22:23:18 1997 by +David Ascher +

+ +


+

5.5. How do I extract C values from a Python object?

+That depends on the object's type. If it's a tuple, +PyTupleSize(o) returns its length and PyTuple_GetItem(o, i) +returns its i'th item; similar for lists with PyListSize(o) +and PyList_GetItem(o, i). For strings, PyString_Size(o) returns +its length and PyString_AsString(o) a pointer to its value +(note that Python strings may contain null bytes so strlen() +is not safe). To test which type an object is, first make sure +it isn't NULL, and then use PyString_Check(o), PyTuple_Check(o), +PyList_Check(o), etc. +

+There is also a high-level API to Python objects which is +provided by the so-called 'abstract' interface -- read +Include/abstract.h for further details. It allows for example +interfacing with any kind of Python sequence (e.g. lists and tuples) +using calls like PySequence_Length(), PySequence_GetItem(), etc.) +as well as many other useful protocols. +

+ +Edit this entry / +Log info + +/ Last changed on Wed May 21 22:34:20 1997 by +David Ascher +

+ +


+

5.6. How do I use Py_BuildValue() to create a tuple of arbitrary length?

+You can't. Use t = PyTuple_New(n) instead, and fill it with +objects using PyTuple_SetItem(t, i, o) -- note that this "eats" a +reference count of o. Similar for lists with PyList_New(n) and +PyList_SetItem(l, i, o). Note that you must set all the tuple items to +some value before you pass the tuple to Python code -- +PyTuple_New(n) initializes them to NULL, which isn't a valid Python +value. +

+ +Edit this entry / +Log info + +/ Last changed on Thu Jul 31 18:15:29 1997 by +Guido van Rossum +

+ +


+

5.7. How do I call an object's method from C?

+The PyObject_CallMethod() function can be used to call an arbitrary +method of an object. The parameters are the object, the name of the +method to call, a format string like that used with Py_BuildValue(), and the argument values: +

+

+    PyObject *
+    PyObject_CallMethod(PyObject *object, char *method_name,
+                        char *arg_format, ...);
+
+This works for any object that has methods -- whether built-in or +user-defined. You are responsible for eventually DECREF'ing the +return value. +

+To call, e.g., a file object's "seek" method with arguments 10, 0 +(assuming the file object pointer is "f"): +

+

+        res = PyObject_CallMethod(f, "seek", "(ii)", 10, 0);
+        if (res == NULL) {
+                ... an exception occurred ...
+        }
+        else {
+                Py_DECREF(res);
+        }
+
+Note that since PyObject_CallObject() always wants a tuple for the +argument list, to call a function without arguments, pass "()" for the +format, and to call a function with one argument, surround the argument +in parentheses, e.g. "(i)". +

+ +Edit this entry / +Log info + +/ Last changed on Thu Jun 6 16:15:46 2002 by +Neal Norwitz +

+ +


+

5.8. How do I catch the output from PyErr_Print() (or anything that prints to stdout/stderr)?

+(Due to Mark Hammond): +

+In Python code, define an object that supports the "write()" method. +Redirect sys.stdout and sys.stderr to this object. +Call print_error, or just allow the standard traceback mechanism to +work. Then, the output will go wherever your write() method sends it. +

+The easiest way to do this is to use the StringIO class in the standard +library. +

+Sample code and use for catching stdout: +

+	>>> class StdoutCatcher:
+	...  def __init__(self):
+	...   self.data = ''
+	...  def write(self, stuff):
+	...   self.data = self.data + stuff
+	...  
+	>>> import sys
+	>>> sys.stdout = StdoutCatcher()
+	>>> print 'foo'
+	>>> print 'hello world!'
+	>>> sys.stderr.write(sys.stdout.data)
+	foo
+	hello world!
+
+

+ +Edit this entry / +Log info + +/ Last changed on Wed Dec 16 18:34:25 1998 by +Richard Jones +

+ +


+

5.9. How do I access a module written in Python from C?

+You can get a pointer to the module object as follows: +

+

+        module = PyImport_ImportModule("<modulename>");
+
+If the module hasn't been imported yet (i.e. it is not yet present in +sys.modules), this initializes the module; otherwise it simply returns +the value of sys.modules["<modulename>"]. Note that it doesn't enter +the module into any namespace -- it only ensures it has been +initialized and is stored in sys.modules. +

+You can then access the module's attributes (i.e. any name defined in +the module) as follows: +

+

+        attr = PyObject_GetAttrString(module, "<attrname>");
+
+Calling PyObject_SetAttrString(), to assign to variables in the module, also works. +

+ +Edit this entry / +Log info + +/ Last changed on Wed May 21 22:56:40 1997 by +david ascher +

+ +


+

5.10. How do I interface to C++ objects from Python?

+Depending on your requirements, there are many approaches. To do +this manually, begin by reading the "Extending and Embedding" document +(Doc/ext.tex, see also http://www.python.org/doc/). Realize +that for the Python run-time system, there isn't a whole lot of +difference between C and C++ -- so the strategy to build a new Python +type around a C structure (pointer) type will also work for C++ +objects. +

+A useful automated approach (which also works for C) is SWIG: +http://www.swig.org/. +

+ +Edit this entry / +Log info + +/ Last changed on Fri Oct 15 05:14:01 1999 by +Sjoerd Mullender +

+ +


+

5.11. mSQLmodule (or other old module) won't build with Python 1.5 (or later)

+Since python-1.4 "Python.h" will have the file includes needed in an +extension module. +Backward compatibility is dropped after version 1.4 and therefore +mSQLmodule.c will not build as "allobjects.h" cannot be found. +The following change in mSQLmodule.c is harmless when building it with +1.4 and necessary when doing so for later python versions: +

+Remove lines: +

+

+	#include "allobjects.h"
+	#include "modsupport.h"
+
+And insert instead: +

+

+	#include "Python.h"
+
+You may also need to add +

+

+                #include "rename2.h"
+
+if the module uses "old names". +

+This may happen with other ancient python modules as well, +and the same fix applies. +

+ +Edit this entry / +Log info + +/ Last changed on Sun Dec 21 02:03:35 1997 by +GvR +

+ +


+

5.12. I added a module using the Setup file and the make fails! Huh?

+Setup must end in a newline, if there is no newline there it gets +very sad. Aside from this possibility, maybe you have other +non-Python-specific linkage problems. +

+ +Edit this entry / +Log info + +/ Last changed on Tue Jun 24 15:54:01 1997 by +aaron watters +

+ +


+

5.13. I want to compile a Python module on my Red Hat Linux system, but some files are missing.

+Red Hat's RPM for Python doesn't include the +/usr/lib/python1.x/config/ directory, which contains various files required +for compiling Python extensions. +Install the python-devel RPM to get the necessary files. +

+ +Edit this entry / +Log info + +/ Last changed on Tue Jan 26 13:44:04 1999 by +A.M. Kuchling +

+ +


+

5.14. What does "SystemError: _PyImport_FixupExtension: module yourmodule not loaded" mean?

+This means that you have created an extension module named "yourmodule", but your module init function does not initialize with that name. +

+Every module init function will have a line similar to: +

+

+  module = Py_InitModule("yourmodule", yourmodule_functions);
+
+If the string passed to this function is not the same name as your extenion module, the SystemError will be raised. +

+ +Edit this entry / +Log info + +/ Last changed on Thu Mar 25 07:16:08 1999 by +Mark Hammond +

+ +


+

5.15. How to tell "incomplete input" from "invalid input"?

+Sometimes you want to emulate the Python interactive interpreter's +behavior, where it gives you a continuation prompt when the input +is incomplete (e.g. you typed the start of an "if" statement +or you didn't close your parentheses or triple string quotes), +but it gives you a syntax error message immediately when the input +is invalid. +

+In Python you can use the codeop module, which approximates the +parser's behavior sufficiently. IDLE uses this, for example. +

+The easiest way to do it in C is to call PyRun_InteractiveLoop() +(in a separate thread maybe) and let the Python interpreter handle +the input for you. You can also set the PyOS_ReadlineFunctionPointer +to point at your custom input function. See Modules/readline.c and +Parser/myreadline.c for more hints. +

+However sometimes you have to run the embedded Python interpreter +in the same thread as your rest application and you can't allow the +PyRun_InteractiveLoop() to stop while waiting for user input. +The one solution then is to call PyParser_ParseString() +and test for e.error equal to E_EOF (then the input is incomplete). +Sample code fragment, untested, inspired by code from Alex Farber: +

+

+  #include <Python.h>
+  #include <node.h>
+  #include <errcode.h>
+  #include <grammar.h>
+  #include <parsetok.h>
+  #include <compile.h>
+
+
+  int testcomplete(char *code)
+    /* code should end in \n */
+    /* return -1 for error, 0 for incomplete, 1 for complete */
+  {
+    node *n;
+    perrdetail e;
+
+
+    n = PyParser_ParseString(code, &_PyParser_Grammar,
+                             Py_file_input, &e);
+    if (n == NULL) {
+      if (e.error == E_EOF) 
+        return 0;
+      return -1;
+    }
+
+
+    PyNode_Free(n);
+    return 1;
+  }
+
+Another solution is trying to compile the received string with +Py_CompileString(). If it compiles fine - try to execute the returned +code object by calling PyEval_EvalCode(). Otherwise save the input for +later. If the compilation fails, find out if it's an error or just +more input is required - by extracting the message string from the +exception tuple and comparing it to the "unexpected EOF while parsing". +Here is a complete example using the GNU readline library (you may +want to ignore SIGINT while calling readline()): +

+

+  #include <stdio.h>
+  #include <readline.h>
+
+
+  #include <Python.h>
+  #include <object.h>
+  #include <compile.h>
+  #include <eval.h>
+
+
+  int main (int argc, char* argv[])
+  {
+    int i, j, done = 0;                          /* lengths of line, code */
+    char ps1[] = ">>> ";
+    char ps2[] = "... ";
+    char *prompt = ps1;
+    char *msg, *line, *code = NULL;
+    PyObject *src, *glb, *loc;
+    PyObject *exc, *val, *trb, *obj, *dum;
+
+
+    Py_Initialize ();
+    loc = PyDict_New ();
+    glb = PyDict_New ();
+    PyDict_SetItemString (glb, "__builtins__", PyEval_GetBuiltins ());
+
+
+    while (!done)
+    {
+      line = readline (prompt);
+
+
+      if (NULL == line)                          /* CTRL-D pressed */
+      {
+        done = 1;
+      }
+      else
+      {
+        i = strlen (line);
+
+
+        if (i > 0)
+          add_history (line);                    /* save non-empty lines */
+
+
+        if (NULL == code)                        /* nothing in code yet */
+          j = 0;
+        else
+          j = strlen (code);
+
+
+        code = realloc (code, i + j + 2);
+        if (NULL == code)                        /* out of memory */
+          exit (1);
+
+
+        if (0 == j)                              /* code was empty, so */
+          code[0] = '\0';                        /* keep strncat happy */
+
+
+        strncat (code, line, i);                 /* append line to code */
+        code[i + j] = '\n';                      /* append '\n' to code */
+        code[i + j + 1] = '\0';
+
+
+        src = Py_CompileString (code, "<stdin>", Py_single_input);       
+
+
+        if (NULL != src)                         /* compiled just fine - */
+        {
+          if (ps1  == prompt ||                  /* ">>> " or */
+              '\n' == code[i + j - 1])           /* "... " and double '\n' */
+          {                                               /* so execute it */
+            dum = PyEval_EvalCode ((PyCodeObject *)src, glb, loc);
+            Py_XDECREF (dum);
+            Py_XDECREF (src);
+            free (code);
+            code = NULL;
+            if (PyErr_Occurred ())
+              PyErr_Print ();
+            prompt = ps1;
+          }
+        }                                        /* syntax error or E_EOF? */
+        else if (PyErr_ExceptionMatches (PyExc_SyntaxError))           
+        {
+          PyErr_Fetch (&exc, &val, &trb);        /* clears exception! */
+
+
+          if (PyArg_ParseTuple (val, "sO", &msg, &obj) &&
+              !strcmp (msg, "unexpected EOF while parsing")) /* E_EOF */
+          {
+            Py_XDECREF (exc);
+            Py_XDECREF (val);
+            Py_XDECREF (trb);
+            prompt = ps2;
+          }
+          else                                   /* some other syntax error */
+          {
+            PyErr_Restore (exc, val, trb);
+            PyErr_Print ();
+            free (code);
+            code = NULL;
+            prompt = ps1;
+          }
+        }
+        else                                     /* some non-syntax error */
+        {
+          PyErr_Print ();
+          free (code);
+          code = NULL;
+          prompt = ps1;
+        }
+
+
+        free (line);
+      }
+    }
+
+
+    Py_XDECREF(glb);
+    Py_XDECREF(loc);
+    Py_Finalize();
+    exit(0);
+  }
+
+

+ +Edit this entry / +Log info + +/ Last changed on Wed Mar 15 09:47:24 2000 by +Alex Farber +

+ +


+

5.16. How do I debug an extension?

+When using gdb with dynamically loaded extensions, you can't set a +breakpoint in your extension until your extension is loaded. +

+In your .gdbinit file (or interactively), add the command +

+br _PyImport_LoadDynamicModule +

+

+$ gdb /local/bin/python +

+gdb) run myscript.py +

+gdb) continue # repeat until your extension is loaded +

+gdb) finish # so that your extension is loaded +

+gdb) br myfunction.c:50 +

+gdb) continue +

+ +Edit this entry / +Log info + +/ Last changed on Fri Oct 20 11:10:32 2000 by +Joe VanAndel +

+ +


+

5.17. How do I find undefined Linux g++ symbols, __builtin_new or __pure_virtural

+To dynamically load g++ extension modules, you must recompile python, relink python using g++ (change LINKCC in the python Modules Makefile), and link your extension module using g++ (e.g., "g++ -shared -o mymodule.so mymodule.o"). +

+ +Edit this entry / +Log info + +/ Last changed on Sun Jan 14 18:03:51 2001 by +douglas orr +

+ +


+

5.18. How do I define and create objects corresponding to built-in/extension types

+Usually you would like to be able to inherit from a Python type when +you ask this question. The bottom line for Python 2.2 is: types and classes are miscible. You build instances by calling classes, and you can build subclasses to your heart's desire. +

+You need to be careful when instantiating immutable types like integers or strings. See http://www.amk.ca/python/2.2/, section 2, for details. +

+Prior to version 2.2, Python (like Java) insisted that there are first-class and second-class objects (the former are types, the latter classes), and never the twain shall meet. +

+The library has, however, done a good job of providing class wrappers for the more commonly desired objects (see UserDict, UserList and UserString for examples), and more are always welcome if you happen to be in the mood to write code. These wrappers still exist in Python 2.2. +

+ +Edit this entry / +Log info + +/ Last changed on Mon Jun 10 15:14:07 2002 by +Matthias Urlichs +

+ +


+

6. Python's design

+ +
+

6.1. Why isn't there a switch or case statement in Python?

+You can do this easily enough with a sequence of +if... elif... elif... else. There have been some proposals for switch +statement syntax, but there is no consensus (yet) on whether and how +to do range tests. +

+ +Edit this entry / +Log info +

+ +


+

6.2. Why does Python use indentation for grouping of statements?

+Basically I believe that using indentation for grouping is +extremely elegant and contributes a lot to the clarity of the average +Python program. Most people learn to love this feature after a while. +Some arguments for it: +

+Since there are no begin/end brackets there cannot be a disagreement +between grouping perceived by the parser and the human reader. I +remember long ago seeing a C fragment like this: +

+

+        if (x <= y)
+                x++;
+                y--;
+        z++;
+
+and staring a long time at it wondering why y was being decremented +even for x > y... (And I wasn't a C newbie then either.) +

+Since there are no begin/end brackets, Python is much less prone to +coding-style conflicts. In C there are loads of different ways to +place the braces (including the choice whether to place braces around +single statements in certain cases, for consistency). If you're used +to reading (and writing) code that uses one style, you will feel at +least slightly uneasy when reading (or being required to write) +another style. +Many coding styles place begin/end brackets on a line by themself. +This makes programs considerably longer and wastes valuable screen +space, making it harder to get a good overview over a program. +Ideally, a function should fit on one basic tty screen (say, 20 +lines). 20 lines of Python are worth a LOT more than 20 lines of C. +This is not solely due to the lack of begin/end brackets (the lack of +declarations also helps, and the powerful operations of course), but +it certainly helps! +

+ +Edit this entry / +Log info + +/ Last changed on Wed May 21 16:00:15 1997 by +GvR +

+ +


+

6.3. Why are Python strings immutable?

+There are two advantages. One is performance: knowing that a +string is immutable makes it easy to lay it out at construction time +-- fixed and unchanging storage requirements. (This is also one of +the reasons for the distinction between tuples and lists.) The +other is that strings in Python are considered as "elemental" as +numbers. No amount of activity will change the value 8 to anything +else, and in Python, no amount of activity will change the string +"eight" to anything else. (Adapted from Jim Roskind) +

+ +Edit this entry / +Log info +

+ +


+

6.4. Delete

+

+

+ +Edit this entry / +Log info + +/ Last changed on Tue Jan 2 03:05:25 2001 by +Moshe Zadka +

+ +


+

6.5. Why does Python use methods for some functionality (e.g. list.index()) but functions for other (e.g. len(list))?

+The major reason is history. Functions were used for those +operations that were generic for a group of types and which +were intended to work even for objects that didn't have +methods at all (e.g. numbers before type/class unification +began, or tuples). +

+It is also convenient to have a function that can readily be applied +to an amorphous collection of objects when you use the functional features of Python (map(), apply() et al). +

+In fact, implementing len(), max(), min() as a built-in function is +actually less code than implementing them as methods for each type. +One can quibble about individual cases but it's a part of Python, +and it's too late to change such things fundamentally now. The +functions have to remain to avoid massive code breakage. +

+Note that for string operations Python has moved from external functions +(the string module) to methods. However, len() is still a function. +

+ +Edit this entry / +Log info + +/ Last changed on Thu May 30 14:08:58 2002 by +Steve Holden +

+ +


+

6.6. Why can't I derive a class from built-in types (e.g. lists or files)?

+As of Python 2.2, you can derive from built-in types. For previous versions, the answer is: +

+This is caused by the relatively late addition of (user-defined) +classes to the language -- the implementation framework doesn't easily +allow it. See the answer to question 4.2 for a work-around. This +may be fixed in the (distant) future. +

+ +Edit this entry / +Log info + +/ Last changed on Thu May 23 02:53:22 2002 by +Neal Norwitz +

+ +


+

6.7. Why must 'self' be declared and used explicitly in method definitions and calls?

+So, is your current programming language C++ or Java? :-) +When classes were added to Python, this was (again) the simplest way of +implementing methods without too many changes to the interpreter. The +idea was borrowed from Modula-3. It turns out to be very useful, for +a variety of reasons. +

+First, it makes it more obvious that you are using a method or +instance attribute instead of a local variable. Reading "self.x" or +"self.meth()" makes it absolutely clear that an instance variable or +method is used even if you don't know the class definition by heart. +In C++, you can sort of tell by the lack of a local variable +declaration (assuming globals are rare or easily recognizable) -- but +in Python, there are no local variable declarations, so you'd have to +look up the class definition to be sure. +

+Second, it means that no special syntax is necessary if you want to +explicitly reference or call the method from a particular class. In +C++, if you want to use a method from base class that is overridden in +a derived class, you have to use the :: operator -- in Python you can +write baseclass.methodname(self, <argument list>). This is +particularly useful for __init__() methods, and in general in cases +where a derived class method wants to extend the base class method of +the same name and thus has to call the base class method somehow. +

+Lastly, for instance variables, it solves a syntactic problem with +assignment: since local variables in Python are (by definition!) those +variables to which a value assigned in a function body (and that +aren't explicitly declared global), there has to be some way to tell +the interpreter that an assignment was meant to assign to an instance +variable instead of to a local variable, and it should preferably be +syntactic (for efficiency reasons). C++ does this through +declarations, but Python doesn't have declarations and it would be a +pity having to introduce them just for this purpose. Using the +explicit "self.var" solves this nicely. Similarly, for using instance +variables, having to write "self.var" means that references to +unqualified names inside a method don't have to search the instance's +directories. +

+ +Edit this entry / +Log info + +/ Last changed on Fri Jan 12 08:01:50 2001 by +Steve Holden +

+ +


+

6.8. Can't you emulate threads in the interpreter instead of relying on an OS-specific thread implementation?

+Answer 1: Unfortunately, the interpreter pushes at least one C stack +frame for each Python stack frame. Also, extensions can call back into +Python at almost random moments. Therefore a complete threads +implementation requires thread support for C. +

+Answer 2: Fortunately, there is Stackless Python, which has a completely redesigned interpreter loop that avoids the C stack. It's still experimental but looks very promising. Although it is binary compatible with standard Python, it's still unclear whether Stackless will make it into the core -- maybe it's just too revolutionary. Stackless Python currently lives here: http://www.stackless.com. A microthread implementation that uses it can be found here: http://world.std.com/~wware/uthread.html. +

+ +Edit this entry / +Log info + +/ Last changed on Sat Apr 15 08:18:16 2000 by +Just van Rossum +

+ +


+

6.9. Why can't lambda forms contain statements?

+Python lambda forms cannot contain statements because Python's +syntactic framework can't handle statements nested inside expressions. +

+However, in Python, this is not a serious problem. Unlike lambda +forms in other languages, where they add functionality, Python lambdas +are only a shorthand notation if you're too lazy to define a function. +

+Functions are already first class objects in Python, and can be +declared in a local scope. Therefore the only advantage of using a +lambda form instead of a locally-defined function is that you don't need to invent a name for the function -- but that's just a local variable to which the function object (which is exactly the same type of object that a lambda form yields) is assigned! +

+ +Edit this entry / +Log info + +/ Last changed on Sun Jun 14 14:15:17 1998 by +Tim Peters +

+ +


+

6.10. [deleted]

+[lambda vs non-nested scopes used to be here] +

+ +Edit this entry / +Log info + +/ Last changed on Thu Mar 21 05:20:56 2002 by +Erno Kuusela +

+ +


+

6.11. [deleted]

+[recursive functions vs non-nested scopes used to be here] +

+ +Edit this entry / +Log info + +/ Last changed on Thu Mar 21 05:22:04 2002 by +Erno Kuusela +

+ +


+

6.12. Why is there no more efficient way of iterating over a dictionary than first constructing the list of keys()?

+As of Python 2.2, you can now iterate over a dictionary directly, +using the new implied dictionary iterator: +

+

+    for k in d: ...
+
+There are also methods returning iterators over the values and items: +

+

+    for k in d.iterkeys(): # same as above
+    for v in d.itervalues(): # iterate over values
+    for k, v in d.iteritems(): # iterate over items
+
+All these require that you do not modify the dictionary during the loop. +

+For previous Python versions, the following defense should do: +

+Have you tried it? I bet it's fast enough for your purposes! In +most cases such a list takes only a few percent of the space occupied +by the dictionary. Apart from the fixed header, +the list needs only 4 bytes (the size of a pointer) per +key. A dictionary uses 12 bytes per key plus between 30 and 70 +percent hash table overhead, plus the space for the keys and values. +By necessity, all keys are distinct objects, and a string object (the most +common key type) costs at least 20 bytes plus the length of the +string. Add to that the values contained in the dictionary, and you +see that 4 bytes more per item really isn't that much more memory... +

+A call to dict.keys() makes one fast scan over the dictionary +(internally, the iteration function does exist) copying the pointers +to the key objects into a pre-allocated list object of the right size. +The iteration time isn't lost (since you'll have to iterate anyway -- +unless in the majority of cases your loop terminates very prematurely +(which I doubt since you're getting the keys in random order). +

+I don't expose the dictionary iteration operation to Python +programmers because the dictionary shouldn't be modified during the +entire iteration -- if it is, there's a small chance that the +dictionary is reorganized because the hash table becomes too full, and +then the iteration may miss some items and see others twice. Exactly +because this only occurs rarely, it would lead to hidden bugs in +programs: it's easy never to have it happen during test runs if you +only insert or delete a few items per iteration -- but your users will +surely hit upon it sooner or later. +

+ +Edit this entry / +Log info + +/ Last changed on Fri May 24 21:24:08 2002 by +GvR +

+ +


+

6.13. Can Python be compiled to machine code, C or some other language?

+Not easily. Python's high level data types, dynamic typing of +objects and run-time invocation of the interpreter (using eval() or +exec) together mean that a "compiled" Python program would probably +consist mostly of calls into the Python run-time system, even for +seemingly simple operations like "x+1". +

+Several projects described in the Python newsgroup or at past +Python conferences have shown that this approach is feasible, +although the speedups reached so far are only modest (e.g. 2x). +JPython uses the same strategy for compiling to Java bytecode. +(Jim Hugunin has demonstrated that in combination with whole-program +analysis, speedups of 1000x are feasible for small demo programs. +See the website for the 1997 Python conference.) +

+Internally, Python source code is always translated into a "virtual +machine code" or "byte code" representation before it is interpreted +(by the "Python virtual machine" or "bytecode interpreter"). In order +to avoid the overhead of parsing and translating modules that rarely +change over and over again, this byte code is written on a file whose +name ends in ".pyc" whenever a module is parsed (from a file whose +name ends in ".py"). When the corresponding .py file is changed, it +is parsed and translated again and the .pyc file is rewritten. +

+There is no performance difference once the .pyc file has been loaded +(the bytecode read from the .pyc file is exactly the same as the bytecode +created by direct translation). The only difference is that loading +code from a .pyc file is faster than parsing and translating a .py +file, so the presence of precompiled .pyc files will generally improve +start-up time of Python scripts. If desired, the Lib/compileall.py +module/script can be used to force creation of valid .pyc files for a +given set of modules. +

+Note that the main script executed by Python, even if its filename +ends in .py, is not compiled to a .pyc file. It is compiled to +bytecode, but the bytecode is not saved to a file. +

+If you are looking for a way to translate Python programs in order to +distribute them in binary form, without the need to distribute the +interpreter and library as well, have a look at the freeze.py script +in the Tools/freeze directory. This creates a single binary file +incorporating your program, the Python interpreter, and those parts of +the Python library that are needed by your program. Of course, the +resulting binary will only run on the same type of platform as that +used to create it. +

+Newsflash: there are now several programs that do this, to some extent. +Look for Psyco, Pyrex, PyInline, Py2Cmod, and Weave. +

+ +Edit this entry / +Log info + +/ Last changed on Fri May 24 21:26:19 2002 by +GvR +

+ +


+

6.14. How does Python manage memory?

+The details of Python memory management depend on the implementation. +The standard Python implementation (the C implementation) uses reference +counting and another mechanism to collect reference cycles. +

+Jython relies on the Java runtime; so it uses +the JVM's garbage collector. This difference can cause some subtle +porting problems if your Python code depends on the behavior of +the reference counting implementation. +

+The reference cycle collector was added in CPython 2.0. It +periodically executes a cycle detection algorithm which looks for inaccessible cycles and deletes the objects involved. A new gc module provides functions to perform a garbage collection, obtain debugging statistics, and tuning the collector's parameters. +

+The detection of cycles can be disabled when Python is compiled, if you can't afford even a tiny speed penalty or suspect that the cycle collection is buggy, by specifying the "--without-cycle-gc" switch when running the configure script. +

+Sometimes objects get stuck in "tracebacks" temporarily and hence are not deallocated when you might expect. Clear the tracebacks via +

+

+       import sys
+       sys.exc_traceback = sys.last_traceback = None
+
+Tracebacks are used for reporting errors and implementing debuggers and related things. They contain a portion of the program state extracted during the handling of an exception (usually the most recent exception). +

+In the absence of circularities and modulo tracebacks, Python programs need not explicitly manage memory. +

+Why python doesn't use a more traditional garbage collection +scheme? For one thing, unless this were +added to C as a standard feature, it's a portability pain in the ass. +And yes, I know about the Xerox library. It has bits of assembler +code for most common platforms. Not for all. And although it is +mostly transparent, it isn't completely transparent (when I once +linked Python with it, it dumped core). +

+Traditional GC also becomes a problem when Python gets embedded into +other applications. While in a stand-alone Python it may be fine to +replace the standard malloc() and free() with versions provided by the +GC library, an application embedding Python may want to have its own +substitute for malloc() and free(), and may not want Python's. Right +now, Python works with anything that implements malloc() and free() +properly. +

+In Jython, the following code (which is +fine in C Python) will probably run out of file descriptors long before +it runs out of memory: +

+

+        for file in <very long list of files>:
+                f = open(file)
+                c = f.read(1)
+
+Using the current reference counting and destructor scheme, each new +assignment to f closes the previous file. Using GC, this is not +guaranteed. Sure, you can think of ways to fix this. But it's not +off-the-shelf technology. If you want to write code that will +work with any Python implementation, you should explicitly close +the file; this will work regardless of GC: +

+

+       for file in <very long list of files>:
+                f = open(file)
+                c = f.read(1)
+                f.close()
+
+

+ +Edit this entry / +Log info + +/ Last changed on Thu Mar 21 05:35:38 2002 by +Erno Kuusela +

+ +


+

6.15. Why are there separate tuple and list data types?

+This is done so that tuples can be immutable while lists are mutable. +

+Immutable tuples are useful in situations where you need to pass a few +items to a function and don't want the function to modify the tuple; +for example, +

+

+	point1 = (120, 140)
+	point2 = (200, 300)
+	record(point1, point2)
+	draw(point1, point2)
+
+You don't want to have to think about what would happen if record() +changed the coordinates -- it can't, because the tuples are immutable. +

+On the other hand, when creating large lists dynamically, it is +absolutely crucial that they are mutable -- adding elements to a tuple +one by one requires using the concatenation operator, which makes it +quadratic in time. +

+As a general guideline, use tuples like you would use structs in C or +records in Pascal, use lists like (variable length) arrays. +

+ +Edit this entry / +Log info + +/ Last changed on Fri May 23 15:26:03 1997 by +GvR +

+ +


+

6.16. How are lists implemented?

+Despite what a Lisper might think, Python's lists are really +variable-length arrays. The implementation uses a contiguous +array of references to other objects, and keeps a pointer +to this array (as well as its length) in a list head structure. +

+This makes indexing a list (a[i]) an operation whose cost is +independent of the size of the list or the value of the index. +

+When items are appended or inserted, the array of references is resized. +Some cleverness is applied to improve the performance of appending +items repeatedly; when the array must be grown, some extra space +is allocated so the next few times don't require an actual resize. +

+ +Edit this entry / +Log info + +/ Last changed on Fri May 23 15:32:24 1997 by +GvR +

+ +


+

6.17. How are dictionaries implemented?

+Python's dictionaries are implemented as resizable hash tables. +

+Compared to B-trees, this gives better performance for lookup +(the most common operation by far) under most circumstances, +and the implementation is simpler. +

+ +Edit this entry / +Log info + +/ Last changed on Fri May 23 23:51:14 1997 by +Vladimir Marangozov +

+ +


+

6.18. Why must dictionary keys be immutable?

+The hash table implementation of dictionaries uses a hash value +calculated from the key value to find the key. If the key were +a mutable object, its value could change, and thus its hash could +change. But since whoever changes the key object can't tell that +is incorporated in a dictionary, it can't move the entry around in +the dictionary. Then, when you try to look up the same object +in the dictionary, it won't be found, since its hash value is different; +and if you try to look up the old value, it won't be found either, +since the value of the object found in that hash bin differs. +

+If you think you need to have a dictionary indexed with a list, +try to use a tuple instead. The function tuple(l) creates a tuple +with the same entries as the list l. +

+Some unacceptable solutions that have been proposed: +

+- Hash lists by their address (object ID). This doesn't work because +if you construct a new list with the same value it won't be found; +e.g., +

+

+  d = {[1,2]: '12'}
+  print d[[1,2]]
+
+will raise a KeyError exception because the id of the [1,2] used +in the second line differs from that in the first line. +In other words, dictionary keys should be compared using '==', not using 'is'. +

+- Make a copy when using a list as a key. This doesn't work because +the list (being a mutable object) could contain a reference to itself, +and then the copying code would run into an infinite loop. +

+- Allow lists as keys but tell the user not to modify them. This would +allow a class of hard-to-track bugs in programs that I'd rather not see; +it invalidates an important invariant of dictionaries (every value in +d.keys() is usable as a key of the dictionary). +

+- Mark lists as read-only once they are used as a dictionary key. +The problem is that it's not just the top-level object that could change +its value; you could use a tuple containing a list as a key. Entering +anything as a key into a dictionary would require marking all objects +reachable from there as read-only -- and again, self-referential objects +could cause an infinite loop again (and again and again). +

+There is a trick to get around this if you need to, but +use it at your own risk: You +can wrap a mutable structure inside a class instance which +has both a __cmp__ and a __hash__ method. +

+

+   class listwrapper:
+        def __init__(self, the_list):
+              self.the_list = the_list
+        def __cmp__(self, other):
+              return self.the_list == other.the_list
+        def __hash__(self):
+              l = self.the_list
+              result = 98767 - len(l)*555
+              for i in range(len(l)):
+                   try:
+                        result = result + (hash(l[i]) % 9999999) * 1001 + i
+                   except:
+                        result = (result % 7777777) + i * 333
+              return result
+
+Note that the hash computation is complicated by the +possibility that some members of the list may be unhashable +and also by the possibility of arithmetic overflow. +

+You must make +sure that the hash value for all such wrapper objects that reside in a +dictionary (or other hash based structure), remain fixed while +the object is in the dictionary (or other structure). +

+Furthermore it must always be the case that if +o1 == o2 (ie o1.__cmp__(o2)==0) then hash(o1)==hash(o2) +(ie, o1.__hash__() == o2.__hash__()), regardless of whether +the object is in a dictionary or not. +If you fail to meet these restrictions dictionaries and other +hash based structures may misbehave! +

+In the case of listwrapper above whenever the wrapper +object is in a dictionary the wrapped list must not change +to avoid anomalies. Don't do this unless you are prepared +to think hard about the requirements and the consequences +of not meeting them correctly. You've been warned! +

+ +Edit this entry / +Log info + +/ Last changed on Thu Jul 10 10:08:40 1997 by +aaron watters +

+ +


+

6.19. How the heck do you make an array in Python?

+["this", 1, "is", "an", "array"] +

+Lists are arrays in the C or Pascal sense of the word (see question +6.16). The array module also provides methods for creating arrays +of fixed types with compact representations (but they are slower to +index than lists). Also note that the Numerics extensions and others +define array-like structures with various characteristics as well. +

+To get Lisp-like lists, emulate cons cells +

+

+    lisp_list = ("like",  ("this",  ("example", None) ) )
+
+using tuples (or lists, if you want mutability). Here the analogue +of lisp car is lisp_list[0] and the analogue of cdr is lisp_list[1]. +Only do this if you're sure you really need to (it's usually a lot +slower than using Python lists). +

+Think of Python lists as mutable heterogeneous arrays of +Python objects (say that 10 times fast :) ). +

+ +Edit this entry / +Log info + +/ Last changed on Wed Aug 13 07:08:27 1997 by +aaron watters +

+ +


+

6.20. Why doesn't list.sort() return the sorted list?

+In situations where performance matters, making a copy of the list +just to sort it would be wasteful. Therefore, list.sort() sorts +the list in place. In order to remind you of that fact, it does +not return the sorted list. This way, you won't be fooled into +accidentally overwriting a list when you need a sorted copy but also +need to keep the unsorted version around. +

+As a result, here's the idiom to iterate over the keys of a dictionary +in sorted order: +

+

+	keys = dict.keys()
+	keys.sort()
+	for key in keys:
+		...do whatever with dict[key]...
+
+

+ +Edit this entry / +Log info + +/ Last changed on Thu Dec 2 17:01:52 1999 by +Fred L. Drake, Jr. +

+ +


+

6.21. How do you specify and enforce an interface spec in Python?

+An interfaces specification for a module as provided +by languages such as C++ and java describes the prototypes +for the methods and functions of the module. Many feel +that compile time enforcement of interface specifications +help aid in the construction of large programs. Python +does not support interface specifications directly, but many +of their advantages can be obtained by an appropriate +test discipline for components, which can often be very +easily accomplished in Python. There is also a tool, PyChecker, +which can be used to find problems due to subclassing. +

+A good test suite for a module can at +once provide a regression test and serve as a module interface +specification (even better since it also gives example usage). Look to +many of the standard libraries which often have a "script +interpretation" which provides a simple "self test." Even +modules which use complex external interfaces can often +be tested in isolation using trivial "stub" emulations of the +external interface. +

+An appropriate testing discipline (if enforced) can help +build large complex applications in Python as well as having interface +specifications would do (or better). Of course Python allows you +to get sloppy and not do it. Also you might want to design +your code with an eye to make it easily tested. +

+ +Edit this entry / +Log info + +/ Last changed on Thu May 23 03:05:29 2002 by +Neal Norwitz +

+ +


+

6.22. Why do all classes have the same type? Why do instances all have the same type?

+The Pythonic use of the word "type" is quite different from +common usage in much of the rest of the programming language +world. A "type" in Python is a description for an object's operations +as implemented in C. All classes have the same operations +implemented in C which sometimes "call back" to differing program +fragments implemented in Python, and hence all classes have the +same type. Similarly at the C level all class instances have the +same C implementation, and hence all instances have the same +type. +

+Remember that in Python usage "type" refers to a C implementation +of an object. To distinguish among instances of different classes +use Instance.__class__, and also look to 4.47. Sorry for the +terminological confusion, but at this point in Python's development +nothing can be done! +

+ +Edit this entry / +Log info + +/ Last changed on Tue Jul 1 12:35:47 1997 by +aaron watters +

+ +


+

6.23. Why isn't all memory freed when Python exits?

+Objects referenced from Python module global name spaces are +not always deallocated when Python exits. +

+This may happen if there are circular references (see question +4.17). There are also certain bits of memory that are allocated +by the C library that are impossible to free (e.g. a tool +like Purify will complain about these). +

+But in general, Python 1.5 and beyond +(in contrast with earlier versions) is quite agressive about +cleaning up memory on exit. +

+If you want to force Python to delete certain things on deallocation +use the sys.exitfunc hook to force those deletions. For example +if you are debugging an extension module using a memory analysis +tool and you wish to make Python deallocate almost everything +you might use an exitfunc like this one: +

+

+  import sys
+
+
+  def my_exitfunc():
+       print "cleaning up"
+       import sys
+       # do order dependant deletions here
+       ...
+       # now delete everything else in arbitrary order
+       for x in sys.modules.values():
+            d = x.__dict__
+            for name in d.keys():
+                 del d[name]
+
+
+  sys.exitfunc = my_exitfunc
+
+Other exitfuncs can be less drastic, of course. +

+(In fact, this one just does what Python now already does itself; +but the example of using sys.exitfunc to force cleanups is still +useful.) +

+ +Edit this entry / +Log info + +/ Last changed on Tue Sep 29 09:46:26 1998 by +GvR +

+ +


+

6.24. Why no class methods or mutable class variables?

+The notation +

+

+    instance.attribute(arg1, arg2)
+
+usually translates to the equivalent of +

+

+    Class.attribute(instance, arg1, arg2)
+
+where Class is a (super)class of instance. Similarly +

+

+    instance.attribute = value
+
+sets an attribute of an instance (overriding any attribute of a class +that instance inherits). +

+Sometimes programmers want to have +different behaviours -- they want a method which does not bind +to the instance and a class attribute which changes in place. +Python does not preclude these behaviours, but you have to +adopt a convention to implement them. One way to accomplish +this is to use "list wrappers" and global functions. +

+

+   def C_hello():
+         print "hello"
+
+
+   class C:
+        hello = [C_hello]
+        counter = [0]
+
+
+    I = C()
+
+Here I.hello[0]() acts very much like a "class method" and +I.counter[0] = 2 alters C.counter (and doesn't override it). +If you don't understand why you'd ever want to do this, that's +because you are pure of mind, and you probably never will +want to do it! This is dangerous trickery, not recommended +when avoidable. (Inspired by Tim Peter's discussion.) +

+In Python 2.2, you can do this using the new built-in operations +classmethod and staticmethod. +See http://www.python.org/2.2/descrintro.html#staticmethods +

+ +Edit this entry / +Log info + +/ Last changed on Tue Sep 11 15:59:37 2001 by +GvR +

+ +


+

6.25. Why are default values sometimes shared between objects?

+It is often expected that a function CALL creates new objects for default +values. This is not what happens. Default values are created when the +function is DEFINED, that is, there is only one such object that all +functions refer to. If that object is changed, subsequent calls to the +function will refer to this changed object. By definition, immutable objects +(like numbers, strings, tuples, None) are safe from change. Changes to mutable +objects (like dictionaries, lists, class instances) is what causes the +confusion. +

+Because of this feature it is good programming practice not to use mutable +objects as default values, but to introduce them in the function. +Don't write: +

+

+	def foo(dict={}):  # XXX shared reference to one dict for all calls
+	    ...
+
+but: +
+	def foo(dict=None):
+		if dict is None:
+			dict = {} # create a new dict for local namespace
+
+See page 182 of "Internet Programming with Python" for one discussion +of this feature. Or see the top of page 144 or bottom of page 277 in +"Programming Python" for another discussion. +

+ +Edit this entry / +Log info + +/ Last changed on Sat Aug 16 07:03:35 1997 by +Case Roole +

+ +


+

6.26. Why no goto?

+Actually, you can use exceptions to provide a "structured goto" +that even works across function calls. Many feel that exceptions +can conveniently emulate all reasonable uses of the "go" or "goto" +constructs of C, Fortran, and other languages. For example: +

+

+   class label: pass # declare a label
+   try:
+        ...
+        if (condition): raise label() # goto label
+        ...
+   except label: # where to goto
+        pass
+   ...
+
+This doesn't allow you to jump into the middle of a loop, but +that's usually considered an abuse of goto anyway. Use sparingly. +

+ +Edit this entry / +Log info + +/ Last changed on Wed Sep 10 07:16:44 1997 by +aaron watters +

+ +


+

6.27. How do you make a higher order function in Python?

+You have two choices: you can use default arguments and override +them or you can use "callable objects." For example suppose you +wanted to define linear(a,b) which returns a function f where f(x) +computes the value a*x+b. Using default arguments: +

+

+     def linear(a,b):
+         def result(x, a=a, b=b):
+             return a*x + b
+         return result
+
+Or using callable objects: +

+

+     class linear:
+        def __init__(self, a, b):
+            self.a, self.b = a,b
+        def __call__(self, x):
+            return self.a * x + self.b
+
+In both cases: +

+

+     taxes = linear(0.3,2)
+
+gives a callable object where taxes(10e6) == 0.3 * 10e6 + 2. +

+The defaults strategy has the disadvantage that the default arguments +could be accidentally or maliciously overridden. The callable objects +approach has the disadvantage that it is a bit slower and a bit +longer. Note however that a collection of callables can share +their signature via inheritance. EG +

+

+      class exponential(linear):
+         # __init__ inherited
+         def __call__(self, x):
+             return self.a * (x ** self.b)
+
+On comp.lang.python, zenin@bawdycaste.org points out that +an object can encapsulate state for several methods in order +to emulate the "closure" concept from functional programming +languages, for example: +

+

+    class counter:
+        value = 0
+        def set(self, x): self.value = x
+        def up(self): self.value=self.value+1
+        def down(self): self.value=self.value-1
+
+
+    count = counter()
+    inc, dec, reset = count.up, count.down, count.set
+
+Here inc, dec and reset act like "functions which share the +same closure containing the variable count.value" (if you +like that way of thinking). +

+ +Edit this entry / +Log info + +/ Last changed on Fri Sep 25 08:38:35 1998 by +Aaron Watters +

+ +


+

6.28. Why do I get a SyntaxError for a 'continue' inside a 'try'?

+This is an implementation limitation, +caused by the extremely simple-minded +way Python generates bytecode. The try block pushes something on the +"block stack" which the continue would have to pop off again. The +current code generator doesn't have the data structures around so that +'continue' can generate the right code. +

+Note that JPython doesn't have this restriction! +

+ +Edit this entry / +Log info + +/ Last changed on Fri May 22 15:01:07 1998 by +GvR +

+ +


+

6.29. Why can't raw strings (r-strings) end with a backslash?

+More precisely, they can't end with an odd number of backslashes: +the unpaired backslash at the end escapes the closing quote character, +leaving an unterminated string. +

+Raw strings were designed to ease creating input for processors (chiefly +regular expression engines) that want to do their own backslash escape processing. Such processors consider an unmatched trailing backslash to be an error anyway, so raw strings disallow that. In return, they allow you to pass on the string quote character by escaping it with a backslash. These rules work well when r-strings are used for their intended purpose. +

+If you're trying to build Windows pathnames, note that all Windows system calls accept forward slashes too: +

+

+    f = open("/mydir/file.txt") # works fine!
+
+If you're trying to build a pathname for a DOS command, try e.g. one of +

+

+    dir = r"\this\is\my\dos\dir" "\\"
+    dir = r"\this\is\my\dos\dir\ "[:-1]
+    dir = "\\this\\is\\my\\dos\\dir\\"
+
+

+ +Edit this entry / +Log info + +/ Last changed on Mon Jul 13 20:50:20 1998 by +Tim Peters +

+ +


+

6.30. Why can't I use an assignment in an expression?

+Many people used to C or Perl complain that they want to be able to +use e.g. this C idiom: +

+

+    while (line = readline(f)) {
+        ...do something with line...
+    }
+
+where in Python you're forced to write this: +

+

+    while 1:
+        line = f.readline()
+        if not line:
+            break
+        ...do something with line...
+
+This issue comes up in the Python newsgroup with alarming frequency +-- search Deja News for past messages about assignment expression. +The reason for not allowing assignment in Python expressions +is a common, hard-to-find bug in those other languages, +caused by this construct: +

+

+    if (x = 0) {
+        ...error handling...
+    }
+    else {
+        ...code that only works for nonzero x...
+    }
+
+Many alternatives have been proposed. Most are hacks that save some +typing but use arbitrary or cryptic syntax or keywords, +and fail the simple criterion that I use for language change proposals: +it should intuitively suggest the proper meaning to a human reader +who has not yet been introduced with the construct. +

+The earliest time something can be done about this will be with +Python 2.0 -- if it is decided that it is worth fixing. +An interesting phenomenon is that most experienced Python programmers +recognize the "while 1" idiom and don't seem to be missing the +assignment in expression construct much; it's only the newcomers +who express a strong desire to add this to the language. +

+One fairly elegant solution would be to introduce a new operator +for assignment in expressions spelled ":=" -- this avoids the "=" +instead of "==" problem. It would have the same precedence +as comparison operators but the parser would flag combination with +other comparisons (without disambiguating parentheses) as an error. +

+Finally -- there's an alternative way of spelling this that seems +attractive but is generally less robust than the "while 1" solution: +

+

+    line = f.readline()
+    while line:
+        ...do something with line...
+        line = f.readline()
+
+The problem with this is that if you change your mind about exactly +how you get the next line (e.g. you want to change it into +sys.stdin.readline()) you have to remember to change two places +in your program -- the second one hidden at the bottom of the loop. +

+ +Edit this entry / +Log info + +/ Last changed on Tue May 18 00:57:41 1999 by +Andrew Dalke +

+ +


+

6.31. Why doesn't Python have a "with" statement like some other languages?

+Basically, because such a construct would be terribly ambiguous. Thanks to Carlos Ribeiro for the following remarks: +

+Some languages, such as Object Pascal, Delphi, and C++, use static types. So it is possible to know, in an unambiguous way, what member is being assigned in a "with" clause. This is the main point - the compiler always knows the scope of every variable at compile time. +

+Python uses dynamic types. It is impossible to know in advance which +attribute will be referenced at runtime. Member attributes may be added or removed from objects on the fly. This would make it impossible to know, from a simple reading, what attribute is being referenced - a local one, a global one, or a member attribute. +

+For instance, take the following snippet (it is incomplete btw, just to +give you the idea): +

+

+   def with_is_broken(a):
+      with a:
+         print x
+
+The snippet assumes that "a" must have a member attribute called "x". +However, there is nothing in Python that guarantees that. What should +happen if "a" is, let us say, an integer? And if I have a global variable named "x", will it end up being used inside the with block? As you see, the dynamic nature of Python makes such choices much harder. +

+The primary benefit of "with" and similar language features (reduction of code volume) can, however, easily be achieved in Python by assignment. Instead of: +

+

+    function(args).dict[index][index].a = 21
+    function(args).dict[index][index].b = 42
+    function(args).dict[index][index].c = 63
+
+would become: +

+

+    ref = function(args).dict[index][index]
+    ref.a = 21
+    ref.b = 42
+    ref.c = 63
+
+This also has the happy side-effect of increasing execution speed, since name bindings are resolved at run-time in Python, and the second method only needs to perform the resolution once. If the referenced object does not have a, b and c attributes, of course, the end result is still a run-time exception. +

+ +Edit this entry / +Log info + +/ Last changed on Fri Jan 11 14:32:58 2002 by +Steve Holden +

+ +


+

6.32. Why are colons required for if/while/def/class?

+The colon is required primarily to enhance readability (one of the +results of the experimental ABC language). Consider this: +

+

+    if a==b
+        print a
+
+versus +

+

+    if a==b:
+        print a
+
+Notice how the second one is slightly easier to read. Notice further how +a colon sets off the example in the second line of this FAQ answer; it's +a standard usage in English. Finally, the colon makes it easier for +editors with syntax highlighting. +

+ +Edit this entry / +Log info + +/ Last changed on Mon Jun 3 07:22:57 2002 by +Matthias Urlichs +

+ +


+

6.33. Can't we get rid of the Global Interpreter Lock?

+The Global Interpreter Lock (GIL) is often seen as a hindrance to +Python's deployment on high-end multiprocessor server machines, +because a multi-threaded Python program effectively only uses +one CPU, due to the insistence that (almost) all Python code +can only run while the GIL is held. +

+Back in the days of Python 1.5, Greg Stein actually implemented +a comprehensive patch set ("free threading") +that removed the GIL, replacing it with +fine-grained locking. Unfortunately, even on Windows (where locks +are very efficient) this ran ordinary Python code about twice as +slow as the interpreter using the GIL. On Linux the performance +loss was even worse (pthread locks aren't as efficient). +

+Since then, the idea of getting rid of the GIL has occasionally +come up but nobody has found a way to deal with the expected slowdown; +Greg's free threading patch set has not been kept up-to-date for +later Python versions. +

+This doesn't mean that you can't make good use of Python on +multi-CPU machines! You just have to be creative with dividing +the work up between multiple processes rather than multiple +threads. +

+

+It has been suggested that the GIL should be a per-interpreter-state +lock rather than truly global; interpreters then wouldn't be able +to share objects. Unfortunately, this isn't likely to happen either. +

+It would be a tremendous amount of work, because many object +implementations currently have global state. E.g. small ints and +small strings are cached; these caches would have to be moved to the +interpreter state. Other object types have their own free list; these +free lists would have to be moved to the interpreter state. And so +on. +

+And I doubt that it can even be done in finite time, because the same +problem exists for 3rd party extensions. It is likely that 3rd party +extensions are being written at a faster rate than you can convert +them to store all their global state in the interpreter state. +

+And finally, once you have multiple interpreters not sharing any +state, what have you gained over running each interpreter +in a separate process? +

+ +Edit this entry / +Log info + +/ Last changed on Fri Feb 7 16:34:01 2003 by +GvR +

+ +


+

7. Using Python on non-UNIX platforms

+ +
+

7.1. Is there a Mac version of Python?

+Yes, it is maintained by Jack Jansen. See Jack's MacPython Page: +

+

+  http://www.cwi.nl/~jack/macpython.html
+
+

+ +Edit this entry / +Log info + +/ Last changed on Fri May 4 09:33:42 2001 by +GvR +

+ +


+

7.2. Are there DOS and Windows versions of Python?

+Yes. The core windows binaries are available from http://www.python.org/windows/. There is a plethora of Windows extensions available, including a large number of not-always-compatible GUI toolkits. The core binaries include the standard Tkinter GUI extension. +

+Most windows extensions can be found (or referenced) at http://www.python.org/windows/ +

+Windows 3.1/DOS support seems to have dropped off recently. You may need to settle for an old version of Python one these platforms. One such port is WPY +

+WPY: Ports to DOS, Windows 3.1(1), Windows 95, Windows NT and OS/2. +Also contains a GUI package that offers portability between Windows +(not DOS) and Unix, and native look and feel on both. +ftp://ftp.python.org/pub/python/wpy/. +

+ +Edit this entry / +Log info + +/ Last changed on Tue Jun 2 20:21:57 1998 by +Mark Hammond +

+ +


+

7.3. Is there an OS/2 version of Python?

+Yes, see http://www.python.org/download/download_os2.html. +

+ +Edit this entry / +Log info + +/ Last changed on Tue Sep 7 11:33:16 1999 by +GvR +

+ +


+

7.4. Is there a VMS version of Python?

+Jean-François Piéronne has ported 2.1.3 to OpenVMS. It can be found at +<http://vmspython.dyndns.org/>. +

+ +Edit this entry / +Log info + +/ Last changed on Thu Sep 19 15:40:38 2002 by +Skip Montanaro +

+ +


+

7.5. What about IBM mainframes, or other non-UNIX platforms?

+I haven't heard about these, except I remember hearing about an +OS/9 port and a port to Vxworks (both operating systems for embedded +systems). If you're interested in any of this, go directly to the +newsgroup and ask there, you may find exactly what you need. For +example, a port to MPE/iX 5.0 on HP3000 computers was just announced, +see http://www.allegro.com/software/. +

+On the IBM mainframe side, for Z/OS there's a port of python 1.4 that goes with their open-unix package, formely OpenEdition MVS, (http://www-1.ibm.com/servers/eserver/zseries/zos/unix/python.html). On a side note, there's also a java vm ported - so, in theory, jython could run too. +

+ +Edit this entry / +Log info + +/ Last changed on Mon Nov 18 03:18:39 2002 by +Bruno Jessen +

+ +


+

7.6. Where are the source or Makefiles for the non-UNIX versions?

+The standard sources can (almost) be used. Additional sources can +be found in the platform-specific subdirectories of the distribution. +

+ +Edit this entry / +Log info +

+ +


+

7.7. What is the status and support for the non-UNIX versions?

+I don't have access to most of these platforms, so in general I am +dependent on material submitted by volunteers. However I strive to +integrate all changes needed to get it to compile on a particular +platform back into the standard sources, so porting of the next +version to the various non-UNIX platforms should be easy. +(Note that Linux is classified as a UNIX platform here. :-) +

+Some specific platforms: +

+Windows: all versions (95, 98, ME, NT, 2000, XP) are supported, +all python.org releases come with a Windows installer. +

+MacOS: Jack Jansen does an admirable job of keeping the Mac version +up to date (both MacOS X and older versions); +see http://www.cwi.nl/~jack/macpython.html +

+For all supported platforms, see http://www.python.org/download/ +(follow the link to "Other platforms" for less common platforms) +

+ +Edit this entry / +Log info + +/ Last changed on Fri May 24 21:34:24 2002 by +GvR +

+ +


+

7.8. I have a PC version but it appears to be only a binary. Where's the library?

+If you are running any version of Windows, then you have the wrong distribution. The FAQ lists current Windows versions. Notably, Pythonwin and wpy provide fully functional installations. +

+But if you are sure you have the only distribution with a hope of working on +your system, then... +

+You still need to copy the files from the distribution directory +"python/Lib" to your system. If you don't have the full distribution, +you can get the file lib<version>.tar.gz from most ftp sites carrying +Python; this is a subset of the distribution containing just those +files, e.g. ftp://ftp.python.org/pub/python/src/lib1.4.tar.gz. +

+Once you have installed the library, you need to point sys.path to it. +Assuming the library is in C:\misc\python\lib, the following commands +will point your Python interpreter to it (note the doubled backslashes +-- you can also use single forward slashes instead): +

+

+        >>> import sys
+        >>> sys.path.insert(0, 'C:\\misc\\python\\lib')
+        >>>
+
+For a more permanent effect, set the environment variable PYTHONPATH, +as follows (talking to a DOS prompt): +

+

+        C> SET PYTHONPATH=C:\misc\python\lib
+
+

+ +Edit this entry / +Log info + +/ Last changed on Fri May 23 16:28:27 1997 by +Ken Manheimer +

+ +


+

7.9. Where's the documentation for the Mac or PC version?

+The documentation for the Unix version also applies to the Mac and +PC versions. Where applicable, differences are indicated in the text. +

+ +Edit this entry / +Log info +

+ +


+

7.10. How do I create a Python program file on the Mac or PC?

+Use an external editor. On the Mac, BBEdit seems to be a popular +no-frills text editor. I work like this: start the interpreter; edit +a module file using BBedit; import and test it in the interpreter; +edit again in BBedit; then use the built-in function reload() to +re-read the imported module; etc. In the 1.4 distribution +you will find a BBEdit extension that makes life a little easier: +it can tell the interpreter to execute the current window. +See :Mac:Tools:BBPy:README. +

+Regarding the same question for the PC, Kurt Wm. Hemr writes: "While +anyone with a pulse could certainly figure out how to do the same on +MS-Windows, I would recommend the NotGNU Emacs clone for MS-Windows. +Not only can you easily resave and "reload()" from Python after making +changes, but since WinNot auto-copies to the clipboard any text you +select, you can simply select the entire procedure (function) which +you changed in WinNot, switch to QWPython, and shift-ins to reenter +the changed program unit." +

+If you're using Windows95 or Windows NT, you should also know about +PythonWin, which provides a GUI framework, with an mouse-driven +editor, an object browser, and a GUI-based debugger. See +

+       http://www.python.org/ftp/python/pythonwin/
+
+for details. +

+ +Edit this entry / +Log info + +/ Last changed on Sun May 25 10:04:25 1997 by +GvR +

+ +


+

7.11. How can I use Tkinter on Windows 95/NT?

+Starting from Python 1.5, it's very easy -- just download and install +Python and Tcl/Tk and you're in business. See +

+

+  http://www.python.org/download/download_windows.html
+
+One warning: don't attempt to use Tkinter from PythonWin +(Mark Hammond's IDE). Use it from the command line interface +(python.exe) or the windowless interpreter (pythonw.exe). +

+ +Edit this entry / +Log info + +/ Last changed on Fri Jun 12 09:32:48 1998 by +GvR +

+ +


+

7.12. cgi.py (or other CGI programming) doesn't work sometimes on NT or win95!

+Be sure you have the latest python.exe, that you are using +python.exe rather than a GUI version of python and that you +have configured the server to execute +

+

+     "...\python.exe -u ..."
+
+for the cgi execution. The -u (unbuffered) option on NT and +win95 prevents the interpreter from altering newlines in the +standard input and output. Without it post/multipart requests +will seem to have the wrong length and binary (eg, GIF) +responses may get garbled (resulting in, eg, a "broken image"). +

+ +Edit this entry / +Log info + +/ Last changed on Wed Jul 30 10:48:02 1997 by +aaron watters +

+ +


+

7.13. Why doesn't os.popen() work in PythonWin on NT?

+The reason that os.popen() doesn't work from within PythonWin is due to a bug in Microsoft's C Runtime Library (CRT). The CRT assumes you have a Win32 console attached to the process. +

+You should use the win32pipe module's popen() instead which doesn't depend on having an attached Win32 console. +

+Example: +

+ import win32pipe
+ f = win32pipe.popen('dir /c c:\\')
+ print f.readlines()
+ f.close()
+
+

+ +Edit this entry / +Log info + +/ Last changed on Thu Jul 31 15:34:09 1997 by +Bill Tutt +

+ +


+

7.14. How do I use different functionality on different platforms with the same program?

+Remember that Python is extremely dynamic and that you +can use this dynamism to configure a program at run-time to +use available functionality on different platforms. For example +you can test the sys.platform and import different modules based +on its value. +

+

+   import sys
+   if sys.platform == "win32":
+      import win32pipe
+      popen = win32pipe.popen
+   else:
+      import os
+      popen = os.popen
+
+(See FAQ 7.13 for an explanation of why you might want to +do something like this.) Also you can try to import a module +and use a fallback if the import fails: +

+

+    try:
+         import really_fast_implementation
+         choice = really_fast_implementation
+    except ImportError:
+         import slower_implementation
+         choice = slower_implementation
+
+

+ +Edit this entry / +Log info + +/ Last changed on Wed Aug 13 07:39:06 1997 by +aaron watters +

+ +


+

7.15. Is there an Amiga version of Python?

+Yes. See the AmigaPython homepage at http://www.bigfoot.com/~irmen/python.html. +

+ +Edit this entry / +Log info + +/ Last changed on Mon Dec 14 06:53:32 1998 by +Irmen de Jong +

+ +


+

7.16. Why doesn't os.popen()/win32pipe.popen() work on Win9x?

+There is a bug in Win9x that prevents os.popen/win32pipe.popen* from working. The good news is there is a way to work around this problem. +The Microsoft Knowledge Base article that you need to lookup is: Q150956. You will find links to the knowledge base at: +http://www.microsoft.com/kb. +

+ +Edit this entry / +Log info + +/ Last changed on Fri Jun 25 10:45:38 1999 by +Bill Tutt +

+ +


+

8. Python on Windows

+ +
+

8.1. Using Python for CGI on Microsoft Windows

+** Setting up the Microsoft IIS Server/Peer Server +

+On the Microsoft IIS +server or on the Win95 MS Personal Web Server +you set up python in the same way that you +would set up any other scripting engine. +

+Run regedt32 and go to: +

+HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W3SVC\Parameters\ScriptMap +

+and enter the following line (making any specific changes that your system may need) +

+.py :REG_SZ: c:\<path to python>\python.exe -u %s %s +

+This line will allow you to call your script with a simple reference like: +http://yourserver/scripts/yourscript.py +provided "scripts" is an "executable" directory for your server (which +it usually is by default). +The "-u" flag specifies unbuffered and binary mode for stdin - needed when working with binary data +

+In addition, it is recommended by people who would know that using ".py" may +not be a good idea for the file extensions when used in this context +(you might want to reserve *.py for support modules and use *.cgi or *.cgp +for "main program" scripts). +However, that issue is beyond this Windows FAQ entry. +

+

+** Apache configuration +

+In the Apache configuration file httpd.conf, add the following line at +the end of the file: +

+ScriptInterpreterSource Registry +

+Then, give your Python CGI-scripts the extension .py and put them in the cgi-bin directory. +

+

+** Netscape Servers: +Information on this topic exists at: +http://home.netscape.com/comprod/server_central/support/fasttrack_man/programs.htm#1010870 +

+ +Edit this entry / +Log info + +/ Last changed on Wed Mar 27 12:25:54 2002 by +Gerhard Häring +

+ +


+

8.2. How to check for a keypress without blocking?

+Use the msvcrt module. This is a standard Windows-specific extensions +in Python 1.5 and beyond. It defines a function kbhit() which checks +whether a keyboard hit is present; also getch() which gets one +character without echo. Plus a few other goodies. +

+(Search for "keypress" to find an answer for Unix as well.) +

+ +Edit this entry / +Log info + +/ Last changed on Mon Mar 30 16:21:46 1998 by +GvR +

+ +


+

8.3. $PYTHONPATH

+In MS-DOS derived environments, a unix variable such as $PYTHONPATH is +set as PYTHONPATH, without the dollar sign. PYTHONPATH is useful for +specifying the location of library files. +

+ +Edit this entry / +Log info + +/ Last changed on Thu Jun 11 00:41:26 1998 by +Gvr +

+ +


+

8.4. dedent syntax errors

+The FAQ does not recommend using tabs, and Guido's Python Style Guide recommends 4 spaces for distributed Python code; this is also the Emacs python-mode default; see +

+

+    http://www.python.org/doc/essays/styleguide.html
+
+Under any editor mixing tabs and spaces is a bad idea. MSVC is no different in this respect, and is easily configured to use spaces: Take Tools -> Options -> Tabs, and for file type "Default" set "Tab size" and "Indent size" to 4, and select the "Insert spaces" radio button. +

+If you suspect mixed tabs and spaces are causing problems in leading whitespace, run Python with the -t switch or, run Tools/Scripts/tabnanny.py to check a directory tree in batch mode. +

+ +Edit this entry / +Log info + +/ Last changed on Mon Feb 12 15:04:14 2001 by +Steve Holden +

+ +


+

8.5. How do I emulate os.kill() in Windows?

+Use win32api: +

+

+    def kill(pid):
+        """kill function for Win32"""
+        import win32api
+        handle = win32api.OpenProcess(1, 0, pid)
+        return (0 != win32api.TerminateProcess(handle, 0))
+
+

+ +Edit this entry / +Log info + +/ Last changed on Sat Aug 8 18:55:06 1998 by +Jeff Bauer +

+ +


+

8.6. Why does os.path.isdir() fail on NT shared directories?

+The solution appears to be always append the "\\" on +the end of shared drives. +

+

+  >>> import os
+  >>> os.path.isdir( '\\\\rorschach\\public')
+  0
+  >>> os.path.isdir( '\\\\rorschach\\public\\')
+  1
+
+[Blake Winton responds:] +I've had the same problem doing "Start >> Run" and then a +directory on a shared drive. If I use "\\rorschach\public", +it will fail, but if I use "\\rorschach\public\", it will +work. For that matter, os.stat() does the same thing (well, +it gives an error for "\\\\rorschach\\public", but you get +the idea)... +

+I've got a theory about why this happens, but it's only +a theory. NT knows the difference between shared directories, +and regular directories. "\\rorschach\public" isn't a +directory, it's _really_ an IPC abstraction. This is sort +of lended credence to by the fact that when you're mapping +a network drive, you can't map "\\rorschach\public\utils", +but only "\\rorschach\public". +

+[Clarification by funkster@midwinter.com] +It's not actually a Python +question, as Python is working just fine; it's clearing up something +a bit muddled about Windows networked drives. +

+It helps to think of share points as being like drive letters. +Example: +

+        k: is not a directory
+        k:\ is a directory
+        k:\media is a directory
+        k:\media\ is not a directory
+
+The same rules apply if you substitute "k:" with "\\conky\foo": +
+        \\conky\foo  is not a directory
+        \\conky\foo\ is a directory
+        \\conky\foo\media is a directory
+        \\conky\foo\media\ is not a directory
+
+

+ +Edit this entry / +Log info + +/ Last changed on Sun Jan 31 08:44:48 1999 by +GvR +

+ +


+

8.7. PyRun_SimpleFile() crashes on Windows but not on Unix

+I've seen a number of reports of PyRun_SimpleFile() failing +in a Windows port of an application embedding Python that worked +fine on Unix. PyRun_SimpleString() works fine on both platforms. +

+I think this happens because the application was compiled with a +different set of compiler flags than Python15.DLL. It seems that some +compiler flags affect the standard I/O library in such a way that +using different flags makes calls fail. You need to set it for +the non-debug multi-threaded DLL (/MD on the command line, or can be set via MSVC under Project Settings->C++/Code Generation then the "Use rum-time library" dropdown.) +

+Also note that you can not mix-and-match Debug and Release versions. If you wish to use the Debug Multithreaded DLL, then your module _must_ have an "_d" appended to the base name. +

+ +Edit this entry / +Log info + +/ Last changed on Wed Nov 17 17:37:07 1999 by +Mark Hammond +

+ +


+

8.8. Import of _tkinter fails on Windows 95/98

+Sometimes, the import of _tkinter fails on Windows 95 or 98, +complaining with a message like the following: +

+

+  ImportError: DLL load failed: One of the library files needed
+  to run this application cannot be found.
+
+It could be that you haven't installed Tcl/Tk, but if you did +install Tcl/Tk, and the Wish application works correctly, +the problem may be that its installer didn't +manage to edit the autoexec.bat file correctly. It tries to add a +statement that changes the PATH environment variable to include +the Tcl/Tk 'bin' subdirectory, but sometimes this edit doesn't +quite work. Opening it with notepad usually reveals what the +problem is. +

+(One additional hint, noted by David Szafranski: you can't use +long filenames here; e.g. use C:\PROGRA~1\Tcl\bin instead of +C:\Program Files\Tcl\bin.) +

+ +Edit this entry / +Log info + +/ Last changed on Wed Dec 2 22:32:41 1998 by +GvR +

+ +


+

8.9. Can't extract the downloaded documentation on Windows

+Sometimes, when you download the documentation package to a Windows +machine using a web browser, the file extension of the saved file +ends up being .EXE. This is a mistake; the extension should be .TGZ. +

+Simply rename the downloaded file to have the .TGZ extension, and +WinZip will be able to handle it. (If your copy of WinZip doesn't, +get a newer one from http://www.winzip.com.) +

+ +Edit this entry / +Log info + +/ Last changed on Sat Nov 21 13:41:35 1998 by +GvR +

+ +


+

8.10. Can't get Py_RunSimpleFile() to work.

+This is very sensitive to the compiler vendor, version and (perhaps) +even options. If the FILE* structure in your embedding program isn't +the same as is assumed by the Python interpreter it won't work. +

+The Python 1.5.* DLLs (python15.dll) are all compiled +with MS VC++ 5.0 and with multithreading-DLL options (/MD, I think). +

+If you can't change compilers or flags, try using Py_RunSimpleString(). +A trick to get it to run an arbitrary file is to construct a call to +execfile() with the name of your file as argument. +

+ +Edit this entry / +Log info + +/ Last changed on Wed Jan 13 10:58:14 1999 by +GvR +

+ +


+

8.11. Where is Freeze for Windows?

+("Freeze" is a program that allows you to ship a Python program +as a single stand-alone executable file. It is not a compiler, +your programs don't run any faster, but they are more easily +distributable (to platforms with the same OS and CPU). Read the +README file of the freeze program for more disclaimers.) +

+You can use freeze on Windows, but you must download the source +tree (see http://www.python.org/download/download_source.html). +This is recommended for Python 1.5.2 (and betas thereof) only; +older versions don't quite work. +

+You need the Microsoft VC++ 5.0 compiler (maybe it works with +6.0 too). You probably need to build Python -- the project files +are all in the PCbuild directory. +

+The freeze program is in the Tools\freeze subdirectory of the source +tree. +

+ +Edit this entry / +Log info + +/ Last changed on Wed Feb 17 18:47:24 1999 by +GvR +

+ +


+

8.12. Is a *.pyd file the same as a DLL?

+Yes, .pyd files are dll's. But there are a few differences. If you +have a DLL named foo.pyd, then it must have a function initfoo(). You +can then write Python "import foo", and Python will search for foo.pyd +(as well as foo.py, foo.pyc) and if it finds it, will attempt to call +initfoo() to initialize it. You do not link your .exe with foo.lib, +as that would cause Windows to require the DLL to be present. +

+Note that the search path for foo.pyd is PYTHONPATH, not the same as +the path that Windows uses to search for foo.dll. Also, foo.pyd need +not be present to run your program, whereas if you linked your program +with a dll, the dll is required. Of course, foo.pyd is required if +you want to say "import foo". In a dll, linkage is declared in the +source code with __declspec(dllexport). In a .pyd, linkage is defined +in a list of available functions. +

+ +Edit this entry / +Log info + +/ Last changed on Tue Nov 23 02:40:08 1999 by +Jameson Quinn +

+ +


+

8.13. Missing cw3215mt.dll (or missing cw3215.dll)

+Sometimes, when using Tkinter on Windows, you get an error that +cw3215mt.dll or cw3215.dll is missing. +

+Cause: you have an old Tcl/Tk DLL built with cygwin in your path +(probably C:\Windows). You must use the Tcl/Tk DLLs from the +standard Tcl/Tk installation (Python 1.5.2 comes with one). +

+ +Edit this entry / +Log info + +/ Last changed on Fri Jun 11 00:54:13 1999 by +GvR +

+ +


+

8.14. How to make python scripts executable:

+[Blake Coverett] +

+Win2K: +

+The standard installer already associates the .py extension with a file type +(Python.File) and gives that file type an open command that runs the +interpreter (D:\Program Files\Python\python.exe "%1" %*). This is enough to +make scripts executable from the command prompt as 'foo.py'. If you'd +rather be able to execute the script by simple typing 'foo' with no +extension you need to add .py to the PATHEXT environment variable. +

+WinNT: +

+The steps taken by the installed as described above allow you do run a +script with 'foo.py', but a long time bug in the NT command processor +prevents you from redirecting the input or output of any script executed in +this way. This is often important. +

+An appropriate incantation for making a Python script executable under WinNT +is to give the file an extension of .cmd and add the following as the first +line: +

+

+    @setlocal enableextensions & python -x %~f0 %* & goto :EOF
+
+Win9x: +

+[Due to Bruce Eckel] +

+

+  @echo off
+  rem = """
+  rem run python on this bat file. Needs the full path where
+  rem you keep your python files. The -x causes python to skip
+  rem the first line of the file:
+  python -x c:\aaa\Python\\"%0".bat %1 %2 %3 %4 %5 %6 %7 %8 %9
+  goto endofpython
+  rem """
+
+
+  # The python program goes here:
+
+
+  print "hello, Python"
+
+
+  # For the end of the batch file:
+  rem = """
+  :endofpython
+  rem """
+
+

+ +Edit this entry / +Log info + +/ Last changed on Tue Nov 30 10:25:17 1999 by +GvR +

+ +


+

8.15. Warning about CTL3D32 version from installer

+The Python installer issues a warning like this: +

+

+  This version uses CTL3D32.DLL whitch is not the correct version.
+  This version is used for windows NT applications only.
+
+[Tim Peters] +This is a Microsoft DLL, and a notorious +source of problems. The msg means what it says: you have the wrong version +of this DLL for your operating system. The Python installation did not +cause this -- something else you installed previous to this overwrote the +DLL that came with your OS (probably older shareware of some sort, but +there's no way to tell now). If you search for "CTL3D32" using any search +engine (AltaVista, for example), you'll find hundreds and hundreds of web +pages complaining about the same problem with all sorts of installation +programs. They'll point you to ways to get the correct version reinstalled +on your system (since Python doesn't cause this, we can't fix it). +

+David A Burton has written a little program to fix this. Go to +http://www.burtonsys.com/download.html and click on "ctl3dfix.zip" +

+ +Edit this entry / +Log info + +/ Last changed on Thu Oct 26 15:42:00 2000 by +GvR +

+ +


+

8.16. How can I embed Python into a Windows application?

+Edward K. Ream <edream@tds.net> writes +

+When '##' appears in a file name below, it is an abbreviated version number. For example, for Python 2.1.1, ## will be replaced by 21. +

+Embedding the Python interpreter in a Windows app can be summarized as +follows: +

+1. Do _not_ build Python into your .exe file directly. On Windows, +Python must be a DLL to handle importing modules that are themselves +DLL's. (This is the first key undocumented fact.) Instead, link to +python##.dll; it is typically installed in c:\Windows\System. +

+You can link to Python statically or dynamically. Linking statically +means linking against python##.lib The drawback is that your app won't +run if python##.dll does not exist on your system. +

+General note: python##.lib is the so-called "import lib" corresponding +to python.dll. It merely defines symbols for the linker. +

+Borland note: convert python##.lib to OMF format using Coff2Omf.exe +first. +

+Linking dynamically greatly simplifies link options; everything happens +at run time. Your code must load python##.dll using the Windows +LoadLibraryEx() routine. The code must also use access routines and +data in python##.dll (that is, Python's C API's) using pointers +obtained by the Windows GetProcAddress() routine. Macros can make +using these pointers transparent to any C code that calls routines in +Python's C API. +

+2. If you use SWIG, it is easy to create a Python "extension module" +that will make the app's data and methods available to Python. SWIG +will handle just about all the grungy details for you. The result is C +code that you link _into your .exe file_ (!) You do _not_ have to +create a DLL file, and this also simplifies linking. +

+3. SWIG will create an init function (a C function) whose name depends +on the name of the extension module. For example, if the name of the +module is leo, the init function will be called initleo(). If you use +SWIG shadow classes, as you should, the init function will be called +initleoc(). This initializes a mostly hidden helper class used by the +shadow class. +

+The reason you can link the C code in step 2 into your .exe file is that +calling the initialization function is equivalent to importing the +module into Python! (This is the second key undocumented fact.) +

+4. In short, you can use the following code to initialize the Python +interpreter with your extension module. +

+

+    #include "python.h"
+    ...
+    Py_Initialize();  // Initialize Python.
+    initmyAppc();  // Initialize (import) the helper class. 
+    PyRun_SimpleString("import myApp") ;  // Import the shadow class.
+
+5. There are two problems with Python's C API which will become apparent +if you use a compiler other than MSVC, the compiler used to build +python##.dll. +

+Problem 1: The so-called "Very High Level" functions that take FILE * +arguments will not work in a multi-compiler environment; each compiler's +notion of a struct FILE will be different. From an implementation +standpoint these are very _low_ level functions. +

+Problem 2: SWIG generates the following code when generating wrappers to +void functions: +

+

+    Py_INCREF(Py_None);
+    _resultobj = Py_None;
+    return _resultobj;
+
+Alas, Py_None is a macro that expands to a reference to a complex data +structure called _Py_NoneStruct inside python##.dll. Again, this code +will fail in a mult-compiler environment. Replace such code by: +

+

+    return Py_BuildValue("");
+
+It may be possible to use SWIG's %typemap command to make the change +automatically, though I have not been able to get this to work (I'm a +complete SWIG newbie). +

+6. Using a Python shell script to put up a Python interpreter window +from inside your Windows app is not a good idea; the resulting window +will be independent of your app's windowing system. Rather, you (or the +wxPythonWindow class) should create a "native" interpreter window. It +is easy to connect that window to the Python interpreter. You can +redirect Python's i/o to _any_ object that supports read and write, so +all you need is a Python object (defined in your extension module) that +contains read() and write() methods. +

+ +Edit this entry / +Log info + +/ Last changed on Thu Jan 31 16:29:34 2002 by +Victor Kryukov +

+ +


+

8.17. Setting up IIS 5 to use Python for CGI

+In order to set up Internet Information Services 5 to use Python for CGI processing, please see the following links: +

+http://www.e-coli.net/pyiis_server.html (for Win2k Server) +http://www.e-coli.net/pyiis.html (for Win2k pro) +

+ +Edit this entry / +Log info + +/ Last changed on Fri Mar 22 22:05:51 2002 by +douglas savitsky +

+ +


+

8.18. How do I run a Python program under Windows?

+This is not necessarily quite the straightforward question it appears +to be. If you are already familiar with running programs from the +Windows command line then everything will seem really easy and +obvious. If your computer experience is limited then you might need a +little more guidance. Also there are differences between Windows 95, +98, NT, ME, 2000 and XP which can add to the confusion. You might +think of this as "why I pay software support charges" if you have a +helpful and friendly administrator to help you set things up without +having to understand all this yourself. If so, then great! Show them +this page and it should be a done deal. +

+Unless you use some sort of integrated development environment (such +as PythonWin or IDLE, to name only two in a growing family) then you +will end up typing Windows commands into what is variously referred +to as a "DOS window" or "Command prompt window". Usually you can +create such a window from your Start menu (under Windows 2000 I use +"Start | Programs | Accessories | Command Prompt"). You should be +able to recognize when you have started such a window because you will +see a Windows "command prompt", which usually looks like this: +

+

+    C:\>
+
+The letter may be different, and there might be other things after it, +so you might just as easily see something like: +

+

+    D:\Steve\Projects\Python>
+
+depending on how your computer has been set up and what else you have +recently done with it. Once you have started such a window, you are +well on the way to running Python programs. +

+You need to realize that your Python scripts have to be processed by +another program, usually called the "Python interpreter". The +interpreter reads your script, "compiles" it into "Python bytecodes" +(which are instructions for an imaginary computer known as the "Python +Virtual Machine") and then executes the bytecodes to run your +program. So, how do you arrange for the interpreter to handle your +Python? +

+First, you need to make sure that your command window recognises the +word "python" as an instruction to start the interpreter. If you have +opened a command window, you should try entering the command: +

+

+    python
+
+and hitting return. If you then see something like: +

+

+    Python 2.2 (#28, Dec 21 2001, 12:21:22) [MSC 32 bit (Intel)] on win32
+    Type "help", "copyright", "credits" or "license" for more information.
+    >>>
+
+then this part of the job has been correctly managed during Python's +installation process, and you have started the interpreter in +"interactive mode". That means you can enter Python statements or +expressions interactively and have them executed or evaluated while +you wait. This is one of Python's strongest features, but it takes a +little getting used to. Check it by entering a few expressions of your +choice and seeing the results... +

+

+    >>> print "Hello"
+    Hello
+    >>> "Hello" * 3
+    HelloHelloHello
+
+When you want to end your interactive Python session, enter a +terminator (hold the Ctrl key down while you enter a Z, then hit the +"Enter" key) to get back to your Windows command prompt. You may also +find that you have a Start-menu entry such as "Start | Programs | +Python 2.2 | Python (command line)" that results in you seeing the +">>>" prompt in a new window. If so, the window will disappear after +you enter the terminator -- Windows runs a single "python" command in +the window, which terminates when you terminate the interpreter. +

+If the "python" command, instead of displaying the interpreter prompt ">>>", gives you a message like +

+

+    'python' is not recognized as an internal or external command,
+    operable program or batch file.
+
+or +

+

+    Bad command or filename
+
+then you need to make sure that your computer knows where to find the +Python interpreter. To do this you will have to modify a setting +called the PATH, which is a just list of directories where Windows +will look for programs. Rather than just enter the right command every +time you create a command window, you should arrange for Python's +installation directory to be added to the PATH of every command window +as it starts. If you installed Python fairly recently then the command +

+

+    dir C:\py*
+
+will probably tell you where it is installed. Alternatively, perhaps +you made a note. Otherwise you will be reduced to a search of your +whole disk ... break out the Windows explorer and use "Tools | Find" +or hit the "Search" button and look for "python.exe". Suppose you +discover that Python is installed in the C:\Python22 directory (the +default at the time of writing) then you should make sure that +entering the command +

+

+    c:\Python22\python
+
+starts up the interpreter as above (and don't forget you'll need a +"CTRL-Z" and an "Enter" to get out of it). Once you have verified the +directory, you need to add it to the start-up routines your computer +goes through. For older versions of Windows the easiest way to do +this is to edit the C:\AUTOEXEC.BAT file. You would want to add a line +like the following to AUTOEXEC.BAT: +

+

+    PATH C:\Python22;%PATH%
+
+For Windows NT, 2000 and (I assume) XP, you will need to add a string +such as +

+

+    ;C:\Python22
+
+to the current setting for the PATH environment variable, which you +will find in the properties window of "My Computer" under the +"Advanced" tab. Note that if you have sufficient privilege you might +get a choice of installing the settings either for the Current User or +for System. The latter is preferred if you want everybody to be able +to run Python on the machine. +

+If you aren't confident doing any of these manipulations yourself, ask +for help! At this stage you may or may not want to reboot your system +to make absolutely sure the new setting has "taken" (don't you love +the way Windows gives you these freqeuent coffee breaks). You probably +won't need to for Windows NT, XP or 2000. You can also avoid it in +earlier versions by editing the file C:\WINDOWS\COMMAND\CMDINIT.BAT +instead of AUTOEXEC.BAT. +

+You should now be able to start a new command window, enter +

+

+    python
+
+at the "C:>" (or whatever) prompt, and see the ">>>" prompt that +indicates the Python interpreter is reading interactive commands. +

+Let's suppose you have a program called "pytest.py" in directory +"C:\Steve\Projects\Python". A session to run that program might look +like this: +

+

+    C:\> cd \Steve\Projects\Python
+    C:\Steve\Projects\Python> python pytest.py
+
+Because you added a file name to the command to start the interpreter, +when it starts up it reads the Python script in the named file, +compiles it, executes it, and terminates (so you see another "C:\>" +prompt). You might also have entered +

+

+    C:\> python \Steve\Projects\Python\pytest.py
+
+if you hadn't wanted to change your current directory. +

+Under NT, 2000 and XP you may well find that the installation process +has also arranged that the command +

+

+    pytest.py
+
+(or, if the file isn't in the current directory) +

+

+    C:\Steve\Projects\Python\pytest.py
+
+will automatically recognize the ".py" extension and run the Python +interpreter on the named file. Using this feature is fine, but some +versions of Windows have bugs which mean that this form isn't exactly +equivalent to using the interpreter explicitly, so be careful. Easier +to remember, for now, that +

+

+    python C:\Steve\Projects\Python\pytest.py
+
+works pretty close to the same, and redirection will work (more) +reliably. +

+The important things to remember are: +

+1. Start Python from the Start Menu, or make sure the PATH is set +correctly so Windows can find the Python interpreter. +

+

+    python
+
+should give you a '>>>" prompt from the Python interpreter. Don't +forget the CTRL-Z and ENTER to terminate the interpreter (and, if you +started the window from the Start Menu, make the window disappear). +

+2. Once this works, you run programs with commands: +

+

+    python {program-file}
+
+3. When you know the commands to use you can build Windows shortcuts +to run the Python interpreter on any of your scripts, naming +particular working directories, and adding them to your menus, but +that's another lessFAQ. Take a look at +

+

+    python --help
+
+if your needs are complex. +

+4. Interactive mode (where you see the ">>>" prompt) is best used +not for running programs, which are better executed as in steps 2 +and 3, but for checking that individual statements and expressions do +what you think they will, and for developing code by experiment. +

+ +Edit this entry / +Log info + +/ Last changed on Tue Aug 20 16:19:53 2002 by +GvR +

+ +


+Python home / +Python FAQ Wizard 1.0.3 / +Feedback to GvR +

Python Powered
+ + --- python2.7-2.7.orig/debian/README.Tk +++ python2.7-2.7/debian/README.Tk @@ -0,0 +1,8 @@ +Tkinter documentation can be found at + + http://www.pythonware.com/library/index.htm + +more specific: + + http://www.pythonware.com/library/tkinter/introduction/index.htm + http://www.pythonware.com/library/tkinter/an-introduction-to-tkinter.pdf --- python2.7-2.7.orig/debian/mkbinfmt.py +++ python2.7-2.7/debian/mkbinfmt.py @@ -0,0 +1,17 @@ +# mkbinfmt.py +import imp, sys, string, os.path + +magic = string.join(["\\x%.2x" % ord(c) for c in imp.get_magic()],"") + +name = sys.argv[1] + +binfmt = '''\ +package %s +interpreter /usr/bin/%s +magic %s\ +''' % (name, name, magic) + +#filename = '/usr/share/binfmts/' + name +#open(filename,'w+').write(binfmt) + +print binfmt --- python2.7-2.7.orig/debian/compat +++ python2.7-2.7/debian/compat @@ -0,0 +1 @@ +5 --- python2.7-2.7.orig/debian/control.in +++ python2.7-2.7/debian/control.in @@ -0,0 +1,113 @@ +Source: @PVER@ +Section: python +Priority: optional +Maintainer: Matthias Klose +Build-Depends: debhelper (>= 5), quilt, autoconf, libreadline-dev, libncursesw5-dev (>= 5.3), tk8.5-dev, zlib1g-dev, blt-dev (>= 2.4z), libssl-dev, libexpat1-dev, sharutils, libbz2-dev, libbluetooth-dev [!hurd-i386 !kfreebsd-i386 !kfreebsd-amd64], locales [!armel !avr32 !hppa !ia64 !mipsel], libsqlite3-dev, libffi-dev (>= 3.0.5), mime-support, libgpm2 [!hurd-i386 !kfreebsd-i386 !kfreebsd-amd64], netbase, lsb-release, bzip2, libdb4.8-dev, gdb, python +Build-Depends-Indep: python-sphinx +Build-Conflicts: tcl8.3-dev, tk8.3-dev, tcl8.4-dev, tk8.4-dev, @PVER@-xml, python-xml, autoconf2.13 +XS-Python-Version: @VER@ +Standards-Version: 3.9.1 +Vcs-Browser: https://code.launchpad.net/~doko/python/pkg@VER@-debian +Vcs-Bzr: http://bazaar.launchpad.net/~doko/python/pkg@VER@-debian + +Package: @PVER@ +Architecture: any +Priority: @PRIO@ +Depends: @PVER@-minimal (= ${binary:Version}), mime-support, ${shlibs:Depends}, ${misc:Depends} +Suggests: @PVER@-doc, @PVER@-profiler, binutils +Provides: @PVER@-cjkcodecs, @PVER@-ctypes, @PVER@-elementtree, @PVER@-celementtree, @PVER@-wsgiref +XB-Python-Version: @VER@ +Description: An interactive high-level object-oriented language (version @VER@) + Version @VER@ of the high-level, interactive object oriented language, + includes an extensive class library with lots of goodies for + network programming, system administration, sounds and graphics. + +Package: @PVER@-minimal +Architecture: any +Priority: @MINPRIO@ +Depends: ${shlibs:Depends}, ${misc:Depends} +Recommends: @PVER@ +Suggests: binfmt-support +Replaces: @PVER@ (<< 2.7~rc2-3) +Conflicts: binfmt-support (<< 1.1.2) +XB-Python-Runtime: @PVER@ +XB-Python-Version: @VER@ +Description: A minimal subset of the Python language (version @VER@) + This package contains the interpreter and some essential modules. It can + be used in the boot process for some basic tasks. + See /usr/share/doc/@PVER@-minimal/README.Debian for a list of the modules + contained in this package. + +Package: lib@PVER@ +Architecture: any +Section: libs +Priority: @PRIO@ +Depends: @PVER@ (= ${binary:Version}), ${shlibs:Depends}, ${misc:Depends} +Replaces: @PVER@ (<< 2.6) +Description: Shared Python runtime library (version @VER@) + Version @VER@ of the high-level, interactive object oriented language, + includes an extensive class library with lots of goodies for + network programming, system administration, sounds and graphics. + . + This package contains the shared runtime library, normally not needed + for programs using the statically linked interpreter. + +Package: @PVER@-examples +Architecture: all +Depends: @PVER@ (>= ${source:Version}), ${misc:Depends} +Description: Examples for the Python language (v@VER@) + Examples, Demos and Tools for Python (v@VER@). These are files included in + the upstream Python distribution (v@VER@). + +Package: @PVER@-dev +Architecture: any +Depends: @PVER@ (= ${binary:Version}), lib@PVER@ (= ${binary:Version}), libexpat1-dev, libssl-dev, ${shlibs:Depends}, ${misc:Depends} +Recommends: libc6-dev | libc-dev +Replaces: @PVER@ (<< 2.7-3) +Description: Header files and a static library for Python (v@VER@) + Header files, a static library and development tools for building + Python (v@VER@) modules, extending the Python interpreter or embedding + Python (v@VER@) in applications. + . + Maintainers of Python packages should read README.maintainers. + +Package: idle-@PVER@ +Architecture: all +Depends: @PVER@, python-tk (>= 2.6~a3), @PVER@-tk, ${misc:Depends} +Enhances: @PVER@ +Replaces: @PVER@ (<< 2.6.1-2) +XB-Python-Version: @VER@ +Description: An IDE for Python (v@VER@) using Tkinter + IDLE is an Integrated Development Environment for Python (v@VER@). + IDLE is written using Tkinter and therefore quite platform-independent. + +Package: @PVER@-doc +Section: doc +Architecture: all +Depends: libjs-jquery, ${misc:Depends} +Suggests: @PVER@ +Description: Documentation for the high-level object-oriented language Python (v@VER@) + These is the official set of documentation for the interactive high-level + object-oriented language Python (v@VER@). All documents are provided + in HTML format. The package consists of ten documents: + . + * What's New in Python@VER@ + * Tutorial + * Python Library Reference + * Macintosh Module Reference + * Python Language Reference + * Extending and Embedding Python + * Python/C API Reference + * Installing Python Modules + * Documenting Python + * Distributing Python Modules + +Package: @PVER@-dbg +Section: debug +Architecture: any +Priority: extra +Depends: @PVER@ (>= ${binary:Version}), ${shlibs:Depends}, ${misc:Depends} +Suggests: python-gdbm-dbg, python-tk-dbg +Description: Debug Build of the Python Interpreter (version @VER@) + Python interpreter configured with --pydebug. Dynamically loaded modules are + searched in /usr/lib/@PVER@/lib-dynload/debug first. --- python2.7-2.7.orig/debian/PVER-doc.doc-base.PVER-new.in +++ python2.7-2.7/debian/PVER-doc.doc-base.PVER-new.in @@ -0,0 +1,10 @@ +Document: @PVER@-new +Title: What's new in Python @VER@ +Author: A.M. Kuchling +Abstract: This documents lists new features and changes worth mentioning + in Python @VER@. +Section: Programming/Python + +Format: HTML +Index: /usr/share/doc/@PVER@/html/whatsnew/@VER@.html +Files: /usr/share/doc/@PVER@/html/whatsnew/@VER@.html --- python2.7-2.7.orig/debian/PVER-doc.doc-base.PVER-ext.in +++ python2.7-2.7/debian/PVER-doc.doc-base.PVER-ext.in @@ -0,0 +1,16 @@ +Document: @PVER@-ext +Title: Extending and Embedding the Python Interpreter (v@VER@) +Author: Guido van Rossum +Abstract: This document describes how to write modules in C or C++ to extend + the Python interpreter with new modules. Those modules can define + new functions but also new object types and their methods. The + document also describes how to embed the Python interpreter in + another application, for use as an extension language. Finally, + it shows how to compile and link extension modules so that they + can be loaded dynamically (at run time) into the interpreter, if + the underlying operating system supports this feature. +Section: Programming/Python + +Format: HTML +Index: /usr/share/doc/@PVER@/html/extending/index.html +Files: /usr/share/doc/@PVER@/html/extending/*.html --- python2.7-2.7.orig/debian/PVER-dbg.README.Debian.in +++ python2.7-2.7/debian/PVER-dbg.README.Debian.in @@ -0,0 +1,51 @@ +Contents of the @PVER@-dbg package +------------------------------------- + +For debugging python and extension modules, you may want to add the contents +of /usr/share/doc/@PVER@/gdbinit to your ~/.gdbinit file. + +@PVER@-dbg contains two sets of packages: + + - debugging symbols for the standard @PVER@ build. When this package + is installed, gdb will automatically load up the debugging symbols + from it when debugging @PVER@ or one of the included extension + modules. + + - a separate @PVER@-dbg binary, configured --with-pydebug, enabling the + additional debugging code to help debug memory management problems. + +For the latter, all extension modules have to be recompiled to +correctly load with an pydebug enabled build. + + +Debian and Ubuntu specific changes to the debug interpreter +----------------------------------------------------------- +The python2.4 and python2.5 packages in Ubuntu feisty are modified to +first look for extension modules under a different name. + + normal build: foo.so + debug build: foo_d.so foo.so + +This naming schema allows installation of the extension modules into +the same path (The naming is directly taken from the Windows builds +which already uses this naming scheme). + +See https://wiki.ubuntu.com/PyDbgBuilds for more information. + + +Using the python-dbg builds +--------------------------- + + * Call the python-dbg or the pythonX.Y-dbg binaries instead of the + python or pythonX.Y binaries. + + * Properties of the debug build are described in + /usr/share/doc/@PVER@/SpecialBuilds.txt.gz. + The debug interpreter is built with Py_DEBUG defined. + + * From SpecialBuilds.txt: This is what is generally meant by "a debug + build" of Python. Py_DEBUG implies LLTRACE, Py_REF_DEBUG, + Py_TRACE_REFS, and PYMALLOC_DEBUG (if WITH_PYMALLOC is enabled). + In addition, C assert()s are enabled (via the C way: by not defining + NDEBUG), and some routines do additional sanity checks inside + "#ifdef Py_DEBUG" blocks. --- python2.7-2.7.orig/debian/libPVER.symbols.in +++ python2.7-2.7/debian/libPVER.symbols.in @@ -0,0 +1,3 @@ +libpython@VER@.so.1.0 libpython@VER@ #MINVER# + Py_InitModule4@Base @VER@ +#include "libpython.symbols" --- python2.7-2.7.orig/debian/source.lintian-overrides.in +++ python2.7-2.7/debian/source.lintian-overrides.in @@ -0,0 +1,5 @@ +# this is conditional in the rules file +@PVER@ source: debhelper-script-needs-versioned-build-depends dh_icons (>= 5.0.51~) + +# generated during the build +@PVER@ source: quilt-build-dep-but-no-series-file --- python2.7-2.7.orig/debian/rules +++ python2.7-2.7/debian/rules @@ -0,0 +1,1035 @@ +#!/usr/bin/make -f +# Sample debian/rules that uses debhelper. GNU copyright 1997 by Joey Hess. + +unexport LANG LC_ALL LC_CTYPE LC_COLLATE LC_TIME LC_NUMERIC LC_MESSAGES + +export SHELL = /bin/bash + +# Uncomment this to turn on verbose mode. +#export DH_VERBOSE=1 + +DEB_HOST_ARCH ?= $(shell dpkg-architecture -qDEB_HOST_ARCH) +DEB_HOST_ARCH_OS ?= $(shell dpkg-architecture -qDEB_HOST_ARCH_OS) + +changelog_values := $(shell dpkg-parsechangelog \ + | awk '/^(Version|Source):/ {print $$2}') +PKGSOURCE := $(word 1, $(changelog_values)) +PKGVERSION := $(word 2, $(changelog_values)) + +on_buildd := $(shell [ -f /CurrentlyBuilding -o "$$LOGNAME" = buildd ] && echo yes) + +ifneq (,$(findstring nocheck, $(DEB_BUILD_OPTIONS))) + WITHOUT_CHECK := yes +endif +WITHOUT_BENCH := +ifneq (,$(findstring nobench, $(DEB_BUILD_OPTIONS))) + WITHOUT_BENCH := yes +endif +ifeq ($(on_buildd),yes) + ifneq (,$(findstring $(DEB_HOST_ARCH), hppa mips mipsel s390)) + WITHOUT_CHECK := yes + endif +endif + +COMMA = , +ifneq (,$(filter parallel=%,$(subst $(COMMA), ,$(DEB_BUILD_OPTIONS)))) + NJOBS := -j $(subst parallel=,,$(filter parallel=%,$(subst $(COMMA), ,$(DEB_BUILD_OPTIONS)))) +endif + +distribution := $(shell lsb_release -is) +#distribution := Ubuntu + +export VER=2.7 +export NVER=2.8 +export PVER=python2.7 +export PRIORITY=$(shell echo $(VER) | tr -d '.')0 + +PREVVER := $(shell awk '/^python/ && NR > 1 {print substr($$2,2,length($$2)-2); exit}' debian/changelog) + +# default versions are built from the python-defaults source package +# keep the definition to adjust package priorities. +DEFAULT_VERSION = no +STATIC_PYTHON=yes + +MIN_MODS := $(shell awk '/^ / && $$2 == "module" { print $$1 }' \ + debian/PVER-minimal.README.Debian.in) +MIN_EXTS := $(shell awk '/^ / && $$2 == "extension" { print $$1 }' \ + debian/PVER-minimal.README.Debian.in) +MIN_BUILTINS := $(shell awk '/^ / && $$2 == "builtin" { print $$1 }' \ + debian/PVER-minimal.README.Debian.in) +MIN_PACKAGES := $(shell awk '/^ / && $$2 == "package" { print $$1 }' \ + debian/PVER-minimal.README.Debian.in) +MIN_ENCODINGS := $(foreach i, \ + $(filter-out \ + big5% bz2% cp932.py cp949.py cp950.py euc_% \ + gb% iso2022% johab.py shift_jis% , \ + $(shell cd Lib/encodings && echo *.py)), \ + encodings/$(i)) \ + codecs.py stringprep.py + +with_tk := no +with_gdbm := no +with_interp := static +#with_interp := shared + +build_target := build-all +install_target := install + +PY_INTERPRETER = /usr/bin/python$(VER) + +ifeq ($(DEFAULT_VERSION),yes) + PY_PRIO = standard + #PYSTDDEP = , python (>= $(VER)) + ifeq ($(distribution),Ubuntu) + PY_MINPRIO = required + else + PY_MINPRIO = $(PY_PRIO) + endif +else + PY_PRIO = optional + PY_MINPRIO = $(PY_PRIO) +endif +with_fpectl = yes + +CC = gcc + +# on alpha, use -O2 only, use -mieee +ifeq ($(DEB_HOST_ARCH),alpha) + OPTSETTINGS = OPT="-g -O2 -fwrapv -mieee -Wall -Wstrict-prototypes" + OPTDEBUGSETTINGS = OPT="-g -O0 -fwrapv -mieee -Wall -Wstrict-prototypes" +endif +ifeq ($(DEB_HOST_ARCH),m68k) + OPTSETTINGS = OPT="-fwrapv -g -O2 -Wall -Wstrict-prototypes" +endif + +PWD := $(shell pwd) +buildd_static := $(CURDIR)/build-static +buildd_shared := $(CURDIR)/build-shared +buildd_debug := $(CURDIR)/build-debug +buildd_shdebug := $(CURDIR)/build-shdebug + +d := debian/tmp +scriptdir = usr/share/lib/python$(VER) +scriptdir = usr/share/python$(VER) +scriptdir = usr/lib/python$(VER) + +# package names and directories +p_base := $(PVER) +p_min := $(PVER)-minimal +p_lib := lib$(PVER) +p_tk := $(PVER)-tk +p_gdbm := $(PVER)-gdbm +p_dev := $(PVER)-dev +p_exam := $(PVER)-examples +p_idle := idle-$(PVER) +p_doc := $(PVER)-doc +p_dbg := $(PVER)-dbg + +d_base := debian/$(p_base) +d_min := debian/$(p_min) +d_lib := debian/$(p_lib) +d_tk := debian/$(p_tk) +d_gdbm := debian/$(p_gdbm) +d_dev := debian/$(p_dev) +d_exam := debian/$(p_exam) +d_idle := debian/$(p_idle) +d_doc := debian/$(p_doc) +d_dbg := debian/$(p_dbg) + +# profiled build fails on most architectures ... +ifneq (,$(filter $(DEB_HOST_ARCH), alpha amd64 armel hppa i386 ia64 lpia mips mipsel s390 sparc hurd-i386 kfreebsd-i386 kfreebsd-amd64)) + make_build_target = +else + make_build_target = profile-opt +endif + +build: $(build_target) +build-all: stamps/stamp-build +stamps/stamp-build: stamps/stamp-build-static stamps/stamp-build-shared stamps/stamp-build-debug stamps/stamp-build-shared-debug stamps/stamp-mincheck stamps/stamp-check stamps/stamp-pystone stamps/stamp-pybench + touch stamps/stamp-build + +PROFILE_EXCLUDES = test_compiler test_distutils test_platform test_subprocess \ + test_pstats test_profile test_multiprocessing test_cprofile \ + test_thread test_threaded_import test_threadedtempfile \ + test_socketserver \ + test_threading test_threading_local test_threadsignals \ + test_dbm_dumb test_dbm_ndbm test_pydoc test_sundry test_gdb \ + +ifneq (,$(filter $(DEB_HOST_ARCH), arm armel)) + PROFILE_EXCLUDES += test_float +endif +PROFILE_EXCLUDES += test_zipfile +PROFILE_EXCLUDES += test_xmlrpc + +PROFILE_TASK = ../Lib/test/regrtest.py \ + -x $(sort $(TEST_EXCLUDES) $(PROFILE_EXCLUDES)) + +stamps/stamp-build-static: stamps/stamp-configure-static + dh_testdir + $(MAKE) $(NJOBS) -C $(buildd_static) \ + PROFILE_TASK='$(PROFILE_TASK)' $(make_build_target) + touch stamps/stamp-build-static + +stamps/stamp-build-shared: stamps/stamp-configure-shared + dh_testdir + $(MAKE) $(NJOBS) -C $(buildd_shared) +# : # build the shared library +# $(MAKE) $(NJOBS) -C $(buildd_shared) \ +# libpython$(VER).so + : # build a static library with PIC objects + $(MAKE) $(NJOBS) -C $(buildd_shared) \ + LIBRARY=libpython$(VER)-pic.a libpython$(VER)-pic.a + touch stamps/stamp-build-shared + +stamps/stamp-build-debug: stamps/stamp-configure-debug + dh_testdir + $(MAKE) $(NJOBS) -C $(buildd_debug) + touch stamps/stamp-build-debug + +stamps/stamp-build-shared-debug: stamps/stamp-configure-shared-debug + dh_testdir + : # build the shared debug library + $(MAKE) $(NJOBS) -C $(buildd_shdebug) \ + libpython$(VER)_d.so + touch stamps/stamp-build-shared-debug + +common_configure_args = \ + --prefix=/usr \ + --enable-ipv6 \ + --enable-unicode=ucs4 \ + --with-dbmliborder=bdb \ + --with-system-expat + +ifeq ($(DEB_HOST_ARCH), avr32) + common_configure_args += --without-ffi +else + common_configure_args += --with-system-ffi +endif + +ifeq ($(with_fpectl),yes) + common_configure_args += \ + --with-fpectl +endif + +stamps/stamp-configure-shared: stamps/stamp-patch + rm -rf $(buildd_shared) + mkdir -p $(buildd_shared) + cd $(buildd_shared) && \ + CC="$(CC)" $(OPTSETTINGS) \ + ../configure \ + --enable-shared \ + $(common_configure_args) + egrep \ + "^#($$(awk '$$2 ~ /^extension$$/ {print $$1}' debian/PVER-minimal.README.Debian.in | tr '\012' '|')XX)" \ + Modules/Setup.dist \ + | sed -e 's/^#//' -e 's/-Wl,-Bdynamic//;s/-Wl,-Bstatic//' \ + >> $(buildd_shared)/Modules/Setup.local + cd $(buildd_shared) && \ + ../Modules/makesetup -c ../Modules/config.c.in -s Modules \ + Modules/Setup.config Modules/Setup.local Modules/Setup + mv $(buildd_shared)/config.c $(buildd_shared)/Modules/ + + touch stamps/stamp-configure-shared + +stamps/stamp-configure-static: stamps/stamp-patch + rm -rf $(buildd_static) + mkdir -p $(buildd_static) + cd $(buildd_static) && \ + CC="$(CC)" $(OPTSETTINGS) \ + ../configure \ + $(common_configure_args) + egrep \ + "^#($$(awk '$$2 ~ /^extension$$/ {print $$1}' debian/PVER-minimal.README.Debian.in | tr '\012' '|')XX)" \ + Modules/Setup.dist | sed 's/^#//' \ + >> $(buildd_static)/Modules/Setup.local + cd $(buildd_static) && \ + ../Modules/makesetup -c ../Modules/config.c.in -s Modules \ + Modules/Setup.config Modules/Setup.local Modules/Setup + + : # apply workaround for missing os.fsync + sed 's/HAVE_SYNC/HAVE_FSYNC/g' $(buildd_static)/pyconfig.h \ + > $(buildd_static)/pyconfig.h.new + touch -r $(buildd_static)/pyconfig.h $(buildd_static)/pyconfig.h.new + mv -f $(buildd_static)/pyconfig.h.new $(buildd_static)/pyconfig.h + mv $(buildd_static)/config.c $(buildd_static)/Modules/ + + touch stamps/stamp-configure-static + +stamps/stamp-configure-debug: stamps/stamp-patch + rm -rf $(buildd_debug) + mkdir -p $(buildd_debug) + cd $(buildd_debug) && \ + CC="$(CC)" $(OPTDEBUGSETTINGS) CFLAGS="" CXXFLAGS="" \ + ../configure \ + $(common_configure_args) \ + --with-pydebug + egrep \ + "^#($$(awk '$$2 ~ /^extension$$/ {print $$1}' debian/PVER-minimal.README.Debian.in | tr '\012' '|')XX)" \ + Modules/Setup.dist | sed 's/^#//' \ + >> $(buildd_debug)/Modules/Setup.local + cd $(buildd_debug) && \ + ../Modules/makesetup -c ../Modules/config.c.in -s Modules \ + Modules/Setup.config Modules/Setup.local Modules/Setup + mv $(buildd_debug)/config.c $(buildd_debug)/Modules/ + + : # apply workaround for missing os.fsync + sed 's/HAVE_SYNC/HAVE_FSYNC/g' $(buildd_debug)/pyconfig.h \ + > $(buildd_debug)/pyconfig.h.new + touch -r $(buildd_debug)/pyconfig.h $(buildd_debug)/pyconfig.h.new + mv -f $(buildd_debug)/pyconfig.h.new $(buildd_debug)/pyconfig.h + + touch stamps/stamp-configure-debug + +stamps/stamp-configure-shared-debug: stamps/stamp-patch + rm -rf $(buildd_shdebug) + mkdir -p $(buildd_shdebug) + cd $(buildd_shdebug) && \ + CC="$(CC)" $(OPTDEBUGSETTINGS) CFLAGS="" CXXFLAGS="" \ + ../configure \ + $(common_configure_args) \ + --enable-shared \ + --with-pydebug + egrep \ + "^#($$(awk '$$2 ~ /^extension$$/ {print $$1}' debian/PVER-minimal.README.Debian.in | tr '\012' '|')XX)" \ + Modules/Setup.dist \ + | sed -e 's/^#//' -e 's/-Wl,-Bdynamic//;s/-Wl,-Bstatic//' \ + >> $(buildd_shdebug)/Modules/Setup.local + cd $(buildd_shdebug) && \ + ../Modules/makesetup -c ../Modules/config.c.in -s Modules \ + Modules/Setup.config Modules/Setup.local Modules/Setup + mv $(buildd_shdebug)/config.c $(buildd_shdebug)/Modules/ + + : # apply workaround for missing os.fsync + sed 's/HAVE_SYNC/HAVE_FSYNC/g' $(buildd_shdebug)/pyconfig.h \ + > $(buildd_shdebug)/pyconfig.h.new + touch -r $(buildd_shdebug)/pyconfig.h $(buildd_shdebug)/pyconfig.h.new + mv -f $(buildd_shdebug)/pyconfig.h.new $(buildd_shdebug)/pyconfig.h + + touch stamps/stamp-configure-shared-debug + +stamps/stamp-mincheck: stamps/stamp-build-static debian/PVER-minimal.README.Debian.in + for m in $(MIN_MODS) $(MIN_PACKAGES) $(MIN_EXTS) $(MIN_BUILTINS); do \ + echo "import $$m"; \ + done > $(buildd_static)/minmods.py + cd $(buildd_static) && ./python ../debian/pymindeps.py minmods.py \ + > $(buildd_static)/mindeps.txt + if [ -x /usr/bin/dot ]; then \ + python debian/depgraph.py < $(buildd_static)/mindeps.txt \ + > $(buildd_static)/mindeps.dot; \ + dot -Tpng -o $(buildd_static)/mindeps.png \ + $(buildd_static)/mindeps.dot; \ + else true; fi + cd $(buildd_static) && ./python ../debian/mincheck.py \ + minmods.py mindeps.txt + touch stamps/stamp-mincheck + +TEST_RESOURCES = all +ifeq ($(on_buildd),yes) + TEST_RESOURCES := $(TEST_RESOURCES),-network,-urlfetch +endif +TESTOPTS = -w -l -u$(TEST_RESOURCES) +TEST_EXCLUDES = +# not built from this source +TEST_EXCLUDES += test_bsddb3 +# profile.py and pstats.py removed from sources +TEST_EXCLUDES += test_pstats test_profile test_cprofile +ifeq ($(on_buildd),yes) + TEST_EXCLUDES += test_tcl test_codecmaps_cn test_codecmaps_hk \ + test_codecmaps_jp test_codecmaps_kr test_codecmaps_tw \ + test_normalization test_ossaudiodev +endif +ifeq (,$(wildcard /dev/dsp)) + TEST_EXCLUDES += test_linuxaudiodev test_ossaudiodev +endif +ifneq (,$(filter $(DEB_HOST_ARCH), hppa)) + TEST_EXCLUDES += test_fork1 test_multiprocessing test_socketserver test_threading test_wait3 test_wait4 test_gdb +endif +ifneq (,$(filter $(DEB_HOST_ARCH), arm avr32)) + TEST_EXCLUDES += test_ctypes +endif +ifneq (,$(filter $(DEB_HOST_ARCH), m68k avr32)) + TEST_EXCLUDES += test_bsddb3 +endif +ifneq (,$(filter $(DEB_HOST_ARCH), arm armel avr32 m68k)) + ifeq ($(on_buildd),yes) + TEST_EXCLUDES += test_compiler + endif +endif +ifneq (,$(filter $(DEB_HOST_ARCH), hurd-i386)) + TEST_EXCLUDES += test_io test_random test_signal test_socketserver test_ssl test_threading +endif +ifneq (,$(TEST_EXCLUDES)) + TESTOPTS += -x $(sort $(TEST_EXCLUDES)) +endif + +ifneq (,$(wildcard /usr/bin/localedef)) + SET_LOCPATH = LOCPATH=$(CURDIR)/locales +endif + +stamps/stamp-check: +ifeq ($(WITHOUT_CHECK),yes) + echo "check run disabled for this build" > $(buildd_static)/test_results +else + : # build locales needed by the testsuite + rm -rf locales + mkdir locales + if which localedef >/dev/null 2>&1; then \ + sh debian/locale-gen; \ + fi + + @echo ========== test environment ============ + @env + @echo ======================================== + + @echo "BEGIN test static" + -time \ + $(SET_LOCPATH) \ + $(MAKE) -C $(buildd_static) test \ + TESTOPTS="$(TESTOPTS)" 2>&1 \ + | tee $(buildd_static)/test_results + @echo "END test static" + @echo "BEGIN test shared" + -time \ + $(SET_LOCPATH) \ + $(MAKE) -C $(buildd_shared) test \ + TESTOPTS="$(TESTOPTS)" 2>&1 \ + | tee $(buildd_shared)/test_results + @echo "END test shared" + ifeq (0,1) + ifeq (,$(findstring $(DEB_HOST_ARCH), alpha)) + @echo "BEGIN test debug" + -time \ + $(SET_LOCPATH) \ + $(MAKE) -C $(buildd_debug) test \ + TESTOPTS="$(TESTOPTS)" 2>&1 \ + | tee $(buildd_debug)/test_results + @echo "END test debug" + endif + endif +endif + cp -p $(buildd_static)/test_results debian/ + touch stamps/stamp-check + +stamps/stamp-pystone: + @echo "BEGIN pystone static" + cd $(buildd_static) && ./python ../Lib/test/pystone.py + cd $(buildd_static) && ./python ../Lib/test/pystone.py + @echo "END pystone static" + @echo "BEGIN pystone shared" + cd $(buildd_shared) \ + && LD_LIBRARY_PATH=$${LD_LIBRARY_PATH:+$$LD_LIBRARY_PATH:}. ./python ../Lib/test/pystone.py + cd $(buildd_shared) \ + && LD_LIBRARY_PATH=$${LD_LIBRARY_PATH:+$$LD_LIBRARY_PATH:}. ./python ../Lib/test/pystone.py + @echo "END pystone shared" + @echo "BEGIN pystone debug" + cd $(buildd_debug) && ./python ../Lib/test/pystone.py + cd $(buildd_debug) && ./python ../Lib/test/pystone.py + @echo "END pystone debug" + touch stamps/stamp-pystone + +#ifeq (,$(filter $(DEB_HOST_ARCH), arm armel avr32 hppa mips mipsel m68k)) + pybench_options = -C 2 -n 5 -w 4 +#endif + +stamps/stamp-pybench: +ifeq ($(WITHOUT_BENCH),yes) + echo "pybench run disabled for this build" > $(buildd_static)/pybench.log +else + @echo "BEGIN pybench static" + cd $(buildd_static) \ + && time ./python ../Tools/pybench/pybench.py -f run1.pybench $(pybench_options) + cd $(buildd_static) \ + && ./python ../Tools/pybench/pybench.py -f run2.pybench -c run1.pybench $(pybench_options) + @echo "END pybench static" + @echo "BEGIN pybench shared" + cd $(buildd_shared) \ + && LD_LIBRARY_PATH=$${LD_LIBRARY_PATH:+$$LD_LIBRARY_PATH:}. \ + ./python ../Tools/pybench/pybench.py -f run1.pybench $(pybench_options) + cd $(buildd_shared) \ + && LD_LIBRARY_PATH=$${LD_LIBRARY_PATH:+$$LD_LIBRARY_PATH:}. \ + ./python ../Tools/pybench/pybench.py -f run2.pybench -c run1.pybench $(pybench_options) + @echo "END pybench shared" + @echo "BEGIN shared/static comparision" + $(buildd_static)/python Tools/pybench/pybench.py \ + -s $(buildd_static)/run2.pybench -c $(buildd_shared)/run2.pybench \ + | tee $(buildd_static)/pybench.log + @echo "END shared/static comparision" +endif + touch stamps/stamp-pybench + +minimal-test: + rm -rf mintest + mkdir -p mintest/lib mintest/dynlib mintest/testlib mintest/all-lib + cp -p $(buildd_static)/python mintest/ + cp -p $(foreach i,$(MIN_MODS),Lib/$(i).py) \ + mintest/lib/ + cp -a $(foreach i,$(MIN_PACKAGES),Lib/$(i)) \ + mintest/lib/ +# cp -p $(foreach i,$(MIN_EXTS),$(buildd_static)/build/lib*/$(i).so) \ +# mintest/dynlib/ + cp -p Lib/unittest.py mintest/lib/ + cp -pr Lib/test mintest/lib/ + cp -pr Lib mintest/all-lib + cp -p $(buildd_static)/build/lib*/*.so mintest/all-lib/ + ( \ + echo "import sys"; \ + echo "sys.path = ["; \ + echo " '$(CURDIR)/mintest/lib',"; \ + echo " '$(CURDIR)/mintest/dynlib',"; \ + echo "]"; \ + cat Lib/test/regrtest.py; \ + ) > mintest/lib/test/mintest.py + cd mintest && ./python -E -S lib/test/mintest.py \ + -x test_codecencodings_cn test_codecencodings_hk \ + test_codecencodings_jp test_codecencodings_kr \ + test_codecencodings_tw test_codecs test_multibytecodec \ + +stamps/stamp-doc-html: + dh_testdir + $(MAKE) -C Doc html + touch stamps/stamp-doc-html + +build-doc: stamps/stamp-patch stamps/stamp-build-doc +stamps/stamp-build-doc: stamps/stamp-doc-html + touch stamps/stamp-build-doc + +control-file: + sed -e "s/@PVER@/$(PVER)/g" \ + -e "s/@VER@/$(VER)/g" \ + -e "s/@PYSTDDEP@/$(PYSTDDEP)/g" \ + -e "s/@PRIO@/$(PY_PRIO)/g" \ + -e "s/@MINPRIO@/$(PY_MINPRIO)/g" \ + debian/control.in > debian/control.tmp +ifeq ($(distribution),Ubuntu) + ifneq (,$(findstring ubuntu, $(PKGVERSION))) + m='Ubuntu Core Developers '; \ + sed -i "/^Maintainer:/s/\(.*\)/Maintainer: $$m\nXSBC-Original-\1/" \ + debian/control.tmp + endif +endif + [ -e debian/control ] \ + && cmp -s debian/control debian/control.tmp \ + && rm -f debian/control.tmp && exit 0; \ + mv debian/control.tmp debian/control + + + +clean: control-file + dh_testdir + dh_testroot + $(MAKE) -f debian/rules unpatch + rm -rf stamps .pc + rm -f debian/test_results + + $(MAKE) -C Doc clean + sed 's/^@/#/' Makefile.pre.in | $(MAKE) -f - srcdir=. distclean + rm -rf Lib/test/db_home + rm -rf $(buildd_static) $(buildd_shared) $(buildd_debug) $(buildd_shdebug) + find -name '*.py[co]' | xargs -r rm -f + rm -f Lib/lib2to3/*.pickle + rm -rf locales + rm -rf $(d)-dbg + + for f in debian/*.in; do \ + f2=`echo $$f | sed "s,PVER,$(PVER),g;s/@VER@/$(VER)/g;s,\.in$$,,"`; \ + if [ $$f2 != debian/control ] && [ $$f2 != debian/source.lintian-overrides ]; then \ + rm -f $$f2; \ + fi; \ + done + dh_clean + +stamps/stamp-control: + : # We have to prepare the various control files + + for f in debian/*.in; do \ + f2=`echo $$f | sed "s,PVER,$(PVER),g;s/@VER@/$(VER)/g;s,\.in$$,,"`; \ + if [ $$f2 != debian/control ]; then \ + sed -e "s/@PVER@/$(PVER)/g;s/@VER@/$(VER)/g" \ + -e "s/@PRIORITY@/$(PRIORITY)/g" \ + -e "s,@SCRIPTDIR@,/$(scriptdir),g" \ + -e "s,@INFO@,$(info_docs),g" \ + <$$f >$$f2; \ + fi; \ + done +ifneq (,$(filter $(DEB_HOST_ARCH), alpha amd64 ia64 ppc64 sparc64 kfreebsd-amd64)) + sed -i 's/\(Py_InitModule4[^@]*\)@/\1_64@/' \ + debian/lib$(PVER).symbols debian/$(PVER)-dbg.symbols +endif + +install: $(build_target) stamps/stamp-install +stamps/stamp-install: stamps/stamp-build control-file stamps/stamp-control + dh_testdir + dh_testroot + dh_clean -k + dh_installdirs + + : # make install into tmp and subsequently move the files into + : # their packages' directories. + install -d $(d)/usr +ifeq ($(with_interp),static) + $(MAKE) -C $(buildd_static) install prefix=$(CURDIR)/$(d)/usr +else + $(MAKE) -C $(buildd_shared) install prefix=$(CURDIR)/$(d)/usr +endif + -find $(d)/usr/lib/python$(VER) -name '*_failed*.so' + find $(d)/usr/lib/python$(VER) -name '*_failed*.so' | xargs -r rm -f + + mv $(d)/usr/lib/python$(VER)/site-packages \ + $(d)/usr/lib/python$(VER)/dist-packages + + : # remove files, which are not packaged + rm -f $(d)/usr/bin/smtpd.py + rm -rf $(d)/usr/lib/python$(VER)/ctypes/macholib + rm -f $(d)/usr/lib/pkgconfig/python.pc + + : # fix some file permissions + chmod a-x $(d)/$(scriptdir)/{fractions,lib-tk/Tix}.py + + : # move manpages to new names + if [ -d $(d)/usr/man/man1 ]; then \ + mkdir -p $(d)/usr/share/man; \ + mv $(d)/usr/man/man1/* $(d)/usr/share/man/man1/; \ + rm -rf $(d)/usr/man/; \ + fi + cp -p debian/pydoc.1 $(d)/usr/share/man/man1/pydoc$(VER).1 + + : # Symlinks to /usr/bin for some tools + ln -sf ../lib/python$(VER)/pdb.py $(d)/usr/bin/pdb$(VER) + cp -p debian/pdb.1 $(d)/usr/share/man/man1/pdb$(VER).1 + + : # versioned install only + rm -f $(d)/usr/bin/python-config + + mv $(d)/usr/bin/2to3 $(d)/usr/bin/2to3-$(VER) + +# : # remove the bsddb stuff +# rm -rf $(d)/$(scriptdir)/bsddb +# rm -f $(d)/$(scriptdir)/lib-dynload/_bsddb.so + + : # Remove version information from the egg-info file + mv $(d)/$(scriptdir)/lib-dynload/Python-$(VER)*.egg-info \ + $(d)/$(scriptdir)/lib-dynload/Python-$(VER).egg-info + + dh_installdirs -p$(p_lib) \ + $(scriptdir)/config \ + usr/share/doc + : # install the shared library + cp -p $(buildd_shared)/libpython$(VER).so.1.0 $(d_lib)/usr/lib/ + ln -sf libpython$(VER).so.1.0 $(d_lib)/usr/lib/libpython$(VER).so.1 + ln -sf ../../libpython$(VER).so.1 \ + $(d_lib)/$(scriptdir)/config/libpython$(VER).so + ln -sf $(p_base) $(d_lib)/usr/share/doc/$(p_lib) + + ln -sf libpython$(VER).so.1 $(d)/usr/lib/libpython$(VER).so + +ifeq ($(with_interp),shared) + : # install the statically linked runtime + install -m755 $(buildd_static)/python $(d)/usr/bin/python$(VER)-static +endif + + mv $(d)/usr/bin/pydoc $(d)/usr/bin/pydoc$(VER) + cp -p Tools/i18n/pygettext.py $(d)/usr/bin/pygettext$(VER) + cp -p debian/pygettext.1 $(d)/usr/share/man/man1/pygettext$(VER).1 + + : # install the Makefile of the shared python build + sed -e '/^OPT/s,-O3,-O2,' \ + -e 's,^RUNSHARED *=.*,RUNSHARED=,' \ + build-shared/Makefile > $(d)/$(scriptdir)/config/Makefile + + : # Move the binary and the minimal libraries into $(p_min). + dh_installdirs -p$(p_min) \ + etc/$(PVER) \ + usr/bin \ + usr/share/man/man1 \ + $(scriptdir)/lib-dynload + DH_COMPAT=2 dh_movefiles -p$(p_min) --sourcedir=$(d) \ + usr/bin/python$(VER) \ + usr/share/man/man1/python$(VER).1 \ + $(foreach i,$(MIN_MODS),$(scriptdir)/$(i).py) \ + $(foreach i,$(MIN_PACKAGES),$(scriptdir)/$(i)) \ + $(foreach i,$(MIN_ENCODINGS),$(scriptdir)/$(i)) \ + $(scriptdir)/site.py + +# $(foreach i,$(MIN_EXTS),$(scriptdir)/lib-dynload/$(i).so) \ + + : # Install sitecustomize.py. + cp -p debian/sitecustomize.py $(d_min)/etc/$(PVER)/ + patch --no-backup -d $(d_min)/$(scriptdir) < debian/patches/site-builddir.diff + dh_link -p$(p_min) /etc/$(PVER)/sitecustomize.py \ + /$(scriptdir)/sitecustomize.py + + : # Move the static library and the header files into $(p_dev). +# mv $(d)/usr/share/include/python$(VER)/* $(d)/usr/include/python$(VER)/. +# rm -rf $(d)/usr/share/include + dh_installdirs -p$(p_dev) \ + usr/share/doc/python$(VER) \ + $(scriptdir) \ + $(scriptdir)/doc/html \ + usr/include \ + usr/lib + cp -p Misc/HISTORY Misc/README.valgrind Misc/gdbinit \ + debian/README.maintainers \ + debian/test_results $(buildd_static)/pybench.log \ + $(d_dev)/usr/share/doc/python$(VER)/ + + DH_COMPAT=2 dh_movefiles -p$(p_dev) --sourcedir=$(d) \ + usr/lib/python$(VER)/config \ + usr/include/python$(VER) \ + usr/lib/libpython$(VER).so \ + usr/lib/libpython$(VER).a \ + usr/lib/pkgconfig/python-$(VER).pc \ + usr/bin/python$(VER)-config \ + usr/lib/python$(VER)/distutils/command/wininst-*.exe + + mv $(d_dev)/usr/lib/python$(VER)/config/Makefile \ + $(d)/usr/lib/python$(VER)/config/ + mv $(d_dev)/usr/include/python$(VER)/pyconfig.h \ + $(d)/usr/include/python$(VER)/ + cp -p $(buildd_shared)/libpython$(VER)-pic.a \ + $(d_dev)/usr/lib/python$(VER)/config/ + +ifeq ($(with_tk),yes) + : # Move the Tkinter files into $(p_tk). + dh_installdirs -p$(p_tk) \ + $(scriptdir) \ + usr/lib/python$(VER)/lib-dynload + DH_COMPAT=2 dh_movefiles -p$(p_tk) --sourcedir=$(d) \ + usr/lib/python$(VER)/lib-dynload/_tkinter.so +endif + +ifeq ($(with_gdbm),yes) + : # gdbm and dbm modules into $(p_gdbm). + dh_installdirs -p$(p_gdbm) \ + usr/lib/python$(VER)/lib-dynload + DH_COMPAT=2 dh_movefiles -p$(p_gdbm) --sourcedir=$(d) \ + usr/lib/python$(VER)/lib-dynload/gdbm.so +endif + +# : # The test framework into $(p_base), regression tests dropped + DH_COMPAT=2 dh_movefiles -p$(p_base) --sourcedir=$(d) \ + $(scriptdir)/test/{regrtest.py,test_support.py,__init__.py,pystone.py} + rm -rf $(d)/$(scriptdir)/test + rm -rf $(d)/$(scriptdir)/ctypes/test + rm -rf $(d)/$(scriptdir)/bsddb/test + rm -rf $(d)/$(scriptdir)/email/test + rm -rf $(d)/$(scriptdir)/json/tests + rm -rf $(d)/$(scriptdir)/sqlite3/test + rm -rf $(d)/$(scriptdir)/distutils/tests + rm -rf $(d)/$(scriptdir)/lib2to3/tests + rm -rf $(d)/$(scriptdir)/unittest/test + rm -rf $(d)/$(scriptdir)/lib-tk/test + + : # IDLE + mv $(d)/usr/bin/idle $(d)/usr/bin/idle-python$(VER) + rm -f $(d)/usr/lib/python$(VER)/idlelib/idle.bat + dh_installdirs -p$(p_idle) \ + usr/bin \ + usr/share/man/man1 + DH_COMPAT=2 dh_movefiles -p$(p_idle) \ + usr/lib/python$(VER)/idlelib \ + usr/bin/idle-python$(VER) + cp -p debian/idle-$(PVER).1 $(d_idle)/usr/share/man/man1/ + + : # Move the demos and tools into $(p_exam)'s doc directory + dh_installdirs -p$(p_exam) \ + usr/share/doc/python$(VER)/examples + + cp -rp Demo Tools $(d_exam)/usr/share/doc/python$(VER)/examples/ + rm -rf $(d_exam)/usr/share/doc/python$(VER)/examples/Demo/sgi + : # IDLE is in its own package: + rm -rf $(d_exam)/usr/share/doc/python$(VER)/examples/Tools/idle + : # XXX: We don't need rgb.txt, we'll use our own: + rm -rf $(d_exam)/usr/share/doc/python$(VER)/examples/Tools/pynche/X + + : # XXX: Some files in upstream Demo and Tools have strange + : # exec permissions, make lintian glad: + -chmod 644 $(d_tk)/$(scriptdir)/lib-tk/Tix.py + -chmod 644 $(d)/$(scriptdir)/runpy.py + + cd $(d_exam)/usr/share/doc/python$(VER)/examples && chmod 644 \ + Demo/{classes/*.py*,comparisons/patterns} \ + Demo/{rpc/test,threads/*.py*,md5test/*} \ + Demo/pdist/{client.py,cmdfw.py,cmptree.py,cvslib.py,cvslock.py,FSProxy.py,mac.py,rcsclient.py,rcslib.py,security.py,server.py,sumtree.py} \ + Demo/scripts/{morse.py,newslist.doc} \ + Demo/sockets/{broadcast.py,ftp.py,mcast.py,radio.py} \ + Demo/tix/{bitmaps/{tix.gif,*x[pb]m*},samples/*.py} \ + Demo/tkinter/guido/{AttrDialog.py,hanoi.py,hello.py,imagedraw.py,imageview.py,listtree.py,ManPage.py,ShellWindow.py,wish.py} \ + Tools/scripts/pydocgui.pyw \ + Tools/scripts/mailerdaemon.py + + : # Replace all '#!' calls to python with $(PY_INTERPRETER) + : # and make them executable + for i in `find debian -mindepth 3 -type f ! -name '*.dpatch'`; do \ + sed '1s,#!.*python[^ ]*\(.*\),#! $(PY_INTERPRETER)\1,' \ + $$i > $$i.temp; \ + if cmp --quiet $$i $$i.temp; then \ + rm -f $$i.temp; \ + else \ + mv -f $$i.temp $$i; \ + chmod 755 $$i; \ + echo "fixed interpreter: $$i"; \ + fi; \ + done + + : # Move the docs into $(p_base)'s /usr/share/doc/$(PVER) directory, + : # all other packages only have a copyright file. + dh_installdocs -p$(p_base) \ + README Misc/NEWS Misc/ACKS + ln -sf NEWS.gz $(d_base)/usr/share/doc/$(p_base)/changelog.gz + dh_installdocs --all -N$(p_base) -N$(p_dev) -N$(p_dbg) -N$(p_lib) debian/README.Debian + + : # IDLE has its own changelogs, docs... + dh_installchangelogs -p$(p_idle) Lib/idlelib/ChangeLog + dh_installdocs -p$(p_idle) Lib/idlelib/{NEWS,README,TODO,extend}.txt + + mkdir -p $(d_idle)/usr/share/applications + cp -p debian/idle.desktop \ + $(d_idle)/usr/share/applications/idle-$(PVER).desktop + + : # those packages have own README.Debian's + install -m 644 -p debian/README.$(p_base) \ + $(d_base)/usr/share/doc/$(PVER)/README.Debian + install -m 644 -p debian/README.$(p_idle) \ + $(d_idle)/usr/share/doc/$(p_idle)/README.Debian +ifeq ($(with_tk),yes) + cp -p debian/README.Tk $(d_tk)/usr/share/doc/$(p_tk)/ +endif + + : # The rest goes into $(p_base) + mkdir -p $(d)/usr/lib/python$(VER)/dist-packages + (cd $(d) && tar cf - .) | (cd $(d_base) && tar xpf -) + sh debian/dh_rmemptydirs -p$(p_base) + rm -f $(d_base)/usr/bin/python + + : # Install menu icon + dh_installdirs -p$(p_base) usr/share/pixmaps + cp -p debian/pylogo.xpm $(d_base)/usr/share/pixmaps/$(PVER).xpm + + : # generate binfmt file + mkdir -p $(d_min)/usr/share/binfmts + $(buildd_static)/python debian/mkbinfmt.py $(PVER) \ + > $(d_min)/usr/share/binfmts/$(PVER) + + : # desktop entry + mkdir -p $(d_base)/usr/share/applications + cp -p debian/$(PVER).desktop \ + $(d_base)/usr/share/applications/$(PVER).desktop + + : # remove some things + -find debian -name .cvsignore | xargs rm -f + -find debian -name '*.py[co]' | xargs rm -f + + : # remove empty directories, when all components are in place + -find debian ! -name lib-dynload -type d -empty -delete + + : # install debug package + rm -rf $(d)-dbg + $(MAKE) -C $(buildd_debug) install DESTDIR=$(CURDIR)/$(d)-dbg + dh_installdirs -p$(p_dbg) \ + usr/bin \ + usr/share/man/man1 \ + $(scriptdir)/lib-dynload \ + usr/include/$(PVER)_d \ + usr/lib/pkgconfig \ + usr/share/doc/$(p_base) + cp -p Misc/SpecialBuilds.txt $(d_dbg)/usr/share/doc/$(p_base)/ + cp -p debian/$(PVER)-dbg.README.Debian \ + $(d_dbg)/usr/share/doc/$(p_base)/README.debug + cp -p $(buildd_debug)/python $(d_dbg)/usr/bin/$(PVER)-dbg + sed '1s,#!.*python[^ ]*\(.*\),#! $(PY_INTERPRETER)-dbg\1,' \ + $(d)-dbg/usr/bin/$(PVER)-config \ + > $(d_dbg)/usr/bin/$(PVER)-dbg-config + chmod 755 $(d_dbg)/usr/bin/$(PVER)-dbg-config + cp -p $(buildd_debug)/build/lib*/*_d.so \ + $(d_dbg)/$(scriptdir)/lib-dynload/ + cp -p $(buildd_shdebug)/libpython$(VER)_d.so.1.0 $(d_dbg)/usr/lib/ + ln -sf libpython$(VER)_d.so.1.0 $(d_dbg)/usr/lib/libpython$(VER)_d.so.1 + ln -sf libpython$(VER)_d.so.1 $(d_dbg)/usr/lib/libpython$(VER)_d.so + sed -e '/^Libs:/s,-lpython$(VER),-lpython$(VER)_d,' \ + -e '/^Cflags:/s,python$(VER),python$(VER)_d,' \ + $(d)-dbg/usr/lib/pkgconfig/python-$(VER).pc \ + > $(d_dbg)/usr/lib/pkgconfig/python-$(VER)-dbg.pc +ifneq ($(with_gdbm),yes) + rm -f $(d_dbg)/$(scriptdir)/lib-dynload/gdbm_d.so + rm -f $(d_dbg)/usr/lib/debug/$(scriptdir)/lib-dynload/gdbm.so +endif +ifneq ($(with_tk),yes) + rm -f $(d_dbg)/$(scriptdir)/lib-dynload/_tkinter_d.so + rm -f $(d_dbg)/usr/lib/debug/$(scriptdir)/lib-dynload/_tkinter.so +endif +# rm -f $(d_dbg)/$(scriptdir)/lib-dynload/_bsddb_d.so + + cp -a $(d)-dbg/$(scriptdir)/config_d $(d_dbg)/$(scriptdir)/ + ln -sf ../../libpython$(VER)_d.so \ + $(d_dbg)/$(scriptdir)/config_d/libpython$(VER)_d.so + ln -sf libpython$(VER)_d.so \ + $(d_dbg)/$(scriptdir)/config_d/libpython$(VER).so + ln -sf libpython$(VER)_d.a \ + $(d_dbg)/$(scriptdir)/config_d/libpython$(VER).a + + for i in $(d_dev)/usr/include/$(PVER)/*; do \ + i=$$(basename $$i); \ + case $$i in pyconfig.h) continue; esac; \ + ln -sf ../$(PVER)/$$i $(d_dbg)/usr/include/$(PVER)_d/$$i; \ + done + cp -p $(buildd_debug)/pyconfig.h $(d_dbg)/usr/include/$(PVER)_d/ + ln -sf $(PVER).1.gz $(d_dbg)/usr/share/man/man1/$(PVER)-dbg.1.gz + + for i in debian/*.overrides; do \ + b=$$(basename $$i .overrides); \ + install -D -m 644 $$i debian/$$b/usr/share/lintian/overrides/$$b; \ + done + + touch stamps/stamp-install + +# Build architecture-independent files here. +binary-indep: $(install_target) $(build_target) stamps/stamp-build-doc stamps/stamp-control + dh_testdir -i + dh_testroot -i + + : # $(p_doc) package + dh_installdirs -p$(p_doc) \ + usr/share/doc/$(p_base) \ + usr/share/doc/$(p_doc) + dh_installdocs -p$(p_doc) + cp -a Doc/build/html $(d_doc)/usr/share/doc/$(p_base)/ + rm -f $(d_doc)/usr/share/doc/$(p_base)/html/_static/jquery.js + dh_link -p$(p_doc) \ + /usr/share/doc/$(p_base)/html /usr/share/doc/$(p_doc)/html \ + /usr/share/javascript/jquery/jquery.js /usr/share/doc/$(p_base)/html/_static/jquery.js + + : # devhelp docs + python debian/pyhtml2devhelp.py \ + $(d_doc)/usr/share/doc/$(p_base)/html index.html $(VER) \ + > $(d_doc)/usr/share/doc/$(p_base)/html/$(PVER).devhelp + gzip -9v $(d_doc)/usr/share/doc/$(p_base)/html/$(PVER).devhelp + dh_link -p$(p_doc) \ + /usr/share/doc/$(p_base)/html /usr/share/devhelp/books/$(PVER) + + dh_installdebconf -i $(dh_args) + dh_installexamples -i $(dh_args) + dh_installmenu -i $(dh_args) + -dh_icons -i $(dh_args) || dh_iconcache -i $(dh_args) + dh_installchangelogs -i $(dh_args) + dh_link -i $(dh_args) + dh_compress -i $(dh_args) -X.py -X.cls -X.css -X.txt -X.json -X.js -Xobjects.inv -Xgdbinit + dh_fixperms -i $(dh_args) + + : # make python scripts starting with '#!' executable + for i in `find debian -mindepth 3 -type f ! -name '*.dpatch' ! -perm 755`; do \ + if head -1 $$i | grep -q '^#!'; then \ + chmod 755 $$i; \ + echo "make executable: $$i"; \ + fi; \ + done + -find $(d_doc) -name '*.txt' -perm 755 -exec chmod 644 {} \; + + dh_installdeb -i $(dh_args) + dh_gencontrol -i $(dh_args) + dh_md5sums -i $(dh_args) + dh_builddeb -i $(dh_args) + +# Build architecture-dependent files here. +binary-arch: build install + dh_testdir -a + dh_testroot -a +# dh_installdebconf -a + dh_installexamples -a + dh_installmenu -a + -dh_icons -a || dh_iconcache -a +# dh_installmime -a + dh_installchangelogs -a + for i in $(p_dev) $(p_dbg) $(p_lib); do \ + rm -rf debian/$$i/usr/share/doc/$$i; \ + ln -s $(p_base) debian/$$i/usr/share/doc/$$i; \ + done + -find debian ! -perm -200 -print -exec chmod +w {} \; +ifneq ($(with_tk),yes) + rm -f $(d_base)/$(scriptdir)/lib-dynload/_tkinter.so +endif +ifneq ($(with_gdbm),yes) + rm -f $(d_base)/$(scriptdir)/lib-dynload/gdbm.so +endif + dh_strip -a -N$(p_dbg) -Xdebug -Xdbg --dbg-package=$(p_dbg) + cp Tools/gdb/libpython.py $(d_dbg)/usr/lib/debug/usr/bin/$(PVER)-gdb.py + ln -sf $(PVER)-gdb.py $(d_dbg)/usr/lib/debug/usr/bin/$(PVER)-dbg-gdb.py + ln -sf ../bin/$(PVER)-gdb.py \ + $(d_dbg)/usr/lib/debug/usr/lib/lib$(PVER).so.1.0-gdb.py + ln -sf ../bin/$(PVER)-gdb.py \ + $(d_dbg)/usr/lib/lib$(PVER)_d.so.1.0-gdb.py + dh_link -a + dh_compress -a -X.py + dh_fixperms -a + + : # make python scripts starting with '#!' executable + for i in `find debian -mindepth 3 -type f ! -name '*.dpatch' ! -perm 755`; do \ + if head -1 $$i | grep -q '^#!'; then \ + chmod 755 $$i; \ + echo "make executable: $$i"; \ + fi; \ + done + + dh_makeshlibs -p$(p_lib) -V '$(p_lib)' + dh_makeshlibs -p$(p_dbg) -V '$(p_dbg)' +# don't include the following symbols, found in extensions +# which either can be built as builtin or extension. + sed -ri '/^ (_check_|asdl_|fast_save_|init)/d' \ + $(d_lib)/DEBIAN/symbols $(d_dbg)/DEBIAN/symbols + dh_installdeb -a + dh_shlibdeps -a + dh_gencontrol -a + dh_md5sums -a + dh_builddeb -a + +# rules to patch the unpacked files in the source directory +# --------------------------------------------------------------------------- +# various rules to unpack addons and (un)apply patches. +# - patch / apply-patches +# - unpatch / reverse-patches + +patchdir = debian/patches + +glibc_version := $(shell dpkg -s locales | awk '/^Version:/ {print $$2}') +broken_utimes := $(shell dpkg --compare-versions $(glibc_version) lt 2.3.5 && echo yes || echo no) + +$(patchdir)/series: $(patchdir)/series.in + cpp -E \ + -D$(distribution) \ + $(if $(filter $(broken_utimes),yes),-DBROKEN_UTIMES) \ + -Darch_os_$(DEB_HOST_ARCH_OS) -Darch_$(DEB_HOST_ARCH) \ + -o - $(patchdir)/series.in \ + | egrep -v '^(#.*|$$)' > $(patchdir)/series + +patch: stamps/stamp-patch +stamps/stamp-patch: $(patchdir)/series + dh_testdir + QUILT_PATCHES=$(patchdir) quilt push -a || test $$? = 2 + rm -rf autom4te.cache configure + autoconf + mkdir -p stamps + echo ""; echo "Patches applied in this version:" > stamps/pxx + for i in $$(cat $(patchdir)/series); do \ + echo ""; echo "$$i:"; \ + sed -n 's/^# *DP: */ /p' $(patchdir)/$$i; \ + done >> stamps/pxx + mv stamps/pxx $@ + +reverse-patches: unpatch +unpatch: + QUILT_PATCHES=$(patchdir) quilt pop -a -R || test $$? = 2 + rm -f stamps/stamp-patch $(patchdir)/series + rm -rf configure autom4te.cache + +update-patches: $(patchdir)/series + export QUILT_PATCHES=$(patchdir); \ + export QUILT_REFRESH_ARGS="--no-timestamps --no-index -pab"; \ + export QUILT_DIFF_ARGS="--no-timestamps --no-index -pab"; \ + while quilt push; do quilt refresh; done + +binary: binary-indep binary-arch + +.PHONY: control-file configure build clean binary-indep binary-arch binary install + +# Local Variables: +# mode: makefile +# end: --- python2.7-2.7.orig/debian/PVER-doc.doc-base.PVER-lib.in +++ python2.7-2.7/debian/PVER-doc.doc-base.PVER-lib.in @@ -0,0 +1,15 @@ +Document: @PVER@-lib +Title: Python Library Reference (v@VER@) +Author: Guido van Rossum +Abstract: This library reference manual documents Python's standard library, + as well as many optional library modules (which may or may not be + available, depending on whether the underlying platform supports + them and on the configuration choices made at compile time). It + also documents the standard types of the language and its built-in + functions and exceptions, many of which are not or incompletely + documented in the Reference Manual. +Section: Programming/Python + +Format: HTML +Index: /usr/share/doc/@PVER@/html/library/index.html +Files: /usr/share/doc/@PVER@/html/library/*.html --- python2.7-2.7.orig/debian/PVER-doc.doc-base.PVER-dist.in +++ python2.7-2.7/debian/PVER-doc.doc-base.PVER-dist.in @@ -0,0 +1,13 @@ +Document: @PVER@-dist +Title: Distributing Python Modules (v@VER@) +Author: Greg Ward +Abstract: This document describes the Python Distribution Utilities + (``Distutils'') from the module developer's point-of-view, describing + how to use the Distutils to make Python modules and extensions easily + available to a wider audience with very little overhead for + build/release/install mechanics. +Section: Programming/Python + +Format: HTML +Index: /usr/share/doc/@PVER@/html/distutils/index.html +Files: /usr/share/doc/@PVER@/html/distutils/*.html --- python2.7-2.7.orig/debian/PVER.postinst.in +++ python2.7-2.7/debian/PVER.postinst.in @@ -0,0 +1,37 @@ +#! /bin/sh -e + +if [ "$1" = configure ]; then + ( + files=$(dpkg -L @PVER@ | sed -n '/^\/usr\/lib\/@PVER@\/.*\.py$/p') + @PVER@ /usr/lib/@PVER@/py_compile.py $files + if grep -sq '^byte-compile[^#]*optimize' /etc/python/debian_config; then + @PVER@ -O /usr/lib/@PVER@/py_compile.py $files + fi + ) +fi + +case "$1" in + configure|abort-upgrade|abort-remove|abort-deconfigure) + + # Create empty directories in /usr/local + if [ ! -e /usr/local/lib/python@VER@ ]; then + mkdir -p /usr/local/lib/python@VER@ 2> /dev/null || true + chmod 2775 /usr/local/lib/python@VER@ 2> /dev/null || true + chown root:staff /usr/local/lib/python@VER@ 2> /dev/null || true + fi + if [ ! -e /usr/local/lib/python@VER@/site-packages ]; then + mkdir -p /usr/local/lib/python@VER@/site-packages 2> /dev/null || true + chmod 2775 /usr/local/lib/python@VER@/site-packages 2> /dev/null || true + chown root:staff /usr/local/lib/python@VER@/site-packages 2> /dev/null || true + fi + ;; + + *) + echo "postinst called with unknown argument \`$1'" >&2 + exit 1 + ;; +esac + +#DEBHELPER# + +exit 0 --- python2.7-2.7.orig/debian/pyhtml2devhelp.py +++ python2.7-2.7/debian/pyhtml2devhelp.py @@ -0,0 +1,222 @@ +#! /usr/bin/python + +import formatter, htmllib +import os, sys, re + +class PyHTMLParser(htmllib.HTMLParser): + pages_to_include = set(('whatsnew/index.html', 'tutorial/index.html', 'using/index.html', + 'reference/index.html', 'library/index.html', 'howto/index.html', + 'extending/index.html', 'c-api/index.html', 'install/index.html', + 'distutils/index.html', 'documenting/index.html')) + + def __init__(self, formatter, basedir, fn, indent, parents=set()): + htmllib.HTMLParser.__init__(self, formatter) + self.basedir = basedir + self.dir, self.fn = os.path.split(fn) + self.data = '' + self.parents = parents + self.link = {} + self.indent = indent + self.last_indent = indent - 1 + self.sub_indent = 0 + self.sub_count = 0 + self.next_link = False + + def process_link(self): + new_href = os.path.join(self.dir, self.link['href']) + text = self.link['text'] + indent = self.indent + self.sub_indent + if self.last_indent == indent: + print '%s' % (' ' * self.last_indent) + self.sub_count -= 1 + print '%s' % (' ' * indent, new_href, text) + self.sub_count += 1 + self.last_indent = self.indent + self.sub_indent + + def start_li(self, attrs): + self.sub_indent += 1 + self.next_link = True + + def end_li(self): + indent = self.indent + self.sub_indent + if self.sub_count > 0: + print '%s' % (' ' * self.last_indent) + self.sub_count -= 1 + self.last_indent -= 1 + self.sub_indent -= 1 + + def start_a(self, attrs): + self.link = {} + for attr in attrs: + self.link[attr[0]] = attr[1] + self.data = '' + + def end_a(self): + process = False + text = self.data.replace('\t', '').replace('\n', ' ').replace('&', '&').replace('<', '<').replace('>', '>') + self.link['text'] = text + # handle a tag without href attribute + try: + href = self.link['href'] + except KeyError: + return + + abs_href = os.path.join(self.basedir, href) + if abs_href in self.parents: + return + if href.startswith('..') or href.startswith('http:') \ + or href.startswith('mailto:') or href.startswith('news:'): + return + if href in ('', 'about.html', 'modindex.html', 'genindex.html', 'glossary.html', + 'search.html', 'contents.html', 'download.html', 'bugs.html', + 'license.html', 'copyright.html'): + return + + if self.link.has_key('class'): + if self.link['class'] in ('biglink'): + process = True + if self.link['class'] in ('reference external'): + if self.next_link: + process = True + next_link = False + + if process == True: + self.process_link() + if href in self.pages_to_include: + self.parse_file(os.path.join(self.dir, href)) + + def finish(self): + if self.sub_count > 0: + print '%s' % (' ' * self.last_indent) + + def handle_data(self, data): + self.data += data + + def parse_file(self, href): + # TODO basedir bestimmen + parent = os.path.join(self.basedir, self.fn) + self.parents.add(parent) + parser = PyHTMLParser(formatter.NullFormatter(), + self.basedir, href, self.indent + 1, + self.parents) + text = file(self.basedir + '/' + href).read() + parser.feed(text) + parser.finish() + parser.close() + if parent in self.parents: + self.parents.remove(parent) + +class PyIdxHTMLParser(htmllib.HTMLParser): + def __init__(self, formatter, basedir, fn, indent): + htmllib.HTMLParser.__init__(self, formatter) + self.basedir = basedir + self.dir, self.fn = os.path.split(fn) + self.data = '' + self.link = {} + self.indent = indent + self.active = False + self.indented = False + self.nolink = False + self.header = '' + self.last_letter = 'Z' + self.last_text = '' + + def process_link(self): + new_href = os.path.join(self.dir, self.link['href']) + text = self.link['text'] + if not self.active: + return + if text.startswith('['): + return + if self.link.get('rel', None) in ('prev', 'parent', 'next', 'contents', 'index'): + return + if self.indented: + text = self.last_text + ' ' + text + else: + # Save it in case we need it again + self.last_text = re.sub(' \([\w\-\.\s]+\)', '', text) + indent = self.indent + print '%s' % (' ' * indent, new_href, text) + + def start_dl(self, attrs): + if self.last_text: + # Looks like we found the second part to a command + self.indented = True + + def end_dl(self): + self.indented = False + + def start_dt(self, attrs): + self.data = '' + self.nolink = True + + def end_dt(self): + if not self.active: + return + if self.nolink == True: + # Looks like we found the first part to a command + self.last_text = re.sub(' \([\w\-\.\s]+\)', '', self.data) + self.nolink = False + + def start_h2(self, attrs): + for k, v in attrs: + if k == 'id': + self.header = v + if v == '_': + self.active = True + + def start_td(self, attrs): + self.indented = False + self.last_text = '' + + def start_table(self, attrs): + pass + + def end_table(self): + if self.header == self.last_letter: + self.active = False + + def start_a(self, attrs): + self.nolink = False + self.link = {} + for attr in attrs: + self.link[attr[0]] = attr[1] + self.data = '' + + def end_a(self): + text = self.data.replace('\t', '').replace('\n', ' ').replace('&', '&').replace('<', '<').replace('>', '>') + self.link['text'] = text + # handle a tag without href attribute + try: + href = self.link['href'] + except KeyError: + return + self.process_link() + + def handle_data(self, data): + self.data += data + +def main(): + base = sys.argv[1] + fn = sys.argv[2] + version = sys.argv[3] + + parser = PyHTMLParser(formatter.NullFormatter(), base, fn, indent=0) + print '' + print '' % (version, version) + print '' + parser.parse_file(fn) + print '' + + print '' + + fn = 'genindex-all.html' + parser = PyIdxHTMLParser(formatter.NullFormatter(), base, fn, indent=1) + text = file(base + '/' + fn).read() + parser.feed(text) + parser.close() + + print '' + print '' + +main() --- python2.7-2.7.orig/debian/pdb.1.in +++ python2.7-2.7/debian/pdb.1.in @@ -0,0 +1,16 @@ +.TH PDB@VER@ 1 +.SH NAME +pdb@VER@ \- the Python debugger +.SH SYNOPSIS +.PP +.B pdb@VER@ +.I script [...] +.SH DESCRIPTION +.PP +See /usr/lib/python@VER@/pdb.doc for more information on the use +of pdb. When the debugger is started, help is available via the +help command. +.SH SEE ALSO +python@VER@(1). Chapter 9 of the Python Library Reference +(The Python Debugger). Available in the python@VER@-doc package at +/usr/share/doc/python@VER@/html/lib/module-pdb.html. --- python2.7-2.7.orig/debian/pylogo.xpm +++ python2.7-2.7/debian/pylogo.xpm @@ -0,0 +1,351 @@ +/* XPM */ +static char * pylogo_xpm[] = { +"32 32 316 2", +" c None", +". c #8DB0CE", +"+ c #6396BF", +"@ c #4985B7", +"# c #4181B5", +"$ c #417EB2", +"% c #417EB1", +"& c #4D83B0", +"* c #6290B6", +"= c #94B2CA", +"- c #70A1C8", +"; c #3D83BC", +"> c #3881BD", +", c #387DB6", +"' c #387CB5", +") c #387BB3", +"! c #3779B0", +"~ c #3778AE", +"{ c #3776AB", +"] c #3776AA", +"^ c #3775A9", +"/ c #4A7FAC", +"( c #709FC5", +"_ c #3A83BE", +": c #5795C7", +"< c #94B9DB", +"[ c #73A4CE", +"} c #3D80B7", +"| c #387CB4", +"1 c #377AB2", +"2 c #377AB0", +"3 c #3777AC", +"4 c #3774A7", +"5 c #3773A5", +"6 c #3C73A5", +"7 c #4586BB", +"8 c #4489C1", +"9 c #A7C7E1", +"0 c #F7F9FD", +"a c #E1E9F1", +"b c #4C89BC", +"c c #3779AF", +"d c #3778AD", +"e c #3873A5", +"f c #4B7CA4", +"g c #3982BE", +"h c #4389C1", +"i c #A6C6E1", +"j c #F6F9FC", +"k c #D6E4F0", +"l c #4A88BB", +"m c #3773A6", +"n c #366F9F", +"o c #366E9D", +"p c #376E9C", +"q c #4A8BC0", +"r c #79A7CD", +"s c #548EBD", +"t c #387AB0", +"u c #3773A4", +"v c #366D9C", +"w c #387FBA", +"x c #387DB7", +"y c #387BB4", +"z c #3775A8", +"A c #366FA0", +"B c #4981AF", +"C c #427BAA", +"D c #3772A4", +"E c #376B97", +"F c #77A3C8", +"G c #4586BC", +"H c #3882BE", +"I c #3B76A7", +"J c #3B76A6", +"K c #366E9E", +"L c #376B98", +"M c #376B96", +"N c #5681A3", +"O c #F5EEB8", +"P c #FFED60", +"Q c #FFE85B", +"R c #FFE659", +"S c #FDE55F", +"T c #5592C4", +"U c #3A83BF", +"V c #3882BD", +"W c #387FB9", +"X c #3779AE", +"Y c #366F9E", +"Z c #366C98", +"` c #376A94", +" . c #5D85A7", +".. c #F5EDB7", +"+. c #FFEA5D", +"@. c #FFE75A", +"#. c #FFE354", +"$. c #FDDD56", +"%. c #669DC8", +"&. c #3885C3", +"*. c #3884C2", +"=. c #387EB8", +"-. c #387CB6", +";. c #377AB1", +">. c #3772A3", +",. c #366D9B", +"'. c #F5EBB5", +"). c #FFE557", +"!. c #FFE455", +"~. c #FFDF50", +"{. c #FFDB4C", +"]. c #FAD862", +"^. c #8EB4D2", +"/. c #3C86C1", +"(. c #3883C0", +"_. c #3882BF", +":. c #3881BC", +"<. c #3880BB", +"[. c #3775AA", +"}. c #F5EAB3", +"|. c #FFE051", +"1. c #FFDE4F", +"2. c #FFDA4A", +"3. c #FED446", +"4. c #F5DF9D", +"5. c #77A5CA", +"6. c #3885C2", +"7. c #387BB2", +"8. c #6B8EA8", +"9. c #F8E7A1", +"0. c #FFE153", +"a. c #FFDD4E", +"b. c #FFDB4B", +"c. c #FFD746", +"d. c #FFD645", +"e. c #FFD342", +"f. c #F6DB8D", +"g. c #508DBE", +"h. c #3771A3", +"i. c #376A95", +"j. c #3D6F97", +"k. c #C3CBC2", +"l. c #FBD964", +"m. c #FFDC4D", +"n. c #FFD544", +"o. c #FFD040", +"p. c #F9CF58", +"q. c #3F83BB", +"r. c #376B95", +"s. c #3A6C95", +"t. c #4E7BA0", +"u. c #91AABC", +"v. c #F6E4A3", +"w. c #FFDA4B", +"x. c #FFD646", +"y. c #FFD443", +"z. c #FFD241", +"A. c #FFCE3D", +"B. c #FFCC3B", +"C. c #FCC83E", +"D. c #3880BC", +"E. c #3C79AC", +"F. c #5F8DB4", +"G. c #7AA0C0", +"H. c #82A6C3", +"I. c #82A3BF", +"J. c #82A2BE", +"K. c #82A1BB", +"L. c #82A1B9", +"M. c #8BA4B5", +"N. c #C1C5AE", +"O. c #F2E19F", +"P. c #FDD74C", +"Q. c #FFD94A", +"R. c #FFD343", +"S. c #FFCE3E", +"T. c #FFCB39", +"U. c #FFC937", +"V. c #FEC636", +"W. c #3D79AB", +"X. c #9DB6C6", +"Y. c #D0CFA2", +"Z. c #EFE598", +"`. c #F8EE9B", +" + c #F8EB97", +".+ c #F8E996", +"++ c #F8E894", +"@+ c #FAE489", +"#+ c #FCDB64", +"$+ c #FFDA4D", +"%+ c #FFCF3E", +"&+ c #FFCB3A", +"*+ c #FFC734", +"=+ c #FFC532", +"-+ c #3F82B7", +";+ c #387EB9", +">+ c #9EB9D0", +",+ c #F2E287", +"'+ c #FDEB69", +")+ c #FEEC60", +"!+ c #FFEB5E", +"~+ c #FFE254", +"{+ c #FFE152", +"]+ c #FFD747", +"^+ c #FFC633", +"/+ c #FCC235", +"(+ c #578FBE", +"_+ c #6996BC", +":+ c #DED9A8", +"<+ c #FEEC62", +"[+ c #FFE658", +"}+ c #FFDF51", +"|+ c #FFDE50", +"1+ c #FFD03F", +"2+ c #FFCD3C", +"3+ c #FFC431", +"4+ c #FFBF2C", +"5+ c #FAC244", +"6+ c #85AACA", +"7+ c #A1BBD2", +"8+ c #F7E47C", +"9+ c #FFE456", +"0+ c #FFC735", +"a+ c #FFBC29", +"b+ c #F7D280", +"c+ c #9DBAD2", +"d+ c #3B7CB2", +"e+ c #ABC2D6", +"f+ c #FDEB7B", +"g+ c #FFC12E", +"h+ c #FDBD30", +"i+ c #F4DEA8", +"j+ c #5F91BA", +"k+ c #ABC1D4", +"l+ c #FDEE7E", +"m+ c #FFE253", +"n+ c #FFCC3C", +"o+ c #FFBA27", +"p+ c #FAC75B", +"q+ c #4A82B0", +"r+ c #3877AB", +"s+ c #3774A6", +"t+ c #AAC0D4", +"u+ c #FDEE7D", +"v+ c #FFEC5F", +"w+ c #FFE255", +"x+ c #FFD848", +"y+ c #FFD444", +"z+ c #FFCF3F", +"A+ c #FFBC2A", +"B+ c #FFBB28", +"C+ c #FDBA32", +"D+ c #447AA8", +"E+ c #4379A7", +"F+ c #FFE95C", +"G+ c #FFE558", +"H+ c #FFE355", +"I+ c #FED84B", +"J+ c #FCD149", +"K+ c #FBCE47", +"L+ c #FBCD46", +"M+ c #FBC840", +"N+ c #FBC63E", +"O+ c #FBC037", +"P+ c #FAC448", +"Q+ c #FDD44C", +"R+ c #FCD14E", +"S+ c #FFC836", +"T+ c #FFC22F", +"U+ c #FFC02D", +"V+ c #FFE052", +"W+ c #FFC636", +"X+ c #FFCF5C", +"Y+ c #FFD573", +"Z+ c #FFC33E", +"`+ c #FEBD2D", +" @ c #FFDB4D", +".@ c #FFD949", +"+@ c #FFD545", +"@@ c #FFD140", +"#@ c #FFCB48", +"$@ c #FFF7E4", +"%@ c #FFFCF6", +"&@ c #FFE09D", +"*@ c #FFBA2E", +"=@ c #FDBE2F", +"-@ c #FFD748", +";@ c #FFCA38", +">@ c #FFC844", +",@ c #FFF2D7", +"'@ c #FFF9EC", +")@ c #FFDB94", +"!@ c #FFB92D", +"~@ c #FAC54D", +"{@ c #FDD54E", +"]@ c #FFBD2D", +"^@ c #FFC858", +"/@ c #FFD174", +"(@ c #FFBF3E", +"_@ c #FCBD3C", +":@ c #FAD66A", +"<@ c #FECD3F", +"[@ c #FFC330", +"}@ c #FFBD2A", +"|@ c #FFB724", +"1@ c #FFB521", +"2@ c #FFB526", +"3@ c #FBC457", +"4@ c #F7E09E", +"5@ c #F8D781", +"6@ c #FAC349", +"7@ c #FCC134", +"8@ c #FEBE2C", +"9@ c #FBBE3F", +"0@ c #F7CF79", +"a@ c #F5D795", +" . + @ # $ % % & * = ", +" - ; > > , ' ) ! ~ { ] ^ / ", +" ( _ : < [ } | 1 2 ~ 3 4 5 5 6 ", +" 7 8 9 0 a b 2 c d 3 { 5 5 5 e f ", +" g h i j k l c ~ { { m 5 5 n o p ", +" > > q r s t c c d 4 5 u n v v v ", +" w x ' y 2 c d d z 5 u A v v v v ", +" B C 5 D v v v v E ", +" F G H H H x ' ) c c c d I J 5 K v v L M N O P Q R S ", +" T U H V V W ' ) c c X ~ 5 5 5 Y v v Z ` ` ...+.@.#.#.$. ", +" %.&.*.> w W =.-.;.c 3 { ^ 5 5 >.o v ,.E ` ` .'.).!.#.~.{.]. ", +"^./.(._.:.<., ' ) ;.X d [.5 5 >.K v ,.E ` ` ` .}.#.|.1.{.2.3.4.", +"5.6.(.H H x ' 7.c c 3 3 4 5 D K v v ,.` ` ` ` 8.9.0.a.b.c.d.e.f.", +"g._.> <.w ' ' | 2 3 { z 5 5 h.v v v i.` ` ` j.k.l.m.{.d.n.e.o.p.", +"q.> > :.-.' 1 c c c ] 5 5 >.v v ,.r.` ` s.t.u.v.{.w.x.y.z.A.B.C.", +"D.D.w -.' 1 c c c E.F.G.H.I.J.J.K.L.L.L.M.N.O.P.Q.c.R.S.B.T.U.V.", +"D.D.=.' ' 1 c c W.X.Y.Z.`.`.`.`.`. +.+++@+#+$+Q.d.R.%+B.&+*+=+=+", +"-+;+-.' ;.2 c c >+,+'+)+P P P !+Q R ~+{+1.{.]+d.y.%+B.&+^+=+=+/+", +"(+' ' ;.c X X _+:+<+P P P P !+R [+~+}+|+{.]+n.R.1+2+&+^+=+3+4+5+", +"6+' ) ! ~ { { 7+8+P P P P !+R 9+#.{+{.w.]+y.z.S.&+0+=+=+3+4+a+b+", +"c+d+7.! d 3 z e+f+P P P !+R 9+#.{+m.{.]+y.1+B.&+0+=+=+g+4+a+h+i+", +" j+c d 3 { 4 k+l+P P !+@.9+m+1.m.{.]+y.1+n+B.*+=+=+g+a+a+o+p+ ", +" q+r+{ s+m t+u+v+@.R w+{+}+{.x+d.y+z+n+B.0+=+=+g+A+a+B+C+ ", +" * D+E+E+ +.F+G+H+}+}+{.I+J+K+L+M+M+M+M+N+O+O+O+O+P+ ", +" ).).#.{+a.{.x+Q+R+ ", +" #.m+1.a.{.x+y.o.2+B.S+=+=+T+U+O+ ", +" 0.V+{.{.x+n.o.2+B.B.W+X+Y+Z+a+`+ ", +" @{..@+@n.@@B.B.S+^+#@$@%@&@*@=@ ", +" ].-@x.y.o.%+;@S+=+=+>@,@'@)@!@~@ ", +" {@z.z+2+U.=+=+=+T+]@^@/@(@_@ ", +" :@<@U.=+=+[@4+}@|@1@2@3@ ", +" 4@5@6@7@8@a+a+9@0@a@ "}; --- python2.7-2.7.orig/debian/pymindeps.py +++ python2.7-2.7/debian/pymindeps.py @@ -0,0 +1,174 @@ +#! /usr/bin/python + +# Matthias Klose +# Modified to only exclude module imports from a given module. + +# Copyright 2004 Toby Dickenson +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject +# to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +import os, sys, pprint +import modulefinder +import imp + +class mymf(modulefinder.ModuleFinder): + def __init__(self,*args,**kwargs): + self._depgraph = {} + self._types = {} + self._last_caller = None + modulefinder.ModuleFinder.__init__(self, *args, **kwargs) + + def import_hook(self, name, caller=None, fromlist=None, level=-1): + old_last_caller = self._last_caller + try: + self._last_caller = caller + return modulefinder.ModuleFinder.import_hook(self, name, caller, + fromlist, level) + finally: + self._last_caller = old_last_caller + + def import_module(self, partnam, fqname, parent): + m = modulefinder.ModuleFinder.import_module(self, + partnam, fqname, parent) + if m is not None and self._last_caller: + caller = self._last_caller.__name__ + if '.' in caller: + caller = caller[:caller.index('.')] + callee = m.__name__ + if '.' in callee: + callee = callee[:callee.index('.')] + #print "XXX last_caller", caller, "MOD", callee + #self._depgraph.setdefault(self._last_caller.__name__,{})[r.__name__] = 1 + #if caller in ('pdb', 'doctest') or callee in ('pdb', 'doctest'): + # print caller, "-->", callee + if caller != callee: + self._depgraph.setdefault(caller,{})[callee] = 1 + return m + + def find_module(self, name, path, parent=None): + if parent is not None: + # assert path is not None + fullname = parent.__name__+'.'+name + elif name == "__init__": + fullname = os.path.basename(path[0]) + else: + fullname = name + if self._last_caller: + caller = self._last_caller.__name__ + if fullname in excluded_imports.get(caller, []): + #self.msgout(3, "find_module -> Excluded", fullname) + raise ImportError, name + + if fullname in self.excludes: + #self.msgout(3, "find_module -> Excluded", fullname) + raise ImportError, name + + if path is None: + if name in sys.builtin_module_names: + return (None, None, ("", "", imp.C_BUILTIN)) + + path = self.path + return imp.find_module(name, path) + + def load_module(self, fqname, fp, pathname, file_info): + suffix, mode, type = file_info + m = modulefinder.ModuleFinder.load_module(self, fqname, + fp, pathname, file_info) + if m is not None: + self._types[m.__name__] = type + return m + + def load_package(self, fqname, pathname): + m = modulefinder.ModuleFinder.load_package(self, fqname,pathname) + if m is not None: + self._types[m.__name__] = imp.PKG_DIRECTORY + return m + +def reduce_depgraph(dg): + pass + +# guarded imports, which don't need to be included in python-minimal +excluded_imports = { + 'codecs': set(('encodings',)), + 'collections': set(('doctest', 'dummy_thread', 'cPickle')), + 'copy': set(('reprlib',)), + 'difflib': set(('doctest',)), + 'hashlib': set(('logging',)), + #'hashlib': set(('_hashlib', '_md5', '_sha', '_sha256','_sha512',)), + 'heapq': set(('doctest',)), + 'inspect': set(('compiler',)), + 'os': set(('nt', 'ntpath', 'os2', 'os2emxpath', 'mac', 'macpath', + 'riscos', 'riscospath', 'riscosenviron')), + 'optparse': set(('gettext',)), + 'pickle': set(('doctest',)), + 'platform': set(('plistlib', 'tempfile')), + #'socket': set(('_ssl', 'ssl')), + 'tempfile': set(('dummy_thread',)), + 'subprocess': set(('threading',)), + 'shutil': set(('distutils', 'tarfile', 'zipfile')), + } + +def main(argv): + # Parse command line + import getopt + try: + opts, args = getopt.getopt(sys.argv[1:], "dmp:qx:") + except getopt.error as msg: + print(msg) + return + + # Process options + debug = 1 + domods = 0 + addpath = [] + exclude = [] + for o, a in opts: + if o == '-d': + debug = debug + 1 + if o == '-m': + domods = 1 + if o == '-p': + addpath = addpath + a.split(os.pathsep) + if o == '-q': + debug = 0 + if o == '-x': + exclude.append(a) + + path = sys.path[:] + path = addpath + path + + if debug > 1: + print("version:", sys.version) + print("path:") + for item in path: + print(" ", repr(item)) + + #exclude = ['__builtin__', 'sys', 'os'] + exclude = [] + mf = mymf(path, debug, exclude) + for arg in args: + mf.run_script(arg) + + depgraph = reduce_depgraph(mf._depgraph) + + pprint.pprint({'depgraph':mf._depgraph, 'types':mf._types}) + +if __name__=='__main__': + main(sys.argv[1:]) --- python2.7-2.7.orig/debian/PVER-minimal.preinst.in +++ python2.7-2.7/debian/PVER-minimal.preinst.in @@ -0,0 +1,39 @@ +#!/bin/sh + +set -e + +syssite=/usr/lib/@PVER@/site-packages +oldsite=/usr/lib/@PVER@/old-site-packages +localsite=/usr/local/lib/@PVER@/dist-packages +syslink=../../${localsite#/usr/*} + +case "$1" in + install) + if [ -z "$2" ] && [ -d $syssite ] && [ ! -h $syssite ]; then + echo "new installation of @PVER@-minimal; $syssite is a directory" + echo "which is expected a symlink to $localsite." + echo "please find the package shipping files in $syssite and" + echo "file a bug report to ship these in /usr/lib/@PVER@/dist-packages instead" + echo "aborting installation of @PVER@-minimal" + exit 1 + fi + + # remember newly installed runtime + mkdir -p /var/lib/python + touch /var/lib/python/@PVER@_installed + ;; + upgrade) + ;; + + abort-upgrade) + ;; + + *) + echo "preinst called with unknown argument \`$1'" >&2 + exit 1 + ;; +esac + +#DEBHELPER# + +exit 0 --- python2.7-2.7.orig/debian/watch +++ python2.7-2.7/debian/watch @@ -0,0 +1,3 @@ +version=3 +opts=dversionmangle=s/.*\+//,uversionmangle=s/([abcr]+[1-9])$/~$1/ \ + http://www.python.org/ftp/python/2\.7(\.\d)?/Python-(2\.7[.\dabcr]*)\.tgz --- python2.7-2.7.orig/debian/PVER-dbg.prerm.in +++ python2.7-2.7/debian/PVER-dbg.prerm.in @@ -0,0 +1,22 @@ +#! /bin/sh + +set -e + +case "$1" in + remove) + rm -f /usr/lib/debug/usr/bin/@PVER@-gdb.py[co] + rm -f /usr/lib/debug/usr/lib/lib@PVER@.so.1.0-gdb.py[co] + ;; + upgrade) + ;; + deconfigure) + ;; + failed-upgrade) + ;; + *) + echo "prerm called with unknown argument \`$1'" >&2 + exit 1 + ;; +esac + +#DEBHELPER# --- python2.7-2.7.orig/debian/dh_doclink +++ python2.7-2.7/debian/dh_doclink @@ -0,0 +1,28 @@ +#! /bin/sh + +pkg=`echo $1 | sed 's/^-p//'` +target=$2 + +ln -sf $target debian/$pkg/usr/share/doc/$pkg + +f=debian/$pkg.postinst.debhelper +if [ ! -e $f ] || [ "`grep -c '^# dh_doclink' $f`" -eq 0 ]; then +cat >> $f <> $f <. +# + +DIRLIST="/usr/lib/python@VER@/idlelib" + +case "$1" in + configure|abort-upgrade|abort-remove|abort-deconfigure) + + for i in $DIRLIST ; do + @PVER@ /usr/lib/@PVER@/compileall.py -q $i + if grep -sq '^byte-compile[^#]*optimize' /etc/python/debian_config + then + @PVER@ -O /usr/lib/@PVER@/compileall.py -q $i + fi + done + ;; + + *) + echo "postinst called with unknown argument \`$1'" >&2 + exit 1 + ;; + +esac + +#DEBHELPER# + +exit 0 --- python2.7-2.7.orig/debian/README.maintainers.in +++ python2.7-2.7/debian/README.maintainers.in @@ -0,0 +1,88 @@ + +Hints for maintainers of Debian packages of Python extensions +------------------------------------------------------------- + +Most of the content of this README can be found in the Debian Python policy. +See /usr/share/doc/python/python-policy.txt.gz. + +Documentation Tools +------------------- + +If your package ships documentation produced in the Python +documentation format, you can generate it at build-time by +build-depending on @PVER@-dev, and you will find the +templates, tools and scripts in /usr/lib/@PVER@/doc/tools -- +adjust your build scripts accordingly. + + +Makefile.pre.in issues +---------------------- + +Python comes with a `universal Unix Makefile for Python extensions' in +/usr/lib/@PVER@/config/Makefile.pre.in (with Debian, this is included +in the python-dev package), which is used by most Python extensions. + +In general, packages using the Makefile.pre.in approach can be packaged +simply by running dh_make or by using one of debhelper's rules' templates +(see /usr/doc/debhelper/examples/). Makefile.pre.in works fine with e.g. +"make prefix=debian/tmp/usr install". + +One glitch: You may be running into the problem that Makefile.pre.in +doesn't try to create all the directories when they don't exist. Therefore, +you may have to create them manually before "make install". In most cases, +the following should work: + + ... + dh_installdirs /usr/lib/@PVER@ + $(MAKE) prefix=debian/tmp/usr install + ... + + +Byte-compilation +---------------- + +For speed reasons, Python internally compiles source files into a byte-code. +To speed up subsequent imports, it tries to save the byte-code along with +the source with an extension .pyc (resp. pyo). This will fail if the +libraries are installed in a non-writable directory, which may be the +case for /usr/lib/@PVER@/. + +Not that .pyc and .pyo files should not be relocated, since for debugging +purposes the path of the source for is hard-coded into them. + +To precompile files in batches after installation, Python has a script +compileall.py, which compiles all files in a given directory tree. The +Debian version of compileall has been enhanced to support incremental +compilation and to feature a ddir (destination dir) option. ddir is +used to compile files in debian/usr/lib/python/ when they will be +installed into /usr/lib/python/. + + +Currently, there are two ways to use compileall for Debian packages. The +first has a speed penalty, the second has a space penalty in the package. + +1.) Compiling and removing .pyc files in postinst/prerm: + + Use dh_python(1) from the debhelper packages to add commands to byte- + compile on installation and to remove the byte-compiled files on removal. + Your package has to build-depend on: debhelper (>= 4.1.67), python. + + In /usr/share/doc/@PVER@, you'll find sample.postinst and sample.prerm. + If you set the directory where the .py files are installed, these + scripts will install and remove the .pyc and .pyo files for your + package after unpacking resp. before removing the package. + +2.) Compiling the .pyc files `out of place' during installation: + + As of 1.5.1, compileall.py allows you to specify a faked installation + directory using the "-d destdir" option, so that you can precompile + the files in their temporary directory + (e.g. debian/tmp/usr/lib/python2.1/site-packages/PACKAGE). + + + + 11/02/98 + Gregor Hoffleit + + +Last modified: 2007-10-14 --- python2.7-2.7.orig/debian/dh_rmemptydirs +++ python2.7-2.7/debian/dh_rmemptydirs @@ -0,0 +1,10 @@ +#! /bin/sh -e + +pkg=`echo $1 | sed 's/^-p//'` + +: # remove empty directories, when all components are in place +for d in `find debian/$pkg -depth -type d -empty 2> /dev/null`; do \ + while rmdir $$d 2> /dev/null; do d=`dirname $$d`; done; \ +done + +exit 0 --- python2.7-2.7.orig/debian/PVER-doc.doc-base.PVER-doc.in +++ python2.7-2.7/debian/PVER-doc.doc-base.PVER-doc.in @@ -0,0 +1,19 @@ +Document: @PVER@-doc +Title: Documenting Python (v@VER@) +Author: Fred L. Drake, Jr. +Abstract: The Python language has a substantial body of documentation, much + of it contributed by various authors. The markup used for the Python + documentation is based on LATEX and requires a significant set of + macros written specifically for documenting Python. This document + describes the macros introduced to support Python documentation and + how they should be used to support a wide range of output formats. + . + This document describes the document classes and special markup used + in the Python documentation. Authors may use this guide, in + conjunction with the template files provided with the distribution, + to create or maintain whole documents or sections. +Section: Programming/Python + +Format: HTML +Index: /usr/share/doc/@PVER@/html/documenting/index.html +Files: /usr/share/doc/@PVER@/html/documenting/*.html --- python2.7-2.7.orig/debian/README.python +++ python2.7-2.7/debian/README.python @@ -0,0 +1,153 @@ + + Python 2.x for Debian + --------------------- + +This is Python 2.x packaged for Debian. + +This document contains information specific to the Debian packages of +Python 2.x. + + + + [TODO: This document is not yet up-to-date with the packages.] + + + + + + +Currently, it features those two main topics: + + 1. Release notes for the Debian packages: + 2. Notes for developers using the Debian Python packages: + +Release notes and documentation from the upstream package are installed +in /usr/share/doc/python/. + +Up-to-date information regarding Python on Debian systems is also +available as http://www.debian.org/~flight/python/. + +There's a mailing list for discussion of issues related to Python on Debian +systems: debian-python@lists.debian.org. The list is not intended for +general Python problems, but as a forum for maintainers of Python-related +packages and interested third parties. + + + +1. Release notes for the Debian packages: + + +Results of the regression test: +------------------------------ + +The package does successfully run the regression tests for all included +modules. Seven packages are skipped since they are platform-dependent and +can't be used with Linux. + + +Noteworthy changes since the 1.4 packages: +----------------------------------------- + +- Threading support enabled. +- Tkinter for Tcl/Tk 8.x. +- New package python-zlib. +- The dbmmodule was dropped. Use bsddb instead. gdbmmodule is provided + for compatibility's sake. +- python-elisp adheres to the new emacs add-on policy; it now depends + on emacsen. python-elisp probably won't work correctly with emacs19. + Refer to /usr/doc/python-elisp/ for more information. +- Remember that 1.5 has dropped the `ni' interface in favor of a generic + `packages' concept. +- Python 1.5 regression test as additional package python-regrtest. You + don't need to install this package unless you don't trust the + maintainer ;-). +- once again, modified upstream's compileall.py and py_compile.py. + Now they support compilation of optimized byte-code (.pyo) for use + with "python -O", removal of .pyc and .pyo files where the .py source + files are missing (-d) and finally the fake of a installation directory + when .py files have to be compiled out of place for later installation + in a different directory (-i destdir, used in ./debian/rules). +- The Debian packages for python 1.4 do call + /usr/lib/python1.4/compileall.py in their postrm script. Therefore + I had to provide a link from /usr/lib/python1.5/compileall.py, otherwise + the old packages won't be removed completely. THIS IS A SILLY HACK! + + + +2. Notes for developers using the Debian python packages: + + +Embedding python: +---------------- + +The files for embedding python resp. extending the python interpreter +are included in the python-dev package. With the configuration in the +Debian GNU/Linux packages of python 1.5, you will want to use something +like + + -I/usr/include/python1.5 (e.g. for config.h) + -L/usr/lib/python1.5/config -lpython1.5 (... -lpthread) + (also for Makefile.pre.in, Setup etc.) + +Makefile.pre.in automatically gets that right. Note that unlike 1.4, +python 1.5 has only one library, libpython1.5.a. + +Currently, there's no shared version of libpython. Future version of +the Debian python packages will support this. + + +Python extension packages: +------------------------- + +According to www.python.org/doc/essays/packages.html, extension packages +should only install into /usr/lib/python1.5/site-packages/ (resp. +/usr/lib/site-python/ for packages that are definitely version independent). +No extension package should install files directly into /usr/lib/python1.5/. + +But according to the FSSTND, only Debian packages are allowed to use +/usr/lib/python1.5/. Therefore Debian Python additionally by default +searches a second hierarchy in /usr/local/lib/. These directories take +precedence over their equivalents in /usr/lib/. + +a) Locally installed Python add-ons + + /usr/local/lib/python1.5/site-packages/ + /usr/local/lib/site-python/ (version-independent modules) + +b) Python add-ons packaged for Debian + + /usr/lib/python1.5/site-packages/ + /usr/lib/site-python/ (version-independent modules) + +Note that no package must install files directly into /usr/lib/python1.5/ +or /usr/local/lib/python1.5/. Only the site-packages directory is allowed +for third-party extensions. + +Use of the new `package' scheme is strongly encouraged. The `ni' interface +is obsolete in python 1.5. + +Header files for extensions go into /usr/include/python1.5/. + + +Installing extensions for local use only: +---------------------------------------- + +Most extensions use Python's Makefile.pre.in. Note that Makefile.pre.in +by default will install files into /usr/lib/, not into /usr/local/lib/, +which is not allowed for local extensions. You'll have to change the +Makefile accordingly. Most times, "make prefix=/usr/local install" will +work. + + +Packaging python extensions for Debian: +-------------------------------------- + +Maintainers of Python extension packages should read README.maintainers. + + + + + 03/09/98 + Gregor Hoffleit + +Last change: 07/16/1999 --- python2.7-2.7.orig/debian/README.source +++ python2.7-2.7/debian/README.source @@ -0,0 +1,7 @@ +The source tarball is lacking the files Lib/profile.py and Lib/pstats.py, +which Debian considers to have a license non-suitable for main (the use +of these modules limited to python). + +The package uses quilt to apply / unapply patches. +See /usr/share/doc/quilt/README.source. The series file is generated +during the build. --- python2.7-2.7.orig/debian/pygettext.1 +++ python2.7-2.7/debian/pygettext.1 @@ -0,0 +1,108 @@ +.TH PYGETTEXT 1 "" "pygettext 1.4" +.SH NAME +pygettext \- Python equivalent of xgettext(1) +.SH SYNOPSIS +.B pygettext +[\fIOPTIONS\fR] \fIINPUTFILE \fR... +.SH DESCRIPTION +pygettext is deprecated. The current version of xgettext supports +many languages, including Python. + +pygettext uses Python's standard tokenize module to scan Python +source code, generating .pot files identical to what GNU xgettext generates +for C and C++ code. From there, the standard GNU tools can be used. +.PP +pygettext searches only for _() by default, even though GNU xgettext +recognizes the following keywords: gettext, dgettext, dcgettext, +and gettext_noop. See the \fB\-k\fR/\fB\--keyword\fR flag below for how to +augment this. +.PP +.SH OPTIONS +.TP +\fB\-a\fR, \fB\-\-extract\-all\fR +Extract all strings. +.TP +\fB\-d\fR, \fB\-\-default\-domain\fR=\fINAME\fR +Rename the default output file from messages.pot to name.pot. +.TP +\fB\-E\fR, \fB\-\-escape\fR +Replace non-ASCII characters with octal escape sequences. +.TP +\fB\-D\fR, \fB\-\-docstrings\fR +Extract module, class, method, and function docstrings. +These do not need to be wrapped in _() markers, and in fact cannot +be for Python to consider them docstrings. (See also the \fB\-X\fR option). +.TP +\fB\-h\fR, \fB\-\-help\fR +Print this help message and exit. +.TP +\fB\-k\fR, \fB\-\-keyword\fR=\fIWORD\fR +Keywords to look for in addition to the default set, which are: _ +.IP +You can have multiple \fB\-k\fR flags on the command line. +.TP +\fB\-K\fR, \fB\-\-no\-default\-keywords\fR +Disable the default set of keywords (see above). +Any keywords explicitly added with the \fB\-k\fR/\fB\--keyword\fR option +are still recognized. +.TP +\fB\-\-no\-location\fR +Do not write filename/lineno location comments. +.TP +\fB\-n\fR, \fB\-\-add\-location\fR +Write filename/lineno location comments indicating where each +extracted string is found in the source. These lines appear before +each msgid. The style of comments is controlled by the +\fB\-S\fR/\fB\--style\fR option. This is the default. +.TP +\fB\-o\fR, \fB\-\-output\fR=\fIFILENAME\fR +Rename the default output file from messages.pot to FILENAME. +If FILENAME is `-' then the output is sent to standard out. +.TP +\fB\-p\fR, \fB\-\-output\-dir\fR=\fIDIR\fR +Output files will be placed in directory DIR. +.TP +\fB\-S\fR, \fB\-\-style\fR=\fISTYLENAME\fR +Specify which style to use for location comments. +Two styles are supported: +.RS +.IP \(bu 4 +Solaris # File: filename, line: line-number +.IP \(bu 4 +GNU #: filename:line +.RE +.IP +The style name is case insensitive. +GNU style is the default. +.TP +\fB\-v\fR, \fB\-\-verbose\fR +Print the names of the files being processed. +.TP +\fB\-V\fR, \fB\-\-version\fR +Print the version of pygettext and exit. +.TP +\fB\-w\fR, \fB\-\-width\fR=\fICOLUMNS\fR +Set width of output to columns. +.TP +\fB\-x\fR, \fB\-\-exclude\-file\fR=\fIFILENAME\fR +Specify a file that contains a list of strings that are not be +extracted from the input files. Each string to be excluded must +appear on a line by itself in the file. +.TP +\fB\-X\fR, \fB\-\-no\-docstrings\fR=\fIFILENAME\fR +Specify a file that contains a list of files (one per line) that +should not have their docstrings extracted. This is only useful in +conjunction with the \fB\-D\fR option above. +.PP +If `INPUTFILE' is -, standard input is read. +.SH BUGS +pygettext attempts to be option and feature compatible with GNU xgettext +where ever possible. However some options are still missing or are not fully +implemented. Also, xgettext's use of command line switches with option +arguments is broken, and in these cases, pygettext just defines additional +switches. +.SH AUTHOR +pygettext is written by Barry Warsaw . +.PP +Joonas Paalasmaa put this manual page together +based on "pygettext --help". --- python2.7-2.7.orig/debian/PVER-examples.overrides.in +++ python2.7-2.7/debian/PVER-examples.overrides.in @@ -0,0 +1,2 @@ +# don't care about permissions of the example files +@PVER@-examples binary: executable-not-elf-or-script --- python2.7-2.7.orig/debian/locale-gen +++ python2.7-2.7/debian/locale-gen @@ -0,0 +1,31 @@ +#!/bin/sh + +LOCPATH=`pwd`/locales +export LOCPATH + +[ -d $LOCPATH ] || mkdir -p $LOCPATH + +umask 022 + +echo "Generating locales..." +while read locale charset; do + case $locale in \#*) continue;; esac + [ -n "$locale" -a -n "$charset" ] || continue + echo -n " `echo $locale | sed 's/\([^.\@]*\).*/\1/'`" + echo -n ".$charset" + echo -n `echo $locale | sed 's/\([^\@]*\)\(\@.*\)*/\2/'` + echo -n '...' + if [ -f $LOCPATH/$locale ]; then + input=$locale + else + input=`echo $locale | sed 's/\([^.]*\)[^@]*\(.*\)/\1\2/'` + fi + localedef -i $input -c -f $charset $LOCPATH/$locale #-A /etc/locale.alias + echo ' done'; \ +done < + +Last change: 2001-12-14 --- python2.7-2.7.orig/debian/idle-PVER.postrm.in +++ python2.7-2.7/debian/idle-PVER.postrm.in @@ -0,0 +1,9 @@ +#! /bin/sh -e + +if [ "$1" = "purge" ]; then + rm -rf /etc/idle-@PVER@ +fi + +#DEBHELPER# + +exit 0 --- python2.7-2.7.orig/debian/changelog +++ python2.7-2.7/debian/changelog @@ -0,0 +1,2354 @@ +python2.7 (2.7-9ubuntu1) natty; urgency=low + + * Disable profiled build on powerpc + + -- Scott Kitterman Fri, 22 Oct 2010 10:01:45 -0400 + +python2.7 (2.7-9) experimental; urgency=low + + * Update to 20101016, taken from the 2.7 branch. + + -- Matthias Klose Sat, 16 Oct 2010 12:46:57 +0200 + +python2.7 (2.7-8) experimental; urgency=low + + * Disabled the profiled build on armel. + + -- Matthias Klose Thu, 23 Sep 2010 15:06:06 +0200 + +python2.7 (2.7-7) experimental; urgency=low + + * Update to 20100922, taken from the 2.7 branch. + * Update GNU/Hurd patches (Pino Toscano). Closes: #597419. + + -- Matthias Klose Wed, 22 Sep 2010 20:35:24 +0200 + +python2.7 (2.7-6) experimental; urgency=low + + * Update to 20100915, taken from the 2.7 branch. + - Fix issue #9729, Unconnected SSLSocket.{send,recv} raises TypeError + (Andrew Bennetts). LP: #637821. + * Add copyright information for expat, libffi and zlib. Addresses: #596276. + * Apply proposed fix for issue 9054, configure --with-system-expat. + * Provide Lib/plat-gnukfreebsd[78] (Jakub Wilk). Addresses: #593818. + + -- Matthias Klose Wed, 15 Sep 2010 17:43:18 +0200 + +python2.7 (2.7-5) experimental; urgency=low + + * Update to 20100829, taken from the 2.7 branch. + * Don't configure --with-system-expat, segfaults the interpreter in the + testsuite. + * Disable more tests on hppa and hurd-i386, which fail on the buildds. + + -- Matthias Klose Sun, 29 Aug 2010 16:22:37 +0200 + +python2.7 (2.7-4) experimental; urgency=low + + * Update to 20100822, taken from the 2.7 branch. + * Fixed in previous 2.7 uploads: Multiple integer overflows in audioop.c + in the audioop module (CVE-2010-1634). + * Fix some lintian warnings. + * Configure --with-system-expat. + + -- Matthias Klose Mon, 23 Aug 2010 13:03:40 +0200 + +python2.7 (2.7-3) experimental; urgency=low + + * Update to 20100807, taken from the 2.7 branch. + * Move '/usr/local/.../dist-packages' before '/usr/lib/.../dist-packages' + in sys.path. Adresses: #588342. + * Fix detection of ffi.h header file. Closes: #591408. + * python2-7-dev: Depend on libssl-dev. LP: #611845. + + -- Matthias Klose Sat, 07 Aug 2010 21:28:04 +0200 + +python2.7 (2.7-2) experimental; urgency=low + + * Complete debug-build.diff, some parts lost in quilt conversion. + * Move the pkgconfig file into the -dev package. + + -- Matthias Klose Tue, 06 Jul 2010 21:07:48 +0200 + +python2.7 (2.7-1) experimental; urgency=low + + * Python 2.7 release. + * Update to 20100706, taken from the trunk. + * Update symbols files. + + -- Matthias Klose Tue, 06 Jul 2010 07:21:23 +0200 + +python2.7 (2.7~rc2-3) experimental; urgency=low + + * Update to 20100703, taken from the trunk. + * Move the _weakrefset module, not extension to -minimal. Closes: #587568. + * Move the sysconfig module to -minimal. Closes: #586113. + * Move the shutil module to python2.6-minimal. Addresses: #587628. + + -- Matthias Klose Sat, 03 Jul 2010 13:27:36 +0200 + +python2.7 (2.7~rc2-2) experimental; urgency=low + + * Fix applying plat-linux2* patches. + * Use the profiled build on armel, sparc and sparc64. + + -- Matthias Klose Tue, 29 Jun 2010 08:04:59 +0200 + +python2.7 (2.7~rc2-1) experimental; urgency=low + + * Python 2.7 release candidate 2. + * Update to 20100628, taken from the trunk. + * Merge packaging changes from python2.6 (2.6.5+20100628-1). + + -- Matthias Klose Tue, 29 Jun 2010 00:57:00 +0200 + +python2.7 (2.7~b1-2) experimental; urgency=low + + * Update to 20100508, taken from the trunk. + + -- Matthias Klose Sat, 08 May 2010 17:34:07 +0200 + +python2.7 (2.7~b1-1) experimental; urgency=low + + * Python 2.7 beta1. + * Update to 20100420, taken from the trunk. + * Update libpython symbols files. + * Apply proposed patch for issue #7332, segfaults in + PyMarshal_ReadLastObjectFromFile in import_submodule. + * Don't build-depend on locales on avr32. Closes: #575144. + + -- Matthias Klose Tue, 20 Apr 2010 23:53:42 +0200 + +python2.7 (2.7~a4-1) experimental; urgency=low + + * Python 2.7 alpha4. + * Update to 20100316, taken from the trunk. + * Point distutils.sysconfig to the system installation. Closes: #573363. + + -- Matthias Klose Tue, 16 Mar 2010 15:45:07 +0100 + +python2.7 (2.7~a3-1) experimental; urgency=low + + * Python 2.7 alpha3. + + -- Matthias Klose Tue, 16 Feb 2010 03:04:01 +0100 + +python2.7 (2.7~a2-1) experimental; urgency=low + + * Python 2.7 alpha2. + + -- Matthias Klose Sat, 16 Jan 2010 14:49:59 +0100 + +python2.6 (2.6.5+20100628-1) unstable; urgency=low + + * Update to 20100614, taken from the 2.6 release branch (r82337). + * Apply plat-linux2- patch for alpha, hppa, mips, mipsel, sparc + and sparc64. + + -- Matthias Klose Mon, 28 Jun 2010 21:26:43 +0200 + +python2.6 (2.6.5+20100626-1) unstable; urgency=low + + * Update to 20100614, taken from the 2.6 release branch (r82245). + * Update libpython symbols files. Closes: #587012. + * Move the logging package and the runpy module to python2.6-minimal. + + -- Matthias Klose Sat, 26 Jun 2010 14:29:41 +0200 + +python2.6 (2.6.5+20100616-1) unstable; urgency=medium + + * Update to 20100614, taken from the 2.6 release branch (r81601). + * Reapply the backport for issue #8233, lost in the conversion to + quilt. + * Disable the profiled build on alpha. + * Make pydoc more robust not to fail on exceptions other than import + exceptions. + * posixmodule: Add flags for statvfs.f_flag to constant list. + + -- Matthias Klose Wed, 16 Jun 2010 07:56:40 +0200 + +python2.6 (2.6.5+20100529-1) unstable; urgency=low + + * Update to 20100529, taken from the 2.6 release branch (r81601). + - Fix issue #5753, CVE-2008-5983 python: untrusted python modules + search path. Closes: #572010. + * Convert internal dpatch system to quilt. + * Build the ossaudio extension on GNU/kFreeBSD. Closes: #574696. + + -- Matthias Klose Sat, 29 May 2010 15:07:51 +0200 + +python2.6 (2.6.5-2) unstable; urgency=low + + * Update libpython symbols files. + * debian/patches/issue8032.dpatch: Update to version from the + trunk. + * Fix issue #8329: Don't return the same lists from select.select + when no fds are changed. + * Fix issue #8310: Allow dis to examine new style classes. + * Fix issues #8279: Fix test_gdb failures. + * Fix issue #8233: When run as a script, py_compile.py optionally + takes a single argument `-`. + * Apply proposed patch for issue #7332, segfaults in + PyMarshal_ReadLastObjectFromFile in import_submodule. + * Don't build-depend on locales on avr32. Closes: #575144. + + -- Matthias Klose Tue, 20 Apr 2010 19:41:36 +0200 + +python2.6 (2.6.5-1ubuntu6) lucid; urgency=low + + * Fix applying patch for issue #8310. + + -- Matthias Klose Fri, 16 Apr 2010 14:20:35 +0200 + +python2.6 (2.6.5-1ubuntu5) lucid; urgency=low + + * Fix issue #8329: Don't return the same lists from select.select + when no fds are changed. + * Fix issue #8310: Allow dis to examine new style classes. + + -- Matthias Klose Thu, 15 Apr 2010 01:21:07 +0200 + +python2.6 (2.6.5-1ubuntu4) lucid; urgency=low + + * debian/patches/issue8032.dpatch: Update to version from the + trunk. Upload for beta2 to avoid apport errors. + - Handle PyFrameObject's: LP: #543624, #548723. + - Detect cycles in object reference graph and add extra + protection: LP: #544823, LP: #552356. + + -- Matthias Klose Thu, 01 Apr 2010 22:53:06 +0200 + +python2.6 (2.6.5-1ubuntu3) lucid; urgency=low + + * debian/patches/issue8140.dpatch: Incomplete patch; regenerate. + * debian/patches/issue8032.dpatch: Update to v4: + - Add support for PySetObject (set/frozenset). + - Add support for PyBaseExceptionObject (BaseException). + - Fix a signed vs unsigned char issue that led to exceptions + in gdb for PyStringObject instances. + - Handle the case of loops in the object reference graph. + - Unit tests for all of the above. + + -- Matthias Klose Wed, 31 Mar 2010 18:52:32 +0200 + +python2.6 (2.6.5-1ubuntu2) lucid; urgency=low + + * Disable profiled build on powerpc. + + -- Matthias Klose Sat, 20 Mar 2010 15:17:18 +0100 + +python2.6 (2.6.5-1ubuntu1) lucid; urgency=low + + * Merge with Debian (2.6.5-1). + + -- Matthias Klose Sat, 20 Mar 2010 03:57:17 +0100 + +python2.6 (2.6.5-1) unstable; urgency=low + + * Python 2.6.5 final release. + * Fix issue #4961: Inconsistent/wrong result of askyesno function in + tkMessageBox with Tcl8.5. LP: #462950. + * Issue #8154, fix segfault with os.execlp('true'). LP: #418848. + * Apply proposed patch for issue #8032, gdb7 hooks for debugging. + + -- Matthias Klose Fri, 19 Mar 2010 00:12:55 +0100 + +python2.6 (2.6.5~rc2-2) unstable; urgency=low + + * Add copyright notices for the readline and _ssl extensions. + Closes: #573866. + * Backport issue #8140: Extend compileall to compile single files. + Add -i option. + * Backport issue #6949, build _bsddb extension with db-4.8.x. + + -- Matthias Klose Tue, 16 Mar 2010 03:02:21 +0100 + +python2.6 (2.6.5~rc2-1) unstable; urgency=low + + * Python 2.6.5 release candidate 2. + - Replace the Monty Python audio test file. Closes: #568674. + * Fix build failure on sparc64. Closes: #570845. + + -- Matthias Klose Thu, 11 Mar 2010 16:50:03 +0100 + +python2.6 (2.6.5~rc2-0ubuntu1) lucid; urgency=low + + * Python 2.6.5 release candidate 2. + + -- Matthias Klose Thu, 11 Mar 2010 13:30:19 +0100 + +python2.6 (2.6.4-6ubuntu1) lucid; urgency=low + + * Merge with Debian (2.6.4-6). + + -- Matthias Klose Tue, 16 Feb 2010 01:08:50 +0100 + +python2.6 (2.6.4-6) unstable; urgency=low + + * Update to 20100215, taken from the 2.6 release branch. + * python2.6-minimal: Skip moving syssite contents to new location, if + /usr/local/lib/python2.6 cannot be written. Closes: #569532. LP: #338227. + * libpython2.6: Fix symlink in /usr/lib/python2.6/config. LP: #521050. + + -- Matthias Klose Mon, 15 Feb 2010 22:12:18 +0100 + +python2.6 (2.6.4-5ubuntu1) lucid; urgency=low + + * Merge with Debian (2.6.4-5). + + -- Matthias Klose Sun, 31 Jan 2010 22:31:41 +0100 + +python2.6 (2.6.4-5) unstable; urgency=low + + * Update to 20100131, taken from the 2.6 release branch. + - Fix typo in os.execvp docstring. Closes: #558764. + * distutils.sysconfig.get_python_lib(): Only return ".../dist-packages" if + prefix is the default prefix and if PYTHONUSERBASE is not set in the + environment and if --user option is not present. LP: #476005. + * distutils install: Don't install into /usr/local/local, if option + --prefix=/usr/local is present, without changing the install prefix. + LP: #510211. + + -- Matthias Klose Sun, 31 Jan 2010 21:16:51 +0100 + +python2.6 (2.6.4-4ubuntu1) lucid; urgency=low + + * Update to 20100122, taken from the 2.6 release branch. + - Fix DoS via XML document with malformed UTF-8 sequences (CVE_2009_3560). + Closes: #566233. + - Fix typo in os.execvp docstring. Closes: #558764. + * python2.6-doc: Fix searching in local documentation. LP: #456025. + * Update locale module from the trunk. LP: #223281. + * Merge with Debian (2.6.4-4). + + -- Matthias Klose Fri, 22 Jan 2010 11:37:29 +0100 + +python2.6 (2.6.4-4) unstable; urgency=low + + * Update to 20100122, taken from the 2.6 release branch. + - Fix DoS via XML document with malformed UTF-8 sequences (CVE_2009_3560). + Closes: #566233. + * Hurd fixes (Pino Toscano). Closes: #565693: + - hurd-broken-poll.dpatch: ported from 2.5. + - hurd-disable-nonworking-constants.dpatch: disable a few constants from + the public API whose C counterparts are not implemented, so using them + either always blocks or always fails (caused issues in the test suite). + - Exclude the profiled build for hurd. + - Disable four blocking tests from the test suite. + + -- Matthias Klose Fri, 22 Jan 2010 11:10:41 +0100 + +python2.6 (2.6.4-3) unstable; urgency=low + + * Disable the profiled build on s390, mips, mipsel. + * Fix symbol files for kfreebsd-amd64 and sparc64. + + -- Matthias Klose Sat, 16 Jan 2010 16:12:17 +0100 + +python2.6 (2.6.4-2) unstable; urgency=low + + * Update to 20100116, taken from the 2.6 release branch. + * Fix bashism in makesetup shell script. Closes: #530170, #530171. + * Fix build issues on avr (Bradley Smith). Closes: #528439. + - Configure --without-ffi. + - Don't run lengthly tests. + * locale.py: Update locale aliases from the 2.7 branch. + + -- Matthias Klose Sat, 16 Jan 2010 11:05:12 +0100 + +python2.6 (2.6.4-1) experimental; urgency=low + + * Python 2.6.4 final release. + - Issue #7120: logging: Removed import of multiprocessing which is causing + crash in GAE. + - Issue #7149: fix exception in urllib when detecting proxy settings + on OSX. + - Issue #7115: Fixed the extension module builds that is failing when + using paths in the extension name instead of dotted names. LP: #449734. + - Issue #6894: Fixed the issue urllib2 doesn't respect "no_proxy" + environment. + - Issue #7052: Removed nonexisting NullHandler from logging.__all__. + - Issue #7039: Fixed distutils.tests.test_sysconfig when running on + installation with no build. + - Issue #7019: Raise ValueError when unmarshalling bad long data, instead + of producing internally inconsistent Python longs. + * distutils install: Don't install into /usr/local/local, if option + --prefix=/usr/local is present. + + -- Matthias Klose Tue, 27 Oct 2009 01:22:21 +0100 + +python2.6 (2.6.4~rc1-1) experimental; urgency=low + + * Python 2.6.4 release candidate 1. + - Issue #7052: Removed nonexisting NullHandler from logging.__all__. + - Issue #7039: Fixed distutils.tests.test_sysconfig when running on + installation with no build. + - Issue #7019: Raise ValueError when unmarshalling bad long data, instead + of producing internally inconsistent Python longs. + - Issue #7068: Fixed the partial renaming that occured in r72594. + - Issue #7042: Fix test_signal (test_itimer_virtual) failure on OS X 10.6. + * Remove the conflict with python-setuptools (fixed in issue #7068). + * Build _hashlib as a builtin. + * python2.6-doc: Don't compress the sphinx inventory. + * python2.6-doc: Fix jquery.js symlink. + + -- Matthias Klose Sat, 10 Oct 2009 10:21:02 +0200 + +python2.6 (2.6.3-1) experimental; urgency=low + + * Final Python 2.6.3 release. + - Issue #5329: Fix os.popen* regression from 2.5 with commands as a + sequence running through the shell. + - Issue #6990: Fix threading.local subclasses leaving old state around + after a reference cycle GC which could be recycled by new locals. + - Issue #6790: Make it possible again to pass an `array.array` to + `httplib.HTTPConnection.send`. + - Issue #6922: Fix an infinite loop when trying to decode an invalid + UTF-32 stream with a non-raising error handler like "replace" or + "ignore". + - Issue #1590864: Fix potential deadlock when mixing threads and fork(). + - Issue #6844: Do not emit DeprecationWarnings when accessing a "message" + attribute on exceptions that was set explicitly. + - Issue #6236, #6348: Fix various failures in the `io` module under AIX + and other platforms, when using a non-gcc compiler. Patch by egreen. + - Issue #6851: Fix urllib.urlopen crash on secondairy threads on OSX 10.6 + - Issue #6947: Fix distutils test on windows. Patch by Hirokazu Yamamoto. + - Issue #4606: Passing 'None' if ctypes argtype is set to POINTER(...) + does now always result in NULL. + - Issue #5042: ctypes Structure sub-subclass does now initialize + correctly with base class positional arguments. + - Issue #6938: Fix a TypeError in string formatting of a multiprocessing + debug message. + - Issue #6944: Fix a SystemError when socket.getnameinfo() was called + with something other than a tuple as first argument. + - Issue #6980: Fix ctypes build failure on armel-linux-gnueabi with + -mfloat-abi=softfp. + * python2.6-dbg: Don't create debug subdirectory in /usr/local. No + separate debug directory needed anymore. + * Run the benchmark with -C 2 -n 5 -w 4 on all architectures. + * Build-depend on the versioned db4.x-dev to avoid unexpected updates + for anydbm databases. + + -- Matthias Klose Sat, 03 Oct 2009 13:19:56 +0200 + +python2.6 (2.6.2-3) experimental; urgency=low + + * Update to 20090919, taken from the 2.6 release branch. + * Add a conflict to python-setuptools (<< 0.6c9-3), C extension + builds broken. + * Add new symbols for update from the branch. + + -- Matthias Klose Sat, 19 Sep 2009 10:36:34 +0200 + +python2.6 (2.6.2-2) experimental; urgency=low + + * Symbol _Py_force_double@Base is i386 only. Closes: #534208. + + -- Matthias Klose Tue, 23 Jun 2009 06:14:40 +0200 + +python2.6 (2.6.2-1) experimental; urgency=low + + * Final Python 2.6.2 release. + - Update Doc/tools/sphinxext/download.html. Closes: #526797. + * Update to 20090621, taken from the 2.6 release branch. + + * Address issues when working with PYTHONUSERBASE and non standard prefix + (pointed out by Larry Hastings): + - distutils.sysconfig.get_python_lib(): Only return ".../dist-packages" if + prefix is the default prefix and if PYTHONUSERBASE is not set in the + environment. + - site.addusersitepackages(): Add USER_BASE/.../dist-packages to sys.path. + * Always use the `unix_prefix' scheme for setup.py install in a virtualenv + setup. LP: #339904. + * Don't make the setup.py install options --install-layout=deb and --prefix + conflict with each other. + * distutils: Always install into `/usr/local/lib/python2.6/dist-packages' + if an option `--prefix=/usr/local' is present (except for virtualenv + and PYTHONUSERBASE installations). LP: #362570. + * Always use `site-packages' as site directory name in virtualenv. + + * Do not add /usr/lib/pythonXY.zip on sys.path. + * Add symbols files for libpython2.6 and python2.6-dbg, don't include symbols + from builtins, which can either be built as builtins or extensions. + * Keep an empty lib-dynload in python2.6-minimal to avoid a warning on + startup. + * Build a shared library configured --with-pydebug. LP: #322580. + * Fix some lintian warnings. + * Use the information in /etc/lsb-release for platform.dist(). LP: #196526. + * Move the bdist_wininst files into the -dev package (only needed to build + windows installers). + * Document changes to the site directory name in the installation manual. + * Fix issue #1113244: Py_XINCREF, Py_DECREF, Py_XDECREF: Add + `do { ... } while (0)' to avoid compiler warnings. Closes: #516956. + * debian/pyhtml2devhelp.py: update for python 2.6 (Marc Deslauriers). + * debian/rules: re-enable documentation files for devhelp. LP: #338791. + * python2.6-doc: Depend on libjs-jquery, use jquery.js from this package. + Closes: #523482. + + -- Matthias Klose Sun, 21 Jun 2009 16:12:15 +0200 + +python2.6 (2.6.1-3) experimental; urgency=low + + * Update to 20090318, taken from the 2.6 release branch. + * Use the information in /etc/lsb-release for platform.dist(). + * Update installation schemes: LP: #338395. Closes: #520278. + - When the --prefix option is used for setup.py install, Use the + `unix_prefix' scheme. + - Use the `deb_system' scheme if --install-layout=deb is specified. + - Use the the `unix_local' scheme if neither --install-layout=deb + nor --prefix is specified. + - The options --install-layout=deb and --prefix are exclusive. + * Don't fail installation/removal if directories in /usr/local cannot + be created. LP: #338227. + * Don't try to move away the site-packages directory. There never was a + python2.6 upload using site-packages. Closes: #518780. + * Fix build failure on mips/mipsel. Closes: #519386. + + -- Matthias Klose Wed, 18 Mar 2009 22:17:20 +0100 + +python2.6 (2.6.1-2) experimental; urgency=low + + * Move libpython2.6.a into the python2.6-dev package. + * Move idlelib into the idle-python2.6 package. + + -- Matthias Klose Wed, 25 Feb 2009 18:42:19 +0100 + +python2.6 (2.6.1-1) experimental; urgency=low + + * New upstream version, upload to experimental. + * Update to 20090225, taken from the 2.6 release branch. + * Don't build-depend on locales on armel, hppa, ia64 and mipsel; package is + currently not installable. + + -- Matthias Klose Wed, 25 Feb 2009 18:42:19 +0100 + +python2.6 (2.6.1-0ubuntu9) jaunty; urgency=low + + * Don't build pyexpat, _elementtree and _ctypes as builtin extensions, + third party packages make too many assumptions about these not built + as builtins. + + -- Matthias Klose Tue, 24 Feb 2009 16:34:27 +0100 + +python2.6 (2.6.1-0ubuntu8) jaunty; urgency=low + + * Link the shared libpython with $(MODLIBS). + + -- Matthias Klose Sun, 22 Feb 2009 16:38:49 +0100 + +python2.6 (2.6.1-0ubuntu7) jaunty; urgency=low + + * Update to 20090222, taken from the 2.6 release branch. + + -- Matthias Klose Sun, 22 Feb 2009 10:35:29 +0100 + +python2.6 (2.6.1-0ubuntu6) jaunty; urgency=low + + * Don't build the gdbm extension from the python2.6 source. + * Build the dbm extension using libdb. + * Don't build-depend on locales on sparc (currently not installable), only + needed by the testsuite. + * Update to 20090219, taken from the 2.6 release branch. + + -- Matthias Klose Thu, 19 Feb 2009 12:43:20 +0100 + +python2.6 (2.6.1-0ubuntu5) jaunty; urgency=low + + * Add build dependency on libdb-dev. + + -- Matthias Klose Mon, 16 Feb 2009 13:34:41 +0100 + +python2.6 (2.6.1-0ubuntu4) jaunty; urgency=low + + * Disable the profiled build on all architectures. + + -- Matthias Klose Mon, 16 Feb 2009 11:18:51 +0100 + +python2.6 (2.6.1-0ubuntu3) jaunty; urgency=low + + * Disable the profiled build on armel as well. + + -- Matthias Klose Sun, 15 Feb 2009 10:38:02 +0100 + +python2.6 (2.6.1-0ubuntu2) jaunty; urgency=low + + * Don't use the profiled build on amd64, lpia and sparc (GCC + PR profile/38292). + + -- Matthias Klose Sat, 14 Feb 2009 14:09:34 +0100 + +python2.6 (2.6.1-0ubuntu1) jaunty; urgency=low + + * Update to 20090211, taken from the 2.6 release branch. + + -- Matthias Klose Fri, 13 Feb 2009 12:51:00 +0100 + +python2.6 (2.6.1-0ubuntu1~ppa1) jaunty; urgency=low + + * Python 2.6.1 release. + * Update to 20081206, taken from the 2.6 release branch. + * Ensure that all extensions from the -minimal package are statically + linked into the interpreter. + * Include expat, _elementtree, datetime, bisect, _bytesio, _locale, + _fileio in -minimal to link these extensions statically. + + -- Matthias Klose Fri, 05 Dec 2008 20:43:51 +0100 + +python2.6 (2.6-0ubuntu1~ppa5) intrepid; urgency=low + + * Test build + + -- Matthias Klose Fri, 14 Nov 2008 10:14:38 +0100 + +python2.6 (2.6-0ubuntu1~ppa4) intrepid; urgency=low + + * Do not build the bsddb3 module from this source, but recommend the + python-bsddb3 package (will be a dependency after python-bsddb3 is in + the archive). + * For locally installed packages, create a directory + /usr/local/lib/python2.6/dist-packages. This is the default for + installations done with distutils and setuptools. Third party stuff + packaged within the distribution goes to /usr/lib/python2.6/dist-packages. + There is no /usr/lib/python2.6/site-packages in the file system and + on sys.path. No package within the distribution must not install + anything in this location. + * Place the gdbm extension into the python2.6 package. + * distutils: Add an option --install-layout=deb, which + - installs into $prefix/dist-packages instead of $prefix/site-packages. + - doesn't encode the python version into the egg name. + + -- Matthias Klose Sat, 25 Oct 2008 11:12:24 +0000 + +python2.6 (2.6-0ubuntu1~ppa3) intrepid; urgency=low + + * Build-depend on libdb4.6-dev, instead of libdb-dev (4.7). Test suite + hangs in the bsddb tests. + + -- Matthias Klose Wed, 22 Oct 2008 11:05:13 +0200 + +python2.6 (2.6-0ubuntu1~ppa2) intrepid; urgency=low + + * Update to 20081021, taken from the 2.6 release branch. + * Fix typos and section names in doc-base files. LP: #273344. + * Build a new package libpython2.6. + * For locally installed packages, create a directory + /usr/local/lib/python2.6/system-site-packages, which is symlinked + from /usr/lib/python2.6/site-packages. Third party stuff packaged + within the distribution goes to /usr/lib/python2.6/dist-packages. + + -- Matthias Klose Tue, 21 Oct 2008 18:09:31 +0200 + +python2.6 (2.6-0ubuntu1~ppa1) intrepid; urgency=low + + * Python 2.6 release. + * Update to current branch 20081009. + + -- Matthias Klose Thu, 09 Oct 2008 14:28:26 +0200 + +python2.6 (2.6~b3-0ubuntu1~ppa1) intrepid; urgency=low + + * Python 2.6 beta3 release. + + -- Matthias Klose Sun, 24 Aug 2008 01:34:54 +0000 + +python2.6 (2.6~b2-0ubuntu1~ppa1) intrepid; urgency=low + + * Python 2.6 beta2 release. + + -- Matthias Klose Thu, 07 Aug 2008 16:45:56 +0200 + +python2.6 (2.6~b1-0ubuntu1~ppa1) intrepid; urgency=low + + * Python 2.6 beta1 release. + + -- Matthias Klose Tue, 15 Jul 2008 12:57:20 +0000 + +python2.6 (2.6~a3-0ubuntu1~ppa2) hardy; urgency=low + + * Test build + + -- Matthias Klose Thu, 29 May 2008 18:08:48 +0200 + +python2.6 (2.6~a3-0ubuntu1~ppa1) hardy; urgency=low + + * Python 2.6 alpha3 release. + * Update to current trunk 20080523. + + -- Matthias Klose Thu, 22 May 2008 17:37:46 +0200 + +python2.5 (2.5.2-5) unstable; urgency=low + + * Backport new function signal.set_wakeup_fd from the trunk. + Background: http://bugzilla.gnome.org/show_bug.cgi?id=481569 + + -- Matthias Klose Wed, 30 Apr 2008 12:05:10 +0000 + +python2.5 (2.5.2-4) unstable; urgency=low + + * Update to 20080427, taken from the 2.5 release branch. + - Fix issues #2670, #2682. + * Disable running pybench on the hppa buildd (ftbfs). + * Allow setting BASECFLAGS, OPT and EXTRA_LDFLAGS (like, CC, CXX, CPP, + CFLAGS, CPPFLAGS, CCSHARED, LDSHARED) from the environment. + * Support parallel= in DEB_BUILD_OPTIONS (see #209008). + + -- Matthias Klose Sun, 27 Apr 2008 10:40:51 +0200 + +python2.5 (2.5.2-3) unstable; urgency=medium + + * Update to 20080416, taken from the 2.5 release branch. + - Fix CVE-2008-1721, integer signedness error in the zlib extension module. + - Fix urllib2 file descriptor happens byte-at-a-time, reverting + a fix for excessively large memory allocations when calling .read() + on a socket object wrapped with makefile(). + * Disable some regression tests on some architectures: + - arm: test_compiler, test_ctypes. + - armel: test_compiler. + - hppa: test_fork1, test_wait3. + - m68k: test_bsddb3, test_compiler. + * Build-depend on libffi-dev instead of libffi4-dev. + * Fix CVE-2008-1679, integer overflows in the imageop module. + + -- Matthias Klose Wed, 16 Apr 2008 23:37:46 +0200 + +python2.5 (2.5.2-2) unstable; urgency=low + + * Use site.addsitedir() to add directories in /usr/local to sys.path. + Addresses: #469157, #469818. + + -- Matthias Klose Sat, 08 Mar 2008 16:11:23 +0100 + +python2.5 (2.5.2-1) unstable; urgency=low + + * Python 2.5.2 release. + * Merge from Ubuntu: + - Move site customization into sitecustomize.py, don't make site.py + a config file. Addresses: #309719, #413172, #457361. + - Move site.py to python2.4-minimal, remove `addbuilddir' from site.py, + which is unnecessary for installed builds. + - python2.5-dev: Recommend libc-dev instead of suggesting it. LP: #164909. + - Fix issue 961805, Tk Text.edit_modified() fails. LP: #84720. + + -- Matthias Klose Thu, 28 Feb 2008 23:18:52 +0100 + +python2.5 (2.5.1-7) unstable; urgency=low + + * Update to 20080209, taken from the 2.5 release branch. + * Build the _bsddb extension with db-4.5 again; 4.6 is seriously + broken when used with the _bsddb extension. + * Do not run pybench on arm and armel. + * python2.5: Provide python2.5-wsgiref. + * Fix a pseudo RC report with duplicated attributes in the control + file. Closes: #464307. + + -- Matthias Klose Sun, 10 Feb 2008 00:22:57 +0100 + +python2.5 (2.5.1-6) unstable; urgency=low + + * Update to 20080102, taken from the 2.5 release branch. + - Only define _BSD_SOURCE on OpenBSD systems. Closes: #455400. + * Fix handling of packages in linecache.py (Kevin Goodsell). LP: #70902. + * Bump debhelper to v5. + * Register binfmt for .py[co] files. + * Use absolute paths when byte-compiling files. Addresses: #453346. + Closes: #413566, LP: #177722. + * CVE-2007-4965, http://bugs.python.org/issue1179: + Multiple integer overflows in the imageop module in Python 2.5.1 and + earlier allow context-dependent attackers to cause a denial of service + (application crash) and possibly obtain sensitive information (memory + contents) via crafted arguments to (1) the tovideo method, and unspecified + other vectors related to (2) imageop.c, (3) rbgimgmodule.c, and other + files, which trigger heap-based buffer overflows. + Patch prepared by Stephan Herrmann. Closes: #443333, LP: #163845. + * Register info docs when doing source only uploads. LP: #174786. + * Remove deprecated value from categories in desktop file. LP: #172874. + * python2.5-dbg: Don't include the gdbm and _tkinter extensions, now provided + in separate packages. + * Provide a symlink changelog -> NEWS. Closes: #439271. + * Fix build failure on hurd, working around poll() on systems on which it + returns an error on invalid FDs. Closes: #438914. + * Configure --with-system-ffi on all architectures. Closes: #448520. + * Fix version numbers in copyright and README files (Dan O'Huiginn). + Closes: #446682. + * Move some documents from python2.5 to python2.5-dev. + + -- Matthias Klose Wed, 02 Jan 2008 22:22:19 +0100 + +python2.5 (2.5.1-5) unstable; urgency=low + + * Build the _bsddb extension with db-4.6. + + -- Matthias Klose Fri, 17 Aug 2007 00:39:35 +0200 + +python2.5 (2.5.1-4) unstable; urgency=low + + * Update to 20070813, taken from the 2.5 release branch. + * Include plat-mac/plistlib.py (plat-mac is not in sys.path by default. + Closes: #435826. + * Use emacs22 to build the documentation in info format. Closes: #434969. + * Build-depend on db-dev (>= 4.6). Closes: #434965. + + -- Matthias Klose Mon, 13 Aug 2007 22:22:44 +0200 + +python2.5 (2.5.1-3) unstable; urgency=high + + * Support mixed-endian IEEE floating point, as found in the ARM old-ABI + (Aurelien Jarno). Closes: #434905. + + -- Matthias Klose Fri, 27 Jul 2007 20:01:35 +0200 + +python2.5 (2.5.1-2) unstable; urgency=low + + * Update to 20070717, taken from the 2.5 release branch. + * Fix reference count for sys.pydebug variable. Addresses: #431393. + * Build depend on libbluetooth-dev instead of libbluetooth2-dev. + + -- Matthias Klose Tue, 17 Jul 2007 14:09:47 +0200 + +python2.5 (2.5.1-1) unstable; urgency=low + + * Python-2.5.1 release. + * Build-depend on gcc-4.1 (>= 4.1.2-4) on alpha, powerpc, s390, sparc. + * Merge from Ubuntu: + - Add debian/patches/subprocess-eintr-safety.dpatch (LP: #87292): + - Create and use wrappers around read(), write(), and os.waitpid() in the + subprocess module which retry the operation on an EINTR (which happens + if e. g. an alarm was raised while the system call was in progress). + It is incredibly hard and inconvenient to sensibly handle this in + applications, so let's fix this at the right level. + - Patch based on original proposal of Peter <85>strand + in http://python.org/sf/1068268. + - Add two test cases. + - Change the interpreter to build and install python extensions + built with the python-dbg interpreter with a different name into + the same path (by appending `_d' to the extension name). The debug build + of the interpreter tries to first load a foo_d.so or foomodule_d.so + extension, then tries again with the normal name. + - When trying to import the profile and pstats modules, don't + exit, add a hint to the exception pointing to the python-profiler + package, don't exit. + - Keep the module version in the .egg-info name, only remove the + python version. + - python2.5-dbg: Install Misc/SpecialBuilds.txt, document the + debug changes in README.debug. + * Update to 20070425, taken from the 2.5 release branch. + + -- Matthias Klose Wed, 25 Apr 2007 22:12:50 +0200 + +python2.5 (2.5-6) unstable; urgency=medium + + * webbrowser.py: Recognize other browsers: www-browser, x-www-browser, + iceweasel, iceape. + * Move pyconfig.h from the python2.5-dev into the python2.5 package; + required by builds for pure python modules without having python2.5-dev + installed (matching the functionality in python2.4). + * Move the unicodedata module into python2.5-minimal; allows byte compilation + of UTF8 encoded files. + * Do not install anymore outdated debhelper sample scripts. + * Install Misc/SpecialBuilds.txt as python2.5-dbg document. + + -- Matthias Klose Wed, 21 Feb 2007 01:17:12 +0100 + +python2.5 (2.5-5) unstable; urgency=high + + * Do not run the python benchmark on m68k. Timer problems. + Fixes FTBFS on m68k. + * Update to 20061209, taken from the 2.5 release branch. + - Fixes building the library reference in info format. + + -- Matthias Klose Sat, 9 Dec 2006 13:40:48 +0100 + +python2.5 (2.5-4) unstable; urgency=medium + + * Update to 20061203, taken from the 2.5 release branch. + - Fixes build failures on knetfreebsd and the hurd. Closes: #397000. + * Clarify README about distutils. Closes: #396394. + * Move python2.5-config to python2.5-dev. Closes: #401451. + * Cleanup build-conflicts. Addresses: #394512. + + -- Matthias Klose Sun, 3 Dec 2006 18:22:49 +0100 + +python2.5 (2.5-3.1) unstable; urgency=low + + * Non-maintainer upload. + * python2.5-minimal depends on python-minimal (>= 2.4.4-1) because it's the + first version which lists python2.5 as an unsupported runtime (ie a + runtime that is available but for which modules are not auto-compiled). + And being listed there is required for python-central to accept the + installation of python2.5-minimal. Closes: #397006 + + -- Raphael Hertzog Wed, 22 Nov 2006 15:41:06 +0100 + +python2.5 (2.5-3) unstable; urgency=medium + + * Update to 20061029 (2.4.4 was released on 20061019), taken from + the 2.5 release branch. We do not want to have regressions in + 2.5 compared to the 2.4.4 release. + * Don't run pybench on m68k, fails in the calibration loop. Closes: #391030. + * Run the installation/removal hooks. Closes: #383292, #391036. + + -- Matthias Klose Sun, 29 Oct 2006 11:35:19 +0100 + +python2.5 (2.5-2) unstable; urgency=medium + + * Update to 20061003, taken from the 2.5 release branch. + * On arm and m68k, don't run the pybench in debug mode. + * Fix building the source within exec_prefix (Alexander Wirt). + Closes: #385336. + + -- Matthias Klose Tue, 3 Oct 2006 10:08:36 +0200 + +python2.5 (2.5-1) unstable; urgency=low + + * Python 2.5 release. + * Update to 20060926, taken from the 2.5 release branch. + * Run the Python benchmark during the build, compare the results + of the static and shared builds. + * Fix invalid html in python2.5.devhelp.gz. + * Add a python2.5 console entry to the menu (hidden by default). + * python2.5: Suggest python-profiler. + + -- Matthias Klose Tue, 26 Sep 2006 02:36:11 +0200 + +python2.5 (2.5~c1-1) unstable; urgency=low + + * Python 2.5 release candidate 1. + * Update to trunk 20060818. + + -- Matthias Klose Sat, 19 Aug 2006 19:21:05 +0200 + +python2.5 (2.5~b3-1) unstable; urgency=low + + * Build the _ctypes module for m68k-linux. + + -- Matthias Klose Fri, 11 Aug 2006 18:19:19 +0000 + +python2.5 (2.5~b3-0ubuntu1) edgy; urgency=low + + * Python 2.5 beta3 release. + * Update to trunk 20060811. + * Rebuild the documentation. + * Fix value of sys.exec_prefix in the debug build. + * Do not build the library reference in info format; fails to build. + * Link the interpreter against the shared runtime library. With + gcc-4.1 the difference in the pystones benchmark dropped from about + 12% to about 6%. + * Install the statically linked version of the interpreter as + python2.5-static for now. + * Link the shared libpython with -O1. + + -- Matthias Klose Thu, 10 Aug 2006 14:04:48 +0000 + +python2.5 (2.4.3+2.5b2-3) unstable; urgency=low + + * Disable the testsuite on s390; don't care about "minimally configured" + buildd's. + + -- Matthias Klose Sun, 23 Jul 2006 11:45:03 +0200 + +python2.5 (2.4.3+2.5b2-2) unstable; urgency=low + + * Update to trunk 20060722. + * Merge idle-lib from idle-python2.5 into python2.5. + * Merge lib-tk from python-tk into python2.5. + * Tkinter.py: Suggest installation of python-tk package on failed + import of the _tkinter extension. + * Don't run the testsuite for the debug build on alpha. + * Don't run the test_compiler test on m68k. Just takes too long. + * Disable building ctypes on m68k (requires support for closures). + + -- Matthias Klose Sat, 22 Jul 2006 22:26:42 +0200 + +python2.5 (2.4.3+2.5b2-1) unstable; urgency=low + + * Python 2.5 beta2 release. + * Update to trunk 20060716. + * When built on a buildd, do not run the following test which try to + access the network: test_codecmaps_cn, test_codecmaps_hk, test_codecmaps_jp, + test_codecmaps_kr, test_codecmaps_tw, test_normalization. + * When built on a buildd, do not run tests requiring missing write permissions: + test_ossaudiodev. + + -- Matthias Klose Sun, 16 Jul 2006 02:53:50 +0000 + +python2.5 (2.4.3+2.5b2-0ubuntu1) edgy; urgency=low + + * Python 2.5 beta2 release. + + -- Matthias Klose Thu, 13 Jul 2006 17:16:52 +0000 + +python2.5 (2.4.3+2.5b1-1ubuntu2) edgy; urgency=low + + * Fix python-dev dependencies. + * Update to trunk 20060709. + + -- Matthias Klose Sun, 9 Jul 2006 18:50:32 +0200 + +python2.5 (2.4.3+2.5b1-1ubuntu1) edgy; urgency=low + + * Python 2.5 beta1 release. + * Update to trunk 20060623. + * Merge changes from the python2.4 packages. + * python2.5-minimal: Add _struct. + + -- Matthias Klose Fri, 23 Jun 2006 16:04:46 +0200 + +python2.5 (2.4.3+2.5a1-1) experimental; urgency=low + + * Update to trunk 20060409. + * Run testsuite for debug build as well. + * Build-depend on gcc-4.1. + + -- Matthias Klose Sun, 9 Apr 2006 22:27:05 +0200 + +python2.5 (2.4.3+2.5a1-0ubuntu1) dapper; urgency=low + + * Python 2.5 alpha1 release. + * Drop integrated patches. + * Add build dependencies on libsqlite3-dev and libffi4-dev. + * Add (build-)dependency on mime-support, libgpmg1 (test suite). + * Build using the system FFI. + * python2.5 provides python2.5-ctypes and python2.5-pysqlite2, + python2.5-elementtree. + * Move hashlib.py to python-minimal. + * Lib/hotshot/pstats.py: Error out on missing profile/pstats modules. + + -- Matthias Klose Wed, 5 Apr 2006 14:56:15 +0200 + +python2.4 (2.4.3-8ubuntu1) edgy; urgency=low + + * Resynchronize with Debian unstable. Remaining changes: + - Apply langpack-gettext patch. + - diff.gz contains pregenerated html and info docs. + - Build the -doc package from this source. + + -- Matthias Klose Thu, 22 Jun 2006 18:39:57 +0200 + +python2.4 (2.4.3-8) unstable; urgency=low + + * Remove python2.4's dependency on python-central. On installation of + the runtime, call hooks /usr/share/python/runtime.d/*.rtinstall. + On removal, call hooks /usr/share/python/runtime.d/*.rtremove. + Addresses: #372658. + * Call the rtinstall hooks only, if it's a new installation, or the first + installation using the hooks. Adresses: #373677. + + -- Matthias Klose Sun, 18 Jun 2006 00:56:13 +0200 + +python2.4 (2.4.3-7) unstable; urgency=medium + + * Reupload, depend on python-central (>= 0.4.15). + * Add build-conflict on python-xml. + + -- Matthias Klose Wed, 14 Jun 2006 18:56:57 +0200 + +python2.4 (2.4.3-6) medium; urgency=low + + * idle-python2.4: Remove the old postinst and prerm scripts. + * Name the runtime correctly in python2.4-minimal's installation + scripts. + + -- Matthias Klose Mon, 12 Jun 2006 17:39:56 +0000 + +python2.4 (2.4.3-5) unstable; urgency=low + + * python2.4-prerm: Handle the case, when python-central is not installed. + * idle-python2.4: Depend on python-tk instead of python2.4-tk. + + -- Matthias Klose Fri, 9 Jun 2006 05:17:17 +0200 + +python2.4 (2.4.3-4) unstable; urgency=low + + * SVN update up to 2006-06-07 + * Use python-central. + * Don't build the -tk and -gdbm packages from this source; now built + from the python-stdlib-extensions source. + * Remove leftover build dependency on libgmp3-dev. + * Do not build-depend on libbluetooth1-dev and libgpmg1-dev on + hurd-i386, kfreebsd-i386, kfreebsd-amd64. Closes: #365830. + * Do not run the test_tcl test; hangs for unknown reasons on at least + the following buildds: vivaldi(m68k), goedel (alpha), mayer (mipsel). + And no virtual package to file bug reports for the buildds ... + Closes: #364419. + * Move the Makefile from python2.4-dev to python2.4. Closes: #366473. + * Fix typo in pdb(1). Closes: #365772. + * New autoconf likes the mandir in /usr/share instead of /usr; work + with both locations. Closes: #367618. + + -- Matthias Klose Wed, 7 Jun 2006 21:37:20 +0200 + +python2.4 (2.4.3-3) unstable; urgency=low + + * SVN update up to 2006-04-21 + * Update locale aliases from /usr/share/X11/locale/locale.alias. + * Start idle with option -n from the desktop menu, so that the program + can be started in parallel. + * Testsuite related changes only: + - Add build dependencies mime-support, libgpmg1 (needed by test cases). + - Run the testsuite with bsddb, audio and curses resources enabled. + - Re-run the failed tests in verbose mode. + - Run the test suite for the debug build as well. + - Build depend on netbase, needed by test_socketmodule. + - Build depend on libgpmg1, needed by test_curses. + - On the buildds do not run the tests needing the network resource. + * Update python logo. + * Check for the availability of the profile and pstats modules when + importing hotshot.pstats. Closes: #334067. + * Don't build the -doc package from the python2.4 source. + * Set OPT in the installed Makefile to -O2. + + -- Matthias Klose Fri, 21 Apr 2006 19:58:43 +0200 + +python2.4 (2.4.3-2) unstable; urgency=low + + * Add (build-)dependency on mime-support. + + -- Matthias Klose Tue, 4 Apr 2006 22:21:41 +0200 + +python2.4 (2.4.3-1) unstable; urgency=low + + * Python 2.4.3 release. + + -- Matthias Klose Thu, 30 Mar 2006 23:42:37 +0200 + +python2.4 (2.4.3-0ubuntu1) dapper; urgency=low + + * Python 2.4.3 release. + - Fixed a bug that the gb18030 codec raises RuntimeError on encoding + surrogate pair area on UCS4 build. Ubuntu: #29289. + + -- Matthias Klose Thu, 30 Mar 2006 10:57:32 +0200 + +python2.4 (2.4.2+2.4.3c1-0ubuntu1) dapper; urgency=low + + * SVN update up to 2006-03-25 (2.4.3 candidate 1). + - Regenerate the documentation. + + -- Matthias Klose Mon, 27 Mar 2006 12:03:05 +0000 + +python2.4 (2.4.2-1ubuntu3) dapper; urgency=low + + * SVN update up to 2006-03-04 + - Regenerate the documentation. + - map.mmap(-1, size, ...) can return anonymous memory again on Unix. + Ubuntu #26201. + * Build-depend on libncursesw5-dev, ncursesw5 is preferred for linking. + Provides UTF-8 compliant curses bindings. + * Fix difflib where certain patterns of differences were making difflib + touch the recursion limit. + + -- Matthias Klose Sat, 4 Mar 2006 21:38:24 +0000 + +python2.4 (2.4.2-1ubuntu2) dapper; urgency=low + + * SVN update up to 2006-01-17 + - pwd is now a builtin module, remove it from python-minimal. + - Regenerate the documentation. + * python2.4-tk: Suggest tix instead of tix8.1. + * Move config/Makefile from the -dev package into the runtime package + to be able to use the bdist_wininst distutils command. Closes: #348335. + + -- Matthias Klose Tue, 17 Jan 2006 11:02:24 +0000 + +python2.4 (2.4.2-1ubuntu1) dapper; urgency=low + + * Temporarily remove build dependency on lsb-release. + + -- Matthias Klose Sun, 20 Nov 2005 17:40:18 +0100 + +python2.4 (2.4.2-1build1) dapper; urgency=low + + * Rebuild (openssl-0.9.8). + + -- Matthias Klose Sun, 20 Nov 2005 15:27:24 +0000 + +python2.4 (2.4.2-1) unstable; urgency=low + + * Python 2.4.2 release. + + -- Matthias Klose Thu, 29 Sep 2005 01:49:28 +0200 + +python2.4 (2.4.1+2.4.2rc1-1) unstable; urgency=low + + * Python 2.4.2 release candidate 1. + * Fix "Fatal Python error" from cStringIO's writelines. + Patch by Andrew Bennetts. + + -- Matthias Klose Thu, 22 Sep 2005 10:33:22 +0200 + +python2.4 (2.4.1-5) unstable; urgency=low + + * CVS update up to 2005-09-14 + - Regenerate the html and info docs. + * Add some more locale aliases. + * Fix substitution pf python version in README.python2.4-minimal. + Closes: #327487. + * On m68k, build using -O2 (closes: #326903). + * On Debian, don't configure --with-fpectl, which stopped working with + glibc-2.3.5. + + -- Matthias Klose Wed, 14 Sep 2005 17:32:56 +0200 + +python2.4 (2.4.1-4) unstable; urgency=low + + * CVS update up to 2005-09-04 + - teTeX 3.0 related fixes (closes: #322407). + - Regenerate the html and info docs. + * Add entry for IDLE in the Gnome menus. + * Don't build-depend on libbluetooth-dev on the Hurd (closes: #307037). + * Reenable the cthreads patch for the Hurd (closes: #307052). + + -- Matthias Klose Sun, 4 Sep 2005 18:31:42 +0200 + +python2.4 (2.4.1-3) unstable; urgency=low + + * Synchronise with Ubuntu: + - Build a python2.4-minimal package. + + -- Matthias Klose Tue, 12 Jul 2005 00:23:10 +0000 + +python2.4 (2.4.1-2ubuntu3) breezy; urgency=low + + * CVS update up to 2005-07-07 + * Regenerate the documentation. + + -- Matthias Klose Thu, 7 Jul 2005 09:21:28 +0200 + +python2.4 (2.4.1-2ubuntu2) breezy; urgency=low + + * CVS update up to 2005-06-15 + * Regenerate the documentation. + * Synchronize with Debian. Ubuntu 10485. + * idle-python2.4 enhances python2.4. Ubuntu 11562. + * README.Debian: Fix reference to the doc directory (closes: #311677). + + -- Matthias Klose Wed, 15 Jun 2005 08:56:57 +0200 + +python2.4 (2.4.1-2ubuntu1) breezy; urgency=low + + * Update build dependencies: + db4.2-dev -> db4.3-dev, + libreadline4-dev -> libreadline5-dev. + * python2.4-dev: Add missing templates to generate HTML docs. Ubuntu 11531. + + -- Matthias Klose Sun, 29 May 2005 00:01:05 +0200 + +python2.4 (2.4.1-2) unstable; urgency=low + + * Add the debug symbols for the python2.4, python2.4-gdbm + and python2.4-tk packages to the python2.4-dbg package. + * Add gdbinit example to doc directory. + + -- Matthias Klose Thu, 5 May 2005 11:12:32 +0200 + +python2.4 (2.4.1-1ubuntu2) breezy; urgency=low + + * Add the debug symbols for the python2.4, python2.4-minimal, python2.4-gdbm + and python2.4-tk packages to the python2.4-dbg package. Ubuntu 10261, + * Add gdbinit example to doc directory. + * For os.utime, use utimes(2), correctly working with glibc-2.3.5. + Ubuntu 10294. + + -- Matthias Klose Thu, 5 May 2005 09:06:07 +0200 + +python2.4 (2.4.1-1ubuntu1) breezy; urgency=low + + * Reupload as 2.4.1-1ubuntu1. + + -- Matthias Klose Thu, 14 Apr 2005 10:46:32 +0200 + +python2.4 (2.4.1-1) unstable; urgency=low + + * Python 2.4.1 release. + * Fix noise in python-doc installation/removal. + * New Python section for the info docs. + + -- Matthias Klose Wed, 30 Mar 2005 19:42:03 +0200 + +python2.4 (2.4.1-0) hoary; urgency=low + + * Python 2.4.1 release. + * Fix noise in python-doc installation/removal. + * New Python section for the info docs. + + -- Matthias Klose Wed, 30 Mar 2005 16:35:34 +0200 + +python2.4 (2.4+2.4.1rc2-2) unstable; urgency=low + + * Add the valgrind support file to /etc/python2.4 + * Build the -dbg package with -DPy_USING_MEMORY_DEBUGGER. + * Lib/locale.py: + - correctly parse LANGUAGE as a colon separated list of languages. + - prefer LC_ALL, LC_CTYPE and LANG over LANGUAGE to get the correct + encoding. + - Don't map 'utf8', 'utf-8' to 'utf', which is not a known encoding + for glibc. + * Fix two typos in python(1). Addresses: #300124. + + -- Matthias Klose Sat, 19 Mar 2005 21:50:14 +0100 + +python2.4 (2.4+2.4.1rc2-1) unstable; urgency=low + + * Python 2.4.1 release candidate 2. + * Build-depend on libbluetooth1-dev. + + -- Matthias Klose Sat, 19 Mar 2005 00:57:14 +0100 + +python2.4 (2.4dfsg-2) unstable; urgency=low + + * CVS update up to 2005-03-03 + + -- Matthias Klose Thu, 3 Mar 2005 22:22:16 +0100 + +python2.4 (2.4dfsg-1ubuntu4) hoary; urgency=medium + + * Move exception finalisation later in the shutdown process - this + fixes the crash seen in bug #1165761, taken from CVS. + * codecs.StreamReader: Reset codec when seeking. Ubuntu #6972. + * Apply fix for SF1124295, fixing an obscure bit of Zope's security machinery. + * distutils: Don't add standard library dirs to library_dirs + and runtime_library_dirs. On amd64, runtime paths pointing to /usr/lib64 + aren't recognized by dpkg-shlibdeps, and the packages containing these + libraries aren't added to ${shlibs:Depends}. + * Lib/locale.py: + - correctly parse LANGUAGE as a colon separated list of languages. + - prefer LC_ALL, LC_CTYPE and LANG over LANGUAGE to get the correct + encoding. + - Don't map 'utf8', 'utf-8' to 'utf', which is not a known encoding + for glibc. + * os.py: Avoid using items() in environ.update(). Fixes #1124513. + * Python/pythonrun.c: + * Build depend on locales, generate the locales needed for the + testsuite. + * Add build dependency on libbluetooth1-dev, adding some bluetooth + functionality to the socket module. + * Lib/test/test_sundry.py: Don't fail on import of profile & pstats, + which are separated out to the python-profiler package. + * Fix typos in manpage. + + -- Matthias Klose Tue, 29 Mar 2005 13:35:53 +0200 + + +python2.4 (2.4dfsg-1ubuntu3) hoary; urgency=low + + * debian/patches/langpack-gettext.dpatch: + - langpack support for python-gettext added + + -- Michael Vogt Tue, 1 Mar 2005 13:13:36 +0100 + +python2.4 (2.4dfsg-1ubuntu2) hoary; urgency=low + + * Revert 'essential' status on python2.4-minimal. This status on + on python-minimal is sufficient (Ubuntu #6392). + + -- Matthias Klose Wed, 9 Feb 2005 23:09:42 +0100 + +python2.4 (2.4dfsg-1ubuntu1) hoary; urgency=low + + * Resyncronise with Debian. + * Mark the python2.4-minimal package as 'essential'. + + -- Matthias Klose Wed, 9 Feb 2005 13:31:09 +0100 + +python2.4 (2.4dfsg-1) unstable; urgency=medium + + * Add licenses and acknowledgements for incorporated software in the + debian/copyright file (addresses: #293932). + * Replace md5 implementation with one having a DFSG conforming license. + * Remove the profile.py and pstats.py modules from the source package, + not having a DFSG conforming license. The modules can be found in + the python2.x-profile package in the non-free section. + Addresses: #293932. + * Add missing norwegian locales (Tollef Fog Heen). + * CVS updates of the release24-maint branch upto 2005-02-08 (date of + the Python 2.3.5 release). + + -- Matthias Klose Tue, 8 Feb 2005 19:13:10 +0100 + +python2.4 (2.4-7ubuntu1) hoary; urgency=low + + * Fix the name of the python-dbg man page. + * Resyncronise with Debian. + * Move more modules to -minimal (new code in copy.py requires these): + dis, inspect, opcode, token, tokenize. + + -- Matthias Klose Tue, 8 Feb 2005 19:13:10 +0100 + +python2.4 (2.4-7) unstable; urgency=medium + + * Add licenses and acknowledgements for incorporated software in the + debian/copyright file (addresses: #293932). + * Replace md5 implementation with one having a DFSG conforming license. + * Add missing norwegian locales (Tollef Fog Heen). + * CVS updates of the release24-maint branch upto 2005-02-08 (date of + the Python 2.3.5 release). + + -- Matthias Klose Tue, 8 Feb 2005 19:13:10 +0100 + +python2.4 (2.4-6) unstable; urgency=low + + * Build a python2.4-dbg package using --with-pydebug. Add a debug + directory /lib-dynload/debug to sys.path instead of + /lib-dynload und install the extension modules of the + debug build in this directory. + Change the module load path to load extension modules from other + site-packages/debug directories (for further details see the + README in the python2.4-dbg package). Closes: #5415. + * Apply the pydebug-path patch. The package was already built in -5. + + -- Matthias Klose Fri, 4 Feb 2005 22:15:13 +0100 + +python2.4 (2.4-5) unstable; urgency=high + + * Fix a flaw in SimpleXMLRPCServerthat can affect any XML-RPC servers. + This affects any programs have been written that allow remote + untrusted users to do unrestricted traversal and can allow them to + access or change function internals using the im_* and func_* attributes. + References: CAN-2005-0089. + * CVS updates of the release24-maint branch upto 2005-02-04. + + -- Matthias Klose Fri, 4 Feb 2005 08:12:10 +0100 + +python2.4 (2.4-4) unstable; urgency=medium + + * Update debian/copyright to the 2.4 license text (closes: #290898). + * Remove /usr/bin/smtpd.py (closes: #291049). + + -- Matthias Klose Mon, 17 Jan 2005 23:54:37 +0100 + +python2.4 (2.4-3ubuntu6) hoary; urgency=low + + * Use old-style dpatches instead of dpatch-run. + + -- Tollef Fog Heen Mon, 7 Feb 2005 15:58:05 +0100 + +python2.4 (2.4-3ubuntu5) hoary; urgency=low + + * Actually apply the patch as well (add to list of patches in + debian/rules) + + -- Tollef Fog Heen Sun, 6 Feb 2005 15:12:58 +0100 + +python2.4 (2.4-3ubuntu4) hoary; urgency=low + + * Add nb_NO and nn_NO locales to Lib/locale.py + + -- Tollef Fog Heen Sun, 6 Feb 2005 14:33:05 +0100 + +python2.4 (2.4-3ubuntu3) hoary; urgency=low + + * Fix a flaw in SimpleXMLRPCServerthat can affect any XML-RPC servers. + This affects any programs have been written that allow remote + untrusted users to do unrestricted traversal and can allow them to + access or change function internals using the im_* and func_* attributes. + References: CAN-2005-0089. + + -- Matthias Klose Wed, 2 Feb 2005 09:08:20 +0000 + +python2.4 (2.4-3ubuntu2) hoary; urgency=low + + * Build a python2.4-dbg package using --with-pydebug. Add a debug + directory /lib-dynload/debug to sys.path instead of + /lib-dynload und install the extension modules of the + debug build in this directory. + Change the module load path to load extension modules from other + site-packages/debug directories (for further details see the + README in the python2.4-dbg package). Closes: #5415. + * Update debian/copyright to the 2.4 license text (closes: #290898). + * Add operator and copy to the -minimal package. + + -- Matthias Klose Mon, 17 Jan 2005 23:19:47 +0100 + +python2.4 (2.4-3ubuntu1) hoary; urgency=low + + * Resynchronise with Debian. + * python2.4: Depend on the very same version of python2.4-minimal. + * Docment, that time.strptime currently cannot be used, if the + python-minimal package is installed without the python package. + + -- Matthias Klose Sun, 9 Jan 2005 19:35:48 +0100 + +python2.4 (2.4-3) unstable; urgency=medium + + * Build the fpectl module. + * Updated to CVS release24-maint 20050107. + + -- Matthias Klose Sat, 8 Jan 2005 19:05:21 +0100 + +python2.4 (2.4-2ubuntu5) hoary; urgency=low + + * Updated to CVS release24-maint 20050102. + * python-minimal: + - os.py: Use dict instead of UserDict, remove UserDict from -minimal. + - add pickle, threading, needed for subprocess module. + - optparse.py: conditionally import gettext, if not available, + define _ as the identity function. Patch taken from the trunk. + Avoids import of _locale, locale, gettext, copy, repr, itertools, + collections, token, tokenize. + - Add a build check to make sure that the minimal module list is + closed under dependency. + * Fix lintian warnings. + + -- Matthias Klose Sun, 2 Jan 2005 22:00:14 +0100 + +python2.4 (2.4-2ubuntu4) hoary; urgency=low + + * Add UserDict.py to the -minimal package, since os.py needs it. + + -- Colin Watson Thu, 30 Dec 2004 20:41:28 +0000 + +python2.4 (2.4-2ubuntu3) hoary; urgency=low + + * Add os.py and traceback.py to the -minimal package, get the list + of modules from the README. + + -- Matthias Klose Mon, 27 Dec 2004 08:20:45 +0100 + +python2.4 (2.4-2ubuntu2) hoary; urgency=low + + * Add compileall.py and py_compile.py to the -minimal package, not + just to the README ... + + -- Matthias Klose Sat, 25 Dec 2004 22:24:56 +0100 + +python2.4 (2.4-2ubuntu1) hoary; urgency=low + + * Separate the interpreter and a minimal subset of modules into + a python2.4-minimal package. See the README.Debian.gz in this + package. + * Move site.py to python2.4-minimal as well. + * Add documentation files for devhelp. + + -- Matthias Klose Sun, 19 Dec 2004 22:47:32 +0100 + +python2.4 (2.4-2) unstable; urgency=medium + + * Updated patch for #283108. Thanks to Jim Meyering. + + -- Matthias Klose Fri, 3 Dec 2004 17:00:16 +0100 + +python2.4 (2.4-1) unstable; urgency=low + + * Final 2.4 release. + * Flush stdout/stderr if closed (SF #1074011). + + -- Matthias Klose Wed, 1 Dec 2004 07:54:34 +0100 + +python2.4 (2.3.97-2) unstable; urgency=low + + * Don't run test_tcl, hanging on the buildds. + + -- Matthias Klose Fri, 19 Nov 2004 23:48:42 +0100 + +python2.4 (2.3.97-1) unstable; urgency=low + + * Python 2.4 Release Candidate 1. + + -- Matthias Klose Fri, 19 Nov 2004 21:27:02 +0100 + +python2.4 (2.3.96-1) experimental; urgency=low + + * Updated to CVS release24-maint 20041113. + * Build the docs in info format again. + + -- Matthias Klose Sat, 13 Nov 2004 21:21:10 +0100 + +python2.4 (2.3.95-2) experimental; urgency=low + + * Move distutils package from the python2.4-dev into the python2.4 + package. + + -- Matthias Klose Thu, 11 Nov 2004 22:56:14 +0100 + +python2.4 (2.3.95-1) experimental; urgency=low + + * Python 2.4 beta2 release. + + -- Matthias Klose Thu, 4 Nov 2004 23:43:47 +0100 + +python2.4 (2.3.94-1) experimental; urgency=low + + * Python 2.4 beta1 release. + + -- Matthias Klose Sat, 16 Oct 2004 08:33:57 +0200 + +python2.4 (2.3.93-1) experimental; urgency=low + + * Python 2.4 alpha3 release. + + -- Matthias Klose Fri, 3 Sep 2004 21:53:47 +0200 + +python2.4 (2.3.92-1) experimental; urgency=low + + * Python 2.4 alpha2 release. + + -- Matthias Klose Thu, 5 Aug 2004 23:53:18 +0200 + +python2.4 (2.3.91-1) experimental; urgency=low + + * Python 2.4 alpha1 release. + Highlights: http://www.python.org/2.4/highlights.html + + -- Matthias Klose Fri, 9 Jul 2004 17:38:54 +0200 + +python2.4 (2.3.90-1) experimental; urgency=low + + * Package HEAD branch (pre alpha ..). + + -- Matthias Klose Mon, 14 Jun 2004 23:19:57 +0200 + +python2.3 (2.3.4-1) unstable; urgency=medium + + * Final Python 2.3.4 Release. + * In the API docs, fix signature of PyModule_AddIntConstant (closes: #250826). + * locale.getdefaultlocale: don't fail with empty environment variables. + Closes: #249816. + * Include distutils/command/wininst.exe in -dev package (closes: #249006). + * Disable cthreads on the Hurd (Michael Banck). Closes: #247211. + * Add a note to pygettext(1), that this program is deprecated in favour + of xgettext, which now includes support for Python as well. + Closes: #246332. + + -- Matthias Klose Fri, 28 May 2004 22:59:42 +0200 + +python2.3 (2.3.3.91-1) unstable; urgency=low + + * Python 2.3.4 Release Candidate 1. + * Do not use the default namespace for attributes. Patch taken from the + 2.3 maintenance branch. + The xmllib module is obsolete. Use xml.sax instead. + * http://python.org/sf/945642 - fix nonblocking i/o with ssl socket. + + -- Matthias Klose Thu, 13 May 2004 21:24:52 +0200 + +python2.3 (2.3.3-7) unstable; urgency=low + + * Add a workaround for GNU libc nl_langinfo()'s returning NULL. + Closes: #239237. + Patch taken from 2.3 maintenance branch. + * threading.py: Remove calls to currentThread() in _Condition methods that + were side-effect. Side-effects were deemed unnecessary and were causing + problems at shutdown time when threads were catching exceptions at start + time and then triggering exceptions trying to call currentThread() after + gc'ed. Masked the initial exception which was deemed bad. + Closes: #195812. + * Properly support normalization of empty unicode strings. Closes: #239986. + Patch taken from 2.3 maintenance branch. + * README.maintainers: Add section where to find the documentation tools. + * Fix crash in pyexpat module (closes: #229281). + * For the Hurd, set the interpreters recursion limit to 930. + * Do not try to byte-compile the test files on installation; this + currently breaks the Hurd install. + + -- Matthias Klose Sat, 1 May 2004 07:50:46 +0200 + +python2.3 (2.3.3-6) unstable; urgency=low + + * Don't build the unversioned python{,-*} packages anymore. Now + built from the python-defaults package. + * Update to the proposed python-policy: byte-compile using -E. + * Remove python-elisp's dependency on emacs20 (closes: #232785). + * Don't build python-elisp from the python2.3 source anymore, + get it from python-mode.sf.net as a separate source package. + * python2.3-dev suggests libc-dev (closes: #231091). + * get LDSHARED and CCSHARED (like, CC, CXX, CPP, CFLAGS) from + the environment + * Set CXX in installed config/Makefile (closes: #230273). + + -- Matthias Klose Tue, 24 Feb 2004 07:07:51 +0100 + +python2.3 (2.3.3-5) unstable; urgency=low + + * Build-depend on libdb4.2-dev, instead of libdb4.1-dev. According + to the docs the file format is compatible. + + -- Matthias Klose Mon, 12 Jan 2004 10:37:45 +0100 + +python2.3 (2.3.3-4) unstable; urgency=low + + * Fix broken _bsddb module. setup.py picked up the wrong library. + + -- Matthias Klose Sun, 4 Jan 2004 11:30:00 +0100 + +python2.3 (2.3.3-3) unstable; urgency=low + + * Fix typo in patch (closes: #224797, #226064). + + -- Matthias Klose Sun, 4 Jan 2004 09:23:21 +0100 + +python2.3 (2.3.3-2) unstable; urgency=medium + + * Lib/email/Charset: use locale unaware function to lower case of locale + name (closes: #224797). + * Update python-mode to version from python-mode.sf.net. Fixes highlighting + problems (closes: #223520). + * Backport from mainline: Add IPV6_ socket options from RFCs 3493 and 3542. + + -- Matthias Klose Fri, 2 Jan 2004 14:03:26 +0100 + +python2.3 (2.3.3-1) unstable; urgency=low + + * New upstream release. + * Copy the templates, tools and scripts from the Doc dir in the source + to /usr/share/lib/python2.3/doc in the python2.3-dev package. Needed + for packages building documentation like python does (closes: #207337). + + -- Matthias Klose Fri, 19 Dec 2003 10:57:39 +0100 + +python2.3 (2.3.2.91-1) unstable; urgency=low + + * New upstream version (2.3.3 release candidate). + * Update python-mode.el (closes: #158811, #159630). + Closing unreproducible report (closes: #159628). + + -- Matthias Klose Sat, 6 Dec 2003 14:41:14 +0100 + +python2.3 (2.3.2-7) unstable; urgency=low + + * Put the conflict in the correct direction. python2.3 (2.3.2-6) doesn't + conflict with python (<= 2.3.2-5) but python (2.3.2-6) conflicts with + python2.3 (<= 2.3.2-5) (thanks to Brian May). Really closes #221791. + + -- Matthias Klose Fri, 21 Nov 2003 00:20:02 +0100 + +python2.3 (2.3.2-6) unstable; urgency=low + + * Add conflicts with older python{,2.3} packages to fix overwrite + errors (closes: #221791). + + -- Matthias Klose Thu, 20 Nov 2003 07:24:36 +0100 + +python2.3 (2.3.2-5) unstable; urgency=low + + * Updated to CVS release23-maint 20031119. + * Re-upgrade the dependency of python2.3 on python (>= 2.3) to + a dependency (closes: #221523). + + -- Matthias Klose Wed, 19 Nov 2003 00:30:27 +0100 + +python2.3 (2.3.2-4) unstable; urgency=low + + * Don't build-depend on latex2html (moved to non-free), but keep + the prebuilt docs in debian/patches (closes: #221347). + * Fix typos in the library reference (closes: #220510, #220954). + * Fix typo in python-elisp's autoloading code (closes: #220308). + * Update proposed python policy: private modules can be installed + into /usr/lib/ (arch dependent) and into /usr/share/ + (arch independent). + + -- Matthias Klose Tue, 18 Nov 2003 00:41:39 +0100 + +python2.3 (2.3.2-3) unstable; urgency=low + + * Downgrade the dependency of python2.3 on python (>= 2.3) to + a recommendation. + * Fix path to interpreter in binfmt file. + * Fix segfault in unicodedata module (closes: #218697). + * Adjust python-elisp autoload code (closes: #219821). + + -- Matthias Klose Sun, 9 Nov 2003 19:43:37 +0100 + +python2.3 (2.3.2-2) unstable; urgency=medium + + * Fix broken doc link (closes: #214217). + * Disable wrongly detected large file support for GNU/Hurd. + * Really fix the FTBFS for the binary-indep target (closes: #214303). + + -- Matthias Klose Mon, 6 Oct 2003 07:54:58 +0200 + +python2.3 (2.3.2-1) unstable; urgency=low + + * New upstream version. + * Fix a FTBFS for the binary-indep target. + + -- Matthias Klose Sat, 4 Oct 2003 10:20:15 +0200 + +python2.3 (2.3.1-3) unstable; urgency=low + + * Fix names of codec packages in recommends. + * On alpha compile using -mieee (see #212912). + + -- Matthias Klose Sun, 28 Sep 2003 10:48:12 +0200 + +python2.3 (2.3.1-2) unstable; urgency=low + + * Update python policy draft (closes: #128911, #163785). + * Re-add os.fsync function (closes: #212672). + * Let python2.3-doc conflict with older python2.3 versions (closes: #211882). + * Add recommends for pythonX.Y-japanese-codecs, pythonX.Y-iconvcodec, + pythonX.Y-cjkcodecs, pythonX.Y-korean-codecs (closes: #207161). + * Generate binfmt file (closes: #208005). + * Add IPPROTO_IPV6 option to the socketmodule (closes: #206569). + * Bugs reported against python2.2 and fixed in python2.3: + - Crashes in idle (closes: #186887, #200084). + + -- Matthias Klose Sat, 27 Sep 2003 11:21:47 +0200 + +python2.3 (2.3.1-1) unstable; urgency=low + + * New upstream version (bug fix release). + + -- Matthias Klose Wed, 24 Sep 2003 11:27:43 +0200 + +python2.3 (2.3-4) unstable; urgency=high + + * Disable check for utimes function, which is broken in glibc-2.3.2. + Packages using distutils had '1970/01/01-01:00:01' timestamps in files. + * Bugs fixed by making python2.3 the default python version: + - Canvas.scan_dragto() takes a 3rd optional parmeter "gain". + Closes: #158168. + - New command line parsing module (closes: #38628). + - compileall.py allows compiling single files (closes: #139971). + * Bugs reported for 2.2 and fixed in 2.3: + - Idle does save files with ASCII characters (closes: #179313). + - imaplib support for prefix-quoted strings (closes: #150485). + - posixpath includes getctime (closes: #173827). + - pydoc has support for keywords (closes: #186775). + * Bugs reported for 2.1 and fixed in 2.3: + - Fix handling of "#anchor" URLs in urlparse (closes: #147844). + - Fix readline if C stdin is not a tty, even if sys.stdin is. + Closes: #131810. + * Updated to CVS release23-maint 20030810 (fixing memory leaks in + array and socket modules). + * pydoc's usage output uses the basename of the script. + * Don't explicitely remove /etc/python2.3 on purge (closes: #202864). + * python conflicts with python-xmlbase (closes: #204773). + * Add dependency python (>= 2.3) to python2.3, so make sure the + unversioned names can be used. + + -- Matthias Klose Sun, 10 Aug 2003 09:27:52 +0200 + +python2.3 (2.3-3) unstable; urgency=medium + + * Fix shlibs file. + + -- Matthias Klose Fri, 8 Aug 2003 08:45:12 +0200 + +python2.3 (2.3-2) unstable; urgency=medium + + * Make python2.3 the default python version. + + -- Matthias Klose Tue, 5 Aug 2003 22:13:22 +0200 + +python2.3 (2.3-1) unstable; urgency=low + + * Python 2.3 final release. + + -- Matthias Klose Wed, 30 Jul 2003 08:12:28 +0200 + +python2.3 (2.2.107-1rc2) unstable; urgency=medium + + * Python 2.3 release candidate 2. + * Don't compress .txt files referenced by the html docs (closes: #200298). + * Include the email/_compat* files (closes: #200349). + + -- Matthias Klose Fri, 25 Jul 2003 07:08:09 +0200 + +python2.3 (2.2.106-2beta2) unstable; urgency=medium + + * Python 2.3 beta2 release, updated to CVS 20030704. + - Fixes AssertionError in httplib (closed: #192452). + - Fixes uncaught division by zero in difflib.py (closed: #199287). + * Detect presence of setgroups(2) at configure time (closes: #199839). + * Use default gcc on arm as well. + + -- Matthias Klose Sat, 5 Jul 2003 10:21:33 +0200 + +python2.3 (2.2.105-1beta2) unstable; urgency=low + + * Python 2.3 beta2 release. + - Includes merged idle fork. + - Fixed socket.setdefaulttimeout(). Closes: #189380. + - socket.ssl works with _socketobj. Closes: #196082. + * Do not link libtix to the _tkinter module. It's loaded via + 'package require tix' at runtime. python2.3-tkinter now + suggests tix8.1 instead. + * On arm, use gcc-3.2 to build. + * Add -fno-strict-aliasing rules to OPT to avoid warnings + "dereferencing type-punned pointer will break strict-aliasing rules", + when building with gcc-3.3. + + -- Matthias Klose Mon, 30 Jun 2003 00:19:32 +0200 + +python2.3 (2.2.104-1beta1.1) unstable; urgency=low + + * Non-maintainer upload with maintainer consent. + * debian/control (Build-Depends): s/libgdbmg1-dev/libgdbm-dev/. + + -- James Troup Wed, 4 Jun 2003 02:24:27 +0100 + +python2.3 (2.2.104-1beta1) unstable; urgency=low + + * Python 2.3 beta1 release, updated to CVS 20030514. + - build the current documentation. + * Reenable Tix support. + + -- Matthias Klose Wed, 14 May 2003 07:38:57 +0200 + +python2.3 (2.2.103-1beta1) unstable; urgency=low + + * Python 2.3 beta1 release, updated to CVS 20030506. + - updated due to build problems on mips/mipsel. + - keep the 2.3b1 documentation (doc build problems with cvs). + + -- Matthias Klose Wed, 7 May 2003 06:26:39 +0200 + +python2.3 (2.2.102-1beta1) unstable; urgency=low + + * Python 2.3 beta1 release. + + -- Matthias Klose Sat, 3 May 2003 22:45:16 +0200 + +python2.3 (2.2.101-1exp1) unstable; urgency=medium + + * Python 2.3 alpha2 release, updated to CVS 20030321. + * Tkinter: Catch exceptions thrown for undefined substitutions in + events (needed for tk 8.4.2). + + -- Matthias Klose Fri, 21 Mar 2003 21:32:14 +0100 + +python2.3 (2.2.100-1exp1) unstable; urgency=low + + * Python 2.3 alpha2 release, updated to CVS 20030221. + + -- Matthias Klose Fri, 21 Feb 2003 19:37:17 +0100 + +python2.3 (2.2.99-1exp1) unstable; urgency=low + + * Python 2.3 alpha1 release updated to CVS 20030123. + - should fix the testsuite (and package build) failure on alpha. + * Remove build dependency on libexpat1-dev. Merge the python2.3-xmlbase + package into python2.3 (closes: #177739). + + -- Matthias Klose Thu, 23 Jan 2003 22:48:12 +0100 + +python2.3 (2.2.98-1exp1) unstable; urgency=low + + * Python 2.3 alpha1 release updated to CVS 20030117. + * Build using libdb4.1. + + -- Matthias Klose Sat, 18 Jan 2003 00:14:01 +0100 + +python2.3 (2.2.97-1exp1) unstable; urgency=low + + * Python 2.3 alpha1 release updated to CVS 20030109. + * Build-Depend on g++ (>= 3:3.2). + * Python package maintainers: please wait uploading python dependent + packages until python2.2 and python2.1 are compiled using gcc-3.2. + + -- Matthias Klose Thu, 9 Jan 2003 23:56:42 +0100 + +python2.3 (2.2.96-1exp1) unstable; urgency=low + + * Python 2.3 alpha1 release (not exactly the tarball, but taken from + CVS 20030101). + - Includes support for linking with threaded tk8.4 (closes: #172714). + * Install and register whatsnew document (closes: #173859). + * Properly unregister info documentation. + + -- Matthias Klose Wed, 1 Jan 2003 17:38:54 +0100 + +python2.3 (2.2.95-1exp1) unstable; urgency=low + + * Experimental packages from CVS 021212. + - data in unicodedate module is up to date (closes: #171061). + * Fix idle packaging (closes: #170394). + * Configure using unicode UCS-4 (closes: #171062). + This change breaks compatibility with binary modules, but what do you + expect from experimental packages ... Please recompile dependent packages. + * Don't strip binaries for now. + + -- Matthias Klose Thu, 12 Dec 2002 21:42:27 +0100 + +python2.3 (2.2.94-1exp1) unstable; urgency=low + + * Experimental packages from CVS 021120. + * Remove outdated README.dbm. + * Depend on tk8.4. + * python-elisp: Install emacsen install file with mode 644 (closes: #167718). + + -- Matthias Klose Thu, 21 Nov 2002 01:04:51 +0100 + +python2.3 (2.2.93-1exp1) unstable; urgency=medium + + * Experimental packages from CVS 021015. + * Build a static library libpython2.3-pic.a. + * Enable large file support for the Hurd (closes: #164602). + + -- Matthias Klose Tue, 15 Oct 2002 21:06:27 +0200 + +python2.3 (2.2.92-1exp1) unstable; urgency=low + + * Experimental packages from CVS 020922. + * Fix build error on ia64 (closes: #161234). + * Build depend on gcc-3.2-3.2.1-0pre2 to fix build error on arm. + + -- Matthias Klose Sun, 22 Sep 2002 18:30:28 +0200 + +python2.3 (2.2.91-1exp1) unstable; urgency=low + + * Experimental packages from CVS 020906. + * idle-python2.3: Fix conflict (closes: #159267). + * Fix location of python-mode.el (closes: #159564, #159619). + * Use tix8.1. + * Apply fix for distutils/ccompiler problem (closes: #159288). + + -- Matthias Klose Sat, 7 Sep 2002 09:55:07 +0200 + +python2.3 (2.2.90-1exp1) unstable; urgency=low + + * Experimental packages from CVS 020820. + * Don't build python2.3-elisp, but put the latest version into + python-elisp. + + -- Matthias Klose Thu, 22 Aug 2002 21:52:04 +0200 + +python2.2 (2.2.1-6) unstable; urgency=low + + * CVS updates of the release22-maint branch upto 2002-07-23. + * Enable IPv6 support (closes: #152543). + * Add python2.2-tk suggestion for python2.2 (pydoc -g). + * Fix from SF patch #527518: proxy config with user+pass authentication. + * Point pydoc to the correct location of the docs (closes: #147579). + * Remove '*.py[co]' files, when removing the python package, + not when purging (closes: #147130). + * Update to new py2texi.el version (Milan Zamazal). + + -- Matthias Klose Mon, 29 Jul 2002 23:11:32 +0200 + +python2.2 (2.2.1-5) unstable; urgency=low + + * CVS updates of the release22-maint branch upto 2002-05-03. + * Build the info docs (closes: #145653). + + -- Matthias Klose Fri, 3 May 2002 22:35:46 +0200 + +python2.2 (2.2.1-4) unstable; urgency=high + + * Fix indentation errors introduced in last upload (closes: #143809). + + -- Matthias Klose Sun, 21 Apr 2002 01:00:14 +0200 + +python2.2 (2.2.1-3) unstable; urgency=high + + * Add Build-Conflicts: tcl8.0-dev, tk8.0-dev, tcl8.2-dev, tk8.2-dev. + Closes: #143534 (build a working _tkinter module, on machines, where + 8.0's tk.h gets included). + * CVS updates of the release22-maint branch upto 2002-04-20. + + -- Matthias Klose Sat, 20 Apr 2002 09:22:37 +0200 + +python2.2 (2.2.1-2) unstable; urgency=low + + * Forgot to copy the dlmodule patch from the 2.1.3 package. Really + closes: #141681. + + -- Matthias Klose Sat, 13 Apr 2002 01:28:05 +0200 + +python2.2 (2.2.1-1) unstable; urgency=high + + * Final 2.2.1 release. + * According to report #131813, the python interpreter is much faster on some + architectures, when beeing linked statically with the python library (25%). + Gregor and me tested on i386, m68k and alpha, but we could not reproduce + such a speedup (generally between 5% and 10%). But we are linking the + python executable now statically ... + * Build info docs from the tex source, merge the python-doc-info + package into the python-doc package. + * Always build the dl module. Failure in case of + sizeof(int)!=sizeof(long)!=sizeof(void*) + is delayed until dl.open is called. Closes: #141681. + + -- Matthias Klose Thu, 11 Apr 2002 00:19:19 +0200 + +python2.2 (2.2.0.92-0) unstable; urgency=low + + * Package CVS sources, omit cvs-updates.dpatch (closes: #140977). + + -- Matthias Klose Wed, 3 Apr 2002 08:20:52 +0200 + +python2.2 (2.2-6) unstable; urgency=medium + + * Update to python-2.2.1 release candidate 2 (final release scheduled + for April 10). + * Enable dl module (closes: #138992). + * Build doc files with python binary from package (closes: #139657). + * Build _tkinter module with BLT and Tix support. + * python2.2-elisp: Conflict with python2-elisp (closes: #138970). + * string.split docs updated in python-2.2.1 (closes: #129272). + + -- Matthias Klose Mon, 1 Apr 2002 13:52:36 +0200 + +python2.2 (2.2-5) unstable; urgency=low + + * CVS updates of the release22-maint branch upto 20020310 (aproaching + the first 2.2.1 release candidate). + * Stolen from HEAD: check argument of locale.nl_langinfo (closes: #137371). + + -- Matthias Klose Fri, 15 Mar 2002 01:05:59 +0100 + +python2.2 (2.2-4) unstable; urgency=medium + + * Include test/{__init__.py,README,pystone.py} in package (closes: #129013). + * Fix python-elisp conflict (closes: #129046). + * Don't compress stylesheets (closes: #133179). + * CVS updates of the release22-maint branch upto 20020310. + + -- Matthias Klose Sun, 10 Mar 2002 23:32:28 +0100 + +python2.2 (2.2-3) unstable; urgency=medium + + * Updates from the CVS python22-maint branch up to 20020107. + webbrowser.py: properly escape url's. + * The Hurd does not have large file support: disabled. + + -- Matthias Klose Mon, 7 Jan 2002 21:55:57 +0100 + +python2.2 (2.2-2) unstable; urgency=medium + + * CVS updates of the release22-maint branch upto 20011229. Fixes: + - Include TCP_CORK flag in plat-linux2 headers (fixes: #84340). + - Update CDROM.py module (fixes: #125785). + * Add missing chunk of the GNU/Hurd patch (therefore urgency medium). + * Send anonymous password when using anonftp (closes: #126814). + + -- Matthias Klose Sat, 29 Dec 2001 20:18:26 +0100 + +python2.2 (2.2-1) unstable; urgency=low + + * New upstream version: 2.2. + * Bugs fixed upstream: + - Docs for os.kill reference the signal module for constants. + - Documentation strings in the tutorial end with a period (closes: #94770). + - Tk: grid_location method moved from Grid to Misc (closes: #98338). + - mhlib.SubMessage.getbodytext takes decode parameter (closes: #31876). + - Strings in modules are locale aware (closes: #51444). + - Printable 8-bit characters in strings are correctly printed + (closes: #64354). + - Dictionary can be updated with abstract mapping object (closes: #46566). + * Make site.py a config files. + + -- Matthias Klose Sat, 22 Dec 2001 00:51:46 +0100 + +python2.2 (2.1.99c1-1) unstable; urgency=low + + * New upstream version: 2.2c1 (release candidate). + * Do not provide python2.2-base anymore. + * Install correct README.Debian for python2.2 package. Include hint + where to find Makefile.pre.in. + * Suggest installation of python-ssl. + * Remove idle config files on purge. + * Remove empty /usr/lib/python2.2 directory on purge. + + -- Matthias Klose Sat, 15 Dec 2001 17:56:27 +0100 + +python2.2 (2.1.99beta2-1) unstable; urgency=high + + * debian/rules: Reflect removal of regrtest package (closes: #122278). + Resulted in build failures on all architectures. + * Build -doc package from source. + + -- Matthias Klose Sat, 8 Dec 2001 00:38:41 +0100 + +python2.2 (2.1.99beta2-0.1) unstable; urgency=low + + * Non maintainer upload. + * New upstream version (this is 2.2beta2). + * Do not build the python-regrtest package anymore; keep the test framework + components test/regrtest.py and test/test_support.py in the python + package (closes: #119408). + + -- Gregor Hoffleit Tue, 27 Nov 2001 09:53:26 +0100 + +python2.2 (2.1.99beta1-4) unstable; urgency=low + + * Configure with --with-fpectl (closes: #118125). + * setup.py: Remove broken check for _curses_panel module (#116081). + * idle: Move config-* files to /etc and mark as conffiles (#106390). + * Move idle packages to section `devel'. + + -- Matthias Klose Wed, 31 Oct 2001 10:56:45 +0100 + +python2.2 (2.1.99beta1-3) unstable; urgency=low + + * Fix shlibs file (was still referring to 2.1). Closes: #116810. + * README.Debian: point to draft of python-policy in the python package. + + -- Matthias Klose Wed, 31 Oct 2001 10:56:45 +0100 + +python2.2 (2.1.99beta1-2) unstable; urgency=medium + + * Fix shlibs file (was still referring to 2.1). Closes: #116810. + * Rename package python2.2-base to python2.2. + + -- Matthias Klose Wed, 24 Oct 2001 23:00:50 +0200 + +python2.2 (2.1.99beta1-1) unstable; urgency=low + + * New upstream version (beta). Call the package version 2.1.99beta1-1. + * New maintainer until the final 2.2 release. + * Updated the debian patches. + + -- Matthias Klose Sat, 20 Oct 2001 18:56:26 +0200 + +python2.1 (2.1.1-1.2) unstable; urgency=low + + * Really remove the python alternative. + + -- Matthias Klose Sat, 20 Oct 2001 15:16:56 +0200 + +python2.1 (2.1.1-1.1) unstable; urgency=low + + * README FOR PACKAGE MAINTAINERS: It is planned to remove the python2-XXX + packages from unstable and move on to python2.1. + If you repackage/adapt your modules for python2.1, don't build + python2-XXX and python2.1-XXX packages from the same source package, + so that the python2-XXX package can be removed without influencing the + python2.1-XXX package. + + See the debian-python mailing list at http://lists.debian.org/devel.html + for details and the current discussion and a draft for a debian-python + policy (August to October 2001). + + * Remove alternative for /usr/bin/python. The python-base package now + provides the default python version. + + * Regenerate control file to fix build dependencies (closes: #116190). + * Remove alternative for /usr/bin/{python,pydoc}. + * Provide a libpython2.1.so symlink in /usr/lib/python2.1/config, + so that the shared library is found when -L/usr/lib/python2.1/config + is specified. + * Conflict with old package versions, where /usr/bin/python is a real + program (closes: #115943). + * python2.1-elisp conflicts with python-elisp (closes: #115895). + * We now have 2.1 (closes: #96851, #107849, #110243). + + -- Matthias Klose Fri, 19 Oct 2001 17:34:41 +0200 + +python2.1 (2.1.1-1) unstable; urgency=low + + * Incorporated Matthias' modifications. + + -- Gregor Hoffleit Thu, 11 Oct 2001 00:16:42 +0200 + +python2.1 (2.1.1-0.2) unstable; urgency=low + + * New upstream 2.1.1. + * GPL compatible licence (fixes #84080, #102949, #110643). + * Fixed upstream (closes: #99692, #111340). + * Build in separate build directory. + * Split Debian patches into debian/patches directory. + * Build dependencies: Add libgmp3-dev, libexpat1-dev, tighten + debhelper dependency. + * debian/rules: Updated a "bit". + * python-elisp: Remove custom dependency (closes: #87783), + fix emacs path (closes: #89712), remove emacs19 dependency (#82694). + * Mention distutils in python-dev package description (closes: #108170). + * Update README.Debian (closes: #85430). + * Run versioned python in postinsts (closes: #113349). + * debian/sample.{postinst,prerm}: Change to version independent scripts. + * Use '/usr/bin/env python2.1' as interpreter for all python scripts. + * Add libssl-dev to Build-Conflicts. + * python-elisp: Add support for emacs21 (closes: #98635). + * Do not compress .py files in doc directories. + * Don't link explicitely with libc. + + -- Matthias Klose Wed, 3 Oct 2001 09:53:08 +0200 + +python2.1 (2.1.1-0.1) unstable; urgency=low + + * New upstream version (CVS branch release21-maint, will become 2.1.1): + This CVS branch will be released as 2.1.1 under a GPL compatible + license. + + -- Gregor Hoffleit Wed, 27 Jun 2001 22:47:58 +0200 + +python2 (2.1-0.1) unstable; urgency=low + + * Fixed Makefile.pre.in. + * Fixed the postinst files in order to use 2.1 (instead of 2.0). + * Mention the immanent release of 2.0.1 and 2.1.1, with a GPL + compatible license. + + -- Gregor Hoffleit Sun, 17 Jun 2001 21:05:25 +0200 + +python2 (2.1-0) unstable; urgency=low + + * New upstream version. + * Experimental packages. + + -- Gregor Hoffleit Thu, 10 May 2001 00:20:04 +0200 + +python2 (2.0-7) unstable; urgency=low + + * Rebuilt with recent tcl8.3-dev/tk8.3-dev in order to fix a + dependency problem with python2-tk (closes: #87793, #92962). + * Change postinst to create and update /usr/local/lib/python2.0 and + site-python with permissions and owner as mandated by policy: + 2775 and root:staff (closes: #89047). + * Fix to compileall.py: A superfluous argument made compileall without + options fail (cf. #92990 for python). + * Move the distutils module into python2-dev. It needs Makefile.pre.in + in order to work (closes: #89900). + * Remove build-dependency on libgdbm2-dev (which isn't built anyway). + * Add a build-dependency on libdb2-dev (cf. #90220 for python). + + -- Gregor Hoffleit Sat, 14 Apr 2001 21:07:51 +0200 + +python2 (2.0-6) unstable; urgency=low + + * Remove python-zlib package; merge it into python-base. + * Mark that README.python2 is not yet updated. + + -- Gregor Hoffleit Wed, 21 Feb 2001 12:34:18 +0100 + +python2 (2.0-5) unstable; urgency=low + + * Recompile with tcl/tk8.3 (closes: #82088). + * Modifications to README.why-python2 (closes: #82116). + * Add menu hint to idle2 menu entry. + * idle2 is renamed idle-python2 and now build correctly (closes: #82218). + * Add build-dependency on autoconf (closes: #85339). + * Build bsddbmodule as shared module (Modules/Setup.config.in), + and link libpython2.so with -lm in Makefile (closes: #86027). + * various cleanups in debian/rules, e.g. removing dh_suidregister. + * Make pdb available as /usr/bin/pdb-python2 in python2-dev + (cf. #79870 in python-base). + * Remove libgmp3 from build-dependencies, since we currently can't + build the mpzmodule for Python2 due to license problems. + + -- Gregor Hoffleit Sun, 18 Feb 2001 00:12:17 +0100 + +python2 (2.0-4) unstable; urgency=low + + * control: make python2-elisp conflict with python-elisp (it doesn't + make sense to have both of them installed, does it ?) + * include build-depend on libxmltok1-dev. + * again, build with tcl/tk8.0. + + -- Gregor Hoffleit Wed, 10 Jan 2001 23:37:01 +0100 + +python2 (2.0-3) unstable; urgency=low + + * Modules/Setup.in: Added a missing \ that made _tkinter be built + incorrectly. + * rules: on the fly, change all '#!' python scripts to use python2. + + -- Gregor Hoffleit Wed, 13 Dec 2000 20:07:24 +0100 + +python2 (2.0-2) unstable; urgency=low + + * Aaargh. Remove conflicts/provides/replaces on python-base to make + parallel installation of python-base and python2-base possible. + * Install examples into /usr/share/doc/python2 (not python) and fix + symlink to python2.0 (thanks to Rick Younie for + pointing out this). + * Rename man page to python2.1. + + -- Gregor Hoffleit Wed, 13 Dec 2000 09:31:05 +0100 + +python2 (2.0-1) unstable; urgency=low + + * New upstream version. Initial release for python2. + + -- Gregor Hoffleit Mon, 11 Dec 2000 22:39:46 +0100 --- python2.7-2.7.orig/debian/PVER-minimal.postrm.in +++ python2.7-2.7/debian/PVER-minimal.postrm.in @@ -0,0 +1,27 @@ +#! /bin/sh -e + +if [ "$1" = "remove" ]; then + + (find /usr/lib/@PVER@ -name '*.py[co]' | xargs rm -f {}) 2>/dev/null || true + + for d in `find /usr/lib/@PVER@ -depth -type d -empty 2> /dev/null`; do \ + while rmdir $d 2> /dev/null; do d=`dirname $d`; done; \ + done + + if [ -f /var/lib/python/@PVER@_installed ]; then + rm -f /var/lib/python/@PVER@_installed + rmdir --ignore-fail-on-non-empty /var/lib/python 2>/dev/null + fi +fi + +if [ "$1" = "purge" ]; then + for d in `find /usr/lib/@PVER@ -depth -type d -empty 2> /dev/null`; do \ + while rmdir $d 2> /dev/null; do d=`dirname $d`; done; \ + done + rm -f /etc/@PVER@/site.py /etc/@PVER@/sitecustomize.py + rmdir --ignore-fail-on-non-empty /etc/@PVER@ 2>/dev/null +fi + +#DEBHELPER# + +exit 0 --- python2.7-2.7.orig/debian/libPVER.overrides.in +++ python2.7-2.7/debian/libPVER.overrides.in @@ -0,0 +1 @@ +lib@PVER@ binary: package-name-doesnt-match-sonames --- python2.7-2.7.orig/debian/PVER-minimal.prerm.in +++ python2.7-2.7/debian/PVER-minimal.prerm.in @@ -0,0 +1,44 @@ +#! /bin/sh -e + +syssite=/usr/lib/@PVER@/site-packages +localsite=/usr/local/lib/@PVER@/dist-packages + +case "$1" in + remove) + if [ "$DEBIAN_FRONTEND" != noninteractive ]; then + echo "Unlinking and removing bytecode for runtime @PVER@" + fi + for hook in /usr/share/python/runtime.d/*.rtremove; do + [ -x $hook ] || continue + $hook rtremove @PVER@ || continue + done + dpkg -L @PVER@-minimal \ + | awk '/\.py$/ {print $0"c\n" $0"o"}' \ + | xargs rm -f >&2 + + if which update-binfmts >/dev/null; then + update-binfmts --package @PVER@ --remove @PVER@ /usr/bin/@PVER@ + fi + + if [ -h $syssite ]; then + rm -f $syssite + fi + [ -d $localsite ] && rmdir $localsite 2>/dev/null || true + [ -d $(dirname $localsite) ] && rmdir $(dirname $localsite) 2>/dev/null || true + ;; + upgrade) + dpkg -L @PVER@-minimal \ + | awk '/\.py$/ {print $0"c\n" $0"o"}' \ + | xargs rm -f >&2 + ;; + deconfigure) + ;; + failed-upgrade) + ;; + *) + echo "prerm called with unknown argument \`$1'" >&2 + exit 1 + ;; +esac + +#DEBHELPER# --- python2.7-2.7.orig/debian/PVER.prerm.in +++ python2.7-2.7/debian/PVER.prerm.in @@ -0,0 +1,27 @@ +#! /bin/sh -e +# +# prerm script for the Debian @PVER@-base package. +# Written 1998 by Gregor Hoffleit . +# + +case "$1" in + remove|upgrade) + dpkg -L @PVER@ \ + | awk '/\.py$/ {print $0"c\n" $0"o"}' \ + | xargs rm -f >&2 + ;; + deconfigure) + ;; + failed-upgrade) + ;; + *) + echo "prerm called with unknown argument \`$1'" >&2 + exit 1 + ;; +esac + +rmdir /usr/local/lib/python@VER@/site-packages 2>/dev/null && \ + rmdir /usr/local/lib/python@VER@ 2>/dev/null || \ + true + +#DEBHELPER# --- python2.7-2.7.orig/debian/PVER-doc.doc-base.PVER-ref.in +++ python2.7-2.7/debian/PVER-doc.doc-base.PVER-ref.in @@ -0,0 +1,18 @@ +Document: @PVER@-ref +Title: Python Reference Manual (v@VER@) +Author: Guido van Rossum +Abstract: This reference manual describes the syntax and "core semantics" of + the language. It is terse, but attempts to be exact and complete. + The semantics of non-essential built-in object types and of the + built-in functions and modules are described in the *Python + Library Reference*. For an informal introduction to the language, + see the *Python Tutorial*. For C or C++ programmers, two + additional manuals exist: *Extending and Embedding the Python + Interpreter* describes the high-level picture of how to write a + Python extension module, and the *Python/C API Reference Manual* + describes the interfaces available to C/C++ programmers in detail. +Section: Programming/Python + +Format: HTML +Index: /usr/share/doc/@PVER@/html/reference/index.html +Files: /usr/share/doc/@PVER@/html/reference/*.html --- python2.7-2.7.orig/debian/PVER-minimal.README.Debian.in +++ python2.7-2.7/debian/PVER-minimal.README.Debian.in @@ -0,0 +1,145 @@ +Contents of the @PVER@-minimal package +----------------------------------------- + +@PVER@-minimal consists of a minimum set of modules which may be needed +for python scripts used during the boot process. If other packages +are needed in these scripts, don't work around the missing module, but +file a bug report against this package. The modules in this package +are: + + __builtin__ builtin + __future__ module + _abcoll module + _bisect extension + _bytesio extension + _codecs builtin + _collections extension + _fileio extension + _functools extension + _hashlib extension + _heapq extension + _locale extension + _random extension + _socket extension + _sre builtin + _ssl extension + _struct extension + _symtable builtin + _types builtin + _warnings builtin + _weakref extension + _weakrefset module + abc module + atexit module + ConfigParser module + StringIO module + UserDict module + cPickle extension + cStringIO extension + array extension + base64 module + binascii extension + bisect module + cmath extension + codecs module + collections module + compileall module + copy module + copy_reg module + dis module + errno builtin + exceptions builtin + fcntl extension + fnmatch module + functools module + gc builtin + genericpath module + getopt module + glob module + grp extension + hashlib module + heapq module + imp builtin + inspect module + itertools extension + keyword module + linecache module + logging package + marshal builtin + math extension + md5 module + opcode module + operator extension + optparse module + os module + pickle module + platform module + popen2 module + posix builtin + posixpath module + pkgutil module + pwd builtin + py_compile module + random module + re module + repr module + runpy module + select extension + sha module + shutil module + signal builtin + socket module + spwd extension + sre module + sre_compile module + sre_constants module + sre_parse module + ssl module + stat module + string module + strop extension + struct module + subprocess module + sys builtin + syslog extension + sysconfig module + tempfile module + textwrap module + time extension + token module + thread builtin + token module + tokenize module + traceback module + types module + unicodedata extension + weakref module + warnings module + zipimport extension + zlib extension + +Included are as well the codecs and stringprep modules, and the encodings +modules for all encodings except the multibyte encodings and the bz2 codec. + +The following modules are excluded, their import is guarded from the +importing module: + + Used in Excluded + ------------ ------------------------------------ + os nt ntpath os2 os2emxpath mac macpath + riscos riscospath riscosenviron + optparse gettext + pickle doctest + subprocess threading + +This list was derived by looking at the modules in the perl-base package, +then adding python specific "core modules". + +TODO's +------ + +- time.strptime cannot be used. The required _strptime module is not + included in the -minimal package yet. _strptime, locale, _locale and + calendar have to be added. + +- modules used very often in the testsuite: copy, cPickle, operator. --- python2.7-2.7.orig/debian/PVER-dbg.overrides.in +++ python2.7-2.7/debian/PVER-dbg.overrides.in @@ -0,0 +1,2 @@ +@PVER@-dbg binary: package-name-doesnt-match-sonames +@PVER@-dbg binary: non-dev-pkg-with-shlib-symlink --- python2.7-2.7.orig/debian/sitecustomize.py.in +++ python2.7-2.7/debian/sitecustomize.py.in @@ -0,0 +1,7 @@ +# install the apport exception handler if available +try: + import apport_python_hook +except ImportError: + pass +else: + apport_python_hook.install() --- python2.7-2.7.orig/debian/idle-PVER.prerm.in +++ python2.7-2.7/debian/idle-PVER.prerm.in @@ -0,0 +1,15 @@ +#! /bin/sh -e +# +# sample prerm script for the Debian idle-@PVER@ package. +# Written 1998 by Gregor Hoffleit . +# + +PACKAGE=`basename $0 .prerm` + +dpkg --listfiles $PACKAGE | + awk '$0~/\.py$/ {print $0"c\n" $0"o"}' | + xargs rm -f >&2 + +#DEBHELPER# + +exit 0 --- python2.7-2.7.orig/debian/README.idle-PVER.in +++ python2.7-2.7/debian/README.idle-PVER.in @@ -0,0 +1,14 @@ + + The Python IDLE package for Debian + ---------------------------------- + +This package contains Python @VER@'s Integrated DeveLopment Environment, IDLE. + +IDLE is included in the Python @VER@ upstream distribution (Tools/idle) and +depends on Tkinter (available as @PVER@-tk package). + +I have written a simple man page. + + + 06/16/1999 + Gregor Hoffleit --- python2.7-2.7.orig/debian/idle-PVER.1.in +++ python2.7-2.7/debian/idle-PVER.1.in @@ -0,0 +1,104 @@ +.TH IDLE 1 "21 September 2004" +.SH NAME +\fBIDLE\fP \- An Integrated DeveLopment Environment for Python +.SH SYNTAX +.B idle [ \fI-dins\fP ] [ \fI-t title\fP ] [ \fIfile\fP ...] +.PP +.B idle [ \fI-dins\fP ] [ \fI-t title\fP ] ( \fI-c cmd\fP | \fI-r file\fP ) [ \fIarg\fP ...] +.PP +.B idle [ \fI-dins\fP ] [ \fI-t title\fP ] - [ \fIarg\fP ...] +.SH DESCRIPTION +This manual page documents briefly the +.BR idle +command. +This manual page was written for Debian +because the original program does not have a manual page. +For more information, refer to IDLE's help menu. +.PP +.B IDLE +is an Integrated DeveLopment Environment for Python. IDLE is based on +Tkinter, Python's bindings to the Tk widget set. Features are 100% pure +Python, multi-windows with multiple undo and Python colorizing, a Python +shell window subclass, a debugger. IDLE is cross-platform, i.e. it works +on all platforms where Tk is installed. +.LP +.SH OPTIONS +.TP +.B \-h +.PD +Print this help message and exit. +.TP +.B \-n +.PD +Run IDLE without a subprocess (see Help/IDLE Help for details). +.PP +The following options will override the IDLE 'settings' configuration: +.TP +.B \-e +.PD +Open an edit window. +.TP +.B \-i +.PD +Open a shell window. +.PP +The following options imply -i and will open a shell: +.TP +.B \-c cmd +.PD +Run the command in a shell, or +.TP +.B \-r file +.PD +Run script from file. +.PP +.TP +.B \-d +.PD +Enable the debugger. +.TP +.B \-s +.PD +Run $IDLESTARTUP or $PYTHONSTARTUP before anything else. +.TP +.B \-t title +.PD +Set title of shell window. +.PP +A default edit window will be bypassed when -c, -r, or - are used. +.PP +[arg]* and [file]* are passed to the command (-c) or script (-r) in sys.argv[1:]. +.SH EXAMPLES +.TP +idle +.PD +Open an edit window or shell depending on IDLE's configuration. +.TP +idle foo.py foobar.py +.PD +Edit the files, also open a shell if configured to start with shell. +.TP +idle -est "Baz" foo.py +.PD +Run $IDLESTARTUP or $PYTHONSTARTUP, edit foo.py, and open a shell +window with the title "Baz". +.TP +idle -c "import sys; print sys.argv" "foo" +.PD +Open a shell window and run the command, passing "-c" in sys.argv[0] +and "foo" in sys.argv[1]. +.TP +idle -d -s -r foo.py "Hello World" +.PD +Open a shell window, run a startup script, enable the debugger, and +run foo.py, passing "foo.py" in sys.argv[0] and "Hello World" in +sys.argv[1]. +.TP +echo "import sys; print sys.argv" | idle - "foobar" +.PD +Open a shell window, run the script piped in, passing '' in sys.argv[0] +and "foobar" in sys.argv[1]. +.SH SEE ALSO +python(1). +.SH AUTHORS +Various. --- python2.7-2.7.orig/debian/PVER-doc.doc-base.PVER-api.in +++ python2.7-2.7/debian/PVER-doc.doc-base.PVER-api.in @@ -0,0 +1,13 @@ +Document: @PVER@-api +Title: Python/C API Reference Manual (v@VER@) +Author: Guido van Rossum +Abstract: This manual documents the API used by C (or C++) programmers who + want to write extension modules or embed Python. It is a + companion to *Extending and Embedding the Python Interpreter*, + which describes the general principles of extension writing but + does not document the API functions in detail. +Section: Programming/Python + +Format: HTML +Index: /usr/share/doc/@PVER@/html/c-api/index.html +Files: /usr/share/doc/@PVER@/html/c-api/*.html --- python2.7-2.7.orig/debian/copyright +++ python2.7-2.7/debian/copyright @@ -0,0 +1,705 @@ +This package was put together by Klee Dienes from +sources from ftp.python.org:/pub/python, based on the Debianization by +the previous maintainers Bernd S. Brentrup and +Bruce Perens. Current maintainer is Matthias Klose . + +It was downloaded from http://python.org/ + +Copyright: + +Upstream Author: Guido van Rossum and others. + +License: + +The following text includes the Python license and licenses and +acknowledgements for incorporated software. The licenses can be read +in the HTML and texinfo versions of the documentation as well, after +installing the pythonx.y-doc package. Licenses for files not licensed +under the Python Licenses are found at the end of this file. + + +Python License +============== + +A. HISTORY OF THE SOFTWARE +========================== + +Python was created in the early 1990s by Guido van Rossum at Stichting +Mathematisch Centrum (CWI, see http://www.cwi.nl) in the Netherlands +as a successor of a language called ABC. Guido remains Python's +principal author, although it includes many contributions from others. + +In 1995, Guido continued his work on Python at the Corporation for +National Research Initiatives (CNRI, see http://www.cnri.reston.va.us) +in Reston, Virginia where he released several versions of the +software. + +In May 2000, Guido and the Python core development team moved to +BeOpen.com to form the BeOpen PythonLabs team. In October of the same +year, the PythonLabs team moved to Digital Creations (now Zope +Corporation, see http://www.zope.com). In 2001, the Python Software +Foundation (PSF, see http://www.python.org/psf/) was formed, a +non-profit organization created specifically to own Python-related +Intellectual Property. Zope Corporation is a sponsoring member of +the PSF. + +All Python releases are Open Source (see http://www.opensource.org for +the Open Source Definition). Historically, most, but not all, Python +releases have also been GPL-compatible; the table below summarizes +the various releases. + + Release Derived Year Owner GPL- + from compatible? (1) + + 0.9.0 thru 1.2 1991-1995 CWI yes + 1.3 thru 1.5.2 1.2 1995-1999 CNRI yes + 1.6 1.5.2 2000 CNRI no + 2.0 1.6 2000 BeOpen.com no + 1.6.1 1.6 2001 CNRI yes (2) + 2.1 2.0+1.6.1 2001 PSF no + 2.0.1 2.0+1.6.1 2001 PSF yes + 2.1.1 2.1+2.0.1 2001 PSF yes + 2.2 2.1.1 2001 PSF yes + 2.1.2 2.1.1 2002 PSF yes + 2.1.3 2.1.2 2002 PSF yes + 2.2.1 2.2 2002 PSF yes + 2.2.2 2.2.1 2002 PSF yes + 2.2.3 2.2.2 2003 PSF yes + 2.3 2.2.2 2002-2003 PSF yes + 2.3.1 2.3 2002-2003 PSF yes + 2.3.2 2.3.1 2002-2003 PSF yes + 2.3.3 2.3.2 2002-2003 PSF yes + 2.3.4 2.3.3 2004 PSF yes + 2.3.5 2.3.4 2005 PSF yes + 2.4 2.3 2004 PSF yes + 2.4.1 2.4 2005 PSF yes + 2.4.2 2.4.1 2005 PSF yes + 2.4.3 2.4.2 2006 PSF yes + 2.5 2.4 2006 PSF yes + 2.5.1 2.5 2007 PSF yes + +Footnotes: + +(1) GPL-compatible doesn't mean that we're distributing Python under + the GPL. All Python licenses, unlike the GPL, let you distribute + a modified version without making your changes open source. The + GPL-compatible licenses make it possible to combine Python with + other software that is released under the GPL; the others don't. + +(2) According to Richard Stallman, 1.6.1 is not GPL-compatible, + because its license has a choice of law clause. According to + CNRI, however, Stallman's lawyer has told CNRI's lawyer that 1.6.1 + is "not incompatible" with the GPL. + +Thanks to the many outside volunteers who have worked under Guido's +direction to make these releases possible. + + +B. TERMS AND CONDITIONS FOR ACCESSING OR OTHERWISE USING PYTHON +=============================================================== + +PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2 +-------------------------------------------- + +1. This LICENSE AGREEMENT is between the Python Software Foundation +("PSF"), and the Individual or Organization ("Licensee") accessing and +otherwise using this software ("Python") in source or binary form and +its associated documentation. + +2. Subject to the terms and conditions of this License Agreement, PSF +hereby grants Licensee a nonexclusive, royalty-free, world-wide +license to reproduce, analyze, test, perform and/or display publicly, +prepare derivative works, distribute, and otherwise use Python +alone or in any derivative version, provided, however, that PSF's +License Agreement and PSF's notice of copyright, i.e., "Copyright (c) +2001, 2002, 2003, 2004, 2005, 2006, 2007 Python Software Foundation; +All Rights Reserved" are retained in Python alone or in any derivative +version prepared by Licensee. + +3. In the event Licensee prepares a derivative work that is based on +or incorporates Python or any part thereof, and wants to make +the derivative work available to others as provided herein, then +Licensee hereby agrees to include in any such work a brief summary of +the changes made to Python. + +4. PSF is making Python available to Licensee on an "AS IS" +basis. PSF MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR +IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, PSF MAKES NO AND +DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS +FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON WILL NOT +INFRINGE ANY THIRD PARTY RIGHTS. + +5. PSF SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON +FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS +A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON, +OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF. + +6. This License Agreement will automatically terminate upon a material +breach of its terms and conditions. + +7. Nothing in this License Agreement shall be deemed to create any +relationship of agency, partnership, or joint venture between PSF and +Licensee. This License Agreement does not grant permission to use PSF +trademarks or trade name in a trademark sense to endorse or promote +products or services of Licensee, or any third party. + +8. By copying, installing or otherwise using Python, Licensee +agrees to be bound by the terms and conditions of this License +Agreement. + + +BEOPEN.COM LICENSE AGREEMENT FOR PYTHON 2.0 +------------------------------------------- + +BEOPEN PYTHON OPEN SOURCE LICENSE AGREEMENT VERSION 1 + +1. This LICENSE AGREEMENT is between BeOpen.com ("BeOpen"), having an +office at 160 Saratoga Avenue, Santa Clara, CA 95051, and the +Individual or Organization ("Licensee") accessing and otherwise using +this software in source or binary form and its associated +documentation ("the Software"). + +2. Subject to the terms and conditions of this BeOpen Python License +Agreement, BeOpen hereby grants Licensee a non-exclusive, +royalty-free, world-wide license to reproduce, analyze, test, perform +and/or display publicly, prepare derivative works, distribute, and +otherwise use the Software alone or in any derivative version, +provided, however, that the BeOpen Python License is retained in the +Software, alone or in any derivative version prepared by Licensee. + +3. BeOpen is making the Software available to Licensee on an "AS IS" +basis. BEOPEN MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR +IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, BEOPEN MAKES NO AND +DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS +FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF THE SOFTWARE WILL NOT +INFRINGE ANY THIRD PARTY RIGHTS. + +4. BEOPEN SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF THE +SOFTWARE FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS +AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THE SOFTWARE, OR ANY +DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF. + +5. This License Agreement will automatically terminate upon a material +breach of its terms and conditions. + +6. This License Agreement shall be governed by and interpreted in all +respects by the law of the State of California, excluding conflict of +law provisions. Nothing in this License Agreement shall be deemed to +create any relationship of agency, partnership, or joint venture +between BeOpen and Licensee. This License Agreement does not grant +permission to use BeOpen trademarks or trade names in a trademark +sense to endorse or promote products or services of Licensee, or any +third party. As an exception, the "BeOpen Python" logos available at +http://www.pythonlabs.com/logos.html may be used according to the +permissions granted on that web page. + +7. By copying, installing or otherwise using the software, Licensee +agrees to be bound by the terms and conditions of this License +Agreement. + + +CNRI LICENSE AGREEMENT FOR PYTHON 1.6.1 +--------------------------------------- + +1. This LICENSE AGREEMENT is between the Corporation for National +Research Initiatives, having an office at 1895 Preston White Drive, +Reston, VA 20191 ("CNRI"), and the Individual or Organization +("Licensee") accessing and otherwise using Python 1.6.1 software in +source or binary form and its associated documentation. + +2. Subject to the terms and conditions of this License Agreement, CNRI +hereby grants Licensee a nonexclusive, royalty-free, world-wide +license to reproduce, analyze, test, perform and/or display publicly, +prepare derivative works, distribute, and otherwise use Python 1.6.1 +alone or in any derivative version, provided, however, that CNRI's +License Agreement and CNRI's notice of copyright, i.e., "Copyright (c) +1995-2001 Corporation for National Research Initiatives; All Rights +Reserved" are retained in Python 1.6.1 alone or in any derivative +version prepared by Licensee. Alternately, in lieu of CNRI's License +Agreement, Licensee may substitute the following text (omitting the +quotes): "Python 1.6.1 is made available subject to the terms and +conditions in CNRI's License Agreement. This Agreement together with +Python 1.6.1 may be located on the Internet using the following +unique, persistent identifier (known as a handle): 1895.22/1013. This +Agreement may also be obtained from a proxy server on the Internet +using the following URL: http://hdl.handle.net/1895.22/1013". + +3. In the event Licensee prepares a derivative work that is based on +or incorporates Python 1.6.1 or any part thereof, and wants to make +the derivative work available to others as provided herein, then +Licensee hereby agrees to include in any such work a brief summary of +the changes made to Python 1.6.1. + +4. CNRI is making Python 1.6.1 available to Licensee on an "AS IS" +basis. CNRI MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR +IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, CNRI MAKES NO AND +DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS +FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON 1.6.1 WILL NOT +INFRINGE ANY THIRD PARTY RIGHTS. + +5. CNRI SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON +1.6.1 FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS +A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON 1.6.1, +OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF. + +6. This License Agreement will automatically terminate upon a material +breach of its terms and conditions. + +7. This License Agreement shall be governed by the federal +intellectual property law of the United States, including without +limitation the federal copyright law, and, to the extent such +U.S. federal law does not apply, by the law of the Commonwealth of +Virginia, excluding Virginia's conflict of law provisions. +Notwithstanding the foregoing, with regard to derivative works based +on Python 1.6.1 that incorporate non-separable material that was +previously distributed under the GNU General Public License (GPL), the +law of the Commonwealth of Virginia shall govern this License +Agreement only as to issues arising under or with respect to +Paragraphs 4, 5, and 7 of this License Agreement. Nothing in this +License Agreement shall be deemed to create any relationship of +agency, partnership, or joint venture between CNRI and Licensee. This +License Agreement does not grant permission to use CNRI trademarks or +trade name in a trademark sense to endorse or promote products or +services of Licensee, or any third party. + +8. By clicking on the "ACCEPT" button where indicated, or by copying, +installing or otherwise using Python 1.6.1, Licensee agrees to be +bound by the terms and conditions of this License Agreement. + + ACCEPT + + +CWI LICENSE AGREEMENT FOR PYTHON 0.9.0 THROUGH 1.2 +-------------------------------------------------- + +Copyright (c) 1991 - 1995, Stichting Mathematisch Centrum Amsterdam, +The Netherlands. All rights reserved. + +Permission to use, copy, modify, and distribute this software and its +documentation for any purpose and without fee is hereby granted, +provided that the above copyright notice appear in all copies and that +both that copyright notice and this permission notice appear in +supporting documentation, and that the name of Stichting Mathematisch +Centrum or CWI not be used in advertising or publicity pertaining to +distribution of the software without specific, written prior +permission. + +STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO +THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND +FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE +FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT +OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + + +Licenses and Acknowledgements for Incorporated Software +======================================================= + +Mersenne Twister +---------------- + +The `_random' module includes code based on a download from +`http://www.math.keio.ac.jp/~matumoto/MT2002/emt19937ar.html'. The +following are the verbatim comments from the original code: + + A C-program for MT19937, with initialization improved 2002/1/26. + Coded by Takuji Nishimura and Makoto Matsumoto. + + Before using, initialize the state by using init_genrand(seed) + or init_by_array(init_key, key_length). + + Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura, + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + 3. The names of its contributors may not be used to endorse or promote + products derived from this software without specific prior written + permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + Any feedback is very welcome. + http://www.math.keio.ac.jp/matumoto/emt.html + email: matumoto@math.keio.ac.jp + + +Sockets +------- + +The `socket' module uses the functions, `getaddrinfo', and +`getnameinfo', which are coded in separate source files from the WIDE +Project, `http://www.wide.ad.jp/about/index.html'. + + Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the project nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND + GAI_ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE + FOR GAI_ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON GAI_ANY THEORY OF LIABILITY, WHETHER + IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN GAI_ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + OF THE POSSIBILITY OF SUCH DAMAGE. + + +Floating point exception control +-------------------------------- + +The source for the `fpectl' module includes the following notice: + + --------------------------------------------------------------------- + / Copyright (c) 1996. \ + | The Regents of the University of California. | + | All rights reserved. | + | | + | Permission to use, copy, modify, and distribute this software for | + | any purpose without fee is hereby granted, provided that this en- | + | tire notice is included in all copies of any software which is or | + | includes a copy or modification of this software and in all | + | copies of the supporting documentation for such software. | + | | + | This work was produced at the University of California, Lawrence | + | Livermore National Laboratory under contract no. W-7405-ENG-48 | + | between the U.S. Department of Energy and The Regents of the | + | University of California for the operation of UC LLNL. | + | | + | DISCLAIMER | + | | + | This software was prepared as an account of work sponsored by an | + | agency of the United States Government. Neither the United States | + | Government nor the University of California nor any of their em- | + | ployees, makes any warranty, express or implied, or assumes any | + | liability or responsibility for the accuracy, completeness, or | + | usefulness of any information, apparatus, product, or process | + | disclosed, or represents that its use would not infringe | + | privately-owned rights. Reference herein to any specific commer- | + | cial products, process, or service by trade name, trademark, | + | manufacturer, or otherwise, does not necessarily constitute or | + | imply its endorsement, recommendation, or favoring by the United | + | States Government or the University of California. The views and | + | opinions of authors expressed herein do not necessarily state or | + | reflect those of the United States Government or the University | + | of California, and shall not be used for advertising or product | + \ endorsement purposes. / + --------------------------------------------------------------------- + + +Cookie management +----------------- + +The `Cookie' module contains the following notice: + + Copyright 2000 by Timothy O'Malley + + All Rights Reserved + + Permission to use, copy, modify, and distribute this software + and its documentation for any purpose and without fee is hereby + granted, provided that the above copyright notice appear in all + copies and that both that copyright notice and this permission + notice appear in supporting documentation, and that the name of + Timothy O'Malley not be used in advertising or publicity + pertaining to distribution of the software without specific, written + prior permission. + + Timothy O'Malley DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS + SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS, IN NO EVENT SHALL Timothy O'Malley BE LIABLE FOR + ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + PERFORMANCE OF THIS SOFTWARE. + + +Execution tracing +----------------- + +The `trace' module contains the following notice: + + portions copyright 2001, Autonomous Zones Industries, Inc., all rights... + err... reserved and offered to the public under the terms of the + Python 2.2 license. + Author: Zooko O'Whielacronx + http://zooko.com/ + mailto:zooko@zooko.com + + Copyright 2000, Mojam Media, Inc., all rights reserved. + Author: Skip Montanaro + + Copyright 1999, Bioreason, Inc., all rights reserved. + Author: Andrew Dalke + + Copyright 1995-1997, Automatrix, Inc., all rights reserved. + Author: Skip Montanaro + + Copyright 1991-1995, Stichting Mathematisch Centrum, all rights reserved. + + Permission to use, copy, modify, and distribute this Python software and + its associated documentation for any purpose without fee is hereby + granted, provided that the above copyright notice appears in all copies, + and that both that copyright notice and this permission notice appear in + supporting documentation, and that the name of neither Automatrix, + Bioreason or Mojam Media be used in advertising or publicity pertaining + to distribution of the software without specific, written prior + permission. + + +UUencode and UUdecode functions +------------------------------- + +The `uu' module contains the following notice: + + Copyright 1994 by Lance Ellinghouse + Cathedral City, California Republic, United States of America. + All Rights Reserved + Permission to use, copy, modify, and distribute this software and its + documentation for any purpose and without fee is hereby granted, + provided that the above copyright notice appear in all copies and that + both that copyright notice and this permission notice appear in + supporting documentation, and that the name of Lance Ellinghouse + not be used in advertising or publicity pertaining to distribution + of the software without specific, written prior permission. + LANCE ELLINGHOUSE DISCLAIMS ALL WARRANTIES WITH REGARD TO + THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS, IN NO EVENT SHALL LANCE ELLINGHOUSE CENTRUM BE LIABLE + FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT + OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + + Modified by Jack Jansen, CWI, July 1995: + - Use binascii module to do the actual line-by-line conversion + between ascii and binary. This results in a 1000-fold speedup. The C + version is still 5 times faster, though. + - Arguments more compliant with python standard + + +XML Remote Procedure Calls +-------------------------- + +The `xmlrpclib' module contains the following notice: + + The XML-RPC client interface is + + Copyright (c) 1999-2002 by Secret Labs AB + Copyright (c) 1999-2002 by Fredrik Lundh + + By obtaining, using, and/or copying this software and/or its + associated documentation, you agree that you have read, understood, + and will comply with the following terms and conditions: + + Permission to use, copy, modify, and distribute this software and + its associated documentation for any purpose and without fee is + hereby granted, provided that the above copyright notice appears in + all copies, and that both that copyright notice and this permission + notice appear in supporting documentation, and that the name of + Secret Labs AB or the author not be used in advertising or publicity + pertaining to distribution of the software without specific, written + prior permission. + + SECRET LABS AB AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD + TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANT- + ABILITY AND FITNESS. IN NO EVENT SHALL SECRET LABS AB OR THE AUTHOR + BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY + DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + OF THIS SOFTWARE. + +Licenses for Software linked to +=============================== + +Note that the choice of GPL compatibility outlined above doesn't extend +to modules linked to particular libraries, since they change the +effective License of the module binary. + + +GNU Readline +------------ + +The 'readline' module makes use of GNU Readline. + + The GNU Readline Library is free software; you can redistribute it + and/or modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2, or (at + your option) any later version. + + On Debian systems, you can find the complete statement in + /usr/share/doc/readline-common/copyright'. A copy of the GNU General + Public License is available in /usr/share/common-licenses/GPL-2'. + + +OpenSSL +------- + +The '_ssl' module makes use of OpenSSL. + + The OpenSSL toolkit stays under a dual license, i.e. both the + conditions of the OpenSSL License and the original SSLeay license + apply to the toolkit. Actually both licenses are BSD-style Open + Source licenses. Note that both licenses are incompatible with + the GPL. + + On Debian systems, you can find the complete license text in + /usr/share/doc/openssl/copyright'. + + +Files with other licenses than the Python License +------------------------------------------------- + +Files: Modules/zlib/* +Copyright: (C) 1995-2010 Jean-loup Gailly and Mark Adler +License: This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + Jean-loup Gailly Mark Adler + jloup@gzip.org madler@alumni.caltech.edu + + If you use the zlib library in a product, we would appreciate *not* receiving + lengthy legal documents to sign. The sources are provided for free but without + warranty of any kind. The library has been entirely written by Jean-loup + Gailly and Mark Adler; it does not include third-party code. + +Files: Modules/_ctypes/libffi/* +Copyright: Copyright (C) 1996-2009 Red Hat, Inc and others. +License: Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + ``Software''), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. + + Documentation: + Permission is granted to copy, distribute and/or modify this document + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. A copy of the license is included in the + section entitled ``GNU General Public License''. + +Files: Modules/expat/* +Copyright: Copyright (c) 1998, 1999, 2000 Thai Open Source Software Center Ltd + and Clark Cooper + Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006 Expat maintainers +License: Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Files: Misc/python-mode.el +Copyright: Copyright (C) 1992,1993,1994 Tim Peters +License: This software is provided as-is, without express or implied + warranty. Permission to use, copy, modify, distribute or sell this + software, without fee, for any purpose and by any individual or + organization, is hereby granted, provided that the above copyright + notice and this paragraph appear in all copies. + +Files: PC/_subprocess.c +Copyright: Copyright (c) 2004 by Fredrik Lundh + Copyright (c) 2004 by Secret Labs AB, http://www.pythonware.com + Copyright (c) 2004 by Peter Astrand +License: + * Permission to use, copy, modify, and distribute this software and + * its associated documentation for any purpose and without fee is + * hereby granted, provided that the above copyright notice appears in + * all copies, and that both that copyright notice and this permission + * notice appear in supporting documentation, and that the name of the + * authors not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior + * permission. + * + * THE AUTHORS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. + * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +Files: PC/winsound.c +Copyright: Copyright (c) 1999 Toby Dickenson +License: * Permission to use this software in any way is granted without + * fee, provided that the copyright notice above appears in all + * copies. This software is provided "as is" without any warranty. + */ + +/* Modified by Guido van Rossum */ +/* Beep added by Mark Hammond */ +/* Win9X Beep and platform identification added by Uncle Timmy */ --- python2.7-2.7.orig/debian/source.lintian-overrides +++ python2.7-2.7/debian/source.lintian-overrides @@ -0,0 +1,5 @@ +# this is conditional in the rules file +python2.7 source: debhelper-script-needs-versioned-build-depends dh_icons (>= 5.0.51~) + +# generated during the build +python2.7 source: quilt-build-dep-but-no-series-file --- python2.7-2.7.orig/debian/control.stdlib +++ python2.7-2.7/debian/control.stdlib @@ -0,0 +1,16 @@ +Package: @PVER@-tk +Architecture: any +Depends: @PVER@ (= ${Source-Version}), ${shlibs:Depends} +Suggests: tix +XB-Python-Version: @VER@ +Description: Tkinter - Writing Tk applications with Python (v@VER@) + A module for writing portable GUI applications with Python (v@VER@) using Tk. + Also known as Tkinter. + +Package: @PVER@-gdbm +Architecture: any +Depends: @PVER@ (= ${Source-Version}), ${shlibs:Depends} +Description: GNU dbm database support for Python (v@VER@) + GNU dbm database module for Python. Install this if you want to + create or read GNU dbm database files with Python. + --- python2.7-2.7.orig/debian/pydoc.1.in +++ python2.7-2.7/debian/pydoc.1.in @@ -0,0 +1,53 @@ +.TH PYDOC@VER@ 1 +.SH NAME +pydoc@VER@ \- the Python documentation tool +.SH SYNOPSIS +.PP +.B pydoc@VER@ +.I name +.PP +.B pydoc@VER@ -k +.I keyword +.PP +.B pydoc@VER@ -p +.I port +.PP +.B pydoc@VER@ -g +.PP +.B pydoc@VER@ -w +.I module [...] +.SH DESCRIPTION +.PP +.B pydoc@VER@ +.I name +Show text documentation on something. +.I name +may be the name of a +Python keyword, topic, function, module, or package, or a dotted +reference to a class or function within a module or module in a +package. If +.I name +contains a '/', it is used as the path to a +Python source file to document. If name is 'keywords', 'topics', +or 'modules', a listing of these things is displayed. +.PP +.B pydoc@VER@ -k +.I keyword +Search for a keyword in the synopsis lines of all available modules. +.PP +.B pydoc@VER@ -p +.I port +Start an HTTP server on the given port on the local machine. +.PP +.B pydoc@VER@ -g +Pop up a graphical interface for finding and serving documentation. +.PP +.B pydoc@VER@ -w +.I name [...] +Write out the HTML documentation for a module to a file in the current +directory. If +.I name +contains a '/', it is treated as a filename; if +it names a directory, documentation is written for all the contents. +.SH AUTHOR +Moshe Zadka, based on "pydoc --help" --- python2.7-2.7.orig/debian/depgraph.py +++ python2.7-2.7/debian/depgraph.py @@ -0,0 +1,199 @@ +#! /usr/bin/python + +# Copyright 2004 Toby Dickenson +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject +# to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + +import sys, getopt, colorsys, imp, md5 + +class pydepgraphdot: + + def main(self,argv): + opts,args = getopt.getopt(argv,'',['mono']) + self.colored = 1 + for o,v in opts: + if o=='--mono': + self.colored = 0 + self.render() + + def fix(self,s): + # Convert a module name to a syntactically correct node name + return s.replace('.','_') + + def render(self): + p,t = self.get_data() + + # normalise our input data + for k,d in p.items(): + for v in d.keys(): + if not p.has_key(v): + p[v] = {} + + f = self.get_output_file() + + f.write('digraph G {\n') + #f.write('concentrate = true;\n') + #f.write('ordering = out;\n') + f.write('ranksep=1.0;\n') + f.write('node [style=filled,fontname=Helvetica,fontsize=10];\n') + allkd = p.items() + allkd.sort() + for k,d in allkd: + tk = t.get(k) + if self.use(k,tk): + allv = d.keys() + allv.sort() + for v in allv: + tv = t.get(v) + if self.use(v,tv) and not self.toocommon(v,tv): + f.write('%s -> %s' % ( self.fix(k),self.fix(v) ) ) + self.write_attributes(f,self.edge_attributes(k,v)) + f.write(';\n') + f.write(self.fix(k)) + self.write_attributes(f,self.node_attributes(k,tk)) + f.write(';\n') + f.write('}\n') + + def write_attributes(self,f,a): + if a: + f.write(' [') + f.write(','.join(a)) + f.write(']') + + def node_attributes(self,k,type): + a = [] + a.append('label="%s"' % self.label(k)) + if self.colored: + a.append('fillcolor="%s"' % self.color(k,type)) + else: + a.append('fillcolor=white') + if self.toocommon(k,type): + a.append('peripheries=2') + return a + + def edge_attributes(self,k,v): + a = [] + weight = self.weight(k,v) + if weight!=1: + a.append('weight=%d' % weight) + length = self.alien(k,v) + if length: + a.append('minlen=%d' % length) + return a + + def get_data(self): + t = eval(sys.stdin.read()) + return t['depgraph'],t['types'] + + def get_output_file(self): + return sys.stdout + + def use(self,s,type): + # Return true if this module is interesting and should be drawn. Return false + # if it should be completely omitted. This is a default policy - please override. + if s=='__main__': + return 0 + #if s in ('os','sys','time','__future__','types','re','string'): + if s in ('sys'): + # nearly all modules use all of these... more or less. They add nothing to + # our diagram. + return 0 + if s.startswith('encodings.'): + return 0 + if self.toocommon(s,type): + # A module where we dont want to draw references _to_. Dot doesnt handle these + # well, so it is probably best to not draw them at all. + return 0 + return 1 + + def toocommon(self,s,type): + # Return true if references to this module are uninteresting. Such references + # do not get drawn. This is a default policy - please override. + # + if s=='__main__': + # references *to* __main__ are never interesting. omitting them means + # that main floats to the top of the page + return 1 + #if type==imp.PKG_DIRECTORY: + # # dont draw references to packages. + # return 1 + return 0 + + def weight(self,a,b): + # Return the weight of the dependency from a to b. Higher weights + # usually have shorter straighter edges. Return 1 if it has normal weight. + # A value of 4 is usually good for ensuring that a related pair of modules + # are drawn next to each other. This is a default policy - please override. + # + if b.split('.')[-1].startswith('_'): + # A module that starts with an underscore. You need a special reason to + # import these (for example random imports _random), so draw them close + # together + return 4 + return 1 + + def alien(self,a,b): + # Return non-zero if references to this module are strange, and should be drawn + # extra-long. the value defines the length, in rank. This is also good for putting some + # vertical space between seperate subsystems. This is a default policy - please override. + # + return 0 + + def label(self,s): + # Convert a module name to a formatted node label. This is a default policy - please override. + # + return '\\.\\n'.join(s.split('.')) + + def color(self,s,type): + # Return the node color for this module name. This is a default policy - please override. + # + # Calculate a color systematically based on the hash of the module name. Modules in the + # same package have the same color. Unpackaged modules are grey + t = self.normalise_module_name_for_hash_coloring(s,type) + return self.color_from_name(t) + + def normalise_module_name_for_hash_coloring(self,s,type): + if type==imp.PKG_DIRECTORY: + return s + else: + i = s.rfind('.') + if i<0: + return '' + else: + return s[:i] + + def color_from_name(self,name): + n = md5.md5(name).digest() + hf = float(ord(n[0])+ord(n[1])*0xff)/0xffff + sf = float(ord(n[2]))/0xff + vf = float(ord(n[3]))/0xff + r,g,b = colorsys.hsv_to_rgb(hf, 0.3+0.6*sf, 0.8+0.2*vf) + return '#%02x%02x%02x' % (r*256,g*256,b*256) + + +def main(): + pydepgraphdot().main(sys.argv[1:]) + +if __name__=='__main__': + main() + + + --- python2.7-2.7.orig/debian/idle-PVER.overrides.in +++ python2.7-2.7/debian/idle-PVER.overrides.in @@ -0,0 +1,3 @@ +# icon in dependent package +idle-@PVER@ binary: menu-icon-missing +idle-@PVER@ binary: image-file-in-usr-lib --- python2.7-2.7.orig/debian/idle-PVER.menu.in +++ python2.7-2.7/debian/idle-PVER.menu.in @@ -0,0 +1,5 @@ +?package(idle-@PVER@):needs="X11" section="Applications/Programming"\ + title="IDLE (Python v@VER@)"\ + icon="/usr/share/pixmaps/@PVER@.xpm"\ + command="/usr/bin/idle-@PVER@ -n" \ + hints="Environments" --- python2.7-2.7.orig/debian/PVER.pycentral.in +++ python2.7-2.7/debian/PVER.pycentral.in @@ -0,0 +1,4 @@ +[@PVER@] +runtime: @PVER@ +interpreter: /usr/bin/@PVER@ +prefix: /usr/lib/@PVER@ --- python2.7-2.7.orig/debian/mincheck.py +++ python2.7-2.7/debian/mincheck.py @@ -0,0 +1,41 @@ + +import sys + +def get_listed(fn): + modules = set() + for line in file(fn).readlines(): + modules.add(line.split()[1]) + return modules + +def get_dependencies(fn): + t = eval(file(fn).read()) + modules = set() + depgraph = t['depgraph'] + for mod, deps in depgraph.iteritems(): + if mod != '__main__': + modules.add(mod) + modules.update(deps.keys()) + return depgraph, modules + +def main(): + mods = get_listed(sys.argv[1]) + depgraph, deps = get_dependencies(sys.argv[2]) + print "Listed modules:", sorted(mods) + print + print "Dependent modules:", sorted(deps) + print + + missing = deps.difference(mods) + if missing: + print "Missing modules in python-minimal:" + print missing + for m in missing: + users = [] + for caller, callees in depgraph.iteritems(): + if m in callees: + users.append(caller) + print m, "used in: ", users + sys.exit(len(missing)) + +main() + --- python2.7-2.7.orig/debian/PVER.menu.in +++ python2.7-2.7/debian/PVER.menu.in @@ -0,0 +1,4 @@ +?package(@PVER@):needs="text" section="Applications/Programming"\ + title="Python (v@VER@)"\ + icon="/usr/share/pixmaps/@PVER@.xpm"\ + command="/usr/bin/python@VER@" --- python2.7-2.7.orig/debian/libpython.symbols.in +++ python2.7-2.7/debian/libpython.symbols.in @@ -0,0 +1,1255 @@ + PyAST_Check@Base @VER@ + PyAST_Compile@Base @VER@ + PyAST_FromNode@Base @VER@ + PyAST_mod2obj@Base @VER@ + PyAST_obj2mod@Base @VER@ + PyArena_AddPyObject@Base @VER@ + PyArena_Free@Base @VER@ + PyArena_Malloc@Base @VER@ + PyArena_New@Base @VER@ + PyArg_Parse@Base @VER@ + PyArg_ParseTuple@Base @VER@ + PyArg_ParseTupleAndKeywords@Base @VER@ + PyArg_UnpackTuple@Base @VER@ + PyArg_VaParse@Base @VER@ + PyArg_VaParseTupleAndKeywords@Base @VER@ + PyBaseObject_Type@Base @VER@ + PyBaseString_Type@Base @VER@ + PyBool_FromLong@Base @VER@ + PyBool_Type@Base @VER@ + PyBuffer_FillContiguousStrides@Base @VER@ + PyBuffer_FillInfo@Base @VER@ + PyBuffer_FromContiguous@Base @VER@ + PyBuffer_FromMemory@Base @VER@ + PyBuffer_FromObject@Base @VER@ + PyBuffer_FromReadWriteMemory@Base @VER@ + PyBuffer_FromReadWriteObject@Base @VER@ + PyBuffer_GetPointer@Base @VER@ + PyBuffer_IsContiguous@Base @VER@ + PyBuffer_New@Base @VER@ + PyBuffer_Release@Base @VER@ + PyBuffer_ToContiguous@Base @VER@ + PyBuffer_Type@Base @VER@ + PyByteArrayIter_Type@Base @VER@ + PyByteArray_AsString@Base @VER@ + PyByteArray_Concat@Base @VER@ + PyByteArray_Fini@Base @VER@ + PyByteArray_FromObject@Base @VER@ + PyByteArray_FromStringAndSize@Base @VER@ + PyByteArray_Init@Base @VER@ + PyByteArray_Resize@Base @VER@ + PyByteArray_Size@Base @VER@ + PyByteArray_Type@Base @VER@ + PyCFunction_Call@Base @VER@ + PyCFunction_ClearFreeList@Base @VER@ + PyCFunction_Fini@Base @VER@ + PyCFunction_GetFlags@Base @VER@ + PyCFunction_GetFunction@Base @VER@ + PyCFunction_GetSelf@Base @VER@ + PyCFunction_New@Base @VER@ + PyCFunction_NewEx@Base @VER@ + PyCFunction_Type@Base @VER@ + PyCObject_AsVoidPtr@Base @VER@ + PyCObject_FromVoidPtr@Base @VER@ + PyCObject_FromVoidPtrAndDesc@Base @VER@ + PyCObject_GetDesc@Base @VER@ + PyCObject_Import@Base @VER@ + PyCObject_SetVoidPtr@Base @VER@ + PyCObject_Type@Base @VER@ + PyCallIter_New@Base @VER@ + PyCallIter_Type@Base @VER@ + PyCallable_Check@Base @VER@ + PyCapsule_GetContext@Base @VER@ + PyCapsule_GetDestructor@Base @VER@ + PyCapsule_GetName@Base @VER@ + PyCapsule_GetPointer@Base @VER@ + PyCapsule_Import@Base @VER@ + PyCapsule_IsValid@Base @VER@ + PyCapsule_New@Base @VER@ + PyCapsule_SetContext@Base @VER@ + PyCapsule_SetDestructor@Base @VER@ + PyCapsule_SetName@Base @VER@ + PyCapsule_SetPointer@Base @VER@ + PyCapsule_Type@Base @VER@ + PyCell_Get@Base @VER@ + PyCell_New@Base @VER@ + PyCell_Set@Base @VER@ + PyCell_Type@Base @VER@ + PyClassMethod_New@Base @VER@ + PyClassMethod_Type@Base @VER@ + PyClass_IsSubclass@Base @VER@ + PyClass_New@Base @VER@ + PyClass_Type@Base @VER@ + PyCode_Addr2Line@Base @VER@ + PyCode_New@Base @VER@ + PyCode_NewEmpty@Base @VER@ + PyCode_Optimize@Base @VER@ + PyCode_Type@Base @VER@ + PyCodec_BackslashReplaceErrors@Base @VER@ + PyCodec_Decode@Base @VER@ + PyCodec_Decoder@Base @VER@ + PyCodec_Encode@Base @VER@ + PyCodec_Encoder@Base @VER@ + PyCodec_IgnoreErrors@Base @VER@ + PyCodec_IncrementalDecoder@Base @VER@ + PyCodec_IncrementalEncoder@Base @VER@ + PyCodec_LookupError@Base @VER@ + PyCodec_Register@Base @VER@ + PyCodec_RegisterError@Base @VER@ + PyCodec_ReplaceErrors@Base @VER@ + PyCodec_StreamReader@Base @VER@ + PyCodec_StreamWriter@Base @VER@ + PyCodec_StrictErrors@Base @VER@ + PyCodec_XMLCharRefReplaceErrors@Base @VER@ + PyComplex_AsCComplex@Base @VER@ + PyComplex_FromCComplex@Base @VER@ + PyComplex_FromDoubles@Base @VER@ + PyComplex_ImagAsDouble@Base @VER@ + PyComplex_RealAsDouble@Base @VER@ + PyComplex_Type@Base @VER@ + PyDescr_NewClassMethod@Base @VER@ + PyDescr_NewGetSet@Base @VER@ + PyDescr_NewMember@Base @VER@ + PyDescr_NewMethod@Base @VER@ + PyDescr_NewWrapper@Base @VER@ + PyDictItems_Type@Base @VER@ + PyDictIterItem_Type@Base @VER@ + PyDictIterKey_Type@Base @VER@ + PyDictIterValue_Type@Base @VER@ + PyDictKeys_Type@Base @VER@ + PyDictProxy_New@Base @VER@ + PyDictProxy_Type@Base @VER@ + PyDictValues_Type@Base @VER@ + PyDict_Clear@Base @VER@ + PyDict_Contains@Base @VER@ + PyDict_Copy@Base @VER@ + PyDict_DelItem@Base @VER@ + PyDict_DelItemString@Base @VER@ + PyDict_Fini@Base @VER@ + PyDict_GetItem@Base @VER@ + PyDict_GetItemString@Base @VER@ + PyDict_Items@Base @VER@ + PyDict_Keys@Base @VER@ + PyDict_Merge@Base @VER@ + PyDict_MergeFromSeq2@Base @VER@ + PyDict_New@Base @VER@ + PyDict_Next@Base @VER@ + PyDict_SetItem@Base @VER@ + PyDict_SetItemString@Base @VER@ + PyDict_Size@Base @VER@ + PyDict_Type@Base @VER@ + PyDict_Update@Base @VER@ + PyDict_Values@Base @VER@ + PyEllipsis_Type@Base @VER@ + PyEnum_Type@Base @VER@ + PyErr_BadArgument@Base @VER@ + PyErr_BadInternalCall@Base @VER@ + PyErr_CheckSignals@Base @VER@ + PyErr_Clear@Base @VER@ + PyErr_Display@Base @VER@ + PyErr_ExceptionMatches@Base @VER@ + PyErr_Fetch@Base @VER@ + PyErr_Format@Base @VER@ + PyErr_GivenExceptionMatches@Base @VER@ + PyErr_NewException@Base @VER@ + PyErr_NewExceptionWithDoc@Base @VER@ + PyErr_NoMemory@Base @VER@ + PyErr_NormalizeException@Base @VER@ + PyErr_Occurred@Base @VER@ + PyErr_Print@Base @VER@ + PyErr_PrintEx@Base @VER@ + PyErr_ProgramText@Base @VER@ + PyErr_Restore@Base @VER@ + PyErr_SetFromErrno@Base @VER@ + PyErr_SetFromErrnoWithFilename@Base @VER@ + PyErr_SetFromErrnoWithFilenameObject@Base @VER@ + PyErr_SetInterrupt@Base @VER@ + PyErr_SetNone@Base @VER@ + PyErr_SetObject@Base @VER@ + PyErr_SetString@Base @VER@ + PyErr_SyntaxLocation@Base @VER@ + PyErr_Warn@Base @VER@ + PyErr_WarnEx@Base @VER@ + PyErr_WarnExplicit@Base @VER@ + PyErr_WriteUnraisable@Base @VER@ + PyEval_AcquireLock@Base @VER@ + PyEval_AcquireThread@Base @VER@ + PyEval_CallFunction@Base @VER@ + PyEval_CallMethod@Base @VER@ + PyEval_CallObjectWithKeywords@Base @VER@ + PyEval_EvalCode@Base @VER@ + PyEval_EvalCodeEx@Base @VER@ + PyEval_EvalFrame@Base @VER@ + PyEval_EvalFrameEx@Base @VER@ + PyEval_GetBuiltins@Base @VER@ + PyEval_GetCallStats@Base @VER@ + PyEval_GetFrame@Base @VER@ + PyEval_GetFuncDesc@Base @VER@ + PyEval_GetFuncName@Base @VER@ + PyEval_GetGlobals@Base @VER@ + PyEval_GetLocals@Base @VER@ + PyEval_GetRestricted@Base @VER@ + PyEval_InitThreads@Base @VER@ + PyEval_MergeCompilerFlags@Base @VER@ + PyEval_ReInitThreads@Base @VER@ + PyEval_ReleaseLock@Base @VER@ + PyEval_ReleaseThread@Base @VER@ + PyEval_RestoreThread@Base @VER@ + PyEval_SaveThread@Base @VER@ + PyEval_SetProfile@Base @VER@ + PyEval_SetTrace@Base @VER@ + PyEval_ThreadsInitialized@Base @VER@ + PyExc_ArithmeticError@Base @VER@ + PyExc_AssertionError@Base @VER@ + PyExc_AttributeError@Base @VER@ + PyExc_BaseException@Base @VER@ + PyExc_BufferError@Base @VER@ + PyExc_BytesWarning@Base @VER@ + PyExc_DeprecationWarning@Base @VER@ + PyExc_EOFError@Base @VER@ + PyExc_EnvironmentError@Base @VER@ + PyExc_Exception@Base @VER@ + PyExc_FloatingPointError@Base @VER@ + PyExc_FutureWarning@Base @VER@ + PyExc_GeneratorExit@Base @VER@ + PyExc_IOError@Base @VER@ + PyExc_ImportError@Base @VER@ + PyExc_ImportWarning@Base @VER@ + PyExc_IndentationError@Base @VER@ + PyExc_IndexError@Base @VER@ + PyExc_KeyError@Base @VER@ + PyExc_KeyboardInterrupt@Base @VER@ + PyExc_LookupError@Base @VER@ + PyExc_MemoryError@Base @VER@ + PyExc_MemoryErrorInst@Base @VER@ + PyExc_NameError@Base @VER@ + PyExc_NotImplementedError@Base @VER@ + PyExc_OSError@Base @VER@ + PyExc_OverflowError@Base @VER@ + PyExc_PendingDeprecationWarning@Base @VER@ + PyExc_RecursionErrorInst@Base @VER@ + PyExc_ReferenceError@Base @VER@ + PyExc_RuntimeError@Base @VER@ + PyExc_RuntimeWarning@Base @VER@ + PyExc_StandardError@Base @VER@ + PyExc_StopIteration@Base @VER@ + PyExc_SyntaxError@Base @VER@ + PyExc_SyntaxWarning@Base @VER@ + PyExc_SystemError@Base @VER@ + PyExc_SystemExit@Base @VER@ + PyExc_TabError@Base @VER@ + PyExc_TypeError@Base @VER@ + PyExc_UnboundLocalError@Base @VER@ + PyExc_UnicodeDecodeError@Base @VER@ + PyExc_UnicodeEncodeError@Base @VER@ + PyExc_UnicodeError@Base @VER@ + PyExc_UnicodeTranslateError@Base @VER@ + PyExc_UnicodeWarning@Base @VER@ + PyExc_UserWarning@Base @VER@ + PyExc_ValueError@Base @VER@ + PyExc_Warning@Base @VER@ + PyExc_ZeroDivisionError@Base @VER@ + PyFile_AsFile@Base @VER@ + PyFile_DecUseCount@Base @VER@ + PyFile_FromFile@Base @VER@ + PyFile_FromString@Base @VER@ + PyFile_GetLine@Base @VER@ + PyFile_IncUseCount@Base @VER@ + PyFile_Name@Base @VER@ + PyFile_SetBufSize@Base @VER@ + PyFile_SetEncoding@Base @VER@ + PyFile_SetEncodingAndErrors@Base @VER@ + PyFile_SoftSpace@Base @VER@ + PyFile_Type@Base @VER@ + PyFile_WriteObject@Base @VER@ + PyFile_WriteString@Base @VER@ + PyFloat_AsDouble@Base @VER@ + PyFloat_AsReprString@Base @VER@ + PyFloat_AsString@Base @VER@ + PyFloat_ClearFreeList@Base @VER@ + PyFloat_Fini@Base @VER@ + PyFloat_FromDouble@Base @VER@ + PyFloat_FromString@Base @VER@ + PyFloat_GetInfo@Base @VER@ + PyFloat_GetMax@Base @VER@ + PyFloat_GetMin@Base @VER@ + PyFloat_Type@Base @VER@ + PyFrame_BlockPop@Base @VER@ + PyFrame_BlockSetup@Base @VER@ + PyFrame_ClearFreeList@Base @VER@ + PyFrame_FastToLocals@Base @VER@ + PyFrame_Fini@Base @VER@ + PyFrame_GetLineNumber@Base @VER@ + PyFrame_LocalsToFast@Base @VER@ + PyFrame_New@Base @VER@ + PyFrame_Type@Base @VER@ + PyFrozenSet_New@Base @VER@ + PyFrozenSet_Type@Base @VER@ + PyFunction_GetClosure@Base @VER@ + PyFunction_GetCode@Base @VER@ + PyFunction_GetDefaults@Base @VER@ + PyFunction_GetGlobals@Base @VER@ + PyFunction_GetModule@Base @VER@ + PyFunction_New@Base @VER@ + PyFunction_SetClosure@Base @VER@ + PyFunction_SetDefaults@Base @VER@ + PyFunction_Type@Base @VER@ + PyFuture_FromAST@Base @VER@ + PyGC_Collect@Base @VER@ + PyGILState_Ensure@Base @VER@ + PyGILState_GetThisThreadState@Base @VER@ + PyGILState_Release@Base @VER@ + PyGen_NeedsFinalizing@Base @VER@ + PyGen_New@Base @VER@ + PyGen_Type@Base @VER@ + PyGetSetDescr_Type@Base @VER@ + PyGrammar_AddAccelerators@Base @VER@ + PyGrammar_FindDFA@Base @VER@ + PyGrammar_LabelRepr@Base @VER@ + PyGrammar_RemoveAccelerators@Base @VER@ + PyImport_AddModule@Base @VER@ + PyImport_AppendInittab@Base @VER@ + PyImport_Cleanup@Base @VER@ + PyImport_ExecCodeModule@Base @VER@ + PyImport_ExecCodeModuleEx@Base @VER@ + PyImport_ExtendInittab@Base @VER@ + PyImport_FrozenModules@Base @VER@ + PyImport_GetImporter@Base @VER@ + PyImport_GetMagicNumber@Base @VER@ + PyImport_GetModuleDict@Base @VER@ + PyImport_Import@Base @VER@ + PyImport_ImportFrozenModule@Base @VER@ + PyImport_ImportModule@Base @VER@ + PyImport_ImportModuleLevel@Base @VER@ + PyImport_ImportModuleNoBlock@Base @VER@ + PyImport_Inittab@Base @VER@ + PyImport_ReloadModule@Base @VER@ + PyInstance_New@Base @VER@ + PyInstance_NewRaw@Base @VER@ + PyInstance_Type@Base @VER@ + PyInt_AsLong@Base @VER@ + PyInt_AsSsize_t@Base @VER@ + PyInt_AsUnsignedLongLongMask@Base @VER@ + PyInt_AsUnsignedLongMask@Base @VER@ + PyInt_ClearFreeList@Base @VER@ + PyInt_Fini@Base @VER@ + PyInt_FromLong@Base @VER@ + PyInt_FromSize_t@Base @VER@ + PyInt_FromSsize_t@Base @VER@ + PyInt_FromString@Base @VER@ + PyInt_FromUnicode@Base @VER@ + PyInt_GetMax@Base @VER@ + PyInt_Type@Base @VER@ + PyInterpreterState_Clear@Base @VER@ + PyInterpreterState_Delete@Base @VER@ + PyInterpreterState_Head@Base @VER@ + PyInterpreterState_New@Base @VER@ + PyInterpreterState_Next@Base @VER@ + PyInterpreterState_ThreadHead@Base @VER@ + PyIter_Next@Base @VER@ + PyListIter_Type@Base @VER@ + PyListRevIter_Type@Base @VER@ + PyList_Append@Base @VER@ + PyList_AsTuple@Base @VER@ + PyList_Fini@Base @VER@ + PyList_GetItem@Base @VER@ + PyList_GetSlice@Base @VER@ + PyList_Insert@Base @VER@ + PyList_New@Base @VER@ + PyList_Reverse@Base @VER@ + PyList_SetItem@Base @VER@ + PyList_SetSlice@Base @VER@ + PyList_Size@Base @VER@ + PyList_Sort@Base @VER@ + PyList_Type@Base @VER@ + PyLong_AsDouble@Base @VER@ + PyLong_AsLong@Base @VER@ + PyLong_AsLongAndOverflow@Base @VER@ + PyLong_AsLongLong@Base @VER@ + PyLong_AsLongLongAndOverflow@Base @VER@ + PyLong_AsSsize_t@Base @VER@ + PyLong_AsUnsignedLong@Base @VER@ + PyLong_AsUnsignedLongLong@Base @VER@ + PyLong_AsUnsignedLongLongMask@Base @VER@ + PyLong_AsUnsignedLongMask@Base @VER@ + PyLong_AsVoidPtr@Base @VER@ + PyLong_FromDouble@Base @VER@ + PyLong_FromLong@Base @VER@ + PyLong_FromLongLong@Base @VER@ + PyLong_FromSize_t@Base @VER@ + PyLong_FromSsize_t@Base @VER@ + PyLong_FromString@Base @VER@ + PyLong_FromUnicode@Base @VER@ + PyLong_FromUnsignedLong@Base @VER@ + PyLong_FromUnsignedLongLong@Base @VER@ + PyLong_FromVoidPtr@Base @VER@ + PyLong_GetInfo@Base @VER@ + PyLong_Type@Base @VER@ + PyMapping_Check@Base @VER@ + PyMapping_GetItemString@Base @VER@ + PyMapping_HasKey@Base @VER@ + PyMapping_HasKeyString@Base @VER@ + PyMapping_Length@Base @VER@ + PyMapping_SetItemString@Base @VER@ + PyMapping_Size@Base @VER@ + PyMarshal_Init@Base @VER@ + PyMarshal_ReadLastObjectFromFile@Base @VER@ + PyMarshal_ReadLongFromFile@Base @VER@ + PyMarshal_ReadObjectFromFile@Base @VER@ + PyMarshal_ReadObjectFromString@Base @VER@ + PyMarshal_ReadShortFromFile@Base @VER@ + PyMarshal_WriteLongToFile@Base @VER@ + PyMarshal_WriteObjectToFile@Base @VER@ + PyMarshal_WriteObjectToString@Base @VER@ + PyMem_Free@Base @VER@ + PyMem_Malloc@Base @VER@ + PyMem_Realloc@Base @VER@ + PyMemberDescr_Type@Base @VER@ + PyMember_Get@Base @VER@ + PyMember_GetOne@Base @VER@ + PyMember_Set@Base @VER@ + PyMember_SetOne@Base @VER@ + PyMemoryView_FromBuffer@Base @VER@ + PyMemoryView_FromObject@Base @VER@ + PyMemoryView_GetContiguous@Base @VER@ + PyMemoryView_Type@Base @VER@ + PyMethod_Class@Base @VER@ + PyMethod_ClearFreeList@Base @VER@ + PyMethod_Fini@Base @VER@ + PyMethod_Function@Base @VER@ + PyMethod_New@Base @VER@ + PyMethod_Self@Base @VER@ + PyMethod_Type@Base @VER@ + PyModule_AddIntConstant@Base @VER@ + PyModule_AddObject@Base @VER@ + PyModule_AddStringConstant@Base @VER@ + PyModule_GetDict@Base @VER@ + PyModule_GetFilename@Base @VER@ + PyModule_GetName@Base @VER@ + PyModule_GetWarningsModule@Base @VER@ + PyModule_New@Base @VER@ + PyModule_Type@Base @VER@ + PyNode_AddChild@Base @VER@ + PyNode_Compile@Base @VER@ + PyNode_Free@Base @VER@ + PyNode_ListTree@Base @VER@ + PyNode_New@Base @VER@ + PyNullImporter_Type@Base @VER@ + PyNumber_Absolute@Base @VER@ + PyNumber_Add@Base @VER@ + PyNumber_And@Base @VER@ + PyNumber_AsSsize_t@Base @VER@ + PyNumber_Check@Base @VER@ + PyNumber_Coerce@Base @VER@ + PyNumber_CoerceEx@Base @VER@ + PyNumber_Divide@Base @VER@ + PyNumber_Divmod@Base @VER@ + PyNumber_Float@Base @VER@ + PyNumber_FloorDivide@Base @VER@ + PyNumber_InPlaceAdd@Base @VER@ + PyNumber_InPlaceAnd@Base @VER@ + PyNumber_InPlaceDivide@Base @VER@ + PyNumber_InPlaceFloorDivide@Base @VER@ + PyNumber_InPlaceLshift@Base @VER@ + PyNumber_InPlaceMultiply@Base @VER@ + PyNumber_InPlaceOr@Base @VER@ + PyNumber_InPlacePower@Base @VER@ + PyNumber_InPlaceRemainder@Base @VER@ + PyNumber_InPlaceRshift@Base @VER@ + PyNumber_InPlaceSubtract@Base @VER@ + PyNumber_InPlaceTrueDivide@Base @VER@ + PyNumber_InPlaceXor@Base @VER@ + PyNumber_Index@Base @VER@ + PyNumber_Int@Base @VER@ + PyNumber_Invert@Base @VER@ + PyNumber_Long@Base @VER@ + PyNumber_Lshift@Base @VER@ + PyNumber_Multiply@Base @VER@ + PyNumber_Negative@Base @VER@ + PyNumber_Or@Base @VER@ + PyNumber_Positive@Base @VER@ + PyNumber_Power@Base @VER@ + PyNumber_Remainder@Base @VER@ + PyNumber_Rshift@Base @VER@ + PyNumber_Subtract@Base @VER@ + PyNumber_ToBase@Base @VER@ + PyNumber_TrueDivide@Base @VER@ + PyNumber_Xor@Base @VER@ + PyOS_AfterFork@Base @VER@ + PyOS_FiniInterrupts@Base @VER@ + PyOS_InitInterrupts@Base @VER@ + PyOS_InputHook@Base @VER@ + PyOS_InterruptOccurred@Base @VER@ + PyOS_Readline@Base @VER@ + PyOS_ReadlineFunctionPointer@Base @VER@ + PyOS_StdioReadline@Base @VER@ + PyOS_ascii_atof@Base @VER@ + PyOS_ascii_formatd@Base @VER@ + PyOS_ascii_strtod@Base @VER@ + PyOS_double_to_string@Base @VER@ + PyOS_getsig@Base @VER@ + PyOS_mystricmp@Base @VER@ + PyOS_mystrnicmp@Base @VER@ + PyOS_setsig@Base @VER@ + PyOS_snprintf@Base @VER@ + PyOS_string_to_double@Base @VER@ + PyOS_strtol@Base @VER@ + PyOS_strtoul@Base @VER@ + PyOS_vsnprintf@Base @VER@ + PyObject_AsCharBuffer@Base @VER@ + PyObject_AsFileDescriptor@Base @VER@ + PyObject_AsReadBuffer@Base @VER@ + PyObject_AsWriteBuffer@Base @VER@ + PyObject_Call@Base @VER@ + PyObject_CallFunction@Base @VER@ + PyObject_CallFunctionObjArgs@Base @VER@ + PyObject_CallMethod@Base @VER@ + PyObject_CallMethodObjArgs@Base @VER@ + PyObject_CallObject@Base @VER@ + PyObject_CheckReadBuffer@Base @VER@ + PyObject_ClearWeakRefs@Base @VER@ + PyObject_Cmp@Base @VER@ + PyObject_Compare@Base @VER@ + PyObject_CopyData@Base @VER@ + PyObject_DelItem@Base @VER@ + PyObject_DelItemString@Base @VER@ + PyObject_Dir@Base @VER@ + PyObject_Format@Base @VER@ + PyObject_Free@Base @VER@ + PyObject_GC_Del@Base @VER@ + PyObject_GC_Track@Base @VER@ + PyObject_GC_UnTrack@Base @VER@ + PyObject_GenericGetAttr@Base @VER@ + PyObject_GenericSetAttr@Base @VER@ + PyObject_GetAttr@Base @VER@ + PyObject_GetAttrString@Base @VER@ + PyObject_GetBuffer@Base @VER@ + PyObject_GetItem@Base @VER@ + PyObject_GetIter@Base @VER@ + PyObject_HasAttr@Base @VER@ + PyObject_HasAttrString@Base @VER@ + PyObject_Hash@Base @VER@ + PyObject_HashNotImplemented@Base @VER@ + PyObject_Init@Base @VER@ + PyObject_InitVar@Base @VER@ + PyObject_IsInstance@Base @VER@ + PyObject_IsSubclass@Base @VER@ + PyObject_IsTrue@Base @VER@ + PyObject_Length@Base @VER@ + PyObject_Malloc@Base @VER@ + PyObject_Not@Base @VER@ + PyObject_Print@Base @VER@ + PyObject_Realloc@Base @VER@ + PyObject_Repr@Base @VER@ + PyObject_RichCompare@Base @VER@ + PyObject_RichCompareBool@Base @VER@ + PyObject_SelfIter@Base @VER@ + PyObject_SetAttr@Base @VER@ + PyObject_SetAttrString@Base @VER@ + PyObject_SetItem@Base @VER@ + PyObject_Size@Base @VER@ + PyObject_Str@Base @VER@ + PyObject_Type@Base @VER@ + PyObject_Unicode@Base @VER@ + PyParser_ASTFromFile@Base @VER@ + PyParser_ASTFromString@Base @VER@ + PyParser_AddToken@Base @VER@ + PyParser_Delete@Base @VER@ + PyParser_New@Base @VER@ + PyParser_ParseFile@Base @VER@ + PyParser_ParseFileFlags@Base @VER@ + PyParser_ParseFileFlagsEx@Base @VER@ + PyParser_ParseString@Base @VER@ + PyParser_ParseStringFlags@Base @VER@ + PyParser_ParseStringFlagsFilename@Base @VER@ + PyParser_ParseStringFlagsFilenameEx@Base @VER@ + PyParser_SetError@Base @VER@ + PyParser_SimpleParseFile@Base @VER@ + PyParser_SimpleParseFileFlags@Base @VER@ + PyParser_SimpleParseString@Base @VER@ + PyParser_SimpleParseStringFilename@Base @VER@ + PyParser_SimpleParseStringFlags@Base @VER@ + PyParser_SimpleParseStringFlagsFilename@Base @VER@ + PyProperty_Type@Base @VER@ + PyRange_Type@Base @VER@ + PyReversed_Type@Base @VER@ + PyRun_AnyFile@Base @VER@ + PyRun_AnyFileEx@Base @VER@ + PyRun_AnyFileExFlags@Base @VER@ + PyRun_AnyFileFlags@Base @VER@ + PyRun_File@Base @VER@ + PyRun_FileEx@Base @VER@ + PyRun_FileExFlags@Base @VER@ + PyRun_FileFlags@Base @VER@ + PyRun_InteractiveLoop@Base @VER@ + PyRun_InteractiveLoopFlags@Base @VER@ + PyRun_InteractiveOne@Base @VER@ + PyRun_InteractiveOneFlags@Base @VER@ + PyRun_SimpleFile@Base @VER@ + PyRun_SimpleFileEx@Base @VER@ + PyRun_SimpleFileExFlags@Base @VER@ + PyRun_SimpleString@Base @VER@ + PyRun_SimpleStringFlags@Base @VER@ + PyRun_String@Base @VER@ + PyRun_StringFlags@Base @VER@ + PySTEntry_Type@Base @VER@ + PyST_GetScope@Base @VER@ + PySeqIter_New@Base @VER@ + PySeqIter_Type@Base @VER@ + PySequence_Check@Base @VER@ + PySequence_Concat@Base @VER@ + PySequence_Contains@Base @VER@ + PySequence_Count@Base @VER@ + PySequence_DelItem@Base @VER@ + PySequence_DelSlice@Base @VER@ + PySequence_Fast@Base @VER@ + PySequence_GetItem@Base @VER@ + PySequence_GetSlice@Base @VER@ + PySequence_In@Base @VER@ + PySequence_InPlaceConcat@Base @VER@ + PySequence_InPlaceRepeat@Base @VER@ + PySequence_Index@Base @VER@ + PySequence_Length@Base @VER@ + PySequence_List@Base @VER@ + PySequence_Repeat@Base @VER@ + PySequence_SetItem@Base @VER@ + PySequence_SetSlice@Base @VER@ + PySequence_Size@Base @VER@ + PySequence_Tuple@Base @VER@ + PySet_Add@Base @VER@ + PySet_Clear@Base @VER@ + PySet_Contains@Base @VER@ + PySet_Discard@Base @VER@ + PySet_Fini@Base @VER@ + PySet_New@Base @VER@ + PySet_Pop@Base @VER@ + PySet_Size@Base @VER@ + PySet_Type@Base @VER@ + PySignal_SetWakeupFd@Base @VER@ + PySlice_GetIndices@Base @VER@ + PySlice_GetIndicesEx@Base @VER@ + PySlice_New@Base @VER@ + PySlice_Type@Base @VER@ + PyStaticMethod_New@Base @VER@ + PyStaticMethod_Type@Base @VER@ + PyString_AsDecodedObject@Base @VER@ + PyString_AsDecodedString@Base @VER@ + PyString_AsEncodedObject@Base @VER@ + PyString_AsEncodedString@Base @VER@ + PyString_AsString@Base @VER@ + PyString_AsStringAndSize@Base @VER@ + PyString_Concat@Base @VER@ + PyString_ConcatAndDel@Base @VER@ + PyString_Decode@Base @VER@ + PyString_DecodeEscape@Base @VER@ + PyString_Encode@Base @VER@ + PyString_Fini@Base @VER@ + PyString_Format@Base @VER@ + PyString_FromFormat@Base @VER@ + PyString_FromFormatV@Base @VER@ + PyString_FromString@Base @VER@ + PyString_FromStringAndSize@Base @VER@ + PyString_InternFromString@Base @VER@ + PyString_InternImmortal@Base @VER@ + PyString_InternInPlace@Base @VER@ + PyString_Repr@Base @VER@ + PyString_Size@Base @VER@ + PyString_Type@Base @VER@ + PyStructSequence_InitType@Base @VER@ + PyStructSequence_New@Base @VER@ + PyStructSequence_UnnamedField@Base @VER@ + PySuper_Type@Base @VER@ + PySymtable_Build@Base @VER@ + PySymtable_Free@Base @VER@ + PySymtable_Lookup@Base @VER@ + PySys_AddWarnOption@Base @VER@ + PySys_GetFile@Base @VER@ + PySys_GetObject@Base @VER@ + PySys_HasWarnOptions@Base @VER@ + PySys_ResetWarnOptions@Base @VER@ + PySys_SetArgv@Base @VER@ + PySys_SetArgvEx@Base @VER@ + PySys_SetObject@Base @VER@ + PySys_SetPath@Base @VER@ + PySys_WriteStderr@Base @VER@ + PySys_WriteStdout@Base @VER@ + PyThreadState_Clear@Base @VER@ + PyThreadState_Delete@Base @VER@ + PyThreadState_DeleteCurrent@Base @VER@ + PyThreadState_Get@Base @VER@ + PyThreadState_GetDict@Base @VER@ + PyThreadState_New@Base @VER@ + PyThreadState_Next@Base @VER@ + PyThreadState_SetAsyncExc@Base @VER@ + PyThreadState_Swap@Base @VER@ + PyThread_ReInitTLS@Base @VER@ + PyThread_acquire_lock@Base @VER@ + PyThread_allocate_lock@Base @VER@ + PyThread_create_key@Base @VER@ + PyThread_delete_key@Base @VER@ + PyThread_delete_key_value@Base @VER@ + PyThread_exit_thread@Base @VER@ + PyThread_free_lock@Base @VER@ + PyThread_get_key_value@Base @VER@ + PyThread_get_stacksize@Base @VER@ + PyThread_get_thread_ident@Base @VER@ + PyThread_init_thread@Base @VER@ + PyThread_release_lock@Base @VER@ + PyThread_set_key_value@Base @VER@ + PyThread_set_stacksize@Base @VER@ + PyThread_start_new_thread@Base @VER@ + PyToken_OneChar@Base @VER@ + PyToken_ThreeChars@Base @VER@ + PyToken_TwoChars@Base @VER@ + PyTokenizer_Free@Base @VER@ + PyTokenizer_FromFile@Base @VER@ + PyTokenizer_FromString@Base @VER@ + PyTokenizer_Get@Base @VER@ + PyTokenizer_RestoreEncoding@Base @VER@ + PyTraceBack_Here@Base @VER@ + PyTraceBack_Print@Base @VER@ + PyTraceBack_Type@Base @VER@ + PyTupleIter_Type@Base @VER@ + PyTuple_ClearFreeList@Base @VER@ + PyTuple_Fini@Base @VER@ + PyTuple_GetItem@Base @VER@ + PyTuple_GetSlice@Base @VER@ + PyTuple_New@Base @VER@ + PyTuple_Pack@Base @VER@ + PyTuple_SetItem@Base @VER@ + PyTuple_Size@Base @VER@ + PyTuple_Type@Base @VER@ + PyType_ClearCache@Base @VER@ + PyType_GenericAlloc@Base @VER@ + PyType_GenericNew@Base @VER@ + PyType_IsSubtype@Base @VER@ + PyType_Modified@Base @VER@ + PyType_Ready@Base @VER@ + PyType_Type@Base @VER@ + PyUnicodeDecodeError_Create@Base @VER@ + PyUnicodeDecodeError_GetEncoding@Base @VER@ + PyUnicodeDecodeError_GetEnd@Base @VER@ + PyUnicodeDecodeError_GetObject@Base @VER@ + PyUnicodeDecodeError_GetReason@Base @VER@ + PyUnicodeDecodeError_GetStart@Base @VER@ + PyUnicodeDecodeError_SetEnd@Base @VER@ + PyUnicodeDecodeError_SetReason@Base @VER@ + PyUnicodeDecodeError_SetStart@Base @VER@ + PyUnicodeEncodeError_Create@Base @VER@ + PyUnicodeEncodeError_GetEncoding@Base @VER@ + PyUnicodeEncodeError_GetEnd@Base @VER@ + PyUnicodeEncodeError_GetObject@Base @VER@ + PyUnicodeEncodeError_GetReason@Base @VER@ + PyUnicodeEncodeError_GetStart@Base @VER@ + PyUnicodeEncodeError_SetEnd@Base @VER@ + PyUnicodeEncodeError_SetReason@Base @VER@ + PyUnicodeEncodeError_SetStart@Base @VER@ + PyUnicodeTranslateError_Create@Base @VER@ + PyUnicodeTranslateError_GetEnd@Base @VER@ + PyUnicodeTranslateError_GetObject@Base @VER@ + PyUnicodeTranslateError_GetReason@Base @VER@ + PyUnicodeTranslateError_GetStart@Base @VER@ + PyUnicodeTranslateError_SetEnd@Base @VER@ + PyUnicodeTranslateError_SetReason@Base @VER@ + PyUnicodeTranslateError_SetStart@Base @VER@ + PyUnicodeUCS4_AsASCIIString@Base @VER@ + PyUnicodeUCS4_AsCharmapString@Base @VER@ + PyUnicodeUCS4_AsEncodedObject@Base @VER@ + PyUnicodeUCS4_AsEncodedString@Base @VER@ + PyUnicodeUCS4_AsLatin1String@Base @VER@ + PyUnicodeUCS4_AsRawUnicodeEscapeString@Base @VER@ + PyUnicodeUCS4_AsUTF16String@Base @VER@ + PyUnicodeUCS4_AsUTF32String@Base @VER@ + PyUnicodeUCS4_AsUTF8String@Base @VER@ + PyUnicodeUCS4_AsUnicode@Base @VER@ + PyUnicodeUCS4_AsUnicodeEscapeString@Base @VER@ + PyUnicodeUCS4_AsWideChar@Base @VER@ + PyUnicodeUCS4_ClearFreelist@Base @VER@ + PyUnicodeUCS4_Compare@Base @VER@ + PyUnicodeUCS4_Concat@Base @VER@ + PyUnicodeUCS4_Contains@Base @VER@ + PyUnicodeUCS4_Count@Base @VER@ + PyUnicodeUCS4_Decode@Base @VER@ + PyUnicodeUCS4_DecodeASCII@Base @VER@ + PyUnicodeUCS4_DecodeCharmap@Base @VER@ + PyUnicodeUCS4_DecodeLatin1@Base @VER@ + PyUnicodeUCS4_DecodeRawUnicodeEscape@Base @VER@ + PyUnicodeUCS4_DecodeUTF16@Base @VER@ + PyUnicodeUCS4_DecodeUTF16Stateful@Base @VER@ + PyUnicodeUCS4_DecodeUTF32@Base @VER@ + PyUnicodeUCS4_DecodeUTF32Stateful@Base @VER@ + PyUnicodeUCS4_DecodeUTF8@Base @VER@ + PyUnicodeUCS4_DecodeUTF8Stateful@Base @VER@ + PyUnicodeUCS4_DecodeUnicodeEscape@Base @VER@ + PyUnicodeUCS4_Encode@Base @VER@ + PyUnicodeUCS4_EncodeASCII@Base @VER@ + PyUnicodeUCS4_EncodeCharmap@Base @VER@ + PyUnicodeUCS4_EncodeDecimal@Base @VER@ + PyUnicodeUCS4_EncodeLatin1@Base @VER@ + PyUnicodeUCS4_EncodeRawUnicodeEscape@Base @VER@ + PyUnicodeUCS4_EncodeUTF16@Base @VER@ + PyUnicodeUCS4_EncodeUTF32@Base @VER@ + PyUnicodeUCS4_EncodeUTF8@Base @VER@ + PyUnicodeUCS4_EncodeUnicodeEscape@Base @VER@ + PyUnicodeUCS4_Find@Base @VER@ + PyUnicodeUCS4_Format@Base @VER@ + PyUnicodeUCS4_FromEncodedObject@Base @VER@ + PyUnicodeUCS4_FromFormat@Base @VER@ + PyUnicodeUCS4_FromFormatV@Base @VER@ + PyUnicodeUCS4_FromObject@Base @VER@ + PyUnicodeUCS4_FromOrdinal@Base @VER@ + PyUnicodeUCS4_FromString@Base @VER@ + PyUnicodeUCS4_FromStringAndSize@Base @VER@ + PyUnicodeUCS4_FromUnicode@Base @VER@ + PyUnicodeUCS4_FromWideChar@Base @VER@ + PyUnicodeUCS4_GetDefaultEncoding@Base @VER@ + PyUnicodeUCS4_GetMax@Base @VER@ + PyUnicodeUCS4_GetSize@Base @VER@ + PyUnicodeUCS4_Join@Base @VER@ + PyUnicodeUCS4_Partition@Base @VER@ + PyUnicodeUCS4_RPartition@Base @VER@ + PyUnicodeUCS4_RSplit@Base @VER@ + PyUnicodeUCS4_Replace@Base @VER@ + PyUnicodeUCS4_Resize@Base @VER@ + PyUnicodeUCS4_RichCompare@Base @VER@ + PyUnicodeUCS4_SetDefaultEncoding@Base @VER@ + PyUnicodeUCS4_Split@Base @VER@ + PyUnicodeUCS4_Splitlines@Base @VER@ + PyUnicodeUCS4_Tailmatch@Base @VER@ + PyUnicodeUCS4_Translate@Base @VER@ + PyUnicodeUCS4_TranslateCharmap@Base @VER@ + PyUnicode_AsDecodedObject@Base @VER@ + PyUnicode_BuildEncodingMap@Base @VER@ + PyUnicode_DecodeUTF7@Base @VER@ + PyUnicode_DecodeUTF7Stateful@Base @VER@ + PyUnicode_EncodeUTF7@Base @VER@ + PyUnicode_Type@Base @VER@ + PyWeakref_GetObject@Base @VER@ + PyWeakref_NewProxy@Base @VER@ + PyWeakref_NewRef@Base @VER@ + PyWrapperDescr_Type@Base @VER@ + PyWrapper_New@Base @VER@ + Py_AddPendingCall@Base @VER@ + Py_AtExit@Base @VER@ + Py_BuildValue@Base @VER@ + Py_BytesWarningFlag@Base @VER@ + Py_CompileString@Base @VER@ + Py_CompileStringFlags@Base @VER@ + Py_DebugFlag@Base @VER@ + Py_DecRef@Base @VER@ + Py_DivisionWarningFlag@Base @VER@ + Py_DontWriteBytecodeFlag@Base @VER@ + Py_EndInterpreter@Base @VER@ + Py_Exit@Base @VER@ + Py_FatalError@Base @VER@ + Py_FdIsInteractive@Base @VER@ + Py_FileSystemDefaultEncoding@Base @VER@ + Py_Finalize@Base @VER@ + Py_FindMethod@Base @VER@ + Py_FindMethodInChain@Base @VER@ + Py_FlushLine@Base @VER@ + Py_FrozenFlag@Base @VER@ + Py_FrozenMain@Base @VER@ + Py_GetArgcArgv@Base @VER@ + Py_GetBuildInfo@Base @VER@ + Py_GetCompiler@Base @VER@ + Py_GetCopyright@Base @VER@ + Py_GetExecPrefix@Base @VER@ + Py_GetPath@Base @VER@ + Py_GetPlatform@Base @VER@ + Py_GetPrefix@Base @VER@ + Py_GetProgramFullPath@Base @VER@ + Py_GetProgramName@Base @VER@ + Py_GetPythonHome@Base @VER@ + Py_GetRecursionLimit@Base @VER@ + Py_GetVersion@Base @VER@ + Py_IgnoreEnvironmentFlag@Base @VER@ + Py_IncRef@Base @VER@ + Py_Initialize@Base @VER@ + Py_InitializeEx@Base @VER@ + Py_InspectFlag@Base @VER@ + Py_InteractiveFlag@Base @VER@ + Py_IsInitialized@Base @VER@ + Py_Main@Base @VER@ + Py_MakePendingCalls@Base @VER@ + Py_NewInterpreter@Base @VER@ + Py_NoSiteFlag@Base @VER@ + Py_NoUserSiteDirectory@Base @VER@ + Py_OptimizeFlag@Base @VER@ + Py_Py3kWarningFlag@Base @VER@ + Py_ReprEnter@Base @VER@ + Py_ReprLeave@Base @VER@ + Py_SetProgramName@Base @VER@ + Py_SetPythonHome@Base @VER@ + Py_SetRecursionLimit@Base @VER@ + Py_SubversionRevision@Base @VER@ + Py_SubversionShortBranch@Base @VER@ + Py_SymtableString@Base @VER@ + Py_TabcheckFlag@Base @VER@ + Py_UnicodeFlag@Base @VER@ + Py_UniversalNewlineFgets@Base @VER@ + Py_UniversalNewlineFread@Base @VER@ + Py_UseClassExceptionsFlag@Base @VER@ + Py_VaBuildValue@Base @VER@ + Py_VerboseFlag@Base @VER@ + Py_meta_grammar@Base @VER@ + Py_pgen@Base @VER@ + _PyArg_NoKeywords@Base @VER@ + _PyArg_ParseTupleAndKeywords_SizeT@Base @VER@ + _PyArg_ParseTuple_SizeT@Base @VER@ + _PyArg_Parse_SizeT@Base @VER@ + _PyArg_VaParseTupleAndKeywords_SizeT@Base @VER@ + _PyArg_VaParse_SizeT@Base @VER@ + _PyBuiltin_Init@Base @VER@ + _PyByteArray_empty_string@Base @VER@ + _PyBytes_FormatAdvanced@Base @VER@ + _PyCode_CheckLineNumber@Base @VER@ + _PyCodec_Lookup@Base @VER@ + _PyComplex_FormatAdvanced@Base @VER@ + _PyDict_Contains@Base @VER@ + _PyDict_MaybeUntrack@Base @VER@ + _PyDict_NewPresized@Base @VER@ + _PyDict_Next@Base @VER@ + _PyErr_BadInternalCall@Base @VER@ + _PyEval_CallTracing@Base @VER@ + _PyEval_SliceIndex@Base @VER@ + _PyExc_Fini@Base @VER@ + _PyExc_Init@Base @VER@ + _PyFile_SanitizeMode@Base @VER@ + _PyFloat_FormatAdvanced@Base @VER@ + _PyFloat_Init@Base @VER@ + _PyFloat_Pack4@Base @VER@ + _PyFloat_Pack8@Base @VER@ + _PyFloat_Unpack4@Base @VER@ + _PyFloat_Unpack8@Base @VER@ + _PyFrame_Init@Base @VER@ + _PyGC_Dump@Base @VER@ + _PyGC_generation0@Base @VER@ + _PyGILState_Fini@Base @VER@ + _PyGILState_Init@Base @VER@ + _PyImportHooks_Init@Base @VER@ + _PyImport_AcquireLock@Base @VER@ + _PyImport_DynLoadFiletab@Base @VER@ + _PyImport_Filetab@Base @VER@ + _PyImport_FindExtension@Base @VER@ + _PyImport_FindModule@Base @VER@ + _PyImport_Fini@Base @VER@ + _PyImport_FixupExtension@Base @VER@ + _PyImport_GetDynLoadFunc@Base @VER@ + _PyImport_Init@Base @VER@ + _PyImport_Inittab@Base @VER@ + _PyImport_IsScript@Base @VER@ + _PyImport_LoadDynamicModule@Base @VER@ + _PyImport_ReleaseLock@Base @VER@ + _PyImport_ReInitLock@Base @VER@ + _PyInstance_Lookup@Base @VER@ + _PyInt_Format@Base @VER@ + _PyInt_FormatAdvanced@Base @VER@ + _PyInt_Init@Base @VER@ + _PyList_Extend@Base @VER@ + _PyLong_AsByteArray@Base @VER@ + _PyLong_Copy@Base @VER@ + _PyLong_DigitValue@Base @VER@ + _PyLong_Format@Base @VER@ + _PyLong_FormatAdvanced@Base @VER@ + _PyLong_Frexp@Base @VER@ + _PyLong_FromByteArray@Base @VER@ + _PyLong_Init@Base @VER@ + _PyLong_New@Base @VER@ + _PyLong_NumBits@Base @VER@ + _PyLong_Sign@Base @VER@ + _PyModule_Clear@Base @VER@ + _PyNumber_ConvertIntegralToInt@Base @VER@ + _PyOS_GetOpt@Base @VER@ + _PyOS_ReadlineTState@Base @VER@ + _PyOS_ascii_formatd@Base @VER@ + _PyOS_ascii_strtod@Base @VER@ + _PyOS_optarg@Base @VER@ + _PyOS_opterr@Base @VER@ + _PyOS_optind@Base @VER@ + _PyObject_CallFunction_SizeT@Base @VER@ + _PyObject_CallMethod_SizeT@Base @VER@ + _PyObject_Del@Base @VER@ + _PyObject_Dump@Base @VER@ + _PyObject_GC_Del@Base @VER@ + _PyObject_GC_Malloc@Base @VER@ + _PyObject_GC_New@Base @VER@ + _PyObject_GC_NewVar@Base @VER@ + _PyObject_GC_Resize@Base @VER@ + _PyObject_GC_Track@Base @VER@ + _PyObject_GC_UnTrack@Base @VER@ + _PyObject_GenericGetAttrWithDict@Base @VER@ + _PyObject_GenericSetAttrWithDict@Base @VER@ + _PyObject_GetDictPtr@Base @VER@ + _PyObject_LengthHint@Base @VER@ + _PyObject_LookupSpecial@Base @VER@ + _PyObject_New@Base @VER@ + _PyObject_NewVar@Base @VER@ + _PyObject_NextNotImplemented@Base @VER@ + _PyObject_RealIsInstance@Base @VER@ + _PyObject_RealIsSubclass@Base @VER@ + _PyObject_SlotCompare@Base @VER@ + _PyObject_Str@Base @VER@ + _PyParser_Grammar@Base @VER@ + _PyParser_TokenNames@Base @VER@ + _PySequence_IterSearch@Base @VER@ + _PySet_Next@Base @VER@ + _PySet_NextEntry@Base @VER@ + _PySet_Update@Base @VER@ + _PySlice_FromIndices@Base @VER@ + _PyString_Eq@Base @VER@ + _PyString_FormatLong@Base @VER@ + _PyString_InsertThousandsGrouping@Base @VER@ + _PyString_Join@Base @VER@ + _PyString_Resize@Base @VER@ + _PySys_Init@Base @VER@ + _PyThreadState_Current@Base @VER@ + _PyThreadState_GetFrame@Base @VER@ + _PyThreadState_Init@Base @VER@ + _PyThreadState_Prealloc@Base @VER@ + _PyThread_CurrentFrames@Base @VER@ + _PyTime_DoubleToTimet@Base @VER@ + _PyTrash_delete_later@Base @VER@ + _PyTrash_delete_nesting@Base @VER@ + _PyTrash_deposit_object@Base @VER@ + _PyTrash_destroy_chain@Base @VER@ + _PyTuple_MaybeUntrack@Base @VER@ + _PyTuple_Resize@Base @VER@ + _PyType_Lookup@Base @VER@ + _PyUnicodeUCS4_AsDefaultEncodedString@Base @VER@ + _PyUnicodeUCS4_Fini@Base @VER@ + _PyUnicodeUCS4_Init@Base @VER@ + _PyUnicodeUCS4_IsAlpha@Base @VER@ + _PyUnicodeUCS4_IsDecimalDigit@Base @VER@ + _PyUnicodeUCS4_IsDigit@Base @VER@ + _PyUnicodeUCS4_IsLinebreak@Base @VER@ + _PyUnicodeUCS4_IsLowercase@Base @VER@ + _PyUnicodeUCS4_IsNumeric@Base @VER@ + _PyUnicodeUCS4_IsTitlecase@Base @VER@ + _PyUnicodeUCS4_IsUppercase@Base @VER@ + _PyUnicodeUCS4_IsWhitespace@Base @VER@ + _PyUnicodeUCS4_ToDecimalDigit@Base @VER@ + _PyUnicodeUCS4_ToDigit@Base @VER@ + _PyUnicodeUCS4_ToLowercase@Base @VER@ + _PyUnicodeUCS4_ToNumeric@Base @VER@ + _PyUnicodeUCS4_ToTitlecase@Base @VER@ + _PyUnicodeUCS4_ToUppercase@Base @VER@ + _PyUnicode_BidirectionalNames@Base @VER@ + _PyUnicode_CategoryNames@Base @VER@ + _PyUnicode_Database_Records@Base @VER@ + _PyUnicode_DecodeUnicodeInternal@Base @VER@ + _PyUnicode_EastAsianWidthNames@Base @VER@ + _PyUnicode_FormatAdvanced@Base @VER@ + _PyUnicode_TypeRecords@Base @VER@ + _PyUnicode_XStrip@Base @VER@ + _PyWarnings_Init@Base @VER@ + _PyWeakref_CallableProxyType@Base @VER@ + _PyWeakref_ClearRef@Base @VER@ + _PyWeakref_GetWeakrefCount@Base @VER@ + _PyWeakref_ProxyType@Base @VER@ + _PyWeakref_RefType@Base @VER@ + _Py_Assert@Base @VER@ + _Py_Assign@Base @VER@ + _Py_Attribute@Base @VER@ + _Py_AugAssign@Base @VER@ + _Py_BinOp@Base @VER@ + _Py_BoolOp@Base @VER@ + _Py_Break@Base @VER@ + _Py_BuildValue_SizeT@Base @VER@ + _Py_Call@Base @VER@ + _Py_CheckInterval@Base @VER@ + _Py_CheckRecursionLimit@Base @VER@ + _Py_CheckRecursiveCall@Base @VER@ + _Py_ClassDef@Base @VER@ + _Py_Compare@Base @VER@ + _Py_Continue@Base @VER@ + _Py_Delete@Base @VER@ + _Py_Dict@Base @VER@ + _Py_DictComp@Base @VER@ + _Py_DisplaySourceLine@Base @VER@ + _Py_Ellipsis@Base @VER@ + _Py_EllipsisObject@Base @VER@ + _Py_ExceptHandler@Base @VER@ + _Py_Exec@Base @VER@ + _Py_Expr@Base @VER@ + _Py_Expression@Base @VER@ + _Py_ExtSlice@Base @VER@ + _Py_For@Base @VER@ + _Py_FunctionDef@Base @VER@ + _Py_GeneratorExp@Base @VER@ + _Py_Global@Base @VER@ + _Py_HashDouble@Base @VER@ + _Py_HashPointer@Base @VER@ + _Py_If@Base @VER@ + _Py_IfExp@Base @VER@ + _Py_Import@Base @VER@ + _Py_ImportFrom@Base @VER@ + _Py_Index@Base @VER@ + _Py_InsertThousandsGroupingLocale@Base @VER@ + _Py_Interactive@Base @VER@ + _Py_Lambda@Base @VER@ + _Py_List@Base @VER@ + _Py_ListComp@Base @VER@ + _Py_Mangle@Base @VER@ + _Py_Module@Base @VER@ + _Py_Name@Base @VER@ + _Py_NoneStruct@Base @VER@ + _Py_NotImplementedStruct@Base @VER@ + _Py_Num@Base @VER@ + _Py_PackageContext@Base @VER@ + _Py_Pass@Base @VER@ + _Py_Print@Base @VER@ + _Py_QnewFlag@Base @VER@ + _Py_Raise@Base @VER@ + _Py_ReadyTypes@Base @VER@ + _Py_ReleaseInternedStrings@Base @VER@ + _Py_Repr@Base @VER@ + _Py_Return@Base @VER@ + _Py_Set@Base @VER@ + _Py_SetComp@Base @VER@ + _Py_Slice@Base @VER@ + _Py_Str@Base @VER@ + _Py_Subscript@Base @VER@ + _Py_Suite@Base @VER@ + _Py_SwappedOp@Base @VER@ + _Py_Ticker@Base @VER@ + _Py_TrueStruct@Base @VER@ + _Py_TryExcept@Base @VER@ + _Py_TryFinally@Base @VER@ + _Py_Tuple@Base @VER@ + _Py_UnaryOp@Base @VER@ + _Py_VaBuildValue_SizeT@Base @VER@ + _Py_While@Base @VER@ + _Py_With@Base @VER@ + _Py_Yield@Base @VER@ + _Py_ZeroStruct@Base @VER@ + _Py_abstract_hack@Base @VER@ + _Py_add_one_to_index_C@Base @VER@ + _Py_add_one_to_index_F@Base @VER@ + (optional)_Py_acosh@Base @VER@ + _Py_addarc@Base @VER@ + _Py_addbit@Base @VER@ + _Py_adddfa@Base @VER@ + _Py_addfirstsets@Base @VER@ + _Py_addlabel@Base @VER@ + _Py_addstate@Base @VER@ + _Py_alias@Base @VER@ + _Py_arguments@Base @VER@ + _Py_ascii_whitespace@Base @VER@ + (optional)_Py_asinh@Base @VER@ + (optional)_Py_atanh@Base @VER@ + _Py_bytes_capitalize@Base @VER@ + _Py_bytes_isalnum@Base @VER@ + _Py_bytes_isalpha@Base @VER@ + _Py_bytes_isdigit@Base @VER@ + _Py_bytes_islower@Base @VER@ + _Py_bytes_isspace@Base @VER@ + _Py_bytes_istitle@Base @VER@ + _Py_bytes_isupper@Base @VER@ + _Py_bytes_lower@Base @VER@ + _Py_bytes_swapcase@Base @VER@ + _Py_bytes_title@Base @VER@ + _Py_bytes_upper@Base @VER@ + _Py_c_abs@Base @VER@ + _Py_c_diff@Base @VER@ + _Py_c_neg@Base @VER@ + _Py_c_pow@Base @VER@ + _Py_c_prod@Base @VER@ + _Py_c_quot@Base @VER@ + _Py_c_sum@Base @VER@ + _Py_capitalize__doc__@Base @VER@ + _Py_capsule_hack@Base @VER@ + _Py_cobject_hack@Base @VER@ + _Py_comprehension@Base @VER@ + _Py_ctype_table@Base @VER@ + _Py_ctype_tolower@Base @VER@ + _Py_ctype_toupper@Base @VER@ + _Py_delbitset@Base @VER@ + _Py_dg_dtoa@Base @VER@ + _Py_dg_freedtoa@Base @VER@ + _Py_dg_strtod@Base @VER@ + _Py_double_round@Base @VER@ + (optional)_Py_expm1@Base @VER@ + _Py_findlabel@Base @VER@ + (arch=i386 lpia)_Py_force_double@Base @VER@ + (arch=amd64 i386 lpia)_Py_get_387controlword@Base @VER@ + _Py_isalnum__doc__@Base @VER@ + _Py_isalpha__doc__@Base @VER@ + _Py_isdigit__doc__@Base @VER@ + _Py_islower__doc__@Base @VER@ + _Py_isspace__doc__@Base @VER@ + _Py_istitle__doc__@Base @VER@ + _Py_isupper__doc__@Base @VER@ + _Py_keyword@Base @VER@ + (optional)_Py_log1p@Base @VER@ + _Py_lower__doc__@Base @VER@ + _Py_mergebitset@Base @VER@ + _Py_meta_grammar@Base @VER@ + _Py_newbitset@Base @VER@ + _Py_newgrammar@Base @VER@ + (optional)_Py_parse_inf_or_nan@Base @VER@ + _Py_pgen@Base @VER@ + _Py_samebitset@Base @VER@ + (arch=amd64 i386 lpia)_Py_set_387controlword@Base @VER@ + _Py_svnversion@Base @VER@ + _Py_swapcase__doc__@Base @VER@ + _Py_title__doc__@Base @VER@ + _Py_translatelabels@Base @VER@ + _Py_upper__doc__@Base @VER@ + + PyFPE_counter@Base @VER@ + PyFPE_dummy@Base @VER@ + PyFPE_jbuf@Base @VER@ + + asdl_int_seq_new@Base @VER@ + asdl_seq_new@Base @VER@ + +# don't check for the following symbols, found in extensions +# which either can be built as builtin or extension. + + (optional)fast_save_leave@Base @VER@ + (optional)partial_reduce@Base @VER@ + (optional)partial_setstate@Base @VER@ + +# _check_for_multiple_distdirs@Base @VER@ + (optional)init_ast@Base @VER@ + (optional)init_bisect@Base @VER@ + (optional)init_codecs@Base @VER@ + (optional)init_collections@Base @VER@ + (optional)init_functools@Base @VER@ + (optional)init_hashlib@Base @VER@ + (optional)init_locale@Base @VER@ + (optional)init_random@Base @VER@ + (optional)init_socket@Base @VER@ + (optional)init_sockobject@Base @VER@ + (optional)init_sre@Base @VER@ + (optional)init_ssl@Base @VER@ + (optional)init_struct@Base @VER@ + (optional)init_symtable@Base @VER@ + (optional)init_weakref@Base @VER@ + (optional)initarray@Base @VER@ + (optional)initbinascii@Base @VER@ + (optional)initcPickle@Base @VER@ + (optional)initcStringIO@Base @VER@ + (optional)initcmath@Base @VER@ + (optional)initerrno@Base @VER@ + (optional)initfcntl@Base @VER@ + (optional)initgc@Base @VER@ + (optional)initgrp@Base @VER@ + (optional)initimp@Base @VER@ + (optional)inititertools@Base @VER@ + (optional)initmath@Base @VER@ + (optional)initoperator@Base @VER@ + (optional)initposix@Base @VER@ + (optional)initpwd@Base @VER@ + (optional)initselect@Base @VER@ + (optional)initsignal@Base @VER@ + (optional)initspwd@Base @VER@ + (optional)initstrop@Base @VER@ + (optional)initsyslog@Base @VER@ + (optional)initthread@Base @VER@ + (optional)inittime@Base @VER@ + (optional)initunicodedata@Base @VER@ + (optional)initxxsubtype@Base @VER@ + (optional)initzipimport@Base @VER@ + (optional)initzlib@Base @VER@ --- python2.7-2.7.orig/debian/PVER-minimal.postinst.in +++ python2.7-2.7/debian/PVER-minimal.postinst.in @@ -0,0 +1,76 @@ +#! /bin/sh + +set -e + +if [ ! -f /etc/@PVER@/sitecustomize.py ]; then + cat <<-EOF + # Empty sitecustomize.py to avoid a dangling symlink +EOF +fi + +syssite=/usr/lib/@PVER@/site-packages +localsite=/usr/local/lib/@PVER@/dist-packages +syslink=../../${localsite#/usr/*} + +case "$1" in + configure) + # Create empty directories in /usr/local + if [ ! -e /usr/local/lib/@PVER@ ]; then + mkdir -p /usr/local/lib/@PVER@ 2> /dev/null || true + chmod 2775 /usr/local/lib/@PVER@ 2> /dev/null || true + chown root:staff /usr/local/lib/@PVER@ 2> /dev/null || true + fi + if [ ! -e $localsite ]; then + mkdir -p $localsite 2> /dev/null || true + chmod 2775 $localsite 2> /dev/null || true + chown root:staff $localsite 2> /dev/null || true + fi + #if [ ! -h $syssite ]; then + # ln -s $syslink $syssite + #fi + + if which update-binfmts >/dev/null; then + update-binfmts --import @PVER@ + fi + + ;; +esac + +if [ "$1" = configure ]; then + ( + files=$(dpkg -L @PVER@-minimal | sed -n '/^\/usr\/lib\/@PVER@\/.*\.py$/p') + @PVER@ /usr/lib/@PVER@/py_compile.py $files + if grep -sq '^byte-compile[^#]*optimize' /etc/python/debian_config; then + @PVER@ -O /usr/lib/@PVER@/py_compile.py $files + fi + ) + bc=no + if [ -z "$2" ] || dpkg --compare-versions "$2" lt 2.7-9 \ + || [ -f /var/lib/python/@PVER@_installed ]; then + bc=yes + fi + if grep -sq '^unsupported-versions[^#]*@PVER@' /usr/share/python/debian_defaults + then + # FIXME: byte compile anyway? + bc=no + fi + if [ "$bc" = yes ]; then + # new installation or installation of first version with hook support + if [ "$DEBIAN_FRONTEND" != noninteractive ]; then + echo "Linking and byte-compiling packages for runtime @PVER@..." + fi + version=$(dpkg -s @PVER@-minimal | awk '/^Version:/ {print $2}') + for hook in /usr/share/python/runtime.d/*.rtinstall; do + [ -x $hook ] || continue + $hook rtinstall @PVER@ "$2" "$version" + done + if [ -f /var/lib/python/@PVER@_installed ]; then + rm -f /var/lib/python/@PVER@_installed + rmdir --ignore-fail-on-non-empty /var/lib/python 2>/dev/null + fi + fi +fi + +#DEBHELPER# + +exit 0 --- python2.7-2.7.orig/debian/control +++ python2.7-2.7/debian/control @@ -0,0 +1,114 @@ +Source: python2.7 +Section: python +Priority: optional +Maintainer: Ubuntu Core Developers +XSBC-Original-Maintainer: Matthias Klose +Build-Depends: debhelper (>= 5), quilt, autoconf, libreadline-dev, libncursesw5-dev (>= 5.3), tk8.5-dev, zlib1g-dev, blt-dev (>= 2.4z), libssl-dev, libexpat1-dev, sharutils, libbz2-dev, libbluetooth-dev [!hurd-i386 !kfreebsd-i386 !kfreebsd-amd64], locales [!armel !avr32 !hppa !ia64 !mipsel], libsqlite3-dev, libffi-dev (>= 3.0.5), mime-support, libgpm2 [!hurd-i386 !kfreebsd-i386 !kfreebsd-amd64], netbase, lsb-release, bzip2, libdb4.8-dev, gdb, python +Build-Depends-Indep: python-sphinx +Build-Conflicts: tcl8.3-dev, tk8.3-dev, tcl8.4-dev, tk8.4-dev, python2.7-xml, python-xml, autoconf2.13 +XS-Python-Version: 2.7 +Standards-Version: 3.9.1 +Vcs-Browser: https://code.launchpad.net/~doko/python/pkg2.7-debian +Vcs-Bzr: http://bazaar.launchpad.net/~doko/python/pkg2.7-debian + +Package: python2.7 +Architecture: any +Priority: optional +Depends: python2.7-minimal (= ${binary:Version}), mime-support, ${shlibs:Depends}, ${misc:Depends} +Suggests: python2.7-doc, python2.7-profiler, binutils +Provides: python2.7-cjkcodecs, python2.7-ctypes, python2.7-elementtree, python2.7-celementtree, python2.7-wsgiref +XB-Python-Version: 2.7 +Description: An interactive high-level object-oriented language (version 2.7) + Version 2.7 of the high-level, interactive object oriented language, + includes an extensive class library with lots of goodies for + network programming, system administration, sounds and graphics. + +Package: python2.7-minimal +Architecture: any +Priority: optional +Depends: ${shlibs:Depends}, ${misc:Depends} +Recommends: python2.7 +Suggests: binfmt-support +Replaces: python2.7 (<< 2.7~rc2-3) +Conflicts: binfmt-support (<< 1.1.2) +XB-Python-Runtime: python2.7 +XB-Python-Version: 2.7 +Description: A minimal subset of the Python language (version 2.7) + This package contains the interpreter and some essential modules. It can + be used in the boot process for some basic tasks. + See /usr/share/doc/python2.7-minimal/README.Debian for a list of the modules + contained in this package. + +Package: libpython2.7 +Architecture: any +Section: libs +Priority: optional +Depends: python2.7 (= ${binary:Version}), ${shlibs:Depends}, ${misc:Depends} +Replaces: python2.7 (<< 2.6) +Description: Shared Python runtime library (version 2.7) + Version 2.7 of the high-level, interactive object oriented language, + includes an extensive class library with lots of goodies for + network programming, system administration, sounds and graphics. + . + This package contains the shared runtime library, normally not needed + for programs using the statically linked interpreter. + +Package: python2.7-examples +Architecture: all +Depends: python2.7 (>= ${source:Version}), ${misc:Depends} +Description: Examples for the Python language (v2.7) + Examples, Demos and Tools for Python (v2.7). These are files included in + the upstream Python distribution (v2.7). + +Package: python2.7-dev +Architecture: any +Depends: python2.7 (= ${binary:Version}), libpython2.7 (= ${binary:Version}), libexpat1-dev, libssl-dev, ${shlibs:Depends}, ${misc:Depends} +Recommends: libc6-dev | libc-dev +Replaces: python2.7 (<< 2.7-3) +Description: Header files and a static library for Python (v2.7) + Header files, a static library and development tools for building + Python (v2.7) modules, extending the Python interpreter or embedding + Python (v2.7) in applications. + . + Maintainers of Python packages should read README.maintainers. + +Package: idle-python2.7 +Architecture: all +Depends: python2.7, python-tk (>= 2.6~a3), python2.7-tk, ${misc:Depends} +Enhances: python2.7 +Replaces: python2.7 (<< 2.6.1-2) +XB-Python-Version: 2.7 +Description: An IDE for Python (v2.7) using Tkinter + IDLE is an Integrated Development Environment for Python (v2.7). + IDLE is written using Tkinter and therefore quite platform-independent. + +Package: python2.7-doc +Section: doc +Architecture: all +Depends: libjs-jquery, ${misc:Depends} +Suggests: python2.7 +Description: Documentation for the high-level object-oriented language Python (v2.7) + These is the official set of documentation for the interactive high-level + object-oriented language Python (v2.7). All documents are provided + in HTML format. The package consists of ten documents: + . + * What's New in Python2.7 + * Tutorial + * Python Library Reference + * Macintosh Module Reference + * Python Language Reference + * Extending and Embedding Python + * Python/C API Reference + * Installing Python Modules + * Documenting Python + * Distributing Python Modules + +Package: python2.7-dbg +Section: debug +Architecture: any +Priority: extra +Depends: python2.7 (>= ${binary:Version}), ${shlibs:Depends}, ${misc:Depends} +Suggests: python-gdbm-dbg, python-tk-dbg +Description: Debug Build of the Python Interpreter (version 2.7) + Python interpreter configured with --pydebug. Dynamically loaded modules are + searched in /usr/lib/python2.7/lib-dynload/debug first. --- python2.7-2.7.orig/debian/PVER-doc.overrides.in +++ python2.7-2.7/debian/PVER-doc.overrides.in @@ -0,0 +1,2 @@ +# this is referenced by the html docs +@PVER@-doc binary: extra-license-file --- python2.7-2.7.orig/debian/README.dbm +++ python2.7-2.7/debian/README.dbm @@ -0,0 +1,72 @@ + + Python and dbm modules on Debian + -------------------------------- + +This file documents the configuration of the dbm modules for Debian. It +gives hints at the preferred use of the dbm modules. + + +The preferred way to access dbm databases in Python is the anydbm module. +dbm databases behave like mappings (dictionaries). + +Since there exist several dbm database formats, we choose the following +layout for Python on Debian: + + * creating a new database with anydbm will create a Berkeley DB 2.X Hash + database file. This is the standard format used by libdb starting + with glibc 2.1. + + * opening an existing database with anydbm will try to guess the format + of the file (using whichdb) and then load it using one of the bsddb, + bsddb1, gdbm or dbm (only if the python-gdbm package is installed) + or dumbdbm modules. + + * The modules use the following database formats: + + - bsddb: Berkeley DB 2.X Hash (as in libc6 >=2.1 or libdb2) + - bsddb1: Berkeley DB 1.85 Hash (as in libc6 >=2.1 or libdb2) + - gdbm: GNU dbm 1.x or ndbm + - dbm: " (nearly the same as the gdbm module for us) + - dumbdbm: a hand-crafted format only used in this module + + That means that all usual formats should be readable with anydbm. + + * If you want to create a database in a format different from DB 2.X, + you can still directly use the specified module. + + * I.e. bsddb is the preferred module, and DB 2.X is the preferred format. + + * Note that the db1hash and bsddb1 modules are Debian specific. anydbm + and whichdb have been modified to support DB 2.X Hash files (see + below for details). + + + +For experts only: +---------------- + +Although bsddb employs the new DB 2.X format and uses the new Sleepycat +DB 2 library as included with glibc >= 2.1, it's still using the old +DB 1.85 API (which is still supported by DB 2). + +A more recent version 1.1 of the BSD DB module (available from +http://starship.skyport.net/robind/python/) directly uses the DB 2.X API. +It has a richer set of features. + + +On a glibc 2.1 system, bsddb is linked with -ldb, bsddb1 is linked with +-ldb1 and gdbm as well as dbm are linked with -lgdbm. + +On a glibc 2.0 system (e.g. potato for m68k or slink), bsddb will be +linked with -ldb2 while bsddb1 will be linked with -ldb (therefore +python-base here depends on libdb2). + + +db1hash and bsddb1 nearly completely identical to dbhash and bsddb. The +only difference is that bsddb is linked with the real DB 2 library, while +bsddb1 is linked with an library which provides compatibility with legacy +DB 1.85 databases. + + + July 16, 1999 + Gregor Hoffleit --- python2.7-2.7.orig/debian/PVER-dbg.symbols.in +++ python2.7-2.7/debian/PVER-dbg.symbols.in @@ -0,0 +1,32 @@ +libpython@VER@_d.so.1.0 python@VER@-dbg #MINVER# + Py_InitModule4TraceRefs@Base @VER@ +#include "libpython.symbols" + _PyDict_Dummy@Base @VER@ + _PyMem_DebugFree@Base @VER@ + _PyMem_DebugMalloc@Base @VER@ + _PyMem_DebugRealloc@Base @VER@ + _PyObject_DebugCheckAddress@Base @VER@ + _PyObject_DebugCheckAddressApi@Base @VER@ + _PyObject_DebugDumpAddress@Base @VER@ + _PyObject_DebugFree@Base @VER@ + _PyObject_DebugFreeApi@Base @VER@ + _PyObject_DebugMalloc@Base @VER@ + _PyObject_DebugMallocApi@Base @VER@ + _PyObject_DebugMallocStats@Base @VER@ + _PyObject_DebugRealloc@Base @VER@ + _PyObject_DebugReallocApi@Base @VER@ + _PySet_Dummy@Base @VER@ + _Py_AddToAllObjects@Base @VER@ + _Py_Dealloc@Base @VER@ + _Py_ForgetReference@Base @VER@ + _Py_GetObjects@Base @VER@ + _Py_GetRefTotal@Base @VER@ + _Py_NegativeRefcount@Base @VER@ + _Py_NewReference@Base @VER@ + _Py_PrintReferenceAddresses@Base @VER@ + _Py_PrintReferences@Base @VER@ + _Py_RefTotal@Base @VER@ + _Py_dumptree@Base @VER@ + _Py_printtree@Base @VER@ + _Py_showtree@Base @VER@ + _Py_tok_dump@Base @VER@ --- python2.7-2.7.orig/debian/PVER-doc.doc-base.PVER-tut.in +++ python2.7-2.7/debian/PVER-doc.doc-base.PVER-tut.in @@ -0,0 +1,13 @@ +Document: @PVER@-tut +Title: Python Tutorial (v@VER@) +Author: Guido van Rossum, Fred L. Drake, Jr., editor +Abstract: This tutorial introduces the reader informally to the basic + concepts and features of the Python language and system. It helps + to have a Python interpreter handy for hands-on experience, but + all examples are self-contained, so the tutorial can be read + off-line as well. +Section: Programming/Python + +Format: HTML +Index: /usr/share/doc/@PVER@/html/tutorial/index.html +Files: /usr/share/doc/@PVER@/html/tutorial/*.html --- python2.7-2.7.orig/debian/changelog.shared +++ python2.7-2.7/debian/changelog.shared @@ -0,0 +1,3 @@ + * Link the interpreter against the shared runtime library. With + gcc-4.1 the difference in the pystones benchmark dropped from about + 12% to about 5%. --- python2.7-2.7.orig/debian/PVER-doc.doc-base.PVER-inst.in +++ python2.7-2.7/debian/PVER-doc.doc-base.PVER-inst.in @@ -0,0 +1,12 @@ +Document: @PVER@-inst +Title: Installing Python Modules (v@VER@) +Author: Greg Ward +Abstract: This document describes the Python Distribution Utilities + (``Distutils'') from the end-user's point-of-view, describing how to + extend the capabilities of a standard Python installation by building + and installing third-party Python modules and extensions. +Section: Programming/Python + +Format: HTML +Index: /usr/share/doc/@PVER@/html/install/index.html +Files: /usr/share/doc/@PVER@/html/install/*.html --- python2.7-2.7.orig/debian/patches/tkinter-import.diff +++ python2.7-2.7/debian/patches/tkinter-import.diff @@ -0,0 +1,16 @@ +# DP: suggest installation of python-tk package on failing _tkinter import + +--- a/Lib/lib-tk/Tkinter.py ++++ b/Lib/lib-tk/Tkinter.py +@@ -36,7 +36,10 @@ + if sys.platform == "win32": + # Attempt to configure Tcl/Tk without requiring PATH + import FixTk +-import _tkinter # If this fails your Python may not be configured for Tk ++try: ++ import _tkinter ++except ImportError, msg: ++ raise ImportError, str(msg) + ', please install the python-tk package' + tkinter = _tkinter # b/w compat for export + TclError = _tkinter.TclError + from types import * --- python2.7-2.7.orig/debian/patches/distutils-install-layout.diff +++ python2.7-2.7/debian/patches/distutils-install-layout.diff @@ -0,0 +1,331 @@ +# DP: distutils: Add an option --install-layout=deb, which +# DP: - installs into $prefix/dist-packages instead of $prefix/site-packages. +# DP: - doesn't encode the python version into the egg name. + +--- a/Doc/install/index.rst ++++ b/Doc/install/index.rst +@@ -237,6 +237,8 @@ + +-----------------+-----------------------------------------------------+--------------------------------------------------+-------+ + | Platform | Standard installation location | Default value | Notes | + +=================+=====================================================+==================================================+=======+ ++| Debian/Ubuntu | :file:`{prefix}/lib/python{X.Y}/dist-packages` | :file:`/usr/local/lib/python{X.Y}/dist-packages` | \(0) | +++-----------------+-----------------------------------------------------+--------------------------------------------------+-------+ + | Unix (pure) | :file:`{prefix}/lib/python{X.Y}/site-packages` | :file:`/usr/local/lib/python{X.Y}/site-packages` | \(1) | + +-----------------+-----------------------------------------------------+--------------------------------------------------+-------+ + | Unix (non-pure) | :file:`{exec-prefix}/lib/python{X.Y}/site-packages` | :file:`/usr/local/lib/python{X.Y}/site-packages` | \(1) | +@@ -246,6 +248,14 @@ + + Notes: + ++(0) ++ Starting with Python-2.6 Debian/Ubuntu uses for the Python which comes within ++ the Linux distribution a non-default name for the installation directory. This ++ is to avoid overwriting of the python modules which come with the distribution, ++ which unfortunately is the upstream behaviour of the installation tools. The ++ non-default name in :file:`/usr/local` is used not to overwrite a local python ++ installation (defaulting to :file:`/usr/local`). ++ + (1) + Most Linux distributions include Python as a standard part of the system, so + :file:`{prefix}` and :file:`{exec-prefix}` are usually both :file:`/usr` on +@@ -367,6 +377,15 @@ + + /usr/bin/python setup.py install --prefix=/usr/local + ++Starting with Python-2.6 Debian/Ubuntu does use ++:file:`/usr/lib/python{X.Y}/dist-packages` and ++:file:`/usr/local/lib/python{X.Y}/dist-packages` for the installation ++of python modules included in the Linux distribution. To overwrite ++the name of the site directory, explicitely use the :option:`--prefix` ++option, however make sure that the installation path is included in ++``sys.path``. For packaging of python modules for Debian/Ubuntu, use ++the new ``setup.py install`` option :option:`--install-layout=deb`. ++ + Another possibility is a network filesystem where the name used to write to a + remote directory is different from the name used to read it: for example, the + Python interpreter accessed as :file:`/usr/local/bin/python` might search for +@@ -605,6 +624,17 @@ + import them, this directory must be added to ``sys.path``. There are several + different ways to add the directory. + ++On Debian/Ubuntu, starting with Python-2.6 the convention for system ++installed packages is to put then in the ++:file:`/usr/lib/python{X.Y}/dist-packages/` directory, and for locally ++installed packages is to put them in the ++:file:`/usr/lib/python{X.Y}/dist-packages/` directory. To share the ++locally installed packages for the system provided Python with the ++locally installed packages of a local python installation, make ++:file:`/usr/lib/python{X.Y}/dist-packages/` a symbolic link to the ++:file:`{...}/site-packages/` directory of your local python ++installation. ++ + The most convenient way is to add a path configuration file to a directory + that's already on Python's path, usually to the :file:`.../site-packages/` + directory. Path configuration files have an extension of :file:`.pth`, and each +--- a/Lib/distutils/command/install.py ++++ b/Lib/distutils/command/install.py +@@ -47,6 +47,20 @@ + 'scripts': '$base/bin', + 'data' : '$base', + }, ++ 'unix_local': { ++ 'purelib': '$base/local/lib/python$py_version_short/dist-packages', ++ 'platlib': '$platbase/local/lib/python$py_version_short/dist-packages', ++ 'headers': '$base/local/include/python$py_version_short/$dist_name', ++ 'scripts': '$base/local/bin', ++ 'data' : '$base/local', ++ }, ++ 'deb_system': { ++ 'purelib': '$base/lib/python$py_version_short/dist-packages', ++ 'platlib': '$platbase/lib/python$py_version_short/dist-packages', ++ 'headers': '$base/include/python$py_version_short/$dist_name', ++ 'scripts': '$base/bin', ++ 'data' : '$base', ++ }, + 'unix_home': { + 'purelib': '$base/lib/python', + 'platlib': '$base/lib/python', +@@ -154,6 +168,9 @@ + + ('record=', None, + "filename in which to record list of installed files"), ++ ++ ('install-layout=', None, ++ "installation layout to choose (known values: deb, unix)"), + ] + + boolean_options = ['compile', 'force', 'skip-build', 'user'] +@@ -168,6 +185,7 @@ + self.exec_prefix = None + self.home = None + self.user = 0 ++ self.prefix_option = None + + # These select only the installation base; it's up to the user to + # specify the installation scheme (currently, that means supplying +@@ -189,6 +207,9 @@ + self.install_userbase = USER_BASE + self.install_usersite = USER_SITE + ++ # enable custom installation, known values: deb ++ self.install_layout = None ++ + self.compile = None + self.optimize = None + +@@ -421,6 +442,7 @@ + self.install_base = self.install_platbase = self.home + self.select_scheme("unix_home") + else: ++ self.prefix_option = self.prefix + if self.prefix is None: + if self.exec_prefix is not None: + raise DistutilsOptionError, \ +@@ -435,7 +457,23 @@ + + self.install_base = self.prefix + self.install_platbase = self.exec_prefix +- self.select_scheme("unix_prefix") ++ if self.install_layout: ++ if self.install_layout.lower() in ['deb']: ++ self.select_scheme("deb_system") ++ elif self.install_layout.lower() in ['posix', 'unix']: ++ self.select_scheme("unix_prefix") ++ else: ++ raise DistutilsOptionError( ++ "unknown value for --install-layout") ++ elif (self.prefix_option and os.path.normpath(self.prefix) != '/usr/local') \ ++ or 'PYTHONUSERBASE' in os.environ \ ++ or 'real_prefix' in sys.__dict__: ++ self.select_scheme("unix_prefix") ++ else: ++ if os.path.normpath(self.prefix) == '/usr/local': ++ self.select_scheme("deb_system") ++ else: ++ self.select_scheme("unix_local") + + # finalize_unix () + +--- a/Lib/distutils/command/install_egg_info.py ++++ b/Lib/distutils/command/install_egg_info.py +@@ -14,18 +14,37 @@ + description = "Install package's PKG-INFO metadata as an .egg-info file" + user_options = [ + ('install-dir=', 'd', "directory to install to"), ++ ('install-layout', None, "custom installation layout"), + ] + + def initialize_options(self): + self.install_dir = None ++ self.install_layout = None ++ self.prefix_option = None + + def finalize_options(self): + self.set_undefined_options('install_lib',('install_dir','install_dir')) +- basename = "%s-%s-py%s.egg-info" % ( +- to_filename(safe_name(self.distribution.get_name())), +- to_filename(safe_version(self.distribution.get_version())), +- sys.version[:3] +- ) ++ self.set_undefined_options('install',('install_layout','install_layout')) ++ self.set_undefined_options('install',('prefix_option','prefix_option')) ++ if self.install_layout: ++ basename = "%s-%s.egg-info" % ( ++ to_filename(safe_name(self.distribution.get_name())), ++ to_filename(safe_version(self.distribution.get_version())) ++ ) ++ if not self.install_layout.lower() in ['deb']: ++ raise DistutilsOptionError( ++ "unknown value for --install-layout") ++ elif self.prefix_option or 'real_prefix' in sys.__dict__: ++ basename = "%s-%s-py%s.egg-info" % ( ++ to_filename(safe_name(self.distribution.get_name())), ++ to_filename(safe_version(self.distribution.get_version())), ++ sys.version[:3] ++ ) ++ else: ++ basename = "%s-%s.egg-info" % ( ++ to_filename(safe_name(self.distribution.get_name())), ++ to_filename(safe_version(self.distribution.get_version())) ++ ) + self.target = os.path.join(self.install_dir, basename) + self.outputs = [self.target] + +--- a/Lib/distutils/sysconfig.py ++++ b/Lib/distutils/sysconfig.py +@@ -110,6 +110,7 @@ + If 'prefix' is supplied, use it instead of sys.prefix or + sys.exec_prefix -- i.e., ignore 'plat_specific'. + """ ++ is_default_prefix = not prefix or os.path.normpath(prefix) in ('/usr', '/usr/local') + if prefix is None: + prefix = plat_specific and EXEC_PREFIX or PREFIX + +@@ -118,6 +119,8 @@ + "lib", "python" + get_python_version()) + if standard_lib: + return libpython ++ elif is_default_prefix and 'PYTHONUSERBASE' not in os.environ and 'real_prefix' not in sys.__dict__: ++ return os.path.join(libpython, "dist-packages") + else: + return os.path.join(libpython, "site-packages") + +--- a/Lib/site.py ++++ b/Lib/site.py +@@ -271,6 +271,13 @@ + + if ENABLE_USER_SITE and os.path.isdir(user_site): + addsitedir(user_site, known_paths) ++ if ENABLE_USER_SITE: ++ for dist_libdir in ("local/lib", "lib"): ++ user_site = os.path.join(USER_BASE, dist_libdir, ++ "python" + sys.version[:3], ++ "dist-packages") ++ if os.path.isdir(user_site): ++ addsitedir(user_site, known_paths) + return known_paths + + def getsitepackages(): +--- a/Lib/sysconfig.py ++++ b/Lib/sysconfig.py +@@ -16,6 +16,26 @@ + 'scripts': '{base}/bin', + 'data': '{base}', + }, ++ 'posix_local': { ++ 'stdlib': '{base}/local/lib/python{py_version_short}', ++ 'platstdlib': '{platbase}/local/lib/python{py_version_short}', ++ 'purelib': '{base}/local/lib/python{py_version_short}/dist-packages', ++ 'platlib': '{platbase}/local/lib/python{py_version_short}/dist-packages', ++ 'include': '{base}/local/include/python{py_version_short}', ++ 'platinclude': '{platbase}/local/include/python{py_version_short}', ++ 'scripts': '{base}/local/bin', ++ 'data': '{base}/local', ++ }, ++ 'deb_system': { ++ 'stdlib': '{base}/lib/python{py_version_short}', ++ 'platstdlib': '{platbase}/lib/python{py_version_short}', ++ 'purelib': '{base}/lib/python{py_version_short}/dist-packages', ++ 'platlib': '{platbase}/lib/python{py_version_short}/dist-packages', ++ 'include': '{base}/include/python{py_version_short}', ++ 'platinclude': '{platbase}/include/python{py_version_short}', ++ 'scripts': '{base}/bin', ++ 'data': '{base}', ++ }, + 'posix_home': { + 'stdlib': '{base}/lib/python', + 'platstdlib': '{base}/lib/python', +@@ -118,7 +138,7 @@ + _PYTHON_BUILD = is_python_build() + + if _PYTHON_BUILD: +- for scheme in ('posix_prefix', 'posix_home'): ++ for scheme in ('posix_prefix', 'posix_local', 'deb_system', 'posix_home'): + _INSTALL_SCHEMES[scheme]['include'] = '{projectbase}/Include' + _INSTALL_SCHEMES[scheme]['platinclude'] = '{srcdir}' + +@@ -152,8 +172,11 @@ + + def _get_default_scheme(): + if os.name == 'posix': +- # the default scheme for posix is posix_prefix +- return 'posix_prefix' ++ # the default scheme for posix on Debian/Ubuntu is posix_local ++ # FIXME: return dist-packages/posix_prefix only for ++ # is_default_prefix and 'PYTHONUSERBASE' not in os.environ and 'real_prefix' not in sys.__dict__ ++ # is_default_prefix = not prefix or os.path.normpath(prefix) in ('/usr', '/usr/local') ++ return 'posix_local' + return os.name + + def _getuserbase(): +@@ -259,7 +282,7 @@ + def _get_makefile_filename(): + if _PYTHON_BUILD: + return os.path.join(_PROJECT_BASE, "Makefile") +- return os.path.join(get_path('stdlib'), "config", "Makefile") ++ return os.path.join(get_path('stdlib').replace("/usr/local","/usr",1), "config", "Makefile") + + + def _init_posix(vars): +@@ -358,7 +381,7 @@ + else: + inc_dir = _PROJECT_BASE + else: +- inc_dir = get_path('platinclude') ++ inc_dir = get_path('platinclude').replace("/usr/local","/usr",1) + return os.path.join(inc_dir, 'pyconfig.h') + + def get_scheme_names(): +--- a/Lib/test/test_import.py ++++ b/Lib/test/test_import.py +@@ -245,7 +245,7 @@ + with check_warnings(('', ImportWarning)): + # Just a random non-package directory we always expect to be + # somewhere in sys.path... +- self.assertRaises(ImportError, __import__, "site-packages") ++ self.assertRaises(ImportError, __import__, "dist-packages") + + def test_import_by_filename(self): + path = os.path.abspath(TESTFN) +--- a/Lib/test/test_site.py ++++ b/Lib/test/test_site.py +@@ -171,7 +171,7 @@ + elif os.sep == '/': + self.assertTrue(len(dirs), 2) + wanted = os.path.join('xoxo', 'lib', 'python' + sys.version[:3], +- 'site-packages') ++ 'dist-packages') + self.assertEquals(dirs[0], wanted) + wanted = os.path.join('xoxo', 'lib', 'site-python') + self.assertEquals(dirs[1], wanted) +--- a/Lib/test/test_sysconfig.py ++++ b/Lib/test/test_sysconfig.py +@@ -236,7 +236,7 @@ + + def test_get_scheme_names(self): + wanted = ('nt', 'nt_user', 'os2', 'os2_home', 'osx_framework_user', +- 'posix_home', 'posix_prefix', 'posix_user') ++ 'posix_home', 'posix_prefix', 'posix_local', 'deb_system', 'posix_user') + self.assertEquals(get_scheme_names(), wanted) + + def test_symlink(self): --- python2.7-2.7.orig/debian/patches/subprocess-eintr-safety.dpatch +++ python2.7-2.7/debian/patches/subprocess-eintr-safety.dpatch @@ -0,0 +1,81 @@ +#! /bin/sh -e + +dir= +if [ $# -eq 3 -a "$2" = '-d' ]; then + pdir="-d $3" + dir="$3/" +elif [ $# -ne 1 ]; then + echo >&2 "usage: `basename $0`: -patch|-unpatch [-d ]" + exit 1 +fi +case "$1" in + -patch) + patch $pdir -f --no-backup-if-mismatch -p0 < $0 + #cd ${dir}gcc && autoconf + ;; + -unpatch) + patch $pdir -f --no-backup-if-mismatch -R -p0 < $0 + #rm ${dir}gcc/configure + ;; + *) + echo >&2 "usage: `basename $0`: -patch|-unpatch [-d ]" + exit 1 +esac +exit 0 + +--- Lib/test/test_subprocess.py 2007-03-14 19:16:36.000000000 +0100 ++++ Lib/test/test_subprocess.py 2007-03-14 19:18:57.000000000 +0100 +@@ -580,6 +578,34 @@ class ProcessTestCase(unittest.TestCase) + os.remove(fname) + self.assertEqual(rc, 47) + ++ def test_eintr(self): ++ # retries on EINTR for an argv ++ ++ # send ourselves a signal that causes EINTR ++ prev_handler = signal.signal(signal.SIGALRM, lambda x,y: 1) ++ signal.alarm(1) ++ time.sleep(0.5) ++ ++ rc = subprocess.Popen(['sleep', '1']) ++ self.assertEqual(rc.wait(), 0) ++ ++ signal.signal(signal.SIGALRM, prev_handler) ++ ++ def test_eintr_out(self): ++ # retries on EINTR for a shell call and pipelining ++ ++ # send ourselves a signal that causes EINTR ++ prev_handler = signal.signal(signal.SIGALRM, lambda x,y: 1) ++ signal.alarm(1) ++ time.sleep(0.5) ++ ++ rc = subprocess.Popen("sleep 1; echo hello", ++ shell=True, stdout=subprocess.PIPE) ++ out = rc.communicate()[0] ++ self.assertEqual(rc.returncode, 0) ++ self.assertEqual(out, "hello\n") ++ ++ signal.signal(signal.SIGALRM, prev_handler) + + # + # Windows tests +--- Lib/subprocess.py~ 2008-07-15 15:41:24.000000000 +0200 ++++ Lib/subprocess.py 2008-07-15 15:42:49.000000000 +0200 +@@ -657,13 +657,13 @@ + stderr = None + if self.stdin: + if input: +- self.stdin.write(input) ++ self._fo_write_no_intr(self.stdin, input) + self.stdin.close() + elif self.stdout: +- stdout = self.stdout.read() ++ stdout = self._fo_read_no_intr(self.stdout) + self.stdout.close() + elif self.stderr: +- stderr = self.stderr.read() ++ stderr = self._fo_read_no_intr(self.stderr) + self.stderr.close() + self.wait() + return (stdout, stderr) --- python2.7-2.7.orig/debian/patches/issue9054.diff +++ python2.7-2.7/debian/patches/issue9054.diff @@ -0,0 +1,14 @@ +# DP: Proposed fix for issue 9054. + +--- a/Modules/pyexpat.c (revision 81539) ++++ b/Modules/pyexpat.c (working copy) +@@ -415,6 +415,9 @@ + PyObject *args; + PyObject *temp; + ++ if (!have_handler(self, CharacterData)) ++ return -1; ++ + args = PyTuple_New(1); + if (args == NULL) + return -1; --- python2.7-2.7.orig/debian/patches/statvfs-f_flag-constants.diff +++ python2.7-2.7/debian/patches/statvfs-f_flag-constants.diff @@ -0,0 +1,57 @@ +From 21fda4c78000d78cb1824fdf0373031d07f5325a Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Wed, 6 Jan 2010 15:22:38 -0500 +Subject: [PATCH] Add flags for statvfs.f_flag to constant list. + +You really need these to figure out what statvfs is trying to say to +you, so add them here. +--- + Modules/posixmodule.c | 37 +++++++++++++++++++++++++++++++++++++ + 1 files changed, 37 insertions(+), 0 deletions(-) + +--- a/Modules/posixmodule.c ++++ b/Modules/posixmodule.c +@@ -9143,6 +9143,43 @@ + if (ins(d, "EX_NOTFOUND", (long)EX_NOTFOUND)) return -1; + #endif /* EX_NOTFOUND */ + ++ /* These came from statvfs.h */ ++#ifdef ST_RDONLY ++ if (ins(d, "ST_RDONLY", (long)ST_RDONLY)) return -1; ++#endif /* ST_RDONLY */ ++#ifdef ST_NOSUID ++ if (ins(d, "ST_NOSUID", (long)ST_NOSUID)) return -1; ++#endif /* ST_NOSUID */ ++ ++ /* GNU extensions */ ++#ifdef ST_NODEV ++ if (ins(d, "ST_NODEV", (long)ST_NODEV)) return -1; ++#endif /* ST_NODEV */ ++#ifdef ST_NOEXEC ++ if (ins(d, "ST_NOEXEC", (long)ST_NOEXEC)) return -1; ++#endif /* ST_NOEXEC */ ++#ifdef ST_SYNCHRONOUS ++ if (ins(d, "ST_SYNCHRONOUS", (long)ST_SYNCHRONOUS)) return -1; ++#endif /* ST_SYNCHRONOUS */ ++#ifdef ST_MANDLOCK ++ if (ins(d, "ST_MANDLOCK", (long)ST_MANDLOCK)) return -1; ++#endif /* ST_MANDLOCK */ ++#ifdef ST_WRITE ++ if (ins(d, "ST_WRITE", (long)ST_WRITE)) return -1; ++#endif /* ST_WRITE */ ++#ifdef ST_APPEND ++ if (ins(d, "ST_APPEND", (long)ST_APPEND)) return -1; ++#endif /* ST_APPEND */ ++#ifdef ST_NOATIME ++ if (ins(d, "ST_NOATIME", (long)ST_NOATIME)) return -1; ++#endif /* ST_NOATIME */ ++#ifdef ST_NODIRATIME ++ if (ins(d, "ST_NODIRATIME", (long)ST_NODIRATIME)) return -1; ++#endif /* ST_NODIRATIME */ ++#ifdef ST_RELATIME ++ if (ins(d, "ST_RELATIME", (long)ST_RELATIME)) return -1; ++#endif /* ST_RELATIME */ ++ + #ifdef HAVE_SPAWNV + #if defined(PYOS_OS2) && defined(PYCC_GCC) + if (ins(d, "P_WAIT", (long)P_WAIT)) return -1; --- python2.7-2.7.orig/debian/patches/hurd-broken-poll.diff +++ python2.7-2.7/debian/patches/hurd-broken-poll.diff @@ -0,0 +1,25 @@ +# DP: Fix build failure on hurd, working around poll() on systems +# DP: on which it returns an error on invalid FDs. + +Index: python2.6-2.6.5+20100521/Modules/selectmodule.c +=================================================================== +--- python2.6-2.6.5+20100521.orig/Modules/selectmodule.c 2010-05-21 16:02:58.343711924 +0200 ++++ python2.6-2.6.5+20100521/Modules/selectmodule.c 2010-05-21 16:04:38.644709872 +0200 +@@ -1714,7 +1714,7 @@ + + static PyMethodDef select_methods[] = { + {"select", select_select, METH_VARARGS, select_doc}, +-#ifdef HAVE_POLL ++#if defined(HAVE_POLL) && !defined(HAVE_BROKEN_POLL) + {"poll", select_poll, METH_NOARGS, poll_doc}, + #endif /* HAVE_POLL */ + {0, 0}, /* sentinel */ +@@ -1738,7 +1738,7 @@ + Py_INCREF(SelectError); + PyModule_AddObject(m, "error", SelectError); + +-#if defined(HAVE_POLL) ++#if defined(HAVE_POLL) && !defined(HAVE_BROKEN_POLL) + #ifdef __APPLE__ + if (select_have_broken_poll()) { + if (PyObject_DelAttrString(m, "poll") == -1) { --- python2.7-2.7.orig/debian/patches/autoconf-version.diff +++ python2.7-2.7/debian/patches/autoconf-version.diff @@ -0,0 +1,20 @@ +# DP: remove autoconf version check + +--- a/configure.in ++++ b/configure.in +@@ -5,15 +5,6 @@ + # Set VERSION so we only need to edit in one place (i.e., here) + m4_define(PYTHON_VERSION, 2.7) + +-dnl Some m4 magic to ensure that the configure script is generated +-dnl by the correct autoconf version. +-m4_define([version_required], +-[m4_if(m4_version_compare(m4_defn([m4_PACKAGE_VERSION]), [$1]), 0, +- [], +- [m4_fatal([Autoconf version $1 is required for Python], 63)]) +-]) +-version_required(2.65) +- + AC_REVISION($Revision: 81582 $) + AC_INIT(python, PYTHON_VERSION, http://bugs.python.org/) + AC_CONFIG_SRCDIR([Include/object.h]) --- python2.7-2.7.orig/debian/patches/doc-faq.dpatch +++ python2.7-2.7/debian/patches/doc-faq.dpatch @@ -0,0 +1,54 @@ +#! /bin/sh -e + +# DP: Mention the FAQ on the documentation index page. + +dir= +if [ $# -eq 3 -a "$2" = '-d' ]; then + pdir="-d $3" + dir="$3/" +elif [ $# -ne 1 ]; then + echo >&2 "usage: `basename $0`: -patch|-unpatch [-d ]" + exit 1 +fi +case "$1" in + -patch) + patch $pdir -f --no-backup-if-mismatch -p0 < $0 + #cd ${dir}gcc && autoconf + ;; + -unpatch) + patch $pdir -f --no-backup-if-mismatch -R -p0 < $0 + #rm ${dir}gcc/configure + ;; + *) + echo >&2 "usage: `basename $0`: -patch|-unpatch [-d ]" + exit 1 +esac +exit 0 + +--- Doc/html/index.html.in~ 2002-04-01 18:11:27.000000000 +0200 ++++ Doc/html/index.html.in 2003-04-05 13:33:35.000000000 +0200 +@@ -123,6 +123,24 @@ + + + ++ ++ ++   ++

++ ++ ++   ++ ++ ++ + + +

--- python2.7-2.7.orig/debian/patches/plat-linux2_sparc.diff +++ python2.7-2.7/debian/patches/plat-linux2_sparc.diff @@ -0,0 +1,72 @@ +Index: Lib/plat-linux2/IN.py +=================================================================== +--- ./Lib/plat-linux2/IN.py (Revision 77754) ++++ ./Lib/plat-linux2/IN.py (Arbeitskopie) +@@ -442,37 +442,37 @@ + SIOCGPGRP = 0x8904 + SIOCATMARK = 0x8905 + SIOCGSTAMP = 0x8906 +-SOL_SOCKET = 1 +-SO_DEBUG = 1 +-SO_REUSEADDR = 2 +-SO_TYPE = 3 +-SO_ERROR = 4 +-SO_DONTROUTE = 5 +-SO_BROADCAST = 6 +-SO_SNDBUF = 7 +-SO_RCVBUF = 8 +-SO_KEEPALIVE = 9 +-SO_OOBINLINE = 10 +-SO_NO_CHECK = 11 +-SO_PRIORITY = 12 +-SO_LINGER = 13 +-SO_BSDCOMPAT = 14 +-SO_PASSCRED = 16 +-SO_PEERCRED = 17 +-SO_RCVLOWAT = 18 +-SO_SNDLOWAT = 19 +-SO_RCVTIMEO = 20 +-SO_SNDTIMEO = 21 +-SO_SECURITY_AUTHENTICATION = 22 +-SO_SECURITY_ENCRYPTION_TRANSPORT = 23 +-SO_SECURITY_ENCRYPTION_NETWORK = 24 +-SO_BINDTODEVICE = 25 +-SO_ATTACH_FILTER = 26 +-SO_DETACH_FILTER = 27 +-SO_PEERNAME = 28 +-SO_TIMESTAMP = 29 ++SOL_SOCKET = 0xffff ++SO_DEBUG = 0x0001 ++SO_REUSEADDR = 0x0004 ++SO_TYPE = 0x1008 ++SO_ERROR = 0x1007 ++SO_DONTROUTE = 0x0010 ++SO_BROADCAST = 0x0020 ++SO_SNDBUF = 0x1001 ++SO_RCVBUF = 0x1002 ++SO_KEEPALIVE = 0x0008 ++SO_OOBINLINE = 0x0100 ++SO_NO_CHECK = 0x000b ++SO_PRIORITY = 0x000c ++SO_LINGER = 0x0080 ++SO_BSDCOMPAT = 0x0400 ++SO_PASSCRED = 0x0002 ++SO_PEERCRED = 0x0040 ++SO_RCVLOWAT = 0x0800 ++SO_SNDLOWAT = 0x1000 ++SO_RCVTIMEO = 0x2000 ++SO_SNDTIMEO = 0x4000 ++SO_SECURITY_AUTHENTICATION = 0x5001 ++SO_SECURITY_ENCRYPTION_TRANSPORT = 0x5002 ++SO_SECURITY_ENCRYPTION_NETWORK = 0x5004 ++SO_BINDTODEVICE = 0x000d ++SO_ATTACH_FILTER = 0x001a ++SO_DETACH_FILTER = 0x001b ++SO_PEERNAME = 0x001c ++SO_TIMESTAMP = 0x001d + SCM_TIMESTAMP = SO_TIMESTAMP +-SO_ACCEPTCONN = 30 ++SO_ACCEPTCONN = 0x8000 + SOCK_STREAM = 1 + SOCK_DGRAM = 2 + SOCK_RAW = 3 --- python2.7-2.7.orig/debian/patches/disable-utimes.diff +++ python2.7-2.7/debian/patches/disable-utimes.diff @@ -0,0 +1,13 @@ +# DP: disable check for utimes function, which is broken in glibc-2.3.2 + +--- a/configure.in ++++ b/configure.in +@@ -2698,7 +2698,7 @@ + setsid setpgid setpgrp setuid setvbuf snprintf \ + sigaction siginterrupt sigrelse strftime \ + sysconf tcgetpgrp tcsetpgrp tempnam timegm times tmpfile tmpnam tmpnam_r \ +- truncate uname unsetenv utimes waitpid wait3 wait4 wcscoll _getpty) ++ truncate uname unsetenv waitpid wait3 wait4 wcscoll _getpty) + + # For some functions, having a definition is not sufficient, since + # we want to take their address. --- python2.7-2.7.orig/debian/patches/doc-nodownload.diff +++ python2.7-2.7/debian/patches/doc-nodownload.diff @@ -0,0 +1,13 @@ +# DP: Don't try to download documentation tools + +--- a/Doc/Makefile ++++ b/Doc/Makefile +@@ -57,7 +57,7 @@ + + update: clean checkout + +-build: checkout ++build: + mkdir -p build/$(BUILDER) build/doctrees + $(PYTHON) tools/sphinx-build.py $(ALLSPHINXOPTS) + @echo --- python2.7-2.7.orig/debian/patches/apport-support.dpatch +++ python2.7-2.7/debian/patches/apport-support.dpatch @@ -0,0 +1,42 @@ +#! /bin/sh -e + +dir= +if [ $# -eq 3 -a "$2" = '-d' ]; then + pdir="-d $3" + dir="$3/" +elif [ $# -ne 1 ]; then + echo >&2 "usage: `basename $0`: -patch|-unpatch [-d ]" + exit 1 +fi +case "$1" in + -patch) + patch $pdir -f --no-backup-if-mismatch -p0 < $0 + #cd ${dir}gcc && autoconf + ;; + -unpatch) + patch $pdir -f --no-backup-if-mismatch -R -p0 < $0 + #rm ${dir}gcc/configure + ;; + *) + echo >&2 "usage: `basename $0`: -patch|-unpatch [-d ]" + exit 1 +esac +exit 0 + +--- Lib/site.py 2004-07-20 12:28:28.000000000 +1000 ++++ Lib/site.py 2006-11-09 09:28:32.000000000 +1100 +@@ -393,6 +393,14 @@ + # this module is run as a script, because this code is executed twice. + if hasattr(sys, "setdefaultencoding"): + del sys.setdefaultencoding ++ # install the apport exception handler if available ++ try: ++ import apport_python_hook ++ except ImportError: ++ pass ++ else: ++ apport_python_hook.install() ++ + + main() + --- python2.7-2.7.orig/debian/patches/profile-doc.diff +++ python2.7-2.7/debian/patches/profile-doc.diff @@ -0,0 +1,32 @@ +# DP: hotshot/pstats.py: Error out on missing profile/pstats modules. +# DP: Add a note to the library documentation, that the profile and pstats +# DP: modules can be found in the python2.x-profiler package. + +--- a/Doc/library/profile.rst ++++ b/Doc/library/profile.rst +@@ -5,6 +5,12 @@ + The Python Profilers + ******************** + ++Debian note: The license for the :mod:`profile` and :mod:`pstats` ++modules doesn't conform to the Debian Free Software Guidelines (DFSG). ++These modules can be found in the *python-profiler* package in the ++*non-free* section of the Debian archives or in the the *multiverse* ++section of the Ubuntu archives. ++ + .. sectionauthor:: James Roskind + + .. module:: profile +@@ -243,6 +249,12 @@ + :synopsis: Python profiler + + ++Debian note: The license for the :mod:`profile` and :mod:`pstats` ++modules doesn't conform to the Debian Free Software Guidelines (DFSG). ++These modules can be found in the *python-profiler* package in the ++*non-free* section of the Debian archives or in the the *multiverse* ++section of the Ubuntu archives. ++ + The primary entry point for the profiler is the global function + :func:`profile.run` (resp. :func:`cProfile.run`). It is typically used to create + any profile information. The reports are formatted and printed using methods of --- python2.7-2.7.orig/debian/patches/webbrowser.diff +++ python2.7-2.7/debian/patches/webbrowser.diff @@ -0,0 +1,27 @@ +# DP: Recognize other browsers: www-browser, x-www-browser, iceweasel, iceape. + +--- a/Lib/webbrowser.py ++++ b/Lib/webbrowser.py +@@ -453,9 +453,13 @@ + if "KDE_FULL_SESSION" in os.environ and _iscommand("kfmclient"): + register("kfmclient", Konqueror, Konqueror("kfmclient")) + ++ if _iscommand("x-www-browser"): ++ register("x-www-browser", None, BackgroundBrowser("x-www-browser")) ++ + # The Mozilla/Netscape browsers + for browser in ("mozilla-firefox", "firefox", + "mozilla-firebird", "firebird", ++ "iceweasel", "iceape", + "seamonkey", "mozilla", "netscape"): + if _iscommand(browser): + register(browser, None, Mozilla(browser)) +@@ -493,6 +497,8 @@ + + # Also try console browsers + if os.environ.get("TERM"): ++ if _iscommand("www-browser"): ++ register("www-browser", None, GenericBrowser("www-browser")) + # The Links/elinks browsers + if _iscommand("links"): + register("links", None, GenericBrowser("links")) --- python2.7-2.7.orig/debian/patches/setup-modules.dpatch +++ python2.7-2.7/debian/patches/setup-modules.dpatch @@ -0,0 +1,75 @@ +#! /bin/sh -e + +# DP: Modules/Setup.dist: patches to build some extensions statically + +dir= +if [ $# -eq 3 -a "$2" = '-d' ]; then + pdir="-d $3" + dir="$3/" +elif [ $# -ne 1 ]; then + echo >&2 "usage: `basename $0`: -patch|-unpatch [-d ]" + exit 1 +fi +case "$1" in + -patch) + patch $pdir -f --no-backup-if-mismatch -p0 < $0 + ;; + -unpatch) + patch $pdir -f --no-backup-if-mismatch -R -p0 < $0 + ;; + *) + echo >&2 "usage: `basename $0`: -patch|-unpatch [-d ]" + exit 1 +esac +exit 0 + +--- Modules/_elementtree.c~ 2008-11-27 10:01:33.000000000 +0100 ++++ Modules/_elementtree.c 2008-11-27 10:03:30.000000000 +0100 +@@ -1837,7 +1837,10 @@ + static struct PyExpat_CAPI* expat_capi; + #define EXPAT(func) (expat_capi->func) + #else +-#define EXPAT(func) (XML_##func) ++#define EXPAT(func) (PyExpat_XML_##func) ++#define PyExpat_XML_GetErrorLineNumber PyExpat_XML_GetCurrentLineNumber ++#define PyExpat_XML_GetErrorColumnNumber PyExpat_XML_GetCurrentColumnNumber ++#define PyExpat_XML_GetErrorByteIndex PyExpat_XML_GetCurrentByteIndex + #endif + + typedef struct { +--- Modules/Setup.dist~ 2008-11-27 10:59:37.000000000 +0100 ++++ Modules/Setup.dist 2008-11-27 11:00:26.000000000 +0100 +@@ -165,7 +165,7 @@ + #itertools itertoolsmodule.c # Functions creating iterators for efficient looping + #atexit atexitmodule.c # Register functions to be run at interpreter-shutdown + #_functools _functoolsmodule.c # Tools for working with functions and callable objects +-#_elementtree -I$(srcdir)/Modules/expat -DHAVE_EXPAT_CONFIG_H -DUSE_PYEXPAT_CAPI _elementtree.c # elementtree accelerator ++#_elementtree -I$(srcdir)/Modules/expat -DHAVE_EXPAT_CONFIG_H _elementtree.c # elementtree accelerator + #_pickle _pickle.c # pickle accelerator + #datetime datetimemodule.c # date/time type + #_bisect _bisectmodule.c # Bisection algorithms +@@ -257,6 +257,7 @@ + #_sha256 sha256module.c + #_sha512 sha512module.c + ++#_hashlib _hashopenssl.c -lssl -lcrypto + + # SGI IRIX specific modules -- off by default. + +@@ -341,6 +341,7 @@ + #DBLIB=$(DB)/lib + #_bsddb _bsddb.c -I$(DBINC) -L$(DBLIB) -ldb-$(DBLIBVER) + ++#_ctypes _ctypes/_ctypes.c _ctypes/callbacks.c _ctypes/callproc.c _ctypes/stgdict.c _ctypes/cfield.c _ctypes/malloc_closure.c -Wl,-Bstatic -lffi -Wl,-Bdynamic + + # Helper module for various ascii-encoders + #binascii binascii.c +@@ -382,7 +382,7 @@ + # + # More information on Expat can be found at www.libexpat.org. + # +-#pyexpat expat/xmlparse.c expat/xmlrole.c expat/xmltok.c pyexpat.c -I$(srcdir)/Modules/expat -DHAVE_EXPAT_CONFIG_H -DUSE_PYEXPAT_CAPI ++#pyexpat expat/xmlparse.c expat/xmlrole.c expat/xmltok.c pyexpat.c -I$(srcdir)/Modules/expat -DHAVE_EXPAT_CONFIG_H + + # Hye-Shik Chang's CJKCodecs + --- python2.7-2.7.orig/debian/patches/deb-locations.diff +++ python2.7-2.7/debian/patches/deb-locations.diff @@ -0,0 +1,63 @@ +# DP: adjust locations of directories to debian policy + +--- a/Demo/tkinter/guido/ManPage.py ++++ b/Demo/tkinter/guido/ManPage.py +@@ -189,8 +189,9 @@ + def test(): + import os + import sys +- # XXX This directory may be different on your system +- MANDIR = '/usr/local/man/mann' ++ # XXX This directory may be different on your system, ++ # it is here set for Debian GNU/Linux. ++ MANDIR = '/usr/share/man' + DEFAULTPAGE = 'Tcl' + formatted = 0 + if sys.argv[1:] and sys.argv[1] == '-f': +--- a/Demo/tkinter/guido/tkman.py ++++ b/Demo/tkinter/guido/tkman.py +@@ -9,8 +9,8 @@ + from Tkinter import * + from ManPage import ManPage + +-MANNDIRLIST = ['/depot/sundry/man/mann','/usr/local/man/mann'] +-MAN3DIRLIST = ['/depot/sundry/man/man3','/usr/local/man/man3'] ++MANNDIRLIST = ['/depot/sundry/man/mann','/usr/share/man/mann'] ++MAN3DIRLIST = ['/depot/sundry/man/man3','/usr/share/man/man3'] + + foundmanndir = 0 + for dir in MANNDIRLIST: +--- a/Misc/python.man ++++ b/Misc/python.man +@@ -323,7 +323,7 @@ + These are subject to difference depending on local installation + conventions; ${prefix} and ${exec_prefix} are installation-dependent + and should be interpreted as for GNU software; they may be the same. +-The default for both is \fI/usr/local\fP. ++On Debian GNU/{Hurd,Linux} the default for both is \fI/usr\fP. + .IP \fI${exec_prefix}/bin/python\fP + Recommended location of the interpreter. + .PP +--- a/Tools/faqwiz/faqconf.py ++++ b/Tools/faqwiz/faqconf.py +@@ -21,7 +21,7 @@ + OWNEREMAIL = "nobody@anywhere.org" # Email for feedback + HOMEURL = "http://www.python.org" # Related home page + HOMENAME = "Python home" # Name of related home page +-RCSBINDIR = "/usr/local/bin/" # Directory containing RCS commands ++RCSBINDIR = "/usr/bin/" # Directory containing RCS commands + # (must end in a slash) + + # Parameters you can normally leave alone +--- a/Tools/webchecker/webchecker.py ++++ b/Tools/webchecker/webchecker.py +@@ -19,7 +19,8 @@ + a directory listing is returned. Now, you can point webchecker to the + document tree in the local file system of your HTTP daemon, and have + most of it checked. In fact the default works this way if your local +-web tree is located at /usr/local/etc/httpd/htdpcs (the default for ++web tree is located at /var/www, which is the default for Debian ++GNU/Linux. Other systems use /usr/local/etc/httpd/htdocs (the default for + the NCSA HTTP daemon and probably others). + + Report printed: --- python2.7-2.7.orig/debian/patches/plat-linux2_alpha.diff +++ python2.7-2.7/debian/patches/plat-linux2_alpha.diff @@ -0,0 +1,73 @@ +Index: Lib/plat-linux2/IN.py +=================================================================== +--- ./Lib/plat-linux2/IN.py (Revision 77754) ++++ ./Lib/plat-linux2/IN.py (Arbeitskopie) +@@ -436,43 +436,43 @@ + # Included from asm/socket.h + + # Included from asm/sockios.h +-FIOSETOWN = 0x8901 +-SIOCSPGRP = 0x8902 +-FIOGETOWN = 0x8903 +-SIOCGPGRP = 0x8904 +-SIOCATMARK = 0x8905 ++FIOSETOWN = 0x8004667c ++SIOCSPGRP = 0x80047308 ++FIOGETOWN = 0x4004667b ++SIOCGPGRP = 0x40047309 ++SIOCATMARK = 0x40047307 + SIOCGSTAMP = 0x8906 +-SOL_SOCKET = 1 +-SO_DEBUG = 1 +-SO_REUSEADDR = 2 +-SO_TYPE = 3 +-SO_ERROR = 4 +-SO_DONTROUTE = 5 +-SO_BROADCAST = 6 +-SO_SNDBUF = 7 +-SO_RCVBUF = 8 +-SO_KEEPALIVE = 9 +-SO_OOBINLINE = 10 ++SOL_SOCKET = 0xffff ++SO_DEBUG = 0x0001 ++SO_REUSEADDR = 0x0004 ++SO_TYPE = 0x1008 ++SO_ERROR = 0x1007 ++SO_DONTROUTE = 0x0010 ++SO_BROADCAST = 0x0020 ++SO_SNDBUF = 0x1001 ++SO_RCVBUF = 0x1002 ++SO_KEEPALIVE = 0x0008 ++SO_OOBINLINE = 0x0100 + SO_NO_CHECK = 11 + SO_PRIORITY = 12 +-SO_LINGER = 13 ++SO_LINGER = 0x0080 + SO_BSDCOMPAT = 14 + SO_PASSCRED = 16 + SO_PEERCRED = 17 +-SO_RCVLOWAT = 18 +-SO_SNDLOWAT = 19 +-SO_RCVTIMEO = 20 +-SO_SNDTIMEO = 21 +-SO_SECURITY_AUTHENTICATION = 22 +-SO_SECURITY_ENCRYPTION_TRANSPORT = 23 +-SO_SECURITY_ENCRYPTION_NETWORK = 24 ++SO_RCVLOWAT = 0x1010 ++SO_SNDLOWAT = 0x1011 ++SO_RCVTIMEO = 0x1012 ++SO_SNDTIMEO = 0x1013 ++SO_SECURITY_AUTHENTICATION = 19 ++SO_SECURITY_ENCRYPTION_TRANSPORT = 20 ++SO_SECURITY_ENCRYPTION_NETWORK = 21 + SO_BINDTODEVICE = 25 + SO_ATTACH_FILTER = 26 + SO_DETACH_FILTER = 27 + SO_PEERNAME = 28 + SO_TIMESTAMP = 29 + SCM_TIMESTAMP = SO_TIMESTAMP +-SO_ACCEPTCONN = 30 ++SO_ACCEPTCONN = 0x1014 + SOCK_STREAM = 1 + SOCK_DGRAM = 2 + SOCK_RAW = 3 --- python2.7-2.7.orig/debian/patches/cthreads.diff +++ python2.7-2.7/debian/patches/cthreads.diff @@ -0,0 +1,39 @@ +# DP: Remove cthreads detection + +--- a/configure.in ++++ b/configure.in +@@ -2154,7 +2154,6 @@ + + # Templates for things AC_DEFINEd more than once. + # For a single AC_DEFINE, no template is needed. +-AH_TEMPLATE(C_THREADS,[Define if you have the Mach cthreads package]) + AH_TEMPLATE(_REENTRANT, + [Define to force use of thread-safe errno, h_errno, and other functions]) + AH_TEMPLATE(WITH_THREAD, +@@ -2236,17 +2235,6 @@ + AC_MSG_RESULT($unistd_defines_pthreads) + + AC_DEFINE(_REENTRANT) +- AC_CHECK_HEADER(cthreads.h, [AC_DEFINE(WITH_THREAD) +- AC_DEFINE(C_THREADS) +- AC_DEFINE(HURD_C_THREADS, 1, +- [Define if you are using Mach cthreads directly under /include]) +- LIBS="$LIBS -lthreads" +- THREADOBJ="Python/thread.o"],[ +- AC_CHECK_HEADER(mach/cthreads.h, [AC_DEFINE(WITH_THREAD) +- AC_DEFINE(C_THREADS) +- AC_DEFINE(MACH_C_THREADS, 1, +- [Define if you are using Mach cthreads under mach /]) +- THREADOBJ="Python/thread.o"],[ + AC_MSG_CHECKING(for --with-pth) + AC_ARG_WITH([pth], + AS_HELP_STRING([--with-pth], [use GNU pth threading libraries]), +@@ -2301,7 +2289,7 @@ + LIBS="$LIBS -lcma" + THREADOBJ="Python/thread.o"],[ + USE_THREAD_MODULE="#"]) +- ])])])])])])])])])]) ++ ])])])])])])])]) + + AC_CHECK_LIB(mpc, usconfig, [AC_DEFINE(WITH_THREAD) + LIBS="$LIBS -lmpc" --- python2.7-2.7.orig/debian/patches/deb-setup.diff +++ python2.7-2.7/debian/patches/deb-setup.diff @@ -0,0 +1,39 @@ +# DP: Don't include /usr/local/include and /usr/local/lib as gcc search paths +# DP: Include /usr/include/ and /usr/lib/ as gcc search paths + +--- a/Makefile.pre.in ++++ b/Makefile.pre.in +@@ -207,6 +207,7 @@ + + + LIBFFI_INCLUDEDIR= @LIBFFI_INCLUDEDIR@ ++DEB_GNU_TYPE=@DEB_GNU_TYPE@ + + ########################################################################## + # Parser +--- a/setup.py ++++ b/setup.py +@@ -347,8 +348,12 @@ + + def detect_modules(self): + # Ensure that /usr/local is always used +- add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib') +- add_dir_to_list(self.compiler.include_dirs, '/usr/local/include') ++ # On Debian /usr/local is always used, so we don't include it twice ++ #add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib') ++ #add_dir_to_list(self.compiler.include_dirs, '/usr/local/include') ++ triplet = sysconfig.get_config_var("DEB_GNU_TYPE") ++ add_dir_to_list(self.compiler.library_dirs, '/usr/lib/%s' % triplet) ++ add_dir_to_list(self.compiler.include_dirs, '/usr/include/%s' % triplet) + + # Add paths specified in the environment variables LDFLAGS and + # CPPFLAGS for header and library files. +@@ -403,6 +403,8 @@ + '/lib', '/usr/lib', + ] + inc_dirs = self.compiler.include_dirs + ['/usr/include'] ++ gnu_triplet = os.popen('dpkg-architecture -qDEB_HOST_GNU_TYPE').readline()[:-1] ++ inc_dirs.append(os.path.join('/usr/include', gnu_triplet)) + exts = [] + missing = [] + --- python2.7-2.7.orig/debian/patches/series.in +++ python2.7-2.7/debian/patches/series.in @@ -0,0 +1,53 @@ +autoconf-version.diff +svn-updates.diff +deb-setup.diff +deb-locations.diff +site-locations.diff +distutils-install-layout.diff +locale-module.diff +distutils-link.diff +// FIXME: Update patch +//distutils-sysconfig.diff +test-sundry.diff +tkinter-import.diff +link-opt.diff +debug-build.diff +hotshot-import.diff +profile-doc.diff +webbrowser.diff +linecache.diff +doc-nodownload.diff +profiled-build2.diff +no-zip-on-sys.path.diff +platform-lsbrelease.diff +bdist-wininst-notfound.diff +setup-modules-ssl.diff +makesetup-bashism.diff +hurd-broken-poll.diff +hurd-disable-nonworking-constants.diff +enable-fpectl.diff +make-pydoc-more-robust.diff +statvfs-f_flag-constants.diff +#if defined (arch_alpha) +plat-linux2_alpha.diff +#elif defined (arch_hppa) +plat-linux2_hppa.diff +#elif defined (arch_mips) || defined(arch_mipsel) +plat-linux2_mips.diff +#elif defined (arch_sparc) || defined (arch_sparc64) +plat-linux2_sparc.diff +#endif +#if defined (BROKEN_UTIMES) +disable-utimes.diff +#endif +#if defined (Ubuntu) +langpack-gettext.diff +#endif +#if defined (arch_os_hurd) +no-large-file-support.diff +cthreads.diff +#endif +issue9012a.diff +issue9054.diff +link-system-expat.diff +plat-gnukfreebsd.diff --- python2.7-2.7.orig/debian/patches/linecache.diff +++ python2.7-2.7/debian/patches/linecache.diff @@ -0,0 +1,16 @@ +# DP: Proper handling of packages in linecache.py + +--- a/Lib/linecache.py ++++ b/Lib/linecache.py +@@ -108,6 +108,11 @@ + if os.path.isabs(filename): + return [] + ++ # Take care to handle packages ++ if basename == '__init__.py': ++ # filename referes to a package ++ basename = filename ++ + for dirname in sys.path: + # When using imputil, sys.path may contain things other than + # strings; ignore them when it happens. --- python2.7-2.7.orig/debian/patches/test-sundry.diff +++ python2.7-2.7/debian/patches/test-sundry.diff @@ -0,0 +1,17 @@ +# DP: test_sundry: Don't fail on import of the profile and pstats module + +--- a/Lib/test/test_sundry.py ++++ b/Lib/test/test_sundry.py +@@ -62,7 +62,11 @@ + import os2emxpath + import pdb + import posixfile +- import pstats ++ try: ++ import pstats # separated out into the python-profiler package ++ except ImportError: ++ if test_support.verbose: ++ print "skipping profile and pstats" + import py_compile + import rexec + import rlcompleter --- python2.7-2.7.orig/debian/patches/distutils-sysconfig.diff +++ python2.7-2.7/debian/patches/distutils-sysconfig.diff @@ -0,0 +1,33 @@ +# DP: Allow setting BASECFLAGS, OPT and EXTRA_LDFLAGS (like, CC, CXX, CPP, +# DP: CFLAGS, CPPFLAGS, CCSHARED, LDSHARED) from the environment. + +Index: python2.6-2.6.5+20100521/Lib/distutils/sysconfig.py +=================================================================== +--- python2.6-2.6.5+20100521.orig/Lib/distutils/sysconfig.py 2010-05-21 15:44:39.599722521 +0200 ++++ python2.6-2.6.5+20100521/Lib/distutils/sysconfig.py 2010-05-21 15:44:39.607707825 +0200 +@@ -169,8 +169,9 @@ + varies across Unices and is stored in Python's Makefile. + """ + if compiler.compiler_type == "unix": +- (cc, cxx, opt, cflags, ccshared, ldshared, so_ext) = \ ++ (cc, cxx, opt, cflags, opt, extra_cflags, basecflags, ccshared, ldshared, so_ext) = \ + get_config_vars('CC', 'CXX', 'OPT', 'CFLAGS', ++ 'OPT', 'EXTRA_CFLAGS', 'BASECFLAGS', + 'CCSHARED', 'LDSHARED', 'SO') + + if 'CC' in os.environ: +@@ -185,8 +186,13 @@ + cpp = cc + " -E" # not always + if 'LDFLAGS' in os.environ: + ldshared = ldshared + ' ' + os.environ['LDFLAGS'] ++ if 'BASECFLAGS' in os.environ: ++ basecflags = os.environ['BASECFLAGS'] ++ if 'OPT' in os.environ: ++ opt = os.environ['OPT'] ++ cflags = ' '.join(str(x) for x in (basecflags, opt, extra_cflags) if x) + if 'CFLAGS' in os.environ: +- cflags = opt + ' ' + os.environ['CFLAGS'] ++ cflags = ' '.join(str(x) for x in (basecflags, opt, os.environ['CFLAGS'], extra_cflags) if x) + ldshared = ldshared + ' ' + os.environ['CFLAGS'] + if 'CPPFLAGS' in os.environ: + cpp = cpp + ' ' + os.environ['CPPFLAGS'] --- python2.7-2.7.orig/debian/patches/profiled-build.dpatch +++ python2.7-2.7/debian/patches/profiled-build.dpatch @@ -0,0 +1,36 @@ +#! /bin/sh -e + +# DP: Fix profiled build; don't use Python/thread.gc*, gcc complains + +dir= +if [ $# -eq 3 -a "$2" = '-d' ]; then + pdir="-d $3" + dir="$3/" +elif [ $# -ne 1 ]; then + echo >&2 "usage: `basename $0`: -patch|-unpatch [-d ]" + exit 1 +fi +case "$1" in + -patch) + patch $pdir -f --no-backup-if-mismatch -p0 < $0 + ;; + -unpatch) + patch $pdir -f --no-backup-if-mismatch -R -p0 < $0 + ;; + *) + echo >&2 "usage: `basename $0`: -patch|-unpatch [-d ]" + exit 1 +esac +exit 0 + +--- Makefile.pre.in~ 2008-11-14 12:13:11.000000000 +0100 ++++ Makefile.pre.in 2008-11-14 14:54:20.000000000 +0100 +@@ -375,6 +375,8 @@ + ./$(BUILDPYTHON) $(PROFILE_TASK) + + build_all_use_profile: ++ : # FIXME: gcc error ++ rm -f Python/thread.gc* + $(MAKE) all CFLAGS="$(CFLAGS) -fprofile-use" + + coverage: --- python2.7-2.7.orig/debian/patches/plat-linux2_mips.diff +++ python2.7-2.7/debian/patches/plat-linux2_mips.diff @@ -0,0 +1,88 @@ +Index: Lib/plat-linux2/DLFCN.py +=================================================================== +--- ./Lib/plat-linux2/DLFCN.py (Revision 77754) ++++ ./Lib/plat-linux2/DLFCN.py (Arbeitskopie) +@@ -77,7 +77,7 @@ + RTLD_LAZY = 0x00001 + RTLD_NOW = 0x00002 + RTLD_BINDING_MASK = 0x3 +-RTLD_NOLOAD = 0x00004 +-RTLD_GLOBAL = 0x00100 ++RTLD_NOLOAD = 0x00008 ++RTLD_GLOBAL = 0x00004 + RTLD_LOCAL = 0 + RTLD_NODELETE = 0x01000 +Index: Lib/plat-linux2/IN.py +=================================================================== +--- ./Lib/plat-linux2/IN.py (Revision 77754) ++++ ./Lib/plat-linux2/IN.py (Arbeitskopie) +@@ -436,33 +436,33 @@ + # Included from asm/socket.h + + # Included from asm/sockios.h +-FIOSETOWN = 0x8901 +-SIOCSPGRP = 0x8902 +-FIOGETOWN = 0x8903 +-SIOCGPGRP = 0x8904 +-SIOCATMARK = 0x8905 ++FIOSETOWN = 0x8004667c ++SIOCSPGRP = 0x80047308 ++FIOGETOWN = 0x4004667b ++SIOCGPGRP = 0x40047309 ++SIOCATMARK = 0x40047307 + SIOCGSTAMP = 0x8906 +-SOL_SOCKET = 1 +-SO_DEBUG = 1 +-SO_REUSEADDR = 2 +-SO_TYPE = 3 +-SO_ERROR = 4 +-SO_DONTROUTE = 5 +-SO_BROADCAST = 6 +-SO_SNDBUF = 7 +-SO_RCVBUF = 8 +-SO_KEEPALIVE = 9 +-SO_OOBINLINE = 10 ++SOL_SOCKET = 0xffff ++SO_DEBUG = 0x0001 ++SO_REUSEADDR = 0x0004 ++SO_TYPE = 0x1008 ++SO_ERROR = 0x1007 ++SO_DONTROUTE = 0x0010 ++SO_BROADCAST = 0x0020 ++SO_SNDBUF = 0x1001 ++SO_RCVBUF = 0x1002 ++SO_KEEPALIVE = 0x0008 ++SO_OOBINLINE = 0x0100 + SO_NO_CHECK = 11 + SO_PRIORITY = 12 +-SO_LINGER = 13 ++SO_LINGER = 0x0080 + SO_BSDCOMPAT = 14 +-SO_PASSCRED = 16 +-SO_PEERCRED = 17 +-SO_RCVLOWAT = 18 +-SO_SNDLOWAT = 19 +-SO_RCVTIMEO = 20 +-SO_SNDTIMEO = 21 ++SO_PASSCRED = 17 ++SO_PEERCRED = 18 ++SO_RCVLOWAT = 0x1004 ++SO_SNDLOWAT = 0x1003 ++SO_RCVTIMEO = 0x1006 ++SO_SNDTIMEO = 0x1005 + SO_SECURITY_AUTHENTICATION = 22 + SO_SECURITY_ENCRYPTION_TRANSPORT = 23 + SO_SECURITY_ENCRYPTION_NETWORK = 24 +@@ -472,9 +472,9 @@ + SO_PEERNAME = 28 + SO_TIMESTAMP = 29 + SCM_TIMESTAMP = SO_TIMESTAMP +-SO_ACCEPTCONN = 30 +-SOCK_STREAM = 1 +-SOCK_DGRAM = 2 ++SO_ACCEPTCONN = 0x1009 ++SOCK_STREAM = 2 ++SOCK_DGRAM = 1 + SOCK_RAW = 3 + SOCK_RDM = 4 + SOCK_SEQPACKET = 5 --- python2.7-2.7.orig/debian/patches/libre.diff +++ python2.7-2.7/debian/patches/libre.diff @@ -0,0 +1,9 @@ +--- Doc/lib/libre.tex~ 2003-07-25 09:29:22.000000000 +0200 ++++ Doc/lib/libre.tex 2003-07-25 09:30:58.000000000 +0200 +@@ -919,5 +919,5 @@ + Starting with Python 2.3, simple uses of the \regexp{*?} pattern are + special-cased to avoid recursion. Thus, the above regular expression + can avoid recursion by being recast as +-\regexp{Begin [a-zA-Z0-9_ ]*?end}. As a further benefit, such regular ++`Begin [a-zA-Z0-9_ ]*?end'. As a further benefit, such regular + expressions will run faster than their recursive equivalents. --- python2.7-2.7.orig/debian/patches/pydebug-path.dpatch +++ python2.7-2.7/debian/patches/pydebug-path.dpatch @@ -0,0 +1,100 @@ +#! /bin/sh -e + +# DP: When built with --with-pydebug, add a debug directory +# DP: /lib-dynload/debug to sys.path just before +# DP: /lib-dynload und install the extension modules +# DP: of the debug build in this directory. + +dir= +if [ $# -eq 3 -a "$2" = '-d' ]; then + pdir="-d $3" + dir="$3/" +elif [ $# -ne 1 ]; then + echo >&2 "usage: `basename $0`: -patch|-unpatch [-d ]" + exit 1 +fi +case "$1" in + -patch) + patch $pdir -f --no-backup-if-mismatch -p0 < $0 + ;; + -unpatch) + patch $pdir -f --no-backup-if-mismatch -R -p0 < $0 + ;; + *) + echo >&2 "usage: `basename $0`: -patch|-unpatch [-d ]" + exit 1 +esac +exit 0 + +--- Modules/getpath.c.orig 2005-01-18 00:56:31.571961744 +0100 ++++ Modules/getpath.c 2005-01-18 01:02:23.811413208 +0100 +@@ -112,9 +112,14 @@ + #endif + + #ifndef PYTHONPATH ++#ifdef Py_DEBUG ++#define PYTHONPATH PREFIX "/lib/python" VERSION ":" \ ++ EXEC_PREFIX "/lib/python" VERSION "/lib-dynload/debug" ++#else + #define PYTHONPATH PREFIX "/lib/python" VERSION ":" \ + EXEC_PREFIX "/lib/python" VERSION "/lib-dynload" + #endif ++#endif + + #ifndef LANDMARK + #define LANDMARK "os.py" +@@ -323,6 +328,9 @@ + strncpy(exec_prefix, home, MAXPATHLEN); + joinpath(exec_prefix, lib_python); + joinpath(exec_prefix, "lib-dynload"); ++#ifdef Py_DEBUG ++ joinpath(exec_prefix, "debug"); ++#endif + return 1; + } + +@@ -340,6 +348,9 @@ + n = strlen(exec_prefix); + joinpath(exec_prefix, lib_python); + joinpath(exec_prefix, "lib-dynload"); ++#ifdef Py_DEBUG ++ joinpath(exec_prefix, "debug"); ++#endif + if (isdir(exec_prefix)) + return 1; + exec_prefix[n] = '\0'; +@@ -350,6 +361,9 @@ + strncpy(exec_prefix, EXEC_PREFIX, MAXPATHLEN); + joinpath(exec_prefix, lib_python); + joinpath(exec_prefix, "lib-dynload"); ++#ifdef Py_DEBUG ++ joinpath(exec_prefix, "debug"); ++#endif + if (isdir(exec_prefix)) + return 1; + +@@ -654,6 +654,9 @@ + reduce(exec_prefix); + reduce(exec_prefix); + reduce(exec_prefix); ++#ifdef Py_DEBUG ++ reduce(exec_prefix); ++#endif + if (!exec_prefix[0]) + strcpy(exec_prefix, separator); + } +--- Lib/site.py~ 2004-12-04 00:39:05.000000000 +0100 ++++ Lib/site.py 2005-01-18 01:33:36.589707632 +0100 +@@ -188,6 +188,12 @@ + "python" + sys.version[:3], + "site-packages"), + os.path.join(prefix, "lib", "site-python")] ++ try: ++ # sys.getobjects only available in --with-pydebug build ++ sys.getobjects ++ sitedirs.insert(0, os.path.join(sitedirs[0], 'debug')) ++ except AttributeError: ++ pass + else: + sitedirs = [prefix, os.path.join(prefix, "lib", "site-packages")] + if sys.platform == 'darwin': --- python2.7-2.7.orig/debian/patches/setup-modules-ssl.diff +++ python2.7-2.7/debian/patches/setup-modules-ssl.diff @@ -0,0 +1,24 @@ +# DP: Modules/Setup.dist: patch to build _hashlib and _ssl extensions statically + +--- a/Modules/Setup.dist ++++ b/Modules/Setup.dist +@@ -211,10 +211,7 @@ + + # Socket module helper for SSL support; you must comment out the other + # socket line above, and possibly edit the SSL variable: +-#SSL=/usr/local/ssl +-#_ssl _ssl.c \ +-# -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \ +-# -L$(SSL)/lib -lssl -lcrypto ++#_ssl _ssl.c -lssl -lcrypto + + # The crypt module is now disabled by default because it breaks builds + # on many systems (where -lcrypt is needed), e.g. Linux (I believe). +@@ -257,6 +254,7 @@ + #_sha256 sha256module.c + #_sha512 sha512module.c + ++#_hashlib _hashopenssl.c -lssl -lcrypto + + # SGI IRIX specific modules -- off by default. + --- python2.7-2.7.orig/debian/patches/plat-linux2_hppa.diff +++ python2.7-2.7/debian/patches/plat-linux2_hppa.diff @@ -0,0 +1,72 @@ +Index: Lib/plat-linux2/IN.py +=================================================================== +--- ./Lib/plat-linux2/IN.py (Revision 77754) ++++ ./Lib/plat-linux2/IN.py (Arbeitskopie) +@@ -442,37 +442,37 @@ + SIOCGPGRP = 0x8904 + SIOCATMARK = 0x8905 + SIOCGSTAMP = 0x8906 +-SOL_SOCKET = 1 +-SO_DEBUG = 1 +-SO_REUSEADDR = 2 +-SO_TYPE = 3 +-SO_ERROR = 4 +-SO_DONTROUTE = 5 +-SO_BROADCAST = 6 +-SO_SNDBUF = 7 +-SO_RCVBUF = 8 +-SO_KEEPALIVE = 9 +-SO_OOBINLINE = 10 +-SO_NO_CHECK = 11 +-SO_PRIORITY = 12 +-SO_LINGER = 13 +-SO_BSDCOMPAT = 14 +-SO_PASSCRED = 16 +-SO_PEERCRED = 17 +-SO_RCVLOWAT = 18 +-SO_SNDLOWAT = 19 +-SO_RCVTIMEO = 20 +-SO_SNDTIMEO = 21 +-SO_SECURITY_AUTHENTICATION = 22 +-SO_SECURITY_ENCRYPTION_TRANSPORT = 23 +-SO_SECURITY_ENCRYPTION_NETWORK = 24 +-SO_BINDTODEVICE = 25 +-SO_ATTACH_FILTER = 26 +-SO_DETACH_FILTER = 27 +-SO_PEERNAME = 28 +-SO_TIMESTAMP = 29 ++SOL_SOCKET = 0xffff ++SO_DEBUG = 0x0001 ++SO_REUSEADDR = 0x0004 ++SO_TYPE = 0x1008 ++SO_ERROR = 0x1007 ++SO_DONTROUTE = 0x0010 ++SO_BROADCAST = 0x0020 ++SO_SNDBUF = 0x1001 ++SO_RCVBUF = 0x1002 ++SO_KEEPALIVE = 0x0008 ++SO_OOBINLINE = 0x0100 ++SO_NO_CHECK = 0x400b ++SO_PRIORITY = 0x400c ++SO_LINGER = 0x0080 ++SO_BSDCOMPAT = 0x400e ++SO_PASSCRED = 0x4010 ++SO_PEERCRED = 0x4011 ++SO_RCVLOWAT = 0x1004 ++SO_SNDLOWAT = 0x1003 ++SO_RCVTIMEO = 0x1006 ++SO_SNDTIMEO = 0x1005 ++SO_SECURITY_AUTHENTICATION = 0x4016 ++SO_SECURITY_ENCRYPTION_TRANSPORT = 0x4017 ++SO_SECURITY_ENCRYPTION_NETWORK = 0x4018 ++SO_BINDTODEVICE = 0x4019 ++SO_ATTACH_FILTER = 0x401a ++SO_DETACH_FILTER = 0x401b ++SO_PEERNAME = 0x2000 ++SO_TIMESTAMP = 0x4012 + SCM_TIMESTAMP = SO_TIMESTAMP +-SO_ACCEPTCONN = 30 ++SO_ACCEPTCONN = 0x401c + SOCK_STREAM = 1 + SOCK_DGRAM = 2 + SOCK_RAW = 3 --- python2.7-2.7.orig/debian/patches/debug-build.diff +++ python2.7-2.7/debian/patches/debug-build.diff @@ -0,0 +1,181 @@ +# DP: Change the interpreter to build and install python extensions +# DP: built with the python-dbg interpreter with a different name into +# DP: the same path (by appending `_d' to the extension name). + +--- a/Lib/distutils/command/build.py ++++ b/Lib/distutils/command/build.py +@@ -91,7 +91,8 @@ + # 'lib.' under the base build directory. We only use one of + # them for a given distribution, though -- + if self.build_purelib is None: +- self.build_purelib = os.path.join(self.build_base, 'lib') ++ self.build_purelib = os.path.join(self.build_base, ++ 'lib' + plat_specifier) + if self.build_platlib is None: + self.build_platlib = os.path.join(self.build_base, + 'lib' + plat_specifier) +--- a/Lib/distutils/sysconfig.py ++++ b/Lib/distutils/sysconfig.py +@@ -85,7 +85,7 @@ + # Include is located in the srcdir + inc_dir = os.path.join(srcdir, "Include") + return inc_dir +- return os.path.join(prefix, "include", "python" + get_python_version()) ++ return os.path.join(prefix, "include", "python" + get_python_version())+(sys.pydebug and "_d" or "") + elif os.name == "nt": + return os.path.join(prefix, "include") + elif os.name == "os2": +@@ -207,7 +210,7 @@ + if python_build: + return os.path.join(os.path.dirname(sys.executable), "Makefile") + lib_dir = get_python_lib(plat_specific=1, standard_lib=1) +- return os.path.join(lib_dir, "config", "Makefile") ++ return os.path.join(lib_dir, "config"+(sys.pydebug and "_d" or ""), "Makefile") + + + def parse_config_h(fp, g=None): +--- a/Lib/sysconfig.py ++++ b/Lib/sysconfig.py +@@ -282,7 +282,7 @@ + def _get_makefile_filename(): + if _PYTHON_BUILD: + return os.path.join(_PROJECT_BASE, "Makefile") +- return os.path.join(get_path('stdlib').replace("/usr/local","/usr",1), "config", "Makefile") ++ return os.path.join(get_path('stdlib').replace("/usr/local","/usr",1), "config" + (sys.pydebug and "_d" or ""), "Makefile") + + + def _init_posix(vars): +@@ -381,7 +381,7 @@ + else: + inc_dir = _PROJECT_BASE + else: +- inc_dir = get_path('platinclude').replace("/usr/local","/usr",1) ++ inc_dir = get_path('platinclude').replace("/usr/local","/usr",1)+(sys.pydebug and "_d" or "") + return os.path.join(inc_dir, 'pyconfig.h') + + def get_scheme_names(): +--- a/Makefile.pre.in ++++ b/Makefile.pre.in +@@ -99,8 +99,8 @@ + # Detailed destination directories + BINLIBDEST= $(LIBDIR)/python$(VERSION) + LIBDEST= $(SCRIPTDIR)/python$(VERSION) +-INCLUDEPY= $(INCLUDEDIR)/python$(VERSION) +-CONFINCLUDEPY= $(CONFINCLUDEDIR)/python$(VERSION) ++INCLUDEPY= $(INCLUDEDIR)/python$(VERSION)$(DEBUG_EXT) ++CONFINCLUDEPY= $(CONFINCLUDEDIR)/python$(VERSION)$(DEBUG_EXT) + LIBP= $(LIBDIR)/python$(VERSION) + + # Symbols used for using shared libraries +@@ -114,6 +114,8 @@ + EXE= @EXEEXT@ + BUILDEXE= @BUILDEXEEXT@ + ++DEBUG_EXT= @DEBUG_EXT@ ++ + # Short name and location for Mac OS X Python framework + UNIVERSALSDK=@UNIVERSALSDK@ + PYTHONFRAMEWORK= @PYTHONFRAMEWORK@ +@@ -421,7 +423,7 @@ + $(AR) $(ARFLAGS) $@ $(MODOBJS) + $(RANLIB) $@ + +-libpython$(VERSION).so: $(LIBRARY_OBJS) ++libpython$(VERSION)$(DEBUG_EXT).so: $(LIBRARY_OBJS) + if test $(INSTSONAME) != $(LDLIBRARY); then \ + $(LDSHARED) $(LDFLAGS) -Wl,-h$(INSTSONAME) -o $(INSTSONAME) $(LIBRARY_OBJS) $(MODLIBS) $(SHLIBS) $(LIBC) $(LIBM) $(LDLAST); \ + $(LN) -f $(INSTSONAME) $@; \ +@@ -975,8 +977,8 @@ + $(INSTALL_DATA) pyconfig.h $(DESTDIR)$(CONFINCLUDEPY)/pyconfig.h + + # Install the library and miscellaneous stuff needed for extending/embedding +-# This goes into $(exec_prefix) +-LIBPL= $(LIBP)/config ++# This goes into $(exec_prefix)$(DEBUG_EXT) ++LIBPL= $(LIBP)/config$(DEBUG_EXT) + + # pkgconfig directory + LIBPC= $(LIBDIR)/pkgconfig +--- a/Misc/python-config.in ++++ b/Misc/python-config.in +@@ -45,7 +45,7 @@ + + elif opt in ('--libs', '--ldflags'): + libs = getvar('LIBS').split() + getvar('SYSLIBS').split() +- libs.append('-lpython'+pyver) ++ libs.append('-lpython' + pyver + (sys.pydebug and "_d" or "")) + # add the prefix/lib/pythonX.Y/config dir, but only if there is no + # shared library in prefix/lib/. + if opt == '--ldflags': +--- a/Python/dynload_shlib.c ++++ b/Python/dynload_shlib.c +@@ -46,6 +46,10 @@ + {"module.exe", "rb", C_EXTENSION}, + {"MODULE.EXE", "rb", C_EXTENSION}, + #else ++#ifdef Py_DEBUG ++ {"_d.so", "rb", C_EXTENSION}, ++ {"module_d.so", "rb", C_EXTENSION}, ++#endif + {".so", "rb", C_EXTENSION}, + {"module.so", "rb", C_EXTENSION}, + #endif +--- a/Python/sysmodule.c ++++ b/Python/sysmodule.c +@@ -1557,6 +1557,12 @@ + PyString_FromString("legacy")); + #endif + ++#ifdef Py_DEBUG ++ PyDict_SetItemString(sysdict, "pydebug", Py_True); ++#else ++ PyDict_SetItemString(sysdict, "pydebug", Py_False); ++#endif ++ + #undef SET_SYS_FROM_STRING + if (PyErr_Occurred()) + return NULL; +--- a/configure.in ++++ b/configure.in +@@ -632,7 +632,7 @@ + AC_MSG_CHECKING(LIBRARY) + if test -z "$LIBRARY" + then +- LIBRARY='libpython$(VERSION).a' ++ LIBRARY='libpython$(VERSION)$(DEBUG_EXT).a' + fi + AC_MSG_RESULT($LIBRARY) + +@@ -777,8 +777,8 @@ + INSTSONAME="$LDLIBRARY".$SOVERSION + ;; + Linux*|GNU*|NetBSD*|FreeBSD*|DragonFly*) +- LDLIBRARY='libpython$(VERSION).so' +- BLDLIBRARY='-L. -lpython$(VERSION)' ++ LDLIBRARY='libpython$(VERSION)$(DEBUG_EXT).so' ++ BLDLIBRARY='-L. -lpython$(VERSION)$(DEBUG_EXT)' + RUNSHARED=LD_LIBRARY_PATH=`pwd`:${LD_LIBRARY_PATH} + case $ac_sys_system in + FreeBSD*) +@@ -883,6 +883,12 @@ + fi], + [AC_MSG_RESULT(no)]) + ++if test "$Py_DEBUG" = 'true' ++then ++ DEBUG_EXT=_d ++fi ++AC_SUBST(DEBUG_EXT) ++ + # XXX Shouldn't the code above that fiddles with BASECFLAGS and OPT be + # merged with this chunk of code? + +@@ -1722,7 +1728,7 @@ + esac + ;; + CYGWIN*) SO=.dll;; +- *) SO=.so;; ++ *) SO=$DEBUG_EXT.so;; + esac + else + # this might also be a termcap variable, see #610332 --- python2.7-2.7.orig/debian/patches/platform-lsbrelease.diff +++ python2.7-2.7/debian/patches/platform-lsbrelease.diff @@ -0,0 +1,41 @@ +# DP: Use /etc/lsb-release to identify the platform. + +--- a/Lib/platform.py ++++ b/Lib/platform.py +@@ -288,6 +288,10 @@ + id = l[1] + return '', version, id + ++_distributor_id_file_re = re.compile("(?:DISTRIB_ID\s*=)\s*(.*)", re.I) ++_release_file_re = re.compile("(?:DISTRIB_RELEASE\s*=)\s*(.*)", re.I) ++_codename_file_re = re.compile("(?:DISTRIB_CODENAME\s*=)\s*(.*)", re.I) ++ + def linux_distribution(distname='', version='', id='', + + supported_dists=_supported_dists, +@@ -312,6 +316,25 @@ + args given as parameters. + + """ ++ # check for the Debian/Ubuntu /etc/lsb-release file first, needed so ++ # that the distribution doesn't get identified as Debian. ++ try: ++ etclsbrel = open("/etc/lsb-release", "rU") ++ for line in etclsbrel: ++ m = _distributor_id_file_re.search(line) ++ if m: ++ _u_distname = m.group(1).strip() ++ m = _release_file_re.search(line) ++ if m: ++ _u_version = m.group(1).strip() ++ m = _codename_file_re.search(line) ++ if m: ++ _u_id = m.group(1).strip() ++ if _u_distname and _u_version: ++ return (_u_distname, _u_version, _u_id) ++ except (EnvironmentError, UnboundLocalError): ++ pass ++ + try: + etc = os.listdir('/etc') + except os.error: --- python2.7-2.7.orig/debian/patches/issue762963.diff +++ python2.7-2.7/debian/patches/issue762963.diff @@ -0,0 +1,69 @@ +# DP: Fix issue #762963, python loses current timezone. + +Index: python2.6-2.6.5+20100521/Lib/test/test_time.py +=================================================================== +--- python2.6-2.6.5+20100521.orig/Lib/test/test_time.py 2010-05-21 16:20:32.980725082 +0200 ++++ python2.6-2.6.5+20100521/Lib/test/test_time.py 2010-05-21 16:20:33.004709833 +0200 +@@ -1,4 +1,5 @@ + from test import test_support ++from os import environ + import time + import unittest + +@@ -218,6 +219,37 @@ + t1 = time.mktime(lt1) + self.assert_(0 <= (t1-t0) < 0.2) + ++ # Check for problems with tm_gmtoff in struct time. These can bite us ++ # on BSD-derived libc's. The primary (only?) sympton is to break the ++ # strftime %z format. ++ def test_tm_gmtoff1(self): ++ # The %z format is not guaranteed to be supported by the libc ++ # strftime(), but strftime(fmt) is documented to work the same as ++ # as strftime(fmt, localtime()) in all cases. ++ self.failUnlessEqual( ++ time.strftime("%z"), time.strftime("%z", time.localtime())) ++ ++ @unittest.skipUnless(hasattr(time, "tzset"), "tzset not available") ++ def test_tm_gmtoff2(self): ++ # The %z format is not guaranteed to be supported by the libc ++ # strftime(), but if it is US Eastern timezone should never ++ # return +0. ++ eastern = "EST+05EDT,M4.1.0,M10.5.0" ++ org_TZ = environ.get("TZ", None) ++ try: ++ environ["TZ"] = eastern ++ time.tzset() ++ self.assertNotEqual( ++ time.strftime("%z", time.localtime()), "+0000") ++ finally: ++ # Repair TZ environment variable in case any other tests ++ # rely on it. ++ if org_TZ is not None: ++ environ["TZ"] = org_TZ ++ elif "TZ" in environ: ++ del environ["TZ"] ++ time.tzset() ++ + def test_main(): + test_support.run_unittest(TimeTestCase) + +Index: python2.6-2.6.5+20100521/Modules/timemodule.c +=================================================================== +--- python2.6-2.6.5+20100521.orig/Modules/timemodule.c 2010-05-21 16:20:33.000710163 +0200 ++++ python2.6-2.6.5+20100521/Modules/timemodule.c 2010-05-21 16:20:33.008710342 +0200 +@@ -345,6 +345,14 @@ + int y; + memset((void *) p, '\0', sizeof(struct tm)); + ++#ifdef HAVE_TM_ZONE ++ /* Use mktime to normalize the struct tm field tm_gmtoff to ++ the current timezone offset for the benefit of the ++ BSD-style struct tm's that have it. Without this we would ++ lie to these libc's by using a struct tm that says we are ++ in GMT. */ ++ mktime(p); ++#endif + if (!PyArg_Parse(args, "(iiiiiiiii)", + &y, + &p->tm_mon, --- python2.7-2.7.orig/debian/patches/distutils-link.diff +++ python2.7-2.7/debian/patches/distutils-link.diff @@ -0,0 +1,18 @@ +# DP: Don't add standard library dirs to library_dirs and runtime_library_dirs. + +--- a/Lib/distutils/unixccompiler.py ++++ b/Lib/distutils/unixccompiler.py +@@ -213,7 +213,12 @@ + objects, output_dir = self._fix_object_args(objects, output_dir) + libraries, library_dirs, runtime_library_dirs = \ + self._fix_lib_args(libraries, library_dirs, runtime_library_dirs) +- ++ # filter out standard library paths, which are not explicitely needed ++ # for linking ++ library_dirs = [dir for dir in library_dirs ++ if not dir in ('/lib', '/lib64', '/usr/lib', '/usr/lib64')] ++ runtime_library_dirs = [dir for dir in runtime_library_dirs ++ if not dir in ('/lib', '/lib64', '/usr/lib', '/usr/lib64')] + lib_opts = gen_lib_options(self, library_dirs, runtime_library_dirs, + libraries) + if type(output_dir) not in (StringType, NoneType): --- python2.7-2.7.orig/debian/patches/makesetup-bashism.diff +++ python2.7-2.7/debian/patches/makesetup-bashism.diff @@ -0,0 +1,13 @@ +# DP: Fix bashism in makesetup shell script + +--- a/Modules/makesetup ++++ b/Modules/makesetup +@@ -281,7 +281,7 @@ + -) ;; + *) sedf="@sed.in.$$" + trap 'rm -f $sedf' 0 1 2 3 +- echo "1i\\" >$sedf ++ printf "1i\\" >$sedf + str="# Generated automatically from $makepre by makesetup." + echo "$str" >>$sedf + echo "s%_MODOBJS_%$OBJS%" >>$sedf --- python2.7-2.7.orig/debian/patches/enable-fpectl.diff +++ python2.7-2.7/debian/patches/enable-fpectl.diff @@ -0,0 +1,14 @@ +# DP: Enable the build of the fpectl module. + +--- a/setup.py ++++ b/setup.py +@@ -1247,6 +1247,9 @@ + else: + missing.append('_curses_panel') + ++ #fpectl fpectlmodule.c ... ++ exts.append( Extension('fpectl', ['fpectlmodule.c']) ) ++ + # Andrew Kuchling's zlib module. Note that some versions of zlib + # 1.1.3 have security problems. See CERT Advisory CA-2002-07: + # http://www.cert.org/advisories/CA-2002-07.html --- python2.7-2.7.orig/debian/patches/link-system-expat.diff +++ python2.7-2.7/debian/patches/link-system-expat.diff @@ -0,0 +1,22 @@ +# DP: Link with the system expat + +--- a/Modules/Setup.dist ++++ b/Modules/Setup.dist +@@ -180,7 +180,7 @@ + #itertools itertoolsmodule.c # Functions creating iterators for efficient looping + #strop stropmodule.c # String manipulations + #_functools _functoolsmodule.c # Tools for working with functions and callable objects +-#_elementtree -I$(srcdir)/Modules/expat -DHAVE_EXPAT_CONFIG_H -DUSE_PYEXPAT_CAPI _elementtree.c # elementtree accelerator ++#_elementtree -DUSE_PYEXPAT_CAPI _elementtree.c # elementtree accelerator + #_pickle _pickle.c # pickle accelerator + #datetime datetimemodule.c # date/time type + #_bisect _bisectmodule.c # Bisection algorithms +@@ -471,7 +471,7 @@ + # + # More information on Expat can be found at www.libexpat.org. + # +-#pyexpat expat/xmlparse.c expat/xmlrole.c expat/xmltok.c pyexpat.c -I$(srcdir)/Modules/expat -DHAVE_EXPAT_CONFIG_H -DUSE_PYEXPAT_CAPI ++#pyexpat pyexpat.c -lexpat + + + # Hye-Shik Chang's CJKCodecs --- python2.7-2.7.orig/debian/patches/make-pydoc-more-robust.diff +++ python2.7-2.7/debian/patches/make-pydoc-more-robust.diff @@ -0,0 +1,18 @@ +--- a/Lib/pydoc.py ++++ b/Lib/pydoc.py +@@ -1960,10 +1960,14 @@ + if modname[-9:] == '.__init__': + modname = modname[:-9] + ' (package)' + print modname, desc and '- ' + desc ++ def onerror(modname): ++ # Ignore non-ImportError exceptions raised whilst trying to ++ # import modules ++ pass + try: import warnings + except ImportError: pass + else: warnings.filterwarnings('ignore') # ignore problems during import +- ModuleScanner().run(callback, key) ++ ModuleScanner().run(callback, key, onerror=onerror) + + # --------------------------------------------------- web browser interface + --- python2.7-2.7.orig/debian/patches/langpack-gettext.diff +++ python2.7-2.7/debian/patches/langpack-gettext.diff @@ -0,0 +1,34 @@ +# DP: Description: support alternative gettext tree in +# DP: /usr/share/locale-langpack; if a file is present in both trees, +# DP: prefer the newer one +# DP: Upstream status: Ubuntu-Specific + +--- a/Lib/gettext.py ++++ b/Lib/gettext.py +@@ -446,11 +446,26 @@ + if lang == 'C': + break + mofile = os.path.join(localedir, lang, 'LC_MESSAGES', '%s.mo' % domain) ++ mofile_lp = os.path.join("/usr/share/locale-langpack", lang, ++ 'LC_MESSAGES', '%s.mo' % domain) ++ ++ # first look into the standard locale dir, then into the ++ # langpack locale dir ++ ++ # standard mo file + if os.path.exists(mofile): + if all: + result.append(mofile) + else: + return mofile ++ ++ # langpack mofile -> use it ++ if os.path.exists(mofile_lp): ++ if all: ++ result.append(mofile_lp) ++ else: ++ return mofile_lp ++ + return result + + --- python2.7-2.7.orig/debian/patches/hotshot-import.diff +++ python2.7-2.7/debian/patches/hotshot-import.diff @@ -0,0 +1,17 @@ +# DP: hotshot: Check for the availability of the profile and pstats modules. + +--- a/Lib/hotshot/stats.py ++++ b/Lib/hotshot/stats.py +@@ -1,7 +1,10 @@ + """Statistics analyzer for HotShot.""" + +-import profile +-import pstats ++try: ++ import profile ++ import pstats ++except ImportError, e: ++ raise ImportError, str(e) + '; please install the python-profiler package' + + import hotshot.log + --- python2.7-2.7.orig/debian/patches/link-opt.diff +++ python2.7-2.7/debian/patches/link-opt.diff @@ -0,0 +1,24 @@ +# DP: Call the linker with -O1 -Bsymbolic-functions + +--- a/configure.in ++++ b/configure.in +@@ -1829,8 +1829,8 @@ + fi + ;; + Linux*|GNU*|QNX*) +- LDSHARED='$(CC) -shared' +- LDCXXSHARED='$(CXX) -shared';; ++ LDSHARED='$(CC) -shared -Wl,-O1 -Wl,-Bsymbolic-functions' ++ LDCXXSHARED='$(CXX) -shared -Wl,-O1 -Wl,-Bsymbolic-functions';; + BSD/OS*/4*) + LDSHARED="gcc -shared" + LDCXXSHARED="g++ -shared";; +@@ -1932,7 +1932,7 @@ + LINKFORSHARED="-Wl,-E -Wl,+s";; + # LINKFORSHARED="-Wl,-E -Wl,+s -Wl,+b\$(BINLIBDEST)/lib-dynload";; + BSD/OS/4*) LINKFORSHARED="-Xlinker -export-dynamic";; +- Linux*|GNU*) LINKFORSHARED="-Xlinker -export-dynamic";; ++ Linux*|GNU*) LINKFORSHARED="-Xlinker -export-dynamic -Wl,-O1 -Wl,-Bsymbolic-functions";; + # -u libsys_s pulls in all symbols in libsys + Darwin/*) + # -u _PyMac_Error is needed to pull in the mac toolbox glue, --- python2.7-2.7.orig/debian/patches/site-builddir.diff +++ python2.7-2.7/debian/patches/site-builddir.diff @@ -0,0 +1,32 @@ +--- site.py~ 2010-06-29 00:20:33.000000000 +0200 ++++ site.py 2010-06-29 00:26:17.440243273 +0200 +@@ -115,19 +115,6 @@ + sys.path[:] = L + return known_paths + +-# XXX This should not be part of site.py, since it is needed even when +-# using the -S option for Python. See http://www.python.org/sf/586680 +-def addbuilddir(): +- """Append ./build/lib. in case we're running in the build dir +- (especially for Guido :-)""" +- from sysconfig import get_platform +- s = "build/lib.%s-%.3s" % (get_platform(), sys.version) +- if hasattr(sys, 'gettotalrefcount'): +- s += '-pydebug' +- s = os.path.join(os.path.dirname(sys.path.pop()), s) +- sys.path.append(s) +- +- + def _init_pathinfo(): + """Return a set containing all existing directory entries from sys.path""" + d = set() +@@ -538,9 +525,6 @@ + + abs__file__() + known_paths = removeduppaths() +- if (os.name == "posix" and sys.path and +- os.path.basename(sys.path[-1]) == "Modules"): +- addbuilddir() + if ENABLE_USER_SITE is None: + ENABLE_USER_SITE = check_enableusersite() + known_paths = addusersitepackages(known_paths) --- python2.7-2.7.orig/debian/patches/no-large-file-support.diff +++ python2.7-2.7/debian/patches/no-large-file-support.diff @@ -0,0 +1,14 @@ +# DP: disable large file support for GNU/Hurd + +--- a/configure.in ++++ b/configure.in +@@ -1434,6 +1434,9 @@ + use_lfs=no + fi + ++# Don't use largefile support anyway. ++use_lfs=no ++ + if test "$use_lfs" = "yes"; then + # Two defines needed to enable largefile support on various platforms + # These may affect some typedefs --- python2.7-2.7.orig/debian/patches/plat-gnukfreebsd.diff +++ python2.7-2.7/debian/patches/plat-gnukfreebsd.diff @@ -0,0 +1,2478 @@ +--- /dev/null ++++ b/Lib/plat-gnukfreebsd7/IN.py +@@ -0,0 +1,809 @@ ++# Generated by h2py from /usr/include/netinet/in.h ++_NETINET_IN_H = 1 ++ ++# Included from features.h ++_FEATURES_H = 1 ++__USE_ANSI = 1 ++__FAVOR_BSD = 1 ++_ISOC99_SOURCE = 1 ++_POSIX_SOURCE = 1 ++_POSIX_C_SOURCE = 200809L ++_XOPEN_SOURCE = 700 ++_XOPEN_SOURCE_EXTENDED = 1 ++_LARGEFILE64_SOURCE = 1 ++_BSD_SOURCE = 1 ++_SVID_SOURCE = 1 ++_ATFILE_SOURCE = 1 ++_BSD_SOURCE = 1 ++_SVID_SOURCE = 1 ++__USE_ISOC99 = 1 ++__USE_ISOC95 = 1 ++_POSIX_SOURCE = 1 ++_POSIX_C_SOURCE = 2 ++_POSIX_C_SOURCE = 199506L ++_POSIX_C_SOURCE = 200112L ++_POSIX_C_SOURCE = 200809L ++__USE_POSIX_IMPLICITLY = 1 ++__USE_POSIX = 1 ++__USE_POSIX2 = 1 ++__USE_POSIX199309 = 1 ++__USE_POSIX199506 = 1 ++__USE_XOPEN2K = 1 ++__USE_ISOC99 = 1 ++__USE_XOPEN2K8 = 1 ++_ATFILE_SOURCE = 1 ++__USE_XOPEN = 1 ++__USE_XOPEN_EXTENDED = 1 ++__USE_UNIX98 = 1 ++_LARGEFILE_SOURCE = 1 ++__USE_XOPEN2K8 = 1 ++__USE_XOPEN2K = 1 ++__USE_ISOC99 = 1 ++__USE_XOPEN_EXTENDED = 1 ++__USE_LARGEFILE = 1 ++__USE_LARGEFILE64 = 1 ++__USE_FILE_OFFSET64 = 1 ++__USE_MISC = 1 ++__USE_BSD = 1 ++__USE_SVID = 1 ++__USE_ATFILE = 1 ++__USE_GNU = 1 ++__USE_REENTRANT = 1 ++__USE_FORTIFY_LEVEL = 2 ++__USE_FORTIFY_LEVEL = 1 ++__USE_FORTIFY_LEVEL = 0 ++ ++# Included from bits/predefs.h ++__STDC_IEC_559__ = 1 ++__STDC_IEC_559_COMPLEX__ = 1 ++__STDC_ISO_10646__ = 200009L ++__GNU_LIBRARY__ = 6 ++__GLIBC__ = 2 ++__GLIBC_MINOR__ = 11 ++__GLIBC_HAVE_LONG_LONG = 1 ++ ++# Included from sys/cdefs.h ++_SYS_CDEFS_H = 1 ++def __NTH(fct): return fct ++ ++def __NTH(fct): return fct ++ ++def __P(args): return args ++ ++def __PMT(args): return args ++ ++def __STRING(x): return #x ++ ++def __bos(ptr): return __builtin_object_size (ptr, __USE_FORTIFY_LEVEL > 1) ++ ++def __bos0(ptr): return __builtin_object_size (ptr, 0) ++ ++def __warnattr(msg): return __attribute__((__warning__ (msg))) ++ ++__flexarr = [] ++__flexarr = [0] ++__flexarr = [] ++__flexarr = [1] ++def __ASMNAME(cname): return __ASMNAME2 (__USER_LABEL_PREFIX__, cname) ++ ++def __attribute__(xyz): return ++ ++def __attribute_format_arg__(x): return __attribute__ ((__format_arg__ (x))) ++ ++def __attribute_format_arg__(x): return ++ ++ ++# Included from bits/wordsize.h ++__WORDSIZE = 32 ++__LDBL_COMPAT = 1 ++def __LDBL_REDIR_DECL(name): return \ ++ ++__USE_LARGEFILE = 1 ++__USE_LARGEFILE64 = 1 ++__USE_EXTERN_INLINES = 1 ++__USE_EXTERN_INLINES_IN_LIBC = 1 ++ ++# Included from gnu/stubs.h ++ ++# Included from stdint.h ++_STDINT_H = 1 ++ ++# Included from bits/wchar.h ++_BITS_WCHAR_H = 1 ++__WCHAR_MAX = (2147483647) ++__WCHAR_MIN = (-__WCHAR_MAX - 1) ++def __INT64_C(c): return c ## L ++ ++def __UINT64_C(c): return c ## UL ++ ++def __INT64_C(c): return c ## LL ++ ++def __UINT64_C(c): return c ## ULL ++ ++INT8_MIN = (-128) ++INT16_MIN = (-32767-1) ++INT32_MIN = (-2147483647-1) ++INT64_MIN = (-__INT64_C(9223372036854775807)-1) ++INT8_MAX = (127) ++INT16_MAX = (32767) ++INT32_MAX = (2147483647) ++INT64_MAX = (__INT64_C(9223372036854775807)) ++UINT8_MAX = (255) ++UINT16_MAX = (65535) ++UINT64_MAX = (__UINT64_C(18446744073709551615)) ++INT_LEAST8_MIN = (-128) ++INT_LEAST16_MIN = (-32767-1) ++INT_LEAST32_MIN = (-2147483647-1) ++INT_LEAST64_MIN = (-__INT64_C(9223372036854775807)-1) ++INT_LEAST8_MAX = (127) ++INT_LEAST16_MAX = (32767) ++INT_LEAST32_MAX = (2147483647) ++INT_LEAST64_MAX = (__INT64_C(9223372036854775807)) ++UINT_LEAST8_MAX = (255) ++UINT_LEAST16_MAX = (65535) ++UINT_LEAST64_MAX = (__UINT64_C(18446744073709551615)) ++INT_FAST8_MIN = (-128) ++INT_FAST16_MIN = (-9223372036854775807L-1) ++INT_FAST32_MIN = (-9223372036854775807L-1) ++INT_FAST16_MIN = (-2147483647-1) ++INT_FAST32_MIN = (-2147483647-1) ++INT_FAST64_MIN = (-__INT64_C(9223372036854775807)-1) ++INT_FAST8_MAX = (127) ++INT_FAST16_MAX = (9223372036854775807L) ++INT_FAST32_MAX = (9223372036854775807L) ++INT_FAST16_MAX = (2147483647) ++INT_FAST32_MAX = (2147483647) ++INT_FAST64_MAX = (__INT64_C(9223372036854775807)) ++UINT_FAST8_MAX = (255) ++UINT_FAST64_MAX = (__UINT64_C(18446744073709551615)) ++INTPTR_MIN = (-9223372036854775807L-1) ++INTPTR_MAX = (9223372036854775807L) ++INTPTR_MIN = (-2147483647-1) ++INTPTR_MAX = (2147483647) ++INTMAX_MIN = (-__INT64_C(9223372036854775807)-1) ++INTMAX_MAX = (__INT64_C(9223372036854775807)) ++UINTMAX_MAX = (__UINT64_C(18446744073709551615)) ++PTRDIFF_MIN = (-9223372036854775807L-1) ++PTRDIFF_MAX = (9223372036854775807L) ++PTRDIFF_MIN = (-2147483647-1) ++PTRDIFF_MAX = (2147483647) ++SIG_ATOMIC_MIN = (-2147483647-1) ++SIG_ATOMIC_MAX = (2147483647) ++WCHAR_MIN = __WCHAR_MIN ++WCHAR_MAX = __WCHAR_MAX ++def INT8_C(c): return c ++ ++def INT16_C(c): return c ++ ++def INT32_C(c): return c ++ ++def INT64_C(c): return c ## L ++ ++def INT64_C(c): return c ## LL ++ ++def UINT8_C(c): return c ++ ++def UINT16_C(c): return c ++ ++def UINT32_C(c): return c ## U ++ ++def UINT64_C(c): return c ## UL ++ ++def UINT64_C(c): return c ## ULL ++ ++def INTMAX_C(c): return c ## L ++ ++def UINTMAX_C(c): return c ## UL ++ ++def INTMAX_C(c): return c ## LL ++ ++def UINTMAX_C(c): return c ## ULL ++ ++ ++# Included from sys/socket.h ++_SYS_SOCKET_H = 1 ++ ++# Included from sys/uio.h ++_SYS_UIO_H = 1 ++from TYPES import * ++ ++# Included from bits/uio.h ++_BITS_UIO_H = 1 ++from TYPES import * ++UIO_MAXIOV = 1024 ++ ++# Included from bits/sigset.h ++_SIGSET_H_types = 1 ++_SIGSET_H_fns = 1 ++def __sigword(sig): return (((sig) - 1) >> 5) ++ ++def __sigemptyset(set): return \ ++ ++def __sigfillset(set): return \ ++ ++def __sigisemptyset(set): return \ ++ ++ ++# Included from bits/socket.h ++__BITS_SOCKET_H = 1 ++ ++# Included from limits.h ++_LIBC_LIMITS_H_ = 1 ++MB_LEN_MAX = 16 ++_LIMITS_H = 1 ++CHAR_BIT = 8 ++SCHAR_MIN = (-128) ++SCHAR_MAX = 127 ++UCHAR_MAX = 255 ++CHAR_MIN = 0 ++CHAR_MAX = UCHAR_MAX ++CHAR_MIN = SCHAR_MIN ++CHAR_MAX = SCHAR_MAX ++SHRT_MIN = (-32768) ++SHRT_MAX = 32767 ++USHRT_MAX = 65535 ++INT_MAX = 2147483647 ++LONG_MAX = 9223372036854775807L ++LONG_MAX = 2147483647L ++LONG_MIN = (-LONG_MAX - 1L) ++ ++# Included from bits/posix1_lim.h ++_BITS_POSIX1_LIM_H = 1 ++_POSIX_AIO_LISTIO_MAX = 2 ++_POSIX_AIO_MAX = 1 ++_POSIX_ARG_MAX = 4096 ++_POSIX_CHILD_MAX = 25 ++_POSIX_CHILD_MAX = 6 ++_POSIX_DELAYTIMER_MAX = 32 ++_POSIX_HOST_NAME_MAX = 255 ++_POSIX_LINK_MAX = 8 ++_POSIX_LOGIN_NAME_MAX = 9 ++_POSIX_MAX_CANON = 255 ++_POSIX_MAX_INPUT = 255 ++_POSIX_MQ_OPEN_MAX = 8 ++_POSIX_MQ_PRIO_MAX = 32 ++_POSIX_NAME_MAX = 14 ++_POSIX_NGROUPS_MAX = 8 ++_POSIX_NGROUPS_MAX = 0 ++_POSIX_OPEN_MAX = 20 ++_POSIX_OPEN_MAX = 16 ++_POSIX_FD_SETSIZE = _POSIX_OPEN_MAX ++_POSIX_PATH_MAX = 256 ++_POSIX_PIPE_BUF = 512 ++_POSIX_RE_DUP_MAX = 255 ++_POSIX_RTSIG_MAX = 8 ++_POSIX_SEM_NSEMS_MAX = 256 ++_POSIX_SEM_VALUE_MAX = 32767 ++_POSIX_SIGQUEUE_MAX = 32 ++_POSIX_SSIZE_MAX = 32767 ++_POSIX_STREAM_MAX = 8 ++_POSIX_SYMLINK_MAX = 255 ++_POSIX_SYMLOOP_MAX = 8 ++_POSIX_TIMER_MAX = 32 ++_POSIX_TTY_NAME_MAX = 9 ++_POSIX_TZNAME_MAX = 6 ++_POSIX_QLIMIT = 1 ++_POSIX_HIWAT = _POSIX_PIPE_BUF ++_POSIX_UIO_MAXIOV = 16 ++_POSIX_CLOCKRES_MIN = 20000000 ++ ++# Included from bits/local_lim.h ++ ++# Included from sys/syslimits.h ++ARG_MAX = 262144 ++CHILD_MAX = 40 ++LINK_MAX = 32767 ++MAX_CANON = 255 ++MAX_INPUT = 255 ++NAME_MAX = 255 ++NGROUPS_MAX = 1023 ++OPEN_MAX = 64 ++PATH_MAX = 1024 ++PIPE_BUF = 512 ++IOV_MAX = 1024 ++_POSIX_THREAD_KEYS_MAX = 128 ++PTHREAD_KEYS_MAX = 1024 ++_POSIX_THREAD_DESTRUCTOR_ITERATIONS = 4 ++PTHREAD_DESTRUCTOR_ITERATIONS = _POSIX_THREAD_DESTRUCTOR_ITERATIONS ++_POSIX_THREAD_THREADS_MAX = 64 ++PTHREAD_THREADS_MAX = 1024 ++AIO_PRIO_DELTA_MAX = 20 ++PTHREAD_STACK_MIN = 16384 ++TIMER_MAX = 256 ++DELAYTIMER_MAX = 2147483647 ++SSIZE_MAX = LONG_MAX ++NGROUPS_MAX = 8 ++ ++# Included from bits/posix2_lim.h ++_BITS_POSIX2_LIM_H = 1 ++_POSIX2_BC_BASE_MAX = 99 ++_POSIX2_BC_DIM_MAX = 2048 ++_POSIX2_BC_SCALE_MAX = 99 ++_POSIX2_BC_STRING_MAX = 1000 ++_POSIX2_COLL_WEIGHTS_MAX = 2 ++_POSIX2_EXPR_NEST_MAX = 32 ++_POSIX2_LINE_MAX = 2048 ++_POSIX2_RE_DUP_MAX = 255 ++_POSIX2_CHARCLASS_NAME_MAX = 14 ++BC_BASE_MAX = _POSIX2_BC_BASE_MAX ++BC_DIM_MAX = _POSIX2_BC_DIM_MAX ++BC_SCALE_MAX = _POSIX2_BC_SCALE_MAX ++BC_STRING_MAX = _POSIX2_BC_STRING_MAX ++COLL_WEIGHTS_MAX = 255 ++EXPR_NEST_MAX = _POSIX2_EXPR_NEST_MAX ++LINE_MAX = _POSIX2_LINE_MAX ++CHARCLASS_NAME_MAX = 2048 ++RE_DUP_MAX = (0x7fff) ++ ++# Included from bits/xopen_lim.h ++_XOPEN_LIM_H = 1 ++ ++# Included from bits/stdio_lim.h ++L_tmpnam = 20 ++TMP_MAX = 238328 ++FILENAME_MAX = 1024 ++L_ctermid = 9 ++L_cuserid = 9 ++FOPEN_MAX = 64 ++IOV_MAX = 1024 ++_XOPEN_IOV_MAX = _POSIX_UIO_MAXIOV ++NL_ARGMAX = _POSIX_ARG_MAX ++NL_LANGMAX = _POSIX2_LINE_MAX ++NL_MSGMAX = INT_MAX ++NL_NMAX = INT_MAX ++NL_SETMAX = INT_MAX ++NL_TEXTMAX = INT_MAX ++NZERO = 20 ++WORD_BIT = 16 ++WORD_BIT = 32 ++WORD_BIT = 64 ++WORD_BIT = 16 ++WORD_BIT = 32 ++WORD_BIT = 64 ++WORD_BIT = 32 ++LONG_BIT = 32 ++LONG_BIT = 64 ++LONG_BIT = 32 ++LONG_BIT = 64 ++LONG_BIT = 64 ++LONG_BIT = 32 ++ ++# Included from bits/types.h ++_BITS_TYPES_H = 1 ++__S32_TYPE = int ++__SWORD_TYPE = int ++__SLONG32_TYPE = int ++ ++# Included from bits/typesizes.h ++_BITS_TYPESIZES_H = 1 ++__PID_T_TYPE = __S32_TYPE ++__CLOCK_T_TYPE = __S32_TYPE ++__SWBLK_T_TYPE = __S32_TYPE ++__CLOCKID_T_TYPE = __S32_TYPE ++__TIMER_T_TYPE = __S32_TYPE ++__SSIZE_T_TYPE = __SWORD_TYPE ++__FD_SETSIZE = 1024 ++PF_UNSPEC = 0 ++PF_LOCAL = 1 ++PF_UNIX = PF_LOCAL ++PF_FILE = PF_LOCAL ++PF_INET = 2 ++PF_IMPLINK = 3 ++PF_PUP = 4 ++PF_CHAOS = 5 ++PF_NS = 6 ++PF_ISO = 7 ++PF_OSI = PF_ISO ++PF_ECMA = 8 ++PF_DATAKIT = 9 ++PF_CCITT = 10 ++PF_SNA = 11 ++PF_DECnet = 12 ++PF_DLI = 13 ++PF_LAT = 14 ++PF_HYLINK = 15 ++PF_APPLETALK = 16 ++PF_ROUTE = 17 ++PF_LINK = 18 ++PF_XTP = 19 ++PF_COIP = 20 ++PF_CNT = 21 ++PF_RTIP = 22 ++PF_IPX = 23 ++PF_SIP = 24 ++PF_PIP = 25 ++PF_ISDN = 26 ++PF_KEY = 27 ++PF_INET6 = 28 ++PF_NATM = 29 ++PF_ATM = 30 ++PF_HDRCMPLT = 31 ++PF_NETGRAPH = 32 ++PF_MAX = 33 ++AF_UNSPEC = PF_UNSPEC ++AF_LOCAL = PF_LOCAL ++AF_UNIX = PF_UNIX ++AF_FILE = PF_FILE ++AF_INET = PF_INET ++AF_IMPLINK = PF_IMPLINK ++AF_PUP = PF_PUP ++AF_CHAOS = PF_CHAOS ++AF_NS = PF_NS ++AF_ISO = PF_ISO ++AF_OSI = PF_OSI ++AF_ECMA = PF_ECMA ++AF_DATAKIT = PF_DATAKIT ++AF_CCITT = PF_CCITT ++AF_SNA = PF_SNA ++AF_DECnet = PF_DECnet ++AF_DLI = PF_DLI ++AF_LAT = PF_LAT ++AF_HYLINK = PF_HYLINK ++AF_APPLETALK = PF_APPLETALK ++AF_ROUTE = PF_ROUTE ++AF_LINK = PF_LINK ++pseudo_AF_XTP = PF_XTP ++AF_COIP = PF_COIP ++AF_CNT = PF_CNT ++pseudo_AF_RTIP = PF_RTIP ++AF_IPX = PF_IPX ++AF_SIP = PF_SIP ++pseudo_AF_PIP = PF_PIP ++AF_ISDN = PF_ISDN ++AF_E164 = AF_ISDN ++pseudo_AF_KEY = PF_KEY ++AF_INET6 = PF_INET6 ++AF_NATM = PF_NATM ++AF_ATM = PF_ATM ++pseudo_AF_HDRCMPLT = PF_HDRCMPLT ++AF_NETGRAPH = PF_NETGRAPH ++AF_MAX = PF_MAX ++SOMAXCONN = 128 ++ ++# Included from bits/sockaddr.h ++_BITS_SOCKADDR_H = 1 ++def __SOCKADDR_COMMON(sa_prefix): return \ ++ ++_HAVE_SA_LEN = 1 ++_SS_SIZE = 128 ++def CMSG_FIRSTHDR(mhdr): return \ ++ ++CMGROUP_MAX = 16 ++SOL_SOCKET = 0xffff ++LOCAL_PEERCRED = 0x001 ++LOCAL_CREDS = 0x002 ++LOCAL_CONNWAIT = 0x004 ++ ++# Included from bits/socket2.h ++def IN_CLASSA(a): return ((((in_addr_t)(a)) & (-2147483648)) == 0) ++ ++IN_CLASSA_NET = (-16777216) ++IN_CLASSA_NSHIFT = 24 ++IN_CLASSA_HOST = ((-1) & ~IN_CLASSA_NET) ++IN_CLASSA_MAX = 128 ++def IN_CLASSB(a): return ((((in_addr_t)(a)) & (-1073741824)) == (-2147483648)) ++ ++IN_CLASSB_NET = (-65536) ++IN_CLASSB_NSHIFT = 16 ++IN_CLASSB_HOST = ((-1) & ~IN_CLASSB_NET) ++IN_CLASSB_MAX = 65536 ++def IN_CLASSC(a): return ((((in_addr_t)(a)) & (-536870912)) == (-1073741824)) ++ ++IN_CLASSC_NET = (-256) ++IN_CLASSC_NSHIFT = 8 ++IN_CLASSC_HOST = ((-1) & ~IN_CLASSC_NET) ++def IN_CLASSD(a): return ((((in_addr_t)(a)) & (-268435456)) == (-536870912)) ++ ++def IN_MULTICAST(a): return IN_CLASSD(a) ++ ++def IN_EXPERIMENTAL(a): return ((((in_addr_t)(a)) & (-536870912)) == (-536870912)) ++ ++def IN_BADCLASS(a): return ((((in_addr_t)(a)) & (-268435456)) == (-268435456)) ++ ++IN_LOOPBACKNET = 127 ++INET_ADDRSTRLEN = 16 ++INET6_ADDRSTRLEN = 46 ++ ++# Included from bits/in.h ++IMPLINK_IP = 155 ++IMPLINK_LOWEXPER = 156 ++IMPLINK_HIGHEXPER = 158 ++IPPROTO_DIVERT = 258 ++SOL_IP = 0 ++IP_OPTIONS = 1 ++IP_HDRINCL = 2 ++IP_TOS = 3 ++IP_TTL = 4 ++IP_RECVOPTS = 5 ++IP_RECVRETOPTS = 6 ++IP_RECVDSTADDR = 7 ++IP_SENDSRCADDR = IP_RECVDSTADDR ++IP_RETOPTS = 8 ++IP_MULTICAST_IF = 9 ++IP_MULTICAST_TTL = 10 ++IP_MULTICAST_LOOP = 11 ++IP_ADD_MEMBERSHIP = 12 ++IP_DROP_MEMBERSHIP = 13 ++IP_MULTICAST_VIF = 14 ++IP_RSVP_ON = 15 ++IP_RSVP_OFF = 16 ++IP_RSVP_VIF_ON = 17 ++IP_RSVP_VIF_OFF = 18 ++IP_PORTRANGE = 19 ++IP_RECVIF = 20 ++IP_IPSEC_POLICY = 21 ++IP_FAITH = 22 ++IP_ONESBCAST = 23 ++IP_NONLOCALOK = 24 ++IP_FW_TABLE_ADD = 40 ++IP_FW_TABLE_DEL = 41 ++IP_FW_TABLE_FLUSH = 42 ++IP_FW_TABLE_GETSIZE = 43 ++IP_FW_TABLE_LIST = 44 ++IP_FW_ADD = 50 ++IP_FW_DEL = 51 ++IP_FW_FLUSH = 52 ++IP_FW_ZERO = 53 ++IP_FW_GET = 54 ++IP_FW_RESETLOG = 55 ++IP_FW_NAT_CFG = 56 ++IP_FW_NAT_DEL = 57 ++IP_FW_NAT_GET_CONFIG = 58 ++IP_FW_NAT_GET_LOG = 59 ++IP_DUMMYNET_CONFIGURE = 60 ++IP_DUMMYNET_DEL = 61 ++IP_DUMMYNET_FLUSH = 62 ++IP_DUMMYNET_GET = 64 ++IP_RECVTTL = 65 ++IP_MINTTL = 66 ++IP_DONTFRAG = 67 ++IP_ADD_SOURCE_MEMBERSHIP = 70 ++IP_DROP_SOURCE_MEMBERSHIP = 71 ++IP_BLOCK_SOURCE = 72 ++IP_UNBLOCK_SOURCE = 73 ++IP_MSFILTER = 74 ++MCAST_JOIN_GROUP = 80 ++MCAST_LEAVE_GROUP = 81 ++MCAST_JOIN_SOURCE_GROUP = 82 ++MCAST_LEAVE_SOURCE_GROUP = 83 ++MCAST_BLOCK_SOURCE = 84 ++MCAST_UNBLOCK_SOURCE = 85 ++IP_DEFAULT_MULTICAST_TTL = 1 ++IP_DEFAULT_MULTICAST_LOOP = 1 ++IP_MIN_MEMBERSHIPS = 31 ++IP_MAX_MEMBERSHIPS = 4095 ++IP_MAX_SOURCE_FILTER = 1024 ++MCAST_UNDEFINED = 0 ++MCAST_INCLUDE = 1 ++MCAST_EXCLUDE = 2 ++IP_PORTRANGE_DEFAULT = 0 ++IP_PORTRANGE_HIGH = 1 ++IP_PORTRANGE_LOW = 2 ++IPCTL_FORWARDING = 1 ++IPCTL_SENDREDIRECTS = 2 ++IPCTL_DEFTTL = 3 ++IPCTL_DEFMTU = 4 ++IPCTL_RTEXPIRE = 5 ++IPCTL_RTMINEXPIRE = 6 ++IPCTL_RTMAXCACHE = 7 ++IPCTL_SOURCEROUTE = 8 ++IPCTL_DIRECTEDBROADCAST = 9 ++IPCTL_INTRQMAXLEN = 10 ++IPCTL_INTRQDROPS = 11 ++IPCTL_STATS = 12 ++IPCTL_ACCEPTSOURCEROUTE = 13 ++IPCTL_FASTFORWARDING = 14 ++IPCTL_KEEPFAITH = 15 ++IPCTL_GIF_TTL = 16 ++IPCTL_MAXID = 17 ++IPV6_SOCKOPT_RESERVED1 = 3 ++IPV6_UNICAST_HOPS = 4 ++IPV6_MULTICAST_IF = 9 ++IPV6_MULTICAST_HOPS = 10 ++IPV6_MULTICAST_LOOP = 11 ++IPV6_JOIN_GROUP = 12 ++IPV6_LEAVE_GROUP = 13 ++IPV6_PORTRANGE = 14 ++ICMP6_FILTER = 18 ++IPV6_CHECKSUM = 26 ++IPV6_V6ONLY = 27 ++IPV6_IPSEC_POLICY = 28 ++IPV6_FAITH = 29 ++IPV6_FW_ADD = 30 ++IPV6_FW_DEL = 31 ++IPV6_FW_FLUSH = 32 ++IPV6_FW_ZERO = 33 ++IPV6_FW_GET = 34 ++IPV6_RTHDRDSTOPTS = 35 ++IPV6_RECVPKTINFO = 36 ++IPV6_RECVHOPLIMIT = 37 ++IPV6_RECVRTHDR = 38 ++IPV6_RECVHOPOPTS = 39 ++IPV6_RECVDSTOPTS = 40 ++IPV6_USE_MIN_MTU = 42 ++IPV6_RECVPATHMTU = 43 ++IPV6_PATHMTU = 44 ++IPV6_PKTINFO = 46 ++IPV6_HOPLIMIT = 47 ++IPV6_NEXTHOP = 48 ++IPV6_HOPOPTS = 49 ++IPV6_DSTOPTS = 50 ++IPV6_RTHDR = 51 ++IPV6_RECVTCLASS = 57 ++IPV6_AUTOFLOWLABEL = 59 ++IPV6_TCLASS = 61 ++IPV6_DONTFRAG = 62 ++IPV6_PREFER_TEMPADDR = 63 ++IPV6_ADD_MEMBERSHIP = IPV6_JOIN_GROUP ++IPV6_DROP_MEMBERSHIP = IPV6_LEAVE_GROUP ++IPV6_RXHOPOPTS = IPV6_HOPOPTS ++IPV6_RXDSTOPTS = IPV6_DSTOPTS ++SOL_IPV6 = 41 ++SOL_ICMPV6 = 58 ++IPV6_DEFAULT_MULTICAST_HOPS = 1 ++IPV6_DEFAULT_MULTICAST_LOOP = 1 ++IPV6_PORTRANGE_DEFAULT = 0 ++IPV6_PORTRANGE_HIGH = 1 ++IPV6_PORTRANGE_LOW = 2 ++IPV6_RTHDR_LOOSE = 0 ++IPV6_RTHDR_STRICT = 1 ++IPV6_RTHDR_TYPE_0 = 0 ++IPV6CTL_FORWARDING = 1 ++IPV6CTL_SENDREDIRECTS = 2 ++IPV6CTL_DEFHLIM = 3 ++IPV6CTL_FORWSRCRT = 5 ++IPV6CTL_STATS = 6 ++IPV6CTL_MRTSTATS = 7 ++IPV6CTL_MRTPROTO = 8 ++IPV6CTL_MAXFRAGPACKETS = 9 ++IPV6CTL_SOURCECHECK = 10 ++IPV6CTL_SOURCECHECK_LOGINT = 11 ++IPV6CTL_ACCEPT_RTADV = 12 ++IPV6CTL_KEEPFAITH = 13 ++IPV6CTL_LOG_INTERVAL = 14 ++IPV6CTL_HDRNESTLIMIT = 15 ++IPV6CTL_DAD_COUNT = 16 ++IPV6CTL_AUTO_FLOWLABEL = 17 ++IPV6CTL_DEFMCASTHLIM = 18 ++IPV6CTL_GIF_HLIM = 19 ++IPV6CTL_KAME_VERSION = 20 ++IPV6CTL_USE_DEPRECATED = 21 ++IPV6CTL_RR_PRUNE = 22 ++IPV6CTL_V6ONLY = 24 ++IPV6CTL_RTEXPIRE = 25 ++IPV6CTL_RTMINEXPIRE = 26 ++IPV6CTL_RTMAXCACHE = 27 ++IPV6CTL_USETEMPADDR = 32 ++IPV6CTL_TEMPPLTIME = 33 ++IPV6CTL_TEMPVLTIME = 34 ++IPV6CTL_AUTO_LINKLOCAL = 35 ++IPV6CTL_RIP6STATS = 36 ++IPV6CTL_PREFER_TEMPADDR = 37 ++IPV6CTL_ADDRCTLPOLICY = 38 ++IPV6CTL_USE_DEFAULTZONE = 39 ++IPV6CTL_MAXFRAGS = 41 ++IPV6CTL_MCAST_PMTU = 44 ++IPV6CTL_STEALTH = 45 ++ICMPV6CTL_ND6_ONLINKNSRFC4861 = 47 ++IPV6CTL_MAXID = 48 ++ ++# Included from endian.h ++_ENDIAN_H = 1 ++__LITTLE_ENDIAN = 1234 ++__BIG_ENDIAN = 4321 ++__PDP_ENDIAN = 3412 ++ ++# Included from bits/endian.h ++__BYTE_ORDER = __LITTLE_ENDIAN ++__FLOAT_WORD_ORDER = __BYTE_ORDER ++LITTLE_ENDIAN = __LITTLE_ENDIAN ++BIG_ENDIAN = __BIG_ENDIAN ++PDP_ENDIAN = __PDP_ENDIAN ++BYTE_ORDER = __BYTE_ORDER ++ ++# Included from bits/byteswap.h ++_BITS_BYTESWAP_H = 1 ++def __bswap_constant_16(x): return \ ++ ++def __bswap_16(x): return \ ++ ++def __bswap_16(x): return \ ++ ++def __bswap_constant_32(x): return \ ++ ++def __bswap_32(x): return \ ++ ++def __bswap_32(x): return \ ++ ++def __bswap_32(x): return \ ++ ++def __bswap_constant_64(x): return \ ++ ++def __bswap_64(x): return \ ++ ++def htobe16(x): return __bswap_16 (x) ++ ++def htole16(x): return (x) ++ ++def be16toh(x): return __bswap_16 (x) ++ ++def le16toh(x): return (x) ++ ++def htobe32(x): return __bswap_32 (x) ++ ++def htole32(x): return (x) ++ ++def be32toh(x): return __bswap_32 (x) ++ ++def le32toh(x): return (x) ++ ++def htobe64(x): return __bswap_64 (x) ++ ++def htole64(x): return (x) ++ ++def be64toh(x): return __bswap_64 (x) ++ ++def le64toh(x): return (x) ++ ++def htobe16(x): return (x) ++ ++def htole16(x): return __bswap_16 (x) ++ ++def be16toh(x): return (x) ++ ++def le16toh(x): return __bswap_16 (x) ++ ++def htobe32(x): return (x) ++ ++def htole32(x): return __bswap_32 (x) ++ ++def be32toh(x): return (x) ++ ++def le32toh(x): return __bswap_32 (x) ++ ++def htobe64(x): return (x) ++ ++def htole64(x): return __bswap_64 (x) ++ ++def be64toh(x): return (x) ++ ++def le64toh(x): return __bswap_64 (x) ++ ++def ntohl(x): return (x) ++ ++def ntohs(x): return (x) ++ ++def htonl(x): return (x) ++ ++def htons(x): return (x) ++ ++def ntohl(x): return __bswap_32 (x) ++ ++def ntohs(x): return __bswap_16 (x) ++ ++def htonl(x): return __bswap_32 (x) ++ ++def htons(x): return __bswap_16 (x) ++ ++def IN6_IS_ADDR_UNSPECIFIED(a): return \ ++ ++def IN6_IS_ADDR_LOOPBACK(a): return \ ++ ++def IN6_IS_ADDR_LINKLOCAL(a): return \ ++ ++def IN6_IS_ADDR_SITELOCAL(a): return \ ++ ++def IN6_IS_ADDR_V4MAPPED(a): return \ ++ ++def IN6_IS_ADDR_V4COMPAT(a): return \ ++ ++def IN6_IS_ADDR_MC_NODELOCAL(a): return \ ++ ++def IN6_IS_ADDR_MC_LINKLOCAL(a): return \ ++ ++def IN6_IS_ADDR_MC_SITELOCAL(a): return \ ++ ++def IN6_IS_ADDR_MC_ORGLOCAL(a): return \ ++ ++def IN6_IS_ADDR_MC_GLOBAL(a): return \ ++ +--- /dev/null ++++ b/Lib/plat-gnukfreebsd7/TYPES.py +@@ -0,0 +1,303 @@ ++# Generated by h2py from /usr/include/sys/types.h ++_SYS_TYPES_H = 1 ++ ++# Included from features.h ++_FEATURES_H = 1 ++__USE_ANSI = 1 ++__FAVOR_BSD = 1 ++_ISOC99_SOURCE = 1 ++_POSIX_SOURCE = 1 ++_POSIX_C_SOURCE = 200809L ++_XOPEN_SOURCE = 700 ++_XOPEN_SOURCE_EXTENDED = 1 ++_LARGEFILE64_SOURCE = 1 ++_BSD_SOURCE = 1 ++_SVID_SOURCE = 1 ++_ATFILE_SOURCE = 1 ++_BSD_SOURCE = 1 ++_SVID_SOURCE = 1 ++__USE_ISOC99 = 1 ++__USE_ISOC95 = 1 ++_POSIX_SOURCE = 1 ++_POSIX_C_SOURCE = 2 ++_POSIX_C_SOURCE = 199506L ++_POSIX_C_SOURCE = 200112L ++_POSIX_C_SOURCE = 200809L ++__USE_POSIX_IMPLICITLY = 1 ++__USE_POSIX = 1 ++__USE_POSIX2 = 1 ++__USE_POSIX199309 = 1 ++__USE_POSIX199506 = 1 ++__USE_XOPEN2K = 1 ++__USE_ISOC99 = 1 ++__USE_XOPEN2K8 = 1 ++_ATFILE_SOURCE = 1 ++__USE_XOPEN = 1 ++__USE_XOPEN_EXTENDED = 1 ++__USE_UNIX98 = 1 ++_LARGEFILE_SOURCE = 1 ++__USE_XOPEN2K8 = 1 ++__USE_XOPEN2K = 1 ++__USE_ISOC99 = 1 ++__USE_XOPEN_EXTENDED = 1 ++__USE_LARGEFILE = 1 ++__USE_LARGEFILE64 = 1 ++__USE_FILE_OFFSET64 = 1 ++__USE_MISC = 1 ++__USE_BSD = 1 ++__USE_SVID = 1 ++__USE_ATFILE = 1 ++__USE_GNU = 1 ++__USE_REENTRANT = 1 ++__USE_FORTIFY_LEVEL = 2 ++__USE_FORTIFY_LEVEL = 1 ++__USE_FORTIFY_LEVEL = 0 ++ ++# Included from bits/predefs.h ++__STDC_IEC_559__ = 1 ++__STDC_IEC_559_COMPLEX__ = 1 ++__STDC_ISO_10646__ = 200009L ++__GNU_LIBRARY__ = 6 ++__GLIBC__ = 2 ++__GLIBC_MINOR__ = 11 ++__GLIBC_HAVE_LONG_LONG = 1 ++ ++# Included from sys/cdefs.h ++_SYS_CDEFS_H = 1 ++def __NTH(fct): return fct ++ ++def __NTH(fct): return fct ++ ++def __P(args): return args ++ ++def __PMT(args): return args ++ ++def __STRING(x): return #x ++ ++def __bos(ptr): return __builtin_object_size (ptr, __USE_FORTIFY_LEVEL > 1) ++ ++def __bos0(ptr): return __builtin_object_size (ptr, 0) ++ ++def __warnattr(msg): return __attribute__((__warning__ (msg))) ++ ++__flexarr = [] ++__flexarr = [0] ++__flexarr = [] ++__flexarr = [1] ++def __ASMNAME(cname): return __ASMNAME2 (__USER_LABEL_PREFIX__, cname) ++ ++def __attribute__(xyz): return ++ ++def __attribute_format_arg__(x): return __attribute__ ((__format_arg__ (x))) ++ ++def __attribute_format_arg__(x): return ++ ++ ++# Included from bits/wordsize.h ++__WORDSIZE = 32 ++__LDBL_COMPAT = 1 ++def __LDBL_REDIR_DECL(name): return \ ++ ++__USE_LARGEFILE = 1 ++__USE_LARGEFILE64 = 1 ++__USE_EXTERN_INLINES = 1 ++__USE_EXTERN_INLINES_IN_LIBC = 1 ++ ++# Included from gnu/stubs.h ++ ++# Included from bits/types.h ++_BITS_TYPES_H = 1 ++__S32_TYPE = int ++__SWORD_TYPE = int ++__SLONG32_TYPE = int ++ ++# Included from bits/typesizes.h ++_BITS_TYPESIZES_H = 1 ++__PID_T_TYPE = __S32_TYPE ++__CLOCK_T_TYPE = __S32_TYPE ++__SWBLK_T_TYPE = __S32_TYPE ++__CLOCKID_T_TYPE = __S32_TYPE ++__TIMER_T_TYPE = __S32_TYPE ++__SSIZE_T_TYPE = __SWORD_TYPE ++__FD_SETSIZE = 1024 ++ ++# Included from time.h ++_TIME_H = 1 ++ ++# Included from bits/time.h ++_BITS_TIME_H = 1 ++CLOCKS_PER_SEC = 1000000l ++CLK_TCK = 128 ++CLOCK_REALTIME = 0 ++CLOCK_PROCESS_CPUTIME_ID = 2 ++CLOCK_THREAD_CPUTIME_ID = 3 ++CLOCK_MONOTONIC = 4 ++CLOCK_VIRTUAL = 1 ++CLOCK_PROF = 2 ++CLOCK_UPTIME = 5 ++CLOCK_UPTIME_PRECISE = 7 ++CLOCK_UPTIME_FAST = 8 ++CLOCK_REALTIME_PRECISE = 9 ++CLOCK_REALTIME_FAST = 10 ++CLOCK_MONOTONIC_PRECISE = 11 ++CLOCK_MONOTONIC_FAST = 12 ++CLOCK_SECOND = 13 ++TIMER_RELTIME = 0 ++TIMER_ABSTIME = 1 ++_STRUCT_TIMEVAL = 1 ++CLK_TCK = CLOCKS_PER_SEC ++__clock_t_defined = 1 ++__time_t_defined = 1 ++__clockid_t_defined = 1 ++__timer_t_defined = 1 ++__timespec_defined = 1 ++ ++# Included from xlocale.h ++_XLOCALE_H = 1 ++def __isleap(year): return \ ++ ++__BIT_TYPES_DEFINED__ = 1 ++ ++# Included from endian.h ++_ENDIAN_H = 1 ++__LITTLE_ENDIAN = 1234 ++__BIG_ENDIAN = 4321 ++__PDP_ENDIAN = 3412 ++ ++# Included from bits/endian.h ++__BYTE_ORDER = __LITTLE_ENDIAN ++__FLOAT_WORD_ORDER = __BYTE_ORDER ++LITTLE_ENDIAN = __LITTLE_ENDIAN ++BIG_ENDIAN = __BIG_ENDIAN ++PDP_ENDIAN = __PDP_ENDIAN ++BYTE_ORDER = __BYTE_ORDER ++ ++# Included from bits/byteswap.h ++_BITS_BYTESWAP_H = 1 ++def __bswap_constant_16(x): return \ ++ ++def __bswap_16(x): return \ ++ ++def __bswap_16(x): return \ ++ ++def __bswap_constant_32(x): return \ ++ ++def __bswap_32(x): return \ ++ ++def __bswap_32(x): return \ ++ ++def __bswap_32(x): return \ ++ ++def __bswap_constant_64(x): return \ ++ ++def __bswap_64(x): return \ ++ ++def htobe16(x): return __bswap_16 (x) ++ ++def htole16(x): return (x) ++ ++def be16toh(x): return __bswap_16 (x) ++ ++def le16toh(x): return (x) ++ ++def htobe32(x): return __bswap_32 (x) ++ ++def htole32(x): return (x) ++ ++def be32toh(x): return __bswap_32 (x) ++ ++def le32toh(x): return (x) ++ ++def htobe64(x): return __bswap_64 (x) ++ ++def htole64(x): return (x) ++ ++def be64toh(x): return __bswap_64 (x) ++ ++def le64toh(x): return (x) ++ ++def htobe16(x): return (x) ++ ++def htole16(x): return __bswap_16 (x) ++ ++def be16toh(x): return (x) ++ ++def le16toh(x): return __bswap_16 (x) ++ ++def htobe32(x): return (x) ++ ++def htole32(x): return __bswap_32 (x) ++ ++def be32toh(x): return (x) ++ ++def le32toh(x): return __bswap_32 (x) ++ ++def htobe64(x): return (x) ++ ++def htole64(x): return __bswap_64 (x) ++ ++def be64toh(x): return (x) ++ ++def le64toh(x): return __bswap_64 (x) ++ ++ ++# Included from sys/select.h ++_SYS_SELECT_H = 1 ++ ++# Included from bits/select.h ++def __FD_ZERO(fdsp): return \ ++ ++def __FD_ZERO(set): return \ ++ ++ ++# Included from bits/sigset.h ++_SIGSET_H_types = 1 ++_SIGSET_H_fns = 1 ++def __sigword(sig): return (((sig) - 1) >> 5) ++ ++def __sigemptyset(set): return \ ++ ++def __sigfillset(set): return \ ++ ++def __sigisemptyset(set): return \ ++ ++def __FDELT(d): return ((d) / __NFDBITS) ++ ++FD_SETSIZE = __FD_SETSIZE ++def FD_ZERO(fdsetp): return __FD_ZERO (fdsetp) ++ ++ ++# Included from sys/sysmacros.h ++_SYS_SYSMACROS_H = 1 ++def minor(dev): return ((int)((dev) & (-65281))) ++ ++def gnu_dev_major(dev): return major (dev) ++ ++def gnu_dev_minor(dev): return minor (dev) ++ ++ ++# Included from bits/pthreadtypes.h ++_BITS_PTHREADTYPES_H = 1 ++ ++# Included from bits/sched.h ++SCHED_OTHER = 2 ++SCHED_FIFO = 1 ++SCHED_RR = 3 ++CSIGNAL = 0x000000ff ++CLONE_VM = 0x00000100 ++CLONE_FS = 0x00000200 ++CLONE_FILES = 0x00000400 ++CLONE_SIGHAND = 0x00000800 ++CLONE_PTRACE = 0x00002000 ++CLONE_VFORK = 0x00004000 ++CLONE_SYSVSEM = 0x00040000 ++__defined_schedparam = 1 ++__CPU_SETSIZE = 128 ++def __CPUELT(cpu): return ((cpu) / __NCPUBITS) ++ ++def __CPU_ALLOC_SIZE(count): return \ ++ ++def __CPU_ALLOC(count): return __sched_cpualloc (count) ++ ++def __CPU_FREE(cpuset): return __sched_cpufree (cpuset) ++ +--- /dev/null ++++ b/Lib/plat-gnukfreebsd7/DLFCN.py +@@ -0,0 +1,118 @@ ++# Generated by h2py from /usr/include/dlfcn.h ++_DLFCN_H = 1 ++ ++# Included from features.h ++_FEATURES_H = 1 ++__USE_ANSI = 1 ++__FAVOR_BSD = 1 ++_ISOC99_SOURCE = 1 ++_POSIX_SOURCE = 1 ++_POSIX_C_SOURCE = 200809L ++_XOPEN_SOURCE = 700 ++_XOPEN_SOURCE_EXTENDED = 1 ++_LARGEFILE64_SOURCE = 1 ++_BSD_SOURCE = 1 ++_SVID_SOURCE = 1 ++_ATFILE_SOURCE = 1 ++_BSD_SOURCE = 1 ++_SVID_SOURCE = 1 ++__USE_ISOC99 = 1 ++__USE_ISOC95 = 1 ++_POSIX_SOURCE = 1 ++_POSIX_C_SOURCE = 2 ++_POSIX_C_SOURCE = 199506L ++_POSIX_C_SOURCE = 200112L ++_POSIX_C_SOURCE = 200809L ++__USE_POSIX_IMPLICITLY = 1 ++__USE_POSIX = 1 ++__USE_POSIX2 = 1 ++__USE_POSIX199309 = 1 ++__USE_POSIX199506 = 1 ++__USE_XOPEN2K = 1 ++__USE_ISOC99 = 1 ++__USE_XOPEN2K8 = 1 ++_ATFILE_SOURCE = 1 ++__USE_XOPEN = 1 ++__USE_XOPEN_EXTENDED = 1 ++__USE_UNIX98 = 1 ++_LARGEFILE_SOURCE = 1 ++__USE_XOPEN2K8 = 1 ++__USE_XOPEN2K = 1 ++__USE_ISOC99 = 1 ++__USE_XOPEN_EXTENDED = 1 ++__USE_LARGEFILE = 1 ++__USE_LARGEFILE64 = 1 ++__USE_FILE_OFFSET64 = 1 ++__USE_MISC = 1 ++__USE_BSD = 1 ++__USE_SVID = 1 ++__USE_ATFILE = 1 ++__USE_GNU = 1 ++__USE_REENTRANT = 1 ++__USE_FORTIFY_LEVEL = 2 ++__USE_FORTIFY_LEVEL = 1 ++__USE_FORTIFY_LEVEL = 0 ++ ++# Included from bits/predefs.h ++__STDC_IEC_559__ = 1 ++__STDC_IEC_559_COMPLEX__ = 1 ++__STDC_ISO_10646__ = 200009L ++__GNU_LIBRARY__ = 6 ++__GLIBC__ = 2 ++__GLIBC_MINOR__ = 11 ++__GLIBC_HAVE_LONG_LONG = 1 ++ ++# Included from sys/cdefs.h ++_SYS_CDEFS_H = 1 ++def __NTH(fct): return fct ++ ++def __NTH(fct): return fct ++ ++def __P(args): return args ++ ++def __PMT(args): return args ++ ++def __STRING(x): return #x ++ ++def __bos(ptr): return __builtin_object_size (ptr, __USE_FORTIFY_LEVEL > 1) ++ ++def __bos0(ptr): return __builtin_object_size (ptr, 0) ++ ++def __warnattr(msg): return __attribute__((__warning__ (msg))) ++ ++__flexarr = [] ++__flexarr = [0] ++__flexarr = [] ++__flexarr = [1] ++def __ASMNAME(cname): return __ASMNAME2 (__USER_LABEL_PREFIX__, cname) ++ ++def __attribute__(xyz): return ++ ++def __attribute_format_arg__(x): return __attribute__ ((__format_arg__ (x))) ++ ++def __attribute_format_arg__(x): return ++ ++ ++# Included from bits/wordsize.h ++__WORDSIZE = 32 ++__LDBL_COMPAT = 1 ++def __LDBL_REDIR_DECL(name): return \ ++ ++__USE_LARGEFILE = 1 ++__USE_LARGEFILE64 = 1 ++__USE_EXTERN_INLINES = 1 ++__USE_EXTERN_INLINES_IN_LIBC = 1 ++ ++# Included from gnu/stubs.h ++ ++# Included from bits/dlfcn.h ++RTLD_LAZY = 0x00001 ++RTLD_NOW = 0x00002 ++RTLD_BINDING_MASK = 0x3 ++RTLD_NOLOAD = 0x00004 ++RTLD_DEEPBIND = 0x00008 ++RTLD_GLOBAL = 0x00100 ++RTLD_LOCAL = 0 ++RTLD_NODELETE = 0x01000 ++LM_ID_BASE = 0 ++LM_ID_NEWLM = -1 +--- /dev/null ++++ b/Lib/plat-gnukfreebsd8/IN.py +@@ -0,0 +1,809 @@ ++# Generated by h2py from /usr/include/netinet/in.h ++_NETINET_IN_H = 1 ++ ++# Included from features.h ++_FEATURES_H = 1 ++__USE_ANSI = 1 ++__FAVOR_BSD = 1 ++_ISOC99_SOURCE = 1 ++_POSIX_SOURCE = 1 ++_POSIX_C_SOURCE = 200809L ++_XOPEN_SOURCE = 700 ++_XOPEN_SOURCE_EXTENDED = 1 ++_LARGEFILE64_SOURCE = 1 ++_BSD_SOURCE = 1 ++_SVID_SOURCE = 1 ++_ATFILE_SOURCE = 1 ++_BSD_SOURCE = 1 ++_SVID_SOURCE = 1 ++__USE_ISOC99 = 1 ++__USE_ISOC95 = 1 ++_POSIX_SOURCE = 1 ++_POSIX_C_SOURCE = 2 ++_POSIX_C_SOURCE = 199506L ++_POSIX_C_SOURCE = 200112L ++_POSIX_C_SOURCE = 200809L ++__USE_POSIX_IMPLICITLY = 1 ++__USE_POSIX = 1 ++__USE_POSIX2 = 1 ++__USE_POSIX199309 = 1 ++__USE_POSIX199506 = 1 ++__USE_XOPEN2K = 1 ++__USE_ISOC99 = 1 ++__USE_XOPEN2K8 = 1 ++_ATFILE_SOURCE = 1 ++__USE_XOPEN = 1 ++__USE_XOPEN_EXTENDED = 1 ++__USE_UNIX98 = 1 ++_LARGEFILE_SOURCE = 1 ++__USE_XOPEN2K8 = 1 ++__USE_XOPEN2K = 1 ++__USE_ISOC99 = 1 ++__USE_XOPEN_EXTENDED = 1 ++__USE_LARGEFILE = 1 ++__USE_LARGEFILE64 = 1 ++__USE_FILE_OFFSET64 = 1 ++__USE_MISC = 1 ++__USE_BSD = 1 ++__USE_SVID = 1 ++__USE_ATFILE = 1 ++__USE_GNU = 1 ++__USE_REENTRANT = 1 ++__USE_FORTIFY_LEVEL = 2 ++__USE_FORTIFY_LEVEL = 1 ++__USE_FORTIFY_LEVEL = 0 ++ ++# Included from bits/predefs.h ++__STDC_IEC_559__ = 1 ++__STDC_IEC_559_COMPLEX__ = 1 ++__STDC_ISO_10646__ = 200009L ++__GNU_LIBRARY__ = 6 ++__GLIBC__ = 2 ++__GLIBC_MINOR__ = 11 ++__GLIBC_HAVE_LONG_LONG = 1 ++ ++# Included from sys/cdefs.h ++_SYS_CDEFS_H = 1 ++def __NTH(fct): return fct ++ ++def __NTH(fct): return fct ++ ++def __P(args): return args ++ ++def __PMT(args): return args ++ ++def __STRING(x): return #x ++ ++def __bos(ptr): return __builtin_object_size (ptr, __USE_FORTIFY_LEVEL > 1) ++ ++def __bos0(ptr): return __builtin_object_size (ptr, 0) ++ ++def __warnattr(msg): return __attribute__((__warning__ (msg))) ++ ++__flexarr = [] ++__flexarr = [0] ++__flexarr = [] ++__flexarr = [1] ++def __ASMNAME(cname): return __ASMNAME2 (__USER_LABEL_PREFIX__, cname) ++ ++def __attribute__(xyz): return ++ ++def __attribute_format_arg__(x): return __attribute__ ((__format_arg__ (x))) ++ ++def __attribute_format_arg__(x): return ++ ++ ++# Included from bits/wordsize.h ++__WORDSIZE = 32 ++__LDBL_COMPAT = 1 ++def __LDBL_REDIR_DECL(name): return \ ++ ++__USE_LARGEFILE = 1 ++__USE_LARGEFILE64 = 1 ++__USE_EXTERN_INLINES = 1 ++__USE_EXTERN_INLINES_IN_LIBC = 1 ++ ++# Included from gnu/stubs.h ++ ++# Included from stdint.h ++_STDINT_H = 1 ++ ++# Included from bits/wchar.h ++_BITS_WCHAR_H = 1 ++__WCHAR_MAX = (2147483647) ++__WCHAR_MIN = (-__WCHAR_MAX - 1) ++def __INT64_C(c): return c ## L ++ ++def __UINT64_C(c): return c ## UL ++ ++def __INT64_C(c): return c ## LL ++ ++def __UINT64_C(c): return c ## ULL ++ ++INT8_MIN = (-128) ++INT16_MIN = (-32767-1) ++INT32_MIN = (-2147483647-1) ++INT64_MIN = (-__INT64_C(9223372036854775807)-1) ++INT8_MAX = (127) ++INT16_MAX = (32767) ++INT32_MAX = (2147483647) ++INT64_MAX = (__INT64_C(9223372036854775807)) ++UINT8_MAX = (255) ++UINT16_MAX = (65535) ++UINT64_MAX = (__UINT64_C(18446744073709551615)) ++INT_LEAST8_MIN = (-128) ++INT_LEAST16_MIN = (-32767-1) ++INT_LEAST32_MIN = (-2147483647-1) ++INT_LEAST64_MIN = (-__INT64_C(9223372036854775807)-1) ++INT_LEAST8_MAX = (127) ++INT_LEAST16_MAX = (32767) ++INT_LEAST32_MAX = (2147483647) ++INT_LEAST64_MAX = (__INT64_C(9223372036854775807)) ++UINT_LEAST8_MAX = (255) ++UINT_LEAST16_MAX = (65535) ++UINT_LEAST64_MAX = (__UINT64_C(18446744073709551615)) ++INT_FAST8_MIN = (-128) ++INT_FAST16_MIN = (-9223372036854775807L-1) ++INT_FAST32_MIN = (-9223372036854775807L-1) ++INT_FAST16_MIN = (-2147483647-1) ++INT_FAST32_MIN = (-2147483647-1) ++INT_FAST64_MIN = (-__INT64_C(9223372036854775807)-1) ++INT_FAST8_MAX = (127) ++INT_FAST16_MAX = (9223372036854775807L) ++INT_FAST32_MAX = (9223372036854775807L) ++INT_FAST16_MAX = (2147483647) ++INT_FAST32_MAX = (2147483647) ++INT_FAST64_MAX = (__INT64_C(9223372036854775807)) ++UINT_FAST8_MAX = (255) ++UINT_FAST64_MAX = (__UINT64_C(18446744073709551615)) ++INTPTR_MIN = (-9223372036854775807L-1) ++INTPTR_MAX = (9223372036854775807L) ++INTPTR_MIN = (-2147483647-1) ++INTPTR_MAX = (2147483647) ++INTMAX_MIN = (-__INT64_C(9223372036854775807)-1) ++INTMAX_MAX = (__INT64_C(9223372036854775807)) ++UINTMAX_MAX = (__UINT64_C(18446744073709551615)) ++PTRDIFF_MIN = (-9223372036854775807L-1) ++PTRDIFF_MAX = (9223372036854775807L) ++PTRDIFF_MIN = (-2147483647-1) ++PTRDIFF_MAX = (2147483647) ++SIG_ATOMIC_MIN = (-2147483647-1) ++SIG_ATOMIC_MAX = (2147483647) ++WCHAR_MIN = __WCHAR_MIN ++WCHAR_MAX = __WCHAR_MAX ++def INT8_C(c): return c ++ ++def INT16_C(c): return c ++ ++def INT32_C(c): return c ++ ++def INT64_C(c): return c ## L ++ ++def INT64_C(c): return c ## LL ++ ++def UINT8_C(c): return c ++ ++def UINT16_C(c): return c ++ ++def UINT32_C(c): return c ## U ++ ++def UINT64_C(c): return c ## UL ++ ++def UINT64_C(c): return c ## ULL ++ ++def INTMAX_C(c): return c ## L ++ ++def UINTMAX_C(c): return c ## UL ++ ++def INTMAX_C(c): return c ## LL ++ ++def UINTMAX_C(c): return c ## ULL ++ ++ ++# Included from sys/socket.h ++_SYS_SOCKET_H = 1 ++ ++# Included from sys/uio.h ++_SYS_UIO_H = 1 ++from TYPES import * ++ ++# Included from bits/uio.h ++_BITS_UIO_H = 1 ++from TYPES import * ++UIO_MAXIOV = 1024 ++ ++# Included from bits/sigset.h ++_SIGSET_H_types = 1 ++_SIGSET_H_fns = 1 ++def __sigword(sig): return (((sig) - 1) >> 5) ++ ++def __sigemptyset(set): return \ ++ ++def __sigfillset(set): return \ ++ ++def __sigisemptyset(set): return \ ++ ++ ++# Included from bits/socket.h ++__BITS_SOCKET_H = 1 ++ ++# Included from limits.h ++_LIBC_LIMITS_H_ = 1 ++MB_LEN_MAX = 16 ++_LIMITS_H = 1 ++CHAR_BIT = 8 ++SCHAR_MIN = (-128) ++SCHAR_MAX = 127 ++UCHAR_MAX = 255 ++CHAR_MIN = 0 ++CHAR_MAX = UCHAR_MAX ++CHAR_MIN = SCHAR_MIN ++CHAR_MAX = SCHAR_MAX ++SHRT_MIN = (-32768) ++SHRT_MAX = 32767 ++USHRT_MAX = 65535 ++INT_MAX = 2147483647 ++LONG_MAX = 9223372036854775807L ++LONG_MAX = 2147483647L ++LONG_MIN = (-LONG_MAX - 1L) ++ ++# Included from bits/posix1_lim.h ++_BITS_POSIX1_LIM_H = 1 ++_POSIX_AIO_LISTIO_MAX = 2 ++_POSIX_AIO_MAX = 1 ++_POSIX_ARG_MAX = 4096 ++_POSIX_CHILD_MAX = 25 ++_POSIX_CHILD_MAX = 6 ++_POSIX_DELAYTIMER_MAX = 32 ++_POSIX_HOST_NAME_MAX = 255 ++_POSIX_LINK_MAX = 8 ++_POSIX_LOGIN_NAME_MAX = 9 ++_POSIX_MAX_CANON = 255 ++_POSIX_MAX_INPUT = 255 ++_POSIX_MQ_OPEN_MAX = 8 ++_POSIX_MQ_PRIO_MAX = 32 ++_POSIX_NAME_MAX = 14 ++_POSIX_NGROUPS_MAX = 8 ++_POSIX_NGROUPS_MAX = 0 ++_POSIX_OPEN_MAX = 20 ++_POSIX_OPEN_MAX = 16 ++_POSIX_FD_SETSIZE = _POSIX_OPEN_MAX ++_POSIX_PATH_MAX = 256 ++_POSIX_PIPE_BUF = 512 ++_POSIX_RE_DUP_MAX = 255 ++_POSIX_RTSIG_MAX = 8 ++_POSIX_SEM_NSEMS_MAX = 256 ++_POSIX_SEM_VALUE_MAX = 32767 ++_POSIX_SIGQUEUE_MAX = 32 ++_POSIX_SSIZE_MAX = 32767 ++_POSIX_STREAM_MAX = 8 ++_POSIX_SYMLINK_MAX = 255 ++_POSIX_SYMLOOP_MAX = 8 ++_POSIX_TIMER_MAX = 32 ++_POSIX_TTY_NAME_MAX = 9 ++_POSIX_TZNAME_MAX = 6 ++_POSIX_QLIMIT = 1 ++_POSIX_HIWAT = _POSIX_PIPE_BUF ++_POSIX_UIO_MAXIOV = 16 ++_POSIX_CLOCKRES_MIN = 20000000 ++ ++# Included from bits/local_lim.h ++ ++# Included from sys/syslimits.h ++ARG_MAX = 262144 ++CHILD_MAX = 40 ++LINK_MAX = 32767 ++MAX_CANON = 255 ++MAX_INPUT = 255 ++NAME_MAX = 255 ++NGROUPS_MAX = 1023 ++OPEN_MAX = 64 ++PATH_MAX = 1024 ++PIPE_BUF = 512 ++IOV_MAX = 1024 ++_POSIX_THREAD_KEYS_MAX = 128 ++PTHREAD_KEYS_MAX = 1024 ++_POSIX_THREAD_DESTRUCTOR_ITERATIONS = 4 ++PTHREAD_DESTRUCTOR_ITERATIONS = _POSIX_THREAD_DESTRUCTOR_ITERATIONS ++_POSIX_THREAD_THREADS_MAX = 64 ++PTHREAD_THREADS_MAX = 1024 ++AIO_PRIO_DELTA_MAX = 20 ++PTHREAD_STACK_MIN = 16384 ++TIMER_MAX = 256 ++DELAYTIMER_MAX = 2147483647 ++SSIZE_MAX = LONG_MAX ++NGROUPS_MAX = 8 ++ ++# Included from bits/posix2_lim.h ++_BITS_POSIX2_LIM_H = 1 ++_POSIX2_BC_BASE_MAX = 99 ++_POSIX2_BC_DIM_MAX = 2048 ++_POSIX2_BC_SCALE_MAX = 99 ++_POSIX2_BC_STRING_MAX = 1000 ++_POSIX2_COLL_WEIGHTS_MAX = 2 ++_POSIX2_EXPR_NEST_MAX = 32 ++_POSIX2_LINE_MAX = 2048 ++_POSIX2_RE_DUP_MAX = 255 ++_POSIX2_CHARCLASS_NAME_MAX = 14 ++BC_BASE_MAX = _POSIX2_BC_BASE_MAX ++BC_DIM_MAX = _POSIX2_BC_DIM_MAX ++BC_SCALE_MAX = _POSIX2_BC_SCALE_MAX ++BC_STRING_MAX = _POSIX2_BC_STRING_MAX ++COLL_WEIGHTS_MAX = 255 ++EXPR_NEST_MAX = _POSIX2_EXPR_NEST_MAX ++LINE_MAX = _POSIX2_LINE_MAX ++CHARCLASS_NAME_MAX = 2048 ++RE_DUP_MAX = (0x7fff) ++ ++# Included from bits/xopen_lim.h ++_XOPEN_LIM_H = 1 ++ ++# Included from bits/stdio_lim.h ++L_tmpnam = 20 ++TMP_MAX = 238328 ++FILENAME_MAX = 1024 ++L_ctermid = 9 ++L_cuserid = 9 ++FOPEN_MAX = 64 ++IOV_MAX = 1024 ++_XOPEN_IOV_MAX = _POSIX_UIO_MAXIOV ++NL_ARGMAX = _POSIX_ARG_MAX ++NL_LANGMAX = _POSIX2_LINE_MAX ++NL_MSGMAX = INT_MAX ++NL_NMAX = INT_MAX ++NL_SETMAX = INT_MAX ++NL_TEXTMAX = INT_MAX ++NZERO = 20 ++WORD_BIT = 16 ++WORD_BIT = 32 ++WORD_BIT = 64 ++WORD_BIT = 16 ++WORD_BIT = 32 ++WORD_BIT = 64 ++WORD_BIT = 32 ++LONG_BIT = 32 ++LONG_BIT = 64 ++LONG_BIT = 32 ++LONG_BIT = 64 ++LONG_BIT = 64 ++LONG_BIT = 32 ++ ++# Included from bits/types.h ++_BITS_TYPES_H = 1 ++__S32_TYPE = int ++__SWORD_TYPE = int ++__SLONG32_TYPE = int ++ ++# Included from bits/typesizes.h ++_BITS_TYPESIZES_H = 1 ++__PID_T_TYPE = __S32_TYPE ++__CLOCK_T_TYPE = __S32_TYPE ++__SWBLK_T_TYPE = __S32_TYPE ++__CLOCKID_T_TYPE = __S32_TYPE ++__TIMER_T_TYPE = __S32_TYPE ++__SSIZE_T_TYPE = __SWORD_TYPE ++__FD_SETSIZE = 1024 ++PF_UNSPEC = 0 ++PF_LOCAL = 1 ++PF_UNIX = PF_LOCAL ++PF_FILE = PF_LOCAL ++PF_INET = 2 ++PF_IMPLINK = 3 ++PF_PUP = 4 ++PF_CHAOS = 5 ++PF_NS = 6 ++PF_ISO = 7 ++PF_OSI = PF_ISO ++PF_ECMA = 8 ++PF_DATAKIT = 9 ++PF_CCITT = 10 ++PF_SNA = 11 ++PF_DECnet = 12 ++PF_DLI = 13 ++PF_LAT = 14 ++PF_HYLINK = 15 ++PF_APPLETALK = 16 ++PF_ROUTE = 17 ++PF_LINK = 18 ++PF_XTP = 19 ++PF_COIP = 20 ++PF_CNT = 21 ++PF_RTIP = 22 ++PF_IPX = 23 ++PF_SIP = 24 ++PF_PIP = 25 ++PF_ISDN = 26 ++PF_KEY = 27 ++PF_INET6 = 28 ++PF_NATM = 29 ++PF_ATM = 30 ++PF_HDRCMPLT = 31 ++PF_NETGRAPH = 32 ++PF_MAX = 33 ++AF_UNSPEC = PF_UNSPEC ++AF_LOCAL = PF_LOCAL ++AF_UNIX = PF_UNIX ++AF_FILE = PF_FILE ++AF_INET = PF_INET ++AF_IMPLINK = PF_IMPLINK ++AF_PUP = PF_PUP ++AF_CHAOS = PF_CHAOS ++AF_NS = PF_NS ++AF_ISO = PF_ISO ++AF_OSI = PF_OSI ++AF_ECMA = PF_ECMA ++AF_DATAKIT = PF_DATAKIT ++AF_CCITT = PF_CCITT ++AF_SNA = PF_SNA ++AF_DECnet = PF_DECnet ++AF_DLI = PF_DLI ++AF_LAT = PF_LAT ++AF_HYLINK = PF_HYLINK ++AF_APPLETALK = PF_APPLETALK ++AF_ROUTE = PF_ROUTE ++AF_LINK = PF_LINK ++pseudo_AF_XTP = PF_XTP ++AF_COIP = PF_COIP ++AF_CNT = PF_CNT ++pseudo_AF_RTIP = PF_RTIP ++AF_IPX = PF_IPX ++AF_SIP = PF_SIP ++pseudo_AF_PIP = PF_PIP ++AF_ISDN = PF_ISDN ++AF_E164 = AF_ISDN ++pseudo_AF_KEY = PF_KEY ++AF_INET6 = PF_INET6 ++AF_NATM = PF_NATM ++AF_ATM = PF_ATM ++pseudo_AF_HDRCMPLT = PF_HDRCMPLT ++AF_NETGRAPH = PF_NETGRAPH ++AF_MAX = PF_MAX ++SOMAXCONN = 128 ++ ++# Included from bits/sockaddr.h ++_BITS_SOCKADDR_H = 1 ++def __SOCKADDR_COMMON(sa_prefix): return \ ++ ++_HAVE_SA_LEN = 1 ++_SS_SIZE = 128 ++def CMSG_FIRSTHDR(mhdr): return \ ++ ++CMGROUP_MAX = 16 ++SOL_SOCKET = 0xffff ++LOCAL_PEERCRED = 0x001 ++LOCAL_CREDS = 0x002 ++LOCAL_CONNWAIT = 0x004 ++ ++# Included from bits/socket2.h ++def IN_CLASSA(a): return ((((in_addr_t)(a)) & (-2147483648)) == 0) ++ ++IN_CLASSA_NET = (-16777216) ++IN_CLASSA_NSHIFT = 24 ++IN_CLASSA_HOST = ((-1) & ~IN_CLASSA_NET) ++IN_CLASSA_MAX = 128 ++def IN_CLASSB(a): return ((((in_addr_t)(a)) & (-1073741824)) == (-2147483648)) ++ ++IN_CLASSB_NET = (-65536) ++IN_CLASSB_NSHIFT = 16 ++IN_CLASSB_HOST = ((-1) & ~IN_CLASSB_NET) ++IN_CLASSB_MAX = 65536 ++def IN_CLASSC(a): return ((((in_addr_t)(a)) & (-536870912)) == (-1073741824)) ++ ++IN_CLASSC_NET = (-256) ++IN_CLASSC_NSHIFT = 8 ++IN_CLASSC_HOST = ((-1) & ~IN_CLASSC_NET) ++def IN_CLASSD(a): return ((((in_addr_t)(a)) & (-268435456)) == (-536870912)) ++ ++def IN_MULTICAST(a): return IN_CLASSD(a) ++ ++def IN_EXPERIMENTAL(a): return ((((in_addr_t)(a)) & (-536870912)) == (-536870912)) ++ ++def IN_BADCLASS(a): return ((((in_addr_t)(a)) & (-268435456)) == (-268435456)) ++ ++IN_LOOPBACKNET = 127 ++INET_ADDRSTRLEN = 16 ++INET6_ADDRSTRLEN = 46 ++ ++# Included from bits/in.h ++IMPLINK_IP = 155 ++IMPLINK_LOWEXPER = 156 ++IMPLINK_HIGHEXPER = 158 ++IPPROTO_DIVERT = 258 ++SOL_IP = 0 ++IP_OPTIONS = 1 ++IP_HDRINCL = 2 ++IP_TOS = 3 ++IP_TTL = 4 ++IP_RECVOPTS = 5 ++IP_RECVRETOPTS = 6 ++IP_RECVDSTADDR = 7 ++IP_SENDSRCADDR = IP_RECVDSTADDR ++IP_RETOPTS = 8 ++IP_MULTICAST_IF = 9 ++IP_MULTICAST_TTL = 10 ++IP_MULTICAST_LOOP = 11 ++IP_ADD_MEMBERSHIP = 12 ++IP_DROP_MEMBERSHIP = 13 ++IP_MULTICAST_VIF = 14 ++IP_RSVP_ON = 15 ++IP_RSVP_OFF = 16 ++IP_RSVP_VIF_ON = 17 ++IP_RSVP_VIF_OFF = 18 ++IP_PORTRANGE = 19 ++IP_RECVIF = 20 ++IP_IPSEC_POLICY = 21 ++IP_FAITH = 22 ++IP_ONESBCAST = 23 ++IP_NONLOCALOK = 24 ++IP_FW_TABLE_ADD = 40 ++IP_FW_TABLE_DEL = 41 ++IP_FW_TABLE_FLUSH = 42 ++IP_FW_TABLE_GETSIZE = 43 ++IP_FW_TABLE_LIST = 44 ++IP_FW_ADD = 50 ++IP_FW_DEL = 51 ++IP_FW_FLUSH = 52 ++IP_FW_ZERO = 53 ++IP_FW_GET = 54 ++IP_FW_RESETLOG = 55 ++IP_FW_NAT_CFG = 56 ++IP_FW_NAT_DEL = 57 ++IP_FW_NAT_GET_CONFIG = 58 ++IP_FW_NAT_GET_LOG = 59 ++IP_DUMMYNET_CONFIGURE = 60 ++IP_DUMMYNET_DEL = 61 ++IP_DUMMYNET_FLUSH = 62 ++IP_DUMMYNET_GET = 64 ++IP_RECVTTL = 65 ++IP_MINTTL = 66 ++IP_DONTFRAG = 67 ++IP_ADD_SOURCE_MEMBERSHIP = 70 ++IP_DROP_SOURCE_MEMBERSHIP = 71 ++IP_BLOCK_SOURCE = 72 ++IP_UNBLOCK_SOURCE = 73 ++IP_MSFILTER = 74 ++MCAST_JOIN_GROUP = 80 ++MCAST_LEAVE_GROUP = 81 ++MCAST_JOIN_SOURCE_GROUP = 82 ++MCAST_LEAVE_SOURCE_GROUP = 83 ++MCAST_BLOCK_SOURCE = 84 ++MCAST_UNBLOCK_SOURCE = 85 ++IP_DEFAULT_MULTICAST_TTL = 1 ++IP_DEFAULT_MULTICAST_LOOP = 1 ++IP_MIN_MEMBERSHIPS = 31 ++IP_MAX_MEMBERSHIPS = 4095 ++IP_MAX_SOURCE_FILTER = 1024 ++MCAST_UNDEFINED = 0 ++MCAST_INCLUDE = 1 ++MCAST_EXCLUDE = 2 ++IP_PORTRANGE_DEFAULT = 0 ++IP_PORTRANGE_HIGH = 1 ++IP_PORTRANGE_LOW = 2 ++IPCTL_FORWARDING = 1 ++IPCTL_SENDREDIRECTS = 2 ++IPCTL_DEFTTL = 3 ++IPCTL_DEFMTU = 4 ++IPCTL_RTEXPIRE = 5 ++IPCTL_RTMINEXPIRE = 6 ++IPCTL_RTMAXCACHE = 7 ++IPCTL_SOURCEROUTE = 8 ++IPCTL_DIRECTEDBROADCAST = 9 ++IPCTL_INTRQMAXLEN = 10 ++IPCTL_INTRQDROPS = 11 ++IPCTL_STATS = 12 ++IPCTL_ACCEPTSOURCEROUTE = 13 ++IPCTL_FASTFORWARDING = 14 ++IPCTL_KEEPFAITH = 15 ++IPCTL_GIF_TTL = 16 ++IPCTL_MAXID = 17 ++IPV6_SOCKOPT_RESERVED1 = 3 ++IPV6_UNICAST_HOPS = 4 ++IPV6_MULTICAST_IF = 9 ++IPV6_MULTICAST_HOPS = 10 ++IPV6_MULTICAST_LOOP = 11 ++IPV6_JOIN_GROUP = 12 ++IPV6_LEAVE_GROUP = 13 ++IPV6_PORTRANGE = 14 ++ICMP6_FILTER = 18 ++IPV6_CHECKSUM = 26 ++IPV6_V6ONLY = 27 ++IPV6_IPSEC_POLICY = 28 ++IPV6_FAITH = 29 ++IPV6_FW_ADD = 30 ++IPV6_FW_DEL = 31 ++IPV6_FW_FLUSH = 32 ++IPV6_FW_ZERO = 33 ++IPV6_FW_GET = 34 ++IPV6_RTHDRDSTOPTS = 35 ++IPV6_RECVPKTINFO = 36 ++IPV6_RECVHOPLIMIT = 37 ++IPV6_RECVRTHDR = 38 ++IPV6_RECVHOPOPTS = 39 ++IPV6_RECVDSTOPTS = 40 ++IPV6_USE_MIN_MTU = 42 ++IPV6_RECVPATHMTU = 43 ++IPV6_PATHMTU = 44 ++IPV6_PKTINFO = 46 ++IPV6_HOPLIMIT = 47 ++IPV6_NEXTHOP = 48 ++IPV6_HOPOPTS = 49 ++IPV6_DSTOPTS = 50 ++IPV6_RTHDR = 51 ++IPV6_RECVTCLASS = 57 ++IPV6_AUTOFLOWLABEL = 59 ++IPV6_TCLASS = 61 ++IPV6_DONTFRAG = 62 ++IPV6_PREFER_TEMPADDR = 63 ++IPV6_ADD_MEMBERSHIP = IPV6_JOIN_GROUP ++IPV6_DROP_MEMBERSHIP = IPV6_LEAVE_GROUP ++IPV6_RXHOPOPTS = IPV6_HOPOPTS ++IPV6_RXDSTOPTS = IPV6_DSTOPTS ++SOL_IPV6 = 41 ++SOL_ICMPV6 = 58 ++IPV6_DEFAULT_MULTICAST_HOPS = 1 ++IPV6_DEFAULT_MULTICAST_LOOP = 1 ++IPV6_PORTRANGE_DEFAULT = 0 ++IPV6_PORTRANGE_HIGH = 1 ++IPV6_PORTRANGE_LOW = 2 ++IPV6_RTHDR_LOOSE = 0 ++IPV6_RTHDR_STRICT = 1 ++IPV6_RTHDR_TYPE_0 = 0 ++IPV6CTL_FORWARDING = 1 ++IPV6CTL_SENDREDIRECTS = 2 ++IPV6CTL_DEFHLIM = 3 ++IPV6CTL_FORWSRCRT = 5 ++IPV6CTL_STATS = 6 ++IPV6CTL_MRTSTATS = 7 ++IPV6CTL_MRTPROTO = 8 ++IPV6CTL_MAXFRAGPACKETS = 9 ++IPV6CTL_SOURCECHECK = 10 ++IPV6CTL_SOURCECHECK_LOGINT = 11 ++IPV6CTL_ACCEPT_RTADV = 12 ++IPV6CTL_KEEPFAITH = 13 ++IPV6CTL_LOG_INTERVAL = 14 ++IPV6CTL_HDRNESTLIMIT = 15 ++IPV6CTL_DAD_COUNT = 16 ++IPV6CTL_AUTO_FLOWLABEL = 17 ++IPV6CTL_DEFMCASTHLIM = 18 ++IPV6CTL_GIF_HLIM = 19 ++IPV6CTL_KAME_VERSION = 20 ++IPV6CTL_USE_DEPRECATED = 21 ++IPV6CTL_RR_PRUNE = 22 ++IPV6CTL_V6ONLY = 24 ++IPV6CTL_RTEXPIRE = 25 ++IPV6CTL_RTMINEXPIRE = 26 ++IPV6CTL_RTMAXCACHE = 27 ++IPV6CTL_USETEMPADDR = 32 ++IPV6CTL_TEMPPLTIME = 33 ++IPV6CTL_TEMPVLTIME = 34 ++IPV6CTL_AUTO_LINKLOCAL = 35 ++IPV6CTL_RIP6STATS = 36 ++IPV6CTL_PREFER_TEMPADDR = 37 ++IPV6CTL_ADDRCTLPOLICY = 38 ++IPV6CTL_USE_DEFAULTZONE = 39 ++IPV6CTL_MAXFRAGS = 41 ++IPV6CTL_MCAST_PMTU = 44 ++IPV6CTL_STEALTH = 45 ++ICMPV6CTL_ND6_ONLINKNSRFC4861 = 47 ++IPV6CTL_MAXID = 48 ++ ++# Included from endian.h ++_ENDIAN_H = 1 ++__LITTLE_ENDIAN = 1234 ++__BIG_ENDIAN = 4321 ++__PDP_ENDIAN = 3412 ++ ++# Included from bits/endian.h ++__BYTE_ORDER = __LITTLE_ENDIAN ++__FLOAT_WORD_ORDER = __BYTE_ORDER ++LITTLE_ENDIAN = __LITTLE_ENDIAN ++BIG_ENDIAN = __BIG_ENDIAN ++PDP_ENDIAN = __PDP_ENDIAN ++BYTE_ORDER = __BYTE_ORDER ++ ++# Included from bits/byteswap.h ++_BITS_BYTESWAP_H = 1 ++def __bswap_constant_16(x): return \ ++ ++def __bswap_16(x): return \ ++ ++def __bswap_16(x): return \ ++ ++def __bswap_constant_32(x): return \ ++ ++def __bswap_32(x): return \ ++ ++def __bswap_32(x): return \ ++ ++def __bswap_32(x): return \ ++ ++def __bswap_constant_64(x): return \ ++ ++def __bswap_64(x): return \ ++ ++def htobe16(x): return __bswap_16 (x) ++ ++def htole16(x): return (x) ++ ++def be16toh(x): return __bswap_16 (x) ++ ++def le16toh(x): return (x) ++ ++def htobe32(x): return __bswap_32 (x) ++ ++def htole32(x): return (x) ++ ++def be32toh(x): return __bswap_32 (x) ++ ++def le32toh(x): return (x) ++ ++def htobe64(x): return __bswap_64 (x) ++ ++def htole64(x): return (x) ++ ++def be64toh(x): return __bswap_64 (x) ++ ++def le64toh(x): return (x) ++ ++def htobe16(x): return (x) ++ ++def htole16(x): return __bswap_16 (x) ++ ++def be16toh(x): return (x) ++ ++def le16toh(x): return __bswap_16 (x) ++ ++def htobe32(x): return (x) ++ ++def htole32(x): return __bswap_32 (x) ++ ++def be32toh(x): return (x) ++ ++def le32toh(x): return __bswap_32 (x) ++ ++def htobe64(x): return (x) ++ ++def htole64(x): return __bswap_64 (x) ++ ++def be64toh(x): return (x) ++ ++def le64toh(x): return __bswap_64 (x) ++ ++def ntohl(x): return (x) ++ ++def ntohs(x): return (x) ++ ++def htonl(x): return (x) ++ ++def htons(x): return (x) ++ ++def ntohl(x): return __bswap_32 (x) ++ ++def ntohs(x): return __bswap_16 (x) ++ ++def htonl(x): return __bswap_32 (x) ++ ++def htons(x): return __bswap_16 (x) ++ ++def IN6_IS_ADDR_UNSPECIFIED(a): return \ ++ ++def IN6_IS_ADDR_LOOPBACK(a): return \ ++ ++def IN6_IS_ADDR_LINKLOCAL(a): return \ ++ ++def IN6_IS_ADDR_SITELOCAL(a): return \ ++ ++def IN6_IS_ADDR_V4MAPPED(a): return \ ++ ++def IN6_IS_ADDR_V4COMPAT(a): return \ ++ ++def IN6_IS_ADDR_MC_NODELOCAL(a): return \ ++ ++def IN6_IS_ADDR_MC_LINKLOCAL(a): return \ ++ ++def IN6_IS_ADDR_MC_SITELOCAL(a): return \ ++ ++def IN6_IS_ADDR_MC_ORGLOCAL(a): return \ ++ ++def IN6_IS_ADDR_MC_GLOBAL(a): return \ ++ +--- /dev/null ++++ b/Lib/plat-gnukfreebsd8/TYPES.py +@@ -0,0 +1,303 @@ ++# Generated by h2py from /usr/include/sys/types.h ++_SYS_TYPES_H = 1 ++ ++# Included from features.h ++_FEATURES_H = 1 ++__USE_ANSI = 1 ++__FAVOR_BSD = 1 ++_ISOC99_SOURCE = 1 ++_POSIX_SOURCE = 1 ++_POSIX_C_SOURCE = 200809L ++_XOPEN_SOURCE = 700 ++_XOPEN_SOURCE_EXTENDED = 1 ++_LARGEFILE64_SOURCE = 1 ++_BSD_SOURCE = 1 ++_SVID_SOURCE = 1 ++_ATFILE_SOURCE = 1 ++_BSD_SOURCE = 1 ++_SVID_SOURCE = 1 ++__USE_ISOC99 = 1 ++__USE_ISOC95 = 1 ++_POSIX_SOURCE = 1 ++_POSIX_C_SOURCE = 2 ++_POSIX_C_SOURCE = 199506L ++_POSIX_C_SOURCE = 200112L ++_POSIX_C_SOURCE = 200809L ++__USE_POSIX_IMPLICITLY = 1 ++__USE_POSIX = 1 ++__USE_POSIX2 = 1 ++__USE_POSIX199309 = 1 ++__USE_POSIX199506 = 1 ++__USE_XOPEN2K = 1 ++__USE_ISOC99 = 1 ++__USE_XOPEN2K8 = 1 ++_ATFILE_SOURCE = 1 ++__USE_XOPEN = 1 ++__USE_XOPEN_EXTENDED = 1 ++__USE_UNIX98 = 1 ++_LARGEFILE_SOURCE = 1 ++__USE_XOPEN2K8 = 1 ++__USE_XOPEN2K = 1 ++__USE_ISOC99 = 1 ++__USE_XOPEN_EXTENDED = 1 ++__USE_LARGEFILE = 1 ++__USE_LARGEFILE64 = 1 ++__USE_FILE_OFFSET64 = 1 ++__USE_MISC = 1 ++__USE_BSD = 1 ++__USE_SVID = 1 ++__USE_ATFILE = 1 ++__USE_GNU = 1 ++__USE_REENTRANT = 1 ++__USE_FORTIFY_LEVEL = 2 ++__USE_FORTIFY_LEVEL = 1 ++__USE_FORTIFY_LEVEL = 0 ++ ++# Included from bits/predefs.h ++__STDC_IEC_559__ = 1 ++__STDC_IEC_559_COMPLEX__ = 1 ++__STDC_ISO_10646__ = 200009L ++__GNU_LIBRARY__ = 6 ++__GLIBC__ = 2 ++__GLIBC_MINOR__ = 11 ++__GLIBC_HAVE_LONG_LONG = 1 ++ ++# Included from sys/cdefs.h ++_SYS_CDEFS_H = 1 ++def __NTH(fct): return fct ++ ++def __NTH(fct): return fct ++ ++def __P(args): return args ++ ++def __PMT(args): return args ++ ++def __STRING(x): return #x ++ ++def __bos(ptr): return __builtin_object_size (ptr, __USE_FORTIFY_LEVEL > 1) ++ ++def __bos0(ptr): return __builtin_object_size (ptr, 0) ++ ++def __warnattr(msg): return __attribute__((__warning__ (msg))) ++ ++__flexarr = [] ++__flexarr = [0] ++__flexarr = [] ++__flexarr = [1] ++def __ASMNAME(cname): return __ASMNAME2 (__USER_LABEL_PREFIX__, cname) ++ ++def __attribute__(xyz): return ++ ++def __attribute_format_arg__(x): return __attribute__ ((__format_arg__ (x))) ++ ++def __attribute_format_arg__(x): return ++ ++ ++# Included from bits/wordsize.h ++__WORDSIZE = 32 ++__LDBL_COMPAT = 1 ++def __LDBL_REDIR_DECL(name): return \ ++ ++__USE_LARGEFILE = 1 ++__USE_LARGEFILE64 = 1 ++__USE_EXTERN_INLINES = 1 ++__USE_EXTERN_INLINES_IN_LIBC = 1 ++ ++# Included from gnu/stubs.h ++ ++# Included from bits/types.h ++_BITS_TYPES_H = 1 ++__S32_TYPE = int ++__SWORD_TYPE = int ++__SLONG32_TYPE = int ++ ++# Included from bits/typesizes.h ++_BITS_TYPESIZES_H = 1 ++__PID_T_TYPE = __S32_TYPE ++__CLOCK_T_TYPE = __S32_TYPE ++__SWBLK_T_TYPE = __S32_TYPE ++__CLOCKID_T_TYPE = __S32_TYPE ++__TIMER_T_TYPE = __S32_TYPE ++__SSIZE_T_TYPE = __SWORD_TYPE ++__FD_SETSIZE = 1024 ++ ++# Included from time.h ++_TIME_H = 1 ++ ++# Included from bits/time.h ++_BITS_TIME_H = 1 ++CLOCKS_PER_SEC = 1000000l ++CLK_TCK = 128 ++CLOCK_REALTIME = 0 ++CLOCK_PROCESS_CPUTIME_ID = 2 ++CLOCK_THREAD_CPUTIME_ID = 3 ++CLOCK_MONOTONIC = 4 ++CLOCK_VIRTUAL = 1 ++CLOCK_PROF = 2 ++CLOCK_UPTIME = 5 ++CLOCK_UPTIME_PRECISE = 7 ++CLOCK_UPTIME_FAST = 8 ++CLOCK_REALTIME_PRECISE = 9 ++CLOCK_REALTIME_FAST = 10 ++CLOCK_MONOTONIC_PRECISE = 11 ++CLOCK_MONOTONIC_FAST = 12 ++CLOCK_SECOND = 13 ++TIMER_RELTIME = 0 ++TIMER_ABSTIME = 1 ++_STRUCT_TIMEVAL = 1 ++CLK_TCK = CLOCKS_PER_SEC ++__clock_t_defined = 1 ++__time_t_defined = 1 ++__clockid_t_defined = 1 ++__timer_t_defined = 1 ++__timespec_defined = 1 ++ ++# Included from xlocale.h ++_XLOCALE_H = 1 ++def __isleap(year): return \ ++ ++__BIT_TYPES_DEFINED__ = 1 ++ ++# Included from endian.h ++_ENDIAN_H = 1 ++__LITTLE_ENDIAN = 1234 ++__BIG_ENDIAN = 4321 ++__PDP_ENDIAN = 3412 ++ ++# Included from bits/endian.h ++__BYTE_ORDER = __LITTLE_ENDIAN ++__FLOAT_WORD_ORDER = __BYTE_ORDER ++LITTLE_ENDIAN = __LITTLE_ENDIAN ++BIG_ENDIAN = __BIG_ENDIAN ++PDP_ENDIAN = __PDP_ENDIAN ++BYTE_ORDER = __BYTE_ORDER ++ ++# Included from bits/byteswap.h ++_BITS_BYTESWAP_H = 1 ++def __bswap_constant_16(x): return \ ++ ++def __bswap_16(x): return \ ++ ++def __bswap_16(x): return \ ++ ++def __bswap_constant_32(x): return \ ++ ++def __bswap_32(x): return \ ++ ++def __bswap_32(x): return \ ++ ++def __bswap_32(x): return \ ++ ++def __bswap_constant_64(x): return \ ++ ++def __bswap_64(x): return \ ++ ++def htobe16(x): return __bswap_16 (x) ++ ++def htole16(x): return (x) ++ ++def be16toh(x): return __bswap_16 (x) ++ ++def le16toh(x): return (x) ++ ++def htobe32(x): return __bswap_32 (x) ++ ++def htole32(x): return (x) ++ ++def be32toh(x): return __bswap_32 (x) ++ ++def le32toh(x): return (x) ++ ++def htobe64(x): return __bswap_64 (x) ++ ++def htole64(x): return (x) ++ ++def be64toh(x): return __bswap_64 (x) ++ ++def le64toh(x): return (x) ++ ++def htobe16(x): return (x) ++ ++def htole16(x): return __bswap_16 (x) ++ ++def be16toh(x): return (x) ++ ++def le16toh(x): return __bswap_16 (x) ++ ++def htobe32(x): return (x) ++ ++def htole32(x): return __bswap_32 (x) ++ ++def be32toh(x): return (x) ++ ++def le32toh(x): return __bswap_32 (x) ++ ++def htobe64(x): return (x) ++ ++def htole64(x): return __bswap_64 (x) ++ ++def be64toh(x): return (x) ++ ++def le64toh(x): return __bswap_64 (x) ++ ++ ++# Included from sys/select.h ++_SYS_SELECT_H = 1 ++ ++# Included from bits/select.h ++def __FD_ZERO(fdsp): return \ ++ ++def __FD_ZERO(set): return \ ++ ++ ++# Included from bits/sigset.h ++_SIGSET_H_types = 1 ++_SIGSET_H_fns = 1 ++def __sigword(sig): return (((sig) - 1) >> 5) ++ ++def __sigemptyset(set): return \ ++ ++def __sigfillset(set): return \ ++ ++def __sigisemptyset(set): return \ ++ ++def __FDELT(d): return ((d) / __NFDBITS) ++ ++FD_SETSIZE = __FD_SETSIZE ++def FD_ZERO(fdsetp): return __FD_ZERO (fdsetp) ++ ++ ++# Included from sys/sysmacros.h ++_SYS_SYSMACROS_H = 1 ++def minor(dev): return ((int)((dev) & (-65281))) ++ ++def gnu_dev_major(dev): return major (dev) ++ ++def gnu_dev_minor(dev): return minor (dev) ++ ++ ++# Included from bits/pthreadtypes.h ++_BITS_PTHREADTYPES_H = 1 ++ ++# Included from bits/sched.h ++SCHED_OTHER = 2 ++SCHED_FIFO = 1 ++SCHED_RR = 3 ++CSIGNAL = 0x000000ff ++CLONE_VM = 0x00000100 ++CLONE_FS = 0x00000200 ++CLONE_FILES = 0x00000400 ++CLONE_SIGHAND = 0x00000800 ++CLONE_PTRACE = 0x00002000 ++CLONE_VFORK = 0x00004000 ++CLONE_SYSVSEM = 0x00040000 ++__defined_schedparam = 1 ++__CPU_SETSIZE = 128 ++def __CPUELT(cpu): return ((cpu) / __NCPUBITS) ++ ++def __CPU_ALLOC_SIZE(count): return \ ++ ++def __CPU_ALLOC(count): return __sched_cpualloc (count) ++ ++def __CPU_FREE(cpuset): return __sched_cpufree (cpuset) ++ +--- /dev/null ++++ b/Lib/plat-gnukfreebsd8/DLFCN.py +@@ -0,0 +1,118 @@ ++# Generated by h2py from /usr/include/dlfcn.h ++_DLFCN_H = 1 ++ ++# Included from features.h ++_FEATURES_H = 1 ++__USE_ANSI = 1 ++__FAVOR_BSD = 1 ++_ISOC99_SOURCE = 1 ++_POSIX_SOURCE = 1 ++_POSIX_C_SOURCE = 200809L ++_XOPEN_SOURCE = 700 ++_XOPEN_SOURCE_EXTENDED = 1 ++_LARGEFILE64_SOURCE = 1 ++_BSD_SOURCE = 1 ++_SVID_SOURCE = 1 ++_ATFILE_SOURCE = 1 ++_BSD_SOURCE = 1 ++_SVID_SOURCE = 1 ++__USE_ISOC99 = 1 ++__USE_ISOC95 = 1 ++_POSIX_SOURCE = 1 ++_POSIX_C_SOURCE = 2 ++_POSIX_C_SOURCE = 199506L ++_POSIX_C_SOURCE = 200112L ++_POSIX_C_SOURCE = 200809L ++__USE_POSIX_IMPLICITLY = 1 ++__USE_POSIX = 1 ++__USE_POSIX2 = 1 ++__USE_POSIX199309 = 1 ++__USE_POSIX199506 = 1 ++__USE_XOPEN2K = 1 ++__USE_ISOC99 = 1 ++__USE_XOPEN2K8 = 1 ++_ATFILE_SOURCE = 1 ++__USE_XOPEN = 1 ++__USE_XOPEN_EXTENDED = 1 ++__USE_UNIX98 = 1 ++_LARGEFILE_SOURCE = 1 ++__USE_XOPEN2K8 = 1 ++__USE_XOPEN2K = 1 ++__USE_ISOC99 = 1 ++__USE_XOPEN_EXTENDED = 1 ++__USE_LARGEFILE = 1 ++__USE_LARGEFILE64 = 1 ++__USE_FILE_OFFSET64 = 1 ++__USE_MISC = 1 ++__USE_BSD = 1 ++__USE_SVID = 1 ++__USE_ATFILE = 1 ++__USE_GNU = 1 ++__USE_REENTRANT = 1 ++__USE_FORTIFY_LEVEL = 2 ++__USE_FORTIFY_LEVEL = 1 ++__USE_FORTIFY_LEVEL = 0 ++ ++# Included from bits/predefs.h ++__STDC_IEC_559__ = 1 ++__STDC_IEC_559_COMPLEX__ = 1 ++__STDC_ISO_10646__ = 200009L ++__GNU_LIBRARY__ = 6 ++__GLIBC__ = 2 ++__GLIBC_MINOR__ = 11 ++__GLIBC_HAVE_LONG_LONG = 1 ++ ++# Included from sys/cdefs.h ++_SYS_CDEFS_H = 1 ++def __NTH(fct): return fct ++ ++def __NTH(fct): return fct ++ ++def __P(args): return args ++ ++def __PMT(args): return args ++ ++def __STRING(x): return #x ++ ++def __bos(ptr): return __builtin_object_size (ptr, __USE_FORTIFY_LEVEL > 1) ++ ++def __bos0(ptr): return __builtin_object_size (ptr, 0) ++ ++def __warnattr(msg): return __attribute__((__warning__ (msg))) ++ ++__flexarr = [] ++__flexarr = [0] ++__flexarr = [] ++__flexarr = [1] ++def __ASMNAME(cname): return __ASMNAME2 (__USER_LABEL_PREFIX__, cname) ++ ++def __attribute__(xyz): return ++ ++def __attribute_format_arg__(x): return __attribute__ ((__format_arg__ (x))) ++ ++def __attribute_format_arg__(x): return ++ ++ ++# Included from bits/wordsize.h ++__WORDSIZE = 32 ++__LDBL_COMPAT = 1 ++def __LDBL_REDIR_DECL(name): return \ ++ ++__USE_LARGEFILE = 1 ++__USE_LARGEFILE64 = 1 ++__USE_EXTERN_INLINES = 1 ++__USE_EXTERN_INLINES_IN_LIBC = 1 ++ ++# Included from gnu/stubs.h ++ ++# Included from bits/dlfcn.h ++RTLD_LAZY = 0x00001 ++RTLD_NOW = 0x00002 ++RTLD_BINDING_MASK = 0x3 ++RTLD_NOLOAD = 0x00004 ++RTLD_DEEPBIND = 0x00008 ++RTLD_GLOBAL = 0x00100 ++RTLD_LOCAL = 0 ++RTLD_NODELETE = 0x01000 ++LM_ID_BASE = 0 ++LM_ID_NEWLM = -1 --- python2.7-2.7.orig/debian/patches/site-locations.diff +++ python2.7-2.7/debian/patches/site-locations.diff @@ -0,0 +1,32 @@ +# DP: Set site-packages/dist-packages + +--- a/Lib/site.py ++++ b/Lib/site.py +@@ -19,6 +19,12 @@ + resulting directories, if they exist, are appended to sys.path, and + also inspected for path configuration files. + ++For Debian and derivatives, this sys.path is augmented with directories ++for packages distributed within the distribution. Local addons go ++into /usr/local/lib/python/dist-packages, Debian addons ++install into /usr/{lib,share}/python/dist-packages. ++/usr/lib/python/site-packages is not used. ++ + A path configuration file is a file whose name has the form + .pth; its contents are additional directories (one per line) + to be added to sys.path. Non-existing directories (or +@@ -286,10 +292,12 @@ + if sys.platform in ('os2emx', 'riscos'): + sitepackages.append(os.path.join(prefix, "Lib", "site-packages")) + elif os.sep == '/': ++ sitepackages.append(os.path.join(prefix, "local/lib", ++ "python" + sys.version[:3], ++ "dist-packages")) + sitepackages.append(os.path.join(prefix, "lib", + "python" + sys.version[:3], +- "site-packages")) +- sitepackages.append(os.path.join(prefix, "lib", "site-python")) ++ "dist-packages")) + else: + sitepackages.append(prefix) + sitepackages.append(os.path.join(prefix, "lib", "site-packages")) --- python2.7-2.7.orig/debian/patches/no-zip-on-sys.path.diff +++ python2.7-2.7/debian/patches/no-zip-on-sys.path.diff @@ -0,0 +1,52 @@ +# DP: Do not add /usr/lib/pythonXY.zip on sys.path. + +--- a/Modules/getpath.c ++++ b/Modules/getpath.c +@@ -376,7 +376,9 @@ + char *path = getenv("PATH"); + char *prog = Py_GetProgramName(); + char argv0_path[MAXPATHLEN+1]; ++#ifdef WITH_ZIP_PATH + char zip_path[MAXPATHLEN+1]; ++#endif + int pfound, efound; /* 1 if found; -1 if found build directory */ + char *buf; + size_t bufsz; +@@ -516,6 +518,7 @@ + else + reduce(prefix); + ++#ifdef WITH_ZIP_PATH + strncpy(zip_path, prefix, MAXPATHLEN); + zip_path[MAXPATHLEN] = '\0'; + if (pfound > 0) { /* Use the reduced prefix returned by Py_GetPrefix() */ +@@ -528,6 +531,7 @@ + bufsz = strlen(zip_path); /* Replace "00" with version */ + zip_path[bufsz - 6] = VERSION[0]; + zip_path[bufsz - 5] = VERSION[2]; ++#endif + + if (!(efound = search_for_exec_prefix(argv0_path, home))) { + if (!Py_FrozenFlag) +@@ -567,7 +571,9 @@ + defpath = delim + 1; + } + ++#ifdef WITH_ZIP_PATH + bufsz += strlen(zip_path) + 1; ++#endif + bufsz += strlen(exec_prefix) + 1; + + /* This is the only malloc call in this file */ +@@ -588,9 +594,11 @@ + else + buf[0] = '\0'; + ++#ifdef WITH_ZIP_PATH + /* Next is the default zip path */ + strcat(buf, zip_path); + strcat(buf, delimiter); ++#endif + + /* Next goes merge of compile-time $PYTHONPATH with + * dynamically located prefix. --- python2.7-2.7.orig/debian/patches/bdist-wininst-notfound.diff +++ python2.7-2.7/debian/patches/bdist-wininst-notfound.diff @@ -0,0 +1,15 @@ +# DP: suggest installation of the pythonX.Y-dev package, if bdist_wininst +# DP: cannot find the wininst-* files. + +--- a/Lib/distutils/command/bdist_wininst.py ++++ b/Lib/distutils/command/bdist_wininst.py +@@ -356,5 +356,8 @@ + sfix = '' + + filename = os.path.join(directory, "wininst-%.1f%s.exe" % (bv, sfix)) +- return open(filename, "rb").read() ++ try: ++ return open(filename, "rb").read() ++ except IOError, msg: ++ raise DistutilsFileError, str(msg) + ', please install the python%s-dev package' % sys.version[:3] + # class bdist_wininst --- python2.7-2.7.orig/debian/patches/locale-module.diff +++ python2.7-2.7/debian/patches/locale-module.diff @@ -0,0 +1,17 @@ +# DP: * Lib/locale.py: +# DP: - Don't map 'utf8', 'utf-8' to 'utf', which is not a known encoding +# DP: for glibc. + +--- a/Lib/locale.py ++++ b/Lib/locale.py +@@ -1512,8 +1512,8 @@ + 'uk_ua.iso88595': 'uk_UA.ISO8859-5', + 'uk_ua.koi8u': 'uk_UA.KOI8-U', + 'uk_ua.microsoftcp1251': 'uk_UA.CP1251', +- 'univ': 'en_US.utf', +- 'universal': 'en_US.utf', ++ 'univ': 'en_US.UTF-8', ++ 'universal': 'en_US.UTF-8', + 'universal.utf8@ucs4': 'en_US.UTF-8', + 'ur': 'ur_PK.CP1256', + 'ur_pk': 'ur_PK.CP1256', --- python2.7-2.7.orig/debian/patches/profiled-build2.diff +++ python2.7-2.7/debian/patches/profiled-build2.diff @@ -0,0 +1,17 @@ +# DP: Fix profiled build; don't use Python/thread.gc*, gcc complains + +--- a/Makefile.pre.in ++++ b/Makefile.pre.in +@@ -383,9 +383,11 @@ + $(MAKE) all CFLAGS="$(CFLAGS) -fprofile-generate" LIBS="$(LIBS) -lgcov" + + run_profile_task: +- ./$(BUILDPYTHON) $(PROFILE_TASK) ++ -./$(BUILDPYTHON) $(PROFILE_TASK) + + build_all_use_profile: ++ : # FIXME: gcc error ++ rm -f Python/thread.gc* + $(MAKE) all CFLAGS="$(CFLAGS) -fprofile-use" + + coverage: --- python2.7-2.7.orig/debian/patches/svn-updates.diff +++ python2.7-2.7/debian/patches/svn-updates.diff @@ -0,0 +1,26032 @@ +# DP: SVN updates of the 2.7 release branch (until 2010-10-16). + +# svn diff http://svn.python.org/projects/python/tags/r27 http://svn.python.org/projects/python/branches/release27-maint | filterdiff --exclude=Lib/pstats.py --exclude=Lib/profile.py --exclude=.*ignore --addoldprefix=a/ --addnewprefix=b/ --remove-timestamps | grep -v '^[I=]' + +--- a/Python/ast.c ++++ b/Python/ast.c +@@ -688,10 +688,10 @@ + } + args = (n_args ? asdl_seq_new(n_args, c->c_arena) : NULL); + if (!args && n_args) +- return NULL; /* Don't need to goto error; no objects allocated */ ++ return NULL; + defaults = (n_defaults ? asdl_seq_new(n_defaults, c->c_arena) : NULL); + if (!defaults && n_defaults) +- return NULL; /* Don't need to goto error; no objects allocated */ ++ return NULL; + + /* fpdef: NAME | '(' fplist ')' + fplist: fpdef (',' fpdef)* [','] +@@ -711,7 +711,7 @@ + if (i + 1 < NCH(n) && TYPE(CHILD(n, i + 1)) == EQUAL) { + expr_ty expression = ast_for_expr(c, CHILD(n, i + 2)); + if (!expression) +- goto error; ++ return NULL; + assert(defaults != NULL); + asdl_seq_SET(defaults, j++, expression); + i += 2; +@@ -722,11 +722,11 @@ + def f((x, (y))): pass will just incur the tuple unpacking warning. */ + if (parenthesized && !complex_args) { + ast_error(n, "parenthesized arg with default"); +- goto error; ++ return NULL; + } + ast_error(n, + "non-default argument follows default argument"); +- goto error; ++ return NULL; + } + if (NCH(ch) == 3) { + ch = CHILD(ch, 1); +@@ -735,11 +735,11 @@ + /* We have complex arguments, setup for unpacking. */ + if (Py_Py3kWarningFlag && !ast_warn(c, ch, + "tuple parameter unpacking has been removed in 3.x")) +- goto error; ++ return NULL; + complex_args = 1; + asdl_seq_SET(args, k++, compiler_complex_args(c, ch)); + if (!asdl_seq_GET(args, k-1)) +- goto error; ++ return NULL; + } else { + /* def foo((x)): setup for checking NAME below. */ + /* Loop because there can be many parens and tuple +@@ -754,14 +754,14 @@ + PyObject *id; + expr_ty name; + if (!forbidden_check(c, n, STR(CHILD(ch, 0)))) +- goto error; ++ return NULL; + id = NEW_IDENTIFIER(CHILD(ch, 0)); + if (!id) +- goto error; ++ return NULL; + name = Name(id, Param, LINENO(ch), ch->n_col_offset, + c->c_arena); + if (!name) +- goto error; ++ return NULL; + asdl_seq_SET(args, k++, name); + + } +@@ -769,40 +769,35 @@ + if (parenthesized && Py_Py3kWarningFlag && + !ast_warn(c, ch, "parenthesized argument names " + "are invalid in 3.x")) +- goto error; ++ return NULL; + + break; + } + case STAR: + if (!forbidden_check(c, CHILD(n, i+1), STR(CHILD(n, i+1)))) +- goto error; ++ return NULL; + vararg = NEW_IDENTIFIER(CHILD(n, i+1)); + if (!vararg) +- goto error; ++ return NULL; + i += 3; + break; + case DOUBLESTAR: + if (!forbidden_check(c, CHILD(n, i+1), STR(CHILD(n, i+1)))) +- goto error; ++ return NULL; + kwarg = NEW_IDENTIFIER(CHILD(n, i+1)); + if (!kwarg) +- goto error; ++ return NULL; + i += 3; + break; + default: + PyErr_Format(PyExc_SystemError, + "unexpected node in varargslist: %d @ %d", + TYPE(ch), i); +- goto error; ++ return NULL; + } + } + + return arguments(args, vararg, kwarg, defaults, c->c_arena); +- +- error: +- Py_XDECREF(vararg); +- Py_XDECREF(kwarg); +- return NULL; + } + + static expr_ty +@@ -887,9 +882,9 @@ + + for (i = 0; i < NCH(n); i++) { + d = ast_for_decorator(c, CHILD(n, i)); +- if (!d) +- return NULL; +- asdl_seq_SET(decorator_seq, i, d); ++ if (!d) ++ return NULL; ++ asdl_seq_SET(decorator_seq, i, d); + } + return decorator_seq; + } +@@ -2247,11 +2242,10 @@ + return NULL; + } + e = ast_for_testlist(c, ch); +- +- /* set context to assign */ + if (!e) + return NULL; + ++ /* set context to assign */ + if (!set_context(c, e, Store, CHILD(n, i))) + return NULL; + +--- a/Python/pystate.c ++++ b/Python/pystate.c +@@ -298,7 +298,7 @@ + Py_FatalError("PyThreadState_Delete: tstate is still current"); + tstate_delete_common(tstate); + #ifdef WITH_THREAD +- if (autoTLSkey && PyThread_get_key_value(autoTLSkey) == tstate) ++ if (autoInterpreterState && PyThread_get_key_value(autoTLSkey) == tstate) + PyThread_delete_key_value(autoTLSkey); + #endif /* WITH_THREAD */ + } +@@ -314,7 +314,7 @@ + "PyThreadState_DeleteCurrent: no current tstate"); + _PyThreadState_Current = NULL; + tstate_delete_common(tstate); +- if (autoTLSkey && PyThread_get_key_value(autoTLSkey) == tstate) ++ if (autoInterpreterState && PyThread_get_key_value(autoTLSkey) == tstate) + PyThread_delete_key_value(autoTLSkey); + PyEval_ReleaseLock(); + } +@@ -534,7 +534,6 @@ + _PyGILState_Fini(void) + { + PyThread_delete_key(autoTLSkey); +- autoTLSkey = 0; + autoInterpreterState = NULL; + } + +@@ -546,10 +545,10 @@ + static void + _PyGILState_NoteThreadState(PyThreadState* tstate) + { +- /* If autoTLSkey is 0, this must be the very first threadstate created +- in Py_Initialize(). Don't do anything for now (we'll be back here +- when _PyGILState_Init is called). */ +- if (!autoTLSkey) ++ /* If autoTLSkey isn't initialized, this must be the very first ++ threadstate created in Py_Initialize(). Don't do anything for now ++ (we'll be back here when _PyGILState_Init is called). */ ++ if (!autoInterpreterState) + return; + + /* Stick the thread state for this thread in thread local storage. +@@ -577,7 +576,7 @@ + PyThreadState * + PyGILState_GetThisThreadState(void) + { +- if (autoInterpreterState == NULL || autoTLSkey == 0) ++ if (autoInterpreterState == NULL) + return NULL; + return (PyThreadState *)PyThread_get_key_value(autoTLSkey); + } +--- a/Python/pythonrun.c ++++ b/Python/pythonrun.c +@@ -1149,7 +1149,7 @@ + PySys_SetObject("last_traceback", tb); + } + hook = PySys_GetObject("excepthook"); +- if (hook) { ++ if (hook && hook != Py_None) { + PyObject *args = PyTuple_Pack(3, + exception, v, tb ? tb : Py_None); + PyObject *result = PyEval_CallObject(hook, args); +@@ -1199,7 +1199,7 @@ + int err = 0; + PyObject *f = PySys_GetObject("stderr"); + Py_INCREF(value); +- if (f == NULL) ++ if (f == NULL || f == Py_None) + fprintf(stderr, "lost sys.stderr\n"); + else { + if (Py_FlushLine()) +--- a/Python/dup2.c ++++ b/Python/dup2.c +@@ -12,6 +12,7 @@ + */ + + #include ++#include + + #define BADEXIT -1 + +--- a/Python/symtable.c ++++ b/Python/symtable.c +@@ -847,7 +847,7 @@ + st->st_cur = ste_new(st, name, block, ast, lineno); + if (st->st_cur == NULL) + return 0; +- if (name == GET_IDENTIFIER(top)) ++ if (block == ModuleBlock) + st->st_global = st->st_cur->ste_symbols; + if (prev) { + if (PyList_Append(prev->ste_children, +--- a/Python/getversion.c ++++ b/Python/getversion.c +@@ -9,7 +9,7 @@ + Py_GetVersion(void) + { + static char version[250]; +- PyOS_snprintf(version, sizeof(version), "%.80s (%.80s) %.80s", ++ PyOS_snprintf(version, sizeof(version), "%.80s (%.80s) %.80s", + PY_VERSION, Py_GetBuildInfo(), Py_GetCompiler()); + return version; + } +--- a/PCbuild/pythoncore.vcproj ++++ b/PCbuild/pythoncore.vcproj +@@ -683,10 +683,6 @@ + > + + +- +- + +@@ -719,6 +715,10 @@ + > + + ++ ++ + +@@ -911,10 +911,6 @@ + > + + +- +- + +@@ -1423,10 +1419,6 @@ + > + + +- +- + +@@ -1443,10 +1435,6 @@ + > + + +- +- + +@@ -1559,6 +1547,10 @@ + > + + ++ ++ + +@@ -1719,6 +1711,10 @@ + > + + ++ ++ + +@@ -1831,10 +1827,6 @@ + > + + +- +- + +--- a/PCbuild/pyd.vsprops ++++ b/PCbuild/pyd.vsprops +@@ -1,4 +1,4 @@ +- ++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ + + + +--- a/PCbuild/readme.txt ++++ b/PCbuild/readme.txt +@@ -55,7 +55,7 @@ + Visual C++ 6.0 + PC/VS7.1/ + Visual Studio 2003 (7.1) +-PCbuild8/ ++PC/VS8.0/ + Visual Studio 2005 (8.0) + + +@@ -155,6 +155,8 @@ + You must install the NASM assembler from + http://nasm.sf.net + for x86 builds. Put nasmw.exe anywhere in your PATH. ++ Note: recent releases of nasm only have nasm.exe. Just rename it to ++ nasmw.exe. + + You can also install ActivePerl from + http://www.activestate.com/Products/ActivePerl/ +--- a/Include/pyport.h ++++ b/Include/pyport.h +@@ -724,23 +724,24 @@ + # ifdef Py_BUILD_CORE + # define PyAPI_FUNC(RTYPE) __declspec(dllexport) RTYPE + # define PyAPI_DATA(RTYPE) extern __declspec(dllexport) RTYPE +- /* module init functions inside the core need no external linkage */ +- /* except for Cygwin to handle embedding (FIXME: BeOS too?) */ ++ /* module init functions inside the core need no external linkage */ ++ /* except for Cygwin to handle embedding (FIXME: BeOS too?) */ + # if defined(__CYGWIN__) + # define PyMODINIT_FUNC __declspec(dllexport) void + # else /* __CYGWIN__ */ + # define PyMODINIT_FUNC void + # endif /* __CYGWIN__ */ + # else /* Py_BUILD_CORE */ +- /* Building an extension module, or an embedded situation */ +- /* public Python functions and data are imported */ +- /* Under Cygwin, auto-import functions to prevent compilation */ +- /* failures similar to http://python.org/doc/FAQ.html#3.24 */ ++ /* Building an extension module, or an embedded situation */ ++ /* public Python functions and data are imported */ ++ /* Under Cygwin, auto-import functions to prevent compilation */ ++ /* failures similar to those described at the bottom of 4.1: */ ++ /* http://docs.python.org/extending/windows.html#a-cookbook-approach */ + # if !defined(__CYGWIN__) + # define PyAPI_FUNC(RTYPE) __declspec(dllimport) RTYPE + # endif /* !__CYGWIN__ */ + # define PyAPI_DATA(RTYPE) extern __declspec(dllimport) RTYPE +- /* module init functions outside the core must be exported */ ++ /* module init functions outside the core must be exported */ + # if defined(__cplusplus) + # define PyMODINIT_FUNC extern "C" __declspec(dllexport) void + # else /* __cplusplus */ +--- a/Include/Python.h ++++ b/Include/Python.h +@@ -150,13 +150,8 @@ + Set ml_flags in the PyMethodDef to METH_NOARGS. */ + #define PyArg_NoArgs(v) PyArg_Parse(v, "") + +-/* Convert a possibly signed character to a nonnegative int */ +-/* XXX This assumes characters are 8 bits wide */ +-#ifdef __CHAR_UNSIGNED__ +-#define Py_CHARMASK(c) (c) +-#else ++/* Argument must be a char or an int in [-128, 127] or [0, 255]. */ + #define Py_CHARMASK(c) ((unsigned char)((c) & 0xff)) +-#endif + + #include "pyfpe.h" + +--- a/Include/patchlevel.h ++++ b/Include/patchlevel.h +@@ -27,7 +27,7 @@ + #define PY_RELEASE_SERIAL 0 + + /* Version as a string */ +-#define PY_VERSION "2.7" ++#define PY_VERSION "2.7.0+" + /*--end constants--*/ + + /* Subversion Revision number of this file (not of the repository) */ +--- a/Include/abstract.h ++++ b/Include/abstract.h +@@ -1383,6 +1383,13 @@ + PyAPI_FUNC(int) _PyObject_RealIsSubclass(PyObject *derived, PyObject *cls); + + ++/* For internal use by buffer API functions */ ++PyAPI_FUNC(void) _Py_add_one_to_index_F(int nd, Py_ssize_t *index, ++ const Py_ssize_t *shape); ++PyAPI_FUNC(void) _Py_add_one_to_index_C(int nd, Py_ssize_t *index, ++ const Py_ssize_t *shape); ++ ++ + #ifdef __cplusplus + } + #endif +--- a/Include/object.h ++++ b/Include/object.h +@@ -492,6 +492,13 @@ + + /* A slot function whose address we need to compare */ + extern int _PyObject_SlotCompare(PyObject *, PyObject *); ++/* Same as PyObject_Generic{Get,Set}Attr, but passing the attributes ++ dict as the last parameter. */ ++PyAPI_FUNC(PyObject *) ++_PyObject_GenericGetAttrWithDict(PyObject *, PyObject *, PyObject *); ++PyAPI_FUNC(int) ++_PyObject_GenericSetAttrWithDict(PyObject *, PyObject *, ++ PyObject *, PyObject *); + + + /* PyObject_Dir(obj) acts like Python __builtin__.dir(obj), returning a +--- a/Demo/classes/Vec.py ++++ b/Demo/classes/Vec.py +@@ -1,23 +1,41 @@ +-# A simple vector class ++class Vec: ++ """ A simple vector class + ++ Instances of the Vec class can be constructed from numbers + +-def vec(*v): +- return Vec(*v) ++ >>> a = Vec(1, 2, 3) ++ >>> b = Vec(3, 2, 1) + ++ added ++ >>> a + b ++ Vec(4, 4, 4) + +-class Vec: ++ subtracted ++ >>> a - b ++ Vec(-2, 0, 2) + ++ and multiplied by a scalar on the left ++ >>> 3.0 * a ++ Vec(3.0, 6.0, 9.0) ++ ++ or on the right ++ >>> a * 3.0 ++ Vec(3.0, 6.0, 9.0) ++ """ + def __init__(self, *v): + self.v = list(v) + +- def fromlist(self, v): ++ @classmethod ++ def fromlist(cls, v): + if not isinstance(v, list): + raise TypeError +- self.v = v[:] +- return self ++ inst = cls() ++ inst.v = v ++ return inst + + def __repr__(self): +- return 'vec(' + repr(self.v)[1:-1] + ')' ++ args = ', '.join(repr(x) for x in self.v) ++ return 'Vec({0})'.format(args) + + def __len__(self): + return len(self.v) +@@ -27,28 +45,24 @@ + + def __add__(self, other): + # Element-wise addition +- v = map(lambda x, y: x+y, self, other) +- return Vec().fromlist(v) ++ v = [x + y for x, y in zip(self.v, other.v)] ++ return Vec.fromlist(v) + + def __sub__(self, other): + # Element-wise subtraction +- v = map(lambda x, y: x-y, self, other) +- return Vec().fromlist(v) ++ v = [x - y for x, y in zip(self.v, other.v)] ++ return Vec.fromlist(v) + + def __mul__(self, scalar): + # Multiply by scalar +- v = map(lambda x: x*scalar, self.v) +- return Vec().fromlist(v) ++ v = [x * scalar for x in self.v] ++ return Vec.fromlist(v) + ++ __rmul__ = __mul__ + + + def test(): +- a = vec(1, 2, 3) +- b = vec(3, 2, 1) +- print a +- print b +- print a+b +- print a-b +- print a*3.0 ++ import doctest ++ doctest.testmod() + + test() +--- a/configure.in ++++ b/configure.in +@@ -479,7 +479,7 @@ + without_gcc=$withval;; + esac], [ + case $ac_sys_system in +- AIX*) CC=cc_r ++ AIX*) CC=${CC:-xlc_r} + without_gcc=;; + BeOS*) + case $BE_HOST_CPU in +@@ -823,6 +823,10 @@ + BLDLIBRARY='-L. -lpython$(VERSION)' + RUNSHARED='DYLD_LIBRARY_PATH=`pwd`:${DYLD_LIBRARY_PATH}' + ;; ++ AIX*) ++ LDLIBRARY='libpython$(VERSION).so' ++ RUNSHARED=LIBPATH=`pwd`:${LIBPATH} ++ ;; + + esac + else # shared is disabled +@@ -1516,6 +1520,9 @@ + [AC_CHECK_SIZEOF(uintptr_t, 4)], + [], [#ifdef HAVE_STDINT_H + #include ++ #endif ++ #ifdef HAVE_INTTYPES_H ++ #include + #endif]) + + AC_CHECK_SIZEOF(off_t, [], [ +@@ -1757,7 +1764,7 @@ + then + case $ac_sys_system/$ac_sys_release in + AIX*) +- BLDSHARED="\$(srcdir)/Modules/ld_so_aix \$(CC) -bI:Modules/python.exp" ++ BLDSHARED="\$(srcdir)/Modules/ld_so_aix \$(CC) -bI:Modules/python.exp -L\$(srcdir)" + LDSHARED="\$(BINLIBDEST)/config/ld_so_aix \$(CC) -bI:\$(BINLIBDEST)/config/python.exp" + ;; + BeOS*) +@@ -2343,6 +2350,9 @@ + AIX/5) AC_DEFINE(HAVE_BROKEN_POSIX_SEMAPHORES, 1, + [Define if the Posix semaphores do not work on your system]) + ;; ++ AIX/6) AC_DEFINE(HAVE_BROKEN_POSIX_SEMAPHORES, 1, ++ Define if the Posix semaphores do not work on your system) ++ ;; + esac + + AC_MSG_CHECKING(if PTHREAD_SCOPE_SYSTEM is supported) +@@ -2771,14 +2781,24 @@ + [AC_MSG_RESULT(no) + ]) + +-AC_MSG_CHECKING(for flock) +-AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ +-#include +-]], [[void* p = flock]])], +- [AC_DEFINE(HAVE_FLOCK, 1, Define if you have the 'flock' function.) +- AC_MSG_RESULT(yes)], +- [AC_MSG_RESULT(no) ++AC_CACHE_CHECK([for flock declaration], [ac_cv_flock_decl], ++ [AC_COMPILE_IFELSE( ++ [AC_LANG_PROGRAM( ++ [#include ], ++ [void* p = flock] ++ )], ++ [ac_cv_flock_decl=yes], ++ [ac_cv_flock_decl=no] ++ ) + ]) ++if test "x${ac_cv_flock_decl}" = xyes; then ++ AC_CHECK_FUNCS(flock,, ++ AC_CHECK_LIB(bsd,flock, ++ [AC_DEFINE(HAVE_FLOCK) ++ AC_DEFINE(FLOCK_NEEDS_LIBBSD, 1, Define if flock needs to be linked with bsd library.) ++ ]) ++ ) ++fi + + AC_MSG_CHECKING(for getpagesize) + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ +@@ -4241,6 +4261,12 @@ + #endif + ]) + ++case $ac_sys_system in ++AIX*) ++ AC_DEFINE(HAVE_BROKEN_PIPE_BUF, 1, [Define if the system reports an invalid PIPE_BUF value.]) ;; ++esac ++ ++ + AC_SUBST(THREADHEADERS) + + for h in `(cd $srcdir;echo Python/thread_*.h)` +@@ -4260,6 +4286,7 @@ + + # generate output files + AC_CONFIG_FILES(Makefile.pre Modules/Setup.config Misc/python.pc) ++AC_CONFIG_FILES([Modules/ld_so_aix], [chmod +x Modules/ld_so_aix]) + AC_OUTPUT + + echo "creating Modules/Setup" +--- a/Grammar/Grammar ++++ b/Grammar/Grammar +@@ -11,9 +11,9 @@ + # "How to Change Python's Grammar" + + # Start symbols for the grammar: +-# single_input is a single interactive statement; +-# file_input is a module or sequence of commands read from an input file; +-# eval_input is the input for the eval() and input() functions. ++# single_input is a single interactive statement; ++# file_input is a module or sequence of commands read from an input file; ++# eval_input is the input for the eval() and input() functions. + # NB: compound_stmt in single_input is followed by extra NEWLINE! + single_input: NEWLINE | simple_stmt | compound_stmt NEWLINE + file_input: (NEWLINE | stmt)* ENDMARKER +@@ -68,9 +68,9 @@ + for_stmt: 'for' exprlist 'in' testlist ':' suite ['else' ':' suite] + try_stmt: ('try' ':' suite + ((except_clause ':' suite)+ +- ['else' ':' suite] +- ['finally' ':' suite] | +- 'finally' ':' suite)) ++ ['else' ':' suite] ++ ['finally' ':' suite] | ++ 'finally' ':' suite)) + with_stmt: 'with' with_item (',' with_item)* ':' suite + with_item: test ['as' expr] + # NB compile.c makes sure that the default except clause is last +--- a/setup.py ++++ b/setup.py +@@ -453,7 +453,7 @@ + # + + # Some modules that are normally always on: +- exts.append( Extension('_weakref', ['_weakref.c']) ) ++ #exts.append( Extension('_weakref', ['_weakref.c']) ) + + # array objects + exts.append( Extension('array', ['arraymodule.c']) ) +@@ -529,7 +529,11 @@ + # supported...) + + # fcntl(2) and ioctl(2) +- exts.append( Extension('fcntl', ['fcntlmodule.c']) ) ++ libs = [] ++ if (config_h_vars.get('FLOCK_NEEDS_LIBBSD', False)): ++ # May be necessary on AIX for flock function ++ libs = ['bsd'] ++ exts.append( Extension('fcntl', ['fcntlmodule.c'], libraries=libs) ) + # pwd(3) + exts.append( Extension('pwd', ['pwdmodule.c']) ) + # grp(3) +@@ -594,16 +598,18 @@ + # Determine if readline is already linked against curses or tinfo. + if do_readline and find_executable('ldd'): + fp = os.popen("ldd %s" % do_readline) +- for ln in fp: +- if 'curses' in ln: +- readline_termcap_library = re.sub( +- r'.*lib(n?cursesw?)\.so.*', r'\1', ln +- ).rstrip() +- break +- if 'tinfo' in ln: # termcap interface split out from ncurses +- readline_termcap_library = 'tinfo' +- break +- fp.close() ++ ldd_output = fp.readlines() ++ ret = fp.close() ++ if ret is None or ret >> 8 == 0: ++ for ln in ldd_output: ++ if 'curses' in ln: ++ readline_termcap_library = re.sub( ++ r'.*lib(n?cursesw?)\.so.*', r'\1', ln ++ ).rstrip() ++ break ++ if 'tinfo' in ln: # termcap interface split out from ncurses ++ readline_termcap_library = 'tinfo' ++ break + # Issue 7384: If readline is already linked against curses, + # use the same library for the readline and curses modules. + if 'curses' in readline_termcap_library: +@@ -1865,11 +1871,11 @@ + '_ctypes/callbacks.c', + '_ctypes/callproc.c', + '_ctypes/stgdict.c', +- '_ctypes/cfield.c', +- '_ctypes/malloc_closure.c'] ++ '_ctypes/cfield.c'] + depends = ['_ctypes/ctypes.h'] + + if sys.platform == 'darwin': ++ sources.append('_ctypes/malloc_closure.c') + sources.append('_ctypes/darwin/dlfcn_simple.c') + extra_compile_args.append('-DMACOSX') + include_dirs.append('_ctypes/darwin') +--- a/Objects/abstract.c ++++ b/Objects/abstract.c +@@ -443,7 +443,7 @@ + + + void +-_add_one_to_index_F(int nd, Py_ssize_t *index, Py_ssize_t *shape) ++_Py_add_one_to_index_F(int nd, Py_ssize_t *index, const Py_ssize_t *shape) + { + int k; + +@@ -459,7 +459,7 @@ + } + + void +-_add_one_to_index_C(int nd, Py_ssize_t *index, Py_ssize_t *shape) ++_Py_add_one_to_index_C(int nd, Py_ssize_t *index, const Py_ssize_t *shape) + { + int k; + +@@ -483,7 +483,7 @@ + PyBuffer_ToContiguous(void *buf, Py_buffer *view, Py_ssize_t len, char fort) + { + int k; +- void (*addone)(int, Py_ssize_t *, Py_ssize_t *); ++ void (*addone)(int, Py_ssize_t *, const Py_ssize_t *); + Py_ssize_t *indices, elements; + char *dest, *ptr; + +@@ -510,10 +510,10 @@ + } + + if (fort == 'F') { +- addone = _add_one_to_index_F; ++ addone = _Py_add_one_to_index_F; + } + else { +- addone = _add_one_to_index_C; ++ addone = _Py_add_one_to_index_C; + } + dest = buf; + /* XXX : This is not going to be the fastest code in the world +@@ -534,7 +534,7 @@ + PyBuffer_FromContiguous(Py_buffer *view, void *buf, Py_ssize_t len, char fort) + { + int k; +- void (*addone)(int, Py_ssize_t *, Py_ssize_t *); ++ void (*addone)(int, Py_ssize_t *, const Py_ssize_t *); + Py_ssize_t *indices, elements; + char *src, *ptr; + +@@ -561,10 +561,10 @@ + } + + if (fort == 'F') { +- addone = _add_one_to_index_F; ++ addone = _Py_add_one_to_index_F; + } + else { +- addone = _add_one_to_index_C; ++ addone = _Py_add_one_to_index_C; + } + src = buf; + /* XXX : This is not going to be the fastest code in the world +@@ -641,7 +641,7 @@ + elements *= view_src.shape[k]; + } + while (elements--) { +- _add_one_to_index_C(view_src.ndim, indices, view_src.shape); ++ _Py_add_one_to_index_C(view_src.ndim, indices, view_src.shape); + dptr = PyBuffer_GetPointer(&view_dest, indices); + sptr = PyBuffer_GetPointer(&view_src, indices); + memcpy(dptr, sptr, view_src.itemsize); +@@ -1713,7 +1713,14 @@ + if (m && m->nb_long) { /* This should include subclasses of long */ + /* Classic classes always take this branch. */ + PyObject *res = m->nb_long(o); +- if (res && (!PyInt_Check(res) && !PyLong_Check(res))) { ++ if (res == NULL) ++ return NULL; ++ if (PyInt_Check(res)) { ++ long value = PyInt_AS_LONG(res); ++ Py_DECREF(res); ++ return PyLong_FromLong(value); ++ } ++ else if (!PyLong_Check(res)) { + PyErr_Format(PyExc_TypeError, + "__long__ returned non-long (type %.200s)", + res->ob_type->tp_name); +--- a/Objects/object.c ++++ b/Objects/object.c +@@ -1317,7 +1317,7 @@ + /* Generic GetAttr functions - put these in your tp_[gs]etattro slot */ + + PyObject * +-PyObject_GenericGetAttr(PyObject *obj, PyObject *name) ++_PyObject_GenericGetAttrWithDict(PyObject *obj, PyObject *name, PyObject *dict) + { + PyTypeObject *tp = Py_TYPE(obj); + PyObject *descr = NULL; +@@ -1395,36 +1395,37 @@ + } + } + +- /* Inline _PyObject_GetDictPtr */ +- dictoffset = tp->tp_dictoffset; +- if (dictoffset != 0) { +- PyObject *dict; +- if (dictoffset < 0) { +- Py_ssize_t tsize; +- size_t size; ++ if (dict == NULL) { ++ /* Inline _PyObject_GetDictPtr */ ++ dictoffset = tp->tp_dictoffset; ++ if (dictoffset != 0) { ++ if (dictoffset < 0) { ++ Py_ssize_t tsize; ++ size_t size; + +- tsize = ((PyVarObject *)obj)->ob_size; +- if (tsize < 0) +- tsize = -tsize; +- size = _PyObject_VAR_SIZE(tp, tsize); ++ tsize = ((PyVarObject *)obj)->ob_size; ++ if (tsize < 0) ++ tsize = -tsize; ++ size = _PyObject_VAR_SIZE(tp, tsize); + +- dictoffset += (long)size; +- assert(dictoffset > 0); +- assert(dictoffset % SIZEOF_VOID_P == 0); ++ dictoffset += (long)size; ++ assert(dictoffset > 0); ++ assert(dictoffset % SIZEOF_VOID_P == 0); ++ } ++ dictptr = (PyObject **) ((char *)obj + dictoffset); ++ dict = *dictptr; + } +- dictptr = (PyObject **) ((char *)obj + dictoffset); +- dict = *dictptr; +- if (dict != NULL) { +- Py_INCREF(dict); +- res = PyDict_GetItem(dict, name); +- if (res != NULL) { +- Py_INCREF(res); +- Py_XDECREF(descr); +- Py_DECREF(dict); +- goto done; +- } ++ } ++ if (dict != NULL) { ++ Py_INCREF(dict); ++ res = PyDict_GetItem(dict, name); ++ if (res != NULL) { ++ Py_INCREF(res); ++ Py_XDECREF(descr); + Py_DECREF(dict); ++ goto done; + } ++ Py_DECREF(dict); + } + + if (f != NULL) { +@@ -1447,8 +1448,15 @@ + return res; + } + ++PyObject * ++PyObject_GenericGetAttr(PyObject *obj, PyObject *name) ++{ ++ return _PyObject_GenericGetAttrWithDict(obj, name, NULL); ++} ++ + int +-PyObject_GenericSetAttr(PyObject *obj, PyObject *name, PyObject *value) ++_PyObject_GenericSetAttrWithDict(PyObject *obj, PyObject *name, ++ PyObject *value, PyObject *dict) + { + PyTypeObject *tp = Py_TYPE(obj); + PyObject *descr; +@@ -1494,27 +1502,29 @@ + } + } + +- dictptr = _PyObject_GetDictPtr(obj); +- if (dictptr != NULL) { +- PyObject *dict = *dictptr; +- if (dict == NULL && value != NULL) { +- dict = PyDict_New(); +- if (dict == NULL) +- goto done; +- *dictptr = dict; ++ if (dict == NULL) { ++ dictptr = _PyObject_GetDictPtr(obj); ++ if (dictptr != NULL) { ++ dict = *dictptr; ++ if (dict == NULL && value != NULL) { ++ dict = PyDict_New(); ++ if (dict == NULL) ++ goto done; ++ *dictptr = dict; ++ } + } +- if (dict != NULL) { +- Py_INCREF(dict); +- if (value == NULL) +- res = PyDict_DelItem(dict, name); +- else +- res = PyDict_SetItem(dict, name, value); +- if (res < 0 && PyErr_ExceptionMatches(PyExc_KeyError)) +- PyErr_SetObject(PyExc_AttributeError, name); +- Py_DECREF(dict); +- goto done; +- } + } ++ if (dict != NULL) { ++ Py_INCREF(dict); ++ if (value == NULL) ++ res = PyDict_DelItem(dict, name); ++ else ++ res = PyDict_SetItem(dict, name, value); ++ if (res < 0 && PyErr_ExceptionMatches(PyExc_KeyError)) ++ PyErr_SetObject(PyExc_AttributeError, name); ++ Py_DECREF(dict); ++ goto done; ++ } + + if (f != NULL) { + res = f(descr, obj, value); +@@ -1536,6 +1546,13 @@ + return res; + } + ++int ++PyObject_GenericSetAttr(PyObject *obj, PyObject *name, PyObject *value) ++{ ++ return _PyObject_GenericSetAttrWithDict(obj, name, value, NULL); ++} ++ ++ + /* Test a value used as condition, e.g., in a for or if statement. + Return -1 if an error occurred */ + +--- a/Objects/typeobject.c ++++ b/Objects/typeobject.c +@@ -188,8 +188,8 @@ + + + static PyMemberDef type_members[] = { +- {"__basicsize__", T_INT, offsetof(PyTypeObject,tp_basicsize),READONLY}, +- {"__itemsize__", T_INT, offsetof(PyTypeObject, tp_itemsize), READONLY}, ++ {"__basicsize__", T_PYSSIZET, offsetof(PyTypeObject,tp_basicsize),READONLY}, ++ {"__itemsize__", T_PYSSIZET, offsetof(PyTypeObject, tp_itemsize), READONLY}, + {"__flags__", T_LONG, offsetof(PyTypeObject, tp_flags), READONLY}, + {"__weakrefoffset__", T_LONG, + offsetof(PyTypeObject, tp_weaklistoffset), READONLY}, +@@ -307,8 +307,11 @@ + static PyObject * + type_abstractmethods(PyTypeObject *type, void *context) + { +- PyObject *mod = PyDict_GetItemString(type->tp_dict, +- "__abstractmethods__"); ++ PyObject *mod = NULL; ++ /* type itself has an __abstractmethods__ descriptor (this). Don't return ++ that. */ ++ if (type != &PyType_Type) ++ mod = PyDict_GetItemString(type->tp_dict, "__abstractmethods__"); + if (!mod) { + PyErr_Format(PyExc_AttributeError, "__abstractmethods__"); + return NULL; +@@ -2655,7 +2658,7 @@ + {"__instancecheck__", type___instancecheck__, METH_O, + PyDoc_STR("__instancecheck__() -> check if an object is an instance")}, + {"__subclasscheck__", type___subclasscheck__, METH_O, +- PyDoc_STR("__subclasschck__ -> check if an class is a subclass")}, ++ PyDoc_STR("__subclasscheck__() -> check if a class is a subclass")}, + {0} + }; + +@@ -6001,7 +6004,7 @@ + wrap_descr_delete, "descr.__delete__(obj)"), + FLSLOT("__init__", tp_init, slot_tp_init, (wrapperfunc)wrap_init, + "x.__init__(...) initializes x; " +- "see x.__class__.__doc__ for signature", ++ "see help(type(x)) for signature", + PyWrapperFlag_KEYWORDS), + TPSLOT("__new__", tp_new, slot_tp_new, NULL, ""), + TPSLOT("__del__", tp_del, slot_tp_del, NULL, ""), +--- a/Objects/bytes_methods.c ++++ b/Objects/bytes_methods.c +@@ -332,7 +332,8 @@ + PyDoc_STRVAR_shared(_Py_capitalize__doc__, + "B.capitalize() -> copy of B\n\ + \n\ +-Return a copy of B with only its first character capitalized (ASCII)."); ++Return a copy of B with only its first character capitalized (ASCII)\n\ ++and the rest lower-cased."); + + void + _Py_bytes_capitalize(char *result, char *s, Py_ssize_t len) +--- a/Objects/unicodeobject.c ++++ b/Objects/unicodeobject.c +@@ -285,8 +285,7 @@ + reset: + /* Reset the object caches */ + if (unicode->defenc) { +- Py_DECREF(unicode->defenc); +- unicode->defenc = NULL; ++ Py_CLEAR(unicode->defenc); + } + unicode->hash = -1; + +@@ -294,7 +293,7 @@ + } + + /* We allocate one more byte to make sure the string is +- Ux0000 terminated -- XXX is this needed ? ++ Ux0000 terminated; some code relies on that. + + XXX This allocator could further be enhanced by assuring that the + free list never reduces its size below 1. +@@ -384,8 +383,7 @@ + unicode->length = 0; + } + if (unicode->defenc) { +- Py_DECREF(unicode->defenc); +- unicode->defenc = NULL; ++ Py_CLEAR(unicode->defenc); + } + /* Add to free list */ + *(PyUnicodeObject **)unicode = free_list; +@@ -5938,7 +5936,7 @@ + "S.capitalize() -> unicode\n\ + \n\ + Return a capitalized version of S, i.e. make the first character\n\ +-have upper case."); ++have upper case and the rest lower case."); + + static PyObject* + unicode_capitalize(PyUnicodeObject *self) +@@ -8417,7 +8415,7 @@ + else if (c >= '0' && c <= '9') { + prec = c - '0'; + while (--fmtcnt >= 0) { +- c = Py_CHARMASK(*fmt++); ++ c = *fmt++; + if (c < '0' || c > '9') + break; + if ((prec*10) / 10 != prec) { +--- a/Objects/memoryobject.c ++++ b/Objects/memoryobject.c +@@ -172,9 +172,6 @@ + return; + } + +-void _add_one_to_index_F(int nd, Py_ssize_t *index, Py_ssize_t *shape); +-void _add_one_to_index_C(int nd, Py_ssize_t *index, Py_ssize_t *shape); +- + static int + _indirect_copy_nd(char *dest, Py_buffer *view, char fort) + { +@@ -182,7 +179,7 @@ + int k; + Py_ssize_t elements; + char *ptr; +- void (*func)(int, Py_ssize_t *, Py_ssize_t *); ++ void (*func)(int, Py_ssize_t *, const Py_ssize_t *); + + if (view->ndim > PY_SSIZE_T_MAX / sizeof(Py_ssize_t)) { + PyErr_NoMemory(); +@@ -203,10 +200,10 @@ + elements *= view->shape[k]; + } + if (fort == 'F') { +- func = _add_one_to_index_F; ++ func = _Py_add_one_to_index_F; + } + else { +- func = _add_one_to_index_C; ++ func = _Py_add_one_to_index_C; + } + while (elements--) { + func(view->ndim, indices, view->shape); +@@ -632,7 +629,7 @@ + static int + memory_ass_sub(PyMemoryViewObject *self, PyObject *key, PyObject *value) + { +- Py_ssize_t start, len, bytelen, i; ++ Py_ssize_t start, len, bytelen; + Py_buffer srcview; + Py_buffer *view = &(self->view); + char *srcbuf, *destbuf; +@@ -642,6 +639,11 @@ + "cannot modify read-only memory"); + return -1; + } ++ if (value == NULL) { ++ PyErr_SetString(PyExc_TypeError, ++ "cannot delete memory"); ++ return -1; ++ } + if (view->ndim != 1) { + PyErr_SetNone(PyExc_NotImplementedError); + return -1; +@@ -702,16 +704,8 @@ + if (destbuf + bytelen < srcbuf || srcbuf + bytelen < destbuf) + /* No overlapping */ + memcpy(destbuf, srcbuf, bytelen); +- else if (destbuf < srcbuf) { +- /* Copy in ascending order */ +- for (i = 0; i < bytelen; i++) +- destbuf[i] = srcbuf[i]; +- } +- else { +- /* Copy in descencing order */ +- for (i = bytelen - 1; i >= 0; i--) +- destbuf[i] = srcbuf[i]; +- } ++ else ++ memmove(destbuf, srcbuf, bytelen); + + PyBuffer_Release(&srcview); + return 0; +--- a/Objects/fileobject.c ++++ b/Objects/fileobject.c +@@ -1735,8 +1735,10 @@ + file_write(PyFileObject *f, PyObject *args) + { + Py_buffer pbuf; +- char *s; ++ const char *s; + Py_ssize_t n, n2; ++ PyObject *encoded = NULL; ++ + if (f->f_fp == NULL) + return err_closed(); + if (!f->writable) +@@ -1746,14 +1748,41 @@ + return NULL; + s = pbuf.buf; + n = pbuf.len; +- } else +- if (!PyArg_ParseTuple(args, "t#", &s, &n)) +- return NULL; ++ } ++ else { ++ const char *encoding, *errors; ++ PyObject *text; ++ if (!PyArg_ParseTuple(args, "O", &text)) ++ return NULL; ++ ++ if (PyString_Check(text)) { ++ s = PyString_AS_STRING(text); ++ n = PyString_GET_SIZE(text); ++ } else if (PyUnicode_Check(text)) { ++ if (f->f_encoding != Py_None) ++ encoding = PyString_AS_STRING(f->f_encoding); ++ else ++ encoding = PyUnicode_GetDefaultEncoding(); ++ if (f->f_errors != Py_None) ++ errors = PyString_AS_STRING(f->f_errors); ++ else ++ errors = "strict"; ++ encoded = PyUnicode_AsEncodedString(text, encoding, errors); ++ if (encoded == NULL) ++ return NULL; ++ s = PyString_AS_STRING(encoded); ++ n = PyString_GET_SIZE(encoded); ++ } else { ++ if (PyObject_AsCharBuffer(text, &s, &n)) ++ return NULL; ++ } ++ } + f->f_softspace = 0; + FILE_BEGIN_ALLOW_THREADS(f) + errno = 0; + n2 = fwrite(s, 1, n, f->f_fp); + FILE_END_ALLOW_THREADS(f) ++ Py_XDECREF(encoded); + if (f->f_binary) + PyBuffer_Release(&pbuf); + if (n2 != n) { +--- a/Objects/stringlib/fastsearch.h ++++ b/Objects/stringlib/fastsearch.h +@@ -140,13 +140,13 @@ + /* got a match! */ + return i; + /* miss: check if previous character is part of pattern */ +- if (!STRINGLIB_BLOOM(mask, s[i-1])) ++ if (i > 0 && !STRINGLIB_BLOOM(mask, s[i-1])) + i = i - m; + else + i = i - skip; + } else { + /* skip: check if previous character is part of pattern */ +- if (!STRINGLIB_BLOOM(mask, s[i-1])) ++ if (i > 0 && !STRINGLIB_BLOOM(mask, s[i-1])) + i = i - m; + } + } +--- a/Objects/stringlib/formatter.h ++++ b/Objects/stringlib/formatter.h +@@ -1144,9 +1144,10 @@ + /* Omitted type specifier. Should be like str(self). */ + type = 'g'; + default_precision = PyFloat_STR_PRECISION; +- add_parens = 1; +- if (re == 0.0) ++ if (re == 0.0 && copysign(1.0, re) == 1.0) + skip_re = 1; ++ else ++ add_parens = 1; + } + + if (type == 'n') +@@ -1231,8 +1232,11 @@ + n_re_digits, n_re_remainder, + re_has_decimal, &locale, &tmp_format); + +- /* Same formatting, but always include a sign. */ +- tmp_format.sign = '+'; ++ /* Same formatting, but always include a sign, unless the real part is ++ * going to be omitted, in which case we use whatever sign convention was ++ * requested by the original format. */ ++ if (!skip_re) ++ tmp_format.sign = '+'; + n_im_total = calc_number_widths(&im_spec, 0, im_sign_char, p_im, + n_im_digits, n_im_remainder, + im_has_decimal, &locale, &tmp_format); +--- a/Objects/moduleobject.c ++++ b/Objects/moduleobject.c +@@ -175,10 +175,7 @@ + { + PyObject_GC_UnTrack(m); + if (m->md_dict != NULL) { +- /* If we are the only ones holding a reference, we can clear +- the dictionary. */ +- if (Py_REFCNT(m->md_dict) == 1) +- _PyModule_Clear((PyObject *)m); ++ _PyModule_Clear((PyObject *)m); + Py_DECREF(m->md_dict); + } + Py_TYPE(m)->tp_free((PyObject *)m); +--- a/Objects/setobject.c ++++ b/Objects/setobject.c +@@ -1855,12 +1855,10 @@ + if (!PySet_Check(key) || !PyErr_ExceptionMatches(PyExc_TypeError)) + return -1; + PyErr_Clear(); +- tmpkey = make_new_set(&PyFrozenSet_Type, NULL); ++ tmpkey = make_new_set(&PyFrozenSet_Type, key); + if (tmpkey == NULL) + return -1; +- set_swap_bodies((PySetObject *)tmpkey, (PySetObject *)key); + rv = set_contains(so, tmpkey); +- set_swap_bodies((PySetObject *)tmpkey, (PySetObject *)key); + Py_DECREF(tmpkey); + } + return rv; +@@ -1890,12 +1888,10 @@ + if (!PySet_Check(key) || !PyErr_ExceptionMatches(PyExc_TypeError)) + return NULL; + PyErr_Clear(); +- tmpkey = make_new_set(&PyFrozenSet_Type, NULL); ++ tmpkey = make_new_set(&PyFrozenSet_Type, key); + if (tmpkey == NULL) + return NULL; +- set_swap_bodies((PySetObject *)tmpkey, (PySetObject *)key); + rv = set_discard_key(so, tmpkey); +- set_swap_bodies((PySetObject *)tmpkey, (PySetObject *)key); + Py_DECREF(tmpkey); + if (rv == -1) + return NULL; +@@ -1924,12 +1920,10 @@ + if (!PySet_Check(key) || !PyErr_ExceptionMatches(PyExc_TypeError)) + return NULL; + PyErr_Clear(); +- tmpkey = make_new_set(&PyFrozenSet_Type, NULL); ++ tmpkey = make_new_set(&PyFrozenSet_Type, key); + if (tmpkey == NULL) + return NULL; +- set_swap_bodies((PySetObject *)tmpkey, (PySetObject *)key); + result = set_discard(so, tmpkey); +- set_swap_bodies((PySetObject *)tmpkey, (PySetObject *)key); + Py_DECREF(tmpkey); + return result; + } +--- a/Objects/stringobject.c ++++ b/Objects/stringobject.c +@@ -3580,7 +3580,7 @@ + #include "stringlib/string_format.h" + + PyDoc_STRVAR(format__doc__, +-"S.format(*args, **kwargs) -> unicode\n\ ++"S.format(*args, **kwargs) -> string\n\ + \n\ + "); + +@@ -3614,7 +3614,7 @@ + } + + PyDoc_STRVAR(p_format__doc__, +-"S.__format__(format_spec) -> unicode\n\ ++"S.__format__(format_spec) -> string\n\ + \n\ + "); + +--- a/Misc/NEWS.help ++++ b/Misc/NEWS.help +@@ -1,73 +0,0 @@ +- -*- text -*- +- +-If you edited Misc/NEWS before it was converted to ReST format skimming this +-file should help make the transition a bit easier. For full details about +-Docutils and ReST, go to the Docutils website: +- +- http://docutils.sourceforge.net/ +- +-To process Misc/NEWS using Docutils, you'll need the latest docutils +-snapshot: +- +- http://docutils.sf.net/docutils-snapshot.tgz +- +-Docutils works with Python 2.2 or newer. +- +-To process NEWS into NEWS.html, first install Docutils, and then run +-this command: +- +- python .../docutils/tools/rst2html.py NEWS NEWS.html +- +-Here ".../docutils" is the directory into which the above snapshot was +-extracted. (I hope this recipe will change for the better.) +- +-David Goodger made a change to the allowable structure of internal +-references which greatly simplified initial conversion of the file. +- +-The changes required fell into the following categories: +- +-* The top-level "What's New" section headers changed to: +- +- What's New in Python 2.3 alpha 1? +- ================================= +- +- *Release date: DD-MMM-2002* +- +- Note that the release date line is emphasized, with a "*" at each +- end. +- +-* Subsections are underlined with a single row of hyphens: +- +- Type/class unification and new-style classes +- -------------------------------------------- +- +-* Places where "balanced" single quotes were used were changed to use +- apostrophes as both the opening and closing quote (`string' -> 'string'). +- +-* In a few places asterisks needed to be escaped which would otherwise have +- been interpreted as beginning blocks of italic or bold text, e.g.: +- +- - The type of tp_free has been changed from "``void (*)(PyObject *)``" +- to "``void (*)(void *)``". +- +- Note that only the asterisks preceded by whitespace needed to be escaped. +- +-* One instance of a word ending with an underscore needed to be quoted +- ("PyCmp_" became "``PyCmp_``"). +- +-* One table was converted to ReST form (search Misc/NEWS for "New codecs" +- for this example). +- +-* A few places where chunks of code or indented text were displayed needed +- to be properly introduced (preceding paragraph terminated by "::" and the +- chunk of code or text indented w.r.t. the paragraph). For example: +- +- - Note that PyLong_AsDouble can fail! This has always been true, +- but no callers checked for it. It's more likely to fail now, +- because overflow errors are properly detected now. The proper way +- to check:: +- +- double x = PyLong_AsDouble(some_long_object); +- if (x == -1.0 && PyErr_Occurred()) { +- /* The conversion failed. */ +- } +--- a/Misc/maintainers.rst ++++ b/Misc/maintainers.rst +@@ -11,6 +11,10 @@ + a given module, then questionable changes should go to python-dev, while + any other issues can and should be decided by any committer. + ++Unless a name is followed by a '*', you should never assign an issue to ++that person, only make them nosy. Names followed by a '*' may be assigned ++issues involving the module or topic for which the name has a '*'. ++ + The Platform and Interest Area tables list broader fields in which various + people have expertise. These people can also be contacted for help, + opinions, and decisions when issues involve their areas. +@@ -21,8 +25,8 @@ + tracker id. They are of course free to remove that inactive mark at + any time. + +-Committers should update this table as their areas of expertise widen. +-New topics may be added to the third table at will. ++Committers should update these tables as their areas of expertise widen. ++New topics may be added to the Interest Area table at will. + + The existence of this list is not meant to indicate that these people + *must* be contacted for decisions; it is, rather, a resource to be used +@@ -43,14 +47,15 @@ + __future__ + __main__ gvanrossum + _dummy_thread brett.cannon +-_thread ++_thread pitrou ++_winreg brian.curtin* + abc + aifc r.david.murray + argparse bethard + array + ast +-asynchat josiahcarlson, giampaolo.rodola +-asyncore josiahcarlson, giampaolo.rodola ++asynchat josiahcarlson, giampaolo.rodola, stutzbach ++asyncore josiahcarlson, giampaolo.rodola, stutzbach + atexit + audioop + base64 +@@ -70,7 +75,7 @@ + code + codecs lemburg, doerwalter + codeop +-collections rhettinger ++collections rhettinger, stutzbach + colorsys + compileall + ConfigParser +@@ -81,16 +86,16 @@ + crypt + csv + ctypes theller +-curses andrew.kuchling ++curses akuchling + datetime alexander.belopolsky + dbm + decimal facundobatista, rhettinger, mark.dickinson + difflib tim_one + dis +-distutils tarek ++distutils tarek*, eric.araujo* + doctest tim_one (inactive) + dummy_threading brett.cannon +-email barry, r.david.murray ++email barry, r.david.murray* + encodings lemburg, loewis + errno + exceptions +@@ -111,7 +116,7 @@ + grp + gzip + hashlib +-heapq rhettinger ++heapq rhettinger, stutzbach + hmac + htmlentitydefs + htmllib +@@ -123,19 +128,19 @@ + imp + importlib brett.cannon + inspect +-io pitrou, benjamin.peterson ++io pitrou, benjamin.peterson, stutzbach + itertools rhettinger + json bob.ippolito (inactive) + keyword + lib2to3 benjamin.peterson + linecache + locale loewis, lemburg +-logging vsajip ++logging vinay.sajip + macpath +-mailbox andrew.kuchling ++mailbox akuchling + mailcap + marshal +-math mark.dickinson, rhettinger ++math mark.dickinson, rhettinger, stutzbach + mimetypes + mmap + modulefinder theller, jvr +@@ -151,7 +156,7 @@ + os loewis + ossaudiodev + parser +-pdb ++pdb georg.brandl* + pickle alexandre.vassalotti, pitrou + pickletools alexandre.vassalotti + pipes +@@ -161,7 +166,8 @@ + poplib + posix + pprint fdrake +-pstats ++profile georg.brandl ++pstats georg.brandl + pty + pwd + py_compile +@@ -171,7 +177,7 @@ + Queue rhettinger + quopri + random rhettinger +-re effbot (inactive), pitrou ++re effbot (inactive), pitrou, ezio.melotti + readline + reprlib + resource +@@ -194,7 +200,7 @@ + sqlite3 ghaering + ssl janssen, pitrou, giampaolo.rodola + stat +-string ++string georg.brandl* + stringprep + struct mark.dickinson + subprocess astrand (inactive) +@@ -207,18 +213,18 @@ + tabnanny tim_one + tarfile lars.gustaebel + telnetlib +-tempfile ++tempfile georg.brandl + termios + test +-textwrap +-threading ++textwrap georg.brandl ++threading pitrou + time alexander.belopolsky +-timeit ++timeit georg.brandl + Tkinter gpolo + token georg.brandl + tokenize +-trace +-traceback georg.brandl ++trace alexander.belopolsky ++traceback georg.brandl* + tty + turtle gregorlingl + types +@@ -229,16 +235,23 @@ + uuid + warnings brett.cannon + wave +-weakref fdrake ++weakref fdrake, pitrou + webbrowser georg.brandl +-winreg ++_winreg brian.curtin*, stutzbach + winsound effbot (inactive) + wsgiref pje + xdrlib +-xml loewis ++xml.dom ++xml.dom.minidom ++xml.dom.pulldom + xml.etree effbot (inactive) ++xml.parsers.expat ++xml.sax ++xml.sax.handler ++xml.sax.saxutils ++xml.sax.xmlreader + xmlrpc loewis +-zipfile ++zipfile alanmcintyre + zipimport + zlib + ================== =========== +@@ -248,13 +261,14 @@ + Tool Maintainers + ------------------ ----------- + pybench lemburg ++================== =========== + + + ================== =========== + Platform Maintainers + ------------------ ----------- + AIX +-Cygwin jlt63 ++Cygwin jlt63, stutzbach + FreeBSD + HP-UX + Linux +@@ -262,7 +276,7 @@ + NetBSD1 + OS2/EMX aimacintyre + Solaris +-Windows ++Windows tim.golden, brian.curtin + ================== =========== + + +@@ -273,6 +287,7 @@ + ast/compiler ncoghlan, benjamin.peterson, brett.cannon, georg.brandl + autoconf/makefiles + bsd ++bug tracker ezio.melotti + buildbots + bytecode pitrou + data formats mark.dickinson, georg.brandl +@@ -281,9 +296,9 @@ + GUI + i18n lemburg + import machinery brett.cannon, ncoghlan +-io pitrou, benjamin.peterson ++io pitrou, benjamin.peterson, stutzbach + locale lemburg, loewis +-mathematics mark.dickinson, eric.smith, lemburg ++mathematics mark.dickinson, eric.smith, lemburg, stutzbach + memory management tim_one, lemburg + networking giampaolo.rodola + packaging tarek, lemburg +@@ -291,10 +306,9 @@ + release management tarek, lemburg, benjamin.peterson, barry, loewis, + gvanrossum, anthonybaxter + str.format eric.smith ++testing michael.foord, pitrou, giampaolo.rodola ++threads pitrou + time and dates lemburg +-testing michael.foord, pitrou, giampaolo.rodola +-threads +-tracker + unicode lemburg, ezio.melotti, haypo + version control + ================== =========== +--- a/Misc/developers.txt ++++ b/Misc/developers.txt +@@ -16,17 +16,49 @@ + agreement from the committer. See http://www.python.org/psf/contrib/ + for details. When the agreement is signed, please note it in this log. + ++This file is encoded in UTF-8. If the usual form for a name is not in ++a Latin or extended Latin alphabet, make sure to include an ASCII ++transliteration too. + + Permissions History + ------------------- + ++- Tal Einat was given commit access on Oct 4 2010 by MvL, ++ for improving IDLE. ++ ++- Åukasz Langa was given commit access on Sep 08 2010 by GFB, ++ at suggestion of Antoine Pitrou, for general bug fixing. ++ ++- Daniel Stutzbach was given commit access on Aug 22 2010 by MvL, ++ for general bug fixing. ++ ++- Ask Solem was given commit access on Aug 17 2010 by MvL, ++ on recommendation by Jesse Noller, for work on the multiprocessing ++ library. ++ ++- George Boutsioukis was given commit access on Aug 10 2010 ++ by MvL, for work on 2to3. ++ ++- Éric Araujo was given commit access on Aug 10 2010 by BAC, ++ at suggestion of Tarek Ziadé. ++ ++- Terry Reedy was given commit access on Aug 04 2010 by MvL, ++ at suggestion of Nick Coghlan. ++ ++- Brian Quinlan was given commit access on Jul 26 2010 by GFB, ++ for work related to PEP 3148. ++ ++- Reid Kleckner was given commit access on Jul 11 2010 by GFB, ++ for work on the py3k-jit branch, at suggestion of the Unladen ++ Swallow team. ++ + - Alexander Belopolsky was given commit access on May 25 2010 + by MvL at suggestion of Mark Dickinson. + + - Tim Golden was given commit access on April 21 2010 by MvL, + at suggestion of Michael Foord. + +-- Giampaolo Rodolà was given commit access on April 17 2010 by ++- Giampaolo Rodolà was given commit access on April 17 2010 by + MvL, at suggestion of R. David Murray. + + - Jean-Paul Calderone was given commit access on April 6 2010 by +@@ -70,7 +102,7 @@ + - Chris Withers was given SVN access on March 8 2009 by MvL, + after recommendation by GvR. + +-- Tarek Ziadé was given SVN access on December 21 2008 by NCN, ++- Tarek Ziadé was given SVN access on December 21 2008 by NCN, + for maintenance of distutils. + + - Hirokazu Yamamoto was given SVN access on August 12 2008 by MvL, +@@ -139,7 +171,7 @@ + for his work on the SSL module and other things related to (SSL) sockets. + + - Jeffrey Yasskin was given SVN access on 9 August 2007 by NCN, +- for his work on PEPs and other general patches. ++ for his work on PEPs and other general patches. + + - Mark Summerfield was given SVN access on 1 August 2007 by GFB, + for work on documentation. +@@ -183,12 +215,12 @@ + have their work reviewed before changes are accepted into the trunk. + + - Matt Fleming was added on 25 May 2006 by AMK; he'll be working on +- enhancing the Python debugger. ++ enhancing the Python debugger. + + - Jackilyn Hoxworth was added on 25 May 2006 by AMK; she'll be adding logging +- to the standard library. ++ to the standard library. + +- - Mateusz Rukowicz was added on 30 May 2006 by AMK; he'll be ++ - Mateusz Rukowicz was added on 30 May 2006 by AMK; he'll be + translating the decimal module into C. + + - SVN access granted to the "Need for Speed" Iceland sprint attendees, +@@ -200,7 +232,7 @@ + Christian Tismer + Jack Diederich + John Benediktsson +- Kristján V. Jónsson ++ Kristján V. Jónsson + Martin Blais + Richard Emslie + Richard Jones +--- a/Misc/python.man ++++ b/Misc/python.man +@@ -401,9 +401,18 @@ + .IP PYTHONINSPECT + If this is set to a non-empty string it is equivalent to specifying + the \fB\-i\fP option. ++.IP PYTHONIOENCODING ++If this is set before running the interpreter, it overrides the encoding used ++for stdin/stdout/stderr, in the syntax ++.IB encodingname ":" errorhandler ++The ++.IB errorhandler ++part is optional and has the same meaning as in str.encode. For stderr, the ++.IB errorhandler ++ part is ignored; the handler will always be \'backslashreplace\'. + .IP PYTHONNOUSERSITE +-If this is set to a non-empty string it is equivalent to specifying +-the \fB\-s\fP option (Don't add the user site directory to sys.path). ++If this is set to a non-empty string it is equivalent to specifying the ++\fB\-s\fP option (Don't add the user site directory to sys.path). + .IP PYTHONUNBUFFERED + If this is set to a non-empty string it is equivalent to specifying + the \fB\-u\fP option. +--- a/Misc/NEWS ++++ b/Misc/NEWS +@@ -2,8 +2,476 @@ + Python News + +++++++++++ + +-(editors: check NEWS.help for information about editing NEWS using ReST.) ++What's New in Python 2.7.1? ++=========================== + ++*Release date: XXXX-XX-XX* ++ ++Core and Builtins ++----------------- ++ ++- Issue #9997: Don't let the name "top" have special significance in scope ++ resolution. ++ ++- Issue #9862: Compensate for broken PIPE_BUF in AIX by hard coding ++ its value as the default 512 when compiling on AIX. ++ ++- Issue #10068: Global objects which have reference cycles with their module's ++ dict are now cleared again. This causes issue #7140 to appear again. ++ ++- Issue #9869: Make long() and PyNumber_Long return something of type ++ long for a class whose __long__ method returns a plain int. This ++ fixes an interpreter crash when initializing an instance of a long ++ subclass from an object whose __long__ method returns a plain int. ++ ++- Issue #10006: type.__abstractmethods__ now raises an AttributeError. ++ ++- Issue #9797: pystate.c wrongly assumed that zero couldn't be a valid ++ thread-local storage key. ++ ++- Issue #4947: The write() method of sys.stdout and sys.stderr uses their ++ encoding and errors attributes instead of using utf-8 in strict mode, to get ++ the same behaviour than the print statement. ++ ++- Issue #9737: Fix a crash when trying to delete a slice or an item from ++ a memoryview object. ++ ++- Restore GIL in nis_cat in case of error. ++ ++- Issue #9688: __basicsize__ and __itemsize__ must be accessed as Py_ssize_t. ++ ++- Issue #8530: Prevent stringlib fastsearch from reading beyond the front ++ of an array. ++ ++- Issue #83755: Implicit set-to-frozenset conversion was not thread-safe. ++ ++- Issue #9416: Fix some issues with complex formatting where the ++ output with no type specifier failed to match the str output: ++ ++ - format(complex(-0.0, 2.0), '-') omitted the real part from the output, ++ - format(complex(0.0, 2.0), '-') included a sign and parentheses. ++ ++- Issue #7616: Fix copying of overlapping memoryview slices with the Intel ++ compiler. ++ ++Library ++------- ++ ++- Issue 9409: Fix the regex to match all kind of filenames, for interactive ++ debugging in doctests. ++ ++- Issue #6612: Fix site and sysconfig to catch os.getcwd() error, eg. if the ++ current directory was deleted. Patch written by W. Trevor King. ++ ++- Issue #10045: Improved performance when writing after seeking past the ++ end of the "file" in cStringIO. ++ ++- Issue #9948: Fixed problem of losing filename case information. ++ ++- Issue #9437: Fix building C extensions with non-default LDFLAGS. ++ ++- Issue #9759: GzipFile now raises ValueError when an operation is attempted ++ after the file is closed. Patch by Jeffrey Finkelstein. ++ ++- Issue #9042: Fix interaction of custom translation classes and caching in ++ gettext. ++ ++- Issue #9065: tarfile no longer uses "root" as the default for the uname and ++ gname field. ++ ++- Issue #1050268: parseaddr now correctly quotes double quote and backslash ++ characters that appear inside quoted strings in email addresses. ++ ++- Issue #10004: quoprimime no longer generates a traceback when confronted ++ with invalid characters after '=' in a Q-encoded word. ++ ++- Issue #9950: Fix socket.sendall() crash or misbehaviour when a signal is ++ received. Now sendall() properly calls signal handlers if necessary, ++ and retries sending if these returned successfully, including on sockets ++ with a timeout. ++ ++- Issue #9947: logging: Fixed locking bug in stopListening. ++ ++- Issue #9945: logging: Fixed locking bugs in addHandler/removeHandler. ++ ++- Issue #9936: Fixed executable lines' search in the trace module. ++ ++- Issue #9928: Properly initialize the types exported by the bz2 module. ++ ++- Issue #9854: The default read() implementation in io.RawIOBase now ++ handles non-blocking readinto() returning None correctly. ++ ++- Issue #9729: Fix the signature of SSLSocket.recvfrom() and ++ SSLSocket.sendto() to match the corresponding socket methods. Also, ++ fix various SSLSocket methods to raise socket.error rather than an ++ unhelpful TypeError when called on an unconnected socket. Original patch ++ by Andrew Bennetts. ++ ++- Issue #9826: OrderedDict.__repr__ can now handle self-referential ++ values: d['x'] = d. ++ ++- Issue #767645: Set os.path.supports_unicode_filenames to True on Mac OS X. ++ ++- Issue #9837: The read() method of ZipExtFile objects (as returned by ++ ZipFile.open()) could return more bytes than requested. ++ ++- Issue #9825: removed __del__ from the definition of collections.OrderedDict. ++ This prevents user-created self-referencing ordered dictionaries from ++ becoming permanently uncollectable GC garbage. The downside is that ++ removing __del__ means that the internal doubly-linked list has to wait for ++ GC collection rather than freeing memory immediately when the refcnt drops ++ to zero. ++ ++- Issue #9816: random.Random.jumpahead(n) did not produce a sufficiently ++ different internal state for small values of n. Fixed by salting the ++ value. ++ ++- Issue #9792: In case of connection failure, socket.create_connection() ++ would swallow the exception and raise a new one, making it impossible ++ to fetch the original errno, or to filter timeout errors. Now the ++ original error is re-raised. ++ ++- Issue #9758: When fcntl.ioctl() was called with mutable_flag set to True, ++ and the passed buffer was exactly 1024 bytes long, the buffer wouldn't ++ be updated back after the system call. Original patch by Brian Brazil. ++ ++- Issue #1100562: Fix deep-copying of objects derived from the list and ++ dict types. Patch by Michele Orrù and Björn Lindqvist. ++ ++- Issue #7005: Fixed output of None values for RawConfigParser.write and ++ ConfigParser.write. ++ ++- Issue #808164: Fixed socket.close to avoid references to globals, to ++ avoid issues when socket.close is called from a __del__ method. ++ ++- Issue #8797: urllib2 does a retry for Basic Authentication failure instead of ++ falling into recursion. ++ ++- Issue #1194222: email.utils.parsedate now returns RFC2822 compliant four ++ character years even if the message contains RFC822 two character years. ++ ++- Issue #8750: Fixed MutableSet's methods to correctly handle ++ reflexive operations, namely x -= x and x ^= x. ++ ++- Issue #9129: smtpd.py is vulnerable to DoS attacks deriving from missing ++ error handling when accepting a new connection. ++ ++- Issue #658749: asyncore's connect() method now correctly interprets winsock ++ errors. ++ ++- Issue #9501: Fixed logging regressions in cleanup code. ++ ++- Issue #9214: Set operations on KeysView or ItemsView in the collections ++ module now correctly return a set. (Patch by Eli Bendersky.) ++ ++- Issue #9617: Signals received during a low-level write operation aren't ++ ignored by the buffered IO layer anymore. ++ ++- Issue #2521: Use weakrefs on for caching in the abc module, so that classes ++ are not held onto after they are deleted elsewhere. ++ ++- Issue #9626: the view methods for collections.OrderedDict() were returning ++ the unordered versions inherited from dict. Those methods are now ++ overridden to provide ordered views. ++ ++- Issue #8688: MANIFEST files created by distutils now include a magic ++ comment indicating they are generated. Manually maintained MANIFESTs ++ without this marker will not be overwritten or removed. ++ ++- Issue #7467: when reading a file from a ZIP archive, its CRC is checked ++ and a BadZipfile error is raised if it doesn't match (as used to be the ++ case in Python 2.5 and earlier). ++ ++- Issue #9550: a BufferedReader could issue an additional read when the ++ original read request had been satisfied, which could block indefinitely ++ when the underlying raw IO channel was e.g. a socket. Report and original ++ patch by Jason V. Miller. ++ ++- Issue #9551: Don't raise TypeError when setting the value to None for ++ SafeConfigParser instances constructed with allow_no_value == True. ++ ++- Issue #6915: Under Windows, os.listdir() didn't release the Global ++ Interpreter Lock around all system calls. Original patch by Ryan Kelly. ++ ++- Issue #3757: thread-local objects now support cyclic garbage collection. ++ Thread-local objects involved in reference cycles will be deallocated ++ timely by the cyclic GC, even if the underlying thread is still running. ++ ++- Issue #6231: Fix xml.etree.ElementInclude to include the tail of the ++ current node. ++ ++- Issue #6869: Fix a refcount problem in the _ctypes extension. ++ ++- Issue5504 - ctypes should now work with systems where mmap can't be ++ PROT_WRITE and PROT_EXEC. ++ ++- Fix Issue8280 - urllib2's Request method will remove fragements in the url. ++ This is how it is supposed to work, wget and curl do the same. Previous ++ behavior was wrong. ++ ++- Issue #2944: asyncore doesn't handle connection refused correctly. ++ ++- Issue #3196: email header decoding is now forgiving if an RFC2047 ++ encoded word encoded in base64 is lacking padding. ++ ++- Issue #9444: Argparse now uses the first element of prefix_chars as ++ the option character for the added 'h/help' option if prefix_chars ++ does not contain a '-', instead of raising an error. ++ ++- Issue #9354: Provide getsockopt() in asyncore's file_wrapper. ++ ++- Issue #9428: Fix running scripts with the profile/cProfile modules from ++ the command line. ++ ++- Issue #7781: Fix restricting stats by entry counts in the pstats ++ interactive browser. ++ ++- Issue #9209: Do not crash in the pstats interactive browser on invalid ++ regular expressions. ++ ++- Issue #7372: Fix pstats regression when stripping paths from profile ++ data generated with the profile module. ++ ++- Issue #4108: In urllib.robotparser, if there are multiple 'User-agent: *' ++ entries, consider the first one. ++ ++- Issue #8397: Raise an error when attempting to mix iteration and regular ++ reads on a BZ2File object, rather than returning incorrect results. ++ ++- Issue #5294: Fix the behavior of pdb's "continue" command when called ++ in the top-level debugged frame. ++ ++- Issue #5727: Restore the ability to use readline when calling into pdb ++ in doctests. ++ ++- Issue #6719: In pdb, do not stop somewhere in the encodings machinery ++ if the source file to be debugged is in a non-builtin encoding. ++ ++- Issue #8048: Prevent doctests from failing when sys.displayhook has ++ been reassigned. ++ ++- Issue #8015: In pdb, do not crash when an empty line is entered as ++ a breakpoint command. ++ ++- Issue #9448: Fix a leak of OS resources (mutexes or semaphores) when ++ re-initializing a buffered IO object by calling its ``__init__`` method. ++ ++- Issue #7909: Do not touch paths with the special prefixes ``\\.\`` ++ or ``\\?\`` in ntpath.normpath(). ++ ++- Issue #5146: Handle UID THREAD command correctly in imaplib. ++ ++- Issue #5147: Fix the header generated for cookie files written by ++ http.cookiejar.MozillaCookieJar. ++ ++- Issue #8198: In pydoc, output all help text to the correct stream ++ when sys.stdout is reassigned. ++ ++- Issue #7395: Fix tracebacks in pstats interactive browser. ++ ++- Issue #8230: Fix Lib/test/sortperf.py. ++ ++- Issue #1713: Fix os.path.ismount(), which returned true for symbolic links ++ across devices. ++ ++- Issue #8826: Properly load old-style "expires" attribute in http.cookies. ++ ++- Issue #1690103: Fix initial namespace for code run with trace.main(). ++ ++- Issue #8471: In doctest, properly reset the output stream to an empty ++ string when Unicode was previously output. ++ ++- Issue #8620: when a Cmd is fed input that reaches EOF without a final ++ newline, it no longer truncates the last character of the last command line. ++ ++- Issue #6213: Implement getstate() and setstate() methods of utf-8-sig and ++ utf-16 incremental encoders. ++ ++- Issue #7113: Speed up loading in ConfigParser. Patch by Åukasz Langa. ++ ++- Issue #3704: cookielib was not properly handling URLs with a / in the ++ parameters. ++ ++- Issue #9032: XML-RPC client retries the request on EPIPE error. The EPIPE ++ error occurs when the server closes the socket and the client sends a big ++ XML-RPC request. ++ ++- Issue #5542: Remove special logic that closes HTTPConnection socket on EPIPE. ++ ++- Issue #4629: getopt raises an error if an argument ends with = whereas getopt ++ doesn't except a value (eg. --help= is rejected if getopt uses ['help='] long ++ options). ++ ++- Issue #7895: platform.mac_ver() no longer crashes after calling os.fork() ++ ++- Issue #5395: array.fromfile() would raise a spurious EOFError when an ++ I/O error occurred. Now an IOError is raised instead. Patch by chuck ++ (Jan Hosang). ++ ++- Issue #7646: The fnmatch pattern cache no longer grows without bound. ++ ++- Issue #9136: Fix 'dictionary changed size during iteration' ++ RuntimeError produced when profiling the decimal module. This was ++ due to a dangerous iteration over 'locals()' in Context.__init__. ++ ++- Fix extreme speed issue in Decimal.pow when the base is an exact ++ power of 10 and the exponent is tiny (for example, ++ Decimal(10) ** Decimal('1e-999999999')). ++ ++- Issue #9161: Fix regression in optparse's acceptance of unicode ++ strings in add_option calls. ++ ++- Issue #9130: Fix validation of relative imports in parser module. ++ ++- Issue #9128: Fix validation of class decorators in parser module. ++ ++- Issue #9164: Ensure sysconfig handles dupblice archs while building on OSX ++ ++- Issue #9315: Fix for the trace module to record correct class name ++ for tracing methods. ++ ++Extension Modules ++----------------- ++ ++- Issue #10003: Allow handling of SIGBREAK on Windows. Fixes a regression ++ introduced by issue #9324. ++ ++- Issue #8734: Avoid crash in msvcrt.get_osfhandle() when an invalid file ++ descriptor is provided. Patch by Pascal Chambon. ++ ++- Issue #7736: Release the GIL around calls to opendir() and closedir() ++ in the posix module. Patch by Marcin Bachry. ++ ++- As a result of issue #2521, the _weakref module is now compiled into the ++ interpreter by default. ++ ++- Issue #9324: Add parameter validation to signal.signal on Windows in order ++ to prevent crashes. ++ ++- Issue #9526: Remove some outdated (int) casts that were preventing ++ the array module from working correctly with arrays of more than ++ 2**31 elements. ++ ++- Fix memory leak in ssl._ssl._test_decode_cert. ++ ++- Issue #8065: Fix memory leak in readline module (from failure to ++ free the result of history_get_history_state()). ++ ++- Issue #9450: Fix memory leak in readline.replace_history_item and ++ readline.remove_history_item for readline version >= 5.0. ++ ++- Issue #8105: Validate file descriptor passed to mmap.mmap on Windows. ++ ++- Issue #1019882: Fix IndexError when loading certain hotshot stats. ++ ++- Issue #9422: Fix memory leak when re-initializing a struct.Struct object. ++ ++- Issue #7900: The getgroups(2) system call on MacOSX behaves rather oddly ++ compared to other unix systems. In particular, os.getgroups() does ++ not reflect any changes made using os.setgroups() but basicly always ++ returns the same information as the id command. ++ ++ os.getgroups() can now return more than 16 groups on MacOSX. ++ ++- Issue #9277: Fix bug in struct.pack for bools in standard mode ++ (e.g., struct.pack('>?')): if conversion to bool raised an exception ++ then that exception wasn't properly propagated on machines where ++ char is unsigned. ++ ++- Issue #7567: Don't call `setupterm' twice. ++ ++Tools/Demos ++----------- ++ ++- Issue #7287: Demo/imputil/knee.py was removed. ++ ++- Issue #9188: The gdb extension now handles correctly narrow (UCS2) as well ++ as wide (UCS4) unicode builds for both the host interpreter (embedded ++ inside gdb) and the interpreter under test. ++ ++Build ++----- ++ ++- Issue #10054: Some platforms provide uintptr_t in inttypes.h. Patch by ++ Akira Kitada. ++ ++- Issue #10055: Make json C89-compliant in UCS4 mode. ++ ++- Issue #1633863: Don't ignore $CC under AIX. ++ ++- Issue #9810: Compile bzip2 source files in python's project file ++ directly. It used to be built with bzip2's makefile. ++ ++- Issue #941346: Improve the build process under AIX and allow Python to ++ be built as a shared library. Patch by Sébastien Sablé. ++ ++- Issue #4026: Make the fcntl extension build under AIX. Patch by Sébastien ++ Sablé. ++ ++- Issue #3101: Helper functions _add_one_to_index_C() and ++ _add_one_to_index_F() become _Py_add_one_to_index_C() and ++ _Py_add_one_to_index_F(), respectively. ++ ++- Issue #9700: define HAVE_BROKEN_POSIX_SEMAPHORES under AIX 6.x. Patch by ++ Sébastien Sablé. ++ ++- Issue #9280: Make sharedinstall depend on sharedmods. ++ ++- Issue #9275: The OSX installer once again installs links to binaries in ++ ``/usr/local/bin``. ++ ++- Issue #9392: A framework build on OSX will once again use a versioned name ++ of the ``2to3`` tool, that is you can use ``2to3-2.7`` to select the Python ++ 2.7 edition of 2to3. ++ ++- Issue #9701: The MacOSX installer can patch the shell profile to ensure that ++ the "bin" directory inside the framework is on the shell's search path. This ++ feature now also supports the ZSH shell. ++ ++ ++Tests ++----- ++ ++- Issue #9978: Wait until subprocess completes initialization. (Win32KillTests ++ in test_os) ++ ++- Issue #9894: Do not hardcode ENOENT in test_subprocess. ++ ++- Issue #9323: Make test.regrtest.__file__ absolute, this was not always the ++ case when running profile or trace, for example. ++ ++- Issue #9315: Added tests for the trace module. Patch by Eli Bendersky. ++ ++- Strengthen test_unicode with explicit type checking for assertEqual tests. ++ ++- Issue #8857: Provide a test case for socket.getaddrinfo. ++ ++- Issue #7564: Skip test_ioctl if another process is attached to /dev/tty. ++ ++- Issue #8433: Fix test_curses failure with newer versions of ncurses. ++ ++- Issue #9496: Provide a test suite for the rlcompleter module. Patch by ++ Michele Orrù. ++ ++- Issue #8605: Skip test_gdb if Python is compiled with optimizations. ++ ++- Issue #9568: Fix test_urllib2_localnet on OS X 10.3. ++ ++Documentation ++------------- ++ ++- Issue #9817: Add expat COPYING file; add expat, libffi and expat licenses ++ to Doc/license.rst. ++ ++- Issue #9524: Document that two CTRL* signals are meant for use only ++ with os.kill. ++ ++- Issue #9255: Document that the 'test' package is for internal Python use ++ only. ++ ++- Issue #7829: Document in dis that bytecode is an implementation detail. ++ ++ + What's New in Python 2.7? + ========================= + +@@ -17,6 +485,9 @@ + Library + ------- + ++- Issue #1868: Eliminate subtle timing issues in thread-local objects by ++ getting rid of the cached copy of thread-local attribute dictionary. ++ + - Issue #9125: Add recognition of 'except ... as ...' syntax to parser module. + + Extension Modules +@@ -792,6 +1263,9 @@ + Library + ------- + ++- Issue #1555570: email no longer inserts extra blank lines when a \r\n ++ combo crosses an 8192 byte boundary. ++ + - Issue #6906: Tk should not set Unicode environment variables on Windows. + + - Issue #1054943: Fix ``unicodedata.normalize('NFC', text)`` for the Public +@@ -963,6 +1437,9 @@ + Library + ------- + ++- Issue #9137: Fix issue in MutableMapping.update, which incorrectly ++ treated keyword arguments called 'self' or 'other' specially. ++ + - Issue #7835: shelve should no longer produce mysterious warnings during + interpreter shutdown. + +@@ -2143,7 +2620,7 @@ + Makefile besides AR and make Distutils use it. Original patch by David + Cournapeau. + +-- Issue 5955: aifc's close method did not close the file it wrapped, now it ++- Issue #5955: aifc's close method did not close the file it wrapped, now it + does. This also means getfp method now returns the real fp. + + - Issue #4875: On win32, ctypes.util.find_library does no longer return +@@ -2752,10 +3229,10 @@ + + - Issue #6244: Allow detect_tkinter to look for Tcl/Tk 8.6. + +-- Issue 5390: Add uninstall icon independent of whether file extensions are ++- Issue #5390: Add uninstall icon independent of whether file extensions are + installed. + +-- Issue 5809: Specifying both --enable-framework and --enable-shared is an ++- Issue #5809: Specifying both --enable-framework and --enable-shared is an + error. Configure now explicity tells you about this. + + - Issue #3585: Add pkg-config support. It creates a python-2.7.pc file and a +@@ -3182,7 +3659,7 @@ + + - Issue #3772: Fixed regression problem in StreamHandler.emit(). + +-- Issue 600362: Relocated parse_qs() and parse_qsl(), from the cgi module ++- Issue #600362: Relocated parse_qs() and parse_qsl(), from the cgi module + to the urlparse one. Added a PendingDeprecationWarning in the old + module, it will be deprecated in the future. + +@@ -3194,7 +3671,7 @@ + - Issue #3719: platform.architecture() fails if there are spaces in the + path to the Python binary. + +-- Issue 3602: Moved test.test_support.catch_warning() to ++- Issue #3602: Moved test.test_support.catch_warning() to + warnings.catch_warnings() along with some API cleanup. Expanding the tests + for catch_warnings() also led to an improvement in the raising of a + DeprecationWarning related to warnings.warn_explicit(). +@@ -3352,7 +3829,7 @@ + - Issue #2222: Fixed reference leak when occurred os.rename() + fails unicode conversion on 2nd parameter. (windows only) + +-- Issue 2464. urllib2 now supports a malformation in the URL received ++- Issue #2464: urllib2 now supports a malformation in the URL received + in a redirect. + + - Silence the DeprecationWarning raised when importing mimetools in +@@ -3412,9 +3889,9 @@ + - Issue #3449: Update decimal module to use most recent specification + (v. 1.68) and tests (v. 2.58) from IBM. + +-- Issue 3437: Bug fix in robotparser parsing of Allow: lines. ++- Issue #3437: Bug fix in robotparser parsing of Allow: lines. + +-- Issue 1592: Improve error reporting when operations are attempted ++- Issue #1592: Improve error reporting when operations are attempted + on a closed shelf. + + - Deprecate the "ast" parser function aliases. +@@ -4367,7 +4844,7 @@ + + - Issue #2055: Convert test_fcntl to unittest. + +-- Issue 1960: Convert test_gdbm to unittest. ++- Issue #1960: Convert test_gdbm to unittest. + + - GHOP 294: Convert test_contains, test_crypt, and test_select to + unittest. +@@ -4412,7 +4889,7 @@ + - Patch #1759: Backport of PEP 3129 class decorators. + + - Issue #1881: An internal parser limit has been increased. Also see +- issue 215555 for a discussion. ++ issue #215555 for a discussion. + + - Added the future_builtins module, which contains hex() and oct(). + These are the PEP 3127 version of these functions, designed to be +@@ -5924,7 +6401,7 @@ + - Tools/scripts/reindent.py now creates the backup file using + shutil.copy to preserve user/group and permissions. Added also a + --nobackup option to not create the backup if the user is concerned +- regarding this. Check issue 1050828 for more details. ++ regarding this. Check issue #1050828 for more details. + + - Tools/scripts/win_add2path.py was added. The simple script modifes + the PATH environment var of the HKCU tree and adds the python bin +--- a/Misc/ACKS ++++ b/Misc/ACKS +@@ -8,7 +8,8 @@ + + --Guido + +-PS: In the standard Python distribution, this file is encoded in UTF-8. ++PS: In the standard Python distribution, this file is encoded in UTF-8 ++and the list is in rough alphabetical order by last names. + + David Abrahams + Jim Ahlstrom +@@ -62,7 +63,7 @@ + Reimer Behrends + Ben Bell + Thomas Bellman +-Alexander Belopolsky ++Alexander “Саша†Belopolsky + Andrew Bennetts + Andy Bensky + Michel Van den Bergh +@@ -143,6 +144,7 @@ + Vadim Chugunov + David Cinege + Mike Clarkson ++Andrew Clegg + Brad Clements + Steve Clift + Nick Coghlan +@@ -188,6 +190,7 @@ + Erik Demaine + Roger Dev + Raghuram Devarakonda ++Catherine Devlin + Scott Dial + Toby Dickenson + Mark Dickinson +@@ -244,6 +247,7 @@ + Sebastian Fernandez + Vincent Fiack + Tomer Filiba ++Jeffrey Finkelstein + Russell Finn + Nils Fischbeck + Frederik Fix +@@ -354,6 +358,7 @@ + Brian Hooper + Randall Hopper + Nadav Horesh ++Jan Hosang + Ken Howard + Brad Howes + Chih-Hao Huang +@@ -404,13 +409,16 @@ + Lou Kates + Hiroaki Kawai + Sebastien Keim ++Ryan Kelly + Robert Kern + Randall Kern + Magnus Kessler + Lawrence Kesteloot + Vivek Khera ++Akira Kitada + Mads Kiilerich + Taek Joo Kim ++W. Trevor King + Paul Kippes + Steve Kirsch + Sebastian Kirsche +@@ -431,10 +439,12 @@ + Michael Kremer + Fabian Kreutz + Hannu Krosing ++Andrej Krpic + Ivan Krstić + Andrew Kuchling + Vladimir Kushnir + Cameron Laird ++Åukasz Langa + Tino Lange + Andrew Langmead + Detlef Lannert +@@ -464,7 +474,7 @@ + Shawn Ligocki + Martin Ligr + Christopher Lindblad +-Bjorn Lindqvist ++Björn Lindqvist + Per Lindqvist + Eric Lindvall + Gregor Lingl +@@ -521,6 +531,7 @@ + Aristotelis Mikropoulos + Damien Miller + Chad Miller ++Jason V. Miller + Jay T. Miller + Roman Milner + Andrii V. Mishkovskyi +@@ -571,6 +582,7 @@ + Piet van Oostrum + Jason Orendorff + Douglas Orr ++Michele Orrù + Denis S. Otkidach + Michael Otteneder + R. M. Oudkerk +@@ -672,6 +684,7 @@ + Sam Rushing + Mark Russell + Nick Russo ++Sébastien Sablé + Hajime Saitou + George Sakkis + Rich Salz +@@ -705,6 +718,7 @@ + Ha Shao + Richard Shapiro + Bruce Sherwood ++Alexander Shigin + Pete Shinners + Michael Shiplett + John W. Shipman +@@ -742,6 +756,7 @@ + Casper Stoel + Michael Stone + Ken Stox ++Patrick Strawderman + Dan Stromberg + Daniel Stutzbach + Nathan Sullivan +@@ -778,6 +793,7 @@ + Jason Trowbridge + Anthony Tuininga + Stephen Turner ++Theodore Turocy + Bill Tutt + Doobee R. Tzeck + Eren Türkay +@@ -826,6 +842,7 @@ + Gerry Wiener + Frank Wierzbicki + Bryce "Zooko" Wilcox-O'Hearn ++Jason Williams + John Williams + Sue Williams + Gerald S. Williams +@@ -850,6 +867,7 @@ + Heiko Wundram + Doug Wyatt + Florent Xicluna ++Hirokazu Yamamoto + Ka-Ping Yee + Bob Yodlowski + Danny Yoo +@@ -864,4 +882,3 @@ + Uwe Zessin + Tarek Ziadé + Peter Ã…strand +-Andrej Krpic +--- a/Misc/pymemcompat.h ++++ b/Misc/pymemcompat.h +@@ -72,7 +72,7 @@ + + It is possible to support both the 2.0 and 2.2 GC APIs, but it's + not pretty and this comment block is too narrow to contain a +- desciption of what's required... */ ++ description of what's required... */ + + #if PY_VERSION_HEX < 0x020200B1 + #define PyObject_GC_New PyObject_New +--- a/Misc/README ++++ b/Misc/README +@@ -7,35 +7,37 @@ + Files found here + ---------------- + +-ACKS Acknowledgements +-AIX-NOTES Notes for building Python on AIX +-BeOS-NOTES Notes for building on BeOS +-BeOS-setup.py setup.py replacement for BeOS, see BeOS-NOTES +-build.sh Script to build and test latest Python from the repository +-cheatsheet Quick summary of Python by Ken Manheimer +-developers.txt A history of who got developer permissions, and why +-gdbinit Handy stuff to put in your .gdbinit file, if you use gdb +-HISTORY News from previous releases -- oldest last +-indent.pro GNU indent profile approximating my C style +-NEWS News for this release (for some meaning of "this") +-NEWS.help How to edit NEWS +-Porting Mini-FAQ on porting to new platforms +-PURIFY.README Information for Purify users +-pymemcompat.h Memory interface compatibility file. +-python.man UNIX man page for the python interpreter +-python-mode.el Emacs mode for editing Python programs +-python.pc.in Package configuration info template for pkg-config +-python-wing.wpr Wing IDE project file +-README The file you're reading now +-README.coverity Information about running Coverity's Prevent on Python +-README.klocwork Information about running Klocwork's K7 on Python +-README.OpenBSD Help for building problems on OpenBSD +-README.valgrind Information for Valgrind users, see valgrind-python.supp +-RFD Request For Discussion about a Python newsgroup +-RPM (Old) tools to build RPMs +-setuid-prog.c C helper program for set-uid Python scripts +-SpecialBuilds.txt Describes extra symbols you can set for debug builds +-TextMate A TextMate bundle for Python development +-valgrind-python.supp Valgrind suppression file, see README.valgrind +-vgrindefs Python configuration for vgrind (a generic pretty printer) +-Vim Python development utilities for the Vim editor +\ No newline at end of file ++ACKS Acknowledgements ++AIX-NOTES Notes for building Python on AIX ++BeOS-NOTES Notes for building on BeOS ++BeOS-setup.py setup.py replacement for BeOS, see BeOS-NOTES ++build.sh Script to build and test latest Python from the repository ++cheatsheet Quick summary of Python by Ken Manheimer ++developers.txt A history of who got developer permissions, and why ++gdbinit Handy stuff to put in your .gdbinit file, if you use gdb ++HISTORY News from previous releases -- oldest last ++indent.pro GNU indent profile approximating my C style ++maintainers.rst A list of maintainers for library modules ++NEWS News for this release (for some meaning of "this") ++NEWS.help How to edit NEWS ++Porting Mini-FAQ on porting to new platforms ++PURIFY.README Information for Purify users ++pymemcompat.h Memory interface compatibility file. ++python-config.in Python script template for python-config ++python.man UNIX man page for the python interpreter ++python-mode.el Emacs mode for editing Python programs ++python.pc.in Package configuration info template for pkg-config ++python-wing.wpr Wing IDE project file ++README The file you're reading now ++README.coverity Information about running Coverity's Prevent on Python ++README.klocwork Information about running Klocwork's K7 on Python ++README.OpenBSD Help for building problems on OpenBSD ++README.valgrind Information for Valgrind users, see valgrind-python.supp ++RFD Request For Discussion about a Python newsgroup ++RPM (Old) tools to build RPMs ++setuid-prog.c C helper program for set-uid Python scripts ++SpecialBuilds.txt Describes extra symbols you can set for debug builds ++TextMate A TextMate bundle for Python development ++valgrind-python.supp Valgrind suppression file, see README.valgrind ++vgrindefs Python configuration for vgrind (a generic pretty printer) ++Vim Python development utilities for the Vim editor +--- a/Misc/RPM/python-2.7.spec ++++ b/Misc/RPM/python-2.7.spec +@@ -39,8 +39,8 @@ + + %define name python + #--start constants-- +-%define version 2.7 +-%define libver 2.7 ++%define version 2.7.1a0 ++%define libvers 2.7 + #--end constants-- + %define release 1pydotorg + %define __prefix /usr +@@ -61,7 +61,7 @@ + Name: %{name}%{binsuffix} + Version: %{version} + Release: %{release} +-License: Modified CNRI Open Source License ++License: PSF + Group: Development/Languages + Source: Python-%{version}.tar.bz2 + %if %{include_docs} +--- a/README ++++ b/README +@@ -1,5 +1,5 @@ +-This is Python version 2.7 +-=========================== ++This is Python version 2.7.1 release candidate 1 ++================================================ + + Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 + Python Software Foundation. +--- a/Mac/Makefile.in ++++ b/Mac/Makefile.in +@@ -70,9 +70,10 @@ + if [ ! -d "$(DESTDIR)$(FRAMEWORKUNIXTOOLSPREFIX)/bin" ]; then \ + $(INSTALL) -d -m $(DIRMODE) "$(DESTDIR)$(FRAMEWORKUNIXTOOLSPREFIX)/bin" ;\ + fi +- for fn in python pythonw idle pydoc python-config smtpd.py \ ++ for fn in python pythonw idle pydoc python-config smtpd.py 2to3 \ + python$(VERSION) pythonw$(VERSION) idle$(VERSION) \ +- pydoc$(VERSION) python$(VERSION)-config smtpd$(VERSION).py ;\ ++ pydoc$(VERSION) python$(VERSION)-config smtpd$(VERSION).py \ ++ 2to3-$(VERSION) ;\ + do \ + ln -fs "$(prefix)/bin/$${fn}" "$(DESTDIR)$(FRAMEWORKUNIXTOOLSPREFIX)/bin/$${fn}" ;\ + done +@@ -90,6 +91,7 @@ + do \ + ln -fs "$(prefix)/bin/$${fn}" "$(DESTDIR)$(FRAMEWORKUNIXTOOLSPREFIX)/bin/$${fn}" ;\ + done ++ ln -fs "$(prefix)/bin/2to3-$(VERSION)" "$(DESTDIR)$(FRAMEWORKUNIXTOOLSPREFIX)/bin/2to3-$(VERSION)" ;\ + + # By default most tools are installed without a version in their basename, to + # make it easier to install (and use) several python versions side-by-side move +@@ -112,6 +114,10 @@ + mv "$(DESTDIR)$(prefix)/bin/smtpd.py" "$(DESTDIR)$(prefix)/bin/smtpd$(VERSION).py" ;\ + ln -sf "smtpd$(VERSION).py" "$(DESTDIR)$(prefix)/bin/smtpd.py" ;\ + fi ++ if [ ! -h "$(DESTDIR)$(prefix)/bin/2to3" ]; then \ ++ mv "$(DESTDIR)$(prefix)/bin/2to3" "$(DESTDIR)$(prefix)/bin/2to3-$(VERSION)" ;\ ++ ln -sf "2to3-$(VERSION)" "$(DESTDIR)$(prefix)/bin/2to3" ;\ ++ fi + + + pythonw: $(srcdir)/Tools/pythonw.c Makefile +--- a/Mac/BuildScript/build-installer.py ++++ b/Mac/BuildScript/build-installer.py +@@ -275,7 +275,7 @@ + is not necessary to use Python. + """, + required=False, +- selected='unselected', ++ selected='selected', + ), + dict( + name="PythonDocumentation", +--- a/Mac/BuildScript/scripts/postflight.patch-profile ++++ b/Mac/BuildScript/scripts/postflight.patch-profile +@@ -20,7 +20,7 @@ + # Make sure the directory ${PYTHON_ROOT}/bin is on the users PATH. + BSH="`basename "${theShell}"`" + case "${BSH}" in +-bash|ksh|sh|*csh) ++bash|ksh|sh|*csh|zsh) + if [ `id -ur` = 0 ]; then + P=`su - ${USER} -c 'echo A-X-4-X@@$PATH@@X-4-X-A' | grep 'A-X-4-X@@.*@@X-4-X-A' | sed -e 's/^A-X-4-X@@//g' -e 's/@@X-4-X-A$//g'` + else +@@ -76,6 +76,9 @@ + PR="${HOME}/.bash_profile" + fi + ;; ++zsh) ++ PR="${HOME}/.zprofile" ++ ;; + *sh) + PR="${HOME}/.profile" + ;; +--- a/Mac/Modules/_scproxy.c ++++ b/Mac/Modules/_scproxy.c +@@ -73,7 +73,7 @@ + v = PyBool_FromLong(cfnum_to_int32(aNum)); + } + } else { +- v = PyBool_FromLong(1); ++ v = PyBool_FromLong(0); + } + + if (v == NULL) goto error; +--- a/Tools/scripts/2to3 ++++ b/Tools/scripts/2to3 +@@ -1,6 +1,5 @@ + #!/usr/bin/env python +-from lib2to3.main import main + import sys +-import os ++from lib2to3.main import main + + sys.exit(main("lib2to3.fixes")) +--- a/Tools/gdb/libpython.py ++++ b/Tools/gdb/libpython.py +@@ -41,6 +41,7 @@ + ''' + from __future__ import with_statement + import gdb ++import sys + + # Look up the gdb.Type for some standard types: + _type_char_ptr = gdb.lookup_type('char').pointer() # char* +@@ -1010,6 +1011,18 @@ + _typename = 'PyTypeObject' + + ++if sys.maxunicode >= 0x10000: ++ _unichr = unichr ++else: ++ # Needed for proper surrogate support if sizeof(Py_UNICODE) is 2 in gdb ++ def _unichr(x): ++ if x < 0x10000: ++ return unichr(x) ++ x -= 0x10000 ++ ch1 = 0xD800 | (x >> 10) ++ ch2 = 0xDC00 | (x & 0x3FF) ++ return unichr(ch1) + unichr(ch2) ++ + class PyUnicodeObjectPtr(PyObjectPtr): + _typename = 'PyUnicodeObject' + +@@ -1026,38 +1039,37 @@ + + # Gather a list of ints from the Py_UNICODE array; these are either + # UCS-2 or UCS-4 code points: +- Py_UNICODEs = [int(field_str[i]) for i in safe_range(field_length)] ++ if self.char_width() > 2: ++ Py_UNICODEs = [int(field_str[i]) for i in safe_range(field_length)] ++ else: ++ # A more elaborate routine if sizeof(Py_UNICODE) is 2 in the ++ # inferior process: we must join surrogate pairs. ++ Py_UNICODEs = [] ++ i = 0 ++ limit = safety_limit(field_length) ++ while i < limit: ++ ucs = int(field_str[i]) ++ i += 1 ++ if ucs < 0xD800 or ucs >= 0xDC00 or i == field_length: ++ Py_UNICODEs.append(ucs) ++ continue ++ # This could be a surrogate pair. ++ ucs2 = int(field_str[i]) ++ if ucs2 < 0xDC00 or ucs2 > 0xDFFF: ++ continue ++ code = (ucs & 0x03FF) << 10 ++ code |= ucs2 & 0x03FF ++ code += 0x00010000 ++ Py_UNICODEs.append(code) ++ i += 1 + + # Convert the int code points to unicode characters, and generate a +- # local unicode instance: +- result = u''.join([unichr(ucs) for ucs in Py_UNICODEs]) ++ # local unicode instance. ++ # This splits surrogate pairs if sizeof(Py_UNICODE) is 2 here (in gdb). ++ result = u''.join([_unichr(ucs) for ucs in Py_UNICODEs]) + return result + +- def write_repr(self, out, visited): +- proxy = self.proxyval(visited) +- if self.char_width() == 2: +- # sizeof(Py_UNICODE)==2: join surrogates +- proxy2 = [] +- i = 0 +- while i < len(proxy): +- ch = proxy[i] +- i += 1 +- if (i < len(proxy) +- and 0xD800 <= ord(ch) < 0xDC00 \ +- and 0xDC00 <= ord(proxy[i]) <= 0xDFFF): +- # Get code point from surrogate pair +- ch2 = proxy[i] +- code = (ord(ch) & 0x03FF) << 10 +- code |= ord(ch2) & 0x03FF +- code += 0x00010000 +- i += 1 +- proxy2.append(unichr(code)) +- else: +- proxy2.append(ch) +- proxy = u''.join(proxy2) +- out.write(repr(proxy)) + +- + def int_from_int(gdbval): + return int(str(gdbval)) + +--- a/PC/VS8.0/_sqlite3.vcproj ++++ b/PC/VS8.0/_sqlite3.vcproj +@@ -42,7 +42,7 @@ + /> + + + + + + + + + + + + + + + + + ++ ++ +@@ -65,16 +73,8 @@ + Value="" + /> + +- +- + + + + + +- +- + +@@ -1551,6 +1547,10 @@ + > + + ++ ++ + +--- a/PC/VS8.0/sqlite3.vsprops ++++ b/PC/VS8.0/sqlite3.vsprops +@@ -0,0 +1,14 @@ ++ ++ ++ ++ +--- a/PC/VS8.0/pyd.vsprops ++++ b/PC/VS8.0/pyd.vsprops +@@ -15,8 +15,13 @@ + OutputFile="$(OutDir)\$(ProjectName).pyd" + ProgramDatabaseFile="$(OutDir)\$(ProjectName).pdb" + ImportLibrary="$(OutDir)\$(TargetName).lib" ++ GenerateManifest="false" + /> + ++ +--- a/PC/VS8.0/bdist_wininst.vcproj ++++ b/PC/VS8.0/bdist_wininst.vcproj +@@ -55,7 +55,7 @@ + AdditionalIncludeDirectories="..\..\PC\bdist_wininst;..\..\Include;..\..\Modules\zlib" + PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE" + StringPooling="true" +- RuntimeLibrary="2" ++ RuntimeLibrary="0" + EnableFunctionLevelLinking="true" + WarningLevel="3" + SuppressStartupBanner="true" +@@ -145,7 +145,7 @@ + AdditionalIncludeDirectories="..\..\PC\bdist_wininst;..\..\Include;..\..\Modules\zlib" + PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE" + StringPooling="true" +- RuntimeLibrary="2" ++ RuntimeLibrary="0" + EnableFunctionLevelLinking="true" + WarningLevel="3" + SuppressStartupBanner="true" +--- a/PC/VS8.0/sqlite3.vcproj ++++ b/PC/VS8.0/sqlite3.vcproj +@@ -22,7 +22,7 @@ + + + + + + + +@@ -166,8 +164,7 @@ + /> + + +@@ -229,8 +226,7 @@ + /> + + +@@ -291,8 +287,7 @@ + /> + + +@@ -354,8 +349,7 @@ + /> + + +@@ -415,8 +409,7 @@ + /> + + +@@ -478,8 +471,7 @@ + /> + + + + + + + +@@ -535,7 +527,7 @@ + Name="Source Files" + > + + + +--- a/PC/VS8.0/_multiprocessing.vcproj ++++ b/PC/VS8.0/_multiprocessing.vcproj +@@ -3,7 +3,7 @@ + ProjectType="Visual C++" + Version="8.00" + Name="_multiprocessing" +- ProjectGUID="{9e48b300-37d1-11dd-8c41-005056c00008}" ++ ProjectGUID="{9E48B300-37D1-11DD-8C41-005056C00008}" + RootNamespace="_multiprocessing" + Keyword="Win32Proj" + TargetFrameworkVersion="196613" +--- a/PC/VS8.0/bz2.vcproj ++++ b/PC/VS8.0/bz2.vcproj +@@ -43,6 +43,7 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ + + + +--- a/PC/VS8.0/pyd_d.vsprops ++++ b/PC/VS8.0/pyd_d.vsprops +@@ -19,8 +19,13 @@ + LinkIncremental="1" + ProgramDatabaseFile="$(OutDir)\$(ProjectName)_d.pdb" + ImportLibrary="$(OutDir)\$(TargetName).lib" ++ GenerateManifest="false" + /> + ++ +--- a/PC/VC6/tcl852.patch ++++ b/PC/VC6/tcl852.patch +@@ -9,14 +9,3 @@ + typedef struct _stati64 Tcl_StatBuf; + # else + typedef struct _stat64 Tcl_StatBuf; +---- tcl8.5.2\generic\tcl.h Fri Jun 13 03:35:39 2008 +-+++ tcl8.5.2\generic\tcl.h Sun Jan 4 16:52:30 2009 +-@@ -367,7 +367,7 @@ +- typedef struct stati64 Tcl_StatBuf; +- # define TCL_LL_MODIFIER "L" +- # else /* __BORLANDC__ */ +--# if _MSC_VER < 1400 && !defined(_M_IX86) +-+# if _MSC_VER < 1400 /*&& !defined(_M_IX86)*/ +- typedef struct _stati64 Tcl_StatBuf; +- # else +- typedef struct _stat64 Tcl_StatBuf; +--- a/PC/VC6/readme.txt ++++ b/PC/VC6/readme.txt +@@ -1,7 +1,8 @@ + Building Python using VC++ 6.0 or 5.0 + ------------------------------------- + This directory is used to build Python for Win32 platforms, e.g. Windows +-2000 and XP. It requires Microsoft Visual C++ 6.x or 5.x. ++2000 and XP. It requires Microsoft Visual C++ 6.x or 5.x and Platform ++SDK February 2003 Edition (Core SDK). + (For other Windows platforms and compilers, see ../readme.txt.) + + All you need to do is open the workspace "pcbuild.dsw" in MSVC++, select +@@ -39,7 +40,6 @@ + pythonw.exe, a variant of python.exe that doesn't pop up a DOS box + _msi + _msi.c. You need to install Windows Installer SDK to build this module. +- http://www.microsoft.com/msdownload/platformsdk/sdkupdate/psdk-full.htm + _socket + socketmodule.c + _testcapi +--- a/PC/msvcrtmodule.c ++++ b/PC/msvcrtmodule.c +@@ -141,6 +141,9 @@ + if (!PyArg_ParseTuple(args,"i:get_osfhandle", &fd)) + return NULL; + ++ if (!_PyVerify_fd(fd)) ++ return PyErr_SetFromErrno(PyExc_IOError); ++ + handle = _get_osfhandle(fd); + if (handle == -1) + return PyErr_SetFromErrno(PyExc_IOError); +--- a/Doc/distutils/builtdist.rst ++++ b/Doc/distutils/builtdist.rst +@@ -146,8 +146,8 @@ + Creating dumb built distributions + ================================= + +-**\*\*** Need to document absolute vs. prefix-relative packages here, but first +-I have to implement it! **\*\*** ++.. XXX Need to document absolute vs. prefix-relative packages here, but first ++ I have to implement it! + + + .. _creating-rpms: +@@ -176,7 +176,7 @@ + explicitly specify multiple :command:`bdist_\*` commands and their options:: + + python setup.py bdist_rpm --packager="John Doe " \ +- bdist_wininst --target_version="2.0" ++ bdist_wininst --target-version="2.0" + + Creating RPM packages is driven by a :file:`.spec` file, much as using the + Distutils is driven by the setup script. To make your life easier, the +@@ -358,7 +358,7 @@ + + To cross-compile, you must download the Python source code and cross-compile + Python itself for the platform you are targetting - it is not possible from a +-binary installtion of Python (as the .lib etc file for other platforms are ++binary installation of Python (as the .lib etc file for other platforms are + not included.) In practice, this means the user of a 32 bit operating + system will need to use Visual Studio 2008 to open the + :file:`PCBuild/PCbuild.sln` solution in the Python source tree and build the +--- a/Doc/distutils/sourcedist.rst ++++ b/Doc/distutils/sourcedist.rst +@@ -76,10 +76,10 @@ + :option:`packages` options + + * all C source files mentioned in the :option:`ext_modules` or +- :option:`libraries` options ( ++ :option:`libraries` options + +- **\*\*** getting C library sources currently broken---no +- :meth:`get_source_files` method in :file:`build_clib.py`! **\*\***) ++ .. XXX Getting C library sources is currently broken -- no ++ :meth:`get_source_files` method in :file:`build_clib.py`! + + * scripts identified by the :option:`scripts` option + See :ref:`distutils-installing-scripts`. +@@ -111,6 +111,10 @@ + :file:`MANIFEST`, you must specify everything: the default set of files + described above does not apply in this case. + ++.. versionadded:: 2.7 ++ :file:`MANIFEST` files start with a comment indicating they are generated. ++ Files without this comment are not overwritten or removed. ++ + See :ref:`manifest_template` section for a syntax reference. + + .. _manifest-options: +@@ -142,7 +146,7 @@ + + python setup.py sdist --manifest-only + +-:option:`-o` is a sortcut for :option:`--manifest-only`. ++:option:`-o` is a shortcut for :option:`--manifest-only`. + + .. _manifest_template: + +@@ -268,3 +272,7 @@ + character" is platform-specific: on Unix it is anything except slash; on Windows + anything except backslash or colon. + ++.. versionchanged:: 2.7 ++ An existing generated :file:`MANIFEST` will be regenerated without ++ :command:`sdist` comparing its modification time to the one of ++ :file:`MANIFEST.in` or :file:`setup.py`. +--- a/Doc/distutils/extending.rst ++++ b/Doc/distutils/extending.rst +@@ -15,8 +15,8 @@ + should be copied into packages in addition to :file:`.py` files as a + convenience. + +-Most distutils command implementations are subclasses of the :class:`Command` +-class from :mod:`distutils.cmd`. New commands may directly inherit from ++Most distutils command implementations are subclasses of the ++:class:`distutils.cmd.Command` class. New commands may directly inherit from + :class:`Command`, while replacements often derive from :class:`Command` + indirectly, directly subclassing the command they are replacing. Commands are + required to derive from :class:`Command`. +--- a/Doc/distutils/setupscript.rst ++++ b/Doc/distutils/setupscript.rst +@@ -207,7 +207,7 @@ + SWIG on the interface file and compile the resulting C/C++ file into your + extension. + +-**\*\*** SWIG support is rough around the edges and largely untested! **\*\*** ++.. XXX SWIG support is rough around the edges and largely untested! + + This warning notwithstanding, options to SWIG can be currently passed like + this:: +@@ -326,7 +326,7 @@ + (Again, this sort of non-portable construct should be avoided if you intend to + distribute your code.) + +-**\*\*** Should mention clib libraries here or somewhere else! **\*\*** ++.. XXX Should mention clib libraries here or somewhere else! + + + Other options +--- a/Doc/distutils/apiref.rst ++++ b/Doc/distutils/apiref.rst +@@ -21,7 +21,7 @@ + .. function:: setup(arguments) + + The basic do-everything function that does most everything you could ever ask +- for from a Distutils method. See XXXXX ++ for from a Distutils method. + + The setup function takes a large number of arguments. These are laid out in the + following table. +@@ -995,7 +995,7 @@ + errors are ignored (apart from being reported to ``sys.stdout`` if *verbose* is + true). + +-**\*\*** Some of this could be replaced with the shutil module? **\*\*** ++.. XXX Some of this could be replaced with the shutil module? + + + :mod:`distutils.file_util` --- Single file operations +@@ -1311,8 +1311,7 @@ + the "negative alias" of :option:`--verbose`, then :option:`--quiet` on the + command line sets *verbose* to false. + +-**\*\*** Should be replaced with :mod:`optik` (which is also now known as +-:mod:`optparse` in Python 2.3 and later). **\*\*** ++.. XXX Should be replaced with :mod:`optparse`. + + + .. function:: fancy_getopt(options, negative_opt, object, args) +--- a/Doc/using/cmdline.rst ++++ b/Doc/using/cmdline.rst +@@ -61,7 +61,7 @@ + + .. cmdoption:: -c + +- Execute the Python code in *command*. *command* can be one ore more ++ Execute the Python code in *command*. *command* can be one or more + statements separated by newlines, with significant leading whitespace as in + normal module code. + +--- a/Doc/using/index.rst ++++ b/Doc/using/index.rst +@@ -1,8 +1,8 @@ + .. _using-index: + +-################ +- Using Python +-################ ++########################## ++ Python Setup and Usage ++########################## + + + This part of the documentation is devoted to general information on the setup +--- a/Doc/extending/windows.rst ++++ b/Doc/extending/windows.rst +@@ -175,7 +175,9 @@ + + PyObject_HEAD_INIT(&PyType_Type) + +-Change it to:: ++Static type object initializers in extension modules may cause ++compiles to fail with an error message like "initializer not a ++constant". This shows up when building DLL under MSVC. Change it to:: + + PyObject_HEAD_INIT(NULL) + +@@ -183,8 +185,6 @@ + + MyObject_Type.ob_type = &PyType_Type; + +-Refer to section 3 of the `Python FAQ `_ for +-details on why you must do this. + + + .. _dynamic-linking: +--- a/Doc/extending/extending.rst ++++ b/Doc/extending/extending.rst +@@ -228,10 +228,29 @@ + become a dangling pointer. Should it become a dangling pointer, C code which + raises the exception could cause a core dump or other unintended side effects. + +-We discuss the use of PyMODINIT_FUNC as a function return type later in this ++We discuss the use of ``PyMODINIT_FUNC`` as a function return type later in this + sample. + ++The :exc:`spam.error` exception can be raised in your extension module using a ++call to :cfunc:`PyErr_SetString` as shown below:: + ++ static PyObject * ++ spam_system(PyObject *self, PyObject *args) ++ { ++ const char *command; ++ int sts; ++ ++ if (!PyArg_ParseTuple(args, "s", &command)) ++ return NULL; ++ sts = system(command); ++ if (sts < 0) { ++ PyErr_SetString(SpamError, "System command failed"); ++ return NULL; ++ } ++ return PyLong_FromLong(sts); ++ } ++ ++ + .. _backtoexample: + + Back to the Example +--- a/Doc/license.rst ++++ b/Doc/license.rst +@@ -748,3 +748,228 @@ + ***************************************************************/ + + ++OpenSSL ++------- ++ ++The modules :mod:`hashlib`, :mod:`posix`, :mod:`ssl`, :mod:`crypt` use ++the OpenSSL library for added performance if made available by the ++operating system. Additionally, the Windows installers for Python ++include a copy of the OpenSSL libraries, so we include a copy of the ++OpenSSL license here:: ++ ++ ++ LICENSE ISSUES ++ ============== ++ ++ The OpenSSL toolkit stays under a dual license, i.e. both the conditions of ++ the OpenSSL License and the original SSLeay license apply to the toolkit. ++ See below for the actual license texts. Actually both licenses are BSD-style ++ Open Source licenses. In case of any license issues related to OpenSSL ++ please contact openssl-core@openssl.org. ++ ++ OpenSSL License ++ --------------- ++ ++ /* ==================================================================== ++ * Copyright (c) 1998-2008 The OpenSSL Project. All rights reserved. ++ * ++ * Redistribution and use in source and binary forms, with or without ++ * modification, are permitted provided that the following conditions ++ * are met: ++ * ++ * 1. Redistributions of source code must retain the above copyright ++ * notice, this list of conditions and the following disclaimer. ++ * ++ * 2. Redistributions in binary form must reproduce the above copyright ++ * notice, this list of conditions and the following disclaimer in ++ * the documentation and/or other materials provided with the ++ * distribution. ++ * ++ * 3. All advertising materials mentioning features or use of this ++ * software must display the following acknowledgment: ++ * "This product includes software developed by the OpenSSL Project ++ * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" ++ * ++ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to ++ * endorse or promote products derived from this software without ++ * prior written permission. For written permission, please contact ++ * openssl-core@openssl.org. ++ * ++ * 5. Products derived from this software may not be called "OpenSSL" ++ * nor may "OpenSSL" appear in their names without prior written ++ * permission of the OpenSSL Project. ++ * ++ * 6. Redistributions of any form whatsoever must retain the following ++ * acknowledgment: ++ * "This product includes software developed by the OpenSSL Project ++ * for use in the OpenSSL Toolkit (http://www.openssl.org/)" ++ * ++ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY ++ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ++ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR ++ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR ++ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ++ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT ++ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; ++ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ++ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, ++ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ++ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED ++ * OF THE POSSIBILITY OF SUCH DAMAGE. ++ * ==================================================================== ++ * ++ * This product includes cryptographic software written by Eric Young ++ * (eay@cryptsoft.com). This product includes software written by Tim ++ * Hudson (tjh@cryptsoft.com). ++ * ++ */ ++ ++ Original SSLeay License ++ ----------------------- ++ ++ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) ++ * All rights reserved. ++ * ++ * This package is an SSL implementation written ++ * by Eric Young (eay@cryptsoft.com). ++ * The implementation was written so as to conform with Netscapes SSL. ++ * ++ * This library is free for commercial and non-commercial use as long as ++ * the following conditions are aheared to. The following conditions ++ * apply to all code found in this distribution, be it the RC4, RSA, ++ * lhash, DES, etc., code; not just the SSL code. The SSL documentation ++ * included with this distribution is covered by the same copyright terms ++ * except that the holder is Tim Hudson (tjh@cryptsoft.com). ++ * ++ * Copyright remains Eric Young's, and as such any Copyright notices in ++ * the code are not to be removed. ++ * If this package is used in a product, Eric Young should be given attribution ++ * as the author of the parts of the library used. ++ * This can be in the form of a textual message at program startup or ++ * in documentation (online or textual) provided with the package. ++ * ++ * Redistribution and use in source and binary forms, with or without ++ * modification, are permitted provided that the following conditions ++ * are met: ++ * 1. Redistributions of source code must retain the copyright ++ * notice, this list of conditions and the following disclaimer. ++ * 2. Redistributions in binary form must reproduce the above copyright ++ * notice, this list of conditions and the following disclaimer in the ++ * documentation and/or other materials provided with the distribution. ++ * 3. All advertising materials mentioning features or use of this software ++ * must display the following acknowledgement: ++ * "This product includes cryptographic software written by ++ * Eric Young (eay@cryptsoft.com)" ++ * The word 'cryptographic' can be left out if the rouines from the library ++ * being used are not cryptographic related :-). ++ * 4. If you include any Windows specific code (or a derivative thereof) from ++ * the apps directory (application code) you must include an acknowledgement: ++ * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" ++ * ++ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND ++ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ++ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ++ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE ++ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ++ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS ++ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ++ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT ++ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY ++ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF ++ * SUCH DAMAGE. ++ * ++ * The licence and distribution terms for any publically available version or ++ * derivative of this code cannot be changed. i.e. this code cannot simply be ++ * copied and put under another distribution licence ++ * [including the GNU Public Licence.] ++ */ ++ ++ ++expat ++----- ++ ++The :mod:`pyexpat` extension is built using an included copy of the expat ++sources unless the build is configured :option:`--with-system-expat`:: ++ ++ Copyright (c) 1998, 1999, 2000 Thai Open Source Software Center Ltd ++ and Clark Cooper ++ ++ Permission is hereby granted, free of charge, to any person obtaining ++ a copy of this software and associated documentation files (the ++ "Software"), to deal in the Software without restriction, including ++ without limitation the rights to use, copy, modify, merge, publish, ++ distribute, sublicense, and/or sell copies of the Software, and to ++ permit persons to whom the Software is furnished to do so, subject to ++ the following conditions: ++ ++ The above copyright notice and this permission notice shall be included ++ in all copies or substantial portions of the Software. ++ ++ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ++ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ++ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. ++ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY ++ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, ++ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE ++ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ++ ++ ++libffi ++------ ++ ++The :mod:`_ctypes` extension is built using an included copy of the libffi ++sources unless the build is configured :option:`--with-system-libffi`:: ++ ++ Copyright (c) 1996-2008 Red Hat, Inc and others. ++ ++ Permission is hereby granted, free of charge, to any person obtaining ++ a copy of this software and associated documentation files (the ++ ``Software''), to deal in the Software without restriction, including ++ without limitation the rights to use, copy, modify, merge, publish, ++ distribute, sublicense, and/or sell copies of the Software, and to ++ permit persons to whom the Software is furnished to do so, subject to ++ the following conditions: ++ ++ The above copyright notice and this permission notice shall be included ++ in all copies or substantial portions of the Software. ++ ++ THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, ++ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ++ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ++ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT ++ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, ++ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, ++ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER ++ DEALINGS IN THE SOFTWARE. ++ ++ ++zlib ++---- ++ ++The :mod:`zlib` extension is built using an included copy of the zlib ++sources unless the zlib version found on the system is too old to be ++used for the build:: ++ ++ Copyright (C) 1995-2010 Jean-loup Gailly and Mark Adler ++ ++ This software is provided 'as-is', without any express or implied ++ warranty. In no event will the authors be held liable for any damages ++ arising from the use of this software. ++ ++ Permission is granted to anyone to use this software for any purpose, ++ including commercial applications, and to alter it and redistribute it ++ freely, subject to the following restrictions: ++ ++ 1. The origin of this software must not be misrepresented; you must not ++ claim that you wrote the original software. If you use this software ++ in a product, an acknowledgment in the product documentation would be ++ appreciated but is not required. ++ ++ 2. Altered source versions must be plainly marked as such, and must not be ++ misrepresented as being the original software. ++ ++ 3. This notice may not be removed or altered from any source distribution. ++ ++ Jean-loup Gailly Mark Adler ++ jloup@gzip.org madler@alumni.caltech.edu ++ +--- a/Doc/c-api/buffer.rst ++++ b/Doc/c-api/buffer.rst +@@ -304,16 +304,47 @@ + MemoryView objects + ================== + +-A memoryview object is an extended buffer object that could replace the buffer +-object (but doesn't have to as that could be kept as a simple 1-d memoryview +-object). It, unlike :ctype:`Py_buffer`, is a Python object (exposed as +-:class:`memoryview` in :mod:`builtins`), so it can be used with Python code. ++.. versionadded:: 2.7 + +-.. cfunction:: PyObject* PyMemoryView_FromObject(PyObject *obj) ++A :class:`memoryview` object exposes the new C level buffer interface as a ++Python object which can then be passed around like any other object. + +- Return a memoryview object from an object that defines the buffer interface. ++.. cfunction:: PyObject *PyMemoryView_FromObject(PyObject *obj) + ++ Create a memoryview object from an object that defines the new buffer ++ interface. + ++ ++.. cfunction:: PyObject *PyMemoryView_FromBuffer(Py_buffer *view) ++ ++ Create a memoryview object wrapping the given buffer-info structure *view*. ++ The memoryview object then owns the buffer, which means you shouldn't ++ try to release it yourself: it will be released on deallocation of the ++ memoryview object. ++ ++ ++.. cfunction:: PyObject *PyMemoryView_GetContiguous(PyObject *obj, int buffertype, char order) ++ ++ Create a memoryview object to a contiguous chunk of memory (in either ++ 'C' or 'F'ortran *order*) from an object that defines the buffer ++ interface. If memory is contiguous, the memoryview object points to the ++ original memory. Otherwise copy is made and the memoryview points to a ++ new bytes object. ++ ++ ++.. cfunction:: int PyMemoryView_Check(PyObject *obj) ++ ++ Return true if the object *obj* is a memoryview object. It is not ++ currently allowed to create subclasses of :class:`memoryview`. ++ ++ ++.. cfunction:: Py_buffer *PyMemoryView_GET_BUFFER(PyObject *obj) ++ ++ Return a pointer to the buffer-info structure wrapped by the given ++ object. The object **must** be a memoryview instance; this macro doesn't ++ check its type, you must do it yourself or you will risk crashes. ++ ++ + Old-style buffer objects + ======================== + +--- a/Doc/c-api/file.rst ++++ b/Doc/c-api/file.rst +@@ -63,7 +63,7 @@ + Return the file object associated with *p* as a :ctype:`FILE\*`. + + If the caller will ever use the returned :ctype:`FILE\*` object while +- the GIL is released it must also call the :cfunc:`PyFile_IncUseCount` and ++ the :term:`GIL` is released it must also call the :cfunc:`PyFile_IncUseCount` and + :cfunc:`PyFile_DecUseCount` functions described below as appropriate. + + +@@ -76,11 +76,20 @@ + finished with the :ctype:`FILE\*`. Otherwise the file object will + never be closed by Python. + +- The GIL must be held while calling this function. ++ The :term:`GIL` must be held while calling this function. + +- The suggested use is to call this after :cfunc:`PyFile_AsFile` just before +- you release the GIL. ++ The suggested use is to call this after :cfunc:`PyFile_AsFile` and before ++ you release the GIL:: + ++ FILE *fp = PyFile_AsFile(p); ++ PyFile_IncUseCount(p); ++ /* ... */ ++ Py_BEGIN_ALLOW_THREADS ++ do_something(fp); ++ Py_END_ALLOW_THREADS ++ /* ... */ ++ PyFile_DecUseCount(p); ++ + .. versionadded:: 2.6 + + +@@ -90,7 +99,8 @@ + indicate that the caller is done with its own use of the :ctype:`FILE\*`. + This may only be called to undo a prior call to :cfunc:`PyFile_IncUseCount`. + +- The GIL must be held while calling this function. ++ The :term:`GIL` must be held while calling this function (see the example ++ above). + + .. versionadded:: 2.6 + +--- a/Doc/c-api/init.rst ++++ b/Doc/c-api/init.rst +@@ -413,6 +413,7 @@ + ============================================ + + .. index:: ++ single: GIL + single: global interpreter lock + single: interpreter lock + single: lock, interpreter +@@ -975,7 +976,7 @@ + .. cvar:: int PyTrace_C_EXCEPTION + + The value for the *what* parameter to :ctype:`Py_tracefunc` functions when a C +- function has thrown an exception. ++ function has raised an exception. + + + .. cvar:: int PyTrace_C_RETURN +--- a/Doc/c-api/dict.rst ++++ b/Doc/c-api/dict.rst +@@ -199,8 +199,8 @@ + .. cfunction:: int PyDict_Merge(PyObject *a, PyObject *b, int override) + + Iterate over mapping object *b* adding key-value pairs to dictionary *a*. +- *b* may be a dictionary, or any object supporting :func:`PyMapping_Keys` +- and :func:`PyObject_GetItem`. If *override* is true, existing pairs in *a* ++ *b* may be a dictionary, or any object supporting :cfunc:`PyMapping_Keys` ++ and :cfunc:`PyObject_GetItem`. If *override* is true, existing pairs in *a* + will be replaced if a matching key is found in *b*, otherwise pairs will + only be added if there is not a matching key in *a*. Return ``0`` on + success or ``-1`` if an exception was raised. +--- a/Doc/c-api/weakref.rst ++++ b/Doc/c-api/weakref.rst +@@ -63,11 +63,18 @@ + .. cfunction:: PyObject* PyWeakref_GetObject(PyObject *ref) + + Return the referenced object from a weak reference, *ref*. If the referent is +- no longer live, returns ``None``. ++ no longer live, returns :const:`Py_None`. + + .. versionadded:: 2.2 + ++ .. warning:: + ++ This function returns a **borrowed reference** to the referenced object. ++ This means that you should always call :cfunc:`Py_INCREF` on the object ++ except if you know that it cannot be destroyed while you are still ++ using it. ++ ++ + .. cfunction:: PyObject* PyWeakref_GET_OBJECT(PyObject *ref) + + Similar to :cfunc:`PyWeakref_GetObject`, but implemented as a macro that does no +--- a/Doc/c-api/unicode.rst ++++ b/Doc/c-api/unicode.rst +@@ -567,6 +567,38 @@ + *NULL* if an exception was raised by the codec. + + ++UTF-7 Codecs ++"""""""""""" ++ ++These are the UTF-7 codec APIs: ++ ++ ++.. cfunction:: PyObject* PyUnicode_DecodeUTF7(const char *s, Py_ssize_t size, const char *errors) ++ ++ Create a Unicode object by decoding *size* bytes of the UTF-7 encoded string ++ *s*. Return *NULL* if an exception was raised by the codec. ++ ++ ++.. cfunction:: PyObject* PyUnicode_DecodeUTF7Stateful(const char *s, Py_ssize_t size, const char *errors, Py_ssize_t *consumed) ++ ++ If *consumed* is *NULL*, behave like :cfunc:`PyUnicode_DecodeUTF7`. If ++ *consumed* is not *NULL*, trailing incomplete UTF-7 base-64 sections will not ++ be treated as an error. Those bytes will not be decoded and the number of ++ bytes that have been decoded will be stored in *consumed*. ++ ++ ++.. cfunction:: PyObject* PyUnicode_EncodeUTF7(const Py_UNICODE *s, Py_ssize_t size, int base64SetO, int base64WhiteSpace, const char *errors) ++ ++ Encode the :ctype:`Py_UNICODE` buffer of the given size using UTF-7 and ++ return a Python bytes object. Return *NULL* if an exception was raised by ++ the codec. ++ ++ If *base64SetO* is nonzero, "Set O" (punctuation that has no otherwise ++ special meaning) will be encoded in base-64. If *base64WhiteSpace* is ++ nonzero, whitespace will be encoded in base-64. Both are set to zero for the ++ Python "utf-7" codec. ++ ++ + Unicode-Escape Codecs + """"""""""""""""""""" + +--- a/Doc/reference/datamodel.rst ++++ b/Doc/reference/datamodel.rst +@@ -739,6 +739,13 @@ + Special read-only attribute: :attr:`__dict__` is the module's namespace as a + dictionary object. + ++ .. impl-detail:: ++ ++ Because of the way CPython clears module dictionaries, the module ++ dictionary will be cleared when the module falls out of scope even if the ++ dictionary still has live references. To avoid this, copy the dictionary ++ or keep the module around while using its dictionary directly. ++ + .. index:: + single: __name__ (module attribute) + single: __doc__ (module attribute) +@@ -908,6 +915,22 @@ + objects, code objects are immutable and contain no references (directly or + indirectly) to mutable objects. + ++ .. index:: ++ single: co_argcount (code object attribute) ++ single: co_code (code object attribute) ++ single: co_consts (code object attribute) ++ single: co_filename (code object attribute) ++ single: co_firstlineno (code object attribute) ++ single: co_flags (code object attribute) ++ single: co_lnotab (code object attribute) ++ single: co_name (code object attribute) ++ single: co_names (code object attribute) ++ single: co_nlocals (code object attribute) ++ single: co_stacksize (code object attribute) ++ single: co_varnames (code object attribute) ++ single: co_cellvars (code object attribute) ++ single: co_freevars (code object attribute) ++ + Special read-only attributes: :attr:`co_name` gives the function name; + :attr:`co_argcount` is the number of positional arguments (including arguments + with default values); :attr:`co_nlocals` is the number of local variables used +@@ -925,22 +948,6 @@ + :attr:`co_stacksize` is the required stack size (including local variables); + :attr:`co_flags` is an integer encoding a number of flags for the interpreter. + +- .. index:: +- single: co_argcount (code object attribute) +- single: co_code (code object attribute) +- single: co_consts (code object attribute) +- single: co_filename (code object attribute) +- single: co_firstlineno (code object attribute) +- single: co_flags (code object attribute) +- single: co_lnotab (code object attribute) +- single: co_name (code object attribute) +- single: co_names (code object attribute) +- single: co_nlocals (code object attribute) +- single: co_stacksize (code object attribute) +- single: co_varnames (code object attribute) +- single: co_cellvars (code object attribute) +- single: co_freevars (code object attribute) +- + .. index:: object: generator + + The following flag bits are defined for :attr:`co_flags`: bit ``0x04`` is set if +--- a/Doc/reference/compound_stmts.rst ++++ b/Doc/reference/compound_stmts.rst +@@ -338,7 +338,8 @@ + + The execution of the :keyword:`with` statement with one "item" proceeds as follows: + +-#. The context expression is evaluated to obtain a context manager. ++#. The context expression (the expression given in the :token:`with_item`) is ++ evaluated to obtain a context manager. + + #. The context manager's :meth:`__exit__` is loaded for later use. + +--- a/Doc/reference/expressions.rst ++++ b/Doc/reference/expressions.rst +@@ -417,7 +417,7 @@ + multiple times, they have more than one entry point and their execution can be + suspended. The only difference is that a generator function cannot control + where should the execution continue after it yields; the control is always +-transfered to the generator's caller. ++transferred to the generator's caller. + + .. index:: object: generator + +@@ -1367,6 +1367,7 @@ + | ``+``, ``-`` | Addition and subtraction | + +-----------------------------------------------+-------------------------------------+ + | ``*``, ``/``, ``//``, ``%`` | Multiplication, division, remainder | ++| | [#]_ | + +-----------------------------------------------+-------------------------------------+ + | ``+x``, ``-x``, ``~x`` | Positive, negative, bitwise NOT | + +-----------------------------------------------+-------------------------------------+ +@@ -1422,5 +1423,7 @@ + the :keyword:`is` operator, like those involving comparisons between instance + methods, or constants. Check their documentation for more info. + ++.. [#] The ``%`` is also used for string formatting; the same precedence applies. ++ + .. [#] The power operator ``**`` binds less tightly than an arithmetic or + bitwise unary operator on its right, that is, ``2**-1`` is ``0.5``. +--- a/Doc/reference/simple_stmts.rst ++++ b/Doc/reference/simple_stmts.rst +@@ -836,7 +836,7 @@ + exists. Two dots means up one package level. Three dots is up two levels, etc. + So if you execute ``from . import mod`` from a module in the ``pkg`` package + then you will end up importing ``pkg.mod``. If you execute ``from ..subpkg2 +-imprt mod`` from within ``pkg.subpkg1`` you will import ``pkg.subpkg2.mod``. ++import mod`` from within ``pkg.subpkg1`` you will import ``pkg.subpkg2.mod``. + The specification for relative imports is contained within :pep:`328`. + + :func:`importlib.import_module` is provided to support applications that +--- a/Doc/reference/lexical_analysis.rst ++++ b/Doc/reference/lexical_analysis.rst +@@ -386,11 +386,12 @@ + information on this convention. + + ``__*__`` +- System-defined names. These names are defined by the interpreter and its +- implementation (including the standard library); applications should not expect +- to define additional names using this convention. The set of names of this +- class defined by Python may be extended in future versions. See section +- :ref:`specialnames`. ++ System-defined names. These names are defined by the interpreter and its ++ implementation (including the standard library). Current system names are ++ discussed in the :ref:`specialnames` section and elsewhere. More will likely ++ be defined in future versions of Python. *Any* use of ``__*__`` names, in ++ any context, that does not follow explicitly documented use, is subject to ++ breakage without warning. + + ``__*`` + Class-private names. Names in this category, when used within the context of a +@@ -425,6 +426,7 @@ + .. productionlist:: + stringliteral: [`stringprefix`](`shortstring` | `longstring`) + stringprefix: "r" | "u" | "ur" | "R" | "U" | "UR" | "Ur" | "uR" ++ : | "b" | "B" | "br" | "Br" | "bR" | "BR" + shortstring: "'" `shortstringitem`* "'" | '"' `shortstringitem`* '"' + longstring: "'''" `longstringitem`* "'''" + : | '"""' `longstringitem`* '"""' +@@ -457,8 +459,10 @@ + ``'u'`` or ``'U'`` makes the string a Unicode string. Unicode strings use the + Unicode character set as defined by the Unicode Consortium and ISO 10646. Some + additional escape sequences, described below, are available in Unicode strings. +-The two prefix characters may be combined; in this case, ``'u'`` must appear +-before ``'r'``. ++A prefix of ``'b'`` or ``'B'`` is ignored in Python 2; it indicates that the ++literal should become a bytes literal in Python 3 (e.g. when code is ++automatically converted with 2to3). A ``'u'`` or ``'b'`` prefix may be followed ++by an ``'r'`` prefix. + + In triple-quoted strings, unescaped newlines and quotes are allowed (and are + retained), except that three unescaped quotes in a row terminate the string. (A +--- a/Doc/whatsnew/2.0.rst ++++ b/Doc/whatsnew/2.0.rst +@@ -656,7 +656,7 @@ + The change which will probably break the most code is tightening up the + arguments accepted by some methods. Some methods would take multiple arguments + and treat them as a tuple, particularly various list methods such as +-:meth:`.append` and :meth:`.insert`. In earlier versions of Python, if ``L`` is ++:meth:`append` and :meth:`insert`. In earlier versions of Python, if ``L`` is + a list, ``L.append( 1,2 )`` appends the tuple ``(1,2)`` to the list. In Python + 2.0 this causes a :exc:`TypeError` exception to be raised, with the message: + 'append requires exactly 1 argument; 2 given'. The fix is to simply add an +--- a/Doc/whatsnew/2.4.rst ++++ b/Doc/whatsnew/2.4.rst +@@ -1066,7 +1066,7 @@ + deprecated APIs and removes support for Python versions earlier than 2.3. The + 3.0 version of the package uses a new incremental parser for MIME messages, + available in the :mod:`email.FeedParser` module. The new parser doesn't require +- reading the entire message into memory, and doesn't throw exceptions if a ++ reading the entire message into memory, and doesn't raise exceptions if a + message is malformed; instead it records any problems in the :attr:`defect` + attribute of the message. (Developed by Anthony Baxter, Barry Warsaw, Thomas + Wouters, and others.) +--- a/Doc/whatsnew/2.5.rst ++++ b/Doc/whatsnew/2.5.rst +@@ -1765,7 +1765,7 @@ + http://effbot.org/zone/element-index.htm. + + ElementTree represents an XML document as a tree of element nodes. The text +-content of the document is stored as the :attr:`.text` and :attr:`.tail` ++content of the document is stored as the :attr:`text` and :attr:`tail` + attributes of (This is one of the major differences between ElementTree and + the Document Object Model; in the DOM there are many different types of node, + including :class:`TextNode`.) +--- a/Doc/whatsnew/2.7.rst ++++ b/Doc/whatsnew/2.7.rst +@@ -52,7 +52,7 @@ + when researching a change. + + This article explains the new features in Python 2.7. Python 2.7 was released +-on July 7, 2010. ++on July 3, 2010. + + Numeric handling has been improved in many ways, for both + floating-point numbers and for the :class:`~decimal.Decimal` class. +@@ -141,10 +141,12 @@ + * The :class:`memoryview` object. + * A small subset of the :mod:`importlib` module, + `described below <#importlib-section>`__. +-* Float-to-string and string-to-float conversions now round their +- results more correctly, and :func:`repr` of a floating-point +- number *x* returns a result that's guaranteed to round back to the +- same number when converted back to a string. ++* The :func:`repr` of a float ``x`` is shorter in many cases: it's now ++ based on the shortest decimal string that's guaranteed to round back ++ to ``x``. As in previous versions of Python, it's guaranteed that ++ ``float(repr(x))`` recovers ``x``. ++* Float-to-string and string-to-float conversions are correctly rounded. ++ The :func:`round` function is also now correctly rounded. + * The :ctype:`PyCapsule` type, used to provide a C API for extension modules. + * The :cfunc:`PyLong_AsLongAndOverflow` C API function. + +@@ -868,12 +870,6 @@ + + Several performance enhancements have been added: + +-.. * A new :program:`configure` option, :option:`--with-computed-gotos`, +- compiles the main bytecode interpreter loop using a new dispatch +- mechanism that gives speedups of up to 20%, depending on the system +- and benchmark. The new mechanism is only supported on certain +- compilers, such as gcc, SunPro, and icc. +- + * A new opcode was added to perform the initial setup for + :keyword:`with` statements, looking up the :meth:`__enter__` and + :meth:`__exit__` methods. (Contributed by Benjamin Peterson.) +@@ -1073,7 +1069,7 @@ + (Added by Raymond Hettinger; :issue:`1818`.) + + Finally, the :class:`~collections.Mapping` abstract base class now +- raises a :exc:`NotImplemented` exception if a mapping is compared to ++ returns :const:`NotImplemented` if a mapping is compared to + another type that isn't a :class:`Mapping`. + (Fixed by Daniel Stutzbach; :issue:`8729`.) + +--- a/Doc/tools/dailybuild.py ++++ b/Doc/tools/dailybuild.py +@@ -33,10 +33,9 @@ + + BRANCHES = [ + # checkout, target, isdev +- (BUILDROOT + '/python26', WWWROOT, False), ++ (BUILDROOT + '/python32', WWWROOT + '/dev', True), ++ (BUILDROOT + '/python27', WWWROOT, False), + (BUILDROOT + '/python31', WWWROOT + '/py3k', False), +- (BUILDROOT + '/python27', WWWROOT + '/dev', True), +- (BUILDROOT + '/python32', WWWROOT + '/dev/py3k', True), + ] + + +@@ -53,7 +52,7 @@ + print 'Copying HTML files' + os.system('cp -a Doc/build/html/* %s' % target) + print 'Copying dist files' +- os.system('mkdir %s/archives' % target) ++ os.system('mkdir -p %s/archives' % target) + os.system('cp -a Doc/dist/* %s/archives' % target) + print 'Finished' + print '=' * 80 +--- a/Doc/tools/sphinxext/indexcontent.html ++++ b/Doc/tools/sphinxext/indexcontent.html +@@ -7,12 +7,12 @@ + or all "What's new" documents since 2.0

+ +- + + ++ + + +--- a/Doc/tools/sphinxext/susp-ignored.csv ++++ b/Doc/tools/sphinxext/susp-ignored.csv +@@ -164,3 +164,139 @@ + whatsnew/2.5,,:memory,:memory: + whatsnew/2.5,,:step,[start:stop:step] + whatsnew/2.5,,:stop,[start:stop:step] ++distutils/examples,267,`,This is the description of the ``foobar`` package. ++documenting/fromlatex,39,:func,:func:`str(object)` ++documenting/fromlatex,39,`,:func:`str(object)` ++documenting/fromlatex,39,`,``str(object)`` ++documenting/fromlatex,55,.. deprecated:,.. deprecated:: 2.5 ++documenting/fromlatex,66,.. note:,.. note:: ++documenting/fromlatex,76,:samp,":samp:`open({filename}, {mode})`" ++documenting/fromlatex,76,`,":samp:`open({filename}, {mode})`" ++documenting/fromlatex,80,`,``'c'`` ++documenting/fromlatex,80,`,`Title `_ ++documenting/fromlatex,80,`,``code`` ++documenting/fromlatex,80,`,`Title `_ ++documenting/fromlatex,99,:file,:file:`C:\\Temp\\my.tmp` ++documenting/fromlatex,99,`,:file:`C:\\Temp\\my.tmp` ++documenting/fromlatex,99,`,"``open(""C:\Temp\my.tmp"")``" ++documenting/fromlatex,129,.. function:,.. function:: do_foo(bar) ++documenting/fromlatex,141,.. function:,".. function:: open(filename[, mode[, buffering]])" ++documenting/fromlatex,152,.. function:,.. function:: foo_* ++documenting/fromlatex,152,:noindex,:noindex: ++documenting/fromlatex,162,.. describe:,.. describe:: a == b ++documenting/fromlatex,168,.. cmdoption:,.. cmdoption:: -O ++documenting/fromlatex,168,.. envvar:,.. envvar:: PYTHONINSPECT ++documenting/rest,33,`,``text`` ++documenting/rest,47,:rolename,:rolename:`content` ++documenting/rest,47,`,:rolename:`content` ++documenting/rest,103,::,This is a normal text paragraph. The next paragraph is a code sample:: ++documenting/rest,130,`,`Link text `_ ++documenting/rest,187,.. function:,.. function:: foo(x) ++documenting/rest,187,:bar,:bar: no ++documenting/rest,208,.. rubric:,.. rubric:: Footnotes ++faq/programming,,:reduce,"print (lambda Ru,Ro,Iu,Io,IM,Sx,Sy:reduce(lambda x,y:x+y,map(lambda y," ++faq/programming,,:reduce,"Sx=Sx,Sy=Sy:reduce(lambda x,y:x+y,map(lambda x,xc=Ru,yc=yc,Ru=Ru,Ro=Ro," ++faq/programming,,:chr,">=4.0) or 1+f(xc,yc,x*x-y*y+xc,2.0*x*y+yc,k-1,f):f(xc,yc,x,y,k,f):chr(" ++faq/programming,,::,for x in sequence[::-1]: ++faq/windows,229,:EOF,@setlocal enableextensions & python -x %~f0 %* & goto :EOF ++faq/windows,393,:REG,.py :REG_SZ: c:\\python.exe -u %s %s ++library/bisect,32,:hi,all(val >= x for val in a[i:hi]) ++library/bisect,42,:hi,all(val > x for val in a[i:hi]) ++library/http.client,52,:port,host:port ++library/nntplib,,:bytes,:bytes ++library/nntplib,,:lines,:lines ++library/nntplib,,:lines,"['xref', 'from', ':lines', ':bytes', 'references', 'date', 'message-id', 'subject']" ++library/nntplib,,:bytes,"['xref', 'from', ':lines', ':bytes', 'references', 'date', 'message-id', 'subject']" ++library/pickle,567,:memory,"conn = sqlite3.connect("":memory:"")" ++library/profile,293,:lineno,"(sort by filename:lineno)," ++library/socket,,::,"(10, 1, 6, '', ('2001:888:2000:d::a2', 80, 0, 0))]" ++library/stdtypes,,:end,s[start:end] ++library/stdtypes,,:end,s[start:end] ++license,,`,* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY ++license,,`,* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND ++license,,`,"``Software''), to deal in the Software without restriction, including" ++license,,`,"THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND," ++reference/lexical_analysis,704,`,$ ? ` ++whatsnew/2.7,735,:Sunday,'2009:4:Sunday' ++whatsnew/2.7,862,::,"export PYTHONWARNINGS=all,error:::Cookie:0" ++whatsnew/2.7,862,:Cookie,"export PYTHONWARNINGS=all,error:::Cookie:0" ++whatsnew/2.7,,::,>>> urlparse.urlparse('http://[1080::8:800:200C:417A]/foo') ++whatsnew/2.7,,::,"ParseResult(scheme='http', netloc='[1080::8:800:200C:417A]'," ++documenting/markup,33,.. sectionauthor:,.. sectionauthor:: Guido van Rossum ++documenting/markup,42,:mod,:mod:`parrot` -- Dead parrot access ++documenting/markup,42,`,:mod:`parrot` -- Dead parrot access ++documenting/markup,42,.. module:,.. module:: parrot ++documenting/markup,42,:platform,":platform: Unix, Windows" ++documenting/markup,42,:synopsis,:synopsis: Analyze and reanimate dead parrots. ++documenting/markup,42,.. moduleauthor:,.. moduleauthor:: Eric Cleese ++documenting/markup,42,.. moduleauthor:,.. moduleauthor:: John Idle ++documenting/markup,88,:noindex,:noindex: ++documenting/markup,95,.. function:,.. function:: spam(eggs) ++documenting/markup,95,:noindex,:noindex: ++documenting/markup,101,.. method:,.. method:: FileInput.input(...) ++documenting/markup,121,.. cfunction:,".. cfunction:: PyObject* PyType_GenericAlloc(PyTypeObject *type, Py_ssize_t nitems)" ++documenting/markup,131,.. cmember:,.. cmember:: PyObject* PyTypeObject.tp_bases ++documenting/markup,150,.. cvar:,.. cvar:: PyObject* PyClass_Type ++documenting/markup,179,.. function:,".. function:: Timer.repeat([repeat=3[, number=1000000]])" ++documenting/markup,209,.. cmdoption:,.. cmdoption:: -m ++documenting/markup,227,.. describe:,.. describe:: opcode ++documenting/markup,256,.. highlightlang:,.. highlightlang:: c ++documenting/markup,276,.. literalinclude:,.. literalinclude:: example.py ++documenting/markup,291,:rolename,:rolename:`content` ++documenting/markup,291,`,:rolename:`content` ++documenting/markup,296,:role,:role:`title ` ++documenting/markup,296,`,:role:`title ` ++documenting/markup,302,:meth,:meth:`~Queue.Queue.get` ++documenting/markup,302,`,:meth:`~Queue.Queue.get` ++documenting/markup,350,:func,:func:`filter` ++documenting/markup,350,`,:func:`filter` ++documenting/markup,350,:func,:func:`foo.filter` ++documenting/markup,350,`,:func:`foo.filter` ++documenting/markup,356,:func,:func:`open` ++documenting/markup,356,`,:func:`open` ++documenting/markup,356,:func,:func:`.open` ++documenting/markup,356,`,:func:`.open` ++documenting/markup,435,:file,... is installed in :file:`/usr/lib/python2.{x}/site-packages` ... ++documenting/markup,435,`,... is installed in :file:`/usr/lib/python2.{x}/site-packages` ... ++documenting/markup,454,:kbd,:kbd:`C-x C-f` ++documenting/markup,454,`,:kbd:`C-x C-f` ++documenting/markup,454,:kbd,:kbd:`Control-x Control-f` ++documenting/markup,454,`,:kbd:`Control-x Control-f` ++documenting/markup,468,:mailheader,:mailheader:`Content-Type` ++documenting/markup,468,`,:mailheader:`Content-Type` ++documenting/markup,477,:manpage,:manpage:`ls(1)` ++documenting/markup,477,`,:manpage:`ls(1)` ++documenting/markup,493,:menuselection,:menuselection:`Start --> Programs` ++documenting/markup,493,`,:menuselection:`Start --> Programs` ++documenting/markup,508,`,``code`` ++documenting/markup,526,:file,:file: ++documenting/markup,526,`,``code`` ++documenting/markup,561,:ref,:ref:`label-name` ++documenting/markup,561,`,:ref:`label-name` ++documenting/markup,565,:ref,"It refers to the section itself, see :ref:`my-reference-label`." ++documenting/markup,565,`,"It refers to the section itself, see :ref:`my-reference-label`." ++documenting/markup,574,:ref,:ref: ++documenting/markup,595,.. note:,.. note:: ++documenting/markup,622,.. versionadded:,.. versionadded:: 2.5 ++documenting/markup,647,::,.. impl-detail:: ++documenting/markup,647,::,.. impl-detail:: This shortly mentions an implementation detail. ++documenting/markup,667,.. seealso:,.. seealso:: ++documenting/markup,667,:mod,Module :mod:`zipfile` ++documenting/markup,667,`,Module :mod:`zipfile` ++documenting/markup,667,:mod,Documentation of the :mod:`zipfile` standard module. ++documenting/markup,667,`,Documentation of the :mod:`zipfile` standard module. ++documenting/markup,667,`,"`GNU tar manual, Basic Tar Format `_" ++documenting/markup,681,.. centered:,.. centered:: ++documenting/markup,726,.. toctree:,.. toctree:: ++documenting/markup,726,:maxdepth,:maxdepth: 2 ++documenting/markup,742,.. index:,.. index:: ++documenting/markup,772,.. index:,".. index:: BNF, grammar, syntax, notation" ++documenting/markup,803,`,"unaryneg ::= ""-"" `integer`" ++documenting/markup,808,.. productionlist:,.. productionlist:: ++documenting/markup,808,`,"try1_stmt: ""try"" "":"" `suite`" ++documenting/markup,808,`,": (""except"" [`expression` ["","" `target`]] "":"" `suite`)+" ++documenting/markup,808,`,": [""else"" "":"" `suite`]" ++documenting/markup,808,`,": [""finally"" "":"" `suite`]" ++documenting/markup,808,`,"try2_stmt: ""try"" "":"" `suite`" ++documenting/markup,808,`,": ""finally"" "":"" `suite`" ++library/urllib2,67,:close,Connection:close +--- a/Doc/tools/sphinxext/suspicious.py ++++ b/Doc/tools/sphinxext/suspicious.py +@@ -41,9 +41,11 @@ + + """ + +-import os, sys ++import os ++import re + import csv +-import re ++import sys ++ + from docutils import nodes + from sphinx.builders import Builder + +@@ -54,9 +56,10 @@ + (?> + + The output suggests that bound and unbound methods are two different types. +-While they could have been implemented that way, the actual C implemention of ++While they could have been implemented that way, the actual C implementation of + :ctype:`PyMethod_Type` in + `Objects/classobject.c `_ + is a single object with two different representations depending on whether the +--- a/Doc/tutorial/controlflow.rst ++++ b/Doc/tutorial/controlflow.rst +@@ -431,9 +431,9 @@ + print "-- I'm sorry, we're all out of", kind + for arg in arguments: print arg + print "-" * 40 +- keys = keywords.keys() +- keys.sort() +- for kw in keys: print kw, ":", keywords[kw] ++ keys = sorted(keywords.keys()) ++ for kw in keys: ++ print kw, ":", keywords[kw] + + It could be called like this:: + +--- a/Doc/tutorial/classes.rst ++++ b/Doc/tutorial/classes.rst +@@ -64,7 +64,7 @@ + A *namespace* is a mapping from names to objects. Most namespaces are currently + implemented as Python dictionaries, but that's normally not noticeable in any + way (except for performance), and it may change in the future. Examples of +-namespaces are: the set of built-in names (functions such as :func:`abs`, and ++namespaces are: the set of built-in names (containing functions such as :func:`abs`, and + built-in exception names); the global names in a module; and the local names in + a function invocation. In a sense the set of attributes of an object also form + a namespace. The important thing to know about namespaces is that there is +@@ -693,7 +693,7 @@ + StopIteration + + Having seen the mechanics behind the iterator protocol, it is easy to add +-iterator behavior to your classes. Define a :meth:`__iter__` method which ++iterator behavior to your classes. Define an :meth:`__iter__` method which + returns an object with a :meth:`next` method. If the class defines + :meth:`next`, then :meth:`__iter__` can just return ``self``:: + +@@ -710,7 +710,10 @@ + self.index = self.index - 1 + return self.data[self.index] + +- >>> for char in Reverse('spam'): ++ >>> rev = Reverse('spam') ++ >>> iter(rev) ++ <__main__.Reverse object at 0x00A1DB50> ++ >>> for char in rev: + ... print char + ... + m +--- a/Doc/tutorial/datastructures.rst ++++ b/Doc/tutorial/datastructures.rst +@@ -481,8 +481,8 @@ + + The :meth:`keys` method of a dictionary object returns a list of all the keys + used in the dictionary, in arbitrary order (if you want it sorted, just apply +-the :meth:`sort` method to the list of keys). To check whether a single key is +-in the dictionary, use the :keyword:`in` keyword. ++the :func:`sorted` function to it). To check whether a single key is in the ++dictionary, use the :keyword:`in` keyword. + + Here is a small example using a dictionary:: + +--- a/Doc/tutorial/floatingpoint.rst ++++ b/Doc/tutorial/floatingpoint.rst +@@ -48,67 +48,75 @@ + + 0.0001100110011001100110011001100110011001100110011... + +-Stop at any finite number of bits, and you get an approximation. This is why +-you see things like:: ++Stop at any finite number of bits, and you get an approximation. + +- >>> 0.1 +- 0.10000000000000001 ++On a typical machine running Python, there are 53 bits of precision available ++for a Python float, so the value stored internally when you enter the decimal ++number ``0.1`` is the binary fraction :: + +-On most machines today, that is what you'll see if you enter 0.1 at a Python +-prompt. You may not, though, because the number of bits used by the hardware to +-store floating-point values can vary across machines, and Python only prints a +-decimal approximation to the true decimal value of the binary approximation +-stored by the machine. On most machines, if Python were to print the true +-decimal value of the binary approximation stored for 0.1, it would have to +-display :: ++ 0.00011001100110011001100110011001100110011001100110011010 + ++which is close to, but not exactly equal to, 1/10. ++ ++It's easy to forget that the stored value is an approximation to the original ++decimal fraction, because of the way that floats are displayed at the ++interpreter prompt. Python only prints a decimal approximation to the true ++decimal value of the binary approximation stored by the machine. If Python ++were to print the true decimal value of the binary approximation stored for ++0.1, it would have to display :: ++ + >>> 0.1 + 0.1000000000000000055511151231257827021181583404541015625 + +-instead! The Python prompt uses the built-in :func:`repr` function to obtain a +-string version of everything it displays. For floats, ``repr(float)`` rounds +-the true decimal value to 17 significant digits, giving :: ++That is more digits than most people find useful, so Python keeps the number ++of digits manageable by displaying a rounded value instead :: + +- 0.10000000000000001 ++ >>> 0.1 ++ 0.1 + +-``repr(float)`` produces 17 significant digits because it turns out that's +-enough (on most machines) so that ``eval(repr(x)) == x`` exactly for all finite +-floats *x*, but rounding to 16 digits is not enough to make that true. ++It's important to realize that this is, in a real sense, an illusion: the value ++in the machine is not exactly 1/10, you're simply rounding the *display* of the ++true machine value. This fact becomes apparent as soon as you try to do ++arithmetic with these values :: + +-Note that this is in the very nature of binary floating-point: this is not a bug +-in Python, and it is not a bug in your code either. You'll see the same kind of +-thing in all languages that support your hardware's floating-point arithmetic +-(although some languages may not *display* the difference by default, or in all +-output modes). ++ >>> 0.1 + 0.2 ++ 0.30000000000000004 + +-Python's built-in :func:`str` function produces only 12 significant digits, and +-you may wish to use that instead. It's unusual for ``eval(str(x))`` to +-reproduce *x*, but the output may be more pleasant to look at:: ++Note that this is in the very nature of binary floating-point: this is not a ++bug in Python, and it is not a bug in your code either. You'll see the same ++kind of thing in all languages that support your hardware's floating-point ++arithmetic (although some languages may not *display* the difference by ++default, or in all output modes). + +- >>> print str(0.1) +- 0.1 ++Other surprises follow from this one. For example, if you try to round the ++value 2.675 to two decimal places, you get this :: + +-It's important to realize that this is, in a real sense, an illusion: the value +-in the machine is not exactly 1/10, you're simply rounding the *display* of the +-true machine value. ++ >>> round(2.675, 2) ++ 2.67 + +-Other surprises follow from this one. For example, after seeing :: ++The documentation for the built-in :func:`round` function says that it rounds ++to the nearest value, rounding ties away from zero. Since the decimal fraction ++2.675 is exactly halfway between 2.67 and 2.68, you might expect the result ++here to be (a binary approximation to) 2.68. It's not, because when the ++decimal string ``2.675`` is converted to a binary floating-point number, it's ++again replaced with a binary approximation, whose exact value is :: + +- >>> 0.1 +- 0.10000000000000001 ++ 2.67499999999999982236431605997495353221893310546875 + +-you may be tempted to use the :func:`round` function to chop it back to the +-single digit you expect. But that makes no difference:: ++Since this approximation is slightly closer to 2.67 than to 2.68, it's rounded ++down. + +- >>> round(0.1, 1) +- 0.10000000000000001 ++If you're in a situation where you care which way your decimal halfway-cases ++are rounded, you should consider using the :mod:`decimal` module. ++Incidentally, the :mod:`decimal` module also provides a nice way to "see" the ++exact value that's stored in any particular Python float :: + +-The problem is that the binary floating-point value stored for "0.1" was already +-the best possible binary approximation to 1/10, so trying to round it again +-can't make it better: it was already as good as it gets. ++ >>> from decimal import Decimal ++ >>> Decimal(2.675) ++ Decimal('2.67499999999999982236431605997495353221893310546875') + +-Another consequence is that since 0.1 is not exactly 1/10, summing ten values of +-0.1 may not yield exactly 1.0, either:: ++Another consequence is that since 0.1 is not exactly 1/10, summing ten values ++of 0.1 may not yield exactly 1.0, either:: + + >>> sum = 0.0 + >>> for i in range(10): +@@ -131,9 +139,9 @@ + + While pathological cases do exist, for most casual use of floating-point + arithmetic you'll see the result you expect in the end if you simply round the +-display of your final results to the number of decimal digits you expect. +-:func:`str` usually suffices, and for finer control see the :meth:`str.format` +-method's format specifiers in :ref:`formatstrings`. ++display of your final results to the number of decimal digits you expect. For ++fine control over how a float is displayed see the :meth:`str.format` method's ++format specifiers in :ref:`formatstrings`. + + + .. _tut-fp-error: +@@ -141,24 +149,24 @@ + Representation Error + ==================== + +-This section explains the "0.1" example in detail, and shows how you can perform +-an exact analysis of cases like this yourself. Basic familiarity with binary +-floating-point representation is assumed. ++This section explains the "0.1" example in detail, and shows how you can ++perform an exact analysis of cases like this yourself. Basic familiarity with ++binary floating-point representation is assumed. + + :dfn:`Representation error` refers to the fact that some (most, actually) + decimal fractions cannot be represented exactly as binary (base 2) fractions. + This is the chief reason why Python (or Perl, C, C++, Java, Fortran, and many + others) often won't display the exact decimal number you expect:: + +- >>> 0.1 +- 0.10000000000000001 ++ >>> 0.1 + 0.2 ++ 0.30000000000000004 + +-Why is that? 1/10 is not exactly representable as a binary fraction. Almost all +-machines today (November 2000) use IEEE-754 floating point arithmetic, and +-almost all platforms map Python floats to IEEE-754 "double precision". 754 +-doubles contain 53 bits of precision, so on input the computer strives to +-convert 0.1 to the closest fraction it can of the form *J*/2**\ *N* where *J* is +-an integer containing exactly 53 bits. Rewriting :: ++Why is that? 1/10 and 2/10 are not exactly representable as a binary ++fraction. Almost all machines today (July 2010) use IEEE-754 floating point ++arithmetic, and almost all platforms map Python floats to IEEE-754 "double ++precision". 754 doubles contain 53 bits of precision, so on input the computer ++strives to convert 0.1 to the closest fraction it can of the form *J*/2**\ *N* ++where *J* is an integer containing exactly 53 bits. Rewriting :: + + 1 / 10 ~= J / (2**N) + +@@ -170,24 +178,24 @@ + the best value for *N* is 56:: + + >>> 2**52 +- 4503599627370496L ++ 4503599627370496 + >>> 2**53 +- 9007199254740992L ++ 9007199254740992 + >>> 2**56/10 +- 7205759403792793L ++ 7205759403792793 + +-That is, 56 is the only value for *N* that leaves *J* with exactly 53 bits. The +-best possible value for *J* is then that quotient rounded:: ++That is, 56 is the only value for *N* that leaves *J* with exactly 53 bits. ++The best possible value for *J* is then that quotient rounded:: + + >>> q, r = divmod(2**56, 10) + >>> r +- 6L ++ 6 + + Since the remainder is more than half of 10, the best approximation is obtained + by rounding up:: + + >>> q+1 +- 7205759403792794L ++ 7205759403792794 + + Therefore the best possible approximation to 1/10 in 754 double precision is + that over 2\*\*56, or :: +@@ -195,8 +203,8 @@ + 7205759403792794 / 72057594037927936 + + Note that since we rounded up, this is actually a little bit larger than 1/10; +-if we had not rounded up, the quotient would have been a little bit smaller than +-1/10. But in no case can it be *exactly* 1/10! ++if we had not rounded up, the quotient would have been a little bit smaller ++than 1/10. But in no case can it be *exactly* 1/10! + + So the computer never "sees" 1/10: what it sees is the exact fraction given + above, the best 754 double approximation it can get:: +@@ -207,13 +215,12 @@ + If we multiply that fraction by 10\*\*30, we can see the (truncated) value of + its 30 most significant decimal digits:: + +- >>> 7205759403792794 * 10**30 / 2**56 ++ >>> 7205759403792794 * 10**30 // 2**56 + 100000000000000005551115123125L + + meaning that the exact number stored in the computer is approximately equal to +-the decimal value 0.100000000000000005551115123125. Rounding that to 17 +-significant digits gives the 0.10000000000000001 that Python displays (well, +-will display on any 754-conforming platform that does best-possible input and +-output conversions in its C library --- yours may not!). +- +- ++the decimal value 0.100000000000000005551115123125. In versions prior to ++Python 2.7 and Python 3.1, Python rounded this value to 17 significant digits, ++giving '0.10000000000000001'. In current versions, Python displays a value ++based on the shortest decimal fraction that rounds correctly back to the true ++binary value, resulting simply in '0.1'. +--- a/Doc/library/cookie.rst ++++ b/Doc/library/cookie.rst +@@ -235,8 +235,6 @@ + + >>> import Cookie + >>> C = Cookie.SimpleCookie() +- >>> C = Cookie.SerialCookie() +- >>> C = Cookie.SmartCookie() + >>> C["fig"] = "newton" + >>> C["sugar"] = "wafer" + >>> print C # generate HTTP headers +@@ -245,28 +243,27 @@ + >>> print C.output() # same thing + Set-Cookie: fig=newton + Set-Cookie: sugar=wafer +- >>> C = Cookie.SmartCookie() ++ >>> C = Cookie.SimpleCookie() + >>> C["rocky"] = "road" + >>> C["rocky"]["path"] = "/cookie" + >>> print C.output(header="Cookie:") + Cookie: rocky=road; Path=/cookie + >>> print C.output(attrs=[], header="Cookie:") + Cookie: rocky=road +- >>> C = Cookie.SmartCookie() ++ >>> C = Cookie.SimpleCookie() + >>> C.load("chips=ahoy; vienna=finger") # load from a string (HTTP header) + >>> print C + Set-Cookie: chips=ahoy + Set-Cookie: vienna=finger +- >>> C = Cookie.SmartCookie() ++ >>> C = Cookie.SimpleCookie() + >>> C.load('keebler="E=everybody; L=\\"Loves\\"; fudge=\\012;";') + >>> print C + Set-Cookie: keebler="E=everybody; L=\"Loves\"; fudge=\012;" +- >>> C = Cookie.SmartCookie() ++ >>> C = Cookie.SimpleCookie() + >>> C["oreo"] = "doublestuff" + >>> C["oreo"]["path"] = "/" + >>> print C + Set-Cookie: oreo=doublestuff; Path=/ +- >>> C = Cookie.SmartCookie() + >>> C["twix"] = "none for you" + >>> C["twix"].value + 'none for you' +@@ -280,6 +277,8 @@ + >>> print C + Set-Cookie: number=7 + Set-Cookie: string=seven ++ >>> # SerialCookie and SmartCookie are deprecated ++ >>> # using it can cause security loopholes in your code. + >>> C = Cookie.SerialCookie() + >>> C["number"] = 7 + >>> C["string"] = "seven" +--- a/Doc/library/subprocess.rst ++++ b/Doc/library/subprocess.rst +@@ -254,7 +254,7 @@ + Exceptions raised in the child process, before the new program has started to + execute, will be re-raised in the parent. Additionally, the exception object + will have one extra attribute called :attr:`child_traceback`, which is a string +-containing traceback information from the childs point of view. ++containing traceback information from the child's point of view. + + The most common exception raised is :exc:`OSError`. This occurs, for example, + when trying to execute a non-existent file. Applications should prepare for +@@ -551,7 +551,7 @@ + pipe = os.popen("cmd", 'w') + ... + rc = pipe.close() +- if rc is not None and rc % 256: ++ if rc is not None and rc >> 8: + print "There were some errors" + ==> + process = Popen("cmd", 'w', shell=True, stdin=PIPE) +--- a/Doc/library/csv.rst ++++ b/Doc/library/csv.rst +@@ -78,7 +78,7 @@ + A short usage example:: + + >>> import csv +- >>> spamReader = csv.reader(open('eggs.csv'), delimiter=' ', quotechar='|') ++ >>> spamReader = csv.reader(open('eggs.csv', 'rb'), delimiter=' ', quotechar='|') + >>> for row in spamReader: + ... print ', '.join(row) + Spam, Spam, Spam, Spam, Spam, Baked Beans +@@ -116,7 +116,7 @@ + A short usage example:: + + >>> import csv +- >>> spamWriter = csv.writer(open('eggs.csv', 'w'), delimiter=' ', ++ >>> spamWriter = csv.writer(open('eggs.csv', 'wb'), delimiter=' ', + ... quotechar='|', quoting=csv.QUOTE_MINIMAL) + >>> spamWriter.writerow(['Spam'] * 5 + ['Baked Beans']) + >>> spamWriter.writerow(['Spam', 'Lovely Spam', 'Wonderful Spam']) +@@ -234,7 +234,7 @@ + + An example for :class:`Sniffer` use:: + +- csvfile = open("example.csv") ++ csvfile = open("example.csv", "rb") + dialect = csv.Sniffer().sniff(csvfile.read(1024)) + csvfile.seek(0) + reader = csv.reader(csvfile, dialect) +--- a/Doc/library/datetime.rst ++++ b/Doc/library/datetime.rst +@@ -235,6 +235,14 @@ + | ``abs(t)`` | equivalent to +\ *t* when ``t.days >= 0``, and| + | | to -*t* when ``t.days < 0``. (2) | + +--------------------------------+-----------------------------------------------+ ++| ``str(t)`` | Returns a string in the form | ++| | ``[D day[s], ][H]H:MM:SS[.UUUUUU]``, where D | ++| | is negative for negative ``t``. (5) | +++--------------------------------+-----------------------------------------------+ ++| ``repr(t)`` | Returns a string in the form | ++| | ``datetime.timedelta(D[, S[, U]])``, where D | ++| | is negative for negative ``t``. (5) | +++--------------------------------+-----------------------------------------------+ + + Notes: + +@@ -250,6 +258,16 @@ + (4) + -*timedelta.max* is not representable as a :class:`timedelta` object. + ++(5) ++ String representations of :class:`timedelta` objects are normalized ++ similarly to their internal representation. This leads to somewhat ++ unusual results for negative timedeltas. For example: ++ ++ >>> timedelta(hours=-5) ++ datetime.timedelta(-1, 68400) ++ >>> print(_) ++ -1 day, 19:00:00 ++ + In addition to the operations listed above :class:`timedelta` objects support + certain additions and subtractions with :class:`date` and :class:`datetime` + objects (see below). +@@ -926,7 +944,7 @@ + d.toordinal() - date(d.year, 1, 1).toordinal() + 1`` is the day number within + the current year starting with ``1`` for January 1st. The :attr:`tm_isdst` flag + of the result is set according to the :meth:`dst` method: :attr:`tzinfo` is +- ``None`` or :meth:`dst`` returns ``None``, :attr:`tm_isdst` is set to ``-1``; ++ ``None`` or :meth:`dst` returns ``None``, :attr:`tm_isdst` is set to ``-1``; + else if :meth:`dst` returns a non-zero value, :attr:`tm_isdst` is set to ``1``; + else :attr:`tm_isdst` is set to ``0``. + +--- a/Doc/library/re.rst ++++ b/Doc/library/re.rst +@@ -672,6 +672,11 @@ + metacharacters in it. + + ++.. function:: purge() ++ ++ Clear the regular expression cache. ++ ++ + .. exception:: error + + Exception raised when a string passed to one of the functions here is not a +@@ -1205,9 +1210,9 @@ + ... random.shuffle(inner_word) + ... return m.group(1) + "".join(inner_word) + m.group(3) + >>> text = "Professor Abdolmalek, please report your absences promptly." +- >>> re.sub("(\w)(\w+)(\w)", repl, text) ++ >>> re.sub(r"(\w)(\w+)(\w)", repl, text) + 'Poefsrosr Aealmlobdk, pslaee reorpt your abnseces plmrptoy.' +- >>> re.sub("(\w)(\w+)(\w)", repl, text) ++ >>> re.sub(r"(\w)(\w+)(\w)", repl, text) + 'Pofsroser Aodlambelk, plasee reoprt yuor asnebces potlmrpy.' + + +--- a/Doc/library/string.rst ++++ b/Doc/library/string.rst +@@ -190,7 +190,7 @@ + the format string (integers for positional arguments, and strings for + named arguments), and a reference to the *args* and *kwargs* that was + passed to vformat. The set of unused args can be calculated from these +- parameters. :meth:`check_unused_args` is assumed to throw an exception if ++ parameters. :meth:`check_unused_args` is assumed to raise an exception if + the check fails. + + .. method:: format_field(value, format_spec) +@@ -324,11 +324,11 @@ + precision: `integer` + type: "b" | "c" | "d" | "e" | "E" | "f" | "F" | "g" | "G" | "n" | "o" | "s" | "x" | "X" | "%" + +-The *fill* character can be any character other than '}' (which signifies the +-end of the field). The presence of a fill character is signaled by the *next* +-character, which must be one of the alignment options. If the second character +-of *format_spec* is not a valid alignment option, then it is assumed that both +-the fill character and the alignment option are absent. ++The *fill* character can be any character other than '{' or '}'. The presence ++of a fill character is signaled by the character following it, which must be ++one of the alignment options. If the second character of *format_spec* is not ++a valid alignment option, then it is assumed that both the fill character and ++the alignment option are absent. + + The meaning of the various alignment options is as follows: + +@@ -472,7 +472,7 @@ + | | from the significand, and the decimal point is also | + | | removed if there are no remaining digits following it. | + | | | +- | | Postive and negative infinity, positive and negative | ++ | | Positive and negative infinity, positive and negative | + | | zero, and nans, are formatted as ``inf``, ``-inf``, | + | | ``0``, ``-0`` and ``nan`` respectively, regardless of | + | | the precision. | +--- a/Doc/library/urllib2.rst ++++ b/Doc/library/urllib2.rst +@@ -18,6 +18,7 @@ + URLs (mostly HTTP) in a complex world --- basic and digest authentication, + redirections, cookies and more. + ++ + The :mod:`urllib2` module defines the following functions: + + +@@ -25,18 +26,22 @@ + + Open the URL *url*, which can be either a string or a :class:`Request` object. + ++ .. warning:: ++ HTTPS requests do not do any verification of the server's certificate. ++ + *data* may be a string specifying additional data to send to the server, or + ``None`` if no such data is needed. Currently HTTP requests are the only ones + that use *data*; the HTTP request will be a POST instead of a GET when the + *data* parameter is provided. *data* should be a buffer in the standard + :mimetype:`application/x-www-form-urlencoded` format. The + :func:`urllib.urlencode` function takes a mapping or sequence of 2-tuples and +- returns a string in this format. ++ returns a string in this format. urllib2 module sends HTTP/1.1 requests with ++ `Connection:close` header included. + + The optional *timeout* parameter specifies a timeout in seconds for blocking + operations like the connection attempt (if not specified, the global default +- timeout setting will be used). This actually only works for HTTP, HTTPS, +- FTP and FTPS connections. ++ timeout setting will be used). This actually only works for HTTP, HTTPS and ++ FTP connections. + + This function returns a file-like object with two additional methods: + +@@ -428,7 +433,7 @@ + optional *timeout* parameter specifies a timeout in seconds for blocking + operations like the connection attempt (if not specified, the global default + timeout setting will be used). The timeout feature actually works only for +- HTTP, HTTPS, FTP and FTPS connections). ++ HTTP, HTTPS and FTP connections). + + .. versionchanged:: 2.6 + *timeout* was added. +@@ -464,7 +469,8 @@ + named :meth:`unknown_open`. + + Note that the implementation of these methods may involve calls of the parent +- :class:`OpenerDirector` instance's :meth:`.open` and :meth:`.error` methods. ++ :class:`OpenerDirector` instance's :meth:`~OpenerDirector.open` and ++ :meth:`~OpenerDirector.error` methods. + + #. Every handler with a method named like :samp:`{protocol}_response` has that + method called to post-process the response. +--- a/Doc/library/linecache.rst ++++ b/Doc/library/linecache.rst +@@ -17,7 +17,7 @@ + + .. function:: getline(filename, lineno[, module_globals]) + +- Get line *lineno* from file named *filename*. This function will never throw an ++ Get line *lineno* from file named *filename*. This function will never raise an + exception --- it will return ``''`` on errors (the terminating newline character + will be included for lines that are found). + +--- a/Doc/library/sys.rst ++++ b/Doc/library/sys.rst +@@ -890,7 +890,7 @@ + A C function has returned. *arg* is ``None``. + + ``'c_exception'`` +- A C function has thrown an exception. *arg* is ``None``. ++ A C function has raised an exception. *arg* is ``None``. + + Note that as an exception is propagated down the chain of callers, an + ``'exception'`` event is generated at each level. +@@ -967,16 +967,12 @@ + .. data:: version + + A string containing the version number of the Python interpreter plus additional +- information on the build number and compiler used. It has a value of the form +- ``'version (#build_number, build_date, build_time) [compiler]'``. The first +- three characters are used to identify the version in the installation +- directories (where appropriate on each platform). An example:: ++ information on the build number and compiler used. This string is displayed ++ when the interactive interpreter is started. Do not extract version information ++ out of it, rather, use :data:`version_info` and the functions provided by the ++ :mod:`platform` module. + +- >>> import sys +- >>> sys.version +- '1.5.2 (#0 Apr 13 1999, 10:51:12) [MSC 32 bit (Intel)]' + +- + .. data:: api_version + + The C API version for this interpreter. Programmers may find this useful when +--- a/Doc/library/itertools.rst ++++ b/Doc/library/itertools.rst +@@ -104,7 +104,7 @@ + yield element + + +-.. function:: itertools.chain.from_iterable(iterable) ++.. classmethod:: chain.from_iterable(iterable) + + Alternate constructor for :func:`chain`. Gets chained inputs from a + single iterable argument that is evaluated lazily. Equivalent to:: +@@ -677,7 +677,7 @@ + # feed the entire iterator into a zero-length deque + collections.deque(iterator, maxlen=0) + else: +- # advance to the emtpy slice starting at position n ++ # advance to the empty slice starting at position n + next(islice(iterator, n, n), None) + + def nth(iterable, n, default=None): +--- a/Doc/library/test.rst ++++ b/Doc/library/test.rst +@@ -6,7 +6,14 @@ + :synopsis: Regression tests package containing the testing suite for Python. + .. sectionauthor:: Brett Cannon + ++.. note:: ++ The :mod:`test` package is meant for internal use by Python only. It is ++ documented for the benefit of the core developers of Python. Any use of ++ this package outside of Python's standard library is discouraged as code ++ mentioned here can change or be removed without notice between releases of ++ Python. + ++ + The :mod:`test` package contains all regression tests for Python as well as the + modules :mod:`test.test_support` and :mod:`test.regrtest`. + :mod:`test.test_support` is used to enhance your tests while +--- a/Doc/library/turtle.rst ++++ b/Doc/library/turtle.rst +@@ -1835,7 +1835,7 @@ + .. function:: setup(width=_CFG["width"], height=_CFG["height"], startx=_CFG["leftright"], starty=_CFG["topbottom"]) + + Set the size and position of the main window. Default values of arguments +- are stored in the configuration dicionary and can be changed via a ++ are stored in the configuration dictionary and can be changed via a + :file:`turtle.cfg` file. + + :param width: if an integer, a size in pixels, if a float, a fraction of the +--- a/Doc/library/fnmatch.rst ++++ b/Doc/library/fnmatch.rst +@@ -73,6 +73,8 @@ + + Return the shell-style *pattern* converted to a regular expression. + ++ Be aware there is no way to quote meta-characters. ++ + Example: + + >>> import fnmatch, re +--- a/Doc/library/ftplib.rst ++++ b/Doc/library/ftplib.rst +@@ -220,9 +220,9 @@ + Retrieve a file or directory listing in ASCII transfer mode. *command* + should be an appropriate ``RETR`` command (see :meth:`retrbinary`) or a + command such as ``LIST``, ``NLST`` or ``MLSD`` (usually just the string +- ``'LIST'``). The *callback* function is called for each line, with the +- trailing CRLF stripped. The default *callback* prints the line to +- ``sys.stdout``. ++ ``'LIST'``). The *callback* function is called for each line with a ++ string argument containing the line with the trailing CRLF stripped. ++ The default *callback* prints the line to ``sys.stdout``. + + + .. method:: FTP.set_pasv(boolean) +--- a/Doc/library/configparser.rst ++++ b/Doc/library/configparser.rst +@@ -41,6 +41,18 @@ + provided on initialization and retrieval. Lines beginning with ``'#'`` or + ``';'`` are ignored and may be used to provide comments. + ++Configuration files may include comments, prefixed by specific characters (``#`` ++and ``;``). Comments may appear on their own in an otherwise empty line, or may ++be entered in lines holding values or spection names. In the latter case, they ++need to be preceded by a whitespace character to be recognized as a comment. ++(For backwards compatibility, only ``;`` starts an inline comment, while ``#`` ++does not.) ++ ++On top of the core functionality, :class:`SafeConfigParser` supports ++interpolation. This means values can contain format strings which refer to ++other values in the same section, or values in a special ``DEFAULT`` section. ++Additional defaults can be provided on initialization. ++ + For example:: + + [My Section] +@@ -128,6 +140,11 @@ + *allow_no_value* was added. + + ++.. exception:: Error ++ ++ Base class for all other configparser exceptions. ++ ++ + .. exception:: NoSectionError + + Exception raised when a specified section is not found. +@@ -371,11 +388,13 @@ + + .. method:: ConfigParser.get(section, option[, raw[, vars]]) + +- Get an *option* value for the named *section*. All the ``'%'`` interpolations +- are expanded in the return values, based on the defaults passed into the +- constructor, as well as the options *vars* provided, unless the *raw* argument +- is true. ++ Get an *option* value for the named *section*. If *vars* is provided, it ++ must be a dictionary. The *option* is looked up in *vars* (if provided), ++ *section*, and in *defaults* in that order. + ++ All the ``'%'`` interpolations are expanded in the return values, unless the ++ *raw* argument is true. Values for interpolation keys are looked up in the ++ same manner as the option. + + .. method:: ConfigParser.items(section[, raw[, vars]]) + +--- a/Doc/library/logging.rst ++++ b/Doc/library/logging.rst +@@ -248,7 +248,7 @@ + methods listed above, but this is how to log at custom log levels. + + :func:`getLogger` returns a reference to a logger instance with the specified +-if it is provided, or ``root`` if not. The names are period-separated ++name if it is provided, or ``root`` if not. The names are period-separated + hierarchical structures. Multiple calls to :func:`getLogger` with the same name + will return a reference to the same logger object. Loggers that are further + down in the hierarchical list are children of loggers higher up in the list. +@@ -321,7 +321,15 @@ + + "%(asctime)s - %(levelname)s - %(message)s" + ++Formatters use a user-configurable function to convert the creation time of a ++record to a tuple. By default, :func:`time.localtime` is used; to change this ++for a particular formatter instance, set the ``converter`` attribute of the ++instance to a function with the same signature as :func:`time.localtime` or ++:func:`time.gmtime`. To change it for all formatters, for example if you want ++all logging times to be shown in GMT, set the ``converter`` attribute in the ++Formatter class (to ``time.gmtime`` for GMT display). + ++ + Configuring Logging + ^^^^^^^^^^^^^^^^^^^ + +@@ -522,6 +530,14 @@ + libraries, then the logger name specified can be "orgname.foo" rather than + just "foo". + ++**PLEASE NOTE:** It is strongly advised that you *do not add any handlers other ++than* :class:`NullHandler` *to your library's loggers*. This is because the ++configuration of handlers is the prerogative of the application developer who ++uses your library. The application developer knows their target audience and ++what handlers are most appropriate for their application: if you add handlers ++"under the hood", you might well interfere with their ability to carry out ++unit tests and deliver logs which suit their requirements. ++ + .. versionadded:: 2.7 + + The :class:`NullHandler` class was not present in previous versions, but is now +@@ -585,6 +601,22 @@ + the message to its destination. Most user-defined subclasses of :class:`Handler` + will need to override this :meth:`emit`. + ++.. _custom-levels: ++ ++Custom Levels ++^^^^^^^^^^^^^ ++ ++Defining your own levels is possible, but should not be necessary, as the ++existing levels have been chosen on the basis of practical experience. ++However, if you are convinced that you need custom levels, great care should ++be exercised when doing this, and it is possibly *a very bad idea to define ++custom levels if you are developing a library*. That's because if multiple ++library authors all define their own custom levels, there is a chance that ++the logging output from such multiple libraries used together will be ++difficult for the using developer to control and/or interpret, because a ++given numeric value might mean different things for different libraries. ++ ++ + Useful Handlers + --------------- + +@@ -722,7 +754,7 @@ + d = {'clientip': '192.168.0.1', 'user': 'fbloggs'} + logging.warning("Protocol problem: %s", "connection reset", extra=d) + +- would print something like :: ++ would print something like:: + + 2006-02-08 22:20:02,165 192.168.0.1 fbloggs Protocol problem: connection reset + +@@ -784,6 +816,14 @@ + Logs a message with level *level* on the root logger. The other arguments are + interpreted as for :func:`debug`. + ++ PLEASE NOTE: The above module-level functions which delegate to the root ++ logger should *not* be used in threads, in versions of Python earlier than ++ 2.7.1 and 3.2, unless at least one handler has been added to the root ++ logger *before* the threads are started. These convenience functions call ++ :func:`basicConfig` to ensure that at least one handler is available; in ++ earlier versions of Python, this can (under rare circumstances) lead to ++ handlers being added multiple times to the root logger, which can in turn ++ lead to multiple messages for the same event. + + .. function:: disable(lvl) + +@@ -805,6 +845,8 @@ + registered using this function, levels should be positive integers and they + should increase in increasing order of severity. + ++ NOTE: If you are thinking of defining your own levels, please see the section ++ on :ref:`custom-levels`. + + .. function:: getLevelName(lvl) + +@@ -839,6 +881,13 @@ + .. versionchanged:: 2.4 + Formerly, :func:`basicConfig` did not take any keyword arguments. + ++ PLEASE NOTE: This function should be called from the main thread ++ before other threads are started. In versions of Python prior to ++ 2.7.1 and 3.2, if this function is called from multiple threads, ++ it is possible (in rare circumstances) that a handler will be added ++ to the root logger more than once, leading to unexpected results ++ such as messages being duplicated in the log. ++ + The following keyword arguments are supported. + + +--------------+---------------------------------------------+ +@@ -1327,6 +1376,10 @@ + be hard to manage if the number of :class:`Logger` instances becomes + effectively unbounded. + ++ ++Using LoggerAdapters to impart contextual information ++^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ++ + An easy way in which you can pass contextual information to be output along + with logging event information is to use the :class:`LoggerAdapter` class. + This class is designed to look like a :class:`Logger`, so that you can call +@@ -1434,6 +1487,80 @@ + + The :class:`LoggerAdapter` class was not present in previous versions. + ++.. _filters-contextual: ++ ++Using Filters to impart contextual information ++^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ++ ++You can also add contextual information to log output using a user-defined ++:class:`Filter`. ``Filter`` instances are allowed to modify the ``LogRecords`` ++passed to them, including adding additional attributes which can then be output ++using a suitable format string, or if needed a custom :class:`Formatter`. ++ ++For example in a web application, the request being processed (or at least, ++the interesting parts of it) can be stored in a threadlocal ++(:class:`threading.local`) variable, and then accessed from a ``Filter`` to ++add, say, information from the request - say, the remote IP address and remote ++user's username - to the ``LogRecord``, using the attribute names 'ip' and ++'user' as in the ``LoggerAdapter`` example above. In that case, the same format ++string can be used to get similar output to that shown above. Here's an example ++script:: ++ ++ import logging ++ from random import choice ++ ++ class ContextFilter(logging.Filter): ++ """ ++ This is a filter which injects contextual information into the log. ++ ++ Rather than use actual contextual information, we just use random ++ data in this demo. ++ """ ++ ++ USERS = ['jim', 'fred', 'sheila'] ++ IPS = ['123.231.231.123', '127.0.0.1', '192.168.0.1'] ++ ++ def filter(self, record): ++ ++ record.ip = choice(ContextFilter.IPS) ++ record.user = choice(ContextFilter.USERS) ++ return True ++ ++ if __name__ == "__main__": ++ levels = (logging.DEBUG, logging.INFO, logging.WARNING, logging.ERROR, logging.CRITICAL) ++ a1 = logging.LoggerAdapter(logging.getLogger("a.b.c"), ++ { "ip" : "123.231.231.123", "user" : "sheila" }) ++ logging.basicConfig(level=logging.DEBUG, ++ format="%(asctime)-15s %(name)-5s %(levelname)-8s IP: %(ip)-15s User: %(user)-8s %(message)s") ++ a1 = logging.getLogger("a.b.c") ++ a2 = logging.getLogger("d.e.f") ++ ++ f = ContextFilter() ++ a1.addFilter(f) ++ a2.addFilter(f) ++ a1.debug("A debug message") ++ a1.info("An info message with %s", "some parameters") ++ for x in range(10): ++ lvl = choice(levels) ++ lvlname = logging.getLevelName(lvl) ++ a2.log(lvl, "A message at %s level with %d %s", lvlname, 2, "parameters") ++ ++which, when run, produces something like:: ++ ++ 2010-09-06 22:38:15,292 a.b.c DEBUG IP: 123.231.231.123 User: fred A debug message ++ 2010-09-06 22:38:15,300 a.b.c INFO IP: 192.168.0.1 User: sheila An info message with some parameters ++ 2010-09-06 22:38:15,300 d.e.f CRITICAL IP: 127.0.0.1 User: sheila A message at CRITICAL level with 2 parameters ++ 2010-09-06 22:38:15,300 d.e.f ERROR IP: 127.0.0.1 User: jim A message at ERROR level with 2 parameters ++ 2010-09-06 22:38:15,300 d.e.f DEBUG IP: 127.0.0.1 User: sheila A message at DEBUG level with 2 parameters ++ 2010-09-06 22:38:15,300 d.e.f ERROR IP: 123.231.231.123 User: fred A message at ERROR level with 2 parameters ++ 2010-09-06 22:38:15,300 d.e.f CRITICAL IP: 192.168.0.1 User: jim A message at CRITICAL level with 2 parameters ++ 2010-09-06 22:38:15,300 d.e.f CRITICAL IP: 127.0.0.1 User: sheila A message at CRITICAL level with 2 parameters ++ 2010-09-06 22:38:15,300 d.e.f DEBUG IP: 192.168.0.1 User: jim A message at DEBUG level with 2 parameters ++ 2010-09-06 22:38:15,301 d.e.f ERROR IP: 127.0.0.1 User: sheila A message at ERROR level with 2 parameters ++ 2010-09-06 22:38:15,301 d.e.f DEBUG IP: 123.231.231.123 User: fred A message at DEBUG level with 2 parameters ++ 2010-09-06 22:38:15,301 d.e.f INFO IP: 123.231.231.123 User: fred A message at INFO level with 2 parameters ++ ++ + .. _multiple-processes: + + Logging to a single file from multiple processes +@@ -1590,6 +1717,13 @@ + 69 myapp.area2 WARNING Jail zesty vixen who grabbed pay from quack. + 69 myapp.area2 ERROR The five boxing wizards jump quickly. + ++Note that there are some security issues with pickle in some scenarios. If ++these affect you, you can use an alternative serialization scheme by overriding ++the :meth:`makePickle` method and implementing your alternative there, as ++well as adapting the above script to use your alternative serialization. ++ ++.. _arbitrary-object-messages: ++ + Using arbitrary objects as messages + ----------------------------------- + +@@ -1831,6 +1965,16 @@ + + This method does nothing. + ++ .. method:: handle(record) ++ ++ This method does nothing. ++ ++ .. method:: createLock() ++ ++ This method returns `None` for the lock, since there is no ++ underlying I/O to which access needs to be serialized. ++ ++ + See :ref:`library-config` for more information on how to use + :class:`NullHandler`. + +@@ -2400,7 +2544,7 @@ + + .. method:: emit(record) + +- Sends the record to the Web server as an URL-encoded dictionary. ++ Sends the record to the Web server as a percent-encoded dictionary. + + + .. _formatter: +@@ -2473,6 +2617,8 @@ + +-------------------------+-----------------------------------------------+ + | ``%(process)d`` | Process ID (if available). | + +-------------------------+-----------------------------------------------+ ++| ``%(processName)s`` | Process name (if available). | +++-------------------------+-----------------------------------------------+ + | ``%(message)s`` | The logged message, computed as ``msg % | + | | args``. | + +-------------------------+-----------------------------------------------+ +@@ -2484,12 +2630,11 @@ + .. class:: Formatter([fmt[, datefmt]]) + + Returns a new instance of the :class:`Formatter` class. The instance is +- initialized with a format string for the message as a whole, as well as a format +- string for the date/time portion of a message. If no *fmt* is specified, +- ``'%(message)s'`` is used. If no *datefmt* is specified, the ISO8601 date format +- is used. ++ initialized with a format string for the message as a whole, as well as a ++ format string for the date/time portion of a message. If no *fmt* is ++ specified, ``'%(message)s'`` is used. If no *datefmt* is specified, the ++ ISO8601 date format is used. + +- + .. method:: format(record) + + The record's attribute dictionary is used as the operand to a string +@@ -2532,7 +2677,7 @@ + Filter Objects + -------------- + +-Filters can be used by :class:`Handler`\ s and :class:`Logger`\ s for ++:class:`Filter`\ s can be used by :class:`Handler`\ s and :class:`Logger`\ s for + more sophisticated filtering than is provided by levels. The base filter class + only allows events which are below a certain point in the logger hierarchy. For + example, a filter initialized with "A.B" will allow events logged by loggers +@@ -2544,7 +2689,7 @@ + + Returns an instance of the :class:`Filter` class. If *name* is specified, it + names a logger which, together with its children, will have its events allowed +- through the filter. If no name is specified, allows every event. ++ through the filter. If *name* is the empty string, allows every event. + + + .. method:: filter(record) +@@ -2553,41 +2698,96 @@ + yes. If deemed appropriate, the record may be modified in-place by this + method. + ++Note that filters attached to handlers are consulted whenever an event is ++emitted by the handler, whereas filters attached to loggers are consulted ++whenever an event is logged to the handler (using :meth:`debug`, :meth:`info`, ++etc.) This means that events which have been generated by descendant loggers ++will not be filtered by a logger's filter setting, unless the filter has also ++been applied to those descendant loggers. ++ ++Other uses for filters ++^^^^^^^^^^^^^^^^^^^^^^ ++ ++Although filters are used primarily to filter records based on more ++sophisticated criteria than levels, they get to see every record which is ++processed by the handler or logger they're attached to: this can be useful if ++you want to do things like counting how many records were processed by a ++particular logger or handler, or adding, changing or removing attributes in ++the LogRecord being processed. Obviously changing the LogRecord needs to be ++done with some care, but it does allow the injection of contextual information ++into logs (see :ref:`filters-contextual`). ++ + .. _log-record: + + LogRecord Objects + ----------------- + +-:class:`LogRecord` instances are created every time something is logged. They +-contain all the information pertinent to the event being logged. The main +-information passed in is in msg and args, which are combined using msg % args to +-create the message field of the record. The record also includes information +-such as when the record was created, the source line where the logging call was +-made, and any exception information to be logged. ++:class:`LogRecord` instances are created automatically by the :class:`Logger` ++every time something is logged, and can be created manually via ++:func:`makeLogRecord` (for example, from a pickled event received over the ++wire). + + +-.. class:: LogRecord(name, lvl, pathname, lineno, msg, args, exc_info [, func]) ++.. class:: ++ LogRecord(name, lvl, pathname, lineno, msg, args, exc_info [, func=None]) + +- Returns an instance of :class:`LogRecord` initialized with interesting +- information. The *name* is the logger name; *lvl* is the numeric level; +- *pathname* is the absolute pathname of the source file in which the logging +- call was made; *lineno* is the line number in that file where the logging +- call is found; *msg* is the user-supplied message (a format string); *args* +- is the tuple which, together with *msg*, makes up the user message; and +- *exc_info* is the exception tuple obtained by calling :func:`sys.exc_info` +- (or :const:`None`, if no exception information is available). The *func* is +- the name of the function from which the logging call was made. If not +- specified, it defaults to ``None``. ++ Contains all the information pertinent to the event being logged. + +- .. versionchanged:: 2.5 +- *func* was added. ++ The primary information is passed in :attr:`msg` and :attr:`args`, which ++ are combined using ``msg % args`` to create the :attr:`message` field of the ++ record. + ++ .. attribute:: args + ++ Tuple of arguments to be used in formatting :attr:`msg`. ++ ++ .. attribute:: exc_info ++ ++ Exception tuple (à la `sys.exc_info`) or `None` if no exception ++ information is available. ++ ++ .. attribute:: func ++ ++ Name of the function of origin (i.e. in which the logging call was made). ++ ++ .. attribute:: lineno ++ ++ Line number in the source file of origin. ++ ++ .. attribute:: lvl ++ ++ Numeric logging level. ++ ++ .. attribute:: message ++ ++ Bound to the result of :meth:`getMessage` when ++ :meth:`Formatter.format(record)` is invoked. ++ ++ .. attribute:: msg ++ ++ User-supplied :ref:`format string` or arbitrary object ++ (see :ref:`arbitrary-object-messages`) used in :meth:`getMessage`. ++ ++ .. attribute:: name ++ ++ Name of the logger that emitted the record. ++ ++ .. attribute:: pathname ++ ++ Absolute pathname of the source file of origin. ++ + .. method:: getMessage() + + Returns the message for this :class:`LogRecord` instance after merging any +- user-supplied arguments with the message. ++ user-supplied arguments with the message. If the user-supplied message ++ argument to the logging call is not a string, :func:`str` is called on it to ++ convert it to a string. This allows use of user-defined classes as ++ messages, whose ``__str__`` method can return the actual format string to ++ be used. + ++ .. versionchanged:: 2.5 ++ *func* was added. ++ + .. _logger-adapter: + + LoggerAdapter Objects +--- a/Doc/library/2to3.rst ++++ b/Doc/library/2to3.rst +@@ -89,7 +89,7 @@ + Since some print statements can be parsed as function calls or statements, 2to3 + cannot always read files containing the print function. When 2to3 detects the + presence of the ``from __future__ import print_function`` compiler directive, it +-modifies its internal grammar to interpert :func:`print` as a function. This ++modifies its internal grammar to interpret :func:`print` as a function. This + change can also be enabled manually with the :option:`-p` flag. Use + :option:`-p` to run fixers on code that already has had its print statements + converted. +--- a/Doc/library/socket.rst ++++ b/Doc/library/socket.rst +@@ -798,7 +798,9 @@ + Shut down one or both halves of the connection. If *how* is :const:`SHUT_RD`, + further receives are disallowed. If *how* is :const:`SHUT_WR`, further sends + are disallowed. If *how* is :const:`SHUT_RDWR`, further sends and receives are +- disallowed. ++ disallowed. Depending on the platform, shutting down one half of the connection ++ can also close the opposite half (e.g. on Mac OS X, ``shutdown(SHUT_WR)`` does ++ not allow further reads on the other end of the connection). + + Note that there are no methods :meth:`read` or :meth:`write`; use + :meth:`~socket.recv` and :meth:`~socket.send` without *flags* argument instead. +--- a/Doc/library/cookielib.rst ++++ b/Doc/library/cookielib.rst +@@ -121,10 +121,6 @@ + HTTP cookie classes, principally useful for server-side code. The + :mod:`cookielib` and :mod:`Cookie` modules do not depend on each other. + +- http://wwwsearch.sourceforge.net/mechanize/ +- Extensions to this module, including a class for reading Microsoft Internet +- Explorer cookies on Windows. +- + http://wp.netscape.com/newsref/std/cookie_spec.html + The specification of the original Netscape cookie protocol. Though this is + still the dominant protocol, the 'Netscape cookie protocol' implemented by all +@@ -310,10 +306,8 @@ + FileCookieJar subclasses and co-operation with web browsers + ----------------------------------------------------------- + +-The following :class:`CookieJar` subclasses are provided for reading and writing +-. Further :class:`CookieJar` subclasses, including one that reads Microsoft +-Internet Explorer cookies, are available at +-http://wwwsearch.sourceforge.net/mechanize/ . ++The following :class:`CookieJar` subclasses are provided for reading and ++writing . + + .. class:: MozillaCookieJar(filename, delayload=None, policy=None) + +--- a/Doc/library/doctest.rst ++++ b/Doc/library/doctest.rst +@@ -972,18 +972,17 @@ + supplies many flexible ways to combine tests from multiple sources. So, in + Python 2.4, :mod:`doctest`'s :class:`Tester` class is deprecated, and + :mod:`doctest` provides two functions that can be used to create :mod:`unittest` +-test suites from modules and text files containing doctests. These test suites +-can then be run using :mod:`unittest` test runners:: ++test suites from modules and text files containing doctests. To integrate with ++:mod:`unittest` test discovery, include a :func:`load_tests` function in your ++test module:: + + import unittest + import doctest +- import my_module_with_doctests, and_another ++ import my_module_with_doctests + +- suite = unittest.TestSuite() +- for mod in my_module_with_doctests, and_another: +- suite.addTest(doctest.DocTestSuite(mod)) +- runner = unittest.TextTestRunner() +- runner.run(suite) ++ def load_tests(loader, tests, ignore): ++ tests.addTests(doctest.DocTestSuite(my_module_with_doctests)) ++ return test + + There are two main functions for creating :class:`unittest.TestSuite` instances + from text files and modules with doctests: +@@ -1769,7 +1768,7 @@ + + .. exception:: DocTestFailure(test, example, got) + +- An exception thrown by :class:`DocTestRunner` to signal that a doctest example's ++ An exception raised by :class:`DocTestRunner` to signal that a doctest example's + actual output did not match its expected output. The constructor arguments are + used to initialize the member variables of the same names. + +@@ -1793,9 +1792,9 @@ + + .. exception:: UnexpectedException(test, example, exc_info) + +- An exception thrown by :class:`DocTestRunner` to signal that a doctest example +- raised an unexpected exception. The constructor arguments are used to +- initialize the member variables of the same names. ++ An exception raised by :class:`DocTestRunner` to signal that a doctest ++ example raised an unexpected exception. The constructor arguments are used ++ to initialize the member variables of the same names. + + :exc:`UnexpectedException` defines the following member variables: + +--- a/Doc/library/smtplib.rst ++++ b/Doc/library/smtplib.rst +@@ -298,9 +298,9 @@ + and ESMTP options suppressed. + + This method will return normally if the mail is accepted for at least one +- recipient. Otherwise it will throw an exception. That is, if this method does +- not throw an exception, then someone should get your mail. If this method does +- not throw an exception, it returns a dictionary, with one entry for each ++ recipient. Otherwise it will raise an exception. That is, if this method does ++ not raise an exception, then someone should get your mail. If this method does ++ not raise an exception, it returns a dictionary, with one entry for each + recipient that was refused. Each entry contains a tuple of the SMTP error code + and the accompanying error message sent by the server. + +--- a/Doc/library/select.rst ++++ b/Doc/library/select.rst +@@ -44,7 +44,7 @@ + + .. function:: kqueue() + +- (Only supported on BSD.) Returns a kernel queue object object; see section ++ (Only supported on BSD.) Returns a kernel queue object; see section + :ref:`kqueue-objects` below for the methods supported by kqueue objects. + + .. versionadded:: 2.6 +@@ -52,8 +52,8 @@ + + .. function:: kevent(ident, filter=KQ_FILTER_READ, flags=KQ_EV_ADD, fflags=0, data=0, udata=0) + +- (Only supported on BSD.) Returns a kernel event object object; see section +- :ref:`kevent-objects` below for the methods supported by kqueue objects. ++ (Only supported on BSD.) Returns a kernel event object; see section ++ :ref:`kevent-objects` below for the methods supported by kevent objects. + + .. versionadded:: 2.6 + +@@ -138,15 +138,15 @@ + | :const:`EPOLLONESHOT` | Set one-shot behavior. After one event is | + | | pulled out, the fd is internally disabled | + +-----------------------+-----------------------------------------------+ +- | :const:`EPOLLRDNORM` | ??? | ++ | :const:`EPOLLRDNORM` | Equivalent to :const:`EPOLLIN` | + +-----------------------+-----------------------------------------------+ +- | :const:`EPOLLRDBAND` | ??? | ++ | :const:`EPOLLRDBAND` | Priority data band can be read. | + +-----------------------+-----------------------------------------------+ +- | :const:`EPOLLWRNORM` | ??? | ++ | :const:`EPOLLWRNORM` | Equivalent to :const:`EPOLLOUT` | + +-----------------------+-----------------------------------------------+ +- | :const:`EPOLLWRBAND` | ??? | ++ | :const:`EPOLLWRBAND` | Priority data may be written. | + +-----------------------+-----------------------------------------------+ +- | :const:`EPOLLMSG` | ??? | ++ | :const:`EPOLLMSG` | Ignored. | + +-----------------------+-----------------------------------------------+ + + +@@ -240,7 +240,7 @@ + .. method:: poll.modify(fd, eventmask) + + Modifies an already registered fd. This has the same effect as +- :meth:`register(fd, eventmask)`. Attempting to modify a file descriptor ++ ``register(fd, eventmask)``. Attempting to modify a file descriptor + that was never registered causes an :exc:`IOError` exception with errno + :const:`ENOENT` to be raised. + +--- a/Doc/library/urlparse.rst ++++ b/Doc/library/urlparse.rst +@@ -58,6 +58,24 @@ + >>> o.geturl() + 'http://www.cwi.nl:80/%7Eguido/Python.html' + ++ ++ If the scheme value is not specified, urlparse following the syntax ++ specifications from RFC 1808, expects the netloc value to start with '//', ++ Otherwise, it is not possible to distinguish between net_loc and path ++ component and would classify the indistinguishable component as path as in ++ a relative url. ++ ++ >>> from urlparse import urlparse ++ >>> urlparse('//www.cwi.nl:80/%7Eguido/Python.html') ++ ParseResult(scheme='', netloc='www.cwi.nl:80', path='/%7Eguido/Python.html', ++ params='', query='', fragment='') ++ >>> urlparse('www.cwi.nl:80/%7Eguido/Python.html') ++ ParseResult(scheme='', netloc='', path='www.cwi.nl:80/%7Eguido/Python.html', ++ params='', query='', fragment='') ++ >>> urlparse('help/Python.html') ++ ParseResult(scheme='', netloc='', path='help/Python.html', params='', ++ query='', fragment='') ++ + If the *scheme* argument is specified, it gives the default addressing + scheme, to be used only if the URL does not specify one. The default value for + this argument is the empty string. +@@ -113,7 +131,7 @@ + values are lists of values for each name. + + The optional argument *keep_blank_values* is a flag indicating whether blank +- values in URL encoded queries should be treated as blank strings. A true value ++ values in percent-encoded queries should be treated as blank strings. A true value + indicates that blanks should be retained as blank strings. The default false + value indicates that blank values are to be ignored and treated as if they were + not included. +@@ -136,7 +154,7 @@ + name, value pairs. + + The optional argument *keep_blank_values* is a flag indicating whether blank +- values in URL encoded queries should be treated as blank strings. A true value ++ values in percent-encoded queries should be treated as blank strings. A true value + indicates that blanks should be retained as blank strings. The default false + value indicates that blank values are to be ignored and treated as if they were + not included. +--- a/Doc/library/httplib.rst ++++ b/Doc/library/httplib.rst +@@ -73,10 +73,9 @@ + formatted file that contains your private key. *cert_file* is a PEM formatted + certificate chain file. + +- .. note:: ++ .. warning:: ++ This does not do any verification of the server's certificate. + +- This does not do any certificate verification. +- + .. versionadded:: 2.0 + + .. versionchanged:: 2.6 +@@ -526,7 +525,10 @@ + + .. versionadded:: 2.4 + ++.. method:: HTTPResponse.fileno() + ++ Returns the ``fileno`` of the underlying socket. ++ + .. attribute:: HTTPResponse.msg + + A :class:`mimetools.Message` instance containing the response headers. +--- a/Doc/library/json.rst ++++ b/Doc/library/json.rst +@@ -154,7 +154,7 @@ + + To use a custom :class:`JSONEncoder` subclass (e.g. one that overrides the + :meth:`default` method to serialize additional types), specify it with the +- *cls* kwarg. ++ *cls* kwarg; otherwise :class:`JSONEncoder` is used. + + + .. function:: dumps(obj[, skipkeys[, ensure_ascii[, check_circular[, allow_nan[, cls[, indent[, separators[, encoding[, default[, **kw]]]]]]]]]]) +@@ -209,8 +209,8 @@ + are encountered. + + To use a custom :class:`JSONDecoder` subclass, specify it with the ``cls`` +- kwarg. Additional keyword arguments will be passed to the constructor of the +- class. ++ kwarg; otherwise :class:`JSONDecoder` is used. Additional keyword arguments ++ will be passed to the constructor of the class. + + + .. function:: loads(s[, encoding[, cls[, object_hook[, parse_float[, parse_int[, parse_constant[, object_pairs_hook[, **kw]]]]]]]]) +@@ -296,7 +296,12 @@ + ``'false'``. This can be used to raise an exception if invalid JSON numbers + are encountered. + ++ If *strict* is ``False`` (``True`` is the default), then control characters ++ will be allowed inside strings. Control characters in this context are ++ those with character codes in the 0-31 range, including ``'\t'`` (tab), ++ ``'\n'``, ``'\r'`` and ``'\0'``. + ++ + .. method:: decode(s) + + Return the Python representation of *s* (a :class:`str` or +@@ -360,7 +365,7 @@ + encoders and decoders. Otherwise, it will be a :exc:`ValueError` to encode + such floats. + +- If *sort_keys* is ``True`` (the default), then the output of dictionaries ++ If *sort_keys* is ``True`` (default ``False``), then the output of dictionaries + will be sorted by key; this is useful for regression tests to ensure that + JSON serializations can be compared on a day-to-day basis. + +--- a/Doc/library/unittest.rst ++++ b/Doc/library/unittest.rst +@@ -634,7 +634,7 @@ + + .. function:: skipUnless(condition, reason) + +- Skip the decoratored test unless *condition* is true. ++ Skip the decorated test unless *condition* is true. + + .. function:: expectedFailure + +@@ -1523,8 +1523,8 @@ + + .. attribute:: expectedFailures + +- A list contaning 2-tuples of :class:`TestCase` instances and strings +- holding formatted tracebacks. Each tuple represents a expected failures ++ A list containing 2-tuples of :class:`TestCase` instances and strings ++ holding formatted tracebacks. Each tuple represents an expected failure + of the test case. + + .. attribute:: unexpectedSuccesses +--- a/Doc/library/sqlite3.rst ++++ b/Doc/library/sqlite3.rst +@@ -138,7 +138,7 @@ + first blank for the column name: the column name would simply be "x". + + +-.. function:: connect(database[, timeout, isolation_level, detect_types, factory]) ++.. function:: connect(database[, timeout, detect_types, isolation_level, check_same_thread, factory, cached_statements]) + + Opens a connection to the SQLite database file *database*. You can use + ``":memory:"`` to open a database connection to a database that resides in RAM +@@ -880,3 +880,18 @@ + committed: + + .. literalinclude:: ../includes/sqlite3/ctx_manager.py ++ ++ ++Common issues ++------------- ++ ++Multithreading ++^^^^^^^^^^^^^^ ++ ++Older SQLite versions had issues with sharing connections between threads. ++That's why the Python module disallows sharing connections and cursors between ++threads. If you still try to do so, you will get an exception at runtime. ++ ++The only exception is calling the :meth:`~Connection.interrupt` method, which ++only makes sense to call from a different thread. ++ +--- a/Doc/library/multiprocessing.rst ++++ b/Doc/library/multiprocessing.rst +@@ -376,7 +376,7 @@ + Otherwise a daemonic process would leave its children orphaned if it gets + terminated when its parent process exits. Additionally, these are **not** + Unix daemons or services, they are normal processes that will be +- terminated (and not joined) if non-dameonic processes have exited. ++ terminated (and not joined) if non-daemonic processes have exited. + + In addition to the :class:`Threading.Thread` API, :class:`Process` objects + also support the following attributes and methods: +@@ -2223,8 +2223,8 @@ + .. literalinclude:: ../includes/mp_synchronize.py + + +-An showing how to use queues to feed tasks to a collection of worker process and +-collect the results: ++An example showing how to use queues to feed tasks to a collection of worker ++process and collect the results: + + .. literalinclude:: ../includes/mp_workers.py + +--- a/Doc/library/importlib.rst ++++ b/Doc/library/importlib.rst +@@ -23,5 +23,5 @@ + specified in relative terms, then the *package* argument must be + specified to the package which is to act as the anchor for resolving the + package name (e.g. ``import_module('..mod', 'pkg.subpkg')`` will import +- ``pkg.mod``). The specified module will be inserted into ++ ``pkg.mod``). The specified module will be inserted into + :data:`sys.modules` and returned. +--- a/Doc/library/constants.rst ++++ b/Doc/library/constants.rst +@@ -3,7 +3,6 @@ + + A small number of constants live in the built-in namespace. They are: + +- + .. data:: False + + The false value of the :class:`bool` type. +@@ -39,16 +38,23 @@ + + Special value used in conjunction with extended slicing syntax. + +- .. XXX Someone who understands extended slicing should fill in here. + +- + .. data:: __debug__ + + This constant is true if Python was not started with an :option:`-O` option. +- Assignments to :const:`__debug__` are illegal and raise a :exc:`SyntaxError`. + See also the :keyword:`assert` statement. + + ++.. note:: ++ ++ The names :data:`None` and :data:`__debug__` cannot be reassigned ++ (assignments to them, even as an attribute name, raise :exc:`SyntaxError`), ++ so they can be considered "true" constants. ++ ++ .. versionchanged:: 2.7 ++ Assignments to ``__debug__`` as an attribute became illegal. ++ ++ + Constants added by the :mod:`site` module + ----------------------------------------- + +--- a/Doc/library/htmlparser.rst ++++ b/Doc/library/htmlparser.rst +@@ -148,12 +148,20 @@ + + .. method:: HTMLParser.handle_decl(decl) + +- Method called when an SGML declaration is read by the parser. The *decl* +- parameter will be the entire contents of the declaration inside the ```` markup. It is intended to be overridden by a derived class; the base +- class implementation does nothing. ++ Method called when an SGML ``doctype`` declaration is read by the parser. ++ The *decl* parameter will be the entire contents of the declaration inside ++ the ```` markup. It is intended to be overridden by a derived class; ++ the base class implementation does nothing. + + ++.. method:: HTMLParser.unknown_decl(data) ++ ++ Method called when an unrecognized SGML declaration is read by the parser. ++ The *data* parameter will be the entire contents of the declaration inside ++ the ```` markup. It is sometimes useful to be be overridden by a ++ derived class; the base class implementation throws an :exc:`HTMLParseError`. ++ ++ + .. method:: HTMLParser.handle_pi(data) + + Method called when a processing instruction is encountered. The *data* +--- a/Doc/library/optparse.rst ++++ b/Doc/library/optparse.rst +@@ -1216,7 +1216,7 @@ + :func:`float` and :func:`complex`, with similar error-handling. + + ``"choice"`` options are a subtype of ``"string"`` options. The +-:attr:`~Option.choices`` option attribute (a sequence of strings) defines the ++:attr:`~Option.choices` option attribute (a sequence of strings) defines the + set of allowed option arguments. :func:`optparse.check_choice` compares + user-supplied option arguments against this master list and raises + :exc:`OptionValueError` if an invalid string is given. +@@ -1238,8 +1238,9 @@ + the list of arguments to process (default: ``sys.argv[1:]``) + + ``values`` +- object to store option arguments in (default: a new instance of +- :class:`optparse.Values`) ++ a :class:`optparse.Values` object to store option arguments in (default: a ++ new instance of :class:`Values`) -- if you give an existing object, the ++ option defaults will not be initialized on it + + and the return values are + +--- a/Doc/library/dis.rst ++++ b/Doc/library/dis.rst +@@ -6,12 +6,18 @@ + :synopsis: Disassembler for Python bytecode. + + +-The :mod:`dis` module supports the analysis of Python :term:`bytecode` by disassembling +-it. Since there is no Python assembler, this module defines the Python assembly +-language. The Python bytecode which this module takes as an input is defined +-in the file :file:`Include/opcode.h` and used by the compiler and the +-interpreter. ++The :mod:`dis` module supports the analysis of CPython :term:`bytecode` by ++disassembling it. The CPython bytecode which this module takes as an ++input is defined in the file :file:`Include/opcode.h` and used by the compiler ++and the interpreter. + ++.. impl-detail:: ++ ++ Bytecode is an implementation detail of the CPython interpreter! No ++ guarantees are made that bytecode will not be added, removed, or changed ++ between versions of Python. Use of this module should not be considered to ++ work across Python VMs or Python releases. ++ + Example: Given the function :func:`myfunc`:: + + def myfunc(alist): +--- a/Doc/library/struct.rst ++++ b/Doc/library/struct.rst +@@ -263,14 +263,14 @@ + string (while ``'0c'`` means 0 characters). + + The ``'p'`` format character encodes a "Pascal string", meaning a short +-variable-length string stored in a fixed number of bytes. The count is the total +-number of bytes stored. The first byte stored is the length of the string, or +-255, whichever is smaller. The bytes of the string follow. If the string +-passed in to :func:`pack` is too long (longer than the count minus 1), only the +-leading count-1 bytes of the string are stored. If the string is shorter than +-count-1, it is padded with null bytes so that exactly count bytes in all are +-used. Note that for :func:`unpack`, the ``'p'`` format character consumes count +-bytes, but that the string returned can never contain more than 255 characters. ++variable-length string stored in a *fixed number of bytes*, given by the count. ++The first byte stored is the length of the string, or 255, whichever is smaller. ++The bytes of the string follow. If the string passed in to :func:`pack` is too ++long (longer than the count minus 1), only the leading ``count-1`` bytes of the ++string are stored. If the string is shorter than ``count-1``, it is padded with ++null bytes so that exactly count bytes in all are used. Note that for ++:func:`unpack`, the ``'p'`` format character consumes count bytes, but that the ++string returned can never contain more than 255 characters. + + For the ``'P'`` format character, the return value is a Python integer or long + integer, depending on the size needed to hold a pointer when it has been cast to +--- a/Doc/library/mmap.rst ++++ b/Doc/library/mmap.rst +@@ -173,7 +173,7 @@ + + Copy the *count* bytes starting at offset *src* to the destination index + *dest*. If the mmap was created with :const:`ACCESS_READ`, then calls to +- move will throw a :exc:`TypeError` exception. ++ move will raise a :exc:`TypeError` exception. + + + .. method:: read(num) +@@ -199,7 +199,7 @@ + + Resizes the map and the underlying file, if any. If the mmap was created + with :const:`ACCESS_READ` or :const:`ACCESS_COPY`, resizing the map will +- throw a :exc:`TypeError` exception. ++ raise a :exc:`TypeError` exception. + + + .. method:: rfind(string[, start[, end]]) +@@ -234,7 +234,7 @@ + Write the bytes in *string* into memory at the current position of the + file pointer; the file position is updated to point after the bytes that + were written. If the mmap was created with :const:`ACCESS_READ`, then +- writing to it will throw a :exc:`TypeError` exception. ++ writing to it will raise a :exc:`TypeError` exception. + + + .. method:: write_byte(byte) +@@ -242,6 +242,4 @@ + Write the single-character string *byte* into memory at the current + position of the file pointer; the file position is advanced by ``1``. If + the mmap was created with :const:`ACCESS_READ`, then writing to it will +- throw a :exc:`TypeError` exception. +- +- ++ raise a :exc:`TypeError` exception. +--- a/Doc/library/email.errors.rst ++++ b/Doc/library/email.errors.rst +@@ -17,7 +17,7 @@ + + .. exception:: MessageParseError() + +- This is the base class for exceptions thrown by the :class:`~email.parser.Parser` ++ This is the base class for exceptions raised by the :class:`~email.parser.Parser` + class. It is derived from :exc:`MessageError`. + + +--- a/Doc/library/telnetlib.rst ++++ b/Doc/library/telnetlib.rst +@@ -198,8 +198,8 @@ + received so far (may be the empty string if a timeout happened). + + If a regular expression ends with a greedy match (such as ``.*``) or if more +- than one expression can match the same input, the results are indeterministic, +- and may depend on the I/O timing. ++ than one expression can match the same input, the results are ++ non-deterministic, and may depend on the I/O timing. + + + .. method:: Telnet.set_option_negotiation_callback(callback) +--- a/Doc/library/xml.sax.reader.rst ++++ b/Doc/library/xml.sax.reader.rst +@@ -157,7 +157,7 @@ + Allow an application to set the locale for errors and warnings. + + SAX parsers are not required to provide localization for errors and warnings; if +- they cannot support the requested locale, however, they must throw a SAX ++ they cannot support the requested locale, however, they must raise a SAX + exception. Applications may request a locale change in the middle of a parse. + + +--- a/Doc/library/zipfile.rst ++++ b/Doc/library/zipfile.rst +@@ -15,10 +15,8 @@ + defined in `PKZIP Application Note + `_. + +-This module does not currently handle multi-disk ZIP files, or ZIP files +-which have appended comments (although it correctly handles comments +-added to individual archive members---for which see the :ref:`zipinfo-objects` +-documentation). It can handle ZIP files that use the ZIP64 extensions ++This module does not currently handle multi-disk ZIP files. ++It can handle ZIP files that use the ZIP64 extensions + (that is ZIP files that are more than 4 GByte in size). It supports + decryption of encrypted files in ZIP archives, but it currently cannot + create an encrypted file. Decryption is extremely slow as it is +@@ -67,7 +65,6 @@ + + Returns ``True`` if *filename* is a valid ZIP file based on its magic number, + otherwise returns ``False``. *filename* may be a file or file-like object too. +- This module does not currently handle ZIP files which have appended comments. + + .. versionchanged:: 2.7 + Support for file and file-like objects. +--- a/Doc/library/cmd.rst ++++ b/Doc/library/cmd.rst +@@ -80,11 +80,13 @@ + are the beginning and ending indexes of the prefix text, which could be used to + provide different completion depending upon which position the argument is in. + +- All subclasses of :class:`Cmd` inherit a predefined :meth:`do_help`. This ++ All subclasses of :class:`Cmd` inherit a predefined :meth:`do_help`. This + method, called with an argument ``'bar'``, invokes the corresponding method +- :meth:`help_bar`. With no argument, :meth:`do_help` lists all available help +- topics (that is, all commands with corresponding :meth:`help_\*` methods), and +- also lists any undocumented commands. ++ :meth:`help_bar`, and if that is not present, prints the docstring of ++ :meth:`do_bar`, if available. With no argument, :meth:`do_help` lists all ++ available help topics (that is, all commands with corresponding ++ :meth:`help_\*` methods or commands that have docstrings), and also lists any ++ undocumented commands. + + + .. method:: Cmd.onecmd(str) +--- a/Doc/library/wsgiref.rst ++++ b/Doc/library/wsgiref.rst +@@ -712,7 +712,7 @@ + # use a function (note that you're not limited to a function, you can + # use a class for example). The first argument passed to the function + # is a dictionary containing CGI-style envrironment variables and the +- # second variable is the callable object (see :pep:`333`) ++ # second variable is the callable object (see PEP 333). + def hello_world_app(environ, start_response): + status = '200 OK' # HTTP Status + headers = [('Content-type', 'text/plain')] # HTTP Headers +--- a/Doc/library/stdtypes.rst ++++ b/Doc/library/stdtypes.rst +@@ -224,19 +224,21 @@ + pair: C; language + + There are four distinct numeric types: :dfn:`plain integers`, :dfn:`long +-integers`, :dfn:`floating point numbers`, and :dfn:`complex numbers`. In ++integers`, :dfn:`floating point numbers`, and :dfn:`complex numbers`. In + addition, Booleans are a subtype of plain integers. Plain integers (also just + called :dfn:`integers`) are implemented using :ctype:`long` in C, which gives + them at least 32 bits of precision (``sys.maxint`` is always set to the maximum + plain integer value for the current platform, the minimum value is +-``-sys.maxint - 1``). Long integers have unlimited precision. Floating point +-numbers are implemented using :ctype:`double` in C. All bets on their precision +-are off unless you happen to know the machine you are working with. ++``-sys.maxint - 1``). Long integers have unlimited precision. Floating point ++numbers are usually implemented using :ctype:`double` in C; information about ++the precision and internal representation of floating point numbers for the ++machine on which your program is running is available in ++:data:`sys.float_info`. Complex numbers have a real and imaginary part, which ++are each a floating point number. To extract these parts from a complex number ++*z*, use ``z.real`` and ``z.imag``. (The standard library includes additional ++numeric types, :mod:`fractions` that hold rationals, and :mod:`decimal` that ++hold floating-point numbers with user-definable precision.) + +-Complex numbers have a real and imaginary part, which are each implemented using +-:ctype:`double` in C. To extract these parts from a complex number *z*, use +-``z.real`` and ``z.imag``. +- + .. index:: + pair: numeric; literals + pair: integer; literals +@@ -830,7 +832,8 @@ + + .. method:: str.capitalize() + +- Return a copy of the string with only its first character capitalized. ++ Return a copy of the string with its first character capitalized and the ++ rest lowercased. + + For 8-bit strings, this method is locale-dependent. + +@@ -1496,6 +1499,23 @@ + such objects cannot be modified once created. The following operations are + defined on mutable sequence types (where *x* is an arbitrary object): + ++.. index:: ++ triple: operations on; sequence; types ++ triple: operations on; list; type ++ pair: subscript; assignment ++ pair: slice; assignment ++ pair: extended slice; assignment ++ statement: del ++ single: append() (list method) ++ single: extend() (list method) ++ single: count() (list method) ++ single: index() (list method) ++ single: insert() (list method) ++ single: pop() (list method) ++ single: remove() (list method) ++ single: reverse() (list method) ++ single: sort() (list method) ++ + +------------------------------+--------------------------------+---------------------+ + | Operation | Result | Notes | + +==============================+================================+=====================+ +@@ -1541,23 +1561,6 @@ + | reverse]]])`` | | | + +------------------------------+--------------------------------+---------------------+ + +-.. index:: +- triple: operations on; sequence; types +- triple: operations on; list; type +- pair: subscript; assignment +- pair: slice; assignment +- pair: extended slice; assignment +- statement: del +- single: append() (list method) +- single: extend() (list method) +- single: count() (list method) +- single: index() (list method) +- single: insert() (list method) +- single: pop() (list method) +- single: remove() (list method) +- single: reverse() (list method) +- single: sort() (list method) +- + Notes: + + (1) +@@ -2098,7 +2101,7 @@ + existing keys. Return ``None``. + + :func:`update` accepts either another dictionary object or an iterable of +- key/value pairs (as a tuple or other iterable of length two). If keyword ++ key/value pairs (as tuples or other iterables of length two). If keyword + arguments are specified, the dictionary is then updated with those + key/value pairs: ``d.update(red=1, blue=2)``. + +@@ -2543,6 +2546,8 @@ + memoryview type + =============== + ++.. versionadded:: 2.7 ++ + :class:`memoryview` objects allow Python code to access the internal data + of an object that supports the buffer protocol without copying. Memory + is generally interpreted as simple bytes. +@@ -2553,10 +2558,18 @@ + buffer protocol. Builtin objects that support the buffer protocol include + :class:`str` and :class:`bytearray` (but not :class:`unicode`). + +- ``len(view)`` returns the total number of bytes in the memoryview, *view*. ++ A :class:`memoryview` has the notion of an *element*, which is the ++ atomic memory unit handled by the originating object *obj*. For many ++ simple types such as :class:`str` and :class:`bytearray`, an element ++ is a single byte, but other third-party types may expose larger elements. + ++ ``len(view)`` returns the total number of elements in the memoryview, ++ *view*. The :class:`~memoryview.itemsize` attribute will give you the ++ number of bytes in a single element. ++ + A :class:`memoryview` supports slicing to expose its data. Taking a single +- index will return a single byte. Full slicing will result in a subview:: ++ index will return a single element as a :class:`str` object. Full ++ slicing will result in a subview:: + + >>> v = memoryview('abcefg') + >>> v[1] +@@ -2565,14 +2578,10 @@ + 'g' + >>> v[1:4] + +- >>> str(v[1:4]) ++ >>> v[1:4].tobytes() + 'bce' +- >>> v[3:-1] +- +- >>> str(v[4:-1]) +- 'f' + +- If the object the memory view is over supports changing its data, the ++ If the object the memoryview is over supports changing its data, the + memoryview supports slice assignment:: + + >>> data = bytearray('abcefg') +@@ -2592,19 +2601,22 @@ + + Notice how the size of the memoryview object cannot be changed. + +- + :class:`memoryview` has two methods: + + .. method:: tobytes() + + Return the data in the buffer as a bytestring (an object of class +- :class:`str`). ++ :class:`str`). :: + ++ >>> m = memoryview("abc") ++ >>> m.tobytes() ++ 'abc' ++ + .. method:: tolist() + + Return the data in the buffer as a list of integers. :: + +- >>> memoryview(b'abc').tolist() ++ >>> memoryview("abc").tolist() + [97, 98, 99] + + There are also several readonly attributes available: +--- a/Doc/library/parser.rst ++++ b/Doc/library/parser.rst +@@ -121,7 +121,7 @@ + The :func:`expr` function parses the parameter *source* as if it were an input + to ``compile(source, 'file.py', 'eval')``. If the parse succeeds, an ST object + is created to hold the internal parse tree representation, otherwise an +- appropriate exception is thrown. ++ appropriate exception is raised. + + + .. function:: suite(source) +@@ -129,7 +129,7 @@ + The :func:`suite` function parses the parameter *source* as if it were an input + to ``compile(source, 'file.py', 'exec')``. If the parse succeeds, an ST object + is created to hold the internal parse tree representation, otherwise an +- appropriate exception is thrown. ++ appropriate exception is raised. + + + .. function:: sequence2st(sequence) +@@ -139,9 +139,9 @@ + to the Python grammar and all nodes are valid node types in the host version of + Python, an ST object is created from the internal representation and returned + to the called. If there is a problem creating the internal representation, or +- if the tree cannot be validated, a :exc:`ParserError` exception is thrown. An ++ if the tree cannot be validated, a :exc:`ParserError` exception is raised. An + ST object created this way should not be assumed to compile correctly; normal +- exceptions thrown by compilation may still be initiated when the ST object is ++ exceptions raised by compilation may still be initiated when the ST object is + passed to :func:`compilest`. This may indicate problems not related to syntax + (such as a :exc:`MemoryError` exception), but may also be due to constructs such + as the result of parsing ``del f(0)``, which escapes the Python parser but is +@@ -264,8 +264,8 @@ + .. exception:: ParserError + + Exception raised when a failure occurs within the parser module. This is +- generally produced for validation failures rather than the built in +- :exc:`SyntaxError` thrown during normal parsing. The exception argument is ++ generally produced for validation failures rather than the built-in ++ :exc:`SyntaxError` raised during normal parsing. The exception argument is + either a string describing the reason of the failure or a tuple containing a + sequence causing the failure from a parse tree passed to :func:`sequence2st` + and an explanatory string. Calls to :func:`sequence2st` need to be able to +@@ -273,7 +273,7 @@ + will only need to be aware of the simple string values. + + Note that the functions :func:`compilest`, :func:`expr`, and :func:`suite` may +-throw exceptions which are normally thrown by the parsing and compilation ++raise exceptions which are normally thrown by the parsing and compilation + process. These include the built in exceptions :exc:`MemoryError`, + :exc:`OverflowError`, :exc:`SyntaxError`, and :exc:`SystemError`. In these + cases, these exceptions carry all the meaning normally associated with them. +--- a/Doc/library/heapq.rst ++++ b/Doc/library/heapq.rst +@@ -6,6 +6,7 @@ + .. moduleauthor:: Kevin O'Connor + .. sectionauthor:: Guido van Rossum + .. sectionauthor:: François Pinard ++.. sectionauthor:: Raymond Hettinger + + .. versionadded:: 2.3 + +@@ -62,47 +63,18 @@ + + Pop and return the smallest item from the *heap*, and also push the new *item*. + The heap size doesn't change. If the heap is empty, :exc:`IndexError` is raised. +- This is more efficient than :func:`heappop` followed by :func:`heappush`, and +- can be more appropriate when using a fixed-size heap. Note that the value +- returned may be larger than *item*! That constrains reasonable uses of this +- routine unless written as part of a conditional replacement:: + +- if item > heap[0]: +- item = heapreplace(heap, item) ++ This one step operation is more efficient than a :func:`heappop` followed by ++ :func:`heappush` and can be more appropriate when using a fixed-size heap. ++ The pop/push combination always returns an element from the heap and replaces ++ it with *item*. + +-Example of use: ++ The value returned may be larger than the *item* added. If that isn't ++ desired, consider using :func:`heappushpop` instead. Its push/pop ++ combination returns the smaller of the two values, leaving the larger value ++ on the heap. + +- >>> from heapq import heappush, heappop +- >>> heap = [] +- >>> data = [1, 3, 5, 7, 9, 2, 4, 6, 8, 0] +- >>> for item in data: +- ... heappush(heap, item) +- ... +- >>> ordered = [] +- >>> while heap: +- ... ordered.append(heappop(heap)) +- ... +- >>> print ordered +- [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] +- >>> data.sort() +- >>> print data == ordered +- True + +-Using a heap to insert items at the correct place in a priority queue: +- +- >>> heap = [] +- >>> data = [(1, 'J'), (4, 'N'), (3, 'H'), (2, 'O')] +- >>> for item in data: +- ... heappush(heap, item) +- ... +- >>> while heap: +- ... print heappop(heap)[1] +- J +- O +- H +- N +- +- + The module also offers three general purpose functions based on heaps. + + +@@ -151,12 +123,100 @@ + functions. + + ++Basic Examples ++-------------- ++ ++A `heapsort `_ can be implemented by ++pushing all values onto a heap and then popping off the smallest values one at a ++time:: ++ ++ >>> def heapsort(iterable): ++ ... 'Equivalent to sorted(iterable)' ++ ... h = [] ++ ... for value in iterable: ++ ... heappush(h, value) ++ ... return [heappop(h) for i in range(len(h))] ++ ... ++ >>> heapsort([1, 3, 5, 7, 9, 2, 4, 6, 8, 0]) ++ [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] ++ ++Heap elements can be tuples. This is useful for assigning comparison values ++(such as task priorities) alongside the main record being tracked:: ++ ++ >>> h = [] ++ >>> heappush(h, (5, 'write code')) ++ >>> heappush(h, (7, 'release product')) ++ >>> heappush(h, (1, 'write spec')) ++ >>> heappush(h, (3, 'create tests')) ++ >>> heappop(h) ++ (1, 'write spec') ++ ++ ++Priority Queue Implementation Notes ++----------------------------------- ++ ++A `priority queue `_ is common use ++for a heap, and it presents several implementation challenges: ++ ++* Sort stability: how do you get two tasks with equal priorities to be returned ++ in the order they were originally added? ++ ++* In the future with Python 3, tuple comparison breaks for (priority, task) ++ pairs if the priorities are equal and the tasks do not have a default ++ comparison order. ++ ++* If the priority of a task changes, how do you move it to a new position in ++ the heap? ++ ++* Or if a pending task needs to be deleted, how do you find it and remove it ++ from the queue? ++ ++A solution to the first two challenges is to store entries as 3-element list ++including the priority, an entry count, and the task. The entry count serves as ++a tie-breaker so that two tasks with the same priority are returned in the order ++they were added. And since no two entry counts are the same, the tuple ++comparison will never attempt to directly compare two tasks. ++ ++The remaining challenges revolve around finding a pending task and making ++changes to its priority or removing it entirely. Finding a task can be done ++with a dictionary pointing to an entry in the queue. ++ ++Removing the entry or changing its priority is more difficult because it would ++break the heap structure invariants. So, a possible solution is to mark an ++entry as invalid and optionally add a new entry with the revised priority:: ++ ++ pq = [] # the priority queue list ++ counter = itertools.count(1) # unique sequence count ++ task_finder = {} # mapping of tasks to entries ++ INVALID = 0 # mark an entry as deleted ++ ++ def add_task(priority, task, count=None): ++ if count is None: ++ count = next(counter) ++ entry = [priority, count, task] ++ task_finder[task] = entry ++ heappush(pq, entry) ++ ++ def get_top_priority(): ++ while True: ++ priority, count, task = heappop(pq) ++ del task_finder[task] ++ if count is not INVALID: ++ return task ++ ++ def delete_task(task): ++ entry = task_finder[task] ++ entry[1] = INVALID ++ ++ def reprioritize(priority, task): ++ entry = task_finder[task] ++ add_task(priority, task, entry[1]) ++ entry[1] = INVALID ++ ++ + Theory + ------ + +-(This explanation is due to François Pinard. The Python code for this module +-was contributed by Kevin O'Connor.) +- + Heaps are arrays for which ``a[k] <= a[2*k+1]`` and ``a[k] <= a[2*k+2]`` for all + *k*, counting elements from 0. For the sake of comparison, non-existing + elements are considered to be infinite. The interesting property of a heap is +--- a/Doc/library/collections.rst ++++ b/Doc/library/collections.rst +@@ -15,13 +15,17 @@ + import itertools + __name__ = '' + +-This module implements high-performance container datatypes. Currently, +-there are four datatypes, :class:`Counter`, :class:`deque`, :class:`OrderedDict` and +-:class:`defaultdict`, and one datatype factory function, :func:`namedtuple`. ++This module implements specialized container datatypes providing alternatives to ++Python's general purpose built-in containers, :class:`dict`, :class:`list`, ++:class:`set`, and :class:`tuple`. + +-The specialized containers provided in this module provide alternatives +-to Python's general purpose built-in containers, :class:`dict`, +-:class:`list`, :class:`set`, and :class:`tuple`. ++===================== ==================================================================== ++:func:`namedtuple` factory function for creating tuple subclasses with named fields ++:class:`deque` list-like container with fast appends and pops on either end ++:class:`Counter` dict subclass for counting hashable objects ++:class:`OrderedDict` dict subclass that remembers the order entries were added ++:class:`defaultdict` dict subclass that calls a factory function to supply missing values ++===================== ==================================================================== + + .. versionchanged:: 2.4 + Added :class:`deque`. +@@ -41,120 +45,6 @@ + a mapping. + + +-ABCs - abstract base classes +----------------------------- +- +-The collections module offers the following ABCs: +- +-========================= ===================== ====================== ==================================================== +-ABC Inherits Abstract Methods Mixin Methods +-========================= ===================== ====================== ==================================================== +-:class:`Container` ``__contains__`` +-:class:`Hashable` ``__hash__`` +-:class:`Iterable` ``__iter__`` +-:class:`Iterator` :class:`Iterable` ``next`` ``__iter__`` +-:class:`Sized` ``__len__`` +-:class:`Callable` ``__call__`` +- +-:class:`Sequence` :class:`Sized`, ``__getitem__`` ``__contains__``. ``__iter__``, ``__reversed__``. +- :class:`Iterable`, ``index``, and ``count`` +- :class:`Container` +- +-:class:`MutableSequence` :class:`Sequence` ``__setitem__`` Inherited Sequence methods and +- ``__delitem__``, ``append``, ``reverse``, ``extend``, ``pop``, +- and ``insert`` ``remove``, and ``__iadd__`` +- +-:class:`Set` :class:`Sized`, ``__le__``, ``__lt__``, ``__eq__``, ``__ne__``, +- :class:`Iterable`, ``__gt__``, ``__ge__``, ``__and__``, ``__or__`` +- :class:`Container` ``__sub__``, ``__xor__``, and ``isdisjoint`` +- +-:class:`MutableSet` :class:`Set` ``add`` and Inherited Set methods and +- ``discard`` ``clear``, ``pop``, ``remove``, ``__ior__``, +- ``__iand__``, ``__ixor__``, and ``__isub__`` +- +-:class:`Mapping` :class:`Sized`, ``__getitem__`` ``__contains__``, ``keys``, ``items``, ``values``, +- :class:`Iterable`, ``get``, ``__eq__``, and ``__ne__`` +- :class:`Container` +- +-:class:`MutableMapping` :class:`Mapping` ``__setitem__`` and Inherited Mapping methods and +- ``__delitem__`` ``pop``, ``popitem``, ``clear``, ``update``, +- and ``setdefault`` +- +- +-:class:`MappingView` :class:`Sized` ``__len__`` +-:class:`KeysView` :class:`MappingView`, ``__contains__``, +- :class:`Set` ``__iter__`` +-:class:`ItemsView` :class:`MappingView`, ``__contains__``, +- :class:`Set` ``__iter__`` +-:class:`ValuesView` :class:`MappingView` ``__contains__``, ``__iter__`` +-========================= ===================== ====================== ==================================================== +- +-These ABCs allow us to ask classes or instances if they provide +-particular functionality, for example:: +- +- size = None +- if isinstance(myvar, collections.Sized): +- size = len(myvar) +- +-Several of the ABCs are also useful as mixins that make it easier to develop +-classes supporting container APIs. For example, to write a class supporting +-the full :class:`Set` API, it only necessary to supply the three underlying +-abstract methods: :meth:`__contains__`, :meth:`__iter__`, and :meth:`__len__`. +-The ABC supplies the remaining methods such as :meth:`__and__` and +-:meth:`isdisjoint` :: +- +- class ListBasedSet(collections.Set): +- ''' Alternate set implementation favoring space over speed +- and not requiring the set elements to be hashable. ''' +- def __init__(self, iterable): +- self.elements = lst = [] +- for value in iterable: +- if value not in lst: +- lst.append(value) +- def __iter__(self): +- return iter(self.elements) +- def __contains__(self, value): +- return value in self.elements +- def __len__(self): +- return len(self.elements) +- +- s1 = ListBasedSet('abcdef') +- s2 = ListBasedSet('defghi') +- overlap = s1 & s2 # The __and__() method is supported automatically +- +-Notes on using :class:`Set` and :class:`MutableSet` as a mixin: +- +-(1) +- Since some set operations create new sets, the default mixin methods need +- a way to create new instances from an iterable. The class constructor is +- assumed to have a signature in the form ``ClassName(iterable)``. +- That assumption is factored-out to an internal classmethod called +- :meth:`_from_iterable` which calls ``cls(iterable)`` to produce a new set. +- If the :class:`Set` mixin is being used in a class with a different +- constructor signature, you will need to override :meth:`from_iterable` +- with a classmethod that can construct new instances from +- an iterable argument. +- +-(2) +- To override the comparisons (presumably for speed, as the +- semantics are fixed), redefine :meth:`__le__` and +- then the other operations will automatically follow suit. +- +-(3) +- The :class:`Set` mixin provides a :meth:`_hash` method to compute a hash value +- for the set; however, :meth:`__hash__` is not defined because not all sets +- are hashable or immutable. To add set hashabilty using mixins, +- inherit from both :meth:`Set` and :meth:`Hashable`, then define +- ``__hash__ = Set._hash``. +- +-.. seealso:: +- +- * `OrderedSet recipe `_ for an +- example built on :class:`MutableSet`. +- +- * For more about ABCs, see the :mod:`abc` module and :pep:`3119`. +- +- + :class:`Counter` objects + ------------------------ + +@@ -787,7 +677,7 @@ + three additional methods and one attribute. To prevent conflicts with + field names, the method and attribute names start with an underscore. + +-.. method:: somenamedtuple._make(iterable) ++.. classmethod:: somenamedtuple._make(iterable) + + Class method that makes a new instance from an existing sequence or iterable. + +@@ -958,3 +848,129 @@ + The new sorted dictionaries maintain their sort order when entries + are deleted. But when new keys are added, the keys are appended + to the end and the sort is not maintained. ++ ++It is also straight-forward to create an ordered dictionary variant ++that the remembers the order the keys were *last* inserted. ++If a new entry overwrites an existing entry, the ++original insertion position is changed and moved to the end:: ++ ++ class LastUpdatedOrderedDict(OrderedDict): ++ 'Store items is the order the keys were last added' ++ def __setitem__(self, key, value): ++ if key in self: ++ del self[key] ++ OrderedDict.__setitem__(self, key, value) ++ ++ ++ABCs - abstract base classes ++---------------------------- ++ ++The collections module offers the following ABCs: ++ ++========================= ===================== ====================== ==================================================== ++ABC Inherits Abstract Methods Mixin Methods ++========================= ===================== ====================== ==================================================== ++:class:`Container` ``__contains__`` ++:class:`Hashable` ``__hash__`` ++:class:`Iterable` ``__iter__`` ++:class:`Iterator` :class:`Iterable` ``next`` ``__iter__`` ++:class:`Sized` ``__len__`` ++:class:`Callable` ``__call__`` ++ ++:class:`Sequence` :class:`Sized`, ``__getitem__`` ``__contains__``. ``__iter__``, ``__reversed__``. ++ :class:`Iterable`, ``index``, and ``count`` ++ :class:`Container` ++ ++:class:`MutableSequence` :class:`Sequence` ``__setitem__`` Inherited Sequence methods and ++ ``__delitem__``, ``append``, ``reverse``, ``extend``, ``pop``, ++ and ``insert`` ``remove``, and ``__iadd__`` ++ ++:class:`Set` :class:`Sized`, ``__le__``, ``__lt__``, ``__eq__``, ``__ne__``, ++ :class:`Iterable`, ``__gt__``, ``__ge__``, ``__and__``, ``__or__`` ++ :class:`Container` ``__sub__``, ``__xor__``, and ``isdisjoint`` ++ ++:class:`MutableSet` :class:`Set` ``add`` and Inherited Set methods and ++ ``discard`` ``clear``, ``pop``, ``remove``, ``__ior__``, ++ ``__iand__``, ``__ixor__``, and ``__isub__`` ++ ++:class:`Mapping` :class:`Sized`, ``__getitem__`` ``__contains__``, ``keys``, ``items``, ``values``, ++ :class:`Iterable`, ``get``, ``__eq__``, and ``__ne__`` ++ :class:`Container` ++ ++:class:`MutableMapping` :class:`Mapping` ``__setitem__`` and Inherited Mapping methods and ++ ``__delitem__`` ``pop``, ``popitem``, ``clear``, ``update``, ++ and ``setdefault`` ++ ++ ++:class:`MappingView` :class:`Sized` ``__len__`` ++:class:`KeysView` :class:`MappingView`, ``__contains__``, ++ :class:`Set` ``__iter__`` ++:class:`ItemsView` :class:`MappingView`, ``__contains__``, ++ :class:`Set` ``__iter__`` ++:class:`ValuesView` :class:`MappingView` ``__contains__``, ``__iter__`` ++========================= ===================== ====================== ==================================================== ++ ++These ABCs allow us to ask classes or instances if they provide ++particular functionality, for example:: ++ ++ size = None ++ if isinstance(myvar, collections.Sized): ++ size = len(myvar) ++ ++Several of the ABCs are also useful as mixins that make it easier to develop ++classes supporting container APIs. For example, to write a class supporting ++the full :class:`Set` API, it only necessary to supply the three underlying ++abstract methods: :meth:`__contains__`, :meth:`__iter__`, and :meth:`__len__`. ++The ABC supplies the remaining methods such as :meth:`__and__` and ++:meth:`isdisjoint` :: ++ ++ class ListBasedSet(collections.Set): ++ ''' Alternate set implementation favoring space over speed ++ and not requiring the set elements to be hashable. ''' ++ def __init__(self, iterable): ++ self.elements = lst = [] ++ for value in iterable: ++ if value not in lst: ++ lst.append(value) ++ def __iter__(self): ++ return iter(self.elements) ++ def __contains__(self, value): ++ return value in self.elements ++ def __len__(self): ++ return len(self.elements) ++ ++ s1 = ListBasedSet('abcdef') ++ s2 = ListBasedSet('defghi') ++ overlap = s1 & s2 # The __and__() method is supported automatically ++ ++Notes on using :class:`Set` and :class:`MutableSet` as a mixin: ++ ++(1) ++ Since some set operations create new sets, the default mixin methods need ++ a way to create new instances from an iterable. The class constructor is ++ assumed to have a signature in the form ``ClassName(iterable)``. ++ That assumption is factored-out to an internal classmethod called ++ :meth:`_from_iterable` which calls ``cls(iterable)`` to produce a new set. ++ If the :class:`Set` mixin is being used in a class with a different ++ constructor signature, you will need to override :meth:`from_iterable` ++ with a classmethod that can construct new instances from ++ an iterable argument. ++ ++(2) ++ To override the comparisons (presumably for speed, as the ++ semantics are fixed), redefine :meth:`__le__` and ++ then the other operations will automatically follow suit. ++ ++(3) ++ The :class:`Set` mixin provides a :meth:`_hash` method to compute a hash value ++ for the set; however, :meth:`__hash__` is not defined because not all sets ++ are hashable or immutable. To add set hashabilty using mixins, ++ inherit from both :meth:`Set` and :meth:`Hashable`, then define ++ ``__hash__ = Set._hash``. ++ ++.. seealso:: ++ ++ * `OrderedSet recipe `_ for an ++ example built on :class:`MutableSet`. ++ ++ * For more about ABCs, see the :mod:`abc` module and :pep:`3119`. +--- a/Doc/library/os.rst ++++ b/Doc/library/os.rst +@@ -223,7 +223,7 @@ + .. function:: getresgid() + + Return a tuple (rgid, egid, sgid) denoting the current process's +- real, effective, and saved user ids. ++ real, effective, and saved group ids. + + Availability: Unix. + +@@ -337,7 +337,7 @@ + + Set the current process's real, effective, and saved user ids. + +- Availibility: Unix. ++ Availability: Unix. + + .. versionadded:: 2.7 + +@@ -756,7 +756,7 @@ + + This function is intended for low-level I/O. For normal usage, use the + built-in function :func:`open`, which returns a "file object" with +- :meth:`~file.read` and :meth:`~file.wprite` methods (and many more). To ++ :meth:`~file.read` and :meth:`~file.write` methods (and many more). To + wrap a file descriptor in a "file object", use :func:`fdopen`. + + +@@ -2096,8 +2096,9 @@ + + The :mod:`subprocess` module provides more powerful facilities for spawning new + processes and retrieving their results; using that module is preferable to using +- this function. Use the :mod:`subprocess` module. Check especially the +- :ref:`subprocess-replacements` section. ++ this function. See the ++ :ref:`subprocess-replacements` section in the :mod:`subprocess` documentation ++ for some helpful recipes. + + Availability: Unix, Windows. + +--- a/Doc/library/pyexpat.rst ++++ b/Doc/library/pyexpat.rst +@@ -464,7 +464,7 @@ + Called if the XML document hasn't been declared as being a standalone document. + This happens when there is an external subset or a reference to a parameter + entity, but the XML declaration does not set standalone to ``yes`` in an XML +- declaration. If this handler returns ``0``, then the parser will throw an ++ declaration. If this handler returns ``0``, then the parser will raise an + :const:`XML_ERROR_NOT_STANDALONE` error. If this handler is not set, no + exception is raised by the parser for this condition. + +@@ -481,7 +481,7 @@ + responsible for creating the sub-parser using + ``ExternalEntityParserCreate(context)``, initializing it with the appropriate + callbacks, and parsing the entity. This handler should return an integer; if it +- returns ``0``, the parser will throw an ++ returns ``0``, the parser will raise an + :const:`XML_ERROR_EXTERNAL_ENTITY_HANDLING` error, otherwise parsing will + continue. + +--- a/Doc/library/argparse.rst ++++ b/Doc/library/argparse.rst +@@ -203,8 +203,8 @@ + add_help + ^^^^^^^^ + +-By default, ArgumentParser objects add a ``-h/--help`` option which simply +-displays the parser's help message. For example, consider a file named ++By default, ArgumentParser objects add an option which simply displays ++the parser's help message. For example, consider a file named + ``myprogram.py`` containing the following code:: + + import argparse +@@ -234,12 +234,27 @@ + optional arguments: + --foo FOO foo help + ++The help option is typically ``-h/--help``. The exception to this is ++if the ``prefix_chars=`` is specified and does not include ``'-'``, in ++which case ``-h`` and ``--help`` are not valid options. In ++this case, the first character in ``prefix_chars`` is used to prefix ++the help options:: + ++ >>> parser = argparse.ArgumentParser(prog='PROG', prefix_chars='+/') ++ >>> parser.print_help() ++ usage: PROG [+h] ++ ++ optional arguments: ++ +h, ++help show this help message and exit ++ ++ ++ + prefix_chars + ^^^^^^^^^^^^ + + Most command-line options will use ``'-'`` as the prefix, e.g. ``-f/--foo``. +-Parsers that need to support additional prefix characters, e.g. for options ++Parsers that need to support different or additional prefix ++characters, e.g. for options + like ``+f`` or ``/foo``, may specify them using the ``prefix_chars=`` argument + to the ArgumentParser constructor:: + +@@ -698,8 +713,8 @@ + + >>> class FooAction(argparse.Action): + ... def __call__(self, parser, namespace, values, option_string=None): +- ... print '%r %r %r' % (namespace, values, option_string) +- ... setattr(namespace, self.dest, values) ++ ... print '%r %r %r' % (namespace, values, option_string) ++ ... setattr(namespace, self.dest, values) + ... + >>> parser = argparse.ArgumentParser() + >>> parser.add_argument('--foo', action=FooAction) +@@ -722,14 +737,14 @@ + * N (an integer). N args from the command-line will be gathered together into a + list. For example:: + +- >>> parser = argparse.ArgumentParser() +- >>> parser.add_argument('--foo', nargs=2) +- >>> parser.add_argument('bar', nargs=1) +- >>> parser.parse_args('c --foo a b'.split()) +- Namespace(bar=['c'], foo=['a', 'b']) ++ >>> parser = argparse.ArgumentParser() ++ >>> parser.add_argument('--foo', nargs=2) ++ >>> parser.add_argument('bar', nargs=1) ++ >>> parser.parse_args('c --foo a b'.split()) ++ Namespace(bar=['c'], foo=['a', 'b']) + +- Note that ``nargs=1`` produces a list of one item. This is different from +- the default, in which the item is produced by itself. ++ Note that ``nargs=1`` produces a list of one item. This is different from ++ the default, in which the item is produced by itself. + + * ``'?'``. One arg will be consumed from the command-line if possible, and + produced as a single item. If no command-line arg is present, the value from +--- a/Doc/library/nntplib.rst ++++ b/Doc/library/nntplib.rst +@@ -18,35 +18,35 @@ + Here are two small examples of how it can be used. To list some statistics + about a newsgroup and print the subjects of the last 10 articles:: + +- >>> s = NNTP('news.cwi.nl') +- >>> resp, count, first, last, name = s.group('comp.lang.python') ++ >>> s = NNTP('news.gmane.org') ++ >>> resp, count, first, last, name = s.group('gmane.comp.python.committers') + >>> print 'Group', name, 'has', count, 'articles, range', first, 'to', last +- Group comp.lang.python has 59 articles, range 3742 to 3803 ++ Group gmane.comp.python.committers has 1071 articles, range 1 to 1071 + >>> resp, subs = s.xhdr('subject', first + '-' + last) + >>> for id, sub in subs[-10:]: print id, sub + ... +- 3792 Re: Removing elements from a list while iterating... +- 3793 Re: Who likes Info files? +- 3794 Emacs and doc strings +- 3795 a few questions about the Mac implementation +- 3796 Re: executable python scripts +- 3797 Re: executable python scripts +- 3798 Re: a few questions about the Mac implementation +- 3799 Re: PROPOSAL: A Generic Python Object Interface for Python C Modules +- 3802 Re: executable python scripts +- 3803 Re: \POSIX{} wait and SIGCHLD ++ 1062 Re: Mercurial Status? ++ 1063 Re: [python-committers] (Windows) buildbots on 3.x ++ 1064 Re: Mercurial Status? ++ 1065 Re: Mercurial Status? ++ 1066 Python 2.6.6 status ++ 1067 Commit Privileges for Ask Solem ++ 1068 Re: Commit Privileges for Ask Solem ++ 1069 Re: Commit Privileges for Ask Solem ++ 1070 Re: Commit Privileges for Ask Solem ++ 1071 2.6.6 rc 2 + >>> s.quit() +- '205 news.cwi.nl closing connection. Goodbye.' ++ '205 Bye!' + + To post an article from a file (this assumes that the article has valid +-headers):: ++headers, and that you have right to post on the particular newsgroup):: + +- >>> s = NNTP('news.cwi.nl') ++ >>> s = NNTP('news.gmane.org') + >>> f = open('/tmp/article') + >>> s.post(f) + '240 Article posted successfully.' + >>> s.quit() +- '205 news.cwi.nl closing connection. Goodbye.' ++ '205 Bye!' + + The module itself defines the following items: + +--- a/Doc/library/compiler.rst ++++ b/Doc/library/compiler.rst +@@ -18,7 +18,7 @@ + + The :mod:`compiler` package is a Python source to bytecode translator written in + Python. It uses the built-in parser and standard :mod:`parser` module to +-generated a concrete syntax tree. This tree is used to generate an abstract ++generate a concrete syntax tree. This tree is used to generate an abstract + syntax tree (AST) and then Python bytecode. + + The full functionality of the package duplicates the built-in compiler provided +--- a/Doc/library/readline.rst ++++ b/Doc/library/readline.rst +@@ -20,7 +20,7 @@ + the ``libedit`` library instead of GNU readline. + + The configuration file for ``libedit`` is different from that +- of GNU readline. If you programmaticly load configuration strings ++ of GNU readline. If you programmatically load configuration strings + you can check for the text "libedit" in :const:`readline.__doc__` + to differentiate between GNU readline and libedit. + +@@ -210,6 +210,7 @@ + :envvar:`PYTHONSTARTUP` file. :: + + import os ++ import readline + histfile = os.path.join(os.environ["HOME"], ".pyhist") + try: + readline.read_history_file(histfile) +--- a/Doc/library/operator.rst ++++ b/Doc/library/operator.rst +@@ -496,8 +496,24 @@ + attribute is requested, returns a tuple of attributes. After, + ``f = attrgetter('name')``, the call ``f(b)`` returns ``b.name``. After, + ``f = attrgetter('name', 'date')``, the call ``f(b)`` returns ``(b.name, +- b.date)``. ++ b.date)``. Equivalent to:: + ++ def attrgetter(*items): ++ if len(items) == 1: ++ attr = items[0] ++ def g(obj): ++ return resolve_attr(obj, attr) ++ else: ++ def g(obj): ++ return tuple(resolve_att(obj, attr) for attr in items) ++ return g ++ ++ def resolve_attr(obj, attr): ++ for name in attr.split("."): ++ obj = getattr(obj, name) ++ return obj ++ ++ + The attribute names can also contain dots; after ``f = attrgetter('date.month')``, + the call ``f(b)`` returns ``b.date.month``. + +@@ -516,15 +532,15 @@ + operand's :meth:`__getitem__` method. If multiple items are specified, + returns a tuple of lookup values. Equivalent to:: + +- def itemgetter(*items): +- if len(items) == 1: +- item = items[0] +- def g(obj): +- return obj[item] +- else: +- def g(obj): +- return tuple(obj[item] for item in items) +- return g ++ def itemgetter(*items): ++ if len(items) == 1: ++ item = items[0] ++ def g(obj): ++ return obj[item] ++ else: ++ def g(obj): ++ return tuple(obj[item] for item in items) ++ return g + + The items can be any type accepted by the operand's :meth:`__getitem__` + method. Dictionaries accept any hashable value. Lists, tuples, and +@@ -545,12 +561,12 @@ + Example of using :func:`itemgetter` to retrieve specific fields from a + tuple record: + +- >>> inventory = [('apple', 3), ('banana', 2), ('pear', 5), ('orange', 1)] +- >>> getcount = itemgetter(1) +- >>> map(getcount, inventory) +- [3, 2, 5, 1] +- >>> sorted(inventory, key=getcount) +- [('orange', 1), ('banana', 2), ('apple', 3), ('pear', 5)] ++ >>> inventory = [('apple', 3), ('banana', 2), ('pear', 5), ('orange', 1)] ++ >>> getcount = itemgetter(1) ++ >>> map(getcount, inventory) ++ [3, 2, 5, 1] ++ >>> sorted(inventory, key=getcount) ++ [('orange', 1), ('banana', 2), ('apple', 3), ('pear', 5)] + + + .. function:: methodcaller(name[, args...]) +@@ -559,8 +575,13 @@ + additional arguments and/or keyword arguments are given, they will be given + to the method as well. After ``f = methodcaller('name')``, the call ``f(b)`` + returns ``b.name()``. After ``f = methodcaller('name', 'foo', bar=1)``, the +- call ``f(b)`` returns ``b.name('foo', bar=1)``. ++ call ``f(b)`` returns ``b.name('foo', bar=1)``. Equivalent to:: + ++ def methodcaller(name, *args, **kwargs): ++ def caller(obj): ++ return getattr(obj, name)(*args, **kwargs) ++ return caller ++ + .. versionadded:: 2.6 + + +--- a/Doc/library/io.rst ++++ b/Doc/library/io.rst +@@ -11,6 +11,8 @@ + .. moduleauthor:: Benjamin Peterson + .. sectionauthor:: Benjamin Peterson + ++.. versionadded:: 2.6 ++ + The :mod:`io` module provides the Python interfaces to stream handling. + Under Python 2.x, this is proposed as an alternative to the built-in + :class:`file` object, but in Python 3.x it is the default interface to +@@ -27,7 +29,7 @@ + At the top of the I/O hierarchy is the abstract base class :class:`IOBase`. It + defines the basic interface to a stream. Note, however, that there is no + separation between reading and writing to streams; implementations are allowed +-to throw an :exc:`IOError` if they do not support a given operation. ++to raise an :exc:`IOError` if they do not support a given operation. + + Extending :class:`IOBase` is :class:`RawIOBase` which deals simply with the + reading and writing of raw bytes to a stream. :class:`FileIO` subclasses +@@ -66,11 +68,11 @@ + Open *file* and return a corresponding stream. If the file cannot be opened, + an :exc:`IOError` is raised. + +- *file* is either a string giving the name (and the path if the file isn't +- in the current working directory) of the file to be opened or an integer +- file descriptor of the file to be wrapped. (If a file descriptor is given, +- for example, from :func:`os.fdopen`, it is closed when the returned I/O +- object is closed, unless *closefd* is set to ``False``.) ++ *file* is either a string giving the pathname (absolute or ++ relative to the current working directory) of the file to be opened or ++ an integer file descriptor of the file to be wrapped. (If a file descriptor ++ is given, it is closed when the returned I/O object is closed, unless ++ *closefd* is set to ``False``.) + + *mode* is an optional string that specifies the mode in which the file is + opened. It defaults to ``'r'`` which means open for reading in text mode. +@@ -369,8 +371,9 @@ + + .. method:: readinto(b) + +- Read up to len(b) bytes into bytearray *b* and return the number of bytes +- read. ++ Read up to len(b) bytes into bytearray *b* and return the number ofbytes ++ read. If the object is in non-blocking mode and no bytes are available, ++ ``None`` is returned. + + .. method:: write(b) + +--- a/Doc/library/functions.rst ++++ b/Doc/library/functions.rst +@@ -347,7 +347,10 @@ + returns the current global and local dictionary, respectively, which may be + useful to pass around for use by :func:`eval` or :func:`execfile`. + ++ See :func:`ast.literal_eval` for a function that can safely evaluate strings ++ with expressions containing only literals. + ++ + .. function:: execfile(filename[, globals[, locals]]) + + This function is similar to the :keyword:`exec` statement, but parses a file +@@ -402,8 +405,9 @@ + iterable if function(item)]`` if function is not ``None`` and ``[item for item + in iterable if item]`` if function is ``None``. + +- See :func:`itertools.ifilterfalse` for the complementary function that returns +- elements of *iterable* for which *function* returns false. ++ See :func:`itertools.ifilter` and :func:`itertools.ifilterfalse` for iterator ++ versions of this function, including a variation that filters for elements ++ where the *function* returns false. + + + .. function:: float([x]) +@@ -873,7 +877,7 @@ + + *fget* is a function for getting an attribute value, likewise *fset* is a + function for setting, and *fdel* a function for del'ing, an attribute. Typical +- use is to define a managed attribute x:: ++ use is to define a managed attribute ``x``:: + + class C(object): + def __init__(self): +@@ -887,6 +891,9 @@ + del self._x + x = property(getx, setx, delx, "I'm the 'x' property.") + ++ If then *c* is an instance of *C*, ``c.x`` will invoke the getter, ++ ``c.x = value`` will invoke the setter and ``del c.x`` the deleter. ++ + If given, *doc* will be the docstring of the property attribute. Otherwise, the + property will copy *fget*'s docstring (if it exists). This makes it possible to + create read-only properties easily using :func:`property` as a :term:`decorator`:: +@@ -1094,6 +1101,14 @@ + example, ``round(0.5)`` is ``1.0`` and ``round(-0.5)`` is ``-1.0``). + + ++ .. note:: ++ ++ The behavior of :func:`round` for floats can be surprising: for example, ++ ``round(2.675, 2)`` gives ``2.67`` instead of the expected ``2.68``. ++ This is not a bug: it's a result of the fact that most decimal fractions ++ can't be represented exactly as a float. See :ref:`tut-fp-issues` for ++ more information. ++ + .. function:: set([iterable]) + :noindex: + +--- a/Doc/library/bisect.rst ++++ b/Doc/library/bisect.rst +@@ -1,10 +1,10 @@ +- + :mod:`bisect` --- Array bisection algorithm + =========================================== + + .. module:: bisect + :synopsis: Array bisection algorithms for binary searching. + .. sectionauthor:: Fred L. Drake, Jr. ++.. sectionauthor:: Raymond Hettinger + .. example based on the PyModules FAQ entry by Aaron Watters + + This module provides support for maintaining a list in sorted order without +@@ -14,80 +14,120 @@ + algorithm to do its work. The source code may be most useful as a working + example of the algorithm (the boundary conditions are already right!). + ++.. versionadded:: 2.1 ++ + The following functions are provided: + + +-.. function:: bisect_left(list, item[, lo[, hi]]) ++.. function:: bisect_left(a, x, lo=0, hi=len(a)) + +- Locate the proper insertion point for *item* in *list* to maintain sorted order. +- The parameters *lo* and *hi* may be used to specify a subset of the list which +- should be considered; by default the entire list is used. If *item* is already +- present in *list*, the insertion point will be before (to the left of) any +- existing entries. The return value is suitable for use as the first parameter +- to ``list.insert()``. This assumes that *list* is already sorted. ++ Locate the insertion point for *x* in *a* to maintain sorted order. ++ The parameters *lo* and *hi* may be used to specify a subset of the list ++ which should be considered; by default the entire list is used. If *x* is ++ already present in *a*, the insertion point will be before (to the left of) ++ any existing entries. The return value is suitable for use as the first ++ parameter to ``list.insert()`` assuming that *a* is already sorted. + +- .. versionadded:: 2.1 ++ The returned insertion point *i* partitions the array *a* into two halves so ++ that ``all(val < x for val in a[lo:i])`` for the left side and ++ ``all(val >= x for val in a[i:hi])`` for the right side. + ++.. function:: bisect_right(a, x, lo=0, hi=len(a)) ++ bisect(a, x, lo=0, hi=len(a)) + +-.. function:: bisect_right(list, item[, lo[, hi]]) ++ Similar to :func:`bisect_left`, but returns an insertion point which comes ++ after (to the right of) any existing entries of *x* in *a*. + +- Similar to :func:`bisect_left`, but returns an insertion point which comes after +- (to the right of) any existing entries of *item* in *list*. ++ The returned insertion point *i* partitions the array *a* into two halves so ++ that ``all(val <= x for val in a[lo:i])`` for the left side and ++ ``all(val > x for val in a[i:hi])`` for the right side. + +- .. versionadded:: 2.1 ++.. function:: insort_left(a, x, lo=0, hi=len(a)) + ++ Insert *x* in *a* in sorted order. This is equivalent to ++ ``a.insert(bisect.bisect_left(a, x, lo, hi), x)`` assuming that *a* is ++ already sorted. Keep in mind that the O(log n) search is dominated by ++ the slow O(n) insertion step. + +-.. function:: bisect(...) ++.. function:: insort_right(a, x, lo=0, hi=len(a)) ++ insort(a, x, lo=0, hi=len(a)) + +- Alias for :func:`bisect_right`. ++ Similar to :func:`insort_left`, but inserting *x* in *a* after any existing ++ entries of *x*. + ++.. seealso:: + +-.. function:: insort_left(list, item[, lo[, hi]]) ++ `SortedCollection recipe ++ `_ that uses ++ bisect to build a full-featured collection class with straight-forward search ++ methods and support for a key-function. The keys are precomputed to save ++ unnecessary calls to the key function during searches. + +- Insert *item* in *list* in sorted order. This is equivalent to +- ``list.insert(bisect.bisect_left(list, item, lo, hi), item)``. This assumes +- that *list* is already sorted. + +- .. versionadded:: 2.1 ++Searching Sorted Lists ++---------------------- + ++The above :func:`bisect` functions are useful for finding insertion points but ++can be tricky or awkward to use for common searching tasks. The following five ++functions show how to transform them into the standard lookups for sorted ++lists:: + +-.. function:: insort_right(list, item[, lo[, hi]]) ++ def index(a, x): ++ 'Locate the leftmost value exactly equal to x' ++ i = bisect_left(a, x) ++ if i != len(a) and a[i] == x: ++ return i ++ raise ValueError + +- Similar to :func:`insort_left`, but inserting *item* in *list* after any +- existing entries of *item*. ++ def find_lt(a, x): ++ 'Find rightmost value less than x' ++ i = bisect_left(a, x) ++ if i: ++ return a[i-1] ++ raise ValueError + +- .. versionadded:: 2.1 ++ def find_le(a, x): ++ 'Find rightmost value less than or equal to x' ++ i = bisect_right(a, x) ++ if i: ++ return a[i-1] ++ raise ValueError + ++ def find_gt(a, x): ++ 'Find leftmost value greater than x' ++ i = bisect_right(a, x) ++ if i != len(a): ++ return a[i] ++ raise ValueError + +-.. function:: insort(...) ++ def find_ge(a, x): ++ 'Find leftmost item greater than or equal to x' ++ i = bisect_left(a, x) ++ if i != len(a): ++ return a[i] ++ raise ValueError + +- Alias for :func:`insort_right`. + ++Other Examples ++-------------- + +-Examples +--------- +- + .. _bisect-example: + +-The :func:`bisect` function is generally useful for categorizing numeric data. +-This example uses :func:`bisect` to look up a letter grade for an exam total +-(say) based on a set of ordered numeric breakpoints: 85 and up is an 'A', 75..84 +-is a 'B', etc. ++The :func:`bisect` function can be useful for numeric table lookups. This ++example uses :func:`bisect` to look up a letter grade for an exam score (say) ++based on a set of ordered numeric breakpoints: 90 and up is an 'A', 80 to 89 is ++a 'B', and so on:: + +- >>> grades = "FEDCBA" +- >>> breakpoints = [30, 44, 66, 75, 85] +- >>> from bisect import bisect +- >>> def grade(total): +- ... return grades[bisect(breakpoints, total)] ++ >>> def grade(score, breakpoints=[60, 70, 80, 90], grades='FDCBA'): ++ ... i = bisect(breakpoints, score) ++ ... return grades[i] + ... +- >>> grade(66) +- 'C' +- >>> map(grade, [33, 99, 77, 44, 12, 88]) +- ['E', 'A', 'B', 'D', 'F', 'A'] ++ >>> [grade(score) for score in [33, 99, 77, 70, 89, 90, 100]] ++ ['F', 'A', 'C', 'C', 'B', 'A', 'A'] + + Unlike the :func:`sorted` function, it does not make sense for the :func:`bisect` + functions to have *key* or *reversed* arguments because that would lead to an +-inefficent design (successive calls to bisect functions would not "remember" ++inefficient design (successive calls to bisect functions would not "remember" + all of the previous key lookups). + + Instead, it is better to search a list of precomputed keys to find the index +@@ -104,3 +144,4 @@ + ('red', 5) + >>> data[bisect_left(keys, 8)] + ('yellow', 8) ++ +--- a/Doc/library/functools.rst ++++ b/Doc/library/functools.rst +@@ -19,23 +19,22 @@ + + .. function:: cmp_to_key(func) + +- Transform an old-style comparison function to a key-function. Used with +- tools that accept key functions (such as :func:`sorted`, :func:`min`, +- :func:`max`, :func:`heapq.nlargest`, :func:`heapq.nsmallest`, +- :func:`itertools.groupby`). +- This function is primarily used as a transition tool for programs +- being converted to Py3.x where comparison functions are no longer +- supported. ++ Transform an old-style comparison function to a key-function. Used with ++ tools that accept key functions (such as :func:`sorted`, :func:`min`, ++ :func:`max`, :func:`heapq.nlargest`, :func:`heapq.nsmallest`, ++ :func:`itertools.groupby`). This function is primarily used as a transition ++ tool for programs being converted to Py3.x where comparison functions are no ++ longer supported. + +- A compare function is any callable that accept two arguments, compares +- them, and returns a negative number for less-than, zero for equality, +- or a positive number for greater-than. A key function is a callable +- that accepts one argument and returns another value that indicates +- the position in the desired collation sequence. ++ A compare function is any callable that accept two arguments, compares them, ++ and returns a negative number for less-than, zero for equality, or a positive ++ number for greater-than. A key function is a callable that accepts one ++ argument and returns another value that indicates the position in the desired ++ collation sequence. + +- Example:: ++ Example:: + +- sorted(iterable, key=cmp_to_key(locale.strcoll)) # locale-aware sort order ++ sorted(iterable, key=cmp_to_key(locale.strcoll)) # locale-aware sort order + + .. versionadded:: 2.7 + +--- a/Doc/library/os.path.rst ++++ b/Doc/library/os.path.rst +@@ -212,7 +212,9 @@ + .. function:: normpath(path) + + Normalize a pathname. This collapses redundant separators and up-level +- references so that ``A//B``, ``A/./B`` and ``A/foo/../B`` all become ``A/B``. ++ references so that ``A//B``, ``A/B/``, ``A/./B`` and ``A/foo/../B`` all become ++ ``A/B``. ++ + It does not normalize the case (use :func:`normcase` for that). On Windows, it + converts forward slashes to backward slashes. It should be understood that this + may change the meaning of the path if it contains symbolic links! +@@ -335,8 +337,7 @@ + .. data:: supports_unicode_filenames + + True if arbitrary Unicode strings can be used as file names (within limitations +- imposed by the file system), and if :func:`os.listdir` returns Unicode strings +- for a Unicode argument. ++ imposed by the file system). + + .. versionadded:: 2.3 + +--- a/Doc/library/signal.rst ++++ b/Doc/library/signal.rst +@@ -77,7 +77,9 @@ + + .. data:: CTRL_C_EVENT + +- The signal corresponding to the CTRL+C keystroke event. ++ The signal corresponding to the CTRL+C keystroke event. This signal can ++ only be used with :func:`os.kill`. ++ + Availability: Windows. + + .. versionadded:: 2.7 +@@ -85,7 +87,9 @@ + + .. data:: CTRL_BREAK_EVENT + +- The signal corresponding to the CTRL+BREAK keystroke event. ++ The signal corresponding to the CTRL+BREAK keystroke event. This signal can ++ only be used with :func:`os.kill`. ++ + Availability: Windows. + + .. versionadded:: 2.7 +@@ -232,7 +236,11 @@ + see the :ref:`description in the type hierarchy ` or see the + attribute descriptions in the :mod:`inspect` module). + ++ On Windows, :func:`signal` can only be called with :const:`SIGABRT`, ++ :const:`SIGFPE`, :const:`SIGILL`, :const:`SIGINT`, :const:`SIGSEGV`, or ++ :const:`SIGTERM`. A :exc:`ValueError` will be raised in any other case. + ++ + .. _signal-example: + + Example +--- a/Doc/library/imp.rst ++++ b/Doc/library/imp.rst +@@ -116,8 +116,7 @@ + .. function:: acquire_lock() + + Acquire the interpreter's import lock for the current thread. This lock should +- be used by import hooks to ensure thread-safety when importing modules. On +- platforms without threads, this function does nothing. ++ be used by import hooks to ensure thread-safety when importing modules. + + Once a thread has acquired the import lock, the same thread may acquire it + again without blocking; the thread must release it once for each time it has +--- a/Doc/library/bdb.rst ++++ b/Doc/library/bdb.rst +@@ -108,7 +108,7 @@ + * ``"exception"``: An exception has occurred. + * ``"c_call"``: A C function is about to be called. + * ``"c_return"``: A C function has returned. +- * ``"c_exception"``: A C function has thrown an exception. ++ * ``"c_exception"``: A C function has raised an exception. + + For the Python events, specialized functions (see below) are called. For + the C events, no action is taken. +--- a/Doc/library/profile.rst ++++ b/Doc/library/profile.rst +@@ -620,7 +620,7 @@ + integers, you can also invoke the class constructor with a second argument + specifying the real duration of one unit of time. For example, if + :func:`your_integer_time_func` returns times measured in thousands of seconds, +- you would constuct the :class:`Profile` instance as follows:: ++ you would construct the :class:`Profile` instance as follows:: + + pr = profile.Profile(your_integer_time_func, 0.001) + +--- a/Doc/library/urllib.rst ++++ b/Doc/library/urllib.rst +@@ -23,6 +23,10 @@ + instead of filenames. Some restrictions apply --- it can only open URLs for + reading, and no seek operations are available. + ++.. warning:: When opening HTTPS URLs, it is not attempted to validate the ++ server certificate. Use at your own risk! ++ ++ + High-level interface + -------------------- + +@@ -237,7 +241,7 @@ + .. function:: urlencode(query[, doseq]) + + Convert a mapping object or a sequence of two-element tuples to a +- "url-encoded" string, suitable to pass to :func:`urlopen` above as the ++ "percent-encoded" string, suitable to pass to :func:`urlopen` above as the + optional *data* argument. This is useful to pass a dictionary of form + fields to a ``POST`` request. The resulting string is a series of + ``key=value`` pairs separated by ``'&'`` characters, where both *key* and +@@ -262,7 +266,7 @@ + + .. function:: url2pathname(path) + +- Convert the path component *path* from an encoded URL to the local syntax for a ++ Convert the path component *path* from an percent-encoded URL to the local syntax for a + path. This does not accept a complete URL. This function uses :func:`unquote` + to decode *path*. + +--- a/Doc/library/locale.rst ++++ b/Doc/library/locale.rst +@@ -248,10 +248,6 @@ + specified, and therefore you should not assume knowledge of it on different + systems. + +- .. data:: ERA_YEAR +- +- Get the year in the relevant era of the locale. +- + .. data:: ERA_D_T_FMT + + Get a format string for :func:`strftime` to represent dates and times in a +--- a/Doc/library/cgi.rst ++++ b/Doc/library/cgi.rst +@@ -349,12 +349,15 @@ + Convert the characters ``'&'``, ``'<'`` and ``'>'`` in string *s* to HTML-safe + sequences. Use this if you need to display text that might contain such + characters in HTML. If the optional flag *quote* is true, the quotation mark +- character (``'"'``) is also translated; this helps for inclusion in an HTML +- attribute value, as in ````. If the value to be quoted might +- include single- or double-quote characters, or both, consider using the +- :func:`quoteattr` function in the :mod:`xml.sax.saxutils` module instead. ++ character (``"``) is also translated; this helps for inclusion in an HTML ++ attribute value delimited by double quotes, as in ````. Note ++ that single quotes are never translated. + ++ If the value to be quoted might include single- or double-quote characters, ++ or both, consider using the :func:`~xml.sax.saxutils.quoteattr` function in the ++ :mod:`xml.sax.saxutils` module instead. + ++ + .. _cgi-security: + + Caring about security +--- a/Doc/library/macosa.rst ++++ b/Doc/library/macosa.rst +@@ -9,7 +9,8 @@ + Architecture (OSA, also commonly referred to as AppleScript) for Python, + allowing you to control scriptable applications from your Python program, + and with a fairly pythonic interface. Development on this set of modules has +-stopped, and a replacement is expected for Python 2.5. ++stopped. For more up-to-date implementation of AppleScript support for Python, ++see the third-party py-appscript project: . + + For a description of the various components of AppleScript and OSA, and to get + an understanding of the architecture and terminology, you should read Apple's +--- a/Doc/library/threading.rst ++++ b/Doc/library/threading.rst +@@ -43,7 +43,9 @@ + variable allows one or more threads to wait until they are notified by another + thread. + ++ See :ref:`condition-objects`. + ++ + .. function:: current_thread() + currentThread() + +@@ -69,7 +71,9 @@ + with the :meth:`clear` method. The :meth:`wait` method blocks until the flag + is true. + ++ See :ref:`event-objects`. + ++ + .. class:: local + + A class that represents thread-local data. Thread-local data are data whose +@@ -93,7 +97,9 @@ + acquired it, subsequent attempts to acquire it block, until it is released; any + thread may release it. + ++ See :ref:`lock-objects`. + ++ + .. function:: RLock() + + A factory function that returns a new reentrant lock object. A reentrant lock +@@ -101,7 +107,9 @@ + reentrant lock, the same thread may acquire it again without blocking; the + thread must release it once for each time it has acquired it. + ++ See :ref:`rlock-objects`. + ++ + .. function:: Semaphore([value]) + :noindex: + +@@ -111,7 +119,9 @@ + if necessary until it can return without making the counter negative. If not + given, *value* defaults to 1. + ++ See :ref:`semaphore-objects`. + ++ + .. function:: BoundedSemaphore([value]) + + A factory function that returns a new bounded semaphore object. A bounded +@@ -122,16 +132,22 @@ + + + .. class:: Thread ++ :noindex: + + A class that represents a thread of control. This class can be safely + subclassed in a limited fashion. + ++ See :ref:`thread-objects`. + ++ + .. class:: Timer ++ :noindex: + + A thread that executes a function after a specified interval has passed. + ++ See :ref:`timer-objects`. + ++ + .. function:: settrace(func) + + .. index:: single: trace function +@@ -319,8 +335,8 @@ + + Return whether the thread is alive. + +- Roughly, a thread is alive from the moment the :meth:`start` method +- returns until its :meth:`run` method terminates. The module function ++ This method returns ``True`` just before the :meth:`run` method starts ++ until just after the :meth:`run` method terminates. The module function + :func:`.enumerate` returns a list of all alive threads. + + .. method:: isDaemon() +--- a/Doc/install/index.rst ++++ b/Doc/install/index.rst +@@ -314,8 +314,8 @@ + stash of Python modules. This scheme's name is derived from the idea of a + "home" directory on Unix, since it's not unusual for a Unix user to make their + home directory have a layout similar to :file:`/usr/` or :file:`/usr/local/`. +-This scheme can be used by anyone, regardless of the operating system their +-installing for. ++This scheme can be used by anyone, regardless of the operating system they ++are installing for. + + Installing a new module distribution is as simple as :: + +--- a/Doc/faq/design.rst ++++ b/Doc/faq/design.rst +@@ -28,7 +28,7 @@ + If you're used to reading and writing code that uses one style, you will feel at + least slightly uneasy when reading (or being required to write) another style. + +-Many coding styles place begin/end brackets on a line by themself. This makes ++Many coding styles place begin/end brackets on a line by themselves. This makes + programs considerably longer and wastes valuable screen space, making it harder + to get a good overview of a program. Ideally, a function should fit on one + screen (say, 20-30 lines). 20 lines of Python can do a lot more work than 20 +--- a/Doc/faq/windows.rst ++++ b/Doc/faq/windows.rst +@@ -594,7 +594,7 @@ + + The Python installer issues a warning like this:: + +- This version uses ``CTL3D32.DLL`` which is not the correct version. ++ This version uses CTL3D32.DLL which is not the correct version. + This version is used for windows NT applications only. + + Tim Peters: +--- a/Doc/faq/programming.rst ++++ b/Doc/faq/programming.rst +@@ -944,7 +944,7 @@ + ------------------------------------------------------------------------------------- + + Starting with Python 2.2, you can use ``S.rstrip("\r\n")`` to remove all +-occurences of any line terminator from the end of the string ``S`` without ++occurrences of any line terminator from the end of the string ``S`` without + removing other trailing whitespace. If the string ``S`` represents more than + one line, with several empty lines at the end, the line terminators for all the + blank lines will be removed:: +@@ -979,8 +979,8 @@ + :func:`float`. ``split()`` supports an optional "sep" parameter which is useful + if the line uses something other than whitespace as a separator. + +-For more complicated input parsing, regular expressions more powerful than C's +-:cfunc:`sscanf` and better suited for the task. ++For more complicated input parsing, regular expressions are more powerful ++than C's :cfunc:`sscanf` and better suited for the task. + + + What does 'UnicodeError: ASCII [decoding,encoding] error: ordinal not in range(128)' mean? +--- a/Doc/faq/library.rst ++++ b/Doc/faq/library.rst +@@ -458,7 +458,7 @@ + + To truncate a file, open it using ``f = open(filename, "r+")``, and use + ``f.truncate(offset)``; offset defaults to the current seek position. There's +-also ```os.ftruncate(fd, offset)`` for files opened with :func:`os.open`, where ++also ``os.ftruncate(fd, offset)`` for files opened with :func:`os.open`, where + ``fd`` is the file descriptor (a small integer). + + The :mod:`shutil` module also contains a number of functions to work on files +@@ -672,9 +672,8 @@ + if reply != 200: + sys.stdout.write(httpobj.getfile().read()) + +-Note that in general for URL-encoded POST operations, query strings must be +-quoted by using :func:`urllib.quote`. For example to send name="Guy Steele, +-Jr.":: ++Note that in general for percent-encoded POST operations, query strings must be ++quoted using :func:`urllib.quote`. For example to send name="Guy Steele, Jr.":: + + >>> from urllib import quote + >>> x = quote("Guy Steele, Jr.") +--- a/Doc/faq/extending.rst ++++ b/Doc/faq/extending.rst +@@ -26,6 +26,8 @@ + C++ objects with constructors are probably not a good idea. + + ++.. _c-wrapper-software: ++ + Writing C is hard; are there any alternatives? + ---------------------------------------------- + +@@ -197,11 +199,7 @@ + whole lot of difference between C and C++ -- so the strategy of building a new + Python type around a C structure (pointer) type will also work for C++ objects. + +-For C++ libraries, you can look at `SIP +-`_, `CXX +-`_, `Boost +-`_, `Weave +-`_ or `SWIG `_ ++For C++ libraries, see :ref:`c-wrapper-software`. + + + I added a module using the Setup file and the make fails; why? +--- a/Doc/glossary.rst ++++ b/Doc/glossary.rst +@@ -19,7 +19,7 @@ + + 2to3 + A tool that tries to convert Python 2.x code to Python 3.x code by +- handling most of the incompatibilites which can be detected by parsing the ++ handling most of the incompatibilities which can be detected by parsing the + source and traversing the parse tree. + + 2to3 is available in the standard library as :mod:`lib2to3`; a standalone +@@ -143,10 +143,9 @@ + For more information about descriptors' methods, see :ref:`descriptors`. + + dictionary +- An associative array, where arbitrary keys are mapped to values. The use +- of :class:`dict` closely resembles that for :class:`list`, but the keys can +- be any object with a :meth:`__hash__` function, not just integers. +- Called a hash in Perl. ++ An associative array, where arbitrary keys are mapped to values. The keys ++ can be any object with :meth:`__hash__` function and :meth:`__eq__` ++ methods. Called a hash in Perl. + + docstring + A string literal which appears as the first expression in a class, +@@ -157,15 +156,15 @@ + object. + + duck-typing +- A pythonic programming style which determines an object's type by inspection +- of its method or attribute signature rather than by explicit relationship +- to some type object ("If it looks like a duck and quacks like a duck, it ++ A programming style which does not look at an object's type to determine ++ if it has the right interface; instead, the method or attribute is simply ++ called or used ("If it looks like a duck and quacks like a duck, it + must be a duck.") By emphasizing interfaces rather than specific types, + well-designed code improves its flexibility by allowing polymorphic + substitution. Duck-typing avoids tests using :func:`type` or +- :func:`isinstance`. (Note, however, that duck-typing can be complemented +- with abstract base classes.) Instead, it typically employs :func:`hasattr` +- tests or :term:`EAFP` programming. ++ :func:`isinstance`. (Note, however, that duck-typing can be complemented ++ with :term:`abstract base class`\ es.) Instead, it typically employs ++ :func:`hasattr` tests or :term:`EAFP` programming. + + EAFP + Easier to ask for forgiveness than permission. This common Python coding +@@ -193,13 +192,20 @@ + implement a method named :meth:`find_module`. See :pep:`302` for + details. + ++ floor division ++ Mathematical division that rounds down to nearest integer. The floor ++ division operator is ``//``. For example, the expression ``11 // 4`` ++ evaluates to ``2`` in contrast to the ``2.75`` returned by float true ++ division. Note that ``(-11) // 4`` is ``-3`` because that is ``-2.75`` ++ rounded *downward*. See :pep:`238`. ++ + function + A series of statements which returns some value to a caller. It can also + be passed zero or more arguments which may be used in the execution of + the body. See also :term:`argument` and :term:`method`. + + __future__ +- A pseudo module which programmers can use to enable new language features ++ A pseudo-module which programmers can use to enable new language features + which are not compatible with the current interpreter. For example, the + expression ``11/4`` currently evaluates to ``2``. If the module in which + it is executed had enabled *true division* by executing:: +@@ -224,13 +230,13 @@ + + generator + A function which returns an iterator. It looks like a normal function +- except that values are returned to the caller using a :keyword:`yield` +- statement instead of a :keyword:`return` statement. Generator functions +- often contain one or more :keyword:`for` or :keyword:`while` loops which +- :keyword:`yield` elements back to the caller. The function execution is +- stopped at the :keyword:`yield` keyword (returning the result) and is +- resumed there when the next element is requested by calling the +- :meth:`next` method of the returned iterator. ++ except that it contains :keyword:`yield` statements for producing a series ++ a values usable in a for-loop or that can be retrieved one at a time with ++ the :func:`next` function. Each :keyword:`yield` temporarily suspends ++ processing, remembering the location execution state (including local ++ variables and pending try-statements). When the generator resumes, it ++ picks-up where it left-off (in contrast to functions which start fresh on ++ every invocation). + + .. index:: single: generator expression + +@@ -275,9 +281,7 @@ + IDLE + An Integrated Development Environment for Python. IDLE is a basic editor + and interpreter environment which ships with the standard distribution of +- Python. Good for beginners, it also serves as clear example code for +- those wanting to implement a moderately sophisticated, multi-platform GUI +- application. ++ Python. + + immutable + An object with a fixed value. Immutable objects include numbers, strings and +@@ -389,7 +393,8 @@ + + mapping + A container object (such as :class:`dict`) which supports arbitrary key +- lookups using the special method :meth:`__getitem__`. ++ lookups using the special method :meth:`__getitem__`. Mappings also ++ support :meth:`__len__`, :meth:`__iter__`, and :meth:`__contains__`. + + metaclass + The class of a class. Class definitions create a class name, a class +--- a/Doc/documenting/markup.rst ++++ b/Doc/documenting/markup.rst +@@ -200,8 +200,8 @@ + + .. describe:: cmdoption + +- Describes a command line option or switch. Option argument names should be +- enclosed in angle brackets. Example:: ++ Describes a Python command line option or switch. Option argument names ++ should be enclosed in angle brackets. Example:: + + .. cmdoption:: -m + +@@ -502,8 +502,9 @@ + + .. describe:: option + +- A command-line option to an executable program. The leading hyphen(s) must +- be included. ++ A command-line option of Python. The leading hyphen(s) must be included. ++ If a matching ``cmdoption`` directive exists, it is linked to. For options ++ of other programs or scripts, use simple ````code```` markup. + + .. describe:: program + +--- a/Doc/conf.py ++++ b/Doc/conf.py +@@ -125,7 +125,7 @@ + ('tutorial/index', 'tutorial.tex', + 'Python Tutorial', _stdauthor, 'manual'), + ('using/index', 'using.tex', +- 'Using Python', _stdauthor, 'manual'), ++ 'Python Setup and Usage', _stdauthor, 'manual'), + ('whatsnew/' + version, 'whatsnew.tex', + 'What\'s New in Python', 'A. M. Kuchling', 'howto'), + ] +--- a/Doc/Makefile ++++ b/Doc/Makefile +@@ -87,13 +87,14 @@ + + linkcheck: BUILDER = linkcheck + linkcheck: build +- @echo "Link check complete; look for any errors in the above output " \ ++ @echo "Link check complete; look for any errors in the above output" \ + "or in build/$(BUILDER)/output.txt" + + suspicious: BUILDER = suspicious + suspicious: build +- @echo "Suspicious check complete; look for any errors in the above output " \ +- "or in build/$(BUILDER)/suspicious.txt" ++ @echo "Suspicious check complete; look for any errors in the above output" \ ++ "or in build/$(BUILDER)/suspicious.csv. If all issues are false" \ ++ "positives, append that file to tools/sphinxext/susp-ignored.csv." + + coverage: BUILDER = coverage + coverage: build +@@ -101,12 +102,12 @@ + + doctest: BUILDER = doctest + doctest: build +- @echo "Testing of doctests in the sources finished, look at the " \ ++ @echo "Testing of doctests in the sources finished, look at the" \ + "results in build/doctest/output.txt" + + pydoc-topics: BUILDER = pydoc-topics + pydoc-topics: build +- @echo "Building finished; now copy build/pydoc-topics/topics.py " \ ++ @echo "Building finished; now copy build/pydoc-topics/topics.py" \ + "to Lib/pydoc_data/topics.py" + + htmlview: html +@@ -120,7 +121,7 @@ + -rm -rf tools/docutils + + dist: +- -rm -rf dist ++ rm -rf dist + mkdir -p dist + + # archive the HTML +@@ -142,15 +143,17 @@ + rm dist/python-$(DISTVERSION)-docs-text.tar + + # archive the A4 latex +- -rm -r build/latex ++ rm -rf build/latex + make latex PAPER=a4 ++ -sed -i 's/makeindex/makeindex -q/' build/latex/Makefile + (cd build/latex; make clean && make all-pdf && make FMT=pdf zip bz2) + cp build/latex/docs-pdf.zip dist/python-$(DISTVERSION)-docs-pdf-a4.zip + cp build/latex/docs-pdf.tar.bz2 dist/python-$(DISTVERSION)-docs-pdf-a4.tar.bz2 + + # archive the letter latex +- rm -r build/latex ++ rm -rf build/latex + make latex PAPER=letter ++ -sed -i 's/makeindex/makeindex -q/' build/latex/Makefile + (cd build/latex; make clean && make all-pdf && make FMT=pdf zip bz2) + cp build/latex/docs-pdf.zip dist/python-$(DISTVERSION)-docs-pdf-letter.zip + cp build/latex/docs-pdf.tar.bz2 dist/python-$(DISTVERSION)-docs-pdf-letter.tar.bz2 +--- a/Lib/CGIHTTPServer.py ++++ b/Lib/CGIHTTPServer.py +@@ -29,6 +29,7 @@ + import BaseHTTPServer + import SimpleHTTPServer + import select ++import copy + + + class CGIHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): +@@ -154,7 +155,7 @@ + + # Reference: http://hoohoo.ncsa.uiuc.edu/cgi/env.html + # XXX Much of the following could be prepared ahead of time! +- env = {} ++ env = copy.deepcopy(os.environ) + env['SERVER_SOFTWARE'] = self.version_string() + env['SERVER_NAME'] = self.server.server_name + env['GATEWAY_INTERFACE'] = 'CGI/1.1' +@@ -216,7 +217,6 @@ + for k in ('QUERY_STRING', 'REMOTE_HOST', 'CONTENT_LENGTH', + 'HTTP_USER_AGENT', 'HTTP_COOKIE', 'HTTP_REFERER'): + env.setdefault(k, "") +- os.environ.update(env) + + self.send_response(200, "Script output follows") + +@@ -248,7 +248,7 @@ + pass + os.dup2(self.rfile.fileno(), 0) + os.dup2(self.wfile.fileno(), 1) +- os.execve(scriptfile, args, os.environ) ++ os.execve(scriptfile, args, env) + except: + self.server.handle_error(self.request, self.client_address) + os._exit(127) +@@ -274,7 +274,8 @@ + p = subprocess.Popen(cmdline, + stdin = subprocess.PIPE, + stdout = subprocess.PIPE, +- stderr = subprocess.PIPE ++ stderr = subprocess.PIPE, ++ env = env + ) + if self.command.lower() == "post" and nbytes > 0: + data = self.rfile.read(nbytes) +--- a/Lib/site.py ++++ b/Lib/site.py +@@ -76,7 +76,11 @@ + + + def makepath(*paths): +- dir = os.path.abspath(os.path.join(*paths)) ++ dir = os.path.join(*paths) ++ try: ++ dir = os.path.abspath(dir) ++ except OSError: ++ pass + return dir, os.path.normcase(dir) + + +@@ -87,8 +91,8 @@ + continue # don't mess with a PEP 302-supplied __file__ + try: + m.__file__ = os.path.abspath(m.__file__) +- except AttributeError: +- continue ++ except (AttributeError, OSError): ++ pass + + + def removeduppaths(): +--- a/Lib/mimetypes.py ++++ b/Lib/mimetypes.py +@@ -199,9 +199,8 @@ + list of standard types, else to the list of non-standard + types. + """ +- fp = open(filename) +- self.readfp(fp, strict) +- fp.close() ++ with open(filename) as fp: ++ self.readfp(fp, strict) + + def readfp(self, fp, strict=True): + """ +@@ -356,7 +355,7 @@ + files = knownfiles + for file in files: + if os.path.isfile(file): +- db.readfp(open(file)) ++ db.read(file) + encodings_map = db.encodings_map + suffix_map = db.suffix_map + types_map = db.types_map[True] +--- a/Lib/curses/wrapper.py ++++ b/Lib/curses/wrapper.py +@@ -17,10 +17,9 @@ + wrapper(). + """ + +- res = None + try: + # Initialize curses +- stdscr=curses.initscr() ++ stdscr = curses.initscr() + + # Turn off echoing of keys, and enter cbreak mode, + # where no buffering is performed on keyboard input +--- a/Lib/idlelib/PyShell.py ++++ b/Lib/idlelib/PyShell.py +@@ -552,7 +552,7 @@ + This method is called from the subprocess, and by returning from this + method we allow the subprocess to unblock. After a bit the shell + requests the subprocess to open the remote stack viewer which returns a +- static object looking at the last exceptiopn. It is queried through ++ static object looking at the last exception. It is queried through + the RPC mechanism. + + """ +--- a/Lib/idlelib/idlever.py ++++ b/Lib/idlelib/idlever.py +@@ -1 +1 @@ +-IDLE_VERSION = "2.7" ++IDLE_VERSION = "2.7.1a0" +--- a/Lib/json/tests/test_fail.py ++++ b/Lib/json/tests/test_fail.py +@@ -74,3 +74,12 @@ + pass + else: + self.fail("Expected failure for fail{0}.json: {1!r}".format(idx, doc)) ++ ++ def test_non_string_keys_dict(self): ++ data = {'a' : 1, (1, 2) : 2} ++ ++ #This is for c encoder ++ self.assertRaises(TypeError, json.dumps, data) ++ ++ #This is for python encoder ++ self.assertRaises(TypeError, json.dumps, data, indent=True) +--- a/Lib/json/__init__.py ++++ b/Lib/json/__init__.py +@@ -160,7 +160,7 @@ + + To use a custom ``JSONEncoder`` subclass (e.g. one that overrides the + ``.default()`` method to serialize additional types), specify it with +- the ``cls`` kwarg. ++ the ``cls`` kwarg; otherwise ``JSONEncoder`` is used. + + """ + # cached encoder +@@ -220,7 +220,7 @@ + + To use a custom ``JSONEncoder`` subclass (e.g. one that overrides the + ``.default()`` method to serialize additional types), specify it with +- the ``cls`` kwarg. ++ the ``cls`` kwarg; otherwise ``JSONEncoder`` is used. + + """ + # cached encoder +@@ -259,8 +259,16 @@ + ``object_hook`` will be used instead of the ``dict``. This feature + can be used to implement custom decoders (e.g. JSON-RPC class hinting). + ++ ``object_pairs_hook`` is an optional function that will be called with the ++ result of any object literal decoded with an ordered list of pairs. The ++ return value of ``object_pairs_hook`` will be used instead of the ``dict``. ++ This feature can be used to implement custom decoders that rely on the ++ order that the key and value pairs are decoded (for example, ++ collections.OrderedDict will remember the order of insertion). If ++ ``object_hook`` is also defined, the ``object_pairs_hook`` takes priority. ++ + To use a custom ``JSONDecoder`` subclass, specify it with the ``cls`` +- kwarg. ++ kwarg; otherwise ``JSONDecoder`` is used. + + """ + return loads(fp.read(), +@@ -285,6 +293,14 @@ + ``object_hook`` will be used instead of the ``dict``. This feature + can be used to implement custom decoders (e.g. JSON-RPC class hinting). + ++ ``object_pairs_hook`` is an optional function that will be called with the ++ result of any object literal decoded with an ordered list of pairs. The ++ return value of ``object_pairs_hook`` will be used instead of the ``dict``. ++ This feature can be used to implement custom decoders that rely on the ++ order that the key and value pairs are decoded (for example, ++ collections.OrderedDict will remember the order of insertion). If ++ ``object_hook`` is also defined, the ``object_pairs_hook`` takes priority. ++ + ``parse_float``, if specified, will be called with the string + of every JSON float to be decoded. By default this is equivalent to + float(num_str). This can be used to use another datatype or parser +@@ -301,7 +317,7 @@ + are encountered. + + To use a custom ``JSONDecoder`` subclass, specify it with the ``cls`` +- kwarg. ++ kwarg; otherwise ``JSONDecoder`` is used. + + """ + if (cls is None and encoding is None and object_hook is None and +--- a/Lib/json/decoder.py ++++ b/Lib/json/decoder.py +@@ -310,6 +310,15 @@ + place of the given ``dict``. This can be used to provide custom + deserializations (e.g. to support JSON-RPC class hinting). + ++ ``object_pairs_hook``, if specified will be called with the result of ++ every JSON object decoded with an ordered list of pairs. The return ++ value of ``object_pairs_hook`` will be used instead of the ``dict``. ++ This feature can be used to implement custom decoders that rely on the ++ order that the key and value pairs are decoded (for example, ++ collections.OrderedDict will remember the order of insertion). If ++ ``object_hook`` is also defined, the ``object_pairs_hook`` takes ++ priority. ++ + ``parse_float``, if specified, will be called with the string + of every JSON float to be decoded. By default this is equivalent to + float(num_str). This can be used to use another datatype or parser +@@ -325,6 +334,11 @@ + This can be used to raise an exception if invalid JSON numbers + are encountered. + ++ If ``strict`` is false (true is the default), then control ++ characters will be allowed inside strings. Control characters in ++ this context are those with character codes in the 0-31 range, ++ including ``'\\t'`` (tab), ``'\\n'``, ``'\\r'`` and ``'\\0'``. ++ + """ + self.encoding = encoding + self.object_hook = object_hook +--- a/Lib/smtpd.py ++++ b/Lib/smtpd.py +@@ -121,7 +121,15 @@ + self.__rcpttos = [] + self.__data = '' + self.__fqdn = socket.getfqdn() +- self.__peer = conn.getpeername() ++ try: ++ self.__peer = conn.getpeername() ++ except socket.error, err: ++ # a race condition may occur if the other end is closing ++ # before we can get the peername ++ self.close() ++ if err[0] != errno.ENOTCONN: ++ raise ++ return + print >> DEBUGSTREAM, 'Peer:', repr(self.__peer) + self.push('220 %s %s' % (self.__fqdn, __version__)) + self.set_terminator('\r\n') +@@ -291,7 +299,20 @@ + localaddr, remoteaddr) + + def handle_accept(self): +- conn, addr = self.accept() ++ try: ++ conn, addr = self.accept() ++ except TypeError: ++ # sometimes accept() might return None ++ return ++ except socket.error, err: ++ # ECONNABORTED might be thrown ++ if err[0] != errno.ECONNABORTED: ++ raise ++ return ++ else: ++ # sometimes addr == None instead of (ip, port) ++ if addr == None: ++ return + print >> DEBUGSTREAM, 'Incoming connection from %s' % repr(addr) + channel = SMTPChannel(self, conn, addr) + +--- a/Lib/unittest/test/test_case.py ++++ b/Lib/unittest/test/test_case.py +@@ -874,6 +874,21 @@ + # unicode strings - so we can't use it for this check + self.assertTrue(sample_text_error == error) + ++ def testAsertEqualSingleLine(self): ++ sample_text = u"laden swallows fly slowly" ++ revised_sample_text = u"unladen swallows fly quickly" ++ sample_text_error = """\ ++- laden swallows fly slowly ++? ^^^^ +++ unladen swallows fly quickly ++? ++ ^^^^^ ++""" ++ try: ++ self.assertEqual(sample_text, revised_sample_text) ++ except self.failureException as e: ++ error = str(e).split('\n', 1)[1] ++ self.assertTrue(sample_text_error == error) ++ + def testAssertIsNone(self): + self.assertIsNone(None) + self.assertRaises(self.failureException, self.assertIsNone, False) + +Property changes on: Lib/unittest/test +___________________________________________________________________ +Added: svn:ignore + + *.pyc +*.pyo + + +--- a/Lib/unittest/case.py ++++ b/Lib/unittest/case.py +@@ -895,9 +895,14 @@ + 'Second argument is not a string')) + + if first != second: +- standardMsg = '%s != %s' % (safe_repr(first, True), safe_repr(second, True)) +- diff = '\n' + ''.join(difflib.ndiff(first.splitlines(True), +- second.splitlines(True))) ++ firstlines = first.splitlines(True) ++ secondlines = second.splitlines(True) ++ if len(firstlines) == 1 and first.strip('\r\n') == first: ++ firstlines = [first + '\n'] ++ secondlines = [second + '\n'] ++ standardMsg = '%s != %s' % (safe_repr(first, True), ++ safe_repr(second, True)) ++ diff = '\n' + ''.join(difflib.ndiff(firstlines, secondlines)) + standardMsg = self._truncateMessage(standardMsg, diff) + self.fail(self._formatMessage(msg, standardMsg)) + + +Property changes on: Lib/unittest +___________________________________________________________________ +Added: svn:ignore + + *.pyc +*.pyo + + +--- a/Lib/_abcoll.py ++++ b/Lib/_abcoll.py +@@ -305,18 +305,24 @@ + return self + + def __ixor__(self, it): +- if not isinstance(it, Set): +- it = self._from_iterable(it) +- for value in it: +- if value in self: +- self.discard(value) +- else: +- self.add(value) ++ if it is self: ++ self.clear() ++ else: ++ if not isinstance(it, Set): ++ it = self._from_iterable(it) ++ for value in it: ++ if value in self: ++ self.discard(value) ++ else: ++ self.add(value) + return self + + def __isub__(self, it): +- for value in it: +- self.discard(value) ++ if it is self: ++ self.clear() ++ else: ++ for value in it: ++ self.discard(value) + return self + + MutableSet.register(set) +@@ -390,6 +396,10 @@ + + class KeysView(MappingView, Set): + ++ @classmethod ++ def _from_iterable(self, it): ++ return set(it) ++ + def __contains__(self, key): + return key in self._mapping + +@@ -400,6 +410,10 @@ + + class ItemsView(MappingView, Set): + ++ @classmethod ++ def _from_iterable(self, it): ++ return set(it) ++ + def __contains__(self, item): + key, value = item + try: +@@ -466,7 +480,15 @@ + except KeyError: + pass + +- def update(self, other=(), **kwds): ++ def update(*args, **kwds): ++ if len(args) > 2: ++ raise TypeError("update() takes at most 2 positional " ++ "arguments ({} given)".format(len(args))) ++ elif not args: ++ raise TypeError("update() takes at least 1 argument (0 given)") ++ self = args[0] ++ other = args[1] if len(args) >= 2 else () ++ + if isinstance(other, Mapping): + for key in other: + self[key] = other[key] +--- a/Lib/xmlrpclib.py ++++ b/Lib/xmlrpclib.py +@@ -1263,7 +1263,7 @@ + try: + return self.single_request(host, handler, request_body, verbose) + except socket.error, e: +- if i or e.errno not in (errno.ECONNRESET, errno.ECONNABORTED): ++ if i or e.errno not in (errno.ECONNRESET, errno.ECONNABORTED, errno.EPIPE): + raise + except httplib.BadStatusLine: #close after we sent request + if i: +--- a/Lib/optparse.py ++++ b/Lib/optparse.py +@@ -1008,7 +1008,7 @@ + """add_option(Option) + add_option(opt_str, ..., kwarg=val, ...) + """ +- if type(args[0]) is types.StringType: ++ if type(args[0]) in types.StringTypes: + option = self.option_class(*args, **kwargs) + elif len(args) == 1 and not kwargs: + option = args[0] +--- a/Lib/imaplib.py ++++ b/Lib/imaplib.py +@@ -751,7 +751,7 @@ + ', '.join(Commands[command]))) + name = 'UID' + typ, dat = self._simple_command(name, command, *args) +- if command in ('SEARCH', 'SORT'): ++ if command in ('SEARCH', 'SORT', 'THREAD'): + name = command + else: + name = 'FETCH' +--- a/Lib/posixpath.py ++++ b/Lib/posixpath.py +@@ -11,6 +11,7 @@ + """ + + import os ++import sys + import stat + import genericpath + import warnings +@@ -178,6 +179,9 @@ + + def ismount(path): + """Test whether a path is a mount point""" ++ if islink(path): ++ # A symlink can never be a mount point ++ return False + try: + s1 = os.lstat(path) + s2 = os.lstat(join(path, '..')) +@@ -391,7 +395,7 @@ + path = normpath(resolved) + return path + +-supports_unicode_filenames = False ++supports_unicode_filenames = (sys.platform == 'darwin') + + def relpath(path, start=curdir): + """Return a relative version of a path""" +--- a/Lib/distutils/__init__.py ++++ b/Lib/distutils/__init__.py +@@ -15,5 +15,5 @@ + # Updated automatically by the Python release process. + # + #--start constants-- +-__version__ = "2.7" ++__version__ = "2.7.1a0" + #--end constants-- +--- a/Lib/distutils/sysconfig.py ++++ b/Lib/distutils/sysconfig.py +@@ -318,6 +318,11 @@ + + fp.close() + ++ # strip spurious spaces ++ for k, v in done.items(): ++ if isinstance(v, str): ++ done[k] = v.strip() ++ + # save the results in the global dictionary + g.update(done) + return g +--- a/Lib/distutils/tests/test_msvc9compiler.py ++++ b/Lib/distutils/tests/test_msvc9compiler.py +@@ -60,7 +60,16 @@ + + """ + +-@unittest.skipUnless(sys.platform=="win32", "These tests are only for win32") ++if sys.platform=="win32": ++ from distutils.msvccompiler import get_build_version ++ if get_build_version()>=8.0: ++ SKIP_MESSAGE = None ++ else: ++ SKIP_MESSAGE = "These tests are only for MSVC8.0 or above" ++else: ++ SKIP_MESSAGE = "These tests are only for win32" ++ ++@unittest.skipUnless(SKIP_MESSAGE is None, SKIP_MESSAGE) + class msvc9compilerTestCase(support.TempdirManager, + unittest.TestCase): + +@@ -68,10 +77,6 @@ + # makes sure query_vcvarsall throws + # a DistutilsPlatformError if the compiler + # is not found +- from distutils.msvccompiler import get_build_version +- if get_build_version() < 8.0: +- # this test is only for MSVC8.0 or above +- return + from distutils.msvc9compiler import query_vcvarsall + def _find_vcvarsall(version): + return None +@@ -86,11 +91,6 @@ + msvc9compiler.find_vcvarsall = old_find_vcvarsall + + def test_reg_class(self): +- from distutils.msvccompiler import get_build_version +- if get_build_version() < 8.0: +- # this test is only for MSVC8.0 or above +- return +- + from distutils.msvc9compiler import Reg + self.assertRaises(KeyError, Reg.get_value, 'xxx', 'xxx') + +--- a/Lib/distutils/tests/test_dir_util.py ++++ b/Lib/distutils/tests/test_dir_util.py +@@ -1,7 +1,9 @@ + """Tests for distutils.dir_util.""" + import unittest + import os ++import stat + import shutil ++import sys + + from distutils.dir_util import (mkpath, remove_tree, create_tree, copy_tree, + ensure_relative) +@@ -48,6 +50,19 @@ + wanted = ["removing '%s' (and everything under it)" % self.root_target] + self.assertEquals(self._logs, wanted) + ++ @unittest.skipIf(sys.platform.startswith('win'), ++ "This test is only appropriate for POSIX-like systems.") ++ def test_mkpath_with_custom_mode(self): ++ # Get and set the current umask value for testing mode bits. ++ umask = os.umask(0o002) ++ os.umask(umask) ++ mkpath(self.target, 0o700) ++ self.assertEqual( ++ stat.S_IMODE(os.stat(self.target).st_mode), 0o700 & ~umask) ++ mkpath(self.target2, 0o555) ++ self.assertEqual( ++ stat.S_IMODE(os.stat(self.target2).st_mode), 0o555 & ~umask) ++ + def test_create_tree_verbosity(self): + + create_tree(self.root_target, ['one', 'two', 'three'], verbose=0) +--- a/Lib/distutils/tests/test_sdist.py ++++ b/Lib/distutils/tests/test_sdist.py +@@ -45,6 +45,7 @@ + """ + + MANIFEST = """\ ++# file GENERATED by distutils, do NOT edit + README + inroot.txt + setup.py +@@ -346,6 +347,7 @@ + finally: + archive.close() + ++ @unittest.skipUnless(zlib, "requires zlib") + def test_get_file_list(self): + # make sure MANIFEST is recalculated + dist, cmd = self.get_cmd() +@@ -363,7 +365,7 @@ + finally: + f.close() + +- self.assertEquals(len(manifest), 4) ++ self.assertEquals(len(manifest), 5) + + # adding a file + self.write_file((self.tmp_dir, 'somecode', 'doc2.txt'), '#') +@@ -383,10 +385,41 @@ + f.close() + + # do we have the new file in MANIFEST ? +- self.assertEquals(len(manifest2), 5) ++ self.assertEquals(len(manifest2), 6) + self.assertIn('doc2.txt', manifest2[-1]) + ++ def test_manifest_marker(self): ++ # check that autogenerated MANIFESTs have a marker ++ dist, cmd = self.get_cmd() ++ cmd.ensure_finalized() ++ cmd.run() + ++ f = open(cmd.manifest) ++ try: ++ manifest = [line.strip() for line in f.read().split('\n') ++ if line.strip() != ''] ++ finally: ++ f.close() ++ ++ self.assertEqual(manifest[0], ++ '# file GENERATED by distutils, do NOT edit') ++ ++ def test_manual_manifest(self): ++ # check that a MANIFEST without a marker is left alone ++ dist, cmd = self.get_cmd() ++ cmd.ensure_finalized() ++ self.write_file((self.tmp_dir, cmd.manifest), 'README.manual') ++ cmd.run() ++ ++ f = open(cmd.manifest) ++ try: ++ manifest = [line.strip() for line in f.read().split('\n') ++ if line.strip() != ''] ++ finally: ++ f.close() ++ ++ self.assertEqual(manifest, ['README.manual']) ++ + def test_suite(): + return unittest.makeSuite(SDistTestCase) + +--- a/Lib/distutils/dir_util.py ++++ b/Lib/distutils/dir_util.py +@@ -68,7 +68,7 @@ + + if not dry_run: + try: +- os.mkdir(head) ++ os.mkdir(head, mode) + created_dirs.append(head) + except OSError, exc: + raise DistutilsFileError, \ +--- a/Lib/distutils/util.py ++++ b/Lib/distutils/util.py +@@ -144,8 +144,7 @@ + cflags = get_config_vars().get('CFLAGS') + + archs = re.findall('-arch\s+(\S+)', cflags) +- archs.sort() +- archs = tuple(archs) ++ archs = tuple(sorted(set(archs))) + + if len(archs) == 1: + machine = archs[0] +--- a/Lib/distutils/command/build_clib.py ++++ b/Lib/distutils/command/build_clib.py +@@ -32,9 +32,9 @@ + description = "build C/C++ libraries used by Python extensions" + + user_options = [ +- ('build-clib', 'b', ++ ('build-clib=', 'b', + "directory to build C/C++ libraries to"), +- ('build-temp', 't', ++ ('build-temp=', 't', + "directory to put temporary build by-products"), + ('debug', 'g', + "compile with debugging information"), +--- a/Lib/distutils/command/bdist_msi.py ++++ b/Lib/distutils/command/bdist_msi.py +@@ -148,7 +148,7 @@ + if not self.skip_build and self.distribution.has_ext_modules()\ + and self.target_version != short_version: + raise DistutilsOptionError, \ +- "target version can only be %s, or the '--skip_build'" \ ++ "target version can only be %s, or the '--skip-build'" \ + " option must be specified" % (short_version,) + else: + self.versions = list(self.all_versions) +--- a/Lib/distutils/command/build_ext.py ++++ b/Lib/distutils/command/build_ext.py +@@ -753,7 +753,9 @@ + elif sys.platform == 'darwin': + # Don't use the default code below + return ext.libraries +- ++ elif sys.platform[:3] == 'aix': ++ # Don't use the default code below ++ return ext.libraries + else: + from distutils import sysconfig + if sysconfig.get_config_var('Py_ENABLE_SHARED'): +--- a/Lib/distutils/command/bdist_wininst.py ++++ b/Lib/distutils/command/bdist_wininst.py +@@ -95,7 +95,7 @@ + short_version = get_python_version() + if self.target_version and self.target_version != short_version: + raise DistutilsOptionError, \ +- "target version can only be %s, or the '--skip_build'" \ ++ "target version can only be %s, or the '--skip-build'" \ + " option must be specified" % (short_version,) + self.target_version = short_version + +--- a/Lib/distutils/command/upload.py ++++ b/Lib/distutils/command/upload.py +@@ -186,4 +186,5 @@ + self.announce('Upload failed (%s): %s' % (status, reason), + log.ERROR) + if self.show_response: +- self.announce('-'*75, result.read(), '-'*75) ++ msg = '\n'.join(('-' * 75, r.read(), '-' * 75)) ++ self.announce(msg, log.INFO) +--- a/Lib/distutils/command/sdist.py ++++ b/Lib/distutils/command/sdist.py +@@ -73,7 +73,7 @@ + ('dist-dir=', 'd', + "directory to put the source distribution archive(s) in " + "[default: dist]"), +- ('medata-check', None, ++ ('metadata-check', None, + "Ensure that all required elements of meta-data " + "are supplied. Warn if any missing. [default]"), + ('owner=', 'u', +@@ -349,8 +349,21 @@ + by 'add_defaults()' and 'read_template()') to the manifest file + named by 'self.manifest'. + """ +- self.execute(file_util.write_file, +- (self.manifest, self.filelist.files), ++ if os.path.isfile(self.manifest): ++ fp = open(self.manifest) ++ try: ++ first_line = fp.readline() ++ finally: ++ fp.close() ++ ++ if first_line != '# file GENERATED by distutils, do NOT edit\n': ++ log.info("not writing to manually maintained " ++ "manifest file '%s'" % self.manifest) ++ return ++ ++ content = self.filelist.files[:] ++ content.insert(0, '# file GENERATED by distutils, do NOT edit') ++ self.execute(file_util.write_file, (self.manifest, content), + "writing manifest file '%s'" % self.manifest) + + def read_manifest(self): +--- a/Lib/ntpath.py ++++ b/Lib/ntpath.py +@@ -399,6 +399,12 @@ + """Normalize path, eliminating double slashes, etc.""" + # Preserve unicode (if path is unicode) + backslash, dot = (u'\\', u'.') if isinstance(path, unicode) else ('\\', '.') ++ if path.startswith(('\\\\.\\', '\\\\?\\')): ++ # in the case of paths with these prefixes: ++ # \\.\ -> device names ++ # \\?\ -> literal paths ++ # do not do any normalization, but return the path unchanged ++ return path + path = path.replace("/", "\\") + prefix, path = splitdrive(path) + # We need to be careful here. If the prefix is empty, and the path starts +--- a/Lib/gzip.py ++++ b/Lib/gzip.py +@@ -138,6 +138,13 @@ + s = repr(self.fileobj) + return '' + ++ def _check_closed(self): ++ """Raises a ValueError if the underlying file object has been closed. ++ ++ """ ++ if self.closed: ++ raise ValueError('I/O operation on closed file.') ++ + def _init_write(self, filename): + self.name = filename + self.crc = zlib.crc32("") & 0xffffffffL +@@ -202,6 +209,7 @@ + self.fileobj.read(2) # Read & discard the 16-bit header CRC + + def write(self,data): ++ self._check_closed() + if self.mode != WRITE: + import errno + raise IOError(errno.EBADF, "write() on read-only GzipFile object") +@@ -222,6 +230,7 @@ + return len(data) + + def read(self, size=-1): ++ self._check_closed() + if self.mode != READ: + import errno + raise IOError(errno.EBADF, "read() on write-only GzipFile object") +@@ -359,6 +368,7 @@ + self.myfileobj = None + + def flush(self,zlib_mode=zlib.Z_SYNC_FLUSH): ++ self._check_closed() + if self.mode == WRITE: + # Ensure the compressor's buffer is flushed + self.fileobj.write(self.compress.flush(zlib_mode)) +--- a/Lib/copy.py ++++ b/Lib/copy.py +@@ -328,17 +328,7 @@ + args = deepcopy(args, memo) + y = callable(*args) + memo[id(x)] = y +- if listiter is not None: +- for item in listiter: +- if deep: +- item = deepcopy(item, memo) +- y.append(item) +- if dictiter is not None: +- for key, value in dictiter: +- if deep: +- key = deepcopy(key, memo) +- value = deepcopy(value, memo) +- y[key] = value ++ + if state: + if deep: + state = deepcopy(state, memo) +@@ -354,6 +344,18 @@ + if slotstate is not None: + for key, value in slotstate.iteritems(): + setattr(y, key, value) ++ ++ if listiter is not None: ++ for item in listiter: ++ if deep: ++ item = deepcopy(item, memo) ++ y.append(item) ++ if dictiter is not None: ++ for key, value in dictiter: ++ if deep: ++ key = deepcopy(key, memo) ++ value = deepcopy(value, memo) ++ y[key] = value + return y + + del d +@@ -416,6 +418,16 @@ + print map(repr.repr, l1) + print map(repr.repr, l2) + print map(repr.repr, l3) ++ class odict(dict): ++ def __init__(self, d = {}): ++ self.a = 99 ++ dict.__init__(self, d) ++ def __setitem__(self, k, i): ++ dict.__setitem__(self, k, i) ++ self.a ++ o = odict({"A" : "B"}) ++ x = deepcopy(o) ++ print(o, x) + + if __name__ == '__main__': + _test() +--- a/Lib/macpath.py ++++ b/Lib/macpath.py +@@ -212,4 +212,4 @@ + pass + return path + +-supports_unicode_filenames = False ++supports_unicode_filenames = True +--- a/Lib/random.py ++++ b/Lib/random.py +@@ -46,6 +46,7 @@ + from math import sqrt as _sqrt, acos as _acos, cos as _cos, sin as _sin + from os import urandom as _urandom + from binascii import hexlify as _hexlify ++import hashlib as _hashlib + + __all__ = ["Random","seed","random","uniform","randint","choice","sample", + "randrange","shuffle","normalvariate","lognormvariate", +@@ -141,6 +142,18 @@ + "Random.setstate() of version %s" % + (version, self.VERSION)) + ++ def jumpahead(self, n): ++ """Change the internal state to one that is likely far away ++ from the current state. This method will not be in Py3.x, ++ so it is better to simply reseed. ++ """ ++ # The super.jumpahead() method uses shuffling to change state, ++ # so it needs a large and "interesting" n to work with. Here, ++ # we use hashing to create a large n for the shuffle. ++ s = repr(n) + repr(self.getstate()) ++ n = int(_hashlib.new('sha512', s).hexdigest(), 16) ++ super(Random, self).jumpahead(n) ++ + ## ---- Methods below this point do not need to be overridden when + ## ---- subclassing for the purpose of using a different core generator. + +@@ -292,15 +305,6 @@ + large population: sample(xrange(10000000), 60) + """ + +- # XXX Although the documentation says `population` is "a sequence", +- # XXX attempts are made to cater to any iterable with a __len__ +- # XXX method. This has had mixed success. Examples from both +- # XXX sides: sets work fine, and should become officially supported; +- # XXX dicts are much harder, and have failed in various subtle +- # XXX ways across attempts. Support for mapping types should probably +- # XXX be dropped (and users should pass mapping.keys() or .values() +- # XXX explicitly). +- + # Sampling without replacement entails tracking either potential + # selections (the pool) in a list or previous selections in a set. + +--- a/Lib/fnmatch.py ++++ b/Lib/fnmatch.py +@@ -12,10 +12,15 @@ + + import re + +-__all__ = ["filter", "fnmatch","fnmatchcase","translate"] ++__all__ = ["filter", "fnmatch", "fnmatchcase", "translate"] + + _cache = {} ++_MAXCACHE = 100 + ++def _purge(): ++ """Clear the pattern cache""" ++ _cache.clear() ++ + def fnmatch(name, pat): + """Test whether FILENAME matches PATTERN. + +@@ -44,6 +49,8 @@ + pat=os.path.normcase(pat) + if not pat in _cache: + res = translate(pat) ++ if len(_cache) >= _MAXCACHE: ++ _cache.clear() + _cache[pat] = re.compile(res) + match=_cache[pat].match + if os.path is posixpath: +@@ -66,6 +73,8 @@ + + if not pat in _cache: + res = translate(pat) ++ if len(_cache) >= _MAXCACHE: ++ _cache.clear() + _cache[pat] = re.compile(res) + return _cache[pat].match(name) is not None + +--- a/Lib/encodings/utf_16.py ++++ b/Lib/encodings/utf_16.py +@@ -34,6 +34,22 @@ + codecs.IncrementalEncoder.reset(self) + self.encoder = None + ++ def getstate(self): ++ # state info we return to the caller: ++ # 0: stream is in natural order for this platform ++ # 2: endianness hasn't been determined yet ++ # (we're never writing in unnatural order) ++ return (2 if self.encoder is None else 0) ++ ++ def setstate(self, state): ++ if state: ++ self.encoder = None ++ else: ++ if sys.byteorder == 'little': ++ self.encoder = codecs.utf_16_le_encode ++ else: ++ self.encoder = codecs.utf_16_be_encode ++ + class IncrementalDecoder(codecs.BufferedIncrementalDecoder): + def __init__(self, errors='strict'): + codecs.BufferedIncrementalDecoder.__init__(self, errors) +--- a/Lib/encodings/utf_8_sig.py ++++ b/Lib/encodings/utf_8_sig.py +@@ -25,19 +25,25 @@ + class IncrementalEncoder(codecs.IncrementalEncoder): + def __init__(self, errors='strict'): + codecs.IncrementalEncoder.__init__(self, errors) +- self.first = True ++ self.first = 1 + + def encode(self, input, final=False): + if self.first: +- self.first = False ++ self.first = 0 + return codecs.BOM_UTF8 + codecs.utf_8_encode(input, self.errors)[0] + else: + return codecs.utf_8_encode(input, self.errors)[0] + + def reset(self): + codecs.IncrementalEncoder.reset(self) +- self.first = True ++ self.first = 1 + ++ def getstate(self): ++ return self.first ++ ++ def setstate(self, state): ++ self.first = state ++ + class IncrementalDecoder(codecs.BufferedIncrementalDecoder): + def __init__(self, errors='strict'): + codecs.BufferedIncrementalDecoder.__init__(self, errors) +--- a/Lib/asyncore.py ++++ b/Lib/asyncore.py +@@ -53,7 +53,7 @@ + import warnings + + import os +-from errno import EALREADY, EINPROGRESS, EWOULDBLOCK, ECONNRESET, \ ++from errno import EALREADY, EINPROGRESS, EWOULDBLOCK, ECONNRESET, EINVAL, \ + ENOTCONN, ESHUTDOWN, EINTR, EISCONN, EBADF, ECONNABORTED, errorcode + + try: +@@ -337,8 +337,8 @@ + def connect(self, address): + self.connected = False + err = self.socket.connect_ex(address) +- # XXX Should interpret Winsock return values +- if err in (EINPROGRESS, EALREADY, EWOULDBLOCK): ++ if err in (EINPROGRESS, EALREADY, EWOULDBLOCK) \ ++ or err == EINVAL and os.name in ('nt', 'ce'): + return + if err in (0, EISCONN): + self.addr = address +@@ -435,8 +435,11 @@ + self.handle_read() + + def handle_connect_event(self): ++ err = self.socket.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR) ++ if err != 0: ++ raise socket.error(err, _strerror(err)) ++ self.handle_connect() + self.connected = True +- self.handle_connect() + + def handle_write_event(self): + if self.accepting: +@@ -607,6 +610,14 @@ + def send(self, *args): + return os.write(self.fd, *args) + ++ def getsockopt(self, level, optname, buflen=None): ++ if (level == socket.SOL_SOCKET and ++ optname == socket.SO_ERROR and ++ not buflen): ++ return 0 ++ raise NotImplementedError("Only asyncore specific behaviour " ++ "implemented.") ++ + read = recv + write = send + +--- a/Lib/base64.py ++++ b/Lib/base64.py +@@ -343,7 +343,8 @@ + if o == '-u': func = decode + if o == '-t': test1(); return + if args and args[0] != '-': +- func(open(args[0], 'rb'), sys.stdout) ++ with open(args[0], 'rb') as f: ++ func(f, sys.stdout) + else: + func(sys.stdin, sys.stdout) + +--- a/Lib/socket.py ++++ b/Lib/socket.py +@@ -189,7 +189,9 @@ + for method in _delegate_methods: + setattr(self, method, getattr(_sock, method)) + +- def close(self): ++ def close(self, _closedsocket=_closedsocket, ++ _delegate_methods=_delegate_methods, setattr=setattr): ++ # This function should not reference any globals. See issue #808164. + self._sock = _closedsocket() + dummy = self._sock._dummy + for method in _delegate_methods: +@@ -546,8 +548,8 @@ + An host of '' or port 0 tells the OS to use the default. + """ + +- msg = "getaddrinfo returns an empty list" + host, port = address ++ err = None + for res in getaddrinfo(host, port, 0, SOCK_STREAM): + af, socktype, proto, canonname, sa = res + sock = None +@@ -560,8 +562,12 @@ + sock.connect(sa) + return sock + +- except error, msg: ++ except error as _: ++ err = _ + if sock is not None: + sock.close() + +- raise error, msg ++ if err is not None: ++ raise err ++ else: ++ raise error("getaddrinfo returns an empty list") +--- a/Lib/pickletools.py ++++ b/Lib/pickletools.py +@@ -1214,10 +1214,11 @@ + stack_before=[anyobject], + stack_after=[pytuple], + proto=2, +- doc="""One-tuple. ++ doc="""Build a one-tuple out of the topmost item on the stack. + + This code pops one value off the stack and pushes a tuple of +- length 1 whose one item is that value back onto it. IOW: ++ length 1 whose one item is that value back onto it. In other ++ words: + + stack[-1] = tuple(stack[-1:]) + """), +@@ -1228,10 +1229,11 @@ + stack_before=[anyobject, anyobject], + stack_after=[pytuple], + proto=2, +- doc="""One-tuple. ++ doc="""Build a two-tuple out of the top two items on the stack. + +- This code pops two values off the stack and pushes a tuple +- of length 2 whose items are those values back onto it. IOW: ++ This code pops two values off the stack and pushes a tuple of ++ length 2 whose items are those values back onto it. In other ++ words: + + stack[-2:] = [tuple(stack[-2:])] + """), +@@ -1242,10 +1244,11 @@ + stack_before=[anyobject, anyobject, anyobject], + stack_after=[pytuple], + proto=2, +- doc="""One-tuple. ++ doc="""Build a three-tuple out of the top three items on the stack. + +- This code pops three values off the stack and pushes a tuple +- of length 3 whose items are those values back onto it. IOW: ++ This code pops three values off the stack and pushes a tuple of ++ length 3 whose items are those values back onto it. In other ++ words: + + stack[-3:] = [tuple(stack[-3:])] + """), +--- a/Lib/decimal.py ++++ b/Lib/decimal.py +@@ -1990,12 +1990,14 @@ + # case where xc == 1: result is 10**(xe*y), with xe*y + # required to be an integer + if xc == 1: +- if ye >= 0: +- exponent = xe*yc*10**ye +- else: +- exponent, remainder = divmod(xe*yc, 10**-ye) +- if remainder: +- return None ++ xe *= yc ++ # result is now 10**(xe * 10**ye); xe * 10**ye must be integral ++ while xe % 10 == 0: ++ xe //= 10 ++ ye += 1 ++ if ye < 0: ++ return None ++ exponent = xe * 10**ye + if y.sign == 1: + exponent = -exponent + # if other is a nonnegative integer, use ideal exponent +@@ -2268,9 +2270,10 @@ + # try for an exact result with precision +1 + if ans is None: + ans = self._power_exact(other, context.prec + 1) +- if ans is not None and result_sign == 1: +- ans = _dec_from_triple(1, ans._int, ans._exp) +- exact = True ++ if ans is not None: ++ if result_sign == 1: ++ ans = _dec_from_triple(1, ans._int, ans._exp) ++ exact = True + + # usual case: inexact result, x**y computed directly as exp(y*log(x)) + if ans is None: +@@ -3753,23 +3756,39 @@ + Emin=None, Emax=None, + capitals=None, _clamp=0, + _ignored_flags=None): +- if flags is None: +- flags = [] ++ # Set defaults; for everything except flags and _ignored_flags, ++ # inherit from DefaultContext. ++ try: ++ dc = DefaultContext ++ except NameError: ++ pass ++ ++ self.prec = prec if prec is not None else dc.prec ++ self.rounding = rounding if rounding is not None else dc.rounding ++ self.Emin = Emin if Emin is not None else dc.Emin ++ self.Emax = Emax if Emax is not None else dc.Emax ++ self.capitals = capitals if capitals is not None else dc.capitals ++ self._clamp = _clamp if _clamp is not None else dc._clamp ++ + if _ignored_flags is None: +- _ignored_flags = [] +- if not isinstance(flags, dict): +- flags = dict([(s, int(s in flags)) for s in _signals]) +- del s +- if traps is not None and not isinstance(traps, dict): +- traps = dict([(s, int(s in traps)) for s in _signals]) +- del s +- for name, val in locals().items(): +- if val is None: +- setattr(self, name, _copy.copy(getattr(DefaultContext, name))) +- else: +- setattr(self, name, val) +- del self.self ++ self._ignored_flags = [] ++ else: ++ self._ignored_flags = _ignored_flags + ++ if traps is None: ++ self.traps = dc.traps.copy() ++ elif not isinstance(traps, dict): ++ self.traps = dict((s, int(s in traps)) for s in _signals) ++ else: ++ self.traps = traps ++ ++ if flags is None: ++ self.flags = dict.fromkeys(_signals, 0) ++ elif not isinstance(flags, dict): ++ self.flags = dict((s, int(s in flags)) for s in _signals) ++ else: ++ self.flags = flags ++ + def __repr__(self): + """Show the current context.""" + s = [] +--- a/Lib/logging/__init__.py ++++ b/Lib/logging/__init__.py +@@ -617,12 +617,16 @@ + """ + Remove a handler reference from the internal cleanup list. + """ +- _acquireLock() +- try: +- if wr in _handlerList: +- _handlerList.remove(wr) +- finally: +- _releaseLock() ++ # This function can be called during module teardown, when globals are ++ # set to None. If _acquireLock is None, assume this is the case and do ++ # nothing. ++ if _acquireLock is not None: ++ _acquireLock() ++ try: ++ if wr in _handlerList: ++ _handlerList.remove(wr) ++ finally: ++ _releaseLock() + + def _addHandlerRef(handler): + """ +@@ -1207,7 +1211,7 @@ + if filename == _srcfile: + f = f.f_back + continue +- rv = (filename, f.f_lineno, co.co_name) ++ rv = (co.co_filename, f.f_lineno, co.co_name) + break + return rv + +@@ -1259,20 +1263,23 @@ + """ + Add the specified handler to this logger. + """ +- if not (hdlr in self.handlers): +- self.handlers.append(hdlr) ++ _acquireLock() ++ try: ++ if not (hdlr in self.handlers): ++ self.handlers.append(hdlr) ++ finally: ++ _releaseLock() + + def removeHandler(self, hdlr): + """ + Remove the specified handler from this logger. + """ +- if hdlr in self.handlers: +- #hdlr.close() +- hdlr.acquire() +- try: ++ _acquireLock() ++ try: ++ if hdlr in self.handlers: + self.handlers.remove(hdlr) +- finally: +- hdlr.release() ++ finally: ++ _releaseLock() + + def callHandlers(self, record): + """ +@@ -1493,22 +1500,28 @@ + using sys.stdout or sys.stderr), whereas FileHandler closes its stream + when the handler is closed. + """ +- if len(root.handlers) == 0: +- filename = kwargs.get("filename") +- if filename: +- mode = kwargs.get("filemode", 'a') +- hdlr = FileHandler(filename, mode) +- else: +- stream = kwargs.get("stream") +- hdlr = StreamHandler(stream) +- fs = kwargs.get("format", BASIC_FORMAT) +- dfs = kwargs.get("datefmt", None) +- fmt = Formatter(fs, dfs) +- hdlr.setFormatter(fmt) +- root.addHandler(hdlr) +- level = kwargs.get("level") +- if level is not None: +- root.setLevel(level) ++ # Add thread safety in case someone mistakenly calls ++ # basicConfig() from multiple threads ++ _acquireLock() ++ try: ++ if len(root.handlers) == 0: ++ filename = kwargs.get("filename") ++ if filename: ++ mode = kwargs.get("filemode", 'a') ++ hdlr = FileHandler(filename, mode) ++ else: ++ stream = kwargs.get("stream") ++ hdlr = StreamHandler(stream) ++ fs = kwargs.get("format", BASIC_FORMAT) ++ dfs = kwargs.get("datefmt", None) ++ fmt = Formatter(fs, dfs) ++ hdlr.setFormatter(fmt) ++ root.addHandler(hdlr) ++ level = kwargs.get("level") ++ if level is not None: ++ root.setLevel(level) ++ finally: ++ _releaseLock() + + #--------------------------------------------------------------------------- + # Utility functions at module level. +@@ -1612,8 +1625,16 @@ + #we just ignore them if raiseExceptions is not set + try: + h = wr() +- h.flush() +- h.close() ++ if h: ++ try: ++ h.flush() ++ h.close() ++ except (IOError, ValueError): ++ # Ignore errors which might be caused ++ # because handlers have been closed but ++ # references to them are still around at ++ # application exit. ++ pass + except: + if raiseExceptions: + raise +@@ -1635,9 +1656,15 @@ + a NullHandler and add it to the top-level logger of the library module or + package. + """ ++ def handle(self, record): ++ pass ++ + def emit(self, record): + pass + ++ def createLock(self): ++ self.lock = None ++ + # Warnings integration + + _warnings_showwarning = None +--- a/Lib/logging/handlers.py ++++ b/Lib/logging/handlers.py +@@ -108,8 +108,13 @@ + + If maxBytes is zero, rollover never occurs. + """ ++ # If rotation/rollover is wanted, it doesn't make sense to use another ++ # mode. If for example 'w' were specified, then if there were multiple ++ # runs of the calling application, the logs from previous runs would be ++ # lost if the 'w' is respected, because the log file would be truncated ++ # on each run. + if maxBytes > 0: +- mode = 'a' # doesn't make sense otherwise! ++ mode = 'a' + BaseRotatingHandler.__init__(self, filename, mode, encoding, delay) + self.maxBytes = maxBytes + self.backupCount = backupCount +@@ -781,20 +786,19 @@ + The record is formatted, and then sent to the syslog server. If + exception information is present, it is NOT sent to the server. + """ +- msg = self.format(record) ++ msg = self.format(record) + '\000' + """ + We need to convert record level to lowercase, maybe this will + change in the future. + """ +- msg = self.log_format_string % ( +- self.encodePriority(self.facility, +- self.mapPriority(record.levelname)), +- msg) +- # Treat unicode messages as required by RFC 5424 +- if _unicode and type(msg) is unicode: ++ prio = '<%d>' % self.encodePriority(self.facility, ++ self.mapPriority(record.levelname)) ++ # Message is a string. Convert to bytes as required by RFC 5424 ++ if type(msg) is unicode: + msg = msg.encode('utf-8') + if codecs: + msg = codecs.BOM_UTF8 + msg ++ msg = prio + msg + try: + if self.unixsocket: + try: +@@ -1018,7 +1022,7 @@ + """ + Emit a record. + +- Send the record to the Web server as an URL-encoded dictionary ++ Send the record to the Web server as a percent-encoded dictionary + """ + try: + import httplib, urllib +--- a/Lib/logging/config.py ++++ b/Lib/logging/config.py +@@ -895,8 +895,10 @@ + Stop the listening server which was created with a call to listen(). + """ + global _listener +- if _listener: +- logging._acquireLock() +- _listener.abort = 1 +- _listener = None ++ logging._acquireLock() ++ try: ++ if _listener: ++ _listener.abort = 1 ++ _listener = None ++ finally: + logging._releaseLock() +--- a/Lib/cookielib.py ++++ b/Lib/cookielib.py +@@ -607,19 +607,14 @@ + return req_host, erhn + + def request_path(request): +- """request-URI, as defined by RFC 2965.""" ++ """Path component of request-URI, as defined by RFC 2965.""" + url = request.get_full_url() +- #scheme, netloc, path, parameters, query, frag = urlparse.urlparse(url) +- #req_path = escape_path("".join(urlparse.urlparse(url)[2:])) +- path, parameters, query, frag = urlparse.urlparse(url)[2:] +- if parameters: +- path = "%s;%s" % (path, parameters) +- path = escape_path(path) +- req_path = urlparse.urlunparse(("", "", path, "", query, frag)) +- if not req_path.startswith("/"): ++ parts = urlparse.urlsplit(url) ++ path = escape_path(parts.path) ++ if not path.startswith("/"): + # fix bad RFC 2396 absoluteURI +- req_path = "/"+req_path +- return req_path ++ path = "/" + path ++ return path + + def request_port(request): + host = request.get_host() +--- a/Lib/hotshot/log.py ++++ b/Lib/hotshot/log.py +@@ -106,7 +106,10 @@ + return what, t, tdelta + + if what == WHAT_EXIT: +- return what, self._pop(), tdelta ++ try: ++ return what, self._pop(), tdelta ++ except IndexError: ++ raise StopIteration + + if what == WHAT_LINENO: + filename, firstlineno, funcname = self._stack[-1] +--- a/Lib/getopt.py ++++ b/Lib/getopt.py +@@ -155,7 +155,7 @@ + if not args: + raise GetoptError('option --%s requires argument' % opt, opt) + optarg, args = args[0], args[1:] +- elif optarg: ++ elif optarg is not None: + raise GetoptError('option --%s must not have an argument' % opt, opt) + opts.append(('--' + opt, optarg or '')) + return opts, args +--- a/Lib/inspect.py ++++ b/Lib/inspect.py +@@ -157,7 +157,7 @@ + + Generator function objects provides same attributes as functions. + +- See isfunction.__doc__ for attributes listing.""" ++ See help(isfunction) for attributes listing.""" + return bool((isfunction(object) or ismethod(object)) and + object.func_code.co_flags & CO_GENERATOR) + +--- a/Lib/string.py ++++ b/Lib/string.py +@@ -508,15 +508,15 @@ + return s.capitalize() + + # Substring replacement (global) +-def replace(s, old, new, maxsplit=-1): +- """replace (str, old, new[, maxsplit]) -> string ++def replace(s, old, new, maxreplace=-1): ++ """replace (str, old, new[, maxreplace]) -> string + + Return a copy of string str with all occurrences of substring +- old replaced by new. If the optional argument maxsplit is +- given, only the first maxsplit occurrences are replaced. ++ old replaced by new. If the optional argument maxreplace is ++ given, only the first maxreplace occurrences are replaced. + + """ +- return s.replace(old, new, maxsplit) ++ return s.replace(old, new, maxreplace) + + + # Try importing optional built-in module "strop" -- if it exists, +@@ -607,7 +607,7 @@ + return str(value) + elif conversion is None: + return value +- raise ValueError("Unknown converion specifier {0!s}".format(conversion)) ++ raise ValueError("Unknown conversion specifier {0!s}".format(conversion)) + + + # returns an iterable that contains tuples of the form: +--- a/Lib/runpy.py ++++ b/Lib/runpy.py +@@ -261,7 +261,7 @@ + _ModifiedArgv0(path_name): + mod_globals = temp_module.module.__dict__ + return _run_code(code, mod_globals, init_globals, +- run_name, fname, loader, pkg_name) ++ run_name, fname, loader, pkg_name).copy() + finally: + try: + sys.path.remove(path_name) +--- a/Lib/collections.py ++++ b/Lib/collections.py +@@ -12,7 +12,33 @@ + import heapq as _heapq + from itertools import repeat as _repeat, chain as _chain, starmap as _starmap, \ + ifilter as _ifilter, imap as _imap ++try: ++ from thread import get_ident ++except AttributeError: ++ from dummy_thread import get_ident + ++def _recursive_repr(user_function): ++ 'Decorator to make a repr function return "..." for a recursive call' ++ repr_running = set() ++ ++ def wrapper(self): ++ key = id(self), get_ident() ++ if key in repr_running: ++ return '...' ++ repr_running.add(key) ++ try: ++ result = user_function(self) ++ finally: ++ repr_running.discard(key) ++ return result ++ ++ # Can't use functools.wraps() here because of bootstrap issues ++ wrapper.__module__ = getattr(user_function, '__module__') ++ wrapper.__doc__ = getattr(user_function, '__doc__') ++ wrapper.__name__ = getattr(user_function, '__name__') ++ return wrapper ++ ++ + ################################################################################ + ### OrderedDict + ################################################################################ +@@ -119,6 +145,18 @@ + iteritems = MutableMapping.iteritems + __ne__ = MutableMapping.__ne__ + ++ def viewkeys(self): ++ "od.viewkeys() -> a set-like object providing a view on od's keys" ++ return KeysView(self) ++ ++ def viewvalues(self): ++ "od.viewvalues() -> an object providing a view on od's values" ++ return ValuesView(self) ++ ++ def viewitems(self): ++ "od.viewitems() -> a set-like object providing a view on od's items" ++ return ItemsView(self) ++ + def popitem(self, last=True): + '''od.popitem() -> (k, v), return and remove a (key, value) pair. + Pairs are returned in LIFO order if last is true or FIFO order if false. +@@ -130,6 +168,7 @@ + value = self.pop(key) + return key, value + ++ @_recursive_repr + def __repr__(self): + 'od.__repr__() <==> repr(od)' + if not self: +@@ -161,10 +200,7 @@ + all(_imap(_eq, self.iteritems(), other.iteritems())) + return dict.__eq__(self, other) + +- def __del__(self): +- self.clear() # eliminate cyclical references + +- + ################################################################################ + ### namedtuple + ################################################################################ + +Property changes on: Lib/pydoc_data +___________________________________________________________________ +Added: svn:ignore + + *.pyc +*.pyo + + +--- a/Lib/ctypes/test/test_callbacks.py ++++ b/Lib/ctypes/test/test_callbacks.py +@@ -205,7 +205,6 @@ + return True #Allow windows to keep enumerating + + windll.user32.EnumWindows(EnumWindowsCallbackFunc, 0) +- self.assertFalse(windowCount == 0) + + ################################################################ + +--- a/Lib/ctypes/util.py ++++ b/Lib/ctypes/util.py +@@ -185,7 +185,7 @@ + def _findLib_ldconfig(name): + # XXX assuming GLIBC's ldconfig (with option -p) + expr = r'/[^\(\)\s]*lib%s\.[^\(\)\s]*' % re.escape(name) +- f = os.popen('LANG=C /sbin/ldconfig -p 2>/dev/null') ++ f = os.popen('LC_ALL=C LANG=C /sbin/ldconfig -p 2>/dev/null') + try: + data = f.read() + finally: +--- a/Lib/abc.py ++++ b/Lib/abc.py +@@ -5,6 +5,7 @@ + + import types + ++from _weakrefset import WeakSet + + # Instance of old-style class + class _C: pass +@@ -95,9 +96,9 @@ + abstracts.add(name) + cls.__abstractmethods__ = frozenset(abstracts) + # Set up inheritance registry +- cls._abc_registry = set() +- cls._abc_cache = set() +- cls._abc_negative_cache = set() ++ cls._abc_registry = WeakSet() ++ cls._abc_cache = WeakSet() ++ cls._abc_negative_cache = WeakSet() + cls._abc_negative_cache_version = ABCMeta._abc_invalidation_counter + return cls + +@@ -128,7 +129,7 @@ + """Override for isinstance(instance, cls).""" + # Inline the cache checking when it's simple. + subclass = getattr(instance, '__class__', None) +- if subclass in cls._abc_cache: ++ if subclass is not None and subclass in cls._abc_cache: + return True + subtype = type(instance) + # Old-style instances +@@ -152,7 +153,7 @@ + # Check negative cache; may have to invalidate + if cls._abc_negative_cache_version < ABCMeta._abc_invalidation_counter: + # Invalidate the negative cache +- cls._abc_negative_cache = set() ++ cls._abc_negative_cache = WeakSet() + cls._abc_negative_cache_version = ABCMeta._abc_invalidation_counter + elif subclass in cls._abc_negative_cache: + return False +--- a/Lib/cgi.py ++++ b/Lib/cgi.py +@@ -132,7 +132,7 @@ + environ : environment dictionary; default: os.environ + + keep_blank_values: flag indicating whether blank values in +- URL encoded forms should be treated as blank strings. ++ percent-encoded forms should be treated as blank strings. + A true value indicates that blanks should be retained as + blank strings. The default false value indicates that + blank values are to be ignored and treated as if they were +@@ -411,7 +411,7 @@ + environ : environment dictionary; default: os.environ + + keep_blank_values: flag indicating whether blank values in +- URL encoded forms should be treated as blank strings. ++ percent-encoded forms should be treated as blank strings. + A true value indicates that blanks should be retained as + blank strings. The default false value indicates that + blank values are to be ignored and treated as if they were +--- a/Lib/robotparser.py ++++ b/Lib/robotparser.py +@@ -68,7 +68,9 @@ + def _add_entry(self, entry): + if "*" in entry.useragents: + # the default entry is considered last +- self.default_entry = entry ++ if self.default_entry is None: ++ # the first default entry wins ++ self.default_entry = entry + else: + self.entries.append(entry) + +@@ -120,7 +122,7 @@ + entry.rulelines.append(RuleLine(line[1], True)) + state = 2 + if state == 2: +- self.entries.append(entry) ++ self._add_entry(entry) + + + def can_fetch(self, useragent, url): +@@ -131,7 +133,12 @@ + return True + # search for given user agent matches + # the first match counts +- url = urllib.quote(urlparse.urlparse(urllib.unquote(url))[2]) or "/" ++ parsed_url = urlparse.urlparse(urllib.unquote(url)) ++ url = urlparse.urlunparse(('', '', parsed_url.path, ++ parsed_url.params, parsed_url.query, parsed_url.fragment)) ++ url = urllib.quote(url) ++ if not url: ++ url = "/" + for entry in self.entries: + if entry.applies_to(useragent): + return entry.allowance(url) +--- a/Lib/pdb.py ++++ b/Lib/pdb.py +@@ -183,14 +183,18 @@ + + def user_return(self, frame, return_value): + """This function is called when a return trap is set here.""" ++ if self._wait_for_mainpyfile: ++ return + frame.f_locals['__return__'] = return_value + print >>self.stdout, '--Return--' + self.interaction(frame, None) + + def user_exception(self, frame, exc_info): +- exc_type, exc_value, exc_traceback = exc_info + """This function is called if an exception occurs, + but only if we are to stop at or just below this level.""" ++ if self._wait_for_mainpyfile: ++ return ++ exc_type, exc_value, exc_traceback = exc_info + frame.f_locals['__exception__'] = exc_type, exc_value + if type(exc_type) == type(''): + exc_type_name = exc_type +@@ -277,8 +281,10 @@ + return self.handle_command_def(line) + + def handle_command_def(self,line): +- """ Handles one command line during command list definition. """ ++ """Handles one command line during command list definition.""" + cmd, arg, line = self.parseline(line) ++ if not cmd: ++ return + if cmd == 'silent': + self.commands_silent[self.commands_bnum] = True + return # continue to handle other cmd def in the cmd list +@@ -286,7 +292,7 @@ + self.cmdqueue = [] + return 1 # end of cmd list + cmdlist = self.commands[self.commands_bnum] +- if (arg): ++ if arg: + cmdlist.append(cmd+' '+arg) + else: + cmdlist.append(cmd) +@@ -329,9 +335,11 @@ + prompt_back = self.prompt + self.prompt = '(com) ' + self.commands_defining = True +- self.cmdloop() +- self.commands_defining = False +- self.prompt = prompt_back ++ try: ++ self.cmdloop() ++ finally: ++ self.commands_defining = False ++ self.prompt = prompt_back + + def do_break(self, arg, temporary = 0): + # break [ ([filename:]lineno | function) [, "condition"] ] +@@ -467,7 +475,10 @@ + Return `lineno` if it is, 0 if not (e.g. a docstring, comment, blank + line or EOF). Warning: testing is not comprehensive. + """ +- line = linecache.getline(filename, lineno, self.curframe.f_globals) ++ # this method should be callable before starting debugging, so default ++ # to "no globals" if there is no current frame ++ globs = self.curframe.f_globals if hasattr(self, 'curframe') else None ++ line = linecache.getline(filename, lineno, globs) + if not line: + print >>self.stdout, 'End of file' + return 0 +@@ -1298,7 +1309,7 @@ + # changed by the user from the command line. There is a "restart" command + # which allows explicit specification of command line arguments. + pdb = Pdb() +- while 1: ++ while True: + try: + pdb._runscript(mainpyfile) + if pdb._user_requested_quit: +--- a/Lib/Cookie.py ++++ b/Lib/Cookie.py +@@ -534,6 +534,8 @@ + r"(?P" # Start of group 'val' + r'"(?:[^\\"]|\\.)*"' # Any doublequoted string + r"|" # or ++ r"\w{3},\s[\w\d-]{9,11}\s[\d:]{8}\sGMT" # Special case for "expires" attr ++ r"|" # or + ""+ _LegalCharsPatt +"*" # Any word or empty string + r")" # End of group 'val' + r"\s*;?" # Probably ending in a semi-colon +--- a/Lib/pydoc.py ++++ b/Lib/pydoc.py +@@ -1705,10 +1705,13 @@ + 'CONTEXTMANAGERS': ('context-managers', 'with'), + } + +- def __init__(self, input, output): +- self.input = input +- self.output = output ++ def __init__(self, input=None, output=None): ++ self._input = input ++ self._output = output + ++ input = property(lambda self: self._input or sys.stdin) ++ output = property(lambda self: self._output or sys.stdout) ++ + def __repr__(self): + if inspect.stack()[1][3] == '?': + self() +@@ -1884,7 +1887,7 @@ + for modules whose descriptions contain the word "spam". + ''') + +-help = Helper(sys.stdin, sys.stdout) ++help = Helper() + + class Scanner: + """A generic tree iterator.""" +@@ -2029,7 +2032,7 @@ + class DocServer(BaseHTTPServer.HTTPServer): + def __init__(self, port, callback): + host = 'localhost' +- self.address = ('', port) ++ self.address = (host, port) + self.url = 'http://%s:%d/' % (host, port) + self.callback = callback + self.base.__init__(self, self.address, self.handler) +--- a/Lib/_pyio.py ++++ b/Lib/_pyio.py +@@ -546,6 +546,8 @@ + return self.readall() + b = bytearray(n.__index__()) + n = self.readinto(b) ++ if n is None: ++ return None + del b[n:] + return bytes(b) + +@@ -563,7 +565,7 @@ + """Read up to len(b) bytes into b. + + Returns number of bytes read (0 for EOF), or None if the object +- is set not to block as has no data to read. ++ is set not to block and has no data to read. + """ + self._unsupported("readinto") + +--- a/Lib/gettext.py ++++ b/Lib/gettext.py +@@ -471,7 +471,7 @@ + # once. + result = None + for mofile in mofiles: +- key = os.path.abspath(mofile) ++ key = (class_, os.path.abspath(mofile)) + t = _translations.get(key) + if t is None: + with open(mofile, 'rb') as fp: +--- a/Lib/urllib.py ++++ b/Lib/urllib.py +@@ -1216,6 +1216,8 @@ + """ + # fastpath + if not s: ++ if s is None: ++ raise TypeError('None object cannot be quoted') + return s + cachekey = (safe, always_safe) + try: +@@ -1453,6 +1455,7 @@ + proxies['http'] = proxyServer + else: + proxies['http'] = 'http://%s' % proxyServer ++ proxies['https'] = 'https://%s' % proxyServer + proxies['ftp'] = 'ftp://%s' % proxyServer + internetSettings.Close() + except (WindowsError, ValueError, TypeError): +--- a/Lib/trace.py ++++ b/Lib/trace.py +@@ -56,9 +56,9 @@ + import time + import token + import tokenize +-import types ++import inspect + import gc +- ++import dis + try: + import cPickle + pickle = cPickle +@@ -195,11 +195,13 @@ + base = path[len(longest) + 1:] + else: + base = path ++ # the drive letter is never part of the module name ++ drive, base = os.path.splitdrive(base) + base = base.replace(os.sep, ".") + if os.altsep: + base = base.replace(os.altsep, ".") + filename, ext = os.path.splitext(base) +- return filename ++ return filename.lstrip(".") + + class CoverageResults: + def __init__(self, counts=None, calledfuncs=None, infile=None, +@@ -377,13 +379,7 @@ + """Return dict where keys are lines in the line number table.""" + linenos = {} + +- line_increments = [ord(c) for c in code.co_lnotab[1::2]] +- table_length = len(line_increments) +- docstring = False +- +- lineno = code.co_firstlineno +- for li in line_increments: +- lineno += li ++ for _, lineno in dis.findlinestarts(code): + if lineno not in strs: + linenos[lineno] = 1 + +@@ -396,7 +392,7 @@ + + # and check the constants for references to other code objects + for c in code.co_consts: +- if isinstance(c, types.CodeType): ++ if inspect.iscode(c): + # find another code object, so recurse into it + linenos.update(find_lines(c, strs)) + return linenos +@@ -492,8 +488,8 @@ + import __main__ + dict = __main__.__dict__ + if not self.donothing: ++ threading.settrace(self.globaltrace) + sys.settrace(self.globaltrace) +- threading.settrace(self.globaltrace) + try: + exec cmd in dict, dict + finally: +@@ -505,8 +501,8 @@ + if globals is None: globals = {} + if locals is None: locals = {} + if not self.donothing: ++ threading.settrace(self.globaltrace) + sys.settrace(self.globaltrace) +- threading.settrace(self.globaltrace) + try: + exec cmd in globals, locals + finally: +@@ -543,7 +539,7 @@ + ## use of gc.get_referrers() was suggested by Michael Hudson + # all functions which refer to this code object + funcs = [f for f in gc.get_referrers(code) +- if hasattr(f, "func_doc")] ++ if inspect.isfunction(f)] + # require len(func) == 1 to avoid ambiguity caused by calls to + # new.function(): "In the face of ambiguity, refuse the + # temptation to guess." +@@ -555,17 +551,13 @@ + if hasattr(c, "__bases__")] + if len(classes) == 1: + # ditto for new.classobj() +- clsname = str(classes[0]) ++ clsname = classes[0].__name__ + # cache the result - assumption is that new.* is + # not called later to disturb this relationship + # _caller_cache could be flushed if functions in + # the new module get called. + self._caller_cache[code] = clsname + if clsname is not None: +- # final hack - module name shows up in str(cls), but we've already +- # computed module name, so remove it +- clsname = clsname.split(".")[1:] +- clsname = ".".join(clsname) + funcname = "%s.%s" % (clsname, funcname) + + return filename, modulename, funcname +@@ -798,7 +790,16 @@ + ignoredirs=ignore_dirs, infile=counts_file, + outfile=counts_file, timing=timing) + try: +- t.run('execfile(%r)' % (progname,)) ++ with open(progname) as fp: ++ code = compile(fp.read(), progname, 'exec') ++ # try to emulate __main__ namespace as much as possible ++ globs = { ++ '__file__': progname, ++ '__name__': '__main__', ++ '__package__': None, ++ '__cached__': None, ++ } ++ t.runctx(code, globs, globs) + except IOError, err: + _err_exit("Cannot run file %r because: %s" % (sys.argv[0], err)) + except SystemExit: +--- a/Lib/cProfile.py ++++ b/Lib/cProfile.py +@@ -36,7 +36,7 @@ + result = prof.print_stats(sort) + return result + +-def runctx(statement, globals, locals, filename=None): ++def runctx(statement, globals, locals, filename=None, sort=-1): + """Run statement under profiler, supplying your own globals and locals, + optionally saving results in filename. + +@@ -53,7 +53,7 @@ + if filename is not None: + prof.dump_stats(filename) + else: +- result = prof.print_stats() ++ result = prof.print_stats(sort) + return result + + # Backwards compatibility. +@@ -169,7 +169,8 @@ + parser.add_option('-o', '--outfile', dest="outfile", + help="Save stats to ", default=None) + parser.add_option('-s', '--sort', dest="sort", +- help="Sort order when printing to stdout, based on pstats.Stats class", default=-1) ++ help="Sort order when printing to stdout, based on pstats.Stats class", ++ default=-1) + + if not sys.argv[1:]: + parser.print_usage() +@@ -178,9 +179,17 @@ + (options, args) = parser.parse_args() + sys.argv[:] = args + +- if (len(sys.argv) > 0): +- sys.path.insert(0, os.path.dirname(sys.argv[0])) +- run('execfile(%r)' % (sys.argv[0],), options.outfile, options.sort) ++ if len(args) > 0: ++ progname = args[0] ++ sys.path.insert(0, os.path.dirname(progname)) ++ with open(progname, 'rb') as fp: ++ code = compile(fp.read(), progname, 'exec') ++ globs = { ++ '__file__': progname, ++ '__name__': '__main__', ++ '__package__': None, ++ } ++ runctx(code, globs, None, options.outfile, options.sort) + else: + parser.print_usage() + return parser +--- a/Lib/cmd.py ++++ b/Lib/cmd.py +@@ -137,7 +137,7 @@ + if not len(line): + line = 'EOF' + else: +- line = line[:-1] # chop \n ++ line = line.rstrip('\r\n') + line = self.precmd(line) + stop = self.onecmd(line) + stop = self.postcmd(stop, line) +--- a/Lib/sysconfig.py ++++ b/Lib/sysconfig.py +@@ -93,21 +93,28 @@ + _EXEC_PREFIX = os.path.normpath(sys.exec_prefix) + _CONFIG_VARS = None + _USER_BASE = None ++ ++def _safe_realpath(path): ++ try: ++ return realpath(path) ++ except OSError: ++ return path ++ + if sys.executable: +- _PROJECT_BASE = os.path.dirname(realpath(sys.executable)) ++ _PROJECT_BASE = os.path.dirname(_safe_realpath(sys.executable)) + else: + # sys.executable can be empty if argv[0] has been changed and Python is + # unable to retrieve the real program name +- _PROJECT_BASE = realpath(os.getcwd()) ++ _PROJECT_BASE = _safe_realpath(os.getcwd()) + + if os.name == "nt" and "pcbuild" in _PROJECT_BASE[-8:].lower(): +- _PROJECT_BASE = realpath(os.path.join(_PROJECT_BASE, pardir)) ++ _PROJECT_BASE = _safe_realpath(os.path.join(_PROJECT_BASE, pardir)) + # PC/VS7.1 + if os.name == "nt" and "\\pc\\v" in _PROJECT_BASE[-10:].lower(): +- _PROJECT_BASE = realpath(os.path.join(_PROJECT_BASE, pardir, pardir)) ++ _PROJECT_BASE = _safe_realpath(os.path.join(_PROJECT_BASE, pardir, pardir)) + # PC/AMD64 + if os.name == "nt" and "\\pcbuild\\amd64" in _PROJECT_BASE[-14:].lower(): +- _PROJECT_BASE = realpath(os.path.join(_PROJECT_BASE, pardir, pardir)) ++ _PROJECT_BASE = _safe_realpath(os.path.join(_PROJECT_BASE, pardir, pardir)) + + def is_python_build(): + for fn in ("Setup.dist", "Setup.local"): +@@ -251,6 +258,11 @@ + else: + # bogus variable reference; just drop it since we can't deal + del notdone[name] ++ # strip spurious spaces ++ for k, v in done.items(): ++ if isinstance(v, str): ++ done[k] = v.strip() ++ + # save the results in the global dictionary + vars.update(done) + return vars +@@ -277,7 +289,8 @@ + # load the installed pyconfig.h: + config_h = get_config_h_filename() + try: +- parse_config_h(open(config_h), vars) ++ with open(config_h) as f: ++ parse_config_h(f, vars) + except IOError, e: + msg = "invalid Python installation: unable to open %s" % config_h + if hasattr(e, "strerror"): +@@ -314,7 +327,7 @@ + vars['SO'] = '.pyd' + vars['EXE'] = '.exe' + vars['VERSION'] = _PY_VERSION_SHORT_NO_DOT +- vars['BINDIR'] = os.path.dirname(realpath(sys.executable)) ++ vars['BINDIR'] = os.path.dirname(_safe_realpath(sys.executable)) + + # + # public APIs +@@ -434,8 +447,12 @@ + # from a different directory. + if _PYTHON_BUILD and os.name == "posix": + base = _PROJECT_BASE ++ try: ++ cwd = os.getcwd() ++ except OSError: ++ cwd = None + if (not os.path.isabs(_CONFIG_VARS['srcdir']) and +- base != os.getcwd()): ++ base != cwd): + # srcdir is relative and we are not in the same directory + # as the executable. Assume executable is in the build + # directory and make srcdir absolute. +@@ -645,8 +662,7 @@ + cflags = get_config_vars().get('CFLAGS') + + archs = re.findall('-arch\s+(\S+)', cflags) +- archs.sort() +- archs = tuple(archs) ++ archs = tuple(sorted(set(archs))) + + if len(archs) == 1: + machine = archs[0] +--- a/Lib/platform.py ++++ b/Lib/platform.py +@@ -727,28 +727,20 @@ + + return hex(bcd)[2:] + +-def mac_ver(release='',versioninfo=('','',''),machine=''): +- +- """ Get MacOS version information and return it as tuple (release, +- versioninfo, machine) with versioninfo being a tuple (version, +- dev_stage, non_release_version). +- +- Entries which cannot be determined are set to the paramter values +- which default to ''. All tuple entries are strings. +- ++def _mac_ver_gestalt(): ++ """ + Thanks to Mark R. Levinson for mailing documentation links and + code examples for this function. Documentation for the + gestalt() API is available online at: + + http://www.rgaros.nl/gestalt/ +- + """ + # Check whether the version info module is available + try: + import gestalt + import MacOS + except ImportError: +- return release,versioninfo,machine ++ return None + # Get the infos + sysv,sysa = _mac_ver_lookup(('sysv','sysa')) + # Decode the infos +@@ -772,8 +764,55 @@ + machine = {0x1: '68k', + 0x2: 'PowerPC', + 0xa: 'i386'}.get(sysa,'') ++ + return release,versioninfo,machine + ++def _mac_ver_xml(): ++ fn = '/System/Library/CoreServices/SystemVersion.plist' ++ if not os.path.exists(fn): ++ return None ++ ++ try: ++ import plistlib ++ except ImportError: ++ return None ++ ++ pl = plistlib.readPlist(fn) ++ release = pl['ProductVersion'] ++ versioninfo=('', '', '') ++ machine = os.uname()[4] ++ if machine in ('ppc', 'Power Macintosh'): ++ # for compatibility with the gestalt based code ++ machine = 'PowerPC' ++ ++ return release,versioninfo,machine ++ ++ ++def mac_ver(release='',versioninfo=('','',''),machine=''): ++ ++ """ Get MacOS version information and return it as tuple (release, ++ versioninfo, machine) with versioninfo being a tuple (version, ++ dev_stage, non_release_version). ++ ++ Entries which cannot be determined are set to the paramter values ++ which default to ''. All tuple entries are strings. ++ """ ++ ++ # First try reading the information from an XML file which should ++ # always be present ++ info = _mac_ver_xml() ++ if info is not None: ++ return info ++ ++ # If that doesn't work for some reason fall back to reading the ++ # information using gestalt calls. ++ info = _mac_ver_gestalt() ++ if info is not None: ++ return info ++ ++ # If that also doesn't work return the default values ++ return release,versioninfo,machine ++ + def _java_getprop(name,default): + + from java.lang import System +--- a/Lib/tarfile.py ++++ b/Lib/tarfile.py +@@ -928,8 +928,8 @@ + self.chksum = 0 # header checksum + self.type = REGTYPE # member type + self.linkname = "" # link name +- self.uname = "root" # user name +- self.gname = "root" # group name ++ self.uname = "" # user name ++ self.gname = "" # group name + self.devmajor = 0 # device major number + self.devminor = 0 # device minor number + +@@ -1112,8 +1112,8 @@ + info.get("type", REGTYPE), + stn(info.get("linkname", ""), 100), + stn(info.get("magic", POSIX_MAGIC), 8), +- stn(info.get("uname", "root"), 32), +- stn(info.get("gname", "root"), 32), ++ stn(info.get("uname", ""), 32), ++ stn(info.get("gname", ""), 32), + itn(info.get("devmajor", 0), 8, format), + itn(info.get("devminor", 0), 8, format), + stn(info.get("prefix", ""), 155) +--- a/Lib/lib2to3/pytree.py ++++ b/Lib/lib2to3/pytree.py +@@ -16,7 +16,6 @@ + import warnings + from StringIO import StringIO + +- + HUGE = 0x7FFFFFFF # maximum repeat count, default max + + _type_reprs = {} +@@ -30,7 +29,6 @@ + if type(val) == int: _type_reprs[val] = name + return _type_reprs.setdefault(type_num, type_num) + +- + class Base(object): + + """ +@@ -47,6 +45,7 @@ + parent = None # Parent node pointer, or None + children = () # Tuple of subnodes + was_changed = False ++ was_checked = False + + def __new__(cls, *args, **kwds): + """Constructor that prevents Base from being instantiated.""" +@@ -213,6 +212,16 @@ + return None + return self.parent.children[i-1] + ++ def leaves(self): ++ for child in self.children: ++ for x in child.leaves(): ++ yield x ++ ++ def depth(self): ++ if self.parent is None: ++ return 0 ++ return 1 + self.parent.depth() ++ + def get_suffix(self): + """ + Return the string immediately following the invocant node. This is +@@ -227,12 +236,14 @@ + def __str__(self): + return unicode(self).encode("ascii") + +- + class Node(Base): + + """Concrete implementation for interior nodes.""" + +- def __init__(self, type, children, context=None, prefix=None): ++ def __init__(self,type, children, ++ context=None, ++ prefix=None, ++ fixers_applied=None): + """ + Initializer. + +@@ -249,6 +260,10 @@ + ch.parent = self + if prefix is not None: + self.prefix = prefix ++ if fixers_applied: ++ self.fixers_applied = fixers_applied[:] ++ else: ++ self.fixers_applied = None + + def __repr__(self): + """Return a canonical string representation.""" +@@ -273,7 +288,8 @@ + + def clone(self): + """Return a cloned (deep) copy of self.""" +- return Node(self.type, [ch.clone() for ch in self.children]) ++ return Node(self.type, [ch.clone() for ch in self.children], ++ fixers_applied=self.fixers_applied) + + def post_order(self): + """Return a post-order iterator for the tree.""" +@@ -286,7 +302,7 @@ + """Return a pre-order iterator for the tree.""" + yield self + for child in self.children: +- for node in child.post_order(): ++ for node in child.pre_order(): + yield node + + def _prefix_getter(self): +@@ -341,7 +357,10 @@ + lineno = 0 # Line where this token starts in the input + column = 0 # Column where this token tarts in the input + +- def __init__(self, type, value, context=None, prefix=None): ++ def __init__(self, type, value, ++ context=None, ++ prefix=None, ++ fixers_applied=[]): + """ + Initializer. + +@@ -355,6 +374,7 @@ + self.value = value + if prefix is not None: + self._prefix = prefix ++ self.fixers_applied = fixers_applied[:] + + def __repr__(self): + """Return a canonical string representation.""" +@@ -380,8 +400,12 @@ + def clone(self): + """Return a cloned (deep) copy of self.""" + return Leaf(self.type, self.value, +- (self.prefix, (self.lineno, self.column))) ++ (self.prefix, (self.lineno, self.column)), ++ fixers_applied=self.fixers_applied) + ++ def leaves(self): ++ yield self ++ + def post_order(self): + """Return a post-order iterator for the tree.""" + yield self +--- a/Lib/lib2to3/fixer_util.py ++++ b/Lib/lib2to3/fixer_util.py +@@ -1,6 +1,8 @@ + """Utility functions, node construction macros, etc.""" + # Author: Collin Winter + ++from itertools import islice ++ + # Local imports + from .pgen2 import token + from .pytree import Leaf, Node +@@ -14,7 +16,7 @@ + + def KeywordArg(keyword, value): + return Node(syms.argument, +- [keyword, Leaf(token.EQUAL, u'='), value]) ++ [keyword, Leaf(token.EQUAL, u"="), value]) + + def LParen(): + return Leaf(token.LPAR, u"(") +@@ -76,9 +78,9 @@ + + def Subscript(index_node): + """A numeric or string subscript""" +- return Node(syms.trailer, [Leaf(token.LBRACE, u'['), ++ return Node(syms.trailer, [Leaf(token.LBRACE, u"["), + index_node, +- Leaf(token.RBRACE, u']')]) ++ Leaf(token.RBRACE, u"]")]) + + def String(string, prefix=None): + """A string leaf""" +@@ -120,9 +122,9 @@ + # Pull the leaves out of their old tree + leaf.remove() + +- children = [Leaf(token.NAME, u'from'), ++ children = [Leaf(token.NAME, u"from"), + Leaf(token.NAME, package_name, prefix=u" "), +- Leaf(token.NAME, u'import', prefix=u" "), ++ Leaf(token.NAME, u"import", prefix=u" "), + Node(syms.import_as_names, name_leafs)] + imp = Node(syms.import_from, children) + return imp +@@ -245,6 +247,16 @@ + return False + return True + ++def find_indentation(node): ++ """Find the indentation of *node*.""" ++ while node is not None: ++ if node.type == syms.suite and len(node.children) > 2: ++ indent = node.children[1] ++ if indent.type == token.INDENT: ++ return indent.value ++ node = node.parent ++ return u"" ++ + ########################################################### + ### The following functions are to find bindings in a suite + ########################################################### +@@ -283,8 +295,8 @@ + """ Works like `does_tree_import` but adds an import statement + if it was not imported. """ + def is_import_stmt(node): +- return node.type == syms.simple_stmt and node.children and \ +- is_import(node.children[0]) ++ return (node.type == syms.simple_stmt and node.children and ++ is_import(node.children[0])) + + root = find_root(node) + +@@ -307,18 +319,18 @@ + # if that also fails, we stick to the beginning of the file + if insert_pos == 0: + for idx, node in enumerate(root.children): +- if node.type == syms.simple_stmt and node.children and \ +- node.children[0].type == token.STRING: ++ if (node.type == syms.simple_stmt and node.children and ++ node.children[0].type == token.STRING): + insert_pos = idx + 1 + break + + if package is None: + import_ = Node(syms.import_name, [ +- Leaf(token.NAME, u'import'), +- Leaf(token.NAME, name, prefix=u' ') ++ Leaf(token.NAME, u"import"), ++ Leaf(token.NAME, name, prefix=u" ") + ]) + else: +- import_ = FromImport(package, [Leaf(token.NAME, name, prefix=u' ')]) ++ import_ = FromImport(package, [Leaf(token.NAME, name, prefix=u" ")]) + + children = [import_, Newline()] + root.insert_child(insert_pos, Node(syms.simple_stmt, children)) +@@ -404,7 +416,7 @@ + if package and unicode(node.children[1]).strip() != package: + return None + n = node.children[3] +- if package and _find(u'as', n): ++ if package and _find(u"as", n): + # See test_from_import_as for explanation + return None + elif n.type == syms.import_as_names and _find(name, n): +--- a/Lib/lib2to3/tests/test_util.py ++++ b/Lib/lib2to3/tests/test_util.py +@@ -575,3 +575,20 @@ + node = parse('bar()') + fixer_util.touch_import(None, "cgi", node) + self.assertEqual(str(node), 'import cgi\nbar()\n\n') ++ ++class Test_find_indentation(support.TestCase): ++ ++ def test_nothing(self): ++ fi = fixer_util.find_indentation ++ node = parse("node()") ++ self.assertEqual(fi(node), u"") ++ node = parse("") ++ self.assertEqual(fi(node), u"") ++ ++ def test_simple(self): ++ fi = fixer_util.find_indentation ++ node = parse("def f():\n x()") ++ self.assertEqual(fi(node), u"") ++ self.assertEqual(fi(node.children[0].children[4].children[2]), u" ") ++ node = parse("def f():\n x()\n y()") ++ self.assertEqual(fi(node.children[0].children[4].children[4]), u" ") +--- a/Lib/lib2to3/tests/test_fixers.py ++++ b/Lib/lib2to3/tests/test_fixers.py +@@ -868,6 +868,11 @@ + raise Exception(5).with_traceback(6) # foo""" + self.check(b, a) + ++ def test_None_value(self): ++ b = """raise Exception(5), None, tb""" ++ a = """raise Exception(5).with_traceback(tb)""" ++ self.check(b, a) ++ + def test_tuple_value(self): + b = """raise Exception, (5, 6, 7)""" + a = """raise Exception(5, 6, 7)""" +@@ -1812,12 +1817,42 @@ + b = "from %s import %s as foo_bar" % (old, member) + a = "from %s import %s as foo_bar" % (new, member) + self.check(b, a) ++ b = "from %s import %s as blah, %s" % (old, member, member) ++ a = "from %s import %s as blah, %s" % (new, member, member) ++ self.check(b, a) + + def test_star(self): + for old in self.modules: + s = "from %s import *" % old + self.warns_unchanged(s, "Cannot handle star imports") + ++ def test_indented(self): ++ b = """ ++def foo(): ++ from urllib import urlencode, urlopen ++""" ++ a = """ ++def foo(): ++ from urllib.parse import urlencode ++ from urllib.request import urlopen ++""" ++ self.check(b, a) ++ ++ b = """ ++def foo(): ++ other() ++ from urllib import urlencode, urlopen ++""" ++ a = """ ++def foo(): ++ other() ++ from urllib.parse import urlencode ++ from urllib.request import urlopen ++""" ++ self.check(b, a) ++ ++ ++ + def test_import_module_usage(self): + for old, changes in self.modules.items(): + for new, members in changes: +@@ -3623,6 +3658,10 @@ + a = "from itertools import bar, foo" + self.check(b, a) + ++ b = "from itertools import chain, imap, izip" ++ a = "from itertools import chain" ++ self.check(b, a) ++ + def test_comments(self): + b = "#foo\nfrom itertools import imap, izip" + a = "#foo\n" +@@ -3670,7 +3709,11 @@ + a = "from itertools import bar, filterfalse, foo" + self.check(b, a) + ++ def test_import_star(self): ++ s = "from itertools import *" ++ self.unchanged(s) + ++ + def test_unchanged(self): + s = "from itertools import foo" + self.unchanged(s) +@@ -4299,15 +4342,91 @@ + a = "operator.contains(x, y)" + self.check(b, a) + ++ b = "operator .sequenceIncludes(x, y)" ++ a = "operator .contains(x, y)" ++ self.check(b, a) ++ ++ b = "operator. sequenceIncludes(x, y)" ++ a = "operator. contains(x, y)" ++ self.check(b, a) ++ ++ def test_operator_isSequenceType(self): ++ b = "operator.isSequenceType(x)" ++ a = "import collections\nisinstance(x, collections.Sequence)" ++ self.check(b, a) ++ ++ def test_operator_isMappingType(self): ++ b = "operator.isMappingType(x)" ++ a = "import collections\nisinstance(x, collections.Mapping)" ++ self.check(b, a) ++ ++ def test_operator_isNumberType(self): ++ b = "operator.isNumberType(x)" ++ a = "import numbers\nisinstance(x, numbers.Number)" ++ self.check(b, a) ++ ++ def test_operator_repeat(self): ++ b = "operator.repeat(x, n)" ++ a = "operator.mul(x, n)" ++ self.check(b, a) ++ ++ b = "operator .repeat(x, n)" ++ a = "operator .mul(x, n)" ++ self.check(b, a) ++ ++ b = "operator. repeat(x, n)" ++ a = "operator. mul(x, n)" ++ self.check(b, a) ++ ++ def test_operator_irepeat(self): ++ b = "operator.irepeat(x, n)" ++ a = "operator.imul(x, n)" ++ self.check(b, a) ++ ++ b = "operator .irepeat(x, n)" ++ a = "operator .imul(x, n)" ++ self.check(b, a) ++ ++ b = "operator. irepeat(x, n)" ++ a = "operator. imul(x, n)" ++ self.check(b, a) ++ + def test_bare_isCallable(self): + s = "isCallable(x)" +- self.warns_unchanged(s, "You should use hasattr(x, '__call__') here.") ++ t = "You should use 'hasattr(x, '__call__')' here." ++ self.warns_unchanged(s, t) + + def test_bare_sequenceIncludes(self): + s = "sequenceIncludes(x, y)" +- self.warns_unchanged(s, "You should use operator.contains here.") ++ t = "You should use 'operator.contains(x, y)' here." ++ self.warns_unchanged(s, t) + ++ def test_bare_operator_isSequenceType(self): ++ s = "isSequenceType(z)" ++ t = "You should use 'isinstance(z, collections.Sequence)' here." ++ self.warns_unchanged(s, t) + ++ def test_bare_operator_isMappingType(self): ++ s = "isMappingType(x)" ++ t = "You should use 'isinstance(x, collections.Mapping)' here." ++ self.warns_unchanged(s, t) ++ ++ def test_bare_operator_isNumberType(self): ++ s = "isNumberType(y)" ++ t = "You should use 'isinstance(y, numbers.Number)' here." ++ self.warns_unchanged(s, t) ++ ++ def test_bare_operator_repeat(self): ++ s = "repeat(x, n)" ++ t = "You should use 'operator.mul(x, n)' here." ++ self.warns_unchanged(s, t) ++ ++ def test_bare_operator_irepeat(self): ++ s = "irepeat(y, 187)" ++ t = "You should use 'operator.imul(y, 187)' here." ++ self.warns_unchanged(s, t) ++ ++ + class Test_exitfunc(FixerTestCase): + + fixer = "exitfunc" +--- a/Lib/lib2to3/tests/data/bom.py ++++ b/Lib/lib2to3/tests/data/bom.py +@@ -1,3 +1,2 @@ + # coding: utf-8 + print "BOM BOOM!" +- +--- a/Lib/lib2to3/tests/test_pytree.py ++++ b/Lib/lib2to3/tests/test_pytree.py +@@ -178,17 +178,42 @@ + self.assertEqual(str(n1), "foo**bar") + self.assertTrue(isinstance(n1.children, list)) + ++ def test_leaves(self): ++ l1 = pytree.Leaf(100, "foo") ++ l2 = pytree.Leaf(100, "bar") ++ l3 = pytree.Leaf(100, "fooey") ++ n2 = pytree.Node(1000, [l1, l2]) ++ n3 = pytree.Node(1000, [l3]) ++ n1 = pytree.Node(1000, [n2, n3]) ++ ++ self.assertEqual(list(n1.leaves()), [l1, l2, l3]) ++ ++ def test_depth(self): ++ l1 = pytree.Leaf(100, "foo") ++ l2 = pytree.Leaf(100, "bar") ++ n2 = pytree.Node(1000, [l1, l2]) ++ n3 = pytree.Node(1000, []) ++ n1 = pytree.Node(1000, [n2, n3]) ++ ++ self.assertEqual(l1.depth(), 2) ++ self.assertEqual(n3.depth(), 1) ++ self.assertEqual(n1.depth(), 0) ++ + def test_post_order(self): + l1 = pytree.Leaf(100, "foo") + l2 = pytree.Leaf(100, "bar") +- n1 = pytree.Node(1000, [l1, l2]) +- self.assertEqual(list(n1.post_order()), [l1, l2, n1]) ++ l3 = pytree.Leaf(100, "fooey") ++ c1 = pytree.Node(1000, [l1, l2]) ++ n1 = pytree.Node(1000, [c1, l3]) ++ self.assertEqual(list(n1.post_order()), [l1, l2, c1, l3, n1]) + + def test_pre_order(self): + l1 = pytree.Leaf(100, "foo") + l2 = pytree.Leaf(100, "bar") +- n1 = pytree.Node(1000, [l1, l2]) +- self.assertEqual(list(n1.pre_order()), [n1, l1, l2]) ++ l3 = pytree.Leaf(100, "fooey") ++ c1 = pytree.Node(1000, [l1, l2]) ++ n1 = pytree.Node(1000, [c1, l3]) ++ self.assertEqual(list(n1.pre_order()), [n1, c1, l1, l2, l3]) + + def test_changed(self): + l1 = pytree.Leaf(100, "f") +--- a/Lib/lib2to3/Grammar.txt ++++ b/Lib/lib2to3/Grammar.txt +@@ -128,7 +128,7 @@ + '`' testlist1 '`' | + NAME | NUMBER | STRING+ | '.' '.' '.') + listmaker: (test|star_expr) ( comp_for | (',' (test|star_expr))* [','] ) +-testlist_gexp: test ( comp_for | (',' (test|star_expr))* [','] ) ++testlist_gexp: (test|star_expr) ( comp_for | (',' (test|star_expr))* [','] ) + lambdef: 'lambda' [varargslist] ':' test + trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME + subscriptlist: subscript (',' subscript)* [','] +--- a/Lib/lib2to3/pygram.py ++++ b/Lib/lib2to3/pygram.py +@@ -13,6 +13,8 @@ + + # The grammar file + _GRAMMAR_FILE = os.path.join(os.path.dirname(__file__), "Grammar.txt") ++_PATTERN_GRAMMAR_FILE = os.path.join(os.path.dirname(__file__), ++ "PatternGrammar.txt") + + + class Symbols(object): +@@ -33,3 +35,6 @@ + + python_grammar_no_print_statement = python_grammar.copy() + del python_grammar_no_print_statement.keywords["print"] ++ ++pattern_grammar = driver.load_grammar(_PATTERN_GRAMMAR_FILE) ++pattern_symbols = Symbols(pattern_grammar) +--- a/Lib/lib2to3/btm_utils.py ++++ b/Lib/lib2to3/btm_utils.py +@@ -0,0 +1,283 @@ ++"Utility functions used by the btm_matcher module" ++ ++from . import pytree ++from .pgen2 import grammar, token ++from .pygram import pattern_symbols, python_symbols ++ ++syms = pattern_symbols ++pysyms = python_symbols ++tokens = grammar.opmap ++token_labels = token ++ ++TYPE_ANY = -1 ++TYPE_ALTERNATIVES = -2 ++TYPE_GROUP = -3 ++ ++class MinNode(object): ++ """This class serves as an intermediate representation of the ++ pattern tree during the conversion to sets of leaf-to-root ++ subpatterns""" ++ ++ def __init__(self, type=None, name=None): ++ self.type = type ++ self.name = name ++ self.children = [] ++ self.leaf = False ++ self.parent = None ++ self.alternatives = [] ++ self.group = [] ++ ++ def __repr__(self): ++ return str(self.type) + ' ' + str(self.name) ++ ++ def leaf_to_root(self): ++ """Internal method. Returns a characteristic path of the ++ pattern tree. This method must be run for all leaves until the ++ linear subpatterns are merged into a single""" ++ node = self ++ subp = [] ++ while node: ++ if node.type == TYPE_ALTERNATIVES: ++ node.alternatives.append(subp) ++ if len(node.alternatives) == len(node.children): ++ #last alternative ++ subp = [tuple(node.alternatives)] ++ node.alternatives = [] ++ node = node.parent ++ continue ++ else: ++ node = node.parent ++ subp = None ++ break ++ ++ if node.type == TYPE_GROUP: ++ node.group.append(subp) ++ #probably should check the number of leaves ++ if len(node.group) == len(node.children): ++ subp = get_characteristic_subpattern(node.group) ++ node.group = [] ++ node = node.parent ++ continue ++ else: ++ node = node.parent ++ subp = None ++ break ++ ++ if node.type == token_labels.NAME and node.name: ++ #in case of type=name, use the name instead ++ subp.append(node.name) ++ else: ++ subp.append(node.type) ++ ++ node = node.parent ++ return subp ++ ++ def get_linear_subpattern(self): ++ """Drives the leaf_to_root method. The reason that ++ leaf_to_root must be run multiple times is because we need to ++ reject 'group' matches; for example the alternative form ++ (a | b c) creates a group [b c] that needs to be matched. Since ++ matching multiple linear patterns overcomes the automaton's ++ capabilities, leaf_to_root merges each group into a single ++ choice based on 'characteristic'ity, ++ ++ i.e. (a|b c) -> (a|b) if b more characteristic than c ++ ++ Returns: The most 'characteristic'(as defined by ++ get_characteristic_subpattern) path for the compiled pattern ++ tree. ++ """ ++ ++ for l in self.leaves(): ++ subp = l.leaf_to_root() ++ if subp: ++ return subp ++ ++ def leaves(self): ++ "Generator that returns the leaves of the tree" ++ for child in self.children: ++ for x in child.leaves(): ++ yield x ++ if not self.children: ++ yield self ++ ++def reduce_tree(node, parent=None): ++ """ ++ Internal function. Reduces a compiled pattern tree to an ++ intermediate representation suitable for feeding the ++ automaton. This also trims off any optional pattern elements(like ++ [a], a*). ++ """ ++ ++ new_node = None ++ #switch on the node type ++ if node.type == syms.Matcher: ++ #skip ++ node = node.children[0] ++ ++ if node.type == syms.Alternatives : ++ #2 cases ++ if len(node.children) <= 2: ++ #just a single 'Alternative', skip this node ++ new_node = reduce_tree(node.children[0], parent) ++ else: ++ #real alternatives ++ new_node = MinNode(type=TYPE_ALTERNATIVES) ++ #skip odd children('|' tokens) ++ for child in node.children: ++ if node.children.index(child)%2: ++ continue ++ reduced = reduce_tree(child, new_node) ++ if reduced is not None: ++ new_node.children.append(reduced) ++ elif node.type == syms.Alternative: ++ if len(node.children) > 1: ++ ++ new_node = MinNode(type=TYPE_GROUP) ++ for child in node.children: ++ reduced = reduce_tree(child, new_node) ++ if reduced: ++ new_node.children.append(reduced) ++ if not new_node.children: ++ # delete the group if all of the children were reduced to None ++ new_node = None ++ ++ else: ++ new_node = reduce_tree(node.children[0], parent) ++ ++ elif node.type == syms.Unit: ++ if (isinstance(node.children[0], pytree.Leaf) and ++ node.children[0].value == '('): ++ #skip parentheses ++ return reduce_tree(node.children[1], parent) ++ if ((isinstance(node.children[0], pytree.Leaf) and ++ node.children[0].value == '[') ++ or ++ (len(node.children)>1 and ++ hasattr(node.children[1], "value") and ++ node.children[1].value == '[')): ++ #skip whole unit if its optional ++ return None ++ ++ leaf = True ++ details_node = None ++ alternatives_node = None ++ has_repeater = False ++ repeater_node = None ++ has_variable_name = False ++ ++ for child in node.children: ++ if child.type == syms.Details: ++ leaf = False ++ details_node = child ++ elif child.type == syms.Repeater: ++ has_repeater = True ++ repeater_node = child ++ elif child.type == syms.Alternatives: ++ alternatives_node = child ++ if hasattr(child, 'value') and child.value == '=': # variable name ++ has_variable_name = True ++ ++ #skip variable name ++ if has_variable_name: ++ #skip variable name, '=' ++ name_leaf = node.children[2] ++ if hasattr(name_leaf, 'value') and name_leaf.value == '(': ++ # skip parenthesis ++ name_leaf = node.children[3] ++ else: ++ name_leaf = node.children[0] ++ ++ #set node type ++ if name_leaf.type == token_labels.NAME: ++ #(python) non-name or wildcard ++ if name_leaf.value == 'any': ++ new_node = MinNode(type=TYPE_ANY) ++ else: ++ if hasattr(token_labels, name_leaf.value): ++ new_node = MinNode(type=getattr(token_labels, name_leaf.value)) ++ else: ++ new_node = MinNode(type=getattr(pysyms, name_leaf.value)) ++ ++ elif name_leaf.type == token_labels.STRING: ++ #(python) name or character; remove the apostrophes from ++ #the string value ++ name = name_leaf.value.strip("'") ++ if name in tokens: ++ new_node = MinNode(type=tokens[name]) ++ else: ++ new_node = MinNode(type=token_labels.NAME, name=name) ++ elif name_leaf.type == syms.Alternatives: ++ new_node = reduce_tree(alternatives_node, parent) ++ ++ #handle repeaters ++ if has_repeater: ++ if repeater_node.children[0].value == '*': ++ #reduce to None ++ new_node = None ++ elif repeater_node.children[0].value == '+': ++ #reduce to a single occurence i.e. do nothing ++ pass ++ else: ++ #TODO: handle {min, max} repeaters ++ raise NotImplementedError ++ pass ++ ++ #add children ++ if details_node and new_node is not None: ++ for child in details_node.children[1:-1]: ++ #skip '<', '>' markers ++ reduced = reduce_tree(child, new_node) ++ if reduced is not None: ++ new_node.children.append(reduced) ++ if new_node: ++ new_node.parent = parent ++ return new_node ++ ++ ++def get_characteristic_subpattern(subpatterns): ++ """Picks the most characteristic from a list of linear patterns ++ Current order used is: ++ names > common_names > common_chars ++ """ ++ if not isinstance(subpatterns, list): ++ return subpatterns ++ if len(subpatterns)==1: ++ return subpatterns[0] ++ ++ # first pick out the ones containing variable names ++ subpatterns_with_names = [] ++ subpatterns_with_common_names = [] ++ common_names = ['in', 'for', 'if' , 'not', 'None'] ++ subpatterns_with_common_chars = [] ++ common_chars = "[]().,:" ++ for subpattern in subpatterns: ++ if any(rec_test(subpattern, lambda x: type(x) is str)): ++ if any(rec_test(subpattern, ++ lambda x: isinstance(x, str) and x in common_chars)): ++ subpatterns_with_common_chars.append(subpattern) ++ elif any(rec_test(subpattern, ++ lambda x: isinstance(x, str) and x in common_names)): ++ subpatterns_with_common_names.append(subpattern) ++ ++ else: ++ subpatterns_with_names.append(subpattern) ++ ++ if subpatterns_with_names: ++ subpatterns = subpatterns_with_names ++ elif subpatterns_with_common_names: ++ subpatterns = subpatterns_with_common_names ++ elif subpatterns_with_common_chars: ++ subpatterns = subpatterns_with_common_chars ++ # of the remaining subpatterns pick out the longest one ++ return max(subpatterns, key=len) ++ ++def rec_test(sequence, test_func): ++ """Tests test_func on all items of sequence and items of included ++ sub-iterables""" ++ for x in sequence: ++ if isinstance(x, (list, tuple)): ++ for y in rec_test(x, test_func): ++ yield y ++ else: ++ yield test_func(x) +--- a/Lib/lib2to3/patcomp.py ++++ b/Lib/lib2to3/patcomp.py +@@ -52,14 +52,17 @@ + self.pysyms = pygram.python_symbols + self.driver = driver.Driver(self.grammar, convert=pattern_convert) + +- def compile_pattern(self, input, debug=False): ++ def compile_pattern(self, input, debug=False, with_tree=False): + """Compiles a pattern string to a nested pytree.*Pattern object.""" + tokens = tokenize_wrapper(input) + try: + root = self.driver.parse_tokens(tokens, debug=debug) +- except parse.ParseError, e: ++ except parse.ParseError as e: + raise PatternSyntaxError(str(e)) +- return self.compile_node(root) ++ if with_tree: ++ return self.compile_node(root), root ++ else: ++ return self.compile_node(root) + + def compile_node(self, node): + """Compiles a node, recursively. +--- a/Lib/lib2to3/btm_matcher.py ++++ b/Lib/lib2to3/btm_matcher.py +@@ -0,0 +1,168 @@ ++"""A bottom-up tree matching algorithm implementation meant to speed ++up 2to3's matching process. After the tree patterns are reduced to ++their rarest linear path, a linear Aho-Corasick automaton is ++created. The linear automaton traverses the linear paths from the ++leaves to the root of the AST and returns a set of nodes for further ++matching. This reduces significantly the number of candidate nodes.""" ++ ++__author__ = "George Boutsioukis " ++ ++import logging ++import itertools ++from collections import defaultdict ++ ++from . import pytree ++from .btm_utils import reduce_tree ++ ++class BMNode(object): ++ """Class for a node of the Aho-Corasick automaton used in matching""" ++ count = itertools.count() ++ def __init__(self): ++ self.transition_table = {} ++ self.fixers = [] ++ self.id = next(BMNode.count) ++ self.content = '' ++ ++class BottomMatcher(object): ++ """The main matcher class. After instantiating the patterns should ++ be added using the add_fixer method""" ++ ++ def __init__(self): ++ self.match = set() ++ self.root = BMNode() ++ self.nodes = [self.root] ++ self.fixers = [] ++ self.logger = logging.getLogger("RefactoringTool") ++ ++ def add_fixer(self, fixer): ++ """Reduces a fixer's pattern tree to a linear path and adds it ++ to the matcher(a common Aho-Corasick automaton). The fixer is ++ appended on the matching states and called when they are ++ reached""" ++ self.fixers.append(fixer) ++ tree = reduce_tree(fixer.pattern_tree) ++ linear = tree.get_linear_subpattern() ++ match_nodes = self.add(linear, start=self.root) ++ for match_node in match_nodes: ++ match_node.fixers.append(fixer) ++ ++ def add(self, pattern, start): ++ "Recursively adds a linear pattern to the AC automaton" ++ #print("adding pattern", pattern, "to", start) ++ if not pattern: ++ #print("empty pattern") ++ return [start] ++ if isinstance(pattern[0], tuple): ++ #alternatives ++ #print("alternatives") ++ match_nodes = [] ++ for alternative in pattern[0]: ++ #add all alternatives, and add the rest of the pattern ++ #to each end node ++ end_nodes = self.add(alternative, start=start) ++ for end in end_nodes: ++ match_nodes.extend(self.add(pattern[1:], end)) ++ return match_nodes ++ else: ++ #single token ++ #not last ++ if pattern[0] not in start.transition_table: ++ #transition did not exist, create new ++ next_node = BMNode() ++ start.transition_table[pattern[0]] = next_node ++ else: ++ #transition exists already, follow ++ next_node = start.transition_table[pattern[0]] ++ ++ if pattern[1:]: ++ end_nodes = self.add(pattern[1:], start=next_node) ++ else: ++ end_nodes = [next_node] ++ return end_nodes ++ ++ def run(self, leaves): ++ """The main interface with the bottom matcher. The tree is ++ traversed from the bottom using the constructed ++ automaton. Nodes are only checked once as the tree is ++ retraversed. When the automaton fails, we give it one more ++ shot(in case the above tree matches as a whole with the ++ rejected leaf), then we break for the next leaf. There is the ++ special case of multiple arguments(see code comments) where we ++ recheck the nodes ++ ++ Args: ++ The leaves of the AST tree to be matched ++ ++ Returns: ++ A dictionary of node matches with fixers as the keys ++ """ ++ current_ac_node = self.root ++ results = defaultdict(list) ++ for leaf in leaves: ++ current_ast_node = leaf ++ while current_ast_node: ++ current_ast_node.was_checked = True ++ for child in current_ast_node.children: ++ # multiple statements, recheck ++ if isinstance(child, pytree.Leaf) and child.value == u";": ++ current_ast_node.was_checked = False ++ break ++ if current_ast_node.type == 1: ++ #name ++ node_token = current_ast_node.value ++ else: ++ node_token = current_ast_node.type ++ ++ if node_token in current_ac_node.transition_table: ++ #token matches ++ current_ac_node = current_ac_node.transition_table[node_token] ++ for fixer in current_ac_node.fixers: ++ if not fixer in results: ++ results[fixer] = [] ++ results[fixer].append(current_ast_node) ++ ++ else: ++ #matching failed, reset automaton ++ current_ac_node = self.root ++ if (current_ast_node.parent is not None ++ and current_ast_node.parent.was_checked): ++ #the rest of the tree upwards has been checked, next leaf ++ break ++ ++ #recheck the rejected node once from the root ++ if node_token in current_ac_node.transition_table: ++ #token matches ++ current_ac_node = current_ac_node.transition_table[node_token] ++ for fixer in current_ac_node.fixers: ++ if not fixer in results.keys(): ++ results[fixer] = [] ++ results[fixer].append(current_ast_node) ++ ++ current_ast_node = current_ast_node.parent ++ return results ++ ++ def print_ac(self): ++ "Prints a graphviz diagram of the BM automaton(for debugging)" ++ print("digraph g{") ++ def print_node(node): ++ for subnode_key in node.transition_table.keys(): ++ subnode = node.transition_table[subnode_key] ++ print("%d -> %d [label=%s] //%s" % ++ (node.id, subnode.id, type_repr(subnode_key), str(subnode.fixers))) ++ if subnode_key == 1: ++ print(subnode.content) ++ print_node(subnode) ++ print_node(self.root) ++ print("}") ++ ++# taken from pytree.py for debugging; only used by print_ac ++_type_reprs = {} ++def type_repr(type_num): ++ global _type_reprs ++ if not _type_reprs: ++ from .pygram import python_symbols ++ # printing tokens is possible but not as useful ++ # from .pgen2 import token // token.__dict__.items(): ++ for name, val in python_symbols.__dict__.items(): ++ if type(val) == int: _type_reprs[val] = name ++ return _type_reprs.setdefault(type_num, type_num) +--- a/Lib/lib2to3/refactor.py ++++ b/Lib/lib2to3/refactor.py +@@ -24,7 +24,10 @@ + + # Local imports + from .pgen2 import driver, tokenize, token ++from .fixer_util import find_root + from . import pytree, pygram ++from . import btm_utils as bu ++from . import btm_matcher as bm + + + def get_all_fix_names(fixer_pkg, remove_prefix=True): +@@ -201,11 +204,28 @@ + logger=self.logger) + self.pre_order, self.post_order = self.get_fixers() + +- self.pre_order_heads = _get_headnode_dict(self.pre_order) +- self.post_order_heads = _get_headnode_dict(self.post_order) + + self.files = [] # List of files that were or should be modified + ++ self.BM = bm.BottomMatcher() ++ self.bmi_pre_order = [] # Bottom Matcher incompatible fixers ++ self.bmi_post_order = [] ++ ++ for fixer in chain(self.post_order, self.pre_order): ++ if fixer.BM_compatible: ++ self.BM.add_fixer(fixer) ++ # remove fixers that will be handled by the bottom-up ++ # matcher ++ elif fixer in self.pre_order: ++ self.bmi_pre_order.append(fixer) ++ elif fixer in self.post_order: ++ self.bmi_post_order.append(fixer) ++ ++ self.bmi_pre_order_heads = _get_headnode_dict(self.bmi_pre_order) ++ self.bmi_post_order_heads = _get_headnode_dict(self.bmi_post_order) ++ ++ ++ + def get_fixers(self): + """Inspects the options to load the requested patterns and handlers. + +@@ -268,6 +288,7 @@ + + def refactor(self, items, write=False, doctests_only=False): + """Refactor a list of files and directories.""" ++ + for dir_or_file in items: + if os.path.isdir(dir_or_file): + self.refactor_dir(dir_or_file, write, doctests_only) +@@ -299,7 +320,7 @@ + """ + try: + f = open(filename, "rb") +- except IOError, err: ++ except IOError as err: + self.log_error("Can't open %s: %s", filename, err) + return None, None + try: +@@ -348,7 +369,7 @@ + self.driver.grammar = pygram.python_grammar_no_print_statement + try: + tree = self.driver.parse_string(data) +- except Exception, err: ++ except Exception as err: + self.log_error("Can't parse %s: %s: %s", + name, err.__class__.__name__, err) + return +@@ -378,6 +399,10 @@ + def refactor_tree(self, tree, name): + """Refactors a parse tree (modifying the tree in place). + ++ For compatible patterns the bottom matcher module is ++ used. Otherwise the tree is traversed node-to-node for ++ matches. ++ + Args: + tree: a pytree.Node instance representing the root of the tree + to be refactored. +@@ -386,12 +411,66 @@ + Returns: + True if the tree was modified, False otherwise. + """ ++ + for fixer in chain(self.pre_order, self.post_order): + fixer.start_tree(tree, name) + +- self.traverse_by(self.pre_order_heads, tree.pre_order()) +- self.traverse_by(self.post_order_heads, tree.post_order()) ++ #use traditional matching for the incompatible fixers ++ self.traverse_by(self.bmi_pre_order_heads, tree.pre_order()) ++ self.traverse_by(self.bmi_post_order_heads, tree.post_order()) + ++ # obtain a set of candidate nodes ++ match_set = self.BM.run(tree.leaves()) ++ ++ while any(match_set.values()): ++ for fixer in self.BM.fixers: ++ if fixer in match_set and match_set[fixer]: ++ #sort by depth; apply fixers from bottom(of the AST) to top ++ match_set[fixer].sort(key=pytree.Base.depth, reverse=True) ++ ++ if fixer.keep_line_order: ++ #some fixers(eg fix_imports) must be applied ++ #with the original file's line order ++ match_set[fixer].sort(key=pytree.Base.get_lineno) ++ ++ for node in list(match_set[fixer]): ++ if node in match_set[fixer]: ++ match_set[fixer].remove(node) ++ ++ try: ++ find_root(node) ++ except AssertionError: ++ # this node has been cut off from a ++ # previous transformation ; skip ++ continue ++ ++ if node.fixers_applied and fixer in node.fixers_applied: ++ # do not apply the same fixer again ++ continue ++ ++ results = fixer.match(node) ++ ++ if results: ++ new = fixer.transform(node, results) ++ if new is not None: ++ node.replace(new) ++ #new.fixers_applied.append(fixer) ++ for node in new.post_order(): ++ # do not apply the fixer again to ++ # this or any subnode ++ if not node.fixers_applied: ++ node.fixers_applied = [] ++ node.fixers_applied.append(fixer) ++ ++ # update the original match set for ++ # the added code ++ new_matches = self.BM.run(new.leaves()) ++ for fxr in new_matches: ++ if not fxr in match_set: ++ match_set[fxr]=[] ++ ++ match_set[fxr].extend(new_matches[fxr]) ++ + for fixer in chain(self.pre_order, self.post_order): + fixer.finish_tree(tree, name) + return tree.was_changed +@@ -448,12 +527,12 @@ + """ + try: + f = _open_with_encoding(filename, "w", encoding=encoding) +- except os.error, err: ++ except os.error as err: + self.log_error("Can't create %s: %s", filename, err) + return + try: + f.write(_to_system_newlines(new_text)) +- except os.error, err: ++ except os.error as err: + self.log_error("Can't write %s: %s", filename, err) + finally: + f.close() +@@ -516,8 +595,8 @@ + """ + try: + tree = self.parse_block(block, lineno, indent) +- except Exception, err: +- if self.log.isEnabledFor(logging.DEBUG): ++ except Exception as err: ++ if self.logger.isEnabledFor(logging.DEBUG): + for line in block: + self.log_debug("Source: %s", line.rstrip(u"\n")) + self.log_error("Can't parse docstring in %s line %s: %s: %s", +--- a/Lib/lib2to3/fixer_base.py ++++ b/Lib/lib2to3/fixer_base.py +@@ -24,6 +24,7 @@ + + PATTERN = None # Most subclasses should override with a string literal + pattern = None # Compiled pattern, set by compile_pattern() ++ pattern_tree = None # Tree representation of the pattern + options = None # Options object passed to initializer + filename = None # The filename (set by set_filename) + logger = None # A logger (set by set_filename) +@@ -36,6 +37,12 @@ + _accept_type = None # [Advanced and not public] This tells RefactoringTool + # which node type to accept when there's not a pattern. + ++ keep_line_order = False # For the bottom matcher: match with the ++ # original line order ++ BM_compatible = False # Compatibility with the bottom matching ++ # module; every fixer should set this ++ # manually ++ + # Shortcut for access to Python grammar symbols + syms = pygram.python_symbols + +@@ -58,7 +65,9 @@ + self.{pattern,PATTERN} in .match(). + """ + if self.PATTERN is not None: +- self.pattern = PatternCompiler().compile_pattern(self.PATTERN) ++ PC = PatternCompiler() ++ self.pattern, self.pattern_tree = PC.compile_pattern(self.PATTERN, ++ with_tree=True) + + def set_filename(self, filename): + """Set the filename, and a logger derived from it. +--- a/Lib/lib2to3/fixes/fix_dict.py ++++ b/Lib/lib2to3/fixes/fix_dict.py +@@ -40,6 +40,8 @@ + + + class FixDict(fixer_base.BaseFix): ++ BM_compatible = True ++ + PATTERN = """ + power< head=any+ + trailer< '.' method=('keys'|'items'|'values'| +--- a/Lib/lib2to3/fixes/fix_has_key.py ++++ b/Lib/lib2to3/fixes/fix_has_key.py +@@ -37,6 +37,7 @@ + + + class FixHasKey(fixer_base.BaseFix): ++ BM_compatible = True + + PATTERN = """ + anchor=power< +--- a/Lib/lib2to3/fixes/fix_exec.py ++++ b/Lib/lib2to3/fixes/fix_exec.py +@@ -16,6 +16,7 @@ + + + class FixExec(fixer_base.BaseFix): ++ BM_compatible = True + + PATTERN = """ + exec_stmt< 'exec' a=any 'in' b=any [',' c=any] > +--- a/Lib/lib2to3/fixes/fix_idioms.py ++++ b/Lib/lib2to3/fixes/fix_idioms.py +@@ -35,7 +35,6 @@ + TYPE = "power< 'type' trailer< '(' x=any ')' > >" + + class FixIdioms(fixer_base.BaseFix): +- + explicit = True # The user must ask for this fixer + + PATTERN = r""" +--- a/Lib/lib2to3/fixes/fix_urllib.py ++++ b/Lib/lib2to3/fixes/fix_urllib.py +@@ -5,39 +5,40 @@ + # Author: Nick Edds + + # Local imports +-from .fix_imports import alternates, FixImports +-from .. import fixer_base +-from ..fixer_util import Name, Comma, FromImport, Newline, attr_chain ++from lib2to3.fixes.fix_imports import alternates, FixImports ++from lib2to3 import fixer_base ++from lib2to3.fixer_util import (Name, Comma, FromImport, Newline, ++ find_indentation, Node, syms) + +-MAPPING = {'urllib': [ +- ('urllib.request', +- ['URLOpener', 'FancyURLOpener', 'urlretrieve', +- '_urlopener', 'urlopen', 'urlcleanup', +- 'pathname2url', 'url2pathname']), +- ('urllib.parse', +- ['quote', 'quote_plus', 'unquote', 'unquote_plus', +- 'urlencode', 'splitattr', 'splithost', 'splitnport', +- 'splitpasswd', 'splitport', 'splitquery', 'splittag', +- 'splittype', 'splituser', 'splitvalue', ]), +- ('urllib.error', +- ['ContentTooShortError'])], +- 'urllib2' : [ +- ('urllib.request', +- ['urlopen', 'install_opener', 'build_opener', +- 'Request', 'OpenerDirector', 'BaseHandler', +- 'HTTPDefaultErrorHandler', 'HTTPRedirectHandler', +- 'HTTPCookieProcessor', 'ProxyHandler', +- 'HTTPPasswordMgr', +- 'HTTPPasswordMgrWithDefaultRealm', +- 'AbstractBasicAuthHandler', +- 'HTTPBasicAuthHandler', 'ProxyBasicAuthHandler', +- 'AbstractDigestAuthHandler', +- 'HTTPDigestAuthHandler', 'ProxyDigestAuthHandler', +- 'HTTPHandler', 'HTTPSHandler', 'FileHandler', +- 'FTPHandler', 'CacheFTPHandler', +- 'UnknownHandler']), +- ('urllib.error', +- ['URLError', 'HTTPError']), ++MAPPING = {"urllib": [ ++ ("urllib.request", ++ ["URLOpener", "FancyURLOpener", "urlretrieve", ++ "_urlopener", "urlopen", "urlcleanup", ++ "pathname2url", "url2pathname"]), ++ ("urllib.parse", ++ ["quote", "quote_plus", "unquote", "unquote_plus", ++ "urlencode", "splitattr", "splithost", "splitnport", ++ "splitpasswd", "splitport", "splitquery", "splittag", ++ "splittype", "splituser", "splitvalue", ]), ++ ("urllib.error", ++ ["ContentTooShortError"])], ++ "urllib2" : [ ++ ("urllib.request", ++ ["urlopen", "install_opener", "build_opener", ++ "Request", "OpenerDirector", "BaseHandler", ++ "HTTPDefaultErrorHandler", "HTTPRedirectHandler", ++ "HTTPCookieProcessor", "ProxyHandler", ++ "HTTPPasswordMgr", ++ "HTTPPasswordMgrWithDefaultRealm", ++ "AbstractBasicAuthHandler", ++ "HTTPBasicAuthHandler", "ProxyBasicAuthHandler", ++ "AbstractDigestAuthHandler", ++ "HTTPDigestAuthHandler", "ProxyDigestAuthHandler", ++ "HTTPHandler", "HTTPSHandler", "FileHandler", ++ "FTPHandler", "CacheFTPHandler", ++ "UnknownHandler"]), ++ ("urllib.error", ++ ["URLError", "HTTPError"]), + ] + } + +@@ -78,7 +79,7 @@ + import name with a comma separated list of its + replacements. + """ +- import_mod = results.get('module') ++ import_mod = results.get("module") + pref = import_mod.prefix + + names = [] +@@ -94,9 +95,9 @@ + the module to be imported from with the appropriate new + module. + """ +- mod_member = results.get('mod_member') ++ mod_member = results.get("mod_member") + pref = mod_member.prefix +- member = results.get('member') ++ member = results.get("member") + + # Simple case with only a single member being imported + if member: +@@ -111,35 +112,51 @@ + if new_name: + mod_member.replace(Name(new_name, prefix=pref)) + else: +- self.cannot_convert(node, +- 'This is an invalid module element') ++ self.cannot_convert(node, "This is an invalid module element") + + # Multiple members being imported + else: + # a dictionary for replacements, order matters + modules = [] + mod_dict = {} +- members = results.get('members') ++ members = results["members"] + for member in members: +- member = member.value + # we only care about the actual members +- if member != ',': ++ if member.type == syms.import_as_name: ++ as_name = member.children[2].value ++ member_name = member.children[0].value ++ else: ++ member_name = member.value ++ as_name = None ++ if member_name != u",": + for change in MAPPING[mod_member.value]: +- if member in change[1]: +- if change[0] in mod_dict: +- mod_dict[change[0]].append(member) +- else: +- mod_dict[change[0]] = [member] ++ if member_name in change[1]: ++ if change[0] not in mod_dict: + modules.append(change[0]) ++ mod_dict.setdefault(change[0], []).append(member) + + new_nodes = [] ++ indentation = find_indentation(node) ++ first = True ++ def handle_name(name, prefix): ++ if name.type == syms.import_as_name: ++ kids = [Name(name.children[0].value, prefix=prefix), ++ name.children[1].clone(), ++ name.children[2].clone()] ++ return [Node(syms.import_as_name, kids)] ++ return [Name(name.value, prefix=prefix)] + for module in modules: + elts = mod_dict[module] + names = [] + for elt in elts[:-1]: +- names.extend([Name(elt, prefix=pref), Comma()]) +- names.append(Name(elts[-1], prefix=pref)) +- new_nodes.append(FromImport(module, names)) ++ names.extend(handle_name(elt, pref)) ++ names.append(Comma()) ++ names.extend(handle_name(elts[-1], pref)) ++ new = FromImport(module, names) ++ if not first or node.parent.prefix.endswith(indentation): ++ new.prefix = indentation ++ new_nodes.append(new) ++ first = False + if new_nodes: + nodes = [] + for new_node in new_nodes[:-1]: +@@ -147,12 +164,12 @@ + nodes.append(new_nodes[-1]) + node.replace(nodes) + else: +- self.cannot_convert(node, 'All module elements are invalid') ++ self.cannot_convert(node, "All module elements are invalid") + + def transform_dot(self, node, results): + """Transform for calls to module members in code.""" +- module_dot = results.get('bare_with_attr') +- member = results.get('member') ++ module_dot = results.get("bare_with_attr") ++ member = results.get("member") + new_name = None + if isinstance(member, list): + member = member[0] +@@ -164,17 +181,17 @@ + module_dot.replace(Name(new_name, + prefix=module_dot.prefix)) + else: +- self.cannot_convert(node, 'This is an invalid module element') ++ self.cannot_convert(node, "This is an invalid module element") + + def transform(self, node, results): +- if results.get('module'): ++ if results.get("module"): + self.transform_import(node, results) +- elif results.get('mod_member'): ++ elif results.get("mod_member"): + self.transform_member(node, results) +- elif results.get('bare_with_attr'): ++ elif results.get("bare_with_attr"): + self.transform_dot(node, results) + # Renaming and star imports are not supported for these modules. +- elif results.get('module_star'): +- self.cannot_convert(node, 'Cannot handle star imports.') +- elif results.get('module_as'): +- self.cannot_convert(node, 'This module is now multiple modules') ++ elif results.get("module_star"): ++ self.cannot_convert(node, "Cannot handle star imports.") ++ elif results.get("module_as"): ++ self.cannot_convert(node, "This module is now multiple modules") +--- a/Lib/lib2to3/fixes/fix_nonzero.py ++++ b/Lib/lib2to3/fixes/fix_nonzero.py +@@ -6,6 +6,7 @@ + from ..fixer_util import Name, syms + + class FixNonzero(fixer_base.BaseFix): ++ BM_compatible = True + PATTERN = """ + classdef< 'class' any+ ':' + suite< any* +--- a/Lib/lib2to3/fixes/fix_print.py ++++ b/Lib/lib2to3/fixes/fix_print.py +@@ -28,6 +28,8 @@ + + class FixPrint(fixer_base.BaseFix): + ++ BM_compatible = True ++ + PATTERN = """ + simple_stmt< any* bare='print' any* > | print_stmt + """ +--- a/Lib/lib2to3/fixes/fix_imports.py ++++ b/Lib/lib2to3/fixes/fix_imports.py +@@ -84,6 +84,8 @@ + + class FixImports(fixer_base.BaseFix): + ++ BM_compatible = True ++ keep_line_order = True + # This is overridden in fix_imports2. + mapping = MAPPING + +--- a/Lib/lib2to3/fixes/fix_input.py ++++ b/Lib/lib2to3/fixes/fix_input.py +@@ -11,7 +11,7 @@ + + + class FixInput(fixer_base.BaseFix): +- ++ BM_compatible = True + PATTERN = """ + power< 'input' args=trailer< '(' [any] ')' > > + """ +--- a/Lib/lib2to3/fixes/fix_itertools_imports.py ++++ b/Lib/lib2to3/fixes/fix_itertools_imports.py +@@ -6,6 +6,7 @@ + + + class FixItertoolsImports(fixer_base.BaseFix): ++ BM_compatible = True + PATTERN = """ + import_from< 'from' 'itertools' 'import' imports=any > + """ %(locals()) +@@ -20,6 +21,9 @@ + if child.type == token.NAME: + member = child.value + name_node = child ++ elif child.type == token.STAR: ++ # Just leave the import as is. ++ return + else: + assert child.type == syms.import_as_name + name_node = child.children[0] +@@ -40,12 +44,12 @@ + else: + remove_comma ^= True + +- if children[-1].type == token.COMMA: +- children[-1].remove() ++ while children and children[-1].type == token.COMMA: ++ children.pop().remove() + + # If there are no imports left, just get rid of the entire statement +- if not (imports.children or getattr(imports, 'value', None)) or \ +- imports.parent is None: ++ if (not (imports.children or getattr(imports, 'value', None)) or ++ imports.parent is None): + p = node.prefix + node = BlankLine() + node.prefix = p +--- a/Lib/lib2to3/fixes/fix_getcwdu.py ++++ b/Lib/lib2to3/fixes/fix_getcwdu.py +@@ -8,6 +8,7 @@ + from ..fixer_util import Name + + class FixGetcwdu(fixer_base.BaseFix): ++ BM_compatible = True + + PATTERN = """ + power< 'os' trailer< dot='.' name='getcwdu' > any* > +--- a/Lib/lib2to3/fixes/fix_zip.py ++++ b/Lib/lib2to3/fixes/fix_zip.py +@@ -13,6 +13,7 @@ + + class FixZip(fixer_base.ConditionalFix): + ++ BM_compatible = True + PATTERN = """ + power< 'zip' args=trailer< '(' [any] ')' > + > +--- a/Lib/lib2to3/fixes/fix_raise.py ++++ b/Lib/lib2to3/fixes/fix_raise.py +@@ -4,6 +4,7 @@ + raise E -> raise E + raise E, V -> raise E(V) + raise E, V, T -> raise E(V).with_traceback(T) ++raise E, None, T -> raise E.with_traceback(T) + + raise (((E, E'), E''), E'''), V -> raise E(V) + raise "foo", V, T -> warns about string exceptions +@@ -29,6 +30,7 @@ + + class FixRaise(fixer_base.BaseFix): + ++ BM_compatible = True + PATTERN = """ + raise_stmt< 'raise' exc=any [',' val=any [',' tb=any]] > + """ +@@ -37,8 +39,9 @@ + syms = self.syms + + exc = results["exc"].clone() +- if exc.type is token.STRING: +- self.cannot_convert(node, "Python 3 does not support string exceptions") ++ if exc.type == token.STRING: ++ msg = "Python 3 does not support string exceptions" ++ self.cannot_convert(node, msg) + return + + # Python 2 supports +@@ -52,7 +55,7 @@ + # exc.children[1:-1] is the unparenthesized tuple + # exc.children[1].children[0] is the first element of the tuple + exc = exc.children[1].children[0].clone() +- exc.prefix = " " ++ exc.prefix = u" " + + if "val" not in results: + # One-argument raise +@@ -71,7 +74,12 @@ + tb = results["tb"].clone() + tb.prefix = u"" + +- e = Call(exc, args) ++ e = exc ++ # If there's a traceback and None is passed as the value, then don't ++ # add a call, since the user probably just wants to add a ++ # traceback. See issue #9661. ++ if val.type != token.NAME or val.value != u"None": ++ e = Call(exc, args) + with_tb = Attr(e, Name(u'with_traceback')) + [ArgList([tb])] + new = pytree.Node(syms.simple_stmt, [Name(u"raise")] + with_tb) + new.prefix = node.prefix +--- a/Lib/lib2to3/fixes/fix_throw.py ++++ b/Lib/lib2to3/fixes/fix_throw.py +@@ -14,7 +14,7 @@ + from ..fixer_util import Name, Call, ArgList, Attr, is_tuple + + class FixThrow(fixer_base.BaseFix): +- ++ BM_compatible = True + PATTERN = """ + power< any trailer< '.' 'throw' > + trailer< '(' args=arglist< exc=any ',' val=any [',' tb=any] > ')' > +--- a/Lib/lib2to3/fixes/fix_types.py ++++ b/Lib/lib2to3/fixes/fix_types.py +@@ -52,7 +52,7 @@ + _pats = ["power< 'types' trailer< '.' name='%s' > >" % t for t in _TYPE_MAPPING] + + class FixTypes(fixer_base.BaseFix): +- ++ BM_compatible = True + PATTERN = '|'.join(_pats) + + def transform(self, node, results): +--- a/Lib/lib2to3/fixes/fix_paren.py ++++ b/Lib/lib2to3/fixes/fix_paren.py +@@ -10,6 +10,8 @@ + + # XXX This doesn't support nested for loops like [x for x in 1, 2 for x in 1, 2] + class FixParen(fixer_base.BaseFix): ++ BM_compatible = True ++ + PATTERN = """ + atom< ('[' | '(') + (listmaker< any +--- a/Lib/lib2to3/fixes/fix_reduce.py ++++ b/Lib/lib2to3/fixes/fix_reduce.py +@@ -14,6 +14,9 @@ + + class FixReduce(fixer_base.BaseFix): + ++ BM_compatible = True ++ order = "pre" ++ + PATTERN = """ + power< 'reduce' + trailer< '(' +--- a/Lib/lib2to3/fixes/fix_repr.py ++++ b/Lib/lib2to3/fixes/fix_repr.py +@@ -10,6 +10,7 @@ + + class FixRepr(fixer_base.BaseFix): + ++ BM_compatible = True + PATTERN = """ + atom < '`' expr=any '`' > + """ +--- a/Lib/lib2to3/fixes/fix_raw_input.py ++++ b/Lib/lib2to3/fixes/fix_raw_input.py +@@ -7,6 +7,7 @@ + + class FixRawInput(fixer_base.BaseFix): + ++ BM_compatible = True + PATTERN = """ + power< name='raw_input' trailer< '(' [any] ')' > any* > + """ +--- a/Lib/lib2to3/fixes/fix_funcattrs.py ++++ b/Lib/lib2to3/fixes/fix_funcattrs.py +@@ -7,6 +7,8 @@ + + + class FixFuncattrs(fixer_base.BaseFix): ++ BM_compatible = True ++ + PATTERN = """ + power< any+ trailer< '.' attr=('func_closure' | 'func_doc' | 'func_globals' + | 'func_name' | 'func_defaults' | 'func_code' +--- a/Lib/lib2to3/fixes/fix_buffer.py ++++ b/Lib/lib2to3/fixes/fix_buffer.py +@@ -9,6 +9,7 @@ + + + class FixBuffer(fixer_base.BaseFix): ++ BM_compatible = True + + explicit = True # The user must ask for this fixer + +--- a/Lib/lib2to3/fixes/fix_standarderror.py ++++ b/Lib/lib2to3/fixes/fix_standarderror.py +@@ -9,7 +9,7 @@ + + + class FixStandarderror(fixer_base.BaseFix): +- ++ BM_compatible = True + PATTERN = """ + 'StandardError' + """ +--- a/Lib/lib2to3/fixes/fix_import.py ++++ b/Lib/lib2to3/fixes/fix_import.py +@@ -36,6 +36,7 @@ + + + class FixImport(fixer_base.BaseFix): ++ BM_compatible = True + + PATTERN = """ + import_from< 'from' imp=any 'import' ['('] any [')'] > +--- a/Lib/lib2to3/fixes/fix_map.py ++++ b/Lib/lib2to3/fixes/fix_map.py +@@ -26,6 +26,7 @@ + from ..pygram import python_symbols as syms + + class FixMap(fixer_base.ConditionalFix): ++ BM_compatible = True + + PATTERN = """ + map_none=power< +--- a/Lib/lib2to3/fixes/fix_next.py ++++ b/Lib/lib2to3/fixes/fix_next.py +@@ -15,6 +15,7 @@ + + + class FixNext(fixer_base.BaseFix): ++ BM_compatible = True + PATTERN = """ + power< base=any+ trailer< '.' attr='next' > trailer< '(' ')' > > + | +--- a/Lib/lib2to3/fixes/fix_xrange.py ++++ b/Lib/lib2to3/fixes/fix_xrange.py +@@ -10,7 +10,7 @@ + + + class FixXrange(fixer_base.BaseFix): +- ++ BM_compatible = True + PATTERN = """ + power< + (name='range'|name='xrange') trailer< '(' args=any ')' > +--- a/Lib/lib2to3/fixes/fix_execfile.py ++++ b/Lib/lib2to3/fixes/fix_execfile.py +@@ -13,6 +13,7 @@ + + + class FixExecfile(fixer_base.BaseFix): ++ BM_compatible = True + + PATTERN = """ + power< 'execfile' trailer< '(' arglist< filename=any [',' globals=any [',' locals=any ] ] > ')' > > +--- a/Lib/lib2to3/fixes/fix_itertools.py ++++ b/Lib/lib2to3/fixes/fix_itertools.py +@@ -12,6 +12,7 @@ + from ..fixer_util import Name + + class FixItertools(fixer_base.BaseFix): ++ BM_compatible = True + it_funcs = "('imap'|'ifilter'|'izip'|'ifilterfalse')" + PATTERN = """ + power< it='itertools' +--- a/Lib/lib2to3/fixes/fix_apply.py ++++ b/Lib/lib2to3/fixes/fix_apply.py +@@ -12,6 +12,7 @@ + from ..fixer_util import Call, Comma, parenthesize + + class FixApply(fixer_base.BaseFix): ++ BM_compatible = True + + PATTERN = """ + power< 'apply' +--- a/Lib/lib2to3/fixes/fix_exitfunc.py ++++ b/Lib/lib2to3/fixes/fix_exitfunc.py +@@ -9,6 +9,8 @@ + + + class FixExitfunc(fixer_base.BaseFix): ++ keep_line_order = True ++ BM_compatible = True + + PATTERN = """ + ( +--- a/Lib/lib2to3/fixes/fix_filter.py ++++ b/Lib/lib2to3/fixes/fix_filter.py +@@ -19,6 +19,7 @@ + from ..fixer_util import Name, Call, ListComp, in_special_context + + class FixFilter(fixer_base.ConditionalFix): ++ BM_compatible = True + + PATTERN = """ + filter_lambda=power< +--- a/Lib/lib2to3/fixes/fix_unicode.py ++++ b/Lib/lib2to3/fixes/fix_unicode.py +@@ -10,7 +10,7 @@ + _literal_re = re.compile(ur"[uU][rR]?[\'\"]") + + class FixUnicode(fixer_base.BaseFix): +- ++ BM_compatible = True + PATTERN = "STRING | 'unicode' | 'unichr'" + + def transform(self, node, results): +--- a/Lib/lib2to3/fixes/fix_except.py ++++ b/Lib/lib2to3/fixes/fix_except.py +@@ -34,6 +34,7 @@ + yield (n, nodes[i+2]) + + class FixExcept(fixer_base.BaseFix): ++ BM_compatible = True + + PATTERN = """ + try_stmt< 'try' ':' (simple_stmt | suite) +--- a/Lib/lib2to3/fixes/fix_renames.py ++++ b/Lib/lib2to3/fixes/fix_renames.py +@@ -40,6 +40,7 @@ + + + class FixRenames(fixer_base.BaseFix): ++ BM_compatible = True + PATTERN = "|".join(build_pattern()) + + order = "pre" # Pre-order tree traversal +--- a/Lib/lib2to3/fixes/fix_operator.py ++++ b/Lib/lib2to3/fixes/fix_operator.py +@@ -1,40 +1,96 @@ +-"""Fixer for operator.{isCallable,sequenceIncludes} ++"""Fixer for operator functions. + +-operator.isCallable(obj) -> hasattr(obj, '__call__') ++operator.isCallable(obj) -> hasattr(obj, '__call__') + operator.sequenceIncludes(obj) -> operator.contains(obj) ++operator.isSequenceType(obj) -> isinstance(obj, collections.Sequence) ++operator.isMappingType(obj) -> isinstance(obj, collections.Mapping) ++operator.isNumberType(obj) -> isinstance(obj, numbers.Number) ++operator.repeat(obj, n) -> operator.mul(obj, n) ++operator.irepeat(obj, n) -> operator.imul(obj, n) + """ + + # Local imports +-from .. import fixer_base +-from ..fixer_util import Call, Name, String ++from lib2to3 import fixer_base ++from lib2to3.fixer_util import Call, Name, String, touch_import + ++ ++def invocation(s): ++ def dec(f): ++ f.invocation = s ++ return f ++ return dec ++ ++ + class FixOperator(fixer_base.BaseFix): ++ BM_compatible = True ++ order = "pre" + +- methods = "method=('isCallable'|'sequenceIncludes')" +- func = "'(' func=any ')'" ++ methods = """ ++ method=('isCallable'|'sequenceIncludes' ++ |'isSequenceType'|'isMappingType'|'isNumberType' ++ |'repeat'|'irepeat') ++ """ ++ obj = "'(' obj=any ')'" + PATTERN = """ + power< module='operator' +- trailer< '.' %(methods)s > trailer< %(func)s > > ++ trailer< '.' %(methods)s > trailer< %(obj)s > > + | +- power< %(methods)s trailer< %(func)s > > +- """ % dict(methods=methods, func=func) ++ power< %(methods)s trailer< %(obj)s > > ++ """ % dict(methods=methods, obj=obj) + + def transform(self, node, results): ++ method = self._check_method(node, results) ++ if method is not None: ++ return method(node, results) ++ ++ @invocation("operator.contains(%s)") ++ def _sequenceIncludes(self, node, results): ++ return self._handle_rename(node, results, u"contains") ++ ++ @invocation("hasattr(%s, '__call__')") ++ def _isCallable(self, node, results): ++ obj = results["obj"] ++ args = [obj.clone(), String(u", "), String(u"'__call__'")] ++ return Call(Name(u"hasattr"), args, prefix=node.prefix) ++ ++ @invocation("operator.mul(%s)") ++ def _repeat(self, node, results): ++ return self._handle_rename(node, results, u"mul") ++ ++ @invocation("operator.imul(%s)") ++ def _irepeat(self, node, results): ++ return self._handle_rename(node, results, u"imul") ++ ++ @invocation("isinstance(%s, collections.Sequence)") ++ def _isSequenceType(self, node, results): ++ return self._handle_type2abc(node, results, u"collections", u"Sequence") ++ ++ @invocation("isinstance(%s, collections.Mapping)") ++ def _isMappingType(self, node, results): ++ return self._handle_type2abc(node, results, u"collections", u"Mapping") ++ ++ @invocation("isinstance(%s, numbers.Number)") ++ def _isNumberType(self, node, results): ++ return self._handle_type2abc(node, results, u"numbers", u"Number") ++ ++ def _handle_rename(self, node, results, name): + method = results["method"][0] ++ method.value = name ++ method.changed() + +- if method.value == u"sequenceIncludes": +- if "module" not in results: +- # operator may not be in scope, so we can't make a change. +- self.warning(node, "You should use operator.contains here.") ++ def _handle_type2abc(self, node, results, module, abc): ++ touch_import(None, module, node) ++ obj = results["obj"] ++ args = [obj.clone(), String(u", " + u".".join([module, abc]))] ++ return Call(Name(u"isinstance"), args, prefix=node.prefix) ++ ++ def _check_method(self, node, results): ++ method = getattr(self, "_" + results["method"][0].value.encode("ascii")) ++ if callable(method): ++ if "module" in results: ++ return method + else: +- method.value = u"contains" +- method.changed() +- elif method.value == u"isCallable": +- if "module" not in results: +- self.warning(node, +- "You should use hasattr(%s, '__call__') here." % +- results["func"].value) +- else: +- func = results["func"] +- args = [func.clone(), String(u", "), String(u"'__call__'")] +- return Call(Name(u"hasattr"), args, prefix=node.prefix) ++ sub = (unicode(results["obj"]),) ++ invocation_str = unicode(method.invocation) % sub ++ self.warning(node, u"You should use '%s' here." % invocation_str) ++ return None +--- a/Lib/lib2to3/fixes/fix_tuple_params.py ++++ b/Lib/lib2to3/fixes/fix_tuple_params.py +@@ -29,6 +29,10 @@ + stmt.children[0].type == token.STRING + + class FixTupleParams(fixer_base.BaseFix): ++ run_order = 4 #use a lower order since lambda is part of other ++ #patterns ++ BM_compatible = True ++ + PATTERN = """ + funcdef< 'def' any parameters< '(' args=any ')' > + ['->' any] ':' suite=any+ > +--- a/Lib/lib2to3/fixes/fix_methodattrs.py ++++ b/Lib/lib2to3/fixes/fix_methodattrs.py +@@ -13,6 +13,7 @@ + } + + class FixMethodattrs(fixer_base.BaseFix): ++ BM_compatible = True + PATTERN = """ + power< any+ trailer< '.' attr=('im_func' | 'im_self' | 'im_class') > any* > + """ +--- a/Lib/lib2to3/fixes/fix_xreadlines.py ++++ b/Lib/lib2to3/fixes/fix_xreadlines.py +@@ -9,6 +9,7 @@ + + + class FixXreadlines(fixer_base.BaseFix): ++ BM_compatible = True + PATTERN = """ + power< call=any+ trailer< '.' 'xreadlines' > trailer< '(' ')' > > + | +--- a/Lib/lib2to3/fixes/fix_long.py ++++ b/Lib/lib2to3/fixes/fix_long.py +@@ -10,7 +10,7 @@ + + + class FixLong(fixer_base.BaseFix): +- ++ BM_compatible = True + PATTERN = "'long'" + + def transform(self, node, results): +--- a/Lib/lib2to3/fixes/fix_intern.py ++++ b/Lib/lib2to3/fixes/fix_intern.py +@@ -12,6 +12,8 @@ + + + class FixIntern(fixer_base.BaseFix): ++ BM_compatible = True ++ order = "pre" + + PATTERN = """ + power< 'intern' +--- a/Lib/lib2to3/fixes/fix_callable.py ++++ b/Lib/lib2to3/fixes/fix_callable.py +@@ -11,7 +11,10 @@ + from lib2to3.fixer_util import Call, Name, String, Attr, touch_import + + class FixCallable(fixer_base.BaseFix): ++ BM_compatible = True + ++ order = "pre" ++ + # Ignore callable(*args) or use of keywords. + # Either could be a hint that the builtin callable() is not being used. + PATTERN = """ +--- a/Lib/lib2to3/fixes/fix_isinstance.py ++++ b/Lib/lib2to3/fixes/fix_isinstance.py +@@ -14,7 +14,7 @@ + + + class FixIsinstance(fixer_base.BaseFix): +- ++ BM_compatible = True + PATTERN = """ + power< + 'isinstance' +--- a/Lib/lib2to3/fixes/fix_basestring.py ++++ b/Lib/lib2to3/fixes/fix_basestring.py +@@ -6,6 +6,7 @@ + from ..fixer_util import Name + + class FixBasestring(fixer_base.BaseFix): ++ BM_compatible = True + + PATTERN = "'basestring'" + +--- a/Lib/lib2to3/fixes/fix_set_literal.py ++++ b/Lib/lib2to3/fixes/fix_set_literal.py +@@ -11,6 +11,7 @@ + + class FixSetLiteral(fixer_base.BaseFix): + ++ BM_compatible = True + explicit = True + + PATTERN = """power< 'set' trailer< '(' +--- a/Lib/lib2to3/fixes/fix_future.py ++++ b/Lib/lib2to3/fixes/fix_future.py +@@ -9,6 +9,8 @@ + from ..fixer_util import BlankLine + + class FixFuture(fixer_base.BaseFix): ++ BM_compatible = True ++ + PATTERN = """import_from< 'from' module_name="__future__" 'import' any >""" + + # This should be run last -- some things check for the import +--- a/Lib/lib2to3/fixes/fix_metaclass.py ++++ b/Lib/lib2to3/fixes/fix_metaclass.py +@@ -143,6 +143,7 @@ + + + class FixMetaclass(fixer_base.BaseFix): ++ BM_compatible = True + + PATTERN = """ + classdef +--- a/Lib/lib2to3/fixes/fix_sys_exc.py ++++ b/Lib/lib2to3/fixes/fix_sys_exc.py +@@ -14,6 +14,7 @@ + class FixSysExc(fixer_base.BaseFix): + # This order matches the ordering of sys.exc_info(). + exc_info = [u"exc_type", u"exc_value", u"exc_traceback"] ++ BM_compatible = True + PATTERN = """ + power< 'sys' trailer< dot='.' attribute=(%s) > > + """ % '|'.join("'%s'" % e for e in exc_info) + +Property changes on: Lib/lib2to3 +___________________________________________________________________ +Modified: svnmerge-integrated + - /sandbox/trunk/2to3/lib2to3:1-81478 + + /sandbox/trunk/2to3/lib2to3:1-85508 + +--- a/Lib/bdb.py ++++ b/Lib/bdb.py +@@ -109,6 +109,8 @@ + self.is_skipped_module(frame.f_globals.get('__name__')): + return False + if frame is self.stopframe: ++ if self.stoplineno == -1: ++ return False + return frame.f_lineno >= self.stoplineno + while frame is not None and frame is not self.stopframe: + if frame is self.botframe: +@@ -166,10 +168,12 @@ + but only if we are to stop at or just below this level.""" + pass + +- def _set_stopinfo(self, stopframe, returnframe, stoplineno=-1): ++ def _set_stopinfo(self, stopframe, returnframe, stoplineno=0): + self.stopframe = stopframe + self.returnframe = returnframe + self.quitting = 0 ++ # stoplineno >= 0 means: stop at line >= the stoplineno ++ # stoplineno -1 means: don't stop at all + self.stoplineno = stoplineno + + # Derived classes and clients can call the following methods +@@ -182,7 +186,7 @@ + + def set_step(self): + """Stop after one line of code.""" +- self._set_stopinfo(None,None) ++ self._set_stopinfo(None, None) + + def set_next(self, frame): + """Stop on the next line in or below the given frame.""" +@@ -209,7 +213,7 @@ + + def set_continue(self): + # Don't stop except at breakpoints or when finished +- self._set_stopinfo(self.botframe, None) ++ self._set_stopinfo(self.botframe, None, -1) + if not self.breaks: + # no breakpoints; run without debugger overhead + sys.settrace(None) + +Property changes on: Lib/mailbox.py +___________________________________________________________________ +Deleted: svn:executable + - * + +--- a/Lib/lib-tk/test/test_ttk/test_widgets.py ++++ b/Lib/lib-tk/test/test_ttk/test_widgets.py +@@ -13,7 +13,7 @@ + + def setUp(self): + support.root_deiconify() +- self.widget = ttk.Button() ++ self.widget = ttk.Button(width=0, text="Text") + self.widget.pack() + self.widget.wait_visibility() + +@@ -24,7 +24,10 @@ + + def test_identify(self): + self.widget.update_idletasks() +- self.assertEqual(self.widget.identify(5, 5), "label") ++ self.assertEqual(self.widget.identify( ++ int(self.widget.winfo_width() / 2), ++ int(self.widget.winfo_height() / 2) ++ ), "label") + self.assertEqual(self.widget.identify(-1, -1), "") + + self.assertRaises(Tkinter.TclError, self.widget.identify, None, 5) +@@ -530,7 +533,7 @@ + + def setUp(self): + support.root_deiconify() +- self.nb = ttk.Notebook() ++ self.nb = ttk.Notebook(padding=0) + self.child1 = ttk.Label() + self.child2 = ttk.Label() + self.nb.add(self.child1, text='a') +@@ -717,6 +720,7 @@ + self.nb.tab(self.child1, text='a', underline=0) + self.nb.enable_traversal() + self.nb.focus_force() ++ support.simulate_mouse_click(self.nb, 5, 5) + self.nb.event_generate('') + self.assertEqual(self.nb.select(), str(self.child1)) + +@@ -725,7 +729,7 @@ + + def setUp(self): + support.root_deiconify() +- self.tv = ttk.Treeview() ++ self.tv = ttk.Treeview(padding=0) + + def tearDown(self): + self.tv.destroy() +--- a/Lib/_MozillaCookieJar.py ++++ b/Lib/_MozillaCookieJar.py +@@ -38,9 +38,9 @@ + """ + magic_re = "#( Netscape)? HTTP Cookie File" + header = """\ +- # Netscape HTTP Cookie File +- # http://www.netscape.com/newsref/std/cookie_spec.html +- # This is a generated file! Do not edit. ++# Netscape HTTP Cookie File ++# http://www.netscape.com/newsref/std/cookie_spec.html ++# This is a generated file! Do not edit. + + """ + +--- a/Lib/email/header.py ++++ b/Lib/email/header.py +@@ -92,6 +92,9 @@ + if encoding == 'q': + dec = email.quoprimime.header_decode(encoded) + elif encoding == 'b': ++ paderr = len(encoded) % 4 # Postel's law: add missing padding ++ if paderr: ++ encoded += '==='[:4 - paderr] + try: + dec = email.base64mime.decode(encoded) + except binascii.Error: +--- a/Lib/email/test/test_email_renamed.py ++++ b/Lib/email/test/test_email_renamed.py +@@ -2958,7 +2958,7 @@ + + def test_broken_base64_header(self): + raises = self.assertRaises +- s = 'Subject: =?EUC-KR?B?CSixpLDtKSC/7Liuvsax4iC6uLmwMcijIKHaILzSwd/H0SC8+LCjwLsgv7W/+Mj3IQ?=' ++ s = 'Subject: =?EUC-KR?B?CSixpLDtKSC/7Liuvsax4iC6uLmwMcijIKHaILzSwd/H0SC8+LCjwLsgv7W/+Mj3I ?=' + raises(errors.HeaderParseError, decode_header, s) + + +--- a/Lib/email/test/test_email.py ++++ b/Lib/email/test/test_email.py +@@ -1611,7 +1611,22 @@ + ('rg', None), ('\xe5', 'iso-8859-1'), + ('sbord', None)]) + ++ def test_rfc2047_B_bad_padding(self): ++ s = '=?iso-8859-1?B?%s?=' ++ data = [ # only test complete bytes ++ ('dm==', 'v'), ('dm=', 'v'), ('dm', 'v'), ++ ('dmk=', 'vi'), ('dmk', 'vi') ++ ] ++ for q, a in data: ++ dh = decode_header(s % q) ++ self.assertEqual(dh, [(a, 'iso-8859-1')]) + ++ def test_rfc2047_Q_invalid_digits(self): ++ # issue 10004. ++ s = '=?iso-8659-1?Q?andr=e9=zz?=' ++ self.assertEqual(decode_header(s), ++ [(b'andr\xe9=zz', 'iso-8659-1')]) ++ + + # Test the MIMEMessage class + class TestMIMEMessage(TestEmailBase): +@@ -2225,6 +2240,19 @@ + eq(time.localtime(t)[:6], timetup[:6]) + eq(int(time.strftime('%Y', timetup[:9])), 2003) + ++ def test_parsedate_y2k(self): ++ """Test for parsing a date with a two-digit year. ++ ++ Parsing a date with a two-digit year should return the correct ++ four-digit year. RFC822 allows two-digit years, but RFC2822 (which ++ obsoletes RFC822) requires four-digit years. ++ ++ """ ++ self.assertEqual(Utils.parsedate_tz('25 Feb 03 13:47:26 -0800'), ++ Utils.parsedate_tz('25 Feb 2003 13:47:26 -0800')) ++ self.assertEqual(Utils.parsedate_tz('25 Feb 71 13:47:26 -0800'), ++ Utils.parsedate_tz('25 Feb 1971 13:47:26 -0800')) ++ + def test_parseaddr_empty(self): + self.assertEqual(Utils.parseaddr('<>'), ('', '')) + self.assertEqual(Utils.formataddr(Utils.parseaddr('<>')), '') +@@ -2259,6 +2287,24 @@ + # formataddr() quotes the name if there's a dot in it + self.assertEqual(Utils.formataddr((a, b)), y) + ++ def test_parseaddr_preserves_quoted_pairs_in_addresses(self): ++ # issue 10005. Note that in the third test the second pair of ++ # backslashes is not actually a quoted pair because it is not inside a ++ # comment or quoted string: the address being parsed has a quoted ++ # string containing a quoted backslash, followed by 'example' and two ++ # backslashes, followed by another quoted string containing a space and ++ # the word 'example'. parseaddr copies those two backslashes ++ # literally. Per rfc5322 this is not technically correct since a \ may ++ # not appear in an address outside of a quoted string. It is probably ++ # a sensible Postel interpretation, though. ++ eq = self.assertEqual ++ eq(Utils.parseaddr('""example" example"@example.com'), ++ ('', '""example" example"@example.com')) ++ eq(Utils.parseaddr('"\\"example\\" example"@example.com'), ++ ('', '"\\"example\\" example"@example.com')) ++ eq(Utils.parseaddr('"\\\\"example\\\\" example"@example.com'), ++ ('', '"\\\\"example\\\\" example"@example.com')) ++ + def test_multiline_from_comment(self): + x = """\ + Foo +@@ -2465,7 +2511,40 @@ + -Me + """) + ++ def test_pushCR_LF(self): ++ '''FeedParser BufferedSubFile.push() assumed it received complete ++ line endings. A CR ending one push() followed by a LF starting ++ the next push() added an empty line. ++ ''' ++ imt = [ ++ ("a\r \n", 2), ++ ("b", 0), ++ ("c\n", 1), ++ ("", 0), ++ ("d\r\n", 1), ++ ("e\r", 0), ++ ("\nf", 1), ++ ("\r\n", 1), ++ ] ++ from email.feedparser import BufferedSubFile, NeedMoreData ++ bsf = BufferedSubFile() ++ om = [] ++ nt = 0 ++ for il, n in imt: ++ bsf.push(il) ++ nt += n ++ n1 = 0 ++ while True: ++ ol = bsf.readline() ++ if ol == NeedMoreData: ++ break ++ om.append(ol) ++ n1 += 1 ++ self.assertTrue(n == n1) ++ self.assertTrue(len(om) == nt) ++ self.assertTrue(''.join([il for il, n in imt]) == ''.join(om)) + ++ + + class TestParsers(TestEmailBase): + def test_header_parser(self): +@@ -3031,7 +3110,7 @@ + + def test_broken_base64_header(self): + raises = self.assertRaises +- s = 'Subject: =?EUC-KR?B?CSixpLDtKSC/7Liuvsax4iC6uLmwMcijIKHaILzSwd/H0SC8+LCjwLsgv7W/+Mj3IQ?=' ++ s = 'Subject: =?EUC-KR?B?CSixpLDtKSC/7Liuvsax4iC6uLmwMcijIKHaILzSwd/H0SC8+LCjwLsgv7W/+Mj3I ?=' + raises(Errors.HeaderParseError, decode_header, s) + + +--- a/Lib/email/_parseaddr.py ++++ b/Lib/email/_parseaddr.py +@@ -107,6 +107,18 @@ + tss = int(tss) + except ValueError: + return None ++ # Check for a yy specified in two-digit format, then convert it to the ++ # appropriate four-digit format, according to the POSIX standard. RFC 822 ++ # calls for a two-digit yy, but RFC 2822 (which obsoletes RFC 822) ++ # mandates a 4-digit yy. For more information, see the documentation for ++ # the time module. ++ if yy < 100: ++ # The year is between 1969 and 1999 (inclusive). ++ if yy > 68: ++ yy += 1900 ++ # The year is between 2000 and 2068 (inclusive). ++ else: ++ yy += 2000 + tzoffset = None + tz = tz.upper() + if tz in _timezones: +@@ -148,7 +160,12 @@ + + + def quote(str): +- """Add quotes around a string.""" ++ """Prepare string to be used in a quoted string. ++ ++ Turns backslash and double quote characters into quoted pairs. These ++ are the only characters that need to be quoted inside a quoted string. ++ Does not add the surrounding double quotes. ++ """ + return str.replace('\\', '\\\\').replace('"', '\\"') + + +@@ -306,7 +323,7 @@ + aslist.append('.') + self.pos += 1 + elif self.field[self.pos] == '"': +- aslist.append('"%s"' % self.getquote()) ++ aslist.append('"%s"' % quote(self.getquote())) + elif self.field[self.pos] in self.atomends: + break + else: +--- a/Lib/email/feedparser.py ++++ b/Lib/email/feedparser.py +@@ -104,6 +104,10 @@ + # data after the final RE. In the case of a NL/CR terminated string, + # this is the empty string. + self._partial = parts.pop() ++ #GAN 29Mar09 bugs 1555570, 1721862 Confusion at 8K boundary ending with \r: ++ # is there a \n to follow later? ++ if not self._partial and parts and parts[-1].endswith('\r'): ++ self._partial = parts.pop(-2)+parts.pop() + # parts is a list of strings, alternating between the line contents + # and the eol character(s). Gather up a list of lines after + # re-attaching the newlines. +--- a/Lib/email/quoprimime.py ++++ b/Lib/email/quoprimime.py +@@ -333,4 +333,4 @@ + the high level email.header class for that functionality. + """ + s = s.replace('_', ' ') +- return re.sub(r'=\w{2}', _unquote_match, s) ++ return re.sub(r'=[a-fA-F0-9]{2}', _unquote_match, s) +--- a/Lib/ssl.py ++++ b/Lib/ssl.py +@@ -184,14 +184,16 @@ + else: + return v + else: +- return socket.send(self, data, flags) ++ return self._sock.send(data, flags) + +- def sendto(self, data, addr, flags=0): ++ def sendto(self, data, flags_or_addr, addr=None): + if self._sslobj: + raise ValueError("sendto not allowed on instances of %s" % + self.__class__) ++ elif addr is None: ++ return self._sock.sendto(data, flags_or_addr) + else: +- return socket.sendto(self, data, addr, flags) ++ return self._sock.sendto(data, flags_or_addr, addr) + + def sendall(self, data, flags=0): + if self._sslobj: +@@ -216,7 +218,7 @@ + self.__class__) + return self.read(buflen) + else: +- return socket.recv(self, buflen, flags) ++ return self._sock.recv(buflen, flags) + + def recv_into(self, buffer, nbytes=None, flags=0): + if buffer and (nbytes is None): +@@ -233,21 +235,21 @@ + buffer[:v] = tmp_buffer + return v + else: +- return socket.recv_into(self, buffer, nbytes, flags) ++ return self._sock.recv_into(buffer, nbytes, flags) + +- def recvfrom(self, addr, buflen=1024, flags=0): ++ def recvfrom(self, buflen=1024, flags=0): + if self._sslobj: + raise ValueError("recvfrom not allowed on instances of %s" % + self.__class__) + else: +- return socket.recvfrom(self, addr, buflen, flags) ++ return self._sock.recvfrom(buflen, flags) + + def recvfrom_into(self, buffer, nbytes=None, flags=0): + if self._sslobj: + raise ValueError("recvfrom_into not allowed on instances of %s" % + self.__class__) + else: +- return socket.recvfrom_into(self, buffer, nbytes, flags) ++ return self._sock.recvfrom_into(buffer, nbytes, flags) + + def pending(self): + if self._sslobj: +--- a/Lib/zipfile.py ++++ b/Lib/zipfile.py +@@ -493,6 +493,12 @@ + self.mode = mode + self.name = zipinfo.filename + ++ if hasattr(zipinfo, 'CRC'): ++ self._expected_crc = zipinfo.CRC ++ self._running_crc = crc32(b'') & 0xffffffff ++ else: ++ self._expected_crc = None ++ + def readline(self, limit=-1): + """Read and return a line from the stream. + +@@ -559,16 +565,29 @@ + """Read and return up to n bytes. + If the argument is omitted, None, or negative, data is read and returned until EOF is reached.. + """ +- + buf = '' +- while n < 0 or n is None or n > len(buf): +- data = self.read1(n) ++ if n is None: ++ n = -1 ++ while True: ++ if n < 0: ++ data = self.read1(n) ++ elif n > len(buf): ++ data = self.read1(n - len(buf)) ++ else: ++ return buf + if len(data) == 0: + return buf +- + buf += data + +- return buf ++ def _update_crc(self, newdata, eof): ++ # Update the CRC using the given data. ++ if self._expected_crc is None: ++ # No need to compute the CRC if we don't have a reference value ++ return ++ self._running_crc = crc32(newdata, self._running_crc) & 0xffffffff ++ # Check the CRC if we're at the end of the file ++ if eof and self._running_crc != self._expected_crc: ++ raise BadZipfile("Bad CRC-32 for file %r" % self.name) + + def read1(self, n): + """Read up to n bytes with at most one read() system call.""" +@@ -593,6 +612,7 @@ + data = ''.join(map(self._decrypter, data)) + + if self._compress_type == ZIP_STORED: ++ self._update_crc(data, eof=(self._compress_left==0)) + self._readbuffer = self._readbuffer[self._offset:] + data + self._offset = 0 + else: +@@ -608,9 +628,11 @@ + ) + + self._unconsumed = self._decompressor.unconsumed_tail +- if len(self._unconsumed) == 0 and self._compress_left == 0: ++ eof = len(self._unconsumed) == 0 and self._compress_left == 0 ++ if eof: + data += self._decompressor.flush() + ++ self._update_crc(data, eof=eof) + self._readbuffer = self._readbuffer[self._offset:] + data + self._offset = 0 + +@@ -1349,7 +1371,9 @@ + print USAGE + sys.exit(1) + zf = ZipFile(args[1], 'r') +- zf.testzip() ++ badfile = zf.testzip() ++ if badfile: ++ print("The following enclosed file is corrupted: {!r}".format(badfile)) + print "Done testing" + + elif args[0] == '-e': +--- a/Lib/argparse.py ++++ b/Lib/argparse.py +@@ -1563,13 +1563,16 @@ + + # add help and version arguments if necessary + # (using explicit default to override global argument_default) ++ default_prefix = '-' if '-' in prefix_chars else prefix_chars[0] + if self.add_help: + self.add_argument( +- '-h', '--help', action='help', default=SUPPRESS, ++ default_prefix+'h', default_prefix*2+'help', ++ action='help', default=SUPPRESS, + help=_('show this help message and exit')) + if self.version: + self.add_argument( +- '-v', '--version', action='version', default=SUPPRESS, ++ default_prefix+'v', default_prefix*2+'version', ++ action='version', default=SUPPRESS, + version=self.version, + help=_("show program's version number and exit")) + +--- a/Lib/doctest.py ++++ b/Lib/doctest.py +@@ -216,7 +216,8 @@ + # get_data() opens files as 'rb', so one must do the equivalent + # conversion as universal newlines would do. + return file_contents.replace(os.linesep, '\n'), filename +- return open(filename).read(), filename ++ with open(filename) as f: ++ return f.read(), filename + + # Use sys.stdout encoding for ouput. + _encoding = getattr(sys.__stdout__, 'encoding', None) or 'utf-8' +@@ -263,6 +264,9 @@ + StringIO.truncate(self, size) + if hasattr(self, "softspace"): + del self.softspace ++ if not self.buf: ++ # Reset it to an empty string, to make sure it's not unicode. ++ self.buf = '' + + # Worst-case linear-time ellipsis matching. + def _ellipsis_match(want, got): +@@ -332,6 +336,8 @@ + self.__out = out + self.__debugger_used = False + pdb.Pdb.__init__(self, stdout=out) ++ # still use input() to get user input ++ self.use_rawinput = 1 + + def set_trace(self, frame=None): + self.__debugger_used = True +@@ -1322,13 +1328,15 @@ + self.tries += t + + __LINECACHE_FILENAME_RE = re.compile(r'[\w\.]+)' ++ r'(?P.+)' + r'\[(?P\d+)\]>$') + def __patched_linecache_getlines(self, filename, module_globals=None): + m = self.__LINECACHE_FILENAME_RE.match(filename) + if m and m.group('name') == self.test.name: + example = self.test.examples[int(m.group('examplenum'))] +- source = example.source.encode('ascii', 'backslashreplace') ++ source = example.source ++ if isinstance(source, unicode): ++ source = source.encode('ascii', 'backslashreplace') + return source.splitlines(True) + else: + return self.save_linecache_getlines(filename, module_globals) +@@ -1378,12 +1386,17 @@ + self.save_linecache_getlines = linecache.getlines + linecache.getlines = self.__patched_linecache_getlines + ++ # Make sure sys.displayhook just prints the value to stdout ++ save_displayhook = sys.displayhook ++ sys.displayhook = sys.__displayhook__ ++ + try: + return self.__run(test, compileflags, out) + finally: + sys.stdout = save_stdout + pdb.set_trace = save_set_trace + linecache.getlines = self.save_linecache_getlines ++ sys.displayhook = save_displayhook + if clear_globs: + test.globs.clear() + +@@ -1761,7 +1774,7 @@ + + Return (#failures, #tests). + +- See doctest.__doc__ for an overview. ++ See help(doctest) for an overview. + + Optional keyword arg "name" gives the name of the module; by default + use m.__name__. +--- a/Lib/httplib.py ++++ b/Lib/httplib.py +@@ -67,6 +67,7 @@ + """ + + from array import array ++import os + import socket + from sys import py3kwarning + from urlparse import urlsplit +@@ -638,6 +639,9 @@ + amt -= len(chunk) + return ''.join(s) + ++ def fileno(self): ++ return self.fp.fileno() ++ + def getheader(self, name, default=None): + if self.msg is None: + raise ResponseNotReady() +@@ -748,35 +752,25 @@ + self.__response = None + self.__state = _CS_IDLE + +- def send(self, str): +- """Send `str' to the server.""" ++ def send(self, data): ++ """Send `data' to the server.""" + if self.sock is None: + if self.auto_open: + self.connect() + else: + raise NotConnected() + +- # send the data to the server. if we get a broken pipe, then close +- # the socket. we want to reconnect when somebody tries to send again. +- # +- # NOTE: we DO propagate the error, though, because we cannot simply +- # ignore the error... the caller will know if they can retry. + if self.debuglevel > 0: +- print "send:", repr(str) +- try: +- blocksize=8192 +- if hasattr(str,'read') and not isinstance(str, array): +- if self.debuglevel > 0: print "sendIng a read()able" +- data=str.read(blocksize) +- while data: +- self.sock.sendall(data) +- data=str.read(blocksize) +- else: +- self.sock.sendall(str) +- except socket.error, v: +- if v.args[0] == 32: # Broken pipe +- self.close() +- raise ++ print "send:", repr(data) ++ blocksize = 8192 ++ if hasattr(data,'read') and not isinstance(data, array): ++ if self.debuglevel > 0: print "sendIng a read()able" ++ datablock = data.read(blocksize) ++ while datablock: ++ self.sock.sendall(datablock) ++ datablock = data.read(blocksize) ++ else: ++ self.sock.sendall(data) + + def _output(self, s): + """Add a line of output to the current request buffer. +@@ -848,9 +842,9 @@ + self._method = method + if not url: + url = '/' +- str = '%s %s %s' % (method, url, self._http_vsn_str) ++ hdr = '%s %s %s' % (method, url, self._http_vsn_str) + +- self._output(str) ++ self._output(hdr) + + if self._http_vsn == 11: + # Issue some standard headers for better HTTP/1.1 compliance +@@ -921,8 +915,8 @@ + if self.__state != _CS_REQ_STARTED: + raise CannotSendHeader() + +- str = '%s: %s' % (header, '\r\n\t'.join(values)) +- self._output(str) ++ hdr = '%s: %s' % (header, '\r\n\t'.join([str(v) for v in values])) ++ self._output(hdr) + + def endheaders(self, message_body=None): + """Indicate that the last header line has been sent to the server. +@@ -941,16 +935,8 @@ + + def request(self, method, url, body=None, headers={}): + """Send a complete request to the server.""" ++ self._send_request(method, url, body, headers) + +- try: +- self._send_request(method, url, body, headers) +- except socket.error, v: +- # trap 'Broken pipe' if we're allowed to automatically reconnect +- if v.args[0] != 32 or not self.auto_open: +- raise +- # try one more time +- self._send_request(method, url, body, headers) +- + def _set_content_length(self, body): + # Set the content-length based on the body. + thelen = None +@@ -959,7 +945,6 @@ + except TypeError, te: + # If this is a file-like object, try to + # fstat its file descriptor +- import os + try: + thelen = str(os.fstat(body.fileno()).st_size) + except (AttributeError, OSError): +@@ -970,7 +955,7 @@ + self.putheader('Content-Length', thelen) + + def _send_request(self, method, url, body, headers): +- # honour explicitly requested Host: and Accept-Encoding headers ++ # Honor explicitly requested Host: and Accept-Encoding: headers. + header_names = dict.fromkeys([k.lower() for k in headers]) + skips = {} + if 'host' in header_names: +--- a/Lib/urllib2.py ++++ b/Lib/urllib2.py +@@ -109,7 +109,7 @@ + from StringIO import StringIO + + from urllib import (unwrap, unquote, splittype, splithost, quote, +- addinfourl, splitport, ++ addinfourl, splitport, splittag, + splitattr, ftpwrapper, splituser, splitpasswd, splitvalue) + + # support for FileHandler, proxies via environment variables +@@ -190,6 +190,7 @@ + origin_req_host=None, unverifiable=False): + # unwrap('') --> 'type://host/path' + self.__original = unwrap(url) ++ self.__original, fragment = splittag(self.__original) + self.type = None + # self.__r_type is what's left after doing the splittype + self.host = None +@@ -821,6 +822,9 @@ + self.add_password = self.passwd.add_password + self.retried = 0 + ++ def reset_retry_count(self): ++ self.retried = 0 ++ + def http_error_auth_reqed(self, authreq, host, req, headers): + # host may be an authority (without userinfo) or a URL with an + # authority +@@ -839,7 +843,10 @@ + if mo: + scheme, quote, realm = mo.groups() + if scheme.lower() == 'basic': +- return self.retry_http_basic_auth(host, req, realm) ++ response = self.retry_http_basic_auth(host, req, realm) ++ if response and response.code != 401: ++ self.retried = 0 ++ return response + + def retry_http_basic_auth(self, host, req, realm): + user, pw = self.passwd.find_user_password(realm, host) +@@ -860,8 +867,10 @@ + + def http_error_401(self, req, fp, code, msg, headers): + url = req.get_full_url() +- return self.http_error_auth_reqed('www-authenticate', +- url, req, headers) ++ response = self.http_error_auth_reqed('www-authenticate', ++ url, req, headers) ++ self.reset_retry_count() ++ return response + + + class ProxyBasicAuthHandler(AbstractBasicAuthHandler, BaseHandler): +@@ -874,8 +883,10 @@ + # should not, RFC 3986 s. 3.2.1) support requests for URLs containing + # userinfo. + authority = req.get_host() +- return self.http_error_auth_reqed('proxy-authenticate', ++ response = self.http_error_auth_reqed('proxy-authenticate', + authority, req, headers) ++ self.reset_retry_count() ++ return response + + + def randombytes(n): +@@ -1116,8 +1127,10 @@ + h = http_class(host, timeout=req.timeout) # will parse host:port + h.set_debuglevel(self._debuglevel) + +- headers = dict(req.headers) +- headers.update(req.unredirected_hdrs) ++ headers = dict(req.unredirected_hdrs) ++ headers.update(dict((k, v) for k, v in req.headers.items() ++ if k not in headers)) ++ + # We want to make an HTTP/1.1 request, but the addinfourl + # class isn't prepared to deal with a persistent connection. + # It will try to read all remaining data from the socket, +@@ -1258,11 +1271,18 @@ + + return [part.strip() for part in res] + ++def _safe_gethostbyname(host): ++ try: ++ return socket.gethostbyname(host) ++ except socket.gaierror: ++ return None ++ + class FileHandler(BaseHandler): + # Use local file or FTP depending on form of URL + def file_open(self, req): + url = req.get_selector() +- if url[:2] == '//' and url[2:3] != '/': ++ if url[:2] == '//' and url[2:3] != '/' and (req.host and ++ req.host != 'localhost'): + req.type = 'ftp' + return self.parent.open(req) + else: +@@ -1298,7 +1318,7 @@ + if host: + host, port = splitport(host) + if not host or \ +- (not port and socket.gethostbyname(host) in self.get_names()): ++ (not port and _safe_gethostbyname(host) in self.get_names()): + if host: + origurl = 'file://' + host + filename + else: +--- a/Lib/_threading_local.py ++++ b/Lib/_threading_local.py +@@ -195,6 +195,10 @@ + lock.release() + + def __setattr__(self, name, value): ++ if name == '__dict__': ++ raise AttributeError( ++ "%r object attribute '__dict__' is read-only" ++ % self.__class__.__name__) + lock = object.__getattribute__(self, '_local__lock') + lock.acquire() + try: +@@ -204,6 +208,10 @@ + lock.release() + + def __delattr__(self, name): ++ if name == '__dict__': ++ raise AttributeError( ++ "%r object attribute '__dict__' is read-only" ++ % self.__class__.__name__) + lock = object.__getattribute__(self, '_local__lock') + lock.acquire() + try: +--- a/Lib/ConfigParser.py ++++ b/Lib/ConfigParser.py +@@ -398,12 +398,11 @@ + for section in self._sections: + fp.write("[%s]\n" % section) + for (key, value) in self._sections[section].items(): +- if key != "__name__": +- if value is None: +- fp.write("%s\n" % (key)) +- else: +- fp.write("%s = %s\n" % +- (key, str(value).replace('\n', '\n\t'))) ++ if key == "__name__": ++ continue ++ if (value is not None) or (self._optcre == self.OPTCRE): ++ key = " = ".join((key, str(value).replace('\n', '\n\t'))) ++ fp.write("%s\n" % (key)) + fp.write("\n") + + def remove_option(self, section, option): +@@ -464,10 +463,10 @@ + leading whitespace. Blank lines, lines beginning with a '#', + and just about everything else are ignored. + """ +- cursect = None # None, or a dictionary ++ cursect = None # None, or a dictionary + optname = None + lineno = 0 +- e = None # None, or an exception ++ e = None # None, or an exception + while True: + line = fp.readline() + if not line: +@@ -483,7 +482,7 @@ + if line[0].isspace() and cursect is not None and optname: + value = line.strip() + if value: +- cursect[optname] = "%s\n%s" % (cursect[optname], value) ++ cursect[optname].append(value) + # a section header or option header? + else: + # is it a section header? +@@ -508,6 +507,7 @@ + mo = self._optcre.match(line) + if mo: + optname, vi, optval = mo.group('option', 'vi', 'value') ++ optname = self.optionxform(optname.rstrip()) + # This check is fine because the OPTCRE cannot + # match if it would set optval to None + if optval is not None: +@@ -518,11 +518,13 @@ + if pos != -1 and optval[pos-1].isspace(): + optval = optval[:pos] + optval = optval.strip() +- # allow empty values +- if optval == '""': +- optval = '' +- optname = self.optionxform(optname.rstrip()) +- cursect[optname] = optval ++ # allow empty values ++ if optval == '""': ++ optval = '' ++ cursect[optname] = [optval] ++ else: ++ # valueless option handling ++ cursect[optname] = optval + else: + # a non-fatal parsing error occurred. set up the + # exception but keep going. the exception will be +@@ -535,18 +537,26 @@ + if e: + raise e + ++ # join the multi-line values collected while reading ++ all_sections = [self._defaults] ++ all_sections.extend(self._sections.values()) ++ for options in all_sections: ++ for name, val in options.items(): ++ if isinstance(val, list): ++ options[name] = '\n'.join(val) + + class ConfigParser(RawConfigParser): + + def get(self, section, option, raw=False, vars=None): + """Get an option value for a given section. + +- All % interpolations are expanded in the return values, based on the +- defaults passed into the constructor, unless the optional argument +- `raw' is true. Additional substitutions may be provided using the +- `vars' argument, which must be a dictionary whose contents overrides +- any pre-existing defaults. ++ If `vars' is provided, it must be a dictionary. The option is looked up ++ in `vars' (if provided), `section', and in `defaults' in that order. + ++ All % interpolations are expanded in the return values, unless the ++ optional argument `raw' is true. Values for interpolation keys are ++ looked up in the same manner as the option. ++ + The section DEFAULT is special. + """ + d = self._defaults.copy() +@@ -689,13 +699,13 @@ + if self._optcre is self.OPTCRE or value: + if not isinstance(value, basestring): + raise TypeError("option values must be strings") +- # check for bad percent signs: +- # first, replace all "good" interpolations +- tmp_value = value.replace('%%', '') +- tmp_value = self._interpvar_re.sub('', tmp_value) +- # then, check if there's a lone percent sign left +- percent_index = tmp_value.find('%') +- if percent_index != -1: +- raise ValueError("invalid interpolation syntax in %r at " +- "position %d" % (value, percent_index)) ++ if value is not None: ++ # check for bad percent signs: ++ # first, replace all "good" interpolations ++ tmp_value = value.replace('%%', '') ++ tmp_value = self._interpvar_re.sub('', tmp_value) ++ # then, check if there's a lone percent sign left ++ if '%' in tmp_value: ++ raise ValueError("invalid interpolation syntax in %r at " ++ "position %d" % (value, tmp_value.find('%'))) + ConfigParser.set(self, section, option, value) +--- a/Lib/subprocess.py ++++ b/Lib/subprocess.py +@@ -853,8 +853,8 @@ + startupinfo.dwFlags |= _subprocess.STARTF_USESHOWWINDOW + startupinfo.wShowWindow = _subprocess.SW_HIDE + comspec = os.environ.get("COMSPEC", "cmd.exe") +- args = comspec + " /c " + args +- if (_subprocess.GetVersion() >= 0x80000000L or ++ args = '{} /c "{}"'.format (comspec, args) ++ if (_subprocess.GetVersion() >= 0x80000000 or + os.path.basename(comspec).lower() == "command.com"): + # Win9x, or using command.com on NT. We need to + # use the w9xpopen intermediate program. For more +@@ -886,6 +886,19 @@ + # translate errno using _sys_errlist (or simliar), but + # how can this be done from Python? + raise WindowsError(*e.args) ++ finally: ++ # Child is launched. Close the parent's copy of those pipe ++ # handles that only the child should have open. You need ++ # to make sure that no handles to the write end of the ++ # output pipe are maintained in this process or else the ++ # pipe will not close when the child process exits and the ++ # ReadFile will hang. ++ if p2cread is not None: ++ p2cread.Close() ++ if c2pwrite is not None: ++ c2pwrite.Close() ++ if errwrite is not None: ++ errwrite.Close() + + # Retain the process handle, but close the thread handle + self._child_created = True +@@ -893,20 +906,6 @@ + self.pid = pid + ht.Close() + +- # Child is launched. Close the parent's copy of those pipe +- # handles that only the child should have open. You need +- # to make sure that no handles to the write end of the +- # output pipe are maintained in this process or else the +- # pipe will not close when the child process exits and the +- # ReadFile will hang. +- if p2cread is not None: +- p2cread.Close() +- if c2pwrite is not None: +- c2pwrite.Close() +- if errwrite is not None: +- errwrite.Close() +- +- + def _internal_poll(self, _deadstate=None, + _WaitForSingleObject=_subprocess.WaitForSingleObject, + _WAIT_OBJECT_0=_subprocess.WAIT_OBJECT_0, +@@ -994,7 +993,7 @@ + elif sig == signal.CTRL_BREAK_EVENT: + os.kill(self.pid, signal.CTRL_BREAK_EVENT) + else: +- raise ValueError("Only SIGTERM is supported on Windows") ++ raise ValueError("Unsupported signal: {}".format(sig)) + + def terminate(self): + """Terminates the process +@@ -1091,6 +1090,8 @@ + + if shell: + args = ["/bin/sh", "-c"] + args ++ if executable: ++ args[0] = executable + + if executable is None: + executable = args[0] +--- a/Lib/test/test_profilehooks.py ++++ b/Lib/test/test_profilehooks.py +@@ -1,385 +0,0 @@ +-import pprint +-import sys +-import unittest +- +-from test import test_support +- +-class TestGetProfile(unittest.TestCase): +- def setUp(self): +- sys.setprofile(None) +- +- def tearDown(self): +- sys.setprofile(None) +- +- def test_empty(self): +- assert sys.getprofile() is None +- +- def test_setget(self): +- def fn(*args): +- pass +- +- sys.setprofile(fn) +- assert sys.getprofile() == fn +- +-class HookWatcher: +- def __init__(self): +- self.frames = [] +- self.events = [] +- +- def callback(self, frame, event, arg): +- if (event == "call" +- or event == "return" +- or event == "exception"): +- self.add_event(event, frame) +- +- def add_event(self, event, frame=None): +- """Add an event to the log.""" +- if frame is None: +- frame = sys._getframe(1) +- +- try: +- frameno = self.frames.index(frame) +- except ValueError: +- frameno = len(self.frames) +- self.frames.append(frame) +- +- self.events.append((frameno, event, ident(frame))) +- +- def get_events(self): +- """Remove calls to add_event().""" +- disallowed = [ident(self.add_event.im_func), ident(ident)] +- self.frames = None +- +- return [item for item in self.events if item[2] not in disallowed] +- +- +-class ProfileSimulator(HookWatcher): +- def __init__(self, testcase): +- self.testcase = testcase +- self.stack = [] +- HookWatcher.__init__(self) +- +- def callback(self, frame, event, arg): +- # Callback registered with sys.setprofile()/sys.settrace() +- self.dispatch[event](self, frame) +- +- def trace_call(self, frame): +- self.add_event('call', frame) +- self.stack.append(frame) +- +- def trace_return(self, frame): +- self.add_event('return', frame) +- self.stack.pop() +- +- def trace_exception(self, frame): +- self.testcase.fail( +- "the profiler should never receive exception events") +- +- def trace_pass(self, frame): +- pass +- +- dispatch = { +- 'call': trace_call, +- 'exception': trace_exception, +- 'return': trace_return, +- 'c_call': trace_pass, +- 'c_return': trace_pass, +- 'c_exception': trace_pass, +- } +- +- +-class TestCaseBase(unittest.TestCase): +- def check_events(self, callable, expected): +- events = capture_events(callable, self.new_watcher()) +- if events != expected: +- self.fail("Expected events:\n%s\nReceived events:\n%s" +- % (pprint.pformat(expected), pprint.pformat(events))) +- +- +-class ProfileHookTestCase(TestCaseBase): +- def new_watcher(self): +- return HookWatcher() +- +- def test_simple(self): +- def f(p): +- pass +- f_ident = ident(f) +- self.check_events(f, [(1, 'call', f_ident), +- (1, 'return', f_ident), +- ]) +- +- def test_exception(self): +- def f(p): +- 1./0 +- f_ident = ident(f) +- self.check_events(f, [(1, 'call', f_ident), +- (1, 'return', f_ident), +- ]) +- +- def test_caught_exception(self): +- def f(p): +- try: 1./0 +- except: pass +- f_ident = ident(f) +- self.check_events(f, [(1, 'call', f_ident), +- (1, 'return', f_ident), +- ]) +- +- def test_caught_nested_exception(self): +- def f(p): +- try: 1./0 +- except: pass +- f_ident = ident(f) +- self.check_events(f, [(1, 'call', f_ident), +- (1, 'return', f_ident), +- ]) +- +- def test_nested_exception(self): +- def f(p): +- 1./0 +- f_ident = ident(f) +- self.check_events(f, [(1, 'call', f_ident), +- # This isn't what I expected: +- # (0, 'exception', protect_ident), +- # I expected this again: +- (1, 'return', f_ident), +- ]) +- +- def test_exception_in_except_clause(self): +- def f(p): +- 1./0 +- def g(p): +- try: +- f(p) +- except: +- try: f(p) +- except: pass +- f_ident = ident(f) +- g_ident = ident(g) +- self.check_events(g, [(1, 'call', g_ident), +- (2, 'call', f_ident), +- (2, 'return', f_ident), +- (3, 'call', f_ident), +- (3, 'return', f_ident), +- (1, 'return', g_ident), +- ]) +- +- def test_exception_propogation(self): +- def f(p): +- 1./0 +- def g(p): +- try: f(p) +- finally: p.add_event("falling through") +- f_ident = ident(f) +- g_ident = ident(g) +- self.check_events(g, [(1, 'call', g_ident), +- (2, 'call', f_ident), +- (2, 'return', f_ident), +- (1, 'falling through', g_ident), +- (1, 'return', g_ident), +- ]) +- +- def test_raise_twice(self): +- def f(p): +- try: 1./0 +- except: 1./0 +- f_ident = ident(f) +- self.check_events(f, [(1, 'call', f_ident), +- (1, 'return', f_ident), +- ]) +- +- def test_raise_reraise(self): +- def f(p): +- try: 1./0 +- except: raise +- f_ident = ident(f) +- self.check_events(f, [(1, 'call', f_ident), +- (1, 'return', f_ident), +- ]) +- +- def test_raise(self): +- def f(p): +- raise Exception() +- f_ident = ident(f) +- self.check_events(f, [(1, 'call', f_ident), +- (1, 'return', f_ident), +- ]) +- +- def test_distant_exception(self): +- def f(): +- 1./0 +- def g(): +- f() +- def h(): +- g() +- def i(): +- h() +- def j(p): +- i() +- f_ident = ident(f) +- g_ident = ident(g) +- h_ident = ident(h) +- i_ident = ident(i) +- j_ident = ident(j) +- self.check_events(j, [(1, 'call', j_ident), +- (2, 'call', i_ident), +- (3, 'call', h_ident), +- (4, 'call', g_ident), +- (5, 'call', f_ident), +- (5, 'return', f_ident), +- (4, 'return', g_ident), +- (3, 'return', h_ident), +- (2, 'return', i_ident), +- (1, 'return', j_ident), +- ]) +- +- def test_generator(self): +- def f(): +- for i in range(2): +- yield i +- def g(p): +- for i in f(): +- pass +- f_ident = ident(f) +- g_ident = ident(g) +- self.check_events(g, [(1, 'call', g_ident), +- # call the iterator twice to generate values +- (2, 'call', f_ident), +- (2, 'return', f_ident), +- (2, 'call', f_ident), +- (2, 'return', f_ident), +- # once more; returns end-of-iteration with +- # actually raising an exception +- (2, 'call', f_ident), +- (2, 'return', f_ident), +- (1, 'return', g_ident), +- ]) +- +- def test_stop_iteration(self): +- def f(): +- for i in range(2): +- yield i +- raise StopIteration +- def g(p): +- for i in f(): +- pass +- f_ident = ident(f) +- g_ident = ident(g) +- self.check_events(g, [(1, 'call', g_ident), +- # call the iterator twice to generate values +- (2, 'call', f_ident), +- (2, 'return', f_ident), +- (2, 'call', f_ident), +- (2, 'return', f_ident), +- # once more to hit the raise: +- (2, 'call', f_ident), +- (2, 'return', f_ident), +- (1, 'return', g_ident), +- ]) +- +- +-class ProfileSimulatorTestCase(TestCaseBase): +- def new_watcher(self): +- return ProfileSimulator(self) +- +- def test_simple(self): +- def f(p): +- pass +- f_ident = ident(f) +- self.check_events(f, [(1, 'call', f_ident), +- (1, 'return', f_ident), +- ]) +- +- def test_basic_exception(self): +- def f(p): +- 1./0 +- f_ident = ident(f) +- self.check_events(f, [(1, 'call', f_ident), +- (1, 'return', f_ident), +- ]) +- +- def test_caught_exception(self): +- def f(p): +- try: 1./0 +- except: pass +- f_ident = ident(f) +- self.check_events(f, [(1, 'call', f_ident), +- (1, 'return', f_ident), +- ]) +- +- def test_distant_exception(self): +- def f(): +- 1./0 +- def g(): +- f() +- def h(): +- g() +- def i(): +- h() +- def j(p): +- i() +- f_ident = ident(f) +- g_ident = ident(g) +- h_ident = ident(h) +- i_ident = ident(i) +- j_ident = ident(j) +- self.check_events(j, [(1, 'call', j_ident), +- (2, 'call', i_ident), +- (3, 'call', h_ident), +- (4, 'call', g_ident), +- (5, 'call', f_ident), +- (5, 'return', f_ident), +- (4, 'return', g_ident), +- (3, 'return', h_ident), +- (2, 'return', i_ident), +- (1, 'return', j_ident), +- ]) +- +- +-def ident(function): +- if hasattr(function, "f_code"): +- code = function.f_code +- else: +- code = function.func_code +- return code.co_firstlineno, code.co_name +- +- +-def protect(f, p): +- try: f(p) +- except: pass +- +-protect_ident = ident(protect) +- +- +-def capture_events(callable, p=None): +- try: +- sys.setprofile() +- except TypeError: +- pass +- else: +- raise test_support.TestFailed( +- 'sys.setprofile() did not raise TypeError') +- +- if p is None: +- p = HookWatcher() +- sys.setprofile(p.callback) +- protect(callable, p) +- sys.setprofile(None) +- return p.get_events()[1:-1] +- +- +-def show_events(callable): +- import pprint +- pprint.pprint(capture_events(callable)) +- +- +-def test_main(): +- test_support.run_unittest( +- TestGetProfile, +- ProfileHookTestCase, +- ProfileSimulatorTestCase +- ) +- +- +-if __name__ == "__main__": +- test_main() +--- a/Lib/test/test_math.py ++++ b/Lib/test/test_math.py +@@ -876,14 +876,9 @@ + + self.assertRaises(TypeError, math.trunc) + self.assertRaises(TypeError, math.trunc, 1, 2) +- # XXX: This is not ideal, but see the comment in math_trunc(). +- self.assertRaises(AttributeError, math.trunc, TestNoTrunc()) ++ self.assertRaises((AttributeError, TypeError), math.trunc, ++ TestNoTrunc()) + +- t = TestNoTrunc() +- t.__trunc__ = lambda *args: args +- self.assertEquals((), math.trunc(t)) +- self.assertRaises(TypeError, math.trunc, t, 0) +- + def testIsnan(self): + self.assertTrue(math.isnan(float("nan"))) + self.assertTrue(math.isnan(float("inf")* 0.)) +--- a/Lib/test/test_urllib2_localnet.py ++++ b/Lib/test/test_urllib2_localnet.py +@@ -501,7 +501,31 @@ + # parameterize the framework with a mock resolver. + urllib2.urlopen, "http://sadflkjsasf.i.nvali.d./") + ++ def test_iteration(self): ++ expected_response = "pycon 2008..." ++ handler = self.start_server([(200, [], expected_response)]) ++ try: ++ data = urllib2.urlopen("http://localhost:%s" % handler.port) ++ for line in data: ++ self.assertEqual(line, expected_response) ++ finally: ++ self.server.stop() + ++ def ztest_line_iteration(self): ++ lines = ["We\n", "got\n", "here\n", "verylong " * 8192 + "\n"] ++ expected_response = "".join(lines) ++ handler = self.start_server([(200, [], expected_response)]) ++ try: ++ data = urllib2.urlopen("http://localhost:%s" % handler.port) ++ for index, line in enumerate(data): ++ self.assertEqual(line, lines[index], ++ "Fetched line number %s doesn't match expected:\n" ++ " Expected length was %s, got %s" % ++ (index, len(lines[index]), len(line))) ++ finally: ++ self.server.stop() ++ self.assertEqual(index + 1, len(lines)) ++ + def test_main(): + # We will NOT depend on the network resource flag + # (Lib/test/regrtest.py -u network) since all tests here are only +--- a/Lib/test/test_optparse.py ++++ b/Lib/test/test_optparse.py +@@ -791,15 +791,13 @@ + (options, args) = self.assertParseOK(["-q"], + {'verbose': 0}, + []) +- if hasattr(__builtins__, 'False'): +- self.assertTrue(options.verbose is False) ++ self.assertTrue(options.verbose is False) + + def test_bool_true(self): + (options, args) = self.assertParseOK(["-v"], + {'verbose': 1}, + []) +- if hasattr(__builtins__, 'True'): +- self.assertTrue(options.verbose is True) ++ self.assertTrue(options.verbose is True) + + def test_bool_flicker_on_and_off(self): + self.assertParseOK(["-qvq", "-q", "-v"], +--- a/Lib/test/regrtest.py ++++ b/Lib/test/regrtest.py +@@ -133,11 +133,7 @@ + decimal - Test the decimal module against a large suite that + verifies compliance with standards. + +- compiler - Test the compiler package by compiling all the source +- in the standard library and test suite. This takes +- a long time. Enabling this resource also allows +- test_tokenize to verify round-trip lexing on every +- file in the test library. ++ cpu - Used for certain CPU-heavy tests. + + subprocess Run all tests for the subprocess module. + +@@ -215,7 +211,7 @@ + from test import test_support + + RESOURCE_NAMES = ('audio', 'curses', 'largefile', 'network', 'bsddb', +- 'decimal', 'compiler', 'subprocess', 'urlfetch', 'gui', ++ 'decimal', 'cpu', 'subprocess', 'urlfetch', 'gui', + 'xpickle') + + TEMPDIR = os.path.abspath(tempfile.gettempdir()) +@@ -365,9 +361,6 @@ + usage(2, "-T and -j don't go together!") + if use_mp and findleaks: + usage(2, "-l and -j don't go together!") +- if use_mp and max(sys.flags): +- # TODO: inherit the environment and the flags +- print "Warning: flags and environment variables are ignored with -j option" + + good = [] + bad = [] +@@ -496,6 +489,8 @@ + ) + yield (test, args_tuple) + pending = tests_and_args() ++ opt_args = test_support.args_from_interpreter_flags() ++ base_cmd = [sys.executable] + opt_args + ['-m', 'test.regrtest'] + def work(): + # A worker thread. + try: +@@ -506,10 +501,10 @@ + output.put((None, None, None, None)) + return + # -E is needed by some tests, e.g. test_import +- popen = Popen([sys.executable, '-E', '-m', 'test.regrtest', +- '--slaveargs', json.dumps(args_tuple)], ++ popen = Popen(base_cmd + ['--slaveargs', json.dumps(args_tuple)], + stdout=PIPE, stderr=PIPE, +- universal_newlines=True, close_fds=True) ++ universal_newlines=True, ++ close_fds=(os.name != 'nt')) + stdout, stderr = popen.communicate() + # Strip last refcount output line if it exists, since it + # comes from the shutdown of the interpreter in the subcommand. +@@ -761,7 +756,7 @@ + # the corresponding method names. + + resources = ('sys.argv', 'cwd', 'sys.stdin', 'sys.stdout', 'sys.stderr', +- 'os.environ', 'sys.path') ++ 'os.environ', 'sys.path', 'asyncore.socket_map') + + def get_sys_argv(self): + return id(sys.argv), sys.argv, sys.argv[:] +@@ -802,6 +797,15 @@ + sys.path = saved_path[1] + sys.path[:] = saved_path[2] + ++ def get_asyncore_socket_map(self): ++ asyncore = sys.modules.get('asyncore') ++ return asyncore and asyncore.socket_map or {} ++ def restore_asyncore_socket_map(self, saved_map): ++ asyncore = sys.modules.get('asyncore') ++ if asyncore is not None: ++ asyncore.socket_map.clear() ++ asyncore.socket_map.update(saved_map) ++ + def resource_info(self): + for name in self.resources: + method_suffix = name.replace('.', '_') +@@ -1491,7 +1495,13 @@ + return self.expected + + if __name__ == '__main__': +- # Simplification for findtestdir(). ++ # findtestdir() gets the dirname out of __file__, so we have to make it ++ # absolute before changing the working directory. ++ # For example __file__ may be relative when running trace or profile. ++ # See issue #9323. ++ __file__ = os.path.abspath(__file__) ++ ++ # sanity check + assert __file__ == os.path.abspath(sys.argv[0]) + + # When tests are run from the Python build directory, it is best practice +--- a/Lib/test/test_robotparser.py ++++ b/Lib/test/test_robotparser.py +@@ -202,28 +202,54 @@ + RobotTest(13, doc, good, bad, agent="googlebot") + + ++# 14. For issue #6325 (query string support) ++doc = """ ++User-agent: * ++Disallow: /some/path?name=value ++""" + ++good = ['/some/path'] ++bad = ['/some/path?name=value'] ++ ++RobotTest(14, doc, good, bad) ++ ++# 15. For issue #4108 (obey first * entry) ++doc = """ ++User-agent: * ++Disallow: /some/path ++ ++User-agent: * ++Disallow: /another/path ++""" ++ ++good = ['/another/path'] ++bad = ['/some/path'] ++ ++RobotTest(15, doc, good, bad) ++ ++ + class NetworkTestCase(unittest.TestCase): + + def testPasswordProtectedSite(self): + test_support.requires('network') +- # XXX it depends on an external resource which could be unavailable +- url = 'http://mueblesmoraleda.com' +- parser = robotparser.RobotFileParser() +- parser.set_url(url) +- try: +- parser.read() +- except IOError: +- self.skipTest('%s is unavailable' % url) +- self.assertEqual(parser.can_fetch("*", url+"/robots.txt"), False) ++ with test_support.transient_internet('mueblesmoraleda.com'): ++ url = 'http://mueblesmoraleda.com' ++ parser = robotparser.RobotFileParser() ++ parser.set_url(url) ++ try: ++ parser.read() ++ except IOError: ++ self.skipTest('%s is unavailable' % url) ++ self.assertEqual(parser.can_fetch("*", url+"/robots.txt"), False) + + def testPythonOrg(self): + test_support.requires('network') +- parser = robotparser.RobotFileParser( +- "http://www.python.org/robots.txt") +- parser.read() +- self.assertTrue(parser.can_fetch("*", +- "http://www.python.org/robots.txt")) ++ with test_support.transient_internet('www.python.org'): ++ parser = robotparser.RobotFileParser( ++ "http://www.python.org/robots.txt") ++ parser.read() ++ self.assertTrue( ++ parser.can_fetch("*", "http://www.python.org/robots.txt")) + + + def test_main(): +--- a/Lib/test/test_file2k.py ++++ b/Lib/test/test_file2k.py +@@ -172,7 +172,7 @@ + class OtherFileTests(unittest.TestCase): + + def testOpenDir(self): +- this_dir = os.path.dirname(__file__) ++ this_dir = os.path.dirname(__file__) or os.curdir + for mode in (None, "w"): + try: + if mode: +@@ -619,7 +619,45 @@ + finally: + sys.stdout = save_stdout + ++ def test_unicode(self): ++ import subprocess + ++ def get_message(encoding, *code): ++ code = '\n'.join(code) ++ env = os.environ.copy() ++ env['PYTHONIOENCODING'] = encoding ++ process = subprocess.Popen([sys.executable, "-c", code], ++ stdout=subprocess.PIPE, env=env) ++ stdout, stderr = process.communicate() ++ self.assertEqual(process.returncode, 0) ++ return stdout ++ ++ def check_message(text, encoding, expected): ++ stdout = get_message(encoding, ++ "import sys", ++ "sys.stdout.write(%r)" % text, ++ "sys.stdout.flush()") ++ self.assertEqual(stdout, expected) ++ ++ # test the encoding ++ check_message(u'15\u20ac', "iso-8859-15", "15\xa4") ++ check_message(u'15\u20ac', "utf-8", '15\xe2\x82\xac') ++ check_message(u'15\u20ac', "utf-16-le", '1\x005\x00\xac\x20') ++ ++ # test the error handler ++ check_message(u'15\u20ac', "iso-8859-1:ignore", "15") ++ check_message(u'15\u20ac', "iso-8859-1:replace", "15?") ++ check_message(u'15\u20ac', "iso-8859-1:backslashreplace", "15\\u20ac") ++ ++ # test the buffer API ++ for objtype in ('buffer', 'bytearray'): ++ stdout = get_message('ascii', ++ 'import sys', ++ r'sys.stdout.write(%s("\xe9"))' % objtype, ++ 'sys.stdout.flush()') ++ self.assertEqual(stdout, "\xe9") ++ ++ + def test_main(): + # Historically, these tests have been sloppy about removing TESTFN. + # So get rid of it no matter what. +--- a/Lib/test/test_sundry.py ++++ b/Lib/test/test_sundry.py +@@ -65,7 +65,6 @@ + import pstats + import py_compile + import rexec +- import rlcompleter + import sched + import sndhdr + import statvfs +--- a/Lib/test/crashers/gc_has_finalizer.py ++++ b/Lib/test/crashers/gc_has_finalizer.py +@@ -0,0 +1,36 @@ ++""" ++The gc module can still invoke arbitrary Python code and crash. ++This is an attack against _PyInstance_Lookup(), which is documented ++as follows: ++ ++ The point of this routine is that it never calls arbitrary Python ++ code, so is always "safe": all it does is dict lookups. ++ ++But of course dict lookups can call arbitrary Python code. ++The following code causes mutation of the object graph during ++the call to has_finalizer() in gcmodule.c, and that might ++segfault. ++""" ++ ++import gc ++ ++ ++class A: ++ def __hash__(self): ++ return hash("__del__") ++ def __eq__(self, other): ++ del self.other ++ return False ++ ++a = A() ++b = A() ++ ++a.__dict__[b] = 'A' ++ ++a.other = b ++b.other = a ++ ++gc.collect() ++del a, b ++ ++gc.collect() + +Property changes on: Lib/test/crashers/gc_has_finalizer.py +___________________________________________________________________ +Added: svn:eol-style + + native + +--- a/Lib/test/test_tokenize.py ++++ b/Lib/test/test_tokenize.py +@@ -493,13 +493,13 @@ + True + + Test roundtrip on random python modules. +-pass the '-ucompiler' option to process the full directory. ++pass the '-ucpu' option to process the full directory. + + >>> + >>> tempdir = os.path.dirname(f) or os.curdir + >>> testfiles = glob.glob(os.path.join(tempdir, "test*.py")) + +- >>> if not test_support.is_resource_enabled("compiler"): ++ >>> if not test_support.is_resource_enabled("cpu"): + ... testfiles = random.sample(testfiles, 10) + ... + >>> for testfile in testfiles: +--- a/Lib/test/test_cmd.py ++++ b/Lib/test/test_cmd.py +@@ -8,6 +8,9 @@ + import cmd + import sys + from test import test_support ++import re ++import unittest ++import StringIO + + class samplecmdclass(cmd.Cmd): + """ +@@ -168,9 +171,33 @@ + def do_exit(self, arg): + return True + ++ ++class TestAlternateInput(unittest.TestCase): ++ ++ class simplecmd(cmd.Cmd): ++ ++ def do_print(self, args): ++ print >>self.stdout, args ++ ++ def do_EOF(self, args): ++ return True ++ ++ def test_file_with_missing_final_nl(self): ++ input = StringIO.StringIO("print test\nprint test2") ++ output = StringIO.StringIO() ++ cmd = self.simplecmd(stdin=input, stdout=output) ++ cmd.use_rawinput = False ++ cmd.cmdloop() ++ self.assertMultiLineEqual(output.getvalue(), ++ ("(Cmd) test\n" ++ "(Cmd) test2\n" ++ "(Cmd) ")) ++ ++ + def test_main(verbose=None): + from test import test_cmd + test_support.run_doctest(test_cmd, verbose) ++ test_support.run_unittest(TestAlternateInput) + + def test_coverage(coverdir): + trace = test_support.import_module('trace') +--- a/Lib/test/test_io.py ++++ b/Lib/test/test_io.py +@@ -30,6 +30,8 @@ + import unittest + import weakref + import abc ++import signal ++import errno + from itertools import cycle, count + from collections import deque + from test import test_support as support +@@ -51,20 +53,16 @@ + return f._CHUNK_SIZE + + +-class MockRawIO: ++class MockRawIOWithoutRead: ++ """A RawIO implementation without read(), so as to exercise the default ++ RawIO.read() which calls readinto().""" + + def __init__(self, read_stack=()): + self._read_stack = list(read_stack) + self._write_stack = [] + self._reads = 0 ++ self._extraneous_reads = 0 + +- def read(self, n=None): +- self._reads += 1 +- try: +- return self._read_stack.pop(0) +- except: +- return b"" +- + def write(self, b): + self._write_stack.append(bytes(b)) + return len(b) +@@ -93,6 +91,7 @@ + try: + data = self._read_stack[0] + except IndexError: ++ self._extraneous_reads += 1 + return 0 + if data is None: + del self._read_stack[0] +@@ -110,6 +109,23 @@ + def truncate(self, pos=None): + return pos + ++class CMockRawIOWithoutRead(MockRawIOWithoutRead, io.RawIOBase): ++ pass ++ ++class PyMockRawIOWithoutRead(MockRawIOWithoutRead, pyio.RawIOBase): ++ pass ++ ++ ++class MockRawIO(MockRawIOWithoutRead): ++ ++ def read(self, n=None): ++ self._reads += 1 ++ try: ++ return self._read_stack.pop(0) ++ except: ++ self._extraneous_reads += 1 ++ return b"" ++ + class CMockRawIO(MockRawIO, io.RawIOBase): + pass + +@@ -555,6 +571,19 @@ + f.close() + self.assertRaises(ValueError, f.flush) + ++ def test_RawIOBase_read(self): ++ # Exercise the default RawIOBase.read() implementation (which calls ++ # readinto() internally). ++ rawio = self.MockRawIOWithoutRead((b"abc", b"d", None, b"efg", None)) ++ self.assertEqual(rawio.read(2), b"ab") ++ self.assertEqual(rawio.read(2), b"c") ++ self.assertEqual(rawio.read(2), b"d") ++ self.assertEqual(rawio.read(2), None) ++ self.assertEqual(rawio.read(2), b"ef") ++ self.assertEqual(rawio.read(2), b"g") ++ self.assertEqual(rawio.read(2), None) ++ self.assertEqual(rawio.read(2), b"") ++ + class CIOTest(IOTest): + pass + +@@ -783,6 +812,7 @@ + self.assertEquals(b"abcdefg", bufio.read()) + + @unittest.skipUnless(threading, 'Threading required for this test.') ++ @support.requires_resource('cpu') + def test_threads(self): + try: + # Write out many bytes with exactly the same number of 0's, +@@ -831,6 +861,27 @@ + self.assertRaises(IOError, bufio.seek, 0) + self.assertRaises(IOError, bufio.tell) + ++ def test_no_extraneous_read(self): ++ # Issue #9550; when the raw IO object has satisfied the read request, ++ # we should not issue any additional reads, otherwise it may block ++ # (e.g. socket). ++ bufsize = 16 ++ for n in (2, bufsize - 1, bufsize, bufsize + 1, bufsize * 2): ++ rawio = self.MockRawIO([b"x" * n]) ++ bufio = self.tp(rawio, bufsize) ++ self.assertEqual(bufio.read(n), b"x" * n) ++ # Simple case: one raw read is enough to satisfy the request. ++ self.assertEqual(rawio._extraneous_reads, 0, ++ "failed for {}: {} != 0".format(n, rawio._extraneous_reads)) ++ # A more complex case where two raw reads are needed to satisfy ++ # the request. ++ rawio = self.MockRawIO([b"x" * (n - 1), b"x"]) ++ bufio = self.tp(rawio, bufsize) ++ self.assertEqual(bufio.read(n), b"x" * n) ++ self.assertEqual(rawio._extraneous_reads, 0, ++ "failed for {}: {} != 0".format(n, rawio._extraneous_reads)) ++ ++ + class CBufferedReaderTest(BufferedReaderTest): + tp = io.BufferedReader + +@@ -1031,6 +1082,7 @@ + self.assertEqual(f.read(), b"abc") + + @unittest.skipUnless(threading, 'Threading required for this test.') ++ @support.requires_resource('cpu') + def test_threads(self): + try: + # Write out many bytes from many threads and test they were +@@ -2087,7 +2139,6 @@ + + self.assertEqual(buffer.seekable(), txt.seekable()) + +- @unittest.skip("Issue #6213 with incremental encoders") + def test_append_bom(self): + # The BOM is not written again when appending to a non-empty file + filename = support.TESTFN +@@ -2103,7 +2154,6 @@ + with self.open(filename, 'rb') as f: + self.assertEquals(f.read(), 'aaaxxx'.encode(charset)) + +- @unittest.skip("Issue #6213 with incremental encoders") + def test_seek_bom(self): + # Same test, but when seeking manually + filename = support.TESTFN +@@ -2449,6 +2499,75 @@ + class PyMiscIOTest(MiscIOTest): + io = pyio + ++ ++@unittest.skipIf(os.name == 'nt', 'POSIX signals required for this test.') ++class SignalsTest(unittest.TestCase): ++ ++ def setUp(self): ++ self.oldalrm = signal.signal(signal.SIGALRM, self.alarm_interrupt) ++ ++ def tearDown(self): ++ signal.signal(signal.SIGALRM, self.oldalrm) ++ ++ def alarm_interrupt(self, sig, frame): ++ 1 // 0 ++ ++ @unittest.skipUnless(threading, 'Threading required for this test.') ++ def check_interrupted_write(self, item, bytes, **fdopen_kwargs): ++ """Check that a partial write, when it gets interrupted, properly ++ invokes the signal handler.""" ++ read_results = [] ++ def _read(): ++ s = os.read(r, 1) ++ read_results.append(s) ++ t = threading.Thread(target=_read) ++ t.daemon = True ++ r, w = os.pipe() ++ try: ++ wio = self.io.open(w, **fdopen_kwargs) ++ t.start() ++ signal.alarm(1) ++ # Fill the pipe enough that the write will be blocking. ++ # It will be interrupted by the timer armed above. Since the ++ # other thread has read one byte, the low-level write will ++ # return with a successful (partial) result rather than an EINTR. ++ # The buffered IO layer must check for pending signal ++ # handlers, which in this case will invoke alarm_interrupt(). ++ self.assertRaises(ZeroDivisionError, ++ wio.write, item * (1024 * 1024)) ++ t.join() ++ # We got one byte, get another one and check that it isn't a ++ # repeat of the first one. ++ read_results.append(os.read(r, 1)) ++ self.assertEqual(read_results, [bytes[0:1], bytes[1:2]]) ++ finally: ++ os.close(w) ++ os.close(r) ++ # This is deliberate. If we didn't close the file descriptor ++ # before closing wio, wio would try to flush its internal ++ # buffer, and block again. ++ try: ++ wio.close() ++ except IOError as e: ++ if e.errno != errno.EBADF: ++ raise ++ ++ def test_interrupted_write_unbuffered(self): ++ self.check_interrupted_write(b"xy", b"xy", mode="wb", buffering=0) ++ ++ def test_interrupted_write_buffered(self): ++ self.check_interrupted_write(b"xy", b"xy", mode="wb") ++ ++ def test_interrupted_write_text(self): ++ self.check_interrupted_write("xy", b"xy", mode="w", encoding="ascii") ++ ++class CSignalsTest(SignalsTest): ++ io = io ++ ++class PySignalsTest(SignalsTest): ++ io = pyio ++ ++ + def test_main(): + tests = (CIOTest, PyIOTest, + CBufferedReaderTest, PyBufferedReaderTest, +@@ -2459,12 +2578,13 @@ + CIncrementalNewlineDecoderTest, PyIncrementalNewlineDecoderTest, + CTextIOWrapperTest, PyTextIOWrapperTest, + CMiscIOTest, PyMiscIOTest, ++ CSignalsTest, PySignalsTest, + ) + + # Put the namespaces of the IO module we are testing and some useful mock + # classes in the __dict__ of each test. + mocks = (MockRawIO, MisbehavedRawIO, MockFileIO, CloseFailureIO, +- MockNonBlockWriterIO) ++ MockNonBlockWriterIO, MockRawIOWithoutRead) + all_members = io.__all__ + ["IncrementalNewlineDecoder"] + c_io_ns = dict((name, getattr(io, name)) for name in all_members) + py_io_ns = dict((name, getattr(pyio, name)) for name in all_members) +--- a/Lib/test/win_console_handler.py ++++ b/Lib/test/win_console_handler.py +@@ -8,12 +8,14 @@ + similar example in C. + """ + +-from ctypes import wintypes ++from ctypes import wintypes, WINFUNCTYPE + import signal + import ctypes ++import mmap ++import sys + + # Function prototype for the handler function. Returns BOOL, takes a DWORD. +-HandlerRoutine = wintypes.WINFUNCTYPE(wintypes.BOOL, wintypes.DWORD) ++HandlerRoutine = WINFUNCTYPE(wintypes.BOOL, wintypes.DWORD) + + def _ctrl_handler(sig): + """Handle a sig event and return 0 to terminate the process""" +@@ -38,6 +40,10 @@ + print("Unable to add SetConsoleCtrlHandler") + exit(-1) + ++ # Awaken mail process ++ m = mmap.mmap(-1, 1, sys.argv[1]) ++ m[0] = '1' ++ + # Do nothing but wait for the signal + while True: + pass +--- a/Lib/test/test_asyncore.py ++++ b/Lib/test/test_asyncore.py +@@ -117,65 +117,65 @@ + # http://mail.python.org/pipermail/python-list/2001-October/109973.html) + # These constants should be present as long as poll is available + +- if hasattr(select, 'poll'): +- def test_readwrite(self): +- # Check that correct methods are called by readwrite() ++ @unittest.skipUnless(hasattr(select, 'poll'), 'select.poll required') ++ def test_readwrite(self): ++ # Check that correct methods are called by readwrite() + +- attributes = ('read', 'expt', 'write', 'closed', 'error_handled') ++ attributes = ('read', 'expt', 'write', 'closed', 'error_handled') + +- expected = ( +- (select.POLLIN, 'read'), +- (select.POLLPRI, 'expt'), +- (select.POLLOUT, 'write'), +- (select.POLLERR, 'closed'), +- (select.POLLHUP, 'closed'), +- (select.POLLNVAL, 'closed'), +- ) ++ expected = ( ++ (select.POLLIN, 'read'), ++ (select.POLLPRI, 'expt'), ++ (select.POLLOUT, 'write'), ++ (select.POLLERR, 'closed'), ++ (select.POLLHUP, 'closed'), ++ (select.POLLNVAL, 'closed'), ++ ) + +- class testobj: +- def __init__(self): +- self.read = False +- self.write = False +- self.closed = False +- self.expt = False +- self.error_handled = False ++ class testobj: ++ def __init__(self): ++ self.read = False ++ self.write = False ++ self.closed = False ++ self.expt = False ++ self.error_handled = False + +- def handle_read_event(self): +- self.read = True ++ def handle_read_event(self): ++ self.read = True + +- def handle_write_event(self): +- self.write = True ++ def handle_write_event(self): ++ self.write = True + +- def handle_close(self): +- self.closed = True ++ def handle_close(self): ++ self.closed = True + +- def handle_expt_event(self): +- self.expt = True ++ def handle_expt_event(self): ++ self.expt = True + +- def handle_error(self): +- self.error_handled = True ++ def handle_error(self): ++ self.error_handled = True + +- for flag, expectedattr in expected: +- tobj = testobj() +- self.assertEqual(getattr(tobj, expectedattr), False) +- asyncore.readwrite(tobj, flag) ++ for flag, expectedattr in expected: ++ tobj = testobj() ++ self.assertEqual(getattr(tobj, expectedattr), False) ++ asyncore.readwrite(tobj, flag) + +- # Only the attribute modified by the routine we expect to be +- # called should be True. +- for attr in attributes: +- self.assertEqual(getattr(tobj, attr), attr==expectedattr) ++ # Only the attribute modified by the routine we expect to be ++ # called should be True. ++ for attr in attributes: ++ self.assertEqual(getattr(tobj, attr), attr==expectedattr) + +- # check that ExitNow exceptions in the object handler method +- # bubbles all the way up through asyncore readwrite call +- tr1 = exitingdummy() +- self.assertRaises(asyncore.ExitNow, asyncore.readwrite, tr1, flag) ++ # check that ExitNow exceptions in the object handler method ++ # bubbles all the way up through asyncore readwrite call ++ tr1 = exitingdummy() ++ self.assertRaises(asyncore.ExitNow, asyncore.readwrite, tr1, flag) + +- # check that an exception other than ExitNow in the object handler +- # method causes the handle_error method to get called +- tr2 = crashingdummy() +- self.assertEqual(tr2.error_handled, False) +- asyncore.readwrite(tr2, flag) +- self.assertEqual(tr2.error_handled, True) ++ # check that an exception other than ExitNow in the object handler ++ # method causes the handle_error method to get called ++ tr2 = crashingdummy() ++ self.assertEqual(tr2.error_handled, False) ++ asyncore.readwrite(tr2, flag) ++ self.assertEqual(tr2.error_handled, True) + + def test_closeall(self): + self.closeall_check(False) +@@ -258,7 +258,7 @@ + sys.stderr = stderr + + lines = fp.getvalue().splitlines() +- self.assertEquals(lines, ['log: %s' % l1, 'log: %s' % l2]) ++ self.assertEqual(lines, ['log: %s' % l1, 'log: %s' % l2]) + + def test_log_info(self): + d = asyncore.dispatcher() +@@ -280,7 +280,7 @@ + lines = fp.getvalue().splitlines() + expected = ['EGGS: %s' % l1, 'info: %s' % l2, 'SPAM: %s' % l3] + +- self.assertEquals(lines, expected) ++ self.assertEqual(lines, expected) + + def test_unhandled(self): + d = asyncore.dispatcher() +@@ -305,7 +305,7 @@ + 'warning: unhandled write event', + 'warning: unhandled connect event', + 'warning: unhandled accept event'] +- self.assertEquals(lines, expected) ++ self.assertEqual(lines, expected) + + def test_issue_8594(self): + # XXX - this test is supposed to be removed in next major Python +@@ -321,7 +321,7 @@ + warnings.simplefilter("always") + family = d.family + self.assertEqual(family, socket.AF_INET) +- self.assertTrue(len(w) == 1) ++ self.assertEqual(len(w), 1) + self.assertTrue(issubclass(w[0].category, DeprecationWarning)) + + def test_strerror(self): +@@ -330,7 +330,7 @@ + if hasattr(os, 'strerror'): + self.assertEqual(err, os.strerror(errno.EPERM)) + err = asyncore._strerror(-1) +- self.assertTrue("unknown error" in err.lower()) ++ self.assertIn("unknown error", err.lower()) + + + class dispatcherwithsend_noread(asyncore.dispatcher_with_send): +@@ -393,40 +393,55 @@ + class DispatcherWithSendTests_UsePoll(DispatcherWithSendTests): + usepoll = True + +-if hasattr(asyncore, 'file_wrapper'): +- class FileWrapperTest(unittest.TestCase): +- def setUp(self): +- self.d = "It's not dead, it's sleeping!" +- file(TESTFN, 'w').write(self.d) ++@unittest.skipUnless(hasattr(asyncore, 'file_wrapper'), ++ 'asyncore.file_wrapper required') ++class FileWrapperTest(unittest.TestCase): ++ def setUp(self): ++ self.d = "It's not dead, it's sleeping!" ++ file(TESTFN, 'w').write(self.d) + +- def tearDown(self): +- unlink(TESTFN) ++ def tearDown(self): ++ unlink(TESTFN) + +- def test_recv(self): +- fd = os.open(TESTFN, os.O_RDONLY) +- w = asyncore.file_wrapper(fd) +- os.close(fd) ++ def test_recv(self): ++ fd = os.open(TESTFN, os.O_RDONLY) ++ w = asyncore.file_wrapper(fd) ++ os.close(fd) + +- self.assertNotEqual(w.fd, fd) +- self.assertNotEqual(w.fileno(), fd) +- self.assertEqual(w.recv(13), "It's not dead") +- self.assertEqual(w.read(6), ", it's") +- w.close() +- self.assertRaises(OSError, w.read, 1) ++ self.assertNotEqual(w.fd, fd) ++ self.assertNotEqual(w.fileno(), fd) ++ self.assertEqual(w.recv(13), "It's not dead") ++ self.assertEqual(w.read(6), ", it's") ++ w.close() ++ self.assertRaises(OSError, w.read, 1) + +- def test_send(self): +- d1 = "Come again?" +- d2 = "I want to buy some cheese." +- fd = os.open(TESTFN, os.O_WRONLY | os.O_APPEND) +- w = asyncore.file_wrapper(fd) +- os.close(fd) + +- w.write(d1) +- w.send(d2) +- w.close() +- self.assertEqual(file(TESTFN).read(), self.d + d1 + d2) ++ def test_send(self): ++ d1 = "Come again?" ++ d2 = "I want to buy some cheese." ++ fd = os.open(TESTFN, os.O_WRONLY | os.O_APPEND) ++ w = asyncore.file_wrapper(fd) ++ os.close(fd) + ++ w.write(d1) ++ w.send(d2) ++ w.close() ++ self.assertEqual(file(TESTFN).read(), self.d + d1 + d2) + ++ @unittest.skipUnless(hasattr(asyncore, 'file_dispatcher'), ++ 'asyncore.file_dispatcher required') ++ def test_dispatcher(self): ++ fd = os.open(TESTFN, os.O_RDONLY) ++ data = [] ++ class FileDispatcher(asyncore.file_dispatcher): ++ def handle_read(self): ++ data.append(self.recv(29)) ++ s = FileDispatcher(fd) ++ os.close(fd) ++ asyncore.loop(timeout=0.01, use_poll=True, count=2) ++ self.assertEqual(b"".join(data), self.d) ++ ++ + class BaseTestHandler(asyncore.dispatcher): + + def __init__(self, sock=None): +@@ -691,18 +706,15 @@ + class TestAPI_UseSelect(BaseTestAPI): + use_poll = False + ++@unittest.skipUnless(hasattr(select, 'poll'), 'select.poll required') + class TestAPI_UsePoll(BaseTestAPI): + use_poll = True + + + def test_main(): + tests = [HelperFunctionTests, DispatcherTests, DispatcherWithSendTests, +- DispatcherWithSendTests_UsePoll, TestAPI_UseSelect] +- if hasattr(asyncore, 'file_wrapper'): +- tests.append(FileWrapperTest) +- if hasattr(select, 'poll'): +- tests.append(TestAPI_UsePoll) +- ++ DispatcherWithSendTests_UsePoll, TestAPI_UseSelect, ++ TestAPI_UsePoll, FileWrapperTest] + run_unittest(*tests) + + if __name__ == "__main__": +--- a/Lib/test/test_smtpnet.py ++++ b/Lib/test/test_smtpnet.py +@@ -12,7 +12,8 @@ + + def test_connect(self): + test_support.get_attribute(smtplib, 'SMTP_SSL') +- server = smtplib.SMTP_SSL(self.testServer, self.remotePort) ++ with test_support.transient_internet(self.testServer): ++ server = smtplib.SMTP_SSL(self.testServer, self.remotePort) + server.ehlo() + server.quit() + +--- a/Lib/test/test_set.py ++++ b/Lib/test/test_set.py +@@ -750,7 +750,7 @@ + result = self.set ^ self.set + self.assertEqual(result, empty_set) + +- def checkempty_symmetric_difference(self): ++ def test_empty_symmetric_difference(self): + result = self.set ^ empty_set + self.assertEqual(result, self.set) + +--- a/Lib/test/test_ssl.py ++++ b/Lib/test/test_ssl.py +@@ -14,6 +14,8 @@ + import urllib, urlparse + import traceback + import weakref ++import functools ++import platform + + from BaseHTTPServer import HTTPServer + from SimpleHTTPServer import SimpleHTTPRequestHandler +@@ -54,6 +56,32 @@ + else: + raise + ++# Issue #9415: Ubuntu hijacks their OpenSSL and forcefully disables SSLv2 ++def skip_if_broken_ubuntu_ssl(func): ++ # We need to access the lower-level wrapper in order to create an ++ # implicit SSL context without trying to connect or listen. ++ try: ++ import _ssl ++ except ImportError: ++ # The returned function won't get executed, just ignore the error ++ pass ++ @functools.wraps(func) ++ def f(*args, **kwargs): ++ try: ++ s = socket.socket(socket.AF_INET) ++ _ssl.sslwrap(s._sock, 0, None, None, ++ ssl.CERT_NONE, ssl.PROTOCOL_SSLv2, None, None) ++ except ssl.SSLError as e: ++ if (ssl.OPENSSL_VERSION_INFO == (0, 9, 8, 15, 15) and ++ platform.linux_distribution() == ('debian', 'squeeze/sid', '') ++ and 'Invalid SSL protocol variant specified' in str(e)): ++ raise unittest.SkipTest("Patched Ubuntu OpenSSL breaks behaviour") ++ return func(*args, **kwargs) ++ return f ++ ++ ++class BasicSocketTests(unittest.TestCase): ++ + def test_constants(self): + ssl.PROTOCOL_SSLv2 + ssl.PROTOCOL_SSLv23 +@@ -151,98 +179,115 @@ + del ss + self.assertEqual(wr(), None) + ++ def test_wrapped_unconnected(self): ++ # The _delegate_methods in socket.py are correctly delegated to by an ++ # unconnected SSLSocket, so they will raise a socket.error rather than ++ # something unexpected like TypeError. ++ s = socket.socket(socket.AF_INET) ++ ss = ssl.wrap_socket(s) ++ self.assertRaises(socket.error, ss.recv, 1) ++ self.assertRaises(socket.error, ss.recv_into, bytearray(b'x')) ++ self.assertRaises(socket.error, ss.recvfrom, 1) ++ self.assertRaises(socket.error, ss.recvfrom_into, bytearray(b'x'), 1) ++ self.assertRaises(socket.error, ss.send, b'x') ++ self.assertRaises(socket.error, ss.sendto, b'x', ('0.0.0.0', 0)) + ++ + class NetworkedTests(unittest.TestCase): + + def test_connect(self): +- s = ssl.wrap_socket(socket.socket(socket.AF_INET), +- cert_reqs=ssl.CERT_NONE) +- s.connect(("svn.python.org", 443)) +- c = s.getpeercert() +- if c: +- self.fail("Peer cert %s shouldn't be here!") +- s.close() +- +- # this should fail because we have no verification certs +- s = ssl.wrap_socket(socket.socket(socket.AF_INET), +- cert_reqs=ssl.CERT_REQUIRED) +- try: ++ with test_support.transient_internet("svn.python.org"): ++ s = ssl.wrap_socket(socket.socket(socket.AF_INET), ++ cert_reqs=ssl.CERT_NONE) + s.connect(("svn.python.org", 443)) +- except ssl.SSLError: +- pass +- finally: ++ c = s.getpeercert() ++ if c: ++ self.fail("Peer cert %s shouldn't be here!") + s.close() + +- # this should succeed because we specify the root cert +- s = ssl.wrap_socket(socket.socket(socket.AF_INET), +- cert_reqs=ssl.CERT_REQUIRED, +- ca_certs=SVN_PYTHON_ORG_ROOT_CERT) +- try: +- s.connect(("svn.python.org", 443)) +- finally: +- s.close() ++ # this should fail because we have no verification certs ++ s = ssl.wrap_socket(socket.socket(socket.AF_INET), ++ cert_reqs=ssl.CERT_REQUIRED) ++ try: ++ s.connect(("svn.python.org", 443)) ++ except ssl.SSLError: ++ pass ++ finally: ++ s.close() + ++ # this should succeed because we specify the root cert ++ s = ssl.wrap_socket(socket.socket(socket.AF_INET), ++ cert_reqs=ssl.CERT_REQUIRED, ++ ca_certs=SVN_PYTHON_ORG_ROOT_CERT) ++ try: ++ s.connect(("svn.python.org", 443)) ++ finally: ++ s.close() ++ + @unittest.skipIf(os.name == "nt", "Can't use a socket as a file under Windows") + def test_makefile_close(self): + # Issue #5238: creating a file-like object with makefile() shouldn't + # delay closing the underlying "real socket" (here tested with its + # file descriptor, hence skipping the test under Windows). +- ss = ssl.wrap_socket(socket.socket(socket.AF_INET)) +- ss.connect(("svn.python.org", 443)) +- fd = ss.fileno() +- f = ss.makefile() +- f.close() +- # The fd is still open +- os.read(fd, 0) +- # Closing the SSL socket should close the fd too +- ss.close() +- gc.collect() +- with self.assertRaises(OSError) as e: ++ with test_support.transient_internet("svn.python.org"): ++ ss = ssl.wrap_socket(socket.socket(socket.AF_INET)) ++ ss.connect(("svn.python.org", 443)) ++ fd = ss.fileno() ++ f = ss.makefile() ++ f.close() ++ # The fd is still open + os.read(fd, 0) +- self.assertEqual(e.exception.errno, errno.EBADF) ++ # Closing the SSL socket should close the fd too ++ ss.close() ++ gc.collect() ++ with self.assertRaises(OSError) as e: ++ os.read(fd, 0) ++ self.assertEqual(e.exception.errno, errno.EBADF) + + def test_non_blocking_handshake(self): +- s = socket.socket(socket.AF_INET) +- s.connect(("svn.python.org", 443)) +- s.setblocking(False) +- s = ssl.wrap_socket(s, +- cert_reqs=ssl.CERT_NONE, +- do_handshake_on_connect=False) +- count = 0 +- while True: +- try: +- count += 1 +- s.do_handshake() +- break +- except ssl.SSLError, err: +- if err.args[0] == ssl.SSL_ERROR_WANT_READ: +- select.select([s], [], []) +- elif err.args[0] == ssl.SSL_ERROR_WANT_WRITE: +- select.select([], [s], []) +- else: +- raise +- s.close() +- if test_support.verbose: +- sys.stdout.write("\nNeeded %d calls to do_handshake() to establish session.\n" % count) ++ with test_support.transient_internet("svn.python.org"): ++ s = socket.socket(socket.AF_INET) ++ s.connect(("svn.python.org", 443)) ++ s.setblocking(False) ++ s = ssl.wrap_socket(s, ++ cert_reqs=ssl.CERT_NONE, ++ do_handshake_on_connect=False) ++ count = 0 ++ while True: ++ try: ++ count += 1 ++ s.do_handshake() ++ break ++ except ssl.SSLError, err: ++ if err.args[0] == ssl.SSL_ERROR_WANT_READ: ++ select.select([s], [], []) ++ elif err.args[0] == ssl.SSL_ERROR_WANT_WRITE: ++ select.select([], [s], []) ++ else: ++ raise ++ s.close() ++ if test_support.verbose: ++ sys.stdout.write("\nNeeded %d calls to do_handshake() to establish session.\n" % count) + + def test_get_server_certificate(self): +- pem = ssl.get_server_certificate(("svn.python.org", 443)) +- if not pem: +- self.fail("No server certificate on svn.python.org:443!") ++ with test_support.transient_internet("svn.python.org"): ++ pem = ssl.get_server_certificate(("svn.python.org", 443)) ++ if not pem: ++ self.fail("No server certificate on svn.python.org:443!") + +- try: +- pem = ssl.get_server_certificate(("svn.python.org", 443), ca_certs=CERTFILE) +- except ssl.SSLError: +- #should fail +- pass +- else: +- self.fail("Got server certificate %s for svn.python.org!" % pem) ++ try: ++ pem = ssl.get_server_certificate(("svn.python.org", 443), ca_certs=CERTFILE) ++ except ssl.SSLError: ++ #should fail ++ pass ++ else: ++ self.fail("Got server certificate %s for svn.python.org!" % pem) + +- pem = ssl.get_server_certificate(("svn.python.org", 443), ca_certs=SVN_PYTHON_ORG_ROOT_CERT) +- if not pem: +- self.fail("No server certificate on svn.python.org:443!") +- if test_support.verbose: +- sys.stdout.write("\nVerified certificate for svn.python.org:443 is\n%s\n" % pem) ++ pem = ssl.get_server_certificate(("svn.python.org", 443), ca_certs=SVN_PYTHON_ORG_ROOT_CERT) ++ if not pem: ++ self.fail("No server certificate on svn.python.org:443!") ++ if test_support.verbose: ++ sys.stdout.write("\nVerified certificate for svn.python.org:443 is\n%s\n" % pem) + + def test_algorithms(self): + # Issue #8484: all algorithms should be available when verifying a +@@ -253,10 +298,10 @@ + # NOTE: https://sha256.tbs-internet.com is another possible test host + remote = ("sha2.hboeck.de", 443) + sha256_cert = os.path.join(os.path.dirname(__file__), "sha256.pem") +- s = ssl.wrap_socket(socket.socket(socket.AF_INET), +- cert_reqs=ssl.CERT_REQUIRED, +- ca_certs=sha256_cert,) +- with test_support.transient_internet(): ++ with test_support.transient_internet("sha2.hboeck.de"): ++ s = ssl.wrap_socket(socket.socket(socket.AF_INET), ++ cert_reqs=ssl.CERT_REQUIRED, ++ ca_certs=sha256_cert,) + try: + s.connect(remote) + if test_support.verbose: +@@ -807,6 +852,7 @@ + finally: + t.join() + ++ @skip_if_broken_ubuntu_ssl + def test_echo(self): + """Basic test of an SSL client connecting to a server""" + if test_support.verbose: +@@ -872,6 +918,7 @@ + bad_cert_test(os.path.join(os.path.dirname(__file__) or os.curdir, + "badkey.pem")) + ++ @skip_if_broken_ubuntu_ssl + def test_protocol_sslv2(self): + """Connecting to an SSLv2 server with various client options""" + if test_support.verbose: +@@ -883,6 +930,7 @@ + try_protocol_combo(ssl.PROTOCOL_SSLv2, ssl.PROTOCOL_SSLv3, False) + try_protocol_combo(ssl.PROTOCOL_SSLv2, ssl.PROTOCOL_TLSv1, False) + ++ @skip_if_broken_ubuntu_ssl + def test_protocol_sslv23(self): + """Connecting to an SSLv23 server with various client options""" + if test_support.verbose: +@@ -907,6 +955,7 @@ + try_protocol_combo(ssl.PROTOCOL_SSLv23, ssl.PROTOCOL_SSLv23, True, ssl.CERT_REQUIRED) + try_protocol_combo(ssl.PROTOCOL_SSLv23, ssl.PROTOCOL_TLSv1, True, ssl.CERT_REQUIRED) + ++ @skip_if_broken_ubuntu_ssl + def test_protocol_sslv3(self): + """Connecting to an SSLv3 server with various client options""" + if test_support.verbose: +@@ -918,6 +967,7 @@ + try_protocol_combo(ssl.PROTOCOL_SSLv3, ssl.PROTOCOL_SSLv23, False) + try_protocol_combo(ssl.PROTOCOL_SSLv3, ssl.PROTOCOL_TLSv1, False) + ++ @skip_if_broken_ubuntu_ssl + def test_protocol_tlsv1(self): + """Connecting to a TLSv1 server with various client options""" + if test_support.verbose: +@@ -1248,7 +1298,7 @@ + not os.path.exists(SVN_PYTHON_ORG_ROOT_CERT)): + raise test_support.TestFailed("Can't read certificate files!") + +- tests = [BasicTests] ++ tests = [BasicTests, BasicSocketTests] + + if test_support.is_resource_enabled('network'): + tests.append(NetworkedTests) +--- a/Lib/test/test_winsound.py ++++ b/Lib/test/test_winsound.py +@@ -5,9 +5,9 @@ + import time + import os + import subprocess +-import ctypes + + winsound = test_support.import_module('winsound') ++ctypes = test_support.import_module('ctypes') + import _winreg + + def has_sound(sound): +--- a/Lib/test/test_complex.py ++++ b/Lib/test/test_complex.py +@@ -558,6 +558,16 @@ + self.assertEqual(format(z, '-'), str(z)) + self.assertEqual(format(z, '<'), str(z)) + self.assertEqual(format(z, '10'), str(z)) ++ z = complex(0.0, 3.0) ++ self.assertEqual(format(z, ''), str(z)) ++ self.assertEqual(format(z, '-'), str(z)) ++ self.assertEqual(format(z, '<'), str(z)) ++ self.assertEqual(format(z, '2'), str(z)) ++ z = complex(-0.0, 2.0) ++ self.assertEqual(format(z, ''), str(z)) ++ self.assertEqual(format(z, '-'), str(z)) ++ self.assertEqual(format(z, '<'), str(z)) ++ self.assertEqual(format(z, '3'), str(z)) + + self.assertEqual(format(1+3j, 'g'), '1+3j') + self.assertEqual(format(3j, 'g'), '0+3j') +--- a/Lib/test/test_ntpath.py ++++ b/Lib/test/test_ntpath.py +@@ -123,6 +123,9 @@ + tester("ntpath.normpath('C:////a/b')", r'C:\a\b') + tester("ntpath.normpath('//machine/share//a/b')", r'\\machine\share\a\b') + ++ tester("ntpath.normpath('\\\\.\\NUL')", r'\\.\NUL') ++ tester("ntpath.normpath('\\\\?\\D:/XY\\Z')", r'\\?\D:/XY\Z') ++ + def test_expandvars(self): + with test_support.EnvironmentVarGuard() as env: + env.clear() +--- a/Lib/test/test_site.py ++++ b/Lib/test/test_site.py +@@ -169,14 +169,14 @@ + wanted = os.path.join('xoxo', 'Lib', 'site-packages') + self.assertEquals(dirs[0], wanted) + elif os.sep == '/': +- self.assertTrue(len(dirs), 2) ++ self.assertEqual(len(dirs), 2) + wanted = os.path.join('xoxo', 'lib', 'python' + sys.version[:3], + 'site-packages') + self.assertEquals(dirs[0], wanted) + wanted = os.path.join('xoxo', 'lib', 'site-python') + self.assertEquals(dirs[1], wanted) + else: +- self.assertTrue(len(dirs), 2) ++ self.assertEqual(len(dirs), 2) + self.assertEquals(dirs[0], 'xoxo') + wanted = os.path.join('xoxo', 'lib', 'site-packages') + self.assertEquals(dirs[1], wanted) +--- a/Lib/test/test_sys_settrace.py ++++ b/Lib/test/test_sys_settrace.py +@@ -0,0 +1,789 @@ ++# Testing the line trace facility. ++ ++from test import test_support ++import unittest ++import sys ++import difflib ++import gc ++ ++# A very basic example. If this fails, we're in deep trouble. ++def basic(): ++ return 1 ++ ++basic.events = [(0, 'call'), ++ (1, 'line'), ++ (1, 'return')] ++ ++# Many of the tests below are tricky because they involve pass statements. ++# If there is implicit control flow around a pass statement (in an except ++# clause or else caluse) under what conditions do you set a line number ++# following that clause? ++ ++ ++# The entire "while 0:" statement is optimized away. No code ++# exists for it, so the line numbers skip directly from "del x" ++# to "x = 1". ++def arigo_example(): ++ x = 1 ++ del x ++ while 0: ++ pass ++ x = 1 ++ ++arigo_example.events = [(0, 'call'), ++ (1, 'line'), ++ (2, 'line'), ++ (5, 'line'), ++ (5, 'return')] ++ ++# check that lines consisting of just one instruction get traced: ++def one_instr_line(): ++ x = 1 ++ del x ++ x = 1 ++ ++one_instr_line.events = [(0, 'call'), ++ (1, 'line'), ++ (2, 'line'), ++ (3, 'line'), ++ (3, 'return')] ++ ++def no_pop_tops(): # 0 ++ x = 1 # 1 ++ for a in range(2): # 2 ++ if a: # 3 ++ x = 1 # 4 ++ else: # 5 ++ x = 1 # 6 ++ ++no_pop_tops.events = [(0, 'call'), ++ (1, 'line'), ++ (2, 'line'), ++ (3, 'line'), ++ (6, 'line'), ++ (2, 'line'), ++ (3, 'line'), ++ (4, 'line'), ++ (2, 'line'), ++ (2, 'return')] ++ ++def no_pop_blocks(): ++ y = 1 ++ while not y: ++ bla ++ x = 1 ++ ++no_pop_blocks.events = [(0, 'call'), ++ (1, 'line'), ++ (2, 'line'), ++ (4, 'line'), ++ (4, 'return')] ++ ++def called(): # line -3 ++ x = 1 ++ ++def call(): # line 0 ++ called() ++ ++call.events = [(0, 'call'), ++ (1, 'line'), ++ (-3, 'call'), ++ (-2, 'line'), ++ (-2, 'return'), ++ (1, 'return')] ++ ++def raises(): ++ raise Exception ++ ++def test_raise(): ++ try: ++ raises() ++ except Exception, exc: ++ x = 1 ++ ++test_raise.events = [(0, 'call'), ++ (1, 'line'), ++ (2, 'line'), ++ (-3, 'call'), ++ (-2, 'line'), ++ (-2, 'exception'), ++ (-2, 'return'), ++ (2, 'exception'), ++ (3, 'line'), ++ (4, 'line'), ++ (4, 'return')] ++ ++def _settrace_and_return(tracefunc): ++ sys.settrace(tracefunc) ++ sys._getframe().f_back.f_trace = tracefunc ++def settrace_and_return(tracefunc): ++ _settrace_and_return(tracefunc) ++ ++settrace_and_return.events = [(1, 'return')] ++ ++def _settrace_and_raise(tracefunc): ++ sys.settrace(tracefunc) ++ sys._getframe().f_back.f_trace = tracefunc ++ raise RuntimeError ++def settrace_and_raise(tracefunc): ++ try: ++ _settrace_and_raise(tracefunc) ++ except RuntimeError, exc: ++ pass ++ ++settrace_and_raise.events = [(2, 'exception'), ++ (3, 'line'), ++ (4, 'line'), ++ (4, 'return')] ++ ++# implicit return example ++# This test is interesting because of the else: pass ++# part of the code. The code generate for the true ++# part of the if contains a jump past the else branch. ++# The compiler then generates an implicit "return None" ++# Internally, the compiler visits the pass statement ++# and stores its line number for use on the next instruction. ++# The next instruction is the implicit return None. ++def ireturn_example(): ++ a = 5 ++ b = 5 ++ if a == b: ++ b = a+1 ++ else: ++ pass ++ ++ireturn_example.events = [(0, 'call'), ++ (1, 'line'), ++ (2, 'line'), ++ (3, 'line'), ++ (4, 'line'), ++ (6, 'line'), ++ (6, 'return')] ++ ++# Tight loop with while(1) example (SF #765624) ++def tightloop_example(): ++ items = range(0, 3) ++ try: ++ i = 0 ++ while 1: ++ b = items[i]; i+=1 ++ except IndexError: ++ pass ++ ++tightloop_example.events = [(0, 'call'), ++ (1, 'line'), ++ (2, 'line'), ++ (3, 'line'), ++ (4, 'line'), ++ (5, 'line'), ++ (5, 'line'), ++ (5, 'line'), ++ (5, 'line'), ++ (5, 'exception'), ++ (6, 'line'), ++ (7, 'line'), ++ (7, 'return')] ++ ++def tighterloop_example(): ++ items = range(1, 4) ++ try: ++ i = 0 ++ while 1: i = items[i] ++ except IndexError: ++ pass ++ ++tighterloop_example.events = [(0, 'call'), ++ (1, 'line'), ++ (2, 'line'), ++ (3, 'line'), ++ (4, 'line'), ++ (4, 'line'), ++ (4, 'line'), ++ (4, 'line'), ++ (4, 'exception'), ++ (5, 'line'), ++ (6, 'line'), ++ (6, 'return')] ++ ++def generator_function(): ++ try: ++ yield True ++ "continued" ++ finally: ++ "finally" ++def generator_example(): ++ # any() will leave the generator before its end ++ x = any(generator_function()) ++ ++ # the following lines were not traced ++ for x in range(10): ++ y = x ++ ++generator_example.events = ([(0, 'call'), ++ (2, 'line'), ++ (-6, 'call'), ++ (-5, 'line'), ++ (-4, 'line'), ++ (-4, 'return'), ++ (-4, 'call'), ++ (-4, 'exception'), ++ (-1, 'line'), ++ (-1, 'return')] + ++ [(5, 'line'), (6, 'line')] * 10 + ++ [(5, 'line'), (5, 'return')]) ++ ++ ++class Tracer: ++ def __init__(self): ++ self.events = [] ++ def trace(self, frame, event, arg): ++ self.events.append((frame.f_lineno, event)) ++ return self.trace ++ def traceWithGenexp(self, frame, event, arg): ++ (o for o in [1]) ++ self.events.append((frame.f_lineno, event)) ++ return self.trace ++ ++class TraceTestCase(unittest.TestCase): ++ ++ # Disable gc collection when tracing, otherwise the ++ # deallocators may be traced as well. ++ def setUp(self): ++ self.using_gc = gc.isenabled() ++ gc.disable() ++ ++ def tearDown(self): ++ if self.using_gc: ++ gc.enable() ++ ++ def compare_events(self, line_offset, events, expected_events): ++ events = [(l - line_offset, e) for (l, e) in events] ++ if events != expected_events: ++ self.fail( ++ "events did not match expectation:\n" + ++ "\n".join(difflib.ndiff([str(x) for x in expected_events], ++ [str(x) for x in events]))) ++ ++ def run_and_compare(self, func, events): ++ tracer = Tracer() ++ sys.settrace(tracer.trace) ++ func() ++ sys.settrace(None) ++ self.compare_events(func.func_code.co_firstlineno, ++ tracer.events, events) ++ ++ def run_test(self, func): ++ self.run_and_compare(func, func.events) ++ ++ def run_test2(self, func): ++ tracer = Tracer() ++ func(tracer.trace) ++ sys.settrace(None) ++ self.compare_events(func.func_code.co_firstlineno, ++ tracer.events, func.events) ++ ++ def set_and_retrieve_none(self): ++ sys.settrace(None) ++ assert sys.gettrace() is None ++ ++ def set_and_retrieve_func(self): ++ def fn(*args): ++ pass ++ ++ sys.settrace(fn) ++ try: ++ assert sys.gettrace() is fn ++ finally: ++ sys.settrace(None) ++ ++ def test_01_basic(self): ++ self.run_test(basic) ++ def test_02_arigo(self): ++ self.run_test(arigo_example) ++ def test_03_one_instr(self): ++ self.run_test(one_instr_line) ++ def test_04_no_pop_blocks(self): ++ self.run_test(no_pop_blocks) ++ def test_05_no_pop_tops(self): ++ self.run_test(no_pop_tops) ++ def test_06_call(self): ++ self.run_test(call) ++ def test_07_raise(self): ++ self.run_test(test_raise) ++ ++ def test_08_settrace_and_return(self): ++ self.run_test2(settrace_and_return) ++ def test_09_settrace_and_raise(self): ++ self.run_test2(settrace_and_raise) ++ def test_10_ireturn(self): ++ self.run_test(ireturn_example) ++ def test_11_tightloop(self): ++ self.run_test(tightloop_example) ++ def test_12_tighterloop(self): ++ self.run_test(tighterloop_example) ++ ++ def test_13_genexp(self): ++ self.run_test(generator_example) ++ # issue1265: if the trace function contains a generator, ++ # and if the traced function contains another generator ++ # that is not completely exhausted, the trace stopped. ++ # Worse: the 'finally' clause was not invoked. ++ tracer = Tracer() ++ sys.settrace(tracer.traceWithGenexp) ++ generator_example() ++ sys.settrace(None) ++ self.compare_events(generator_example.__code__.co_firstlineno, ++ tracer.events, generator_example.events) ++ ++ def test_14_onliner_if(self): ++ def onliners(): ++ if True: False ++ else: True ++ return 0 ++ self.run_and_compare( ++ onliners, ++ [(0, 'call'), ++ (1, 'line'), ++ (3, 'line'), ++ (3, 'return')]) ++ ++ def test_15_loops(self): ++ # issue1750076: "while" expression is skipped by debugger ++ def for_example(): ++ for x in range(2): ++ pass ++ self.run_and_compare( ++ for_example, ++ [(0, 'call'), ++ (1, 'line'), ++ (2, 'line'), ++ (1, 'line'), ++ (2, 'line'), ++ (1, 'line'), ++ (1, 'return')]) ++ ++ def while_example(): ++ # While expression should be traced on every loop ++ x = 2 ++ while x > 0: ++ x -= 1 ++ self.run_and_compare( ++ while_example, ++ [(0, 'call'), ++ (2, 'line'), ++ (3, 'line'), ++ (4, 'line'), ++ (3, 'line'), ++ (4, 'line'), ++ (3, 'line'), ++ (3, 'return')]) ++ ++ def test_16_blank_lines(self): ++ exec("def f():\n" + "\n" * 256 + " pass") ++ self.run_and_compare( ++ f, ++ [(0, 'call'), ++ (257, 'line'), ++ (257, 'return')]) ++ ++ ++class RaisingTraceFuncTestCase(unittest.TestCase): ++ def trace(self, frame, event, arg): ++ """A trace function that raises an exception in response to a ++ specific trace event.""" ++ if event == self.raiseOnEvent: ++ raise ValueError # just something that isn't RuntimeError ++ else: ++ return self.trace ++ ++ def f(self): ++ """The function to trace; raises an exception if that's the case ++ we're testing, so that the 'exception' trace event fires.""" ++ if self.raiseOnEvent == 'exception': ++ x = 0 ++ y = 1 // x ++ else: ++ return 1 ++ ++ def run_test_for_event(self, event): ++ """Tests that an exception raised in response to the given event is ++ handled OK.""" ++ self.raiseOnEvent = event ++ try: ++ for i in xrange(sys.getrecursionlimit() + 1): ++ sys.settrace(self.trace) ++ try: ++ self.f() ++ except ValueError: ++ pass ++ else: ++ self.fail("exception not thrown!") ++ except RuntimeError: ++ self.fail("recursion counter not reset") ++ ++ # Test the handling of exceptions raised by each kind of trace event. ++ def test_call(self): ++ self.run_test_for_event('call') ++ def test_line(self): ++ self.run_test_for_event('line') ++ def test_return(self): ++ self.run_test_for_event('return') ++ def test_exception(self): ++ self.run_test_for_event('exception') ++ ++ def test_trash_stack(self): ++ def f(): ++ for i in range(5): ++ print i # line tracing will raise an exception at this line ++ ++ def g(frame, why, extra): ++ if (why == 'line' and ++ frame.f_lineno == f.func_code.co_firstlineno + 2): ++ raise RuntimeError, "i am crashing" ++ return g ++ ++ sys.settrace(g) ++ try: ++ f() ++ except RuntimeError: ++ # the test is really that this doesn't segfault: ++ import gc ++ gc.collect() ++ else: ++ self.fail("exception not propagated") ++ ++ ++# 'Jump' tests: assigning to frame.f_lineno within a trace function ++# moves the execution position - it's how debuggers implement a Jump ++# command (aka. "Set next statement"). ++ ++class JumpTracer: ++ """Defines a trace function that jumps from one place to another, ++ with the source and destination lines of the jump being defined by ++ the 'jump' property of the function under test.""" ++ ++ def __init__(self, function): ++ self.function = function ++ self.jumpFrom = function.jump[0] ++ self.jumpTo = function.jump[1] ++ self.done = False ++ ++ def trace(self, frame, event, arg): ++ if not self.done and frame.f_code == self.function.func_code: ++ firstLine = frame.f_code.co_firstlineno ++ if event == 'line' and frame.f_lineno == firstLine + self.jumpFrom: ++ # Cope with non-integer self.jumpTo (because of ++ # no_jump_to_non_integers below). ++ try: ++ frame.f_lineno = firstLine + self.jumpTo ++ except TypeError: ++ frame.f_lineno = self.jumpTo ++ self.done = True ++ return self.trace ++ ++# The first set of 'jump' tests are for things that are allowed: ++ ++def jump_simple_forwards(output): ++ output.append(1) ++ output.append(2) ++ output.append(3) ++ ++jump_simple_forwards.jump = (1, 3) ++jump_simple_forwards.output = [3] ++ ++def jump_simple_backwards(output): ++ output.append(1) ++ output.append(2) ++ ++jump_simple_backwards.jump = (2, 1) ++jump_simple_backwards.output = [1, 1, 2] ++ ++def jump_out_of_block_forwards(output): ++ for i in 1, 2: ++ output.append(2) ++ for j in [3]: # Also tests jumping over a block ++ output.append(4) ++ output.append(5) ++ ++jump_out_of_block_forwards.jump = (3, 5) ++jump_out_of_block_forwards.output = [2, 5] ++ ++def jump_out_of_block_backwards(output): ++ output.append(1) ++ for i in [1]: ++ output.append(3) ++ for j in [2]: # Also tests jumping over a block ++ output.append(5) ++ output.append(6) ++ output.append(7) ++ ++jump_out_of_block_backwards.jump = (6, 1) ++jump_out_of_block_backwards.output = [1, 3, 5, 1, 3, 5, 6, 7] ++ ++def jump_to_codeless_line(output): ++ output.append(1) ++ # Jumping to this line should skip to the next one. ++ output.append(3) ++ ++jump_to_codeless_line.jump = (1, 2) ++jump_to_codeless_line.output = [3] ++ ++def jump_to_same_line(output): ++ output.append(1) ++ output.append(2) ++ output.append(3) ++ ++jump_to_same_line.jump = (2, 2) ++jump_to_same_line.output = [1, 2, 3] ++ ++# Tests jumping within a finally block, and over one. ++def jump_in_nested_finally(output): ++ try: ++ output.append(2) ++ finally: ++ output.append(4) ++ try: ++ output.append(6) ++ finally: ++ output.append(8) ++ output.append(9) ++ ++jump_in_nested_finally.jump = (4, 9) ++jump_in_nested_finally.output = [2, 9] ++ ++# The second set of 'jump' tests are for things that are not allowed: ++ ++def no_jump_too_far_forwards(output): ++ try: ++ output.append(2) ++ output.append(3) ++ except ValueError, e: ++ output.append('after' in str(e)) ++ ++no_jump_too_far_forwards.jump = (3, 6) ++no_jump_too_far_forwards.output = [2, True] ++ ++def no_jump_too_far_backwards(output): ++ try: ++ output.append(2) ++ output.append(3) ++ except ValueError, e: ++ output.append('before' in str(e)) ++ ++no_jump_too_far_backwards.jump = (3, -1) ++no_jump_too_far_backwards.output = [2, True] ++ ++# Test each kind of 'except' line. ++def no_jump_to_except_1(output): ++ try: ++ output.append(2) ++ except: ++ e = sys.exc_info()[1] ++ output.append('except' in str(e)) ++ ++no_jump_to_except_1.jump = (2, 3) ++no_jump_to_except_1.output = [True] ++ ++def no_jump_to_except_2(output): ++ try: ++ output.append(2) ++ except ValueError: ++ e = sys.exc_info()[1] ++ output.append('except' in str(e)) ++ ++no_jump_to_except_2.jump = (2, 3) ++no_jump_to_except_2.output = [True] ++ ++def no_jump_to_except_3(output): ++ try: ++ output.append(2) ++ except ValueError, e: ++ output.append('except' in str(e)) ++ ++no_jump_to_except_3.jump = (2, 3) ++no_jump_to_except_3.output = [True] ++ ++def no_jump_to_except_4(output): ++ try: ++ output.append(2) ++ except (ValueError, RuntimeError), e: ++ output.append('except' in str(e)) ++ ++no_jump_to_except_4.jump = (2, 3) ++no_jump_to_except_4.output = [True] ++ ++def no_jump_forwards_into_block(output): ++ try: ++ output.append(2) ++ for i in 1, 2: ++ output.append(4) ++ except ValueError, e: ++ output.append('into' in str(e)) ++ ++no_jump_forwards_into_block.jump = (2, 4) ++no_jump_forwards_into_block.output = [True] ++ ++def no_jump_backwards_into_block(output): ++ try: ++ for i in 1, 2: ++ output.append(3) ++ output.append(4) ++ except ValueError, e: ++ output.append('into' in str(e)) ++ ++no_jump_backwards_into_block.jump = (4, 3) ++no_jump_backwards_into_block.output = [3, 3, True] ++ ++def no_jump_into_finally_block(output): ++ try: ++ try: ++ output.append(3) ++ x = 1 ++ finally: ++ output.append(6) ++ except ValueError, e: ++ output.append('finally' in str(e)) ++ ++no_jump_into_finally_block.jump = (4, 6) ++no_jump_into_finally_block.output = [3, 6, True] # The 'finally' still runs ++ ++def no_jump_out_of_finally_block(output): ++ try: ++ try: ++ output.append(3) ++ finally: ++ output.append(5) ++ output.append(6) ++ except ValueError, e: ++ output.append('finally' in str(e)) ++ ++no_jump_out_of_finally_block.jump = (5, 1) ++no_jump_out_of_finally_block.output = [3, True] ++ ++# This verifies the line-numbers-must-be-integers rule. ++def no_jump_to_non_integers(output): ++ try: ++ output.append(2) ++ except ValueError, e: ++ output.append('integer' in str(e)) ++ ++no_jump_to_non_integers.jump = (2, "Spam") ++no_jump_to_non_integers.output = [True] ++ ++# This verifies that you can't set f_lineno via _getframe or similar ++# trickery. ++def no_jump_without_trace_function(): ++ try: ++ previous_frame = sys._getframe().f_back ++ previous_frame.f_lineno = previous_frame.f_lineno ++ except ValueError, e: ++ # This is the exception we wanted; make sure the error message ++ # talks about trace functions. ++ if 'trace' not in str(e): ++ raise ++ else: ++ # Something's wrong - the expected exception wasn't raised. ++ raise RuntimeError, "Trace-function-less jump failed to fail" ++ ++ ++class JumpTestCase(unittest.TestCase): ++ def compare_jump_output(self, expected, received): ++ if received != expected: ++ self.fail( "Outputs don't match:\n" + ++ "Expected: " + repr(expected) + "\n" + ++ "Received: " + repr(received)) ++ ++ def run_test(self, func): ++ tracer = JumpTracer(func) ++ sys.settrace(tracer.trace) ++ output = [] ++ func(output) ++ sys.settrace(None) ++ self.compare_jump_output(func.output, output) ++ ++ def test_01_jump_simple_forwards(self): ++ self.run_test(jump_simple_forwards) ++ def test_02_jump_simple_backwards(self): ++ self.run_test(jump_simple_backwards) ++ def test_03_jump_out_of_block_forwards(self): ++ self.run_test(jump_out_of_block_forwards) ++ def test_04_jump_out_of_block_backwards(self): ++ self.run_test(jump_out_of_block_backwards) ++ def test_05_jump_to_codeless_line(self): ++ self.run_test(jump_to_codeless_line) ++ def test_06_jump_to_same_line(self): ++ self.run_test(jump_to_same_line) ++ def test_07_jump_in_nested_finally(self): ++ self.run_test(jump_in_nested_finally) ++ def test_08_no_jump_too_far_forwards(self): ++ self.run_test(no_jump_too_far_forwards) ++ def test_09_no_jump_too_far_backwards(self): ++ self.run_test(no_jump_too_far_backwards) ++ def test_10_no_jump_to_except_1(self): ++ self.run_test(no_jump_to_except_1) ++ def test_11_no_jump_to_except_2(self): ++ self.run_test(no_jump_to_except_2) ++ def test_12_no_jump_to_except_3(self): ++ self.run_test(no_jump_to_except_3) ++ def test_13_no_jump_to_except_4(self): ++ self.run_test(no_jump_to_except_4) ++ def test_14_no_jump_forwards_into_block(self): ++ self.run_test(no_jump_forwards_into_block) ++ def test_15_no_jump_backwards_into_block(self): ++ self.run_test(no_jump_backwards_into_block) ++ def test_16_no_jump_into_finally_block(self): ++ self.run_test(no_jump_into_finally_block) ++ def test_17_no_jump_out_of_finally_block(self): ++ self.run_test(no_jump_out_of_finally_block) ++ def test_18_no_jump_to_non_integers(self): ++ self.run_test(no_jump_to_non_integers) ++ def test_19_no_jump_without_trace_function(self): ++ no_jump_without_trace_function() ++ ++ def test_20_large_function(self): ++ d = {} ++ exec("""def f(output): # line 0 ++ x = 0 # line 1 ++ y = 1 # line 2 ++ ''' # line 3 ++ %s # lines 4-1004 ++ ''' # line 1005 ++ x += 1 # line 1006 ++ output.append(x) # line 1007 ++ return""" % ('\n' * 1000,), d) ++ f = d['f'] ++ ++ f.jump = (2, 1007) ++ f.output = [0] ++ self.run_test(f) ++ ++ def test_jump_to_firstlineno(self): ++ # This tests that PDB can jump back to the first line in a ++ # file. See issue #1689458. It can only be triggered in a ++ # function call if the function is defined on a single line. ++ code = compile(""" ++# Comments don't count. ++output.append(2) # firstlineno is here. ++output.append(3) ++output.append(4) ++""", "", "exec") ++ class fake_function: ++ func_code = code ++ jump = (2, 0) ++ tracer = JumpTracer(fake_function) ++ sys.settrace(tracer.trace) ++ namespace = {"output": []} ++ exec code in namespace ++ sys.settrace(None) ++ self.compare_jump_output([2, 3, 2, 3, 4], namespace["output"]) ++ ++ ++def test_main(): ++ test_support.run_unittest( ++ TraceTestCase, ++ RaisingTraceFuncTestCase, ++ JumpTestCase ++ ) ++ ++if __name__ == "__main__": ++ test_main() + +Property changes on: Lib/test/test_sys_settrace.py +___________________________________________________________________ +Added: svn:eol-style + + native +Added: svn:keywords + + Author Date Id Revision + +--- a/Lib/test/test_ioctl.py ++++ b/Lib/test/test_ioctl.py +@@ -1,3 +1,4 @@ ++import array + import unittest + from test.test_support import run_unittest, import_module, get_attribute + import os, struct +@@ -7,9 +8,17 @@ + + try: + tty = open("/dev/tty", "r") +- tty.close() + except IOError: + raise unittest.SkipTest("Unable to open /dev/tty") ++else: ++ # Skip if another process is in foreground ++ r = fcntl.ioctl(tty, termios.TIOCGPGRP, " ") ++ tty.close() ++ rpgrp = struct.unpack("i", r)[0] ++ if rpgrp not in (os.getpgrp(), os.getsid(0)): ++ raise unittest.SkipTest("Neither the process group nor the session " ++ "are attached to /dev/tty") ++ del tty, r, rpgrp + + try: + import pty +@@ -26,16 +35,36 @@ + rpgrp = struct.unpack("i", r)[0] + self.assertIn(rpgrp, ids) + +- def test_ioctl_mutate(self): +- import array +- buf = array.array('i', [0]) ++ def _check_ioctl_mutate_len(self, nbytes=None): ++ buf = array.array('i') ++ intsize = buf.itemsize + ids = (os.getpgrp(), os.getsid(0)) +- tty = open("/dev/tty", "r") +- r = fcntl.ioctl(tty, termios.TIOCGPGRP, buf, 1) ++ # A fill value unlikely to be in `ids` ++ fill = -12345 ++ if nbytes is not None: ++ # Extend the buffer so that it is exactly `nbytes` bytes long ++ buf.extend([fill] * (nbytes // intsize)) ++ self.assertEqual(len(buf) * intsize, nbytes) # sanity check ++ else: ++ buf.append(fill) ++ with open("/dev/tty", "r") as tty: ++ r = fcntl.ioctl(tty, termios.TIOCGPGRP, buf, 1) + rpgrp = buf[0] + self.assertEquals(r, 0) + self.assertIn(rpgrp, ids) + ++ def test_ioctl_mutate(self): ++ self._check_ioctl_mutate_len() ++ ++ def test_ioctl_mutate_1024(self): ++ # Issue #9758: a mutable buffer of exactly 1024 bytes wouldn't be ++ # copied back after the system call. ++ self._check_ioctl_mutate_len(1024) ++ ++ def test_ioctl_mutate_2048(self): ++ # Test with a larger buffer, just for the record. ++ self._check_ioctl_mutate_len(2048) ++ + def test_ioctl_signed_unsigned_code_param(self): + if not pty: + raise unittest.SkipTest('pty module required') +--- a/Lib/test/test_array.py ++++ b/Lib/test/test_array.py +@@ -188,6 +188,17 @@ + f.close() + test_support.unlink(test_support.TESTFN) + ++ def test_fromfile_ioerror(self): ++ # Issue #5395: Check if fromfile raises a proper IOError ++ # instead of EOFError. ++ a = array.array(self.typecode) ++ f = open(test_support.TESTFN, 'wb') ++ try: ++ self.assertRaises(IOError, a.fromfile, f, len(self.example)) ++ finally: ++ f.close() ++ test_support.unlink(test_support.TESTFN) ++ + def test_filewrite(self): + a = array.array(self.typecode, 2*self.example) + f = open(test_support.TESTFN, 'wb') +--- a/Lib/test/test_unicode.py ++++ b/Lib/test/test_unicode.py +@@ -34,6 +34,16 @@ + ): + type2test = unicode + ++ def assertEqual(self, first, second, msg=None): ++ # strict assertEqual method: reject implicit bytes/unicode equality ++ super(UnicodeTest, self).assertEqual(first, second, msg) ++ if isinstance(first, unicode) or isinstance(second, unicode): ++ self.assertIsInstance(first, unicode) ++ self.assertIsInstance(second, unicode) ++ elif isinstance(first, str) or isinstance(second, str): ++ self.assertIsInstance(first, str) ++ self.assertIsInstance(second, str) ++ + def checkequalnofix(self, result, object, methodname, *args): + method = getattr(object, methodname) + realresult = method(*args) +@@ -197,9 +207,9 @@ + + def test_comparison(self): + # Comparisons: +- self.assertEqual(u'abc', 'abc') +- self.assertEqual('abc', u'abc') +- self.assertEqual(u'abc', u'abc') ++ self.assertTrue(u'abc' == 'abc') ++ self.assertTrue('abc' == u'abc') ++ self.assertTrue(u'abc' == u'abc') + self.assertTrue(u'abcd' > 'abc') + self.assertTrue('abcd' > u'abc') + self.assertTrue(u'abcd' > u'abc') +@@ -394,11 +404,14 @@ + + self.assertEqual(u'%c' % 0x1234, u'\u1234') + self.assertRaises(OverflowError, u"%c".__mod__, (sys.maxunicode+1,)) ++ self.assertRaises(ValueError, u"%.1\u1032f".__mod__, (1.0/3)) + + for num in range(0x00,0x80): + char = chr(num) +- self.assertEqual(u"%c" % char, char) +- self.assertEqual(u"%c" % num, char) ++ self.assertEqual(u"%c" % char, unicode(char)) ++ self.assertEqual(u"%c" % num, unicode(char)) ++ self.assertTrue(char == u"%c" % char) ++ self.assertTrue(char == u"%c" % num) + # Issue 7649 + for num in range(0x80,0x100): + uchar = unichr(num) +@@ -557,9 +570,11 @@ + set_o = '!"#$%&*;<=>@[]^_`{|}' + for c in set_d: + self.assertEqual(c.encode('utf7'), c.encode('ascii')) +- self.assertEqual(c.encode('ascii').decode('utf7'), c) ++ self.assertEqual(c.encode('ascii').decode('utf7'), unicode(c)) ++ self.assertTrue(c == c.encode('ascii').decode('utf7')) + for c in set_o: +- self.assertEqual(c.encode('ascii').decode('utf7'), c) ++ self.assertEqual(c.encode('ascii').decode('utf7'), unicode(c)) ++ self.assertTrue(c == c.encode('ascii').decode('utf7')) + + def test_codecs_utf8(self): + self.assertEqual(u''.encode('utf-8'), '') +@@ -592,9 +607,9 @@ + ) + + # UTF-8 specific decoding tests +- self.assertEqual(unicode('\xf0\xa3\x91\x96', 'utf-8'), u'\U00023456' ) +- self.assertEqual(unicode('\xf0\x90\x80\x82', 'utf-8'), u'\U00010002' ) +- self.assertEqual(unicode('\xe2\x82\xac', 'utf-8'), u'\u20ac' ) ++ self.assertEqual(unicode('\xf0\xa3\x91\x96', 'utf-8'), u'\U00023456') ++ self.assertEqual(unicode('\xf0\x90\x80\x82', 'utf-8'), u'\U00010002') ++ self.assertEqual(unicode('\xe2\x82\xac', 'utf-8'), u'\u20ac') + + # Other possible utf-8 test cases: + # * strict decoding testing for all of the +@@ -1208,7 +1223,7 @@ + # format specifiers for user defined type + self.assertEqual(u'{0:abc}'.format(C()), u'abc') + +- # !r and !s coersions ++ # !r and !s coercions + self.assertEqual(u'{0!s}'.format(u'Hello'), u'Hello') + self.assertEqual(u'{0!s:}'.format(u'Hello'), u'Hello') + self.assertEqual(u'{0!s:15}'.format(u'Hello'), u'Hello ') +@@ -1222,12 +1237,15 @@ + self.assertEqual(u'{0}'.format([]), u'[]') + self.assertEqual(u'{0}'.format([1]), u'[1]') + self.assertEqual(u'{0}'.format(E(u'data')), u'E(data)') +- self.assertEqual(u'{0:^10}'.format(E(u'data')), u' E(data) ') +- self.assertEqual(u'{0:^10s}'.format(E(u'data')), u' E(data) ') + self.assertEqual(u'{0:d}'.format(G(u'data')), u'G(data)') +- self.assertEqual(u'{0:>15s}'.format(G(u'data')), u' string is data') + self.assertEqual(u'{0!s}'.format(G(u'data')), u'string is data') + ++ msg = 'object.__format__ with a non-empty format string is deprecated' ++ with test_support.check_warnings((msg, PendingDeprecationWarning)): ++ self.assertEqual(u'{0:^10}'.format(E(u'data')), u' E(data) ') ++ self.assertEqual(u'{0:^10s}'.format(E(u'data')), u' E(data) ') ++ self.assertEqual(u'{0:>15s}'.format(G(u'data')), u' string is data') ++ + self.assertEqual(u"{0:date: %Y-%m-%d}".format(I(year=2007, + month=8, + day=27)), +@@ -1359,8 +1377,8 @@ + def __unicode__(self): + return u'__unicode__ overridden' + u = U(u'xxx') +- self.assertEquals("%s" % u, u'__unicode__ overridden') +- self.assertEquals("{}".format(u), u'__unicode__ overridden') ++ self.assertEqual("%s" % u, u'__unicode__ overridden') ++ self.assertEqual("{}".format(u), '__unicode__ overridden') + + + def test_main(): +--- a/Lib/test/test_socket.py ++++ b/Lib/test/test_socket.py +@@ -12,9 +12,27 @@ + import sys + import os + import array ++import contextlib + from weakref import proxy + import signal ++import math + ++def try_address(host, port=0, family=socket.AF_INET): ++ """Try to bind a socket on the given host:port and return True ++ if that has been possible.""" ++ try: ++ sock = socket.socket(family, socket.SOCK_STREAM) ++ sock.bind((host, port)) ++ except (socket.error, socket.gaierror): ++ return False ++ else: ++ sock.close() ++ return True ++ ++HOST = test_support.HOST ++MSG = b'Michael Gilfix was here\n' ++SUPPORTS_IPV6 = socket.has_ipv6 and try_address('::1', family=socket.AF_INET6) ++ + try: + import thread + import threading +@@ -555,7 +573,81 @@ + self.assertRaises(ValueError, s.ioctl, -1, None) + s.ioctl(socket.SIO_KEEPALIVE_VALS, (1, 100, 100)) + ++ def testGetaddrinfo(self): ++ try: ++ socket.getaddrinfo('localhost', 80) ++ except socket.gaierror as err: ++ if err.errno == socket.EAI_SERVICE: ++ # see http://bugs.python.org/issue1282647 ++ self.skipTest("buggy libc version") ++ raise ++ # len of every sequence is supposed to be == 5 ++ for info in socket.getaddrinfo(HOST, None): ++ self.assertEqual(len(info), 5) ++ # host can be a domain name, a string representation of an ++ # IPv4/v6 address or None ++ socket.getaddrinfo('localhost', 80) ++ socket.getaddrinfo('127.0.0.1', 80) ++ socket.getaddrinfo(None, 80) ++ if SUPPORTS_IPV6: ++ socket.getaddrinfo('::1', 80) ++ # port can be a string service name such as "http", a numeric ++ # port number or None ++ socket.getaddrinfo(HOST, "http") ++ socket.getaddrinfo(HOST, 80) ++ socket.getaddrinfo(HOST, None) ++ # test family and socktype filters ++ infos = socket.getaddrinfo(HOST, None, socket.AF_INET) ++ for family, _, _, _, _ in infos: ++ self.assertEqual(family, socket.AF_INET) ++ infos = socket.getaddrinfo(HOST, None, 0, socket.SOCK_STREAM) ++ for _, socktype, _, _, _ in infos: ++ self.assertEqual(socktype, socket.SOCK_STREAM) ++ # test proto and flags arguments ++ socket.getaddrinfo(HOST, None, 0, 0, socket.SOL_TCP) ++ socket.getaddrinfo(HOST, None, 0, 0, 0, socket.AI_PASSIVE) ++ # a server willing to support both IPv4 and IPv6 will ++ # usually do this ++ socket.getaddrinfo(None, 0, socket.AF_UNSPEC, socket.SOCK_STREAM, 0, ++ socket.AI_PASSIVE) + ++ ++ def check_sendall_interrupted(self, with_timeout): ++ # socketpair() is not stricly required, but it makes things easier. ++ if not hasattr(signal, 'alarm') or not hasattr(socket, 'socketpair'): ++ self.skipTest("signal.alarm and socket.socketpair required for this test") ++ # Our signal handlers clobber the C errno by calling a math function ++ # with an invalid domain value. ++ def ok_handler(*args): ++ self.assertRaises(ValueError, math.acosh, 0) ++ def raising_handler(*args): ++ self.assertRaises(ValueError, math.acosh, 0) ++ 1 // 0 ++ c, s = socket.socketpair() ++ old_alarm = signal.signal(signal.SIGALRM, raising_handler) ++ try: ++ if with_timeout: ++ # Just above the one second minimum for signal.alarm ++ c.settimeout(1.5) ++ with self.assertRaises(ZeroDivisionError): ++ signal.alarm(1) ++ c.sendall(b"x" * (1024**2)) ++ if with_timeout: ++ signal.signal(signal.SIGALRM, ok_handler) ++ signal.alarm(1) ++ self.assertRaises(socket.timeout, c.sendall, b"x" * (1024**2)) ++ finally: ++ signal.signal(signal.SIGALRM, old_alarm) ++ c.close() ++ s.close() ++ ++ def test_sendall_interrupted(self): ++ self.check_sendall_interrupted(False) ++ ++ def test_sendall_interrupted_with_timeout(self): ++ self.check_sendall_interrupted(True) ++ ++ + @unittest.skipUnless(thread, 'Threading required for this test.') + class BasicTCPTest(SocketConnectedTest): + +@@ -994,13 +1086,43 @@ + """ + + class NetworkConnectionNoServer(unittest.TestCase): +- def testWithoutServer(self): ++ class MockSocket(socket.socket): ++ def connect(self, *args): ++ raise socket.timeout('timed out') ++ ++ @contextlib.contextmanager ++ def mocked_socket_module(self): ++ """Return a socket which times out on connect""" ++ old_socket = socket.socket ++ socket.socket = self.MockSocket ++ try: ++ yield ++ finally: ++ socket.socket = old_socket ++ ++ def test_connect(self): + port = test_support.find_unused_port() +- self.assertRaises( +- socket.error, +- lambda: socket.create_connection((HOST, port)) +- ) ++ cli = socket.socket(socket.AF_INET, socket.SOCK_STREAM) ++ with self.assertRaises(socket.error) as cm: ++ cli.connect((HOST, port)) ++ self.assertEqual(cm.exception.errno, errno.ECONNREFUSED) + ++ def test_create_connection(self): ++ # Issue #9792: errors raised by create_connection() should have ++ # a proper errno attribute. ++ port = test_support.find_unused_port() ++ with self.assertRaises(socket.error) as cm: ++ socket.create_connection((HOST, port)) ++ self.assertEqual(cm.exception.errno, errno.ECONNREFUSED) ++ ++ def test_create_connection_timeout(self): ++ # Issue #9792: create_connection() should not recast timeout errors ++ # as generic socket errors. ++ with self.mocked_socket_module(): ++ with self.assertRaises(socket.timeout): ++ socket.create_connection((HOST, 1234)) ++ ++ + @unittest.skipUnless(thread, 'Threading required for this test.') + class NetworkConnectionAttributesTest(SocketTCPTest, ThreadableTest): + +--- a/Lib/test/test_getopt.py ++++ b/Lib/test/test_getopt.py +@@ -173,6 +173,12 @@ + m = types.ModuleType("libreftest", s) + run_doctest(m, verbose) + ++ def test_issue4629(self): ++ longopts, shortopts = getopt.getopt(['--help='], '', ['help=']) ++ self.assertEquals(longopts, [('--help', '')]) ++ longopts, shortopts = getopt.getopt(['--help=x'], '', ['help=']) ++ self.assertEquals(longopts, [('--help', 'x')]) ++ self.assertRaises(getopt.GetoptError, getopt.getopt, ['--help='], '', ['help']) + + def test_main(): + run_unittest(GetoptTests) +--- a/Lib/test/test_shutil.py ++++ b/Lib/test/test_shutil.py +@@ -277,7 +277,8 @@ + + os.link(src, dst) + self.assertRaises(shutil.Error, shutil.copyfile, src, dst) +- self.assertEqual(open(src,'r').read(), 'cheddar') ++ with open(src, 'r') as f: ++ self.assertEqual(f.read(), 'cheddar') + os.remove(dst) + + # Using `src` here would mean we end up with a symlink pointing +@@ -285,7 +286,8 @@ + # TESTFN/cheese. + os.symlink('cheese', dst) + self.assertRaises(shutil.Error, shutil.copyfile, src, dst) +- self.assertEqual(open(src,'r').read(), 'cheddar') ++ with open(src, 'r') as f: ++ self.assertEqual(f.read(), 'cheddar') + os.remove(dst) + finally: + try: +@@ -588,9 +590,11 @@ + pass + + def _check_move_file(self, src, dst, real_dst): +- contents = open(src, "rb").read() ++ with open(src, "rb") as f: ++ contents = f.read() + shutil.move(src, dst) +- self.assertEqual(contents, open(real_dst, "rb").read()) ++ with open(real_dst, "rb") as f: ++ self.assertEqual(contents, f.read()) + self.assertFalse(os.path.exists(src)) + + def _check_move_dir(self, src, dst, real_dst): +--- a/Lib/test/test_threadsignals.py ++++ b/Lib/test/test_threadsignals.py +@@ -4,7 +4,7 @@ + import signal + import os + import sys +-from test.test_support import run_unittest, import_module ++from test.test_support import run_unittest, import_module, reap_threads + thread = import_module('thread') + + if sys.platform[:3] in ('win', 'os2') or sys.platform=='riscos': +@@ -39,6 +39,7 @@ + wait for it to finish. Check that we got both signals + and that they were run by the main thread. + """ ++ @reap_threads + def test_signals(self): + signalled_all.acquire() + self.spawnSignallingThread() +--- a/Lib/test/test_heapq.py ++++ b/Lib/test/test_heapq.py +@@ -330,14 +330,6 @@ + self.assertRaises(TypeError, f, 2, LenOnly()) + + def test_get_only(self): +- for f in (self.module.heapify, self.module.heappop): +- self.assertRaises(TypeError, f, GetOnly()) +- for f in (self.module.heappush, self.module.heapreplace): +- self.assertRaises(TypeError, f, GetOnly(), 10) +- for f in (self.module.nlargest, self.module.nsmallest): +- self.assertRaises(TypeError, f, 2, GetOnly()) +- +- def test_get_only(self): + seq = [CmpErr(), CmpErr(), CmpErr()] + for f in (self.module.heapify, self.module.heappop): + self.assertRaises(ZeroDivisionError, f, seq) +--- a/Lib/test/test_long.py ++++ b/Lib/test/test_long.py +@@ -601,6 +601,22 @@ + slicemin, slicemax = X()[-2L**100:2L**100] + self.assertEqual(X()[slicemin:slicemax], (slicemin, slicemax)) + ++ def test_issue9869(self): ++ # Issue 9869: Interpreter crash when initializing an instance ++ # of a long subclass from an object whose __long__ method returns ++ # a plain int. ++ class BadLong(object): ++ def __long__(self): ++ return 1000000 ++ ++ class MyLong(long): ++ pass ++ ++ x = MyLong(BadLong()) ++ self.assertIsInstance(x, long) ++ self.assertEqual(x, 1000000) ++ ++ + # ----------------------------------- tests of auto int->long conversion + + def test_auto_overflow(self): +--- a/Lib/test/test_gzip.py ++++ b/Lib/test/test_gzip.py +@@ -33,14 +33,15 @@ + + + def test_write(self): +- f = gzip.GzipFile(self.filename, 'wb') ; f.write(data1 * 50) ++ with gzip.GzipFile(self.filename, 'wb') as f: ++ f.write(data1 * 50) + +- # Try flush and fileno. +- f.flush() +- f.fileno() +- if hasattr(os, 'fsync'): +- os.fsync(f.fileno()) +- f.close() ++ # Try flush and fileno. ++ f.flush() ++ f.fileno() ++ if hasattr(os, 'fsync'): ++ os.fsync(f.fileno()) ++ f.close() + + # Test multiple close() calls. + f.close() +@@ -48,37 +49,59 @@ + def test_read(self): + self.test_write() + # Try reading. +- f = gzip.GzipFile(self.filename, 'r') ; d = f.read() ; f.close() ++ with gzip.GzipFile(self.filename, 'r') as f: ++ d = f.read() + self.assertEqual(d, data1*50) + ++ def test_io_on_closed_object(self): ++ # Test that I/O operations on closed GzipFile objects raise a ++ # ValueError, just like the corresponding functions on file objects. ++ ++ # Write to a file, open it for reading, then close it. ++ self.test_write() ++ f = gzip.GzipFile(self.filename, 'r') ++ f.close() ++ with self.assertRaises(ValueError): ++ f.read(1) ++ with self.assertRaises(ValueError): ++ f.seek(0) ++ with self.assertRaises(ValueError): ++ f.tell() ++ # Open the file for writing, then close it. ++ f = gzip.GzipFile(self.filename, 'w') ++ f.close() ++ with self.assertRaises(ValueError): ++ f.write('') ++ with self.assertRaises(ValueError): ++ f.flush() ++ + def test_append(self): + self.test_write() + # Append to the previous file +- f = gzip.GzipFile(self.filename, 'ab') ; f.write(data2 * 15) ; f.close() ++ with gzip.GzipFile(self.filename, 'ab') as f: ++ f.write(data2 * 15) + +- f = gzip.GzipFile(self.filename, 'rb') ; d = f.read() ; f.close() ++ with gzip.GzipFile(self.filename, 'rb') as f: ++ d = f.read() + self.assertEqual(d, (data1*50) + (data2*15)) + + def test_many_append(self): + # Bug #1074261 was triggered when reading a file that contained + # many, many members. Create such a file and verify that reading it + # works. +- f = gzip.open(self.filename, 'wb', 9) +- f.write('a') +- f.close() +- for i in range(0,200): +- f = gzip.open(self.filename, "ab", 9) # append ++ with gzip.open(self.filename, 'wb', 9) as f: + f.write('a') +- f.close() ++ for i in range(0, 200): ++ with gzip.open(self.filename, "ab", 9) as f: # append ++ f.write('a') + + # Try reading the file +- zgfile = gzip.open(self.filename, "rb") +- contents = "" +- while 1: +- ztxt = zgfile.read(8192) +- contents += ztxt +- if not ztxt: break +- zgfile.close() ++ with gzip.open(self.filename, "rb") as zgfile: ++ contents = "" ++ while 1: ++ ztxt = zgfile.read(8192) ++ contents += ztxt ++ if not ztxt: break + self.assertEquals(contents, 'a'*201) + + def test_buffered_reader(self): +@@ -86,9 +109,9 @@ + # performance. + self.test_write() + +- f = gzip.GzipFile(self.filename, 'rb') +- with io.BufferedReader(f) as r: +- lines = [line for line in r] ++ with gzip.GzipFile(self.filename, 'rb') as f: ++ with io.BufferedReader(f) as r: ++ lines = [line for line in r] + + self.assertEqual(lines, 50 * data1.splitlines(True)) + +@@ -96,141 +119,128 @@ + self.test_write() + # Try .readline() with varying line lengths + +- f = gzip.GzipFile(self.filename, 'rb') +- line_length = 0 +- while 1: +- L = f.readline(line_length) +- if L == "" and line_length != 0: break +- self.assertTrue(len(L) <= line_length) +- line_length = (line_length + 1) % 50 +- f.close() ++ with gzip.GzipFile(self.filename, 'rb') as f: ++ line_length = 0 ++ while 1: ++ L = f.readline(line_length) ++ if not L and line_length != 0: break ++ self.assertTrue(len(L) <= line_length) ++ line_length = (line_length + 1) % 50 + + def test_readlines(self): + self.test_write() + # Try .readlines() + +- f = gzip.GzipFile(self.filename, 'rb') +- L = f.readlines() +- f.close() ++ with gzip.GzipFile(self.filename, 'rb') as f: ++ L = f.readlines() + +- f = gzip.GzipFile(self.filename, 'rb') +- while 1: +- L = f.readlines(150) +- if L == []: break +- f.close() ++ with gzip.GzipFile(self.filename, 'rb') as f: ++ while 1: ++ L = f.readlines(150) ++ if L == []: break + + def test_seek_read(self): + self.test_write() + # Try seek, read test + +- f = gzip.GzipFile(self.filename) +- while 1: +- oldpos = f.tell() +- line1 = f.readline() +- if not line1: break +- newpos = f.tell() +- f.seek(oldpos) # negative seek +- if len(line1)>10: +- amount = 10 +- else: +- amount = len(line1) +- line2 = f.read(amount) +- self.assertEqual(line1[:amount], line2) +- f.seek(newpos) # positive seek +- f.close() ++ with gzip.GzipFile(self.filename) as f: ++ while 1: ++ oldpos = f.tell() ++ line1 = f.readline() ++ if not line1: break ++ newpos = f.tell() ++ f.seek(oldpos) # negative seek ++ if len(line1)>10: ++ amount = 10 ++ else: ++ amount = len(line1) ++ line2 = f.read(amount) ++ self.assertEqual(line1[:amount], line2) ++ f.seek(newpos) # positive seek + + def test_seek_whence(self): + self.test_write() + # Try seek(whence=1), read test + +- f = gzip.GzipFile(self.filename) +- f.read(10) +- f.seek(10, whence=1) +- y = f.read(10) +- f.close() ++ with gzip.GzipFile(self.filename) as f: ++ f.read(10) ++ f.seek(10, whence=1) ++ y = f.read(10) + self.assertEquals(y, data1[20:30]) + + def test_seek_write(self): + # Try seek, write test +- f = gzip.GzipFile(self.filename, 'w') +- for pos in range(0, 256, 16): +- f.seek(pos) +- f.write('GZ\n') +- f.close() ++ with gzip.GzipFile(self.filename, 'w') as f: ++ for pos in range(0, 256, 16): ++ f.seek(pos) ++ f.write('GZ\n') + + def test_mode(self): + self.test_write() +- f = gzip.GzipFile(self.filename, 'r') +- self.assertEqual(f.myfileobj.mode, 'rb') +- f.close() ++ with gzip.GzipFile(self.filename, 'r') as f: ++ self.assertEqual(f.myfileobj.mode, 'rb') + + def test_1647484(self): + for mode in ('wb', 'rb'): +- f = gzip.GzipFile(self.filename, mode) +- self.assertTrue(hasattr(f, "name")) +- self.assertEqual(f.name, self.filename) +- f.close() ++ with gzip.GzipFile(self.filename, mode) as f: ++ self.assertTrue(hasattr(f, "name")) ++ self.assertEqual(f.name, self.filename) + + def test_mtime(self): + mtime = 123456789 +- fWrite = gzip.GzipFile(self.filename, 'w', mtime = mtime) +- fWrite.write(data1) +- fWrite.close() +- fRead = gzip.GzipFile(self.filename) +- dataRead = fRead.read() +- self.assertEqual(dataRead, data1) +- self.assertTrue(hasattr(fRead, 'mtime')) +- self.assertEqual(fRead.mtime, mtime) +- fRead.close() ++ with gzip.GzipFile(self.filename, 'w', mtime = mtime) as fWrite: ++ fWrite.write(data1) ++ with gzip.GzipFile(self.filename) as fRead: ++ dataRead = fRead.read() ++ self.assertEqual(dataRead, data1) ++ self.assertTrue(hasattr(fRead, 'mtime')) ++ self.assertEqual(fRead.mtime, mtime) + + def test_metadata(self): + mtime = 123456789 + +- fWrite = gzip.GzipFile(self.filename, 'w', mtime = mtime) +- fWrite.write(data1) +- fWrite.close() ++ with gzip.GzipFile(self.filename, 'w', mtime = mtime) as fWrite: ++ fWrite.write(data1) + +- fRead = open(self.filename, 'rb') ++ with open(self.filename, 'rb') as fRead: ++ # see RFC 1952: http://www.faqs.org/rfcs/rfc1952.html + +- # see RFC 1952: http://www.faqs.org/rfcs/rfc1952.html ++ idBytes = fRead.read(2) ++ self.assertEqual(idBytes, '\x1f\x8b') # gzip ID + +- idBytes = fRead.read(2) +- self.assertEqual(idBytes, '\x1f\x8b') # gzip ID ++ cmByte = fRead.read(1) ++ self.assertEqual(cmByte, '\x08') # deflate + +- cmByte = fRead.read(1) +- self.assertEqual(cmByte, '\x08') # deflate ++ flagsByte = fRead.read(1) ++ self.assertEqual(flagsByte, '\x08') # only the FNAME flag is set + +- flagsByte = fRead.read(1) +- self.assertEqual(flagsByte, '\x08') # only the FNAME flag is set ++ mtimeBytes = fRead.read(4) ++ self.assertEqual(mtimeBytes, struct.pack(' A(1)) +- self.assert_(A(1) <= A(2)) +- self.assert_(A(2) >= A(1)) +- self.assert_(A(2) <= A(2)) +- self.assert_(A(2) >= A(2)) ++ self.assert_(A("a") < A("b")) ++ self.assert_(A("b") > A("a")) ++ self.assert_(A("a") <= A("b")) ++ self.assert_(A("b") >= A("a")) ++ self.assert_(A("b") <= A("b")) ++ self.assert_(A("b") >= A("b")) + + def test_no_operations_defined(self): + with self.assertRaises(ValueError): +@@ -434,6 +434,7 @@ + TestPartialSubclass, + TestPythonPartial, + TestUpdateWrapper, ++ TestTotalOrdering, + TestWraps, + TestReduce, + ) +--- a/Lib/test/test_pstats.py ++++ b/Lib/test/test_pstats.py +@@ -10,10 +10,16 @@ + def test_combine_results(self): + """pstats.add_callers should combine the call results of both target + and source by adding the call time. See issue1269.""" ++ # new format: used by the cProfile module + target = {"a": (1, 2, 3, 4)} + source = {"a": (1, 2, 3, 4), "b": (5, 6, 7, 8)} + new_callers = pstats.add_callers(target, source) + self.assertEqual(new_callers, {'a': (2, 4, 6, 8), 'b': (5, 6, 7, 8)}) ++ # old format: used by the profile module ++ target = {"a": 1} ++ source = {"a": 1, "b": 5} ++ new_callers = pstats.add_callers(target, source) ++ self.assertEqual(new_callers, {'a': 2, 'b': 5}) + + + def test_main(): +--- a/Lib/test/test_os.py ++++ b/Lib/test/test_os.py +@@ -11,6 +11,8 @@ + import subprocess + import time + from test import test_support ++import mmap ++import uuid + + warnings.filterwarnings("ignore", "tempnam", RuntimeWarning, __name__) + warnings.filterwarnings("ignore", "tmpnam", RuntimeWarning, __name__) +@@ -736,13 +738,23 @@ + self._kill(100) + + def _kill_with_event(self, event, name): ++ tagname = "test_os_%s" % uuid.uuid1() ++ m = mmap.mmap(-1, 1, tagname) ++ m[0] = '0' + # Run a script which has console control handling enabled. + proc = subprocess.Popen([sys.executable, + os.path.join(os.path.dirname(__file__), +- "win_console_handler.py")], ++ "win_console_handler.py"), tagname], + creationflags=subprocess.CREATE_NEW_PROCESS_GROUP) + # Let the interpreter startup before we send signals. See #3137. +- time.sleep(0.5) ++ count, max = 0, 20 ++ while count < max and proc.poll() is None: ++ if m[0] == '0': ++ break ++ time.sleep(0.5) ++ count += 1 ++ else: ++ self.fail("Subprocess didn't finish initialization") + os.kill(proc.pid, event) + # proc.send_signal(event) could also be done here. + # Allow time for the signal to be passed and the process to exit. +--- a/Lib/test/test_syntax.py ++++ b/Lib/test/test_syntax.py +@@ -474,6 +474,12 @@ + File "", line 1 + SyntaxError: can't assign to literal + ++Corner-case that used to crash: ++ ++ >>> def f(*xx, **__debug__): pass ++ Traceback (most recent call last): ++ SyntaxError: cannot assign to __debug__ ++ + """ + + import re +--- a/Lib/test/test_parser.py ++++ b/Lib/test/test_parser.py +@@ -180,7 +180,15 @@ + + def test_class_defs(self): + self.check_suite("class foo():pass") ++ self.check_suite("@class_decorator\n" ++ "class foo():pass") ++ self.check_suite("@class_decorator(arg)\n" ++ "class foo():pass") ++ self.check_suite("@decorator1\n" ++ "@decorator2\n" ++ "class foo():pass") + ++ + def test_import_from_statement(self): + self.check_suite("from sys.path import *") + self.check_suite("from sys.path import dirname") +@@ -213,6 +221,12 @@ + self.check_suite("import sys as system, math") + self.check_suite("import sys, math as my_math") + ++ def test_relative_imports(self): ++ self.check_suite("from . import name") ++ self.check_suite("from .. import name") ++ self.check_suite("from .pkg import name") ++ self.check_suite("from ..pkg import name") ++ + def test_pep263(self): + self.check_suite("# -*- coding: iso-8859-1 -*-\n" + "pass\n") +@@ -511,7 +525,21 @@ + (0, '')) + self.check_bad_tree(tree, "malformed global ast") + ++ def test_missing_import_source(self): ++ # from import a ++ tree = \ ++ (257, ++ (267, ++ (268, ++ (269, ++ (281, ++ (283, (1, 'from'), (1, 'import'), ++ (286, (284, (1, 'fred')))))), ++ (4, ''))), ++ (4, ''), (0, '')) ++ self.check_bad_tree(tree, "from import a") + ++ + class CompileTestCase(unittest.TestCase): + + # These tests are very minimal. :-( +--- a/Lib/test/test_doctest.py ++++ b/Lib/test/test_doctest.py +@@ -981,6 +981,35 @@ + ZeroDivisionError: integer division or modulo by zero + TestResults(failed=1, attempted=1) + """ ++ def displayhook(): r""" ++Test that changing sys.displayhook doesn't matter for doctest. ++ ++ >>> import sys ++ >>> orig_displayhook = sys.displayhook ++ >>> def my_displayhook(x): ++ ... print('hi!') ++ >>> sys.displayhook = my_displayhook ++ >>> def f(): ++ ... ''' ++ ... >>> 3 ++ ... 3 ++ ... ''' ++ >>> test = doctest.DocTestFinder().find(f)[0] ++ >>> r = doctest.DocTestRunner(verbose=False).run(test) ++ >>> post_displayhook = sys.displayhook ++ ++ We need to restore sys.displayhook now, so that we'll be able to test ++ results. ++ ++ >>> sys.displayhook = orig_displayhook ++ ++ Ok, now we can check that everything is ok. ++ ++ >>> r ++ TestResults(failed=0, attempted=1) ++ >>> post_displayhook is my_displayhook ++ True ++""" + def optionflags(): r""" + Tests of `DocTestRunner`'s option flag handling. + +@@ -1581,8 +1610,34 @@ + >>> test = doctest.DocTestParser().get_doctest(s, {}, 's', 's.py', 0) + Traceback (most recent call last): + ValueError: line 0 of the doctest for s has an option directive on a line with no example: '# doctest: +ELLIPSIS' +-""" + ++ """ ++ ++ def test_unicode_output(self): r""" ++ ++Check that unicode output works: ++ ++ >>> u'\xe9' ++ u'\xe9' ++ ++If we return unicode, SpoofOut's buf variable becomes automagically ++converted to unicode. This means all subsequent output becomes converted ++to unicode, and if the output contains non-ascii characters that failed. ++It used to be that this state change carried on between tests, meaning ++tests would fail if unicode has been output previously in the testrun. ++This test tests that this is no longer so: ++ ++ >>> print u'abc' ++ abc ++ ++And then return a string with non-ascii characters: ++ ++ >>> print u'\xe9'.encode('utf-8') ++ é ++ ++ """ ++ ++ + def test_testsource(): r""" + Unit tests for `testsource()`. + +@@ -1666,10 +1721,13 @@ + + >>> doc = ''' + ... >>> x = 42 ++ ... >>> raise Exception('clé') ++ ... Traceback (most recent call last): ++ ... Exception: clé + ... >>> import pdb; pdb.set_trace() + ... ''' + >>> parser = doctest.DocTestParser() +- >>> test = parser.get_doctest(doc, {}, "foo", "foo.py", 0) ++ >>> test = parser.get_doctest(doc, {}, "foo-bär@baz", "foo-bär@baz.py", 0) + >>> runner = doctest.DocTestRunner(verbose=False) + + To demonstrate this, we'll create a fake standard input that +@@ -1685,12 +1743,12 @@ + >>> try: runner.run(test) + ... finally: sys.stdin = real_stdin + --Return-- +- > (1)()->None ++ > (1)()->None + -> import pdb; pdb.set_trace() + (Pdb) print x + 42 + (Pdb) continue +- TestResults(failed=0, attempted=2) ++ TestResults(failed=0, attempted=3) + + You can also put pdb.set_trace in a function called from a test: + +@@ -1702,7 +1760,7 @@ + ... >>> x=1 + ... >>> calls_set_trace() + ... ''' +- >>> test = parser.get_doctest(doc, globals(), "foo", "foo.py", 0) ++ >>> test = parser.get_doctest(doc, globals(), "foo-bär@baz", "foo-bär@baz.py", 0) + >>> real_stdin = sys.stdin + >>> sys.stdin = _FakeInput([ + ... 'print y', # print data defined in the function +@@ -1721,7 +1779,7 @@ + (Pdb) print y + 2 + (Pdb) up +- > (1)() ++ > (1)() + -> calls_set_trace() + (Pdb) print x + 1 +@@ -1739,7 +1797,7 @@ + ... ... import pdb; pdb.set_trace() + ... >>> f(3) + ... ''' +- >>> test = parser.get_doctest(doc, globals(), "foo", "foo.py", 0) ++ >>> test = parser.get_doctest(doc, globals(), "foo-bär@baz", "foo-bär@baz.py", 0) + >>> real_stdin = sys.stdin + >>> sys.stdin = _FakeInput([ + ... 'list', # list source from example 2 +@@ -1753,7 +1811,7 @@ + ... finally: sys.stdin = real_stdin + ... # doctest: +NORMALIZE_WHITESPACE + --Return-- +- > (3)g()->None ++ > (3)g()->None + -> import pdb; pdb.set_trace() + (Pdb) list + 1 def g(x): +@@ -1762,7 +1820,7 @@ + [EOF] + (Pdb) next + --Return-- +- > (2)f()->None ++ > (2)f()->None + -> g(x*2) + (Pdb) list + 1 def f(x): +@@ -1770,14 +1828,14 @@ + [EOF] + (Pdb) next + --Return-- +- > (1)()->None ++ > (1)()->None + -> f(3) + (Pdb) list + 1 -> f(3) + [EOF] + (Pdb) continue + ********************************************************************** +- File "foo.py", line 7, in foo ++ File "foo-bär@baz.py", line 7, in foo-bär@baz + Failed example: + f(3) + Expected nothing +@@ -1811,7 +1869,7 @@ + ... ''' + >>> parser = doctest.DocTestParser() + >>> runner = doctest.DocTestRunner(verbose=False) +- >>> test = parser.get_doctest(doc, globals(), "foo", "foo.py", 0) ++ >>> test = parser.get_doctest(doc, globals(), "foo-bär@baz", "foo-bär@baz.py", 0) + >>> real_stdin = sys.stdin + >>> sys.stdin = _FakeInput([ + ... 'print y', # print data defined in the function +@@ -1863,7 +1921,7 @@ + (Pdb) print y + 1 + (Pdb) up +- > (1)() ++ > (1)() + -> calls_set_trace() + (Pdb) print foo + *** NameError: name 'foo' is not defined +--- a/Lib/test/test_httplib.py ++++ b/Lib/test/test_httplib.py +@@ -1,3 +1,4 @@ ++import httplib + import array + import httplib + import StringIO +@@ -2,2 +3,3 @@ + import socket ++import errno + +@@ -24,6 +26,21 @@ + raise httplib.UnimplementedFileMode() + return self.fileclass(self.text) + ++class EPipeSocket(FakeSocket): ++ ++ def __init__(self, text, pipe_trigger): ++ # When sendall() is called with pipe_trigger, raise EPIPE. ++ FakeSocket.__init__(self, text) ++ self.pipe_trigger = pipe_trigger ++ ++ def sendall(self, data): ++ if self.pipe_trigger in data: ++ raise socket.error(errno.EPIPE, "gotcha") ++ self.data += data ++ ++ def close(self): ++ pass ++ + class NoEOFStringIO(StringIO.StringIO): + """Like StringIO, but raises AssertionError on EOF. + +@@ -48,8 +65,6 @@ + # Some headers are added automatically, but should not be added by + # .request() if they are explicitly set. + +- import httplib +- + class HeaderCountingBuffer(list): + def __init__(self): + self.count = {} +@@ -75,6 +90,13 @@ + conn.request('POST', '/', body, headers) + self.assertEqual(conn._buffer.count[header.lower()], 1) + ++ def test_putheader(self): ++ conn = httplib.HTTPConnection('example.com') ++ conn.sock = FakeSocket(None) ++ conn.putrequest('GET','/') ++ conn.putheader('Content-length',42) ++ self.assertTrue('Content-length: 42' in conn._buffer) ++ + class BasicTest(TestCase): + def test_status_lines(self): + # Test HTTP status lines +@@ -254,7 +276,29 @@ + finally: + resp.close() + ++ def test_epipe(self): ++ sock = EPipeSocket( ++ "HTTP/1.0 401 Authorization Required\r\n" ++ "Content-type: text/html\r\n" ++ "WWW-Authenticate: Basic realm=\"example\"\r\n", ++ b"Content-Length") ++ conn = httplib.HTTPConnection("example.com") ++ conn.sock = sock ++ self.assertRaises(socket.error, ++ lambda: conn.request("PUT", "/url", "body")) ++ resp = conn.getresponse() ++ self.assertEqual(401, resp.status) ++ self.assertEqual("Basic realm=\"example\"", ++ resp.getheader("www-authenticate")) + ++ def test_filenoattr(self): ++ # Just test the fileno attribute in the HTTPResponse Object. ++ body = "HTTP/1.1 200 Ok\r\n\r\nText" ++ sock = FakeSocket(body) ++ resp = httplib.HTTPResponse(sock) ++ self.assertTrue(hasattr(resp,'fileno'), ++ 'HTTPResponse should expose a fileno attribute') ++ + class OfflineTest(TestCase): + def test_responses(self): + self.assertEquals(httplib.responses[httplib.NOT_FOUND], "Not Found") +--- a/Lib/test/test_xml_etree.py ++++ b/Lib/test/test_xml_etree.py +@@ -586,10 +586,13 @@ + + + ++ >>> with open(SIMPLE_XMLFILE) as f: ++ ... data = f.read() ++ + >>> parser = ET.XMLParser() + >>> parser.version # doctest: +ELLIPSIS + 'Expat ...' +- >>> parser.feed(open(SIMPLE_XMLFILE).read()) ++ >>> parser.feed(data) + >>> print serialize(parser.close()) + + text +@@ -598,7 +601,7 @@ + + + >>> parser = ET.XMLTreeBuilder() # 1.2 compatibility +- >>> parser.feed(open(SIMPLE_XMLFILE).read()) ++ >>> parser.feed(data) + >>> print serialize(parser.close()) + + text +@@ -608,7 +611,7 @@ + + >>> target = ET.TreeBuilder() + >>> parser = ET.XMLParser(target=target) +- >>> parser.feed(open(SIMPLE_XMLFILE).read()) ++ >>> parser.feed(data) + >>> print serialize(parser.close()) + + text +@@ -711,7 +714,8 @@ + end-ns None + + >>> events = ("start", "end", "bogus") +- >>> context = iterparse(SIMPLE_XMLFILE, events) ++ >>> with open(SIMPLE_XMLFILE, "rb") as f: ++ ... iterparse(f, events) + Traceback (most recent call last): + ValueError: unknown event 'bogus' + +@@ -763,6 +767,8 @@ + """ + Test parser w. custom builder. + ++ >>> with open(SIMPLE_XMLFILE) as f: ++ ... data = f.read() + >>> class Builder: + ... def start(self, tag, attrib): + ... print "start", tag +@@ -772,7 +778,7 @@ + ... pass + >>> builder = Builder() + >>> parser = ET.XMLParser(target=builder) +- >>> parser.feed(open(SIMPLE_XMLFILE, "r").read()) ++ >>> parser.feed(data) + start root + start element + end element +@@ -782,6 +788,8 @@ + end empty-element + end root + ++ >>> with open(SIMPLE_NS_XMLFILE) as f: ++ ... data = f.read() + >>> class Builder: + ... def start(self, tag, attrib): + ... print "start", tag +@@ -795,7 +803,7 @@ + ... print "comment", repr(data) + >>> builder = Builder() + >>> parser = ET.XMLParser(target=builder) +- >>> parser.feed(open(SIMPLE_NS_XMLFILE, "r").read()) ++ >>> parser.feed(data) + pi pi 'data' + comment ' comment ' + start {namespace}root +@@ -813,7 +821,8 @@ + """ + Test Element.getchildren() + +- >>> tree = ET.parse(open(SIMPLE_XMLFILE, "r")) ++ >>> with open(SIMPLE_XMLFILE, "r") as f: ++ ... tree = ET.parse(f) + >>> for elem in tree.getroot().iter(): + ... summarize_list(elem.getchildren()) + ['element', 'element', 'empty-element'] +@@ -1259,6 +1268,14 @@ + + XINCLUDE["count.txt"] = "324387" + ++XINCLUDE["C2b.xml"] = """\ ++ ++ ++

This document has been accessed ++ times.

++
++""" ++ + XINCLUDE["C3.xml"] = """\ + + +@@ -1334,6 +1351,16 @@ + 324387 times.

+
+ ++ Textual inclusion after sibling element (based on modified XInclude C.2) ++ ++ >>> document = xinclude_loader("C2b.xml") ++ >>> ElementInclude.include(document, xinclude_loader) ++ >>> print(serialize(document)) # C2b ++ ++

This document has been accessed ++ 324387 times.

++
++ + Textual inclusion of XML example (XInclude C.3) + + >>> document = xinclude_loader("C3.xml") +--- a/Lib/test/decimaltestdata/extra.decTest ++++ b/Lib/test/decimaltestdata/extra.decTest +@@ -213,7 +213,20 @@ + extr1659 shift 1234567 4 -> 0 + extr1660 shift 1234567 5 -> NaN Invalid_operation + ++-- Cases where the power function was impossibly slow to determine that the ++-- result is inexact. Thanks Stefan Krah for identifying this problem. ++precision: 16 ++maxExponent: 999999999 ++minExponent: -999999999 ++extr1700 power 10 1e-999999999 -> 1.000000000000000 Inexact Rounded ++extr1701 power 100.0 -557.71e-742888888 -> 1.000000000000000 Inexact Rounded ++extr1702 power 10 1e-100 -> 1.000000000000000 Inexact Rounded + ++-- A couple of interesting exact cases for power. Note that the specification ++-- requires these to be reported as Inexact. ++extr1710 power 1e375 56e-3 -> 1.000000000000000E+21 Inexact Rounded ++extr1711 power 10000 0.75 -> 1000.000000000000 Inexact Rounded ++extr1712 power 1e-24 0.875 -> 1.000000000000000E-21 Inexact Rounded + + -- Tests for the is_* boolean operations + precision: 9 +--- a/Lib/test/test_types.py ++++ b/Lib/test/test_types.py +@@ -741,6 +741,11 @@ + for code in 'xXobns': + self.assertRaises(ValueError, format, 0, ',' + code) + ++ def test_internal_sizes(self): ++ self.assertGreater(object.__basicsize__, 0) ++ self.assertGreater(tuple.__itemsize__, 0) ++ ++ + def test_main(): + with check_py3k_warnings( + ("buffer.. not supported", DeprecationWarning), +--- a/Lib/test/test_compiler.py ++++ b/Lib/test/test_compiler.py +@@ -310,7 +310,7 @@ + + def test_main(): + global TEST_ALL +- TEST_ALL = test.test_support.is_resource_enabled("compiler") ++ TEST_ALL = test.test_support.is_resource_enabled("cpu") + test.test_support.run_unittest(CompilerTest) + + if __name__ == "__main__": +--- a/Lib/test/test_abc.py ++++ b/Lib/test/test_abc.py +@@ -3,7 +3,7 @@ + + """Unit tests for abc.py.""" + +-import unittest ++import unittest, weakref + from test import test_support + + import abc +@@ -15,16 +15,16 @@ + def test_abstractmethod_basics(self): + @abc.abstractmethod + def foo(self): pass +- self.assertEqual(foo.__isabstractmethod__, True) ++ self.assertTrue(foo.__isabstractmethod__) + def bar(self): pass +- self.assertEqual(hasattr(bar, "__isabstractmethod__"), False) ++ self.assertFalse(hasattr(bar, "__isabstractmethod__")) + + def test_abstractproperty_basics(self): + @abc.abstractproperty + def foo(self): pass +- self.assertEqual(foo.__isabstractmethod__, True) ++ self.assertTrue(foo.__isabstractmethod__) + def bar(self): pass +- self.assertEqual(hasattr(bar, "__isabstractmethod__"), False) ++ self.assertFalse(hasattr(bar, "__isabstractmethod__")) + + class C: + __metaclass__ = abc.ABCMeta +@@ -70,6 +70,13 @@ + self.assertFalse(issubclass(OldstyleClass, A)) + self.assertFalse(issubclass(A, OldstyleClass)) + ++ def test_type_has_no_abstractmethods(self): ++ # type pretends not to have __abstractmethods__. ++ self.assertRaises(AttributeError, getattr, type, "__abstractmethods__") ++ class meta(type): ++ pass ++ self.assertRaises(AttributeError, getattr, meta, "__abstractmethods__") ++ + def test_isinstance_class(self): + class A: + __metaclass__ = abc.ABCMeta +@@ -87,20 +94,20 @@ + class B(object): + pass + b = B() +- self.assertEqual(issubclass(B, A), False) +- self.assertEqual(issubclass(B, (A,)), False) ++ self.assertFalse(issubclass(B, A)) ++ self.assertFalse(issubclass(B, (A,))) + self.assertNotIsInstance(b, A) + self.assertNotIsInstance(b, (A,)) + A.register(B) +- self.assertEqual(issubclass(B, A), True) +- self.assertEqual(issubclass(B, (A,)), True) ++ self.assertTrue(issubclass(B, A)) ++ self.assertTrue(issubclass(B, (A,))) + self.assertIsInstance(b, A) + self.assertIsInstance(b, (A,)) + class C(B): + pass + c = C() +- self.assertEqual(issubclass(C, A), True) +- self.assertEqual(issubclass(C, (A,)), True) ++ self.assertTrue(issubclass(C, A)) ++ self.assertTrue(issubclass(C, (A,))) + self.assertIsInstance(c, A) + self.assertIsInstance(c, (A,)) + +@@ -110,11 +117,11 @@ + class B(object): + pass + b = B() +- self.assertEqual(isinstance(b, A), False) +- self.assertEqual(isinstance(b, (A,)), False) ++ self.assertFalse(isinstance(b, A)) ++ self.assertFalse(isinstance(b, (A,))) + A.register(B) +- self.assertEqual(isinstance(b, A), True) +- self.assertEqual(isinstance(b, (A,)), True) ++ self.assertTrue(isinstance(b, A)) ++ self.assertTrue(isinstance(b, (A,))) + + def test_registration_builtins(self): + class A: +@@ -122,15 +129,15 @@ + A.register(int) + self.assertIsInstance(42, A) + self.assertIsInstance(42, (A,)) +- self.assertEqual(issubclass(int, A), True) +- self.assertEqual(issubclass(int, (A,)), True) ++ self.assertTrue(issubclass(int, A)) ++ self.assertTrue(issubclass(int, (A,))) + class B(A): + pass + B.register(basestring) + self.assertIsInstance("", A) + self.assertIsInstance("", (A,)) +- self.assertEqual(issubclass(str, A), True) +- self.assertEqual(issubclass(str, (A,)), True) ++ self.assertTrue(issubclass(str, A)) ++ self.assertTrue(issubclass(str, (A,))) + + def test_registration_edge_cases(self): + class A: +@@ -208,6 +215,22 @@ + C() + self.assertEqual(B.counter, 1) + ++ def test_cache_leak(self): ++ # See issue #2521. ++ class A(object): ++ __metaclass__ = abc.ABCMeta ++ @abc.abstractmethod ++ def f(self): ++ pass ++ class C(A): ++ def f(self): ++ A.f(self) ++ r = weakref.ref(C) ++ # Trigger cache. ++ C().f() ++ del C ++ test_support.gc_collect() ++ self.assertEqual(r(), None) + + def test_main(): + test_support.run_unittest(TestABC) +--- a/Lib/test/test_mmap.py ++++ b/Lib/test/test_mmap.py +@@ -1,6 +1,6 @@ + from test.test_support import TESTFN, run_unittest, import_module + import unittest +-import os, re, itertools ++import os, re, itertools, socket + + mmap = import_module('mmap') + +@@ -586,6 +586,16 @@ + pass + m.close() + ++ def test_invalid_descriptor(self): ++ # socket file descriptors are valid, but out of range ++ # for _get_osfhandle, causing a crash when validating the ++ # parameters to _get_osfhandle. ++ s = socket.socket() ++ try: ++ with self.assertRaises(mmap.error): ++ m = mmap.mmap(s.fileno(), 10) ++ finally: ++ s.close() + + def test_main(): + run_unittest(MmapTests) +--- a/Lib/test/test_minidom.py ++++ b/Lib/test/test_minidom.py +@@ -945,6 +945,14 @@ + doc.unlink() + + ++ def testBug0777884(self): ++ doc = parseString("text") ++ text = doc.documentElement.childNodes[0] ++ self.assertEquals(text.nodeType, Node.TEXT_NODE) ++ # Should run quietly, doing nothing. ++ text.normalize() ++ doc.unlink() ++ + def testBug1433694(self): + doc = parseString("t") + node = doc.documentElement +--- a/Lib/test/test_pdb.py ++++ b/Lib/test/test_pdb.py +@@ -126,6 +126,48 @@ + """ + + ++def test_pdb_continue_in_bottomframe(): ++ """Test that "continue" and "next" work properly in bottom frame (issue #5294). ++ ++ >>> def test_function(): ++ ... import pdb, sys; inst = pdb.Pdb() ++ ... inst.set_trace() ++ ... inst.botframe = sys._getframe() # hackery to get the right botframe ++ ... print(1) ++ ... print(2) ++ ... print(3) ++ ... print(4) ++ ++ >>> with PdbTestInput([ ++ ... 'next', ++ ... 'break 7', ++ ... 'continue', ++ ... 'next', ++ ... 'continue', ++ ... 'continue', ++ ... ]): ++ ... test_function() ++ > (4)test_function() ++ -> inst.botframe = sys._getframe() # hackery to get the right botframe ++ (Pdb) next ++ > (5)test_function() ++ -> print(1) ++ (Pdb) break 7 ++ Breakpoint 1 at :7 ++ (Pdb) continue ++ 1 ++ 2 ++ > (7)test_function() ++ -> print(3) ++ (Pdb) next ++ 3 ++ > (8)test_function() ++ -> print(4) ++ (Pdb) continue ++ 4 ++ """ ++ ++ + def test_main(): + from test import test_pdb + test_support.run_doctest(test_pdb, verbosity=True) +--- a/Lib/test/test_str.py ++++ b/Lib/test/test_str.py +@@ -276,7 +276,7 @@ + # format specifiers for user defined type + self.assertEqual('{0:abc}'.format(C()), 'abc') + +- # !r and !s coersions ++ # !r and !s coercions + self.assertEqual('{0!s}'.format('Hello'), 'Hello') + self.assertEqual('{0!s:}'.format('Hello'), 'Hello') + self.assertEqual('{0!s:15}'.format('Hello'), 'Hello ') +@@ -290,12 +290,15 @@ + self.assertEqual('{0}'.format([]), '[]') + self.assertEqual('{0}'.format([1]), '[1]') + self.assertEqual('{0}'.format(E('data')), 'E(data)') +- self.assertEqual('{0:^10}'.format(E('data')), ' E(data) ') +- self.assertEqual('{0:^10s}'.format(E('data')), ' E(data) ') + self.assertEqual('{0:d}'.format(G('data')), 'G(data)') +- self.assertEqual('{0:>15s}'.format(G('data')), ' string is data') + self.assertEqual('{0!s}'.format(G('data')), 'string is data') + ++ msg = 'object.__format__ with a non-empty format string is deprecated' ++ with test_support.check_warnings((msg, PendingDeprecationWarning)): ++ self.assertEqual('{0:^10}'.format(E('data')), ' E(data) ') ++ self.assertEqual('{0:^10s}'.format(E('data')), ' E(data) ') ++ self.assertEqual('{0:>15s}'.format(G('data')), ' string is data') ++ + self.assertEqual("{0:date: %Y-%m-%d}".format(I(year=2007, + month=8, + day=27)), +--- a/Lib/test/test_scope.py ++++ b/Lib/test/test_scope.py +@@ -647,7 +647,14 @@ + self.assertEqual(2, global_ns["result2"]) + self.assertEqual(9, global_ns["result9"]) + ++ def testTopIsNotSignificant(self): ++ # See #9997. ++ def top(a): ++ pass ++ def b(): ++ global a + ++ + def test_main(): + with check_warnings(("import \* only allowed at module level", + SyntaxWarning)): +--- a/Lib/test/test_cfgparser.py ++++ b/Lib/test/test_cfgparser.py +@@ -1,5 +1,6 @@ + import ConfigParser + import StringIO ++import os + import unittest + import UserDict + +@@ -186,7 +187,8 @@ + self.assertEqual(cf.sections(), [], + "new ConfigParser should have no defined sections") + self.assertFalse(cf.has_section("Foo"), +- "new ConfigParser should have no acknowledged sections") ++ "new ConfigParser should have no acknowledged " ++ "sections") + self.assertRaises(ConfigParser.NoSectionError, + cf.options, "Foo") + self.assertRaises(ConfigParser.NoSectionError, +@@ -355,8 +357,14 @@ + + class ConfigParserTestCase(TestCaseBase): + config_class = ConfigParser.ConfigParser ++ allow_no_value = True + + def test_interpolation(self): ++ rawval = { ++ ConfigParser.ConfigParser: ("something %(with11)s " ++ "lots of interpolation (11 steps)"), ++ ConfigParser.SafeConfigParser: "%(with1)s", ++ } + cf = self.get_interpolation_config() + eq = self.assertEqual + eq(cf.get("Foo", "getname"), "Foo") +@@ -390,6 +398,7 @@ + cf.set('non-string', 'dict', {'pi': 3.14159, '%(': 1, + '%(list)': '%(list)'}) + cf.set('non-string', 'string_with_interpolation', '%(list)s') ++ cf.set('non-string', 'no-value') + self.assertEqual(cf.get('non-string', 'int', raw=True), 1) + self.assertRaises(TypeError, cf.get, 'non-string', 'int') + self.assertEqual(cf.get('non-string', 'list', raw=True), +@@ -402,8 +411,36 @@ + raw=True), '%(list)s') + self.assertRaises(ValueError, cf.get, 'non-string', + 'string_with_interpolation', raw=False) ++ self.assertEqual(cf.get('non-string', 'no-value'), None) + ++class MultilineValuesTestCase(TestCaseBase): ++ config_class = ConfigParser.ConfigParser ++ wonderful_spam = ("I'm having spam spam spam spam " ++ "spam spam spam beaked beans spam " ++ "spam spam and spam!").replace(' ', '\t\n') + ++ def setUp(self): ++ cf = self.newconfig() ++ for i in range(100): ++ s = 'section{}'.format(i) ++ cf.add_section(s) ++ for j in range(10): ++ cf.set(s, 'lovely_spam{}'.format(j), self.wonderful_spam) ++ with open(test_support.TESTFN, 'w') as f: ++ cf.write(f) ++ ++ def tearDown(self): ++ os.unlink(test_support.TESTFN) ++ ++ def test_dominating_multiline_values(self): ++ # we're reading from file because this is where the code changed ++ # during performance updates in Python 3.2 ++ cf_from_file = self.newconfig() ++ with open(test_support.TESTFN) as f: ++ cf_from_file.readfp(f) ++ self.assertEqual(cf_from_file.get('section8', 'lovely_spam4'), ++ self.wonderful_spam.replace('\t\n', '\n')) ++ + class RawConfigParserTestCase(TestCaseBase): + config_class = ConfigParser.RawConfigParser + +@@ -493,6 +530,33 @@ + allow_no_value = True + + ++class Issue7005TestCase(unittest.TestCase): ++ """Test output when None is set() as a value and allow_no_value == False. ++ ++ http://bugs.python.org/issue7005 ++ ++ """ ++ ++ expected_output = "[section]\noption = None\n\n" ++ ++ def prepare(self, config_class): ++ # This is the default, but that's the point. ++ cp = config_class(allow_no_value=False) ++ cp.add_section("section") ++ cp.set("section", "option", None) ++ sio = StringIO.StringIO() ++ cp.write(sio) ++ return sio.getvalue() ++ ++ def test_none_as_value_stringified(self): ++ output = self.prepare(ConfigParser.ConfigParser) ++ self.assertEqual(output, self.expected_output) ++ ++ def test_none_as_value_stringified_raw(self): ++ output = self.prepare(ConfigParser.RawConfigParser) ++ self.assertEqual(output, self.expected_output) ++ ++ + class SortedTestCase(RawConfigParserTestCase): + def newconfig(self, defaults=None): + self.cf = self.config_class(defaults=defaults, dict_type=SortedDict) +@@ -521,10 +585,12 @@ + def test_main(): + test_support.run_unittest( + ConfigParserTestCase, ++ MultilineValuesTestCase, + RawConfigParserTestCase, + SafeConfigParserTestCase, ++ SafeConfigParserTestCaseNoValue, + SortedTestCase, +- SafeConfigParserTestCaseNoValue, ++ Issue7005TestCase, + ) + + +--- a/Lib/test/test_signal.py ++++ b/Lib/test/test_signal.py +@@ -9,9 +9,8 @@ + import traceback + import sys, os, time, errno + +-if sys.platform[:3] in ('win', 'os2') or sys.platform == 'riscos': +- raise unittest.SkipTest("Can't test signal on %s" % \ +- sys.platform) ++if sys.platform in ('os2', 'riscos'): ++ raise unittest.SkipTest("Can't test signal on %s" % sys.platform) + + + class HandlerBCalled(Exception): +@@ -37,6 +36,7 @@ + return None + + ++@unittest.skipIf(sys.platform == "win32", "Not valid on Windows") + class InterProcessSignalTests(unittest.TestCase): + MAX_DURATION = 20 # Entire test should last at most 20 sec. + +@@ -186,6 +186,7 @@ + self.MAX_DURATION) + + ++@unittest.skipIf(sys.platform == "win32", "Not valid on Windows") + class BasicSignalTests(unittest.TestCase): + def trivial_signal_handler(self, *args): + pass +@@ -208,6 +209,25 @@ + self.assertEquals(signal.getsignal(signal.SIGHUP), hup) + + ++@unittest.skipUnless(sys.platform == "win32", "Windows specific") ++class WindowsSignalTests(unittest.TestCase): ++ def test_issue9324(self): ++ # Updated for issue #10003, adding SIGBREAK ++ handler = lambda x, y: None ++ for sig in (signal.SIGABRT, signal.SIGBREAK, signal.SIGFPE, ++ signal.SIGILL, signal.SIGINT, signal.SIGSEGV, ++ signal.SIGTERM): ++ # Set and then reset a handler for signals that work on windows ++ signal.signal(sig, signal.signal(sig, handler)) ++ ++ with self.assertRaises(ValueError): ++ signal.signal(-1, handler) ++ ++ with self.assertRaises(ValueError): ++ signal.signal(7, handler) ++ ++ ++@unittest.skipIf(sys.platform == "win32", "Not valid on Windows") + class WakeupSignalTests(unittest.TestCase): + TIMEOUT_FULL = 10 + TIMEOUT_HALF = 5 +@@ -253,14 +273,15 @@ + os.close(self.write) + signal.signal(signal.SIGALRM, self.alrm) + ++@unittest.skipIf(sys.platform == "win32", "Not valid on Windows") + class SiginterruptTest(unittest.TestCase): +- signum = signal.SIGUSR1 + + def setUp(self): + """Install a no-op signal handler that can be set to allow + interrupts or not, and arrange for the original signal handler to be + re-installed when the test is finished. + """ ++ self.signum = signal.SIGUSR1 + oldhandler = signal.signal(self.signum, lambda x,y: None) + self.addCleanup(signal.signal, self.signum, oldhandler) + +@@ -354,7 +375,7 @@ + self.assertFalse(i) + + +- ++@unittest.skipIf(sys.platform == "win32", "Not valid on Windows") + class ItimerTest(unittest.TestCase): + def setUp(self): + self.hndl_called = False +@@ -464,7 +485,8 @@ + + def test_main(): + test_support.run_unittest(BasicSignalTests, InterProcessSignalTests, +- WakeupSignalTests, SiginterruptTest, ItimerTest) ++ WakeupSignalTests, SiginterruptTest, ++ ItimerTest, WindowsSignalTests) + + + if __name__ == "__main__": +--- a/Lib/test/test_bz2.py ++++ b/Lib/test/test_bz2.py +@@ -54,68 +54,68 @@ + os.unlink(self.filename) + + def createTempFile(self, crlf=0): +- f = open(self.filename, "wb") +- if crlf: +- data = self.DATA_CRLF +- else: +- data = self.DATA +- f.write(data) +- f.close() ++ with open(self.filename, "wb") as f: ++ if crlf: ++ data = self.DATA_CRLF ++ else: ++ data = self.DATA ++ f.write(data) + + def testRead(self): + # "Test BZ2File.read()" + self.createTempFile() +- bz2f = BZ2File(self.filename) +- self.assertRaises(TypeError, bz2f.read, None) +- self.assertEqual(bz2f.read(), self.TEXT) +- bz2f.close() ++ with BZ2File(self.filename) as bz2f: ++ self.assertRaises(TypeError, bz2f.read, None) ++ self.assertEqual(bz2f.read(), self.TEXT) + ++ def testRead0(self): ++ # Test BBZ2File.read(0)" ++ self.createTempFile() ++ with BZ2File(self.filename) as bz2f: ++ self.assertRaises(TypeError, bz2f.read, None) ++ self.assertEqual(bz2f.read(0), "") ++ + def testReadChunk10(self): + # "Test BZ2File.read() in chunks of 10 bytes" + self.createTempFile() +- bz2f = BZ2File(self.filename) +- text = '' +- while 1: +- str = bz2f.read(10) +- if not str: +- break +- text += str +- self.assertEqual(text, text) +- bz2f.close() ++ with BZ2File(self.filename) as bz2f: ++ text = '' ++ while 1: ++ str = bz2f.read(10) ++ if not str: ++ break ++ text += str ++ self.assertEqual(text, text) + + def testRead100(self): + # "Test BZ2File.read(100)" + self.createTempFile() +- bz2f = BZ2File(self.filename) +- self.assertEqual(bz2f.read(100), self.TEXT[:100]) +- bz2f.close() ++ with BZ2File(self.filename) as bz2f: ++ self.assertEqual(bz2f.read(100), self.TEXT[:100]) + + def testReadLine(self): + # "Test BZ2File.readline()" + self.createTempFile() +- bz2f = BZ2File(self.filename) +- self.assertRaises(TypeError, bz2f.readline, None) +- sio = StringIO(self.TEXT) +- for line in sio.readlines(): +- self.assertEqual(bz2f.readline(), line) +- bz2f.close() ++ with BZ2File(self.filename) as bz2f: ++ self.assertRaises(TypeError, bz2f.readline, None) ++ sio = StringIO(self.TEXT) ++ for line in sio.readlines(): ++ self.assertEqual(bz2f.readline(), line) + + def testReadLines(self): + # "Test BZ2File.readlines()" + self.createTempFile() +- bz2f = BZ2File(self.filename) +- self.assertRaises(TypeError, bz2f.readlines, None) +- sio = StringIO(self.TEXT) +- self.assertEqual(bz2f.readlines(), sio.readlines()) +- bz2f.close() ++ with BZ2File(self.filename) as bz2f: ++ self.assertRaises(TypeError, bz2f.readlines, None) ++ sio = StringIO(self.TEXT) ++ self.assertEqual(bz2f.readlines(), sio.readlines()) + + def testIterator(self): + # "Test iter(BZ2File)" + self.createTempFile() +- bz2f = BZ2File(self.filename) +- sio = StringIO(self.TEXT) +- self.assertEqual(list(iter(bz2f)), sio.readlines()) +- bz2f.close() ++ with BZ2File(self.filename) as bz2f: ++ sio = StringIO(self.TEXT) ++ self.assertEqual(list(iter(bz2f)), sio.readlines()) + + def testClosedIteratorDeadlock(self): + # "Test that iteration on a closed bz2file releases the lock." +@@ -154,104 +154,91 @@ + + def testWrite(self): + # "Test BZ2File.write()" +- bz2f = BZ2File(self.filename, "w") +- self.assertRaises(TypeError, bz2f.write) +- bz2f.write(self.TEXT) +- bz2f.close() +- f = open(self.filename, 'rb') +- self.assertEqual(self.decompress(f.read()), self.TEXT) +- f.close() ++ with BZ2File(self.filename, "w") as bz2f: ++ self.assertRaises(TypeError, bz2f.write) ++ bz2f.write(self.TEXT) ++ with open(self.filename, 'rb') as f: ++ self.assertEqual(self.decompress(f.read()), self.TEXT) + + def testWriteChunks10(self): + # "Test BZ2File.write() with chunks of 10 bytes" +- bz2f = BZ2File(self.filename, "w") +- n = 0 +- while 1: +- str = self.TEXT[n*10:(n+1)*10] +- if not str: +- break +- bz2f.write(str) +- n += 1 +- bz2f.close() +- f = open(self.filename, 'rb') +- self.assertEqual(self.decompress(f.read()), self.TEXT) +- f.close() ++ with BZ2File(self.filename, "w") as bz2f: ++ n = 0 ++ while 1: ++ str = self.TEXT[n*10:(n+1)*10] ++ if not str: ++ break ++ bz2f.write(str) ++ n += 1 ++ with open(self.filename, 'rb') as f: ++ self.assertEqual(self.decompress(f.read()), self.TEXT) + + def testWriteLines(self): + # "Test BZ2File.writelines()" +- bz2f = BZ2File(self.filename, "w") +- self.assertRaises(TypeError, bz2f.writelines) +- sio = StringIO(self.TEXT) +- bz2f.writelines(sio.readlines()) +- bz2f.close() ++ with BZ2File(self.filename, "w") as bz2f: ++ self.assertRaises(TypeError, bz2f.writelines) ++ sio = StringIO(self.TEXT) ++ bz2f.writelines(sio.readlines()) + # patch #1535500 + self.assertRaises(ValueError, bz2f.writelines, ["a"]) +- f = open(self.filename, 'rb') +- self.assertEqual(self.decompress(f.read()), self.TEXT) +- f.close() ++ with open(self.filename, 'rb') as f: ++ self.assertEqual(self.decompress(f.read()), self.TEXT) + + def testWriteMethodsOnReadOnlyFile(self): +- bz2f = BZ2File(self.filename, "w") +- bz2f.write("abc") +- bz2f.close() ++ with BZ2File(self.filename, "w") as bz2f: ++ bz2f.write("abc") + +- bz2f = BZ2File(self.filename, "r") +- self.assertRaises(IOError, bz2f.write, "a") +- self.assertRaises(IOError, bz2f.writelines, ["a"]) ++ with BZ2File(self.filename, "r") as bz2f: ++ self.assertRaises(IOError, bz2f.write, "a") ++ self.assertRaises(IOError, bz2f.writelines, ["a"]) + + def testSeekForward(self): + # "Test BZ2File.seek(150, 0)" + self.createTempFile() +- bz2f = BZ2File(self.filename) +- self.assertRaises(TypeError, bz2f.seek) +- bz2f.seek(150) +- self.assertEqual(bz2f.read(), self.TEXT[150:]) +- bz2f.close() ++ with BZ2File(self.filename) as bz2f: ++ self.assertRaises(TypeError, bz2f.seek) ++ bz2f.seek(150) ++ self.assertEqual(bz2f.read(), self.TEXT[150:]) + + def testSeekBackwards(self): + # "Test BZ2File.seek(-150, 1)" + self.createTempFile() +- bz2f = BZ2File(self.filename) +- bz2f.read(500) +- bz2f.seek(-150, 1) +- self.assertEqual(bz2f.read(), self.TEXT[500-150:]) +- bz2f.close() ++ with BZ2File(self.filename) as bz2f: ++ bz2f.read(500) ++ bz2f.seek(-150, 1) ++ self.assertEqual(bz2f.read(), self.TEXT[500-150:]) + + def testSeekBackwardsFromEnd(self): + # "Test BZ2File.seek(-150, 2)" + self.createTempFile() +- bz2f = BZ2File(self.filename) +- bz2f.seek(-150, 2) +- self.assertEqual(bz2f.read(), self.TEXT[len(self.TEXT)-150:]) +- bz2f.close() ++ with BZ2File(self.filename) as bz2f: ++ bz2f.seek(-150, 2) ++ self.assertEqual(bz2f.read(), self.TEXT[len(self.TEXT)-150:]) + + def testSeekPostEnd(self): + # "Test BZ2File.seek(150000)" + self.createTempFile() +- bz2f = BZ2File(self.filename) +- bz2f.seek(150000) +- self.assertEqual(bz2f.tell(), len(self.TEXT)) +- self.assertEqual(bz2f.read(), "") +- bz2f.close() ++ with BZ2File(self.filename) as bz2f: ++ bz2f.seek(150000) ++ self.assertEqual(bz2f.tell(), len(self.TEXT)) ++ self.assertEqual(bz2f.read(), "") + + def testSeekPostEndTwice(self): + # "Test BZ2File.seek(150000) twice" + self.createTempFile() +- bz2f = BZ2File(self.filename) +- bz2f.seek(150000) +- bz2f.seek(150000) +- self.assertEqual(bz2f.tell(), len(self.TEXT)) +- self.assertEqual(bz2f.read(), "") +- bz2f.close() ++ with BZ2File(self.filename) as bz2f: ++ bz2f.seek(150000) ++ bz2f.seek(150000) ++ self.assertEqual(bz2f.tell(), len(self.TEXT)) ++ self.assertEqual(bz2f.read(), "") + + def testSeekPreStart(self): + # "Test BZ2File.seek(-150, 0)" + self.createTempFile() +- bz2f = BZ2File(self.filename) +- bz2f.seek(-150) +- self.assertEqual(bz2f.tell(), 0) +- self.assertEqual(bz2f.read(), self.TEXT) +- bz2f.close() ++ with BZ2File(self.filename) as bz2f: ++ bz2f.seek(-150) ++ self.assertEqual(bz2f.tell(), 0) ++ self.assertEqual(bz2f.read(), self.TEXT) + + def testOpenDel(self): + # "Test opening and deleting a file many times" +@@ -277,16 +264,13 @@ + def testBug1191043(self): + # readlines() for files containing no newline + data = 'BZh91AY&SY\xd9b\x89]\x00\x00\x00\x03\x80\x04\x00\x02\x00\x0c\x00 \x00!\x9ah3M\x13<]\xc9\x14\xe1BCe\x8a%t' +- f = open(self.filename, "wb") +- f.write(data) +- f.close() +- bz2f = BZ2File(self.filename) +- lines = bz2f.readlines() +- bz2f.close() ++ with open(self.filename, "wb") as f: ++ f.write(data) ++ with BZ2File(self.filename) as bz2f: ++ lines = bz2f.readlines() + self.assertEqual(lines, ['Test']) +- bz2f = BZ2File(self.filename) +- xlines = list(bz2f.xreadlines()) +- bz2f.close() ++ with BZ2File(self.filename) as bz2f: ++ xlines = list(bz2f.readlines()) + self.assertEqual(xlines, ['Test']) + + def testContextProtocol(self): +@@ -316,8 +300,7 @@ + # Using a BZ2File from several threads doesn't deadlock (issue #7205). + data = "1" * 2**20 + nthreads = 10 +- f = bz2.BZ2File(self.filename, 'wb') +- try: ++ with bz2.BZ2File(self.filename, 'wb') as f: + def comp(): + for i in range(5): + f.write(data) +@@ -326,9 +309,19 @@ + t.start() + for t in threads: + t.join() +- finally: +- f.close() + ++ def testMixedIterationReads(self): ++ # Issue #8397: mixed iteration and reads should be forbidden. ++ with bz2.BZ2File(self.filename, 'wb') as f: ++ # The internal buffer size is hard-wired to 8192 bytes, we must ++ # write out more than that for the test to stop half through ++ # the buffer. ++ f.write(self.TEXT * 100) ++ with bz2.BZ2File(self.filename, 'rb') as f: ++ next(f) ++ self.assertRaises(ValueError, f.read) ++ self.assertRaises(ValueError, f.readline) ++ self.assertRaises(ValueError, f.readlines) + + class BZ2CompressorTest(BaseTest): + def testCompress(self): +--- a/Lib/test/test_cookielib.py ++++ b/Lib/test/test_cookielib.py +@@ -1,11 +1,16 @@ + # -*- coding: latin-1 -*- + """Tests for cookielib.py.""" + +-import re, os, time ++import cookielib ++import os ++import re ++import time ++ + from unittest import TestCase + + from test import test_support + ++ + class DateTimeTests(TestCase): + + def test_time2isoz(self): +@@ -563,6 +568,16 @@ + interact_netscape(c, "http://www.acme.com/blah/rhubarb/", 'eggs="bar"') + self.assertIn("/blah/rhubarb", c._cookies["www.acme.com"]) + ++ def test_default_path_with_query(self): ++ cj = cookielib.CookieJar() ++ uri = "http://example.com/?spam/eggs" ++ value = 'eggs="bar"' ++ interact_netscape(cj, uri, value) ++ # default path does not include query, so is "/", not "/?spam" ++ self.assertIn("/", cj._cookies["example.com"]) ++ # cookie is sent back to the same URI ++ self.assertEquals(interact_netscape(cj, uri), value) ++ + def test_escape_path(self): + from cookielib import escape_path + cases = [ +@@ -591,15 +606,14 @@ + from urllib2 import Request + from cookielib import request_path + # with parameters +- req = Request("http://www.example.com/rheum/rhaponicum;" ++ req = Request("http://www.example.com/rheum/rhaponticum;" + "foo=bar;sing=song?apples=pears&spam=eggs#ni") +- self.assertEquals(request_path(req), "/rheum/rhaponicum;" +- "foo=bar;sing=song?apples=pears&spam=eggs#ni") ++ self.assertEquals(request_path(req), ++ "/rheum/rhaponticum;foo=bar;sing=song") + # without parameters +- req = Request("http://www.example.com/rheum/rhaponicum?" ++ req = Request("http://www.example.com/rheum/rhaponticum?" + "apples=pears&spam=eggs#ni") +- self.assertEquals(request_path(req), "/rheum/rhaponicum?" +- "apples=pears&spam=eggs#ni") ++ self.assertEquals(request_path(req), "/rheum/rhaponticum") + # missing final slash + req = Request("http://www.example.com") + self.assertEquals(request_path(req), "/") +--- a/Lib/test/leakers/test_dictself.py ++++ b/Lib/test/leakers/test_dictself.py +@@ -0,0 +1,12 @@ ++'''Test case for "self.__dict__ = self" circular reference bug (#1469629)''' ++ ++import gc ++ ++class LeakyDict(dict): ++ pass ++ ++def leak(): ++ ld = LeakyDict() ++ ld.__dict__ = ld ++ del ld ++ gc.collect(); gc.collect(); gc.collect() + +Property changes on: Lib/test/leakers/test_dictself.py +___________________________________________________________________ +Added: svn:eol-style + + native + + +Property changes on: Lib/test/leakers +___________________________________________________________________ +Modified: svn:ignore + - *.pyc + + + *.pyc +*.pyo + + +--- a/Lib/test/test_memoryview.py ++++ b/Lib/test/test_memoryview.py +@@ -117,6 +117,15 @@ + m = None + self.assertEquals(sys.getrefcount(b), oldrefcount) + ++ def test_delitem(self): ++ for tp in self._types: ++ b = tp(self._source) ++ m = self._view(b) ++ with self.assertRaises(TypeError): ++ del m[1] ++ with self.assertRaises(TypeError): ++ del m[1:4] ++ + def test_tobytes(self): + for tp in self._types: + m = self._view(tp(self._source)) +--- a/Lib/test/test_httpservers.py ++++ b/Lib/test/test_httpservers.py +@@ -11,6 +11,7 @@ + + import os + import sys ++import re + import base64 + import shutil + import urllib +@@ -18,6 +19,9 @@ + import tempfile + + import unittest ++ ++from StringIO import StringIO ++ + from test import test_support + threading = test_support.import_module('threading') + +@@ -27,7 +31,23 @@ + # don't write log messages to stderr + pass + ++class SocketlessRequestHandler(BaseHTTPRequestHandler): ++ def __init__(self): ++ self.get_called = False ++ self.protocol_version = "HTTP/1.1" + ++ def do_GET(self): ++ self.get_called = True ++ self.send_response(200) ++ self.send_header('Content-Type', 'text/html') ++ self.end_headers() ++ self.wfile.write('Data\r\n') ++ ++ def log_message(self, format, *args): ++ pass ++ ++ ++ + class TestServerThread(threading.Thread): + def __init__(self, test_object, request_handler): + threading.Thread.__init__(self) +@@ -67,7 +87,64 @@ + self.connection.request(method, uri, body, headers) + return self.connection.getresponse() + ++class BaseHTTPRequestHandlerTestCase(unittest.TestCase): ++ """Test the functionaility of the BaseHTTPServer focussing on ++ BaseHTTPRequestHandler. ++ """ + ++ HTTPResponseMatch = re.compile('HTTP/1.[0-9]+ 200 OK') ++ ++ def setUp (self): ++ self.handler = SocketlessRequestHandler() ++ ++ def send_typical_request(self, message): ++ input = StringIO(message) ++ output = StringIO() ++ self.handler.rfile = input ++ self.handler.wfile = output ++ self.handler.handle_one_request() ++ output.seek(0) ++ return output.readlines() ++ ++ def verify_get_called(self): ++ self.assertTrue(self.handler.get_called) ++ ++ def verify_expected_headers(self, headers): ++ for fieldName in 'Server: ', 'Date: ', 'Content-Type: ': ++ self.assertEqual(sum(h.startswith(fieldName) for h in headers), 1) ++ ++ def verify_http_server_response(self, response): ++ match = self.HTTPResponseMatch.search(response) ++ self.assertTrue(match is not None) ++ ++ def test_http_1_1(self): ++ result = self.send_typical_request('GET / HTTP/1.1\r\n\r\n') ++ self.verify_http_server_response(result[0]) ++ self.verify_expected_headers(result[1:-1]) ++ self.verify_get_called() ++ self.assertEqual(result[-1], 'Data\r\n') ++ ++ def test_http_1_0(self): ++ result = self.send_typical_request('GET / HTTP/1.0\r\n\r\n') ++ self.verify_http_server_response(result[0]) ++ self.verify_expected_headers(result[1:-1]) ++ self.verify_get_called() ++ self.assertEqual(result[-1], 'Data\r\n') ++ ++ def test_http_0_9(self): ++ result = self.send_typical_request('GET / HTTP/0.9\r\n\r\n') ++ self.assertEqual(len(result), 1) ++ self.assertEqual(result[0], 'Data\r\n') ++ self.verify_get_called() ++ ++ def test_with_continue_1_0(self): ++ result = self.send_typical_request('GET / HTTP/1.0\r\nExpect: 100-continue\r\n\r\n') ++ self.verify_http_server_response(result[0]) ++ self.verify_expected_headers(result[1:-1]) ++ self.verify_get_called() ++ self.assertEqual(result[-1], 'Data\r\n') ++ ++ + class BaseHTTPServerTestCase(BaseTestCase): + class request_handler(NoLogRequestHandler, BaseHTTPRequestHandler): + protocol_version = 'HTTP/1.1' +@@ -398,14 +475,22 @@ + self.assertEqual(('Hello World\n', 'text/html', 200), + (res.read(), res.getheader('Content-type'), res.status)) + ++ def test_os_environ_is_not_altered(self): ++ signature = "Test CGI Server" ++ os.environ['SERVER_SOFTWARE'] = signature ++ res = self.request('/cgi-bin/file1.py') ++ self.assertEqual((b'Hello World\n', 'text/html', 200), ++ (res.read(), res.getheader('Content-type'), res.status)) ++ self.assertEqual(os.environ['SERVER_SOFTWARE'], signature) + + def test_main(verbose=None): + try: + cwd = os.getcwd() +- test_support.run_unittest(BaseHTTPServerTestCase, +- SimpleHTTPServerTestCase, +- CGIHTTPServerTestCase +- ) ++ test_support.run_unittest(BaseHTTPRequestHandlerTestCase, ++ BaseHTTPServerTestCase, ++ SimpleHTTPServerTestCase, ++ CGIHTTPServerTestCase ++ ) + finally: + os.chdir(cwd) + +--- a/Lib/test/test_fileio.py ++++ b/Lib/test/test_fileio.py +@@ -312,6 +312,9 @@ + def testInvalidFd(self): + self.assertRaises(ValueError, _FileIO, -10) + self.assertRaises(OSError, _FileIO, make_bad_fd()) ++ if sys.platform == 'win32': ++ import msvcrt ++ self.assertRaises(IOError, msvcrt.get_osfhandle, make_bad_fd()) + + def testBadModeArgument(self): + # verify that we get a sensible error message for bad mode argument +--- a/Lib/test/test_fnmatch.py ++++ b/Lib/test/test_fnmatch.py +@@ -3,10 +3,15 @@ + from test import test_support + import unittest + +-from fnmatch import fnmatch, fnmatchcase ++from fnmatch import fnmatch, fnmatchcase, _MAXCACHE, _cache ++from fnmatch import fnmatch, fnmatchcase, _MAXCACHE, _cache, _purge + + + class FnmatchTestCase(unittest.TestCase): ++ ++ def tearDown(self): ++ _purge() ++ + def check_match(self, filename, pattern, should_match=1, fn=fnmatch): + if should_match: + self.assertTrue(fn(filename, pattern), +@@ -49,7 +54,16 @@ + check('AbC', 'abc', 0, fnmatchcase) + check('abc', 'AbC', 0, fnmatchcase) + ++ def test_cache_clearing(self): ++ # check that caches do not grow too large ++ # http://bugs.python.org/issue7846 + ++ # string pattern cache ++ for i in range(_MAXCACHE + 1): ++ fnmatch('foo', '?' * i) ++ ++ self.assertLessEqual(len(_cache), _MAXCACHE) ++ + def test_main(): + test_support.run_unittest(FnmatchTestCase) + +--- a/Lib/test/test_pipes.py ++++ b/Lib/test/test_pipes.py +@@ -23,17 +23,21 @@ + f = t.open(TESTFN, 'w') + f.write('hello world #1') + f.close() +- self.assertEqual(open(TESTFN).read(), 'HELLO WORLD #1') ++ with open(TESTFN) as f: ++ self.assertEqual(f.read(), 'HELLO WORLD #1') + + def testSimplePipe2(self): +- file(TESTFN, 'w').write('hello world #2') ++ with open(TESTFN, 'w') as f: ++ f.write('hello world #2') + t = pipes.Template() + t.append(s_command + ' < $IN > $OUT', pipes.FILEIN_FILEOUT) + t.copy(TESTFN, TESTFN2) +- self.assertEqual(open(TESTFN2).read(), 'HELLO WORLD #2') ++ with open(TESTFN2) as f: ++ self.assertEqual(f.read(), 'HELLO WORLD #2') + + def testSimplePipe3(self): +- file(TESTFN, 'w').write('hello world #2') ++ with open(TESTFN, 'w') as f: ++ f.write('hello world #2') + t = pipes.Template() + t.append(s_command + ' < $IN', pipes.FILEIN_STDOUT) + with t.open(TESTFN, 'r') as f: +@@ -42,16 +46,20 @@ + def testEmptyPipeline1(self): + # copy through empty pipe + d = 'empty pipeline test COPY' +- file(TESTFN, 'w').write(d) +- file(TESTFN2, 'w').write('') ++ with open(TESTFN, 'w') as f: ++ f.write(d) ++ with open(TESTFN2, 'w') as f: ++ f.write('') + t=pipes.Template() + t.copy(TESTFN, TESTFN2) +- self.assertEqual(open(TESTFN2).read(), d) ++ with open(TESTFN2) as f: ++ self.assertEqual(f.read(), d) + + def testEmptyPipeline2(self): + # read through empty pipe + d = 'empty pipeline test READ' +- file(TESTFN, 'w').write(d) ++ with open(TESTFN, 'w') as f: ++ f.write(d) + t=pipes.Template() + with t.open(TESTFN, 'r') as f: + self.assertEqual(f.read(), d) +@@ -60,8 +68,10 @@ + # write through empty pipe + d = 'empty pipeline test WRITE' + t = pipes.Template() +- t.open(TESTFN, 'w').write(d) +- self.assertEqual(open(TESTFN).read(), d) ++ with t.open(TESTFN, 'w') as f: ++ f.write(d) ++ with open(TESTFN) as f: ++ self.assertEqual(f.read(), d) + + def testQuoting(self): + safeunquoted = string.ascii_letters + string.digits + '@%_-+=:,./' +--- a/Lib/test/test_module.py ++++ b/Lib/test/test_module.py +@@ -1,6 +1,6 @@ + # Test the module type + import unittest +-from test.test_support import run_unittest ++from test.test_support import run_unittest, gc_collect + + import sys + ModuleType = type(sys) +@@ -55,14 +55,29 @@ + {"__name__": "foo", "__doc__": "foodoc", "bar": 42}) + self.assertTrue(foo.__dict__ is d) + ++ @unittest.expectedFailure + def test_dont_clear_dict(self): + # See issue 7140. + def f(): + foo = ModuleType("foo") + foo.bar = 4 + return foo ++ gc_collect() + self.assertEqual(f().__dict__["bar"], 4) + ++ def test_clear_dict_in_ref_cycle(self): ++ destroyed = [] ++ m = ModuleType("foo") ++ m.destroyed = destroyed ++ s = """class A: ++ def __del__(self): ++ destroyed.append(1) ++a = A()""" ++ exec(s, m.__dict__) ++ del m ++ gc_collect() ++ self.assertEqual(destroyed, [1]) ++ + def test_main(): + run_unittest(ModuleTests) + +--- a/Lib/test/test_unicode_file.py ++++ b/Lib/test/test_unicode_file.py +@@ -6,7 +6,7 @@ + + import unittest + from test.test_support import run_unittest, TESTFN_UNICODE +-from test.test_support import TESTFN_ENCODING, TESTFN_UNICODE_UNENCODEABLE ++from test.test_support import TESTFN_ENCODING, TESTFN_UNENCODABLE + try: + TESTFN_ENCODED = TESTFN_UNICODE.encode(TESTFN_ENCODING) + except (UnicodeError, TypeError): +@@ -171,8 +171,8 @@ + def test_single_files(self): + self._test_single(TESTFN_ENCODED) + self._test_single(TESTFN_UNICODE) +- if TESTFN_UNICODE_UNENCODEABLE is not None: +- self._test_single(TESTFN_UNICODE_UNENCODEABLE) ++ if TESTFN_UNENCODABLE is not None: ++ self._test_single(TESTFN_UNENCODABLE) + + def test_equivalent_files(self): + self._test_equivalent(TESTFN_ENCODED, TESTFN_UNICODE) +@@ -188,9 +188,9 @@ + self._do_directory(TESTFN_UNICODE+ext, TESTFN_ENCODED+ext, False) + self._do_directory(TESTFN_UNICODE+ext, TESTFN_UNICODE+ext, False) + # Our directory name that can't use a non-unicode name. +- if TESTFN_UNICODE_UNENCODEABLE is not None: +- self._do_directory(TESTFN_UNICODE_UNENCODEABLE+ext, +- TESTFN_UNICODE_UNENCODEABLE+ext, ++ if TESTFN_UNENCODABLE is not None: ++ self._do_directory(TESTFN_UNENCODABLE+ext, ++ TESTFN_UNENCODABLE+ext, + False) + + def test_main(): +--- a/Lib/test/test_hotshot.py ++++ b/Lib/test/test_hotshot.py +@@ -10,6 +10,7 @@ + # Silence Py3k warning + hotshot = test_support.import_module('hotshot', deprecated=True) + from hotshot.log import ENTER, EXIT, LINE ++from hotshot import stats + + + def shortfilename(fn): +@@ -136,6 +137,19 @@ + emptyfile.close() + gc.collect() + ++ def test_load_stats(self): ++ def start(prof): ++ prof.start() ++ # Make sure stats can be loaded when start and stop of profiler ++ # are not executed in the same stack frame. ++ profiler = self.new_profiler() ++ start(profiler) ++ profiler.stop() ++ profiler.close() ++ stats.load(self.logfn) ++ os.unlink(self.logfn) ++ ++ + def test_main(): + test_support.run_unittest(HotShotTestCase) + +--- a/Lib/test/test_gdb.py ++++ b/Lib/test/test_gdb.py +@@ -8,6 +8,7 @@ + import subprocess + import sys + import unittest ++import sysconfig + + from test.test_support import run_unittest, findfile + +@@ -678,6 +679,15 @@ + r".*\na = 1\nb = 2\nc = 3\n.*") + + def test_main(): ++ cflags = sysconfig.get_config_vars()['PY_CFLAGS'] ++ final_opt = "" ++ for opt in cflags.split(): ++ if opt.startswith('-O'): ++ final_opt = opt ++ if final_opt and final_opt != '-O0': ++ raise unittest.SkipTest("Python was built with compiler optimizations, " ++ "tests can't reliably succeed") ++ + run_unittest(PrettyPrintTests, + PyListTests, + StackNavigationTests, +--- a/Lib/test/test_decimal.py ++++ b/Lib/test/test_decimal.py +@@ -77,11 +77,42 @@ + + # list of individual .decTest test ids that correspond to tests that + # we're skipping for one reason or another. +-skipped_test_ids = [ +- 'scbx164', # skipping apparently implementation-specific scaleb +- 'scbx165', # tests, pending clarification of scaleb rules. +-] ++skipped_test_ids = set([ ++ # Skip implementation-specific scaleb tests. ++ 'scbx164', ++ 'scbx165', + ++ # For some operations (currently exp, ln, log10, power), the decNumber ++ # reference implementation imposes additional restrictions on the context ++ # and operands. These restrictions are not part of the specification; ++ # however, the effect of these restrictions does show up in some of the ++ # testcases. We skip testcases that violate these restrictions, since ++ # Decimal behaves differently from decNumber for these testcases so these ++ # testcases would otherwise fail. ++ 'expx901', ++ 'expx902', ++ 'expx903', ++ 'expx905', ++ 'lnx901', ++ 'lnx902', ++ 'lnx903', ++ 'lnx905', ++ 'logx901', ++ 'logx902', ++ 'logx903', ++ 'logx905', ++ 'powx1183', ++ 'powx1184', ++ 'powx4001', ++ 'powx4002', ++ 'powx4003', ++ 'powx4005', ++ 'powx4008', ++ 'powx4010', ++ 'powx4012', ++ 'powx4014', ++ ]) ++ + # Make sure it actually raises errors when not expected and caught in flags + # Slower, since it runs some things several times. + EXTENDEDERRORTEST = False +@@ -171,27 +202,6 @@ + 'same_quantum', + ) + +-# For some operations (currently exp, ln, log10, power), the decNumber +-# reference implementation imposes additional restrictions on the +-# context and operands. These restrictions are not part of the +-# specification; however, the effect of these restrictions does show +-# up in some of the testcases. We skip testcases that violate these +-# restrictions, since Decimal behaves differently from decNumber for +-# these testcases so these testcases would otherwise fail. +- +-decNumberRestricted = ('power', 'ln', 'log10', 'exp') +-DEC_MAX_MATH = 999999 +-def outside_decNumber_bounds(v, context): +- if (context.prec > DEC_MAX_MATH or +- context.Emax > DEC_MAX_MATH or +- -context.Emin > DEC_MAX_MATH): +- return True +- if not v._is_special and v and ( +- v.adjusted() > DEC_MAX_MATH or +- v.adjusted() < 1-2*DEC_MAX_MATH): +- return True +- return False +- + class DecimalTest(unittest.TestCase): + """Class which tests the Decimal class against the test cases. + +@@ -214,14 +224,15 @@ + if skip_expected: + raise unittest.SkipTest + return +- for line in open(file): +- line = line.replace('\r\n', '').replace('\n', '') +- #print line +- try: +- t = self.eval_line(line) +- except DecimalException, exception: +- #Exception raised where there shoudn't have been one. +- self.fail('Exception "'+exception.__class__.__name__ + '" raised on line '+line) ++ with open(file) as f: ++ for line in f: ++ line = line.replace('\r\n', '').replace('\n', '') ++ #print line ++ try: ++ t = self.eval_line(line) ++ except DecimalException as exception: ++ #Exception raised where there shoudn't have been one. ++ self.fail('Exception "'+exception.__class__.__name__ + '" raised on line '+line) + + return + +@@ -329,22 +340,6 @@ + + ans = FixQuotes(ans) + +- # skip tests that are related to bounds imposed in the decNumber +- # reference implementation +- if fname in decNumberRestricted: +- if fname == 'power': +- if not (vals[1]._isinteger() and +- -1999999997 <= vals[1] <= 999999999): +- if outside_decNumber_bounds(vals[0], self.context) or \ +- outside_decNumber_bounds(vals[1], self.context): +- #print "Skipping test %s" % s +- return +- else: +- if outside_decNumber_bounds(vals[0], self.context): +- #print "Skipping test %s" % s +- return +- +- + if EXTENDEDERRORTEST and fname not in ('to_sci_string', 'to_eng_string'): + for error in theirexceptions: + self.context.traps[error] = 1 +--- a/Lib/test/test_xpickle.py ++++ b/Lib/test/test_xpickle.py +@@ -57,7 +57,8 @@ + return cPickle.loads(buf) + + def have_python_version(name): +- """Check whether the given name is a valid Python binary. ++ """Check whether the given name is a valid Python binary and has ++ test.test_support. + + This respects your PATH. + +@@ -67,7 +68,7 @@ + Returns: + True if the name is valid, False otherwise. + """ +- return os.system(name + " -c 'import sys; sys.exit()'") == 0 ++ return os.system(name + " -c 'import test.test_support'") == 0 + + + class AbstractCompatTests(AbstractPickleTests): +--- a/Lib/test/test_multibytecodec.py ++++ b/Lib/test/test_multibytecodec.py +@@ -46,12 +46,9 @@ + 'apple\x92ham\x93spam', 'test.cjktest') + + def test_codingspec(self): +- try: +- for enc in ALL_CJKENCODINGS: +- print >> open(TESTFN, 'w'), '# coding:', enc +- exec open(TESTFN) +- finally: +- os.unlink(TESTFN) ++ for enc in ALL_CJKENCODINGS: ++ code = '# coding: {}\n'.format(enc) ++ exec code + + def test_init_segfault(self): + # bug #3305: this used to segfault +--- a/Lib/test/test_ftplib.py ++++ b/Lib/test/test_ftplib.py +@@ -99,7 +99,7 @@ + addr = map(int, arg.split(',')) + ip = '%d.%d.%d.%d' %tuple(addr[:4]) + port = (addr[4] * 256) + addr[5] +- s = socket.create_connection((ip, port), timeout=2) ++ s = socket.create_connection((ip, port), timeout=10) + self.dtp = self.dtp_handler(s, baseclass=self) + self.push('200 active data connection established') + +@@ -107,7 +107,7 @@ + sock = socket.socket() + sock.bind((self.socket.getsockname()[0], 0)) + sock.listen(5) +- sock.settimeout(2) ++ sock.settimeout(10) + ip, port = sock.getsockname()[:2] + ip = ip.replace('.', ',') + p1, p2 = divmod(port, 256) +@@ -118,7 +118,7 @@ + def cmd_eprt(self, arg): + af, ip, port = arg.split(arg[0])[1:-1] + port = int(port) +- s = socket.create_connection((ip, port), timeout=2) ++ s = socket.create_connection((ip, port), timeout=10) + self.dtp = self.dtp_handler(s, baseclass=self) + self.push('200 active data connection established') + +@@ -126,7 +126,7 @@ + sock = socket.socket(socket.AF_INET6) + sock.bind((self.socket.getsockname()[0], 0)) + sock.listen(5) +- sock.settimeout(2) ++ sock.settimeout(10) + port = sock.getsockname()[1] + self.push('229 entering extended passive mode (|||%d|)' %port) + conn, addr = sock.accept() +@@ -403,7 +403,7 @@ + def setUp(self): + self.server = DummyFTPServer((HOST, 0)) + self.server.start() +- self.client = ftplib.FTP(timeout=2) ++ self.client = ftplib.FTP(timeout=10) + self.client.connect(self.server.host, self.server.port) + + def tearDown(self): +@@ -545,7 +545,7 @@ + + def test_makepasv(self): + host, port = self.client.makepasv() +- conn = socket.create_connection((host, port), 2) ++ conn = socket.create_connection((host, port), 10) + conn.close() + # IPv4 is in use, just make sure send_epsv has not been used + self.assertEqual(self.server.handler.last_received_cmd, 'pasv') +@@ -572,7 +572,7 @@ + + def test_makepasv(self): + host, port = self.client.makepasv() +- conn = socket.create_connection((host, port), 2) ++ conn = socket.create_connection((host, port), 10) + conn.close() + self.assertEqual(self.server.handler.last_received_cmd, 'epsv') + +@@ -595,7 +595,7 @@ + def setUp(self): + self.server = DummyTLS_FTPServer((HOST, 0)) + self.server.start() +- self.client = ftplib.FTP_TLS(timeout=2) ++ self.client = ftplib.FTP_TLS(timeout=10) + self.client.connect(self.server.host, self.server.port) + # enable TLS + self.client.auth() +@@ -608,7 +608,7 @@ + def setUp(self): + self.server = DummyTLS_FTPServer((HOST, 0)) + self.server.start() +- self.client = ftplib.FTP_TLS(timeout=2) ++ self.client = ftplib.FTP_TLS(timeout=10) + self.client.connect(self.server.host, self.server.port) + + def tearDown(self): +--- a/Lib/test/test_random.py ++++ b/Lib/test/test_random.py +@@ -55,8 +55,6 @@ + + with test_support.check_py3k_warnings(quiet=True): + self.assertRaises(TypeError, self.gen.jumpahead) # needs an arg +- self.assertRaises(TypeError, self.gen.jumpahead, "ick") # wrong type +- self.assertRaises(TypeError, self.gen.jumpahead, 2.3) # wrong type + self.assertRaises(TypeError, self.gen.jumpahead, 2, 3) # too many + + def test_sample(self): +--- a/Lib/test/test_struct.py ++++ b/Lib/test/test_struct.py +@@ -62,8 +62,8 @@ + + self.assertRaises(struct.error, struct.pack, 'iii', 3) + self.assertRaises(struct.error, struct.pack, 'i', 3, 3, 3) +- self.assertRaises(struct.error, struct.pack, 'i', 'foo') +- self.assertRaises(struct.error, struct.pack, 'P', 'foo') ++ self.assertRaises((TypeError, struct.error), struct.pack, 'i', 'foo') ++ self.assertRaises((TypeError, struct.error), struct.pack, 'P', 'foo') + self.assertRaises(struct.error, struct.unpack, 'd', 'flap') + s = struct.pack('ii', 1, 2) + self.assertRaises(struct.error, struct.unpack, 'iii', s) +@@ -243,7 +243,8 @@ + '\x01' + got) + else: + # x is out of range -- verify pack realizes that. +- self.assertRaises(struct.error, pack, format, x) ++ self.assertRaises((OverflowError, ValueError, struct.error), ++ pack, format, x) + + def run(self): + from random import randrange +@@ -316,9 +317,8 @@ + randrange) + with check_warnings(("integer argument expected, " + "got non-integer", DeprecationWarning)): +- self.assertRaises((TypeError, struct.error), +- struct.pack, self.format, +- 3+42j) ++ with self.assertRaises((TypeError, struct.error)): ++ struct.pack(self.format, 3+42j) + + # an attempt to convert a non-integer (with an + # implicit conversion via __int__) should succeed, +@@ -450,12 +450,15 @@ + + # Go beyond boundaries. + small_buf = array.array('c', ' '*10) +- self.assertRaises(struct.error, s.pack_into, small_buf, 0, test_string) +- self.assertRaises(struct.error, s.pack_into, small_buf, 2, test_string) ++ self.assertRaises((ValueError, struct.error), s.pack_into, small_buf, 0, ++ test_string) ++ self.assertRaises((ValueError, struct.error), s.pack_into, small_buf, 2, ++ test_string) + + # Test bogus offset (issue 3694) + sb = small_buf +- self.assertRaises(TypeError, struct.pack_into, b'1', sb, None) ++ self.assertRaises((TypeError, struct.error), struct.pack_into, b'', sb, ++ None) + + def test_pack_into_fn(self): + test_string = 'Reykjavik rocks, eow!' +@@ -475,8 +478,10 @@ + + # Go beyond boundaries. + small_buf = array.array('c', ' '*10) +- self.assertRaises(struct.error, pack_into, small_buf, 0, test_string) +- self.assertRaises(struct.error, pack_into, small_buf, 2, test_string) ++ self.assertRaises((ValueError, struct.error), pack_into, small_buf, 0, ++ test_string) ++ self.assertRaises((ValueError, struct.error), pack_into, small_buf, 2, ++ test_string) + + def test_unpack_with_buffer(self): + with check_py3k_warnings(("buffer.. not supported in 3.x", +@@ -491,6 +496,9 @@ + self.test_unpack_from(cls=buffer) + + def test_bool(self): ++ class ExplodingBool(object): ++ def __nonzero__(self): ++ raise IOError + for prefix in tuple("<>!=")+('',): + false = (), [], [], '', 0 + true = [1], 'test', 5, -1, 0xffffffffL+1, 0xffffffff//2 +@@ -519,9 +527,12 @@ + self.assertFalse(prefix, msg='encoded bool is not one byte: %r' + %packed) + +- for c in '\x01\x7f\xff\x0f\xf0': +- self.assertTrue(struct.unpack('>?', c)[0]) ++ self.assertRaises(IOError, struct.pack, prefix + '?', ++ ExplodingBool()) + ++ for c in [b'\x01', b'\x7f', b'\xff', b'\x0f', b'\xf0']: ++ self.assertTrue(struct.unpack('>?', c)[0]) ++ + @unittest.skipUnless(IS32BIT, "Specific to 32bit machines") + def test_crasher(self): + self.assertRaises(MemoryError, struct.pack, "357913941c", "a") +--- a/Lib/test/test_rlcompleter.py ++++ b/Lib/test/test_rlcompleter.py +@@ -0,0 +1,73 @@ ++from test import test_support as support ++import unittest ++import __builtin__ as builtins ++import rlcompleter ++ ++class CompleteMe(object): ++ """ Trivial class used in testing rlcompleter.Completer. """ ++ spam = 1 ++ ++ ++class TestRlcompleter(unittest.TestCase): ++ def setUp(self): ++ self.stdcompleter = rlcompleter.Completer() ++ self.completer = rlcompleter.Completer(dict(spam=int, ++ egg=str, ++ CompleteMe=CompleteMe)) ++ ++ # forces stdcompleter to bind builtins namespace ++ self.stdcompleter.complete('', 0) ++ ++ def test_namespace(self): ++ class A(dict): ++ pass ++ class B(list): ++ pass ++ ++ self.assertTrue(self.stdcompleter.use_main_ns) ++ self.assertFalse(self.completer.use_main_ns) ++ self.assertFalse(rlcompleter.Completer(A()).use_main_ns) ++ self.assertRaises(TypeError, rlcompleter.Completer, B((1,))) ++ ++ def test_global_matches(self): ++ # test with builtins namespace ++ self.assertEqual(self.stdcompleter.global_matches('di'), ++ [x+'(' for x in dir(builtins) if x.startswith('di')]) ++ self.assertEqual(self.stdcompleter.global_matches('st'), ++ [x+'(' for x in dir(builtins) if x.startswith('st')]) ++ self.assertEqual(self.stdcompleter.global_matches('akaksajadhak'), []) ++ ++ # test with a customized namespace ++ self.assertEqual(self.completer.global_matches('CompleteM'), ++ ['CompleteMe(']) ++ self.assertEqual(self.completer.global_matches('eg'), ++ ['egg(']) ++ # XXX: see issue5256 ++ self.assertEqual(self.completer.global_matches('CompleteM'), ++ ['CompleteMe(']) ++ ++ def test_attr_matches(self): ++ # test with builtins namespace ++ self.assertEqual(self.stdcompleter.attr_matches('str.s'), ++ ['str.{}('.format(x) for x in dir(str) ++ if x.startswith('s')]) ++ self.assertEqual(self.stdcompleter.attr_matches('tuple.foospamegg'), []) ++ ++ # test with a customized namespace ++ self.assertEqual(self.completer.attr_matches('CompleteMe.sp'), ++ ['CompleteMe.spam']) ++ self.assertEqual(self.completer.attr_matches('Completeme.egg'), []) ++ ++ CompleteMe.me = CompleteMe ++ self.assertEqual(self.completer.attr_matches('CompleteMe.me.me.sp'), ++ ['CompleteMe.me.me.spam']) ++ self.assertEqual(self.completer.attr_matches('egg.s'), ++ ['egg.{}('.format(x) for x in dir(str) ++ if x.startswith('s')]) ++ ++def test_main(): ++ support.run_unittest(TestRlcompleter) ++ ++ ++if __name__ == '__main__': ++ test_main() +--- a/Lib/test/test_subprocess.py ++++ b/Lib/test/test_subprocess.py +@@ -454,21 +454,41 @@ + + def test_no_leaking(self): + # Make sure we leak no resources +- if not hasattr(test_support, "is_resource_enabled") \ +- or test_support.is_resource_enabled("subprocess") and not mswindows: ++ if not mswindows: + max_handles = 1026 # too much for most UNIX systems + else: +- max_handles = 65 +- for i in range(max_handles): +- p = subprocess.Popen([sys.executable, "-c", +- "import sys;sys.stdout.write(sys.stdin.read())"], +- stdin=subprocess.PIPE, +- stdout=subprocess.PIPE, +- stderr=subprocess.PIPE) +- data = p.communicate("lime")[0] +- self.assertEqual(data, "lime") ++ max_handles = 2050 # too much for (at least some) Windows setups ++ handles = [] ++ try: ++ for i in range(max_handles): ++ try: ++ handles.append(os.open(test_support.TESTFN, ++ os.O_WRONLY | os.O_CREAT)) ++ except OSError as e: ++ if e.errno != errno.EMFILE: ++ raise ++ break ++ else: ++ self.skipTest("failed to reach the file descriptor limit " ++ "(tried %d)" % max_handles) ++ # Close a couple of them (should be enough for a subprocess) ++ for i in range(10): ++ os.close(handles.pop()) ++ # Loop creating some subprocesses. If one of them leaks some fds, ++ # the next loop iteration will fail by reaching the max fd limit. ++ for i in range(15): ++ p = subprocess.Popen([sys.executable, "-c", ++ "import sys;" ++ "sys.stdout.write(sys.stdin.read())"], ++ stdin=subprocess.PIPE, ++ stdout=subprocess.PIPE, ++ stderr=subprocess.PIPE) ++ data = p.communicate(b"lime")[0] ++ self.assertEqual(data, b"lime") ++ finally: ++ for h in handles: ++ os.close(h) + +- + def test_list2cmdline(self): + self.assertEqual(subprocess.list2cmdline(['a b c', 'd', 'e']), + '"a b c" d e') +@@ -530,10 +550,30 @@ + subprocess.Popen(['nonexisting_i_hope'], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) +- if c.exception.errno != 2: # ignore "no such file" ++ if c.exception.errno != errno.ENOENT: # ignore "no such file" + raise c.exception + ++ def test_handles_closed_on_exception(self): ++ # If CreateProcess exits with an error, ensure the ++ # duplicate output handles are released ++ ifhandle, ifname = mkstemp() ++ ofhandle, ofname = mkstemp() ++ efhandle, efname = mkstemp() ++ try: ++ subprocess.Popen (["*"], stdin=ifhandle, stdout=ofhandle, ++ stderr=efhandle) ++ except OSError: ++ os.close(ifhandle) ++ os.remove(ifname) ++ os.close(ofhandle) ++ os.remove(ofname) ++ os.close(efhandle) ++ os.remove(efname) ++ self.assertFalse(os.path.exists(ifname)) ++ self.assertFalse(os.path.exists(ofname)) ++ self.assertFalse(os.path.exists(efname)) + ++ + # context manager + class _SuppressCoreFiles(object): + """Try to prevent core files from being created.""" +@@ -548,6 +588,20 @@ + except (ImportError, ValueError, resource.error): + pass + ++ if sys.platform == 'darwin': ++ # Check if the 'Crash Reporter' on OSX was configured ++ # in 'Developer' mode and warn that it will get triggered ++ # when it is. ++ # ++ # This assumes that this context manager is used in tests ++ # that might trigger the next manager. ++ value = subprocess.Popen(['/usr/bin/defaults', 'read', ++ 'com.apple.CrashReporter', 'DialogType'], ++ stdout=subprocess.PIPE).communicate()[0] ++ if value.strip() == b'developer': ++ print "this tests triggers the Crash Reporter, that is intentional" ++ sys.stdout.flush() ++ + def __exit__(self, *args): + """Return core file behavior to default.""" + if self.old_limit is None: +@@ -641,27 +695,42 @@ + os.remove(fname) + self.assertEqual(rc, 47) + ++ def test_specific_shell(self): ++ # Issue #9265: Incorrect name passed as arg[0]. ++ shells = [] ++ for prefix in ['/bin', '/usr/bin/', '/usr/local/bin']: ++ for name in ['bash', 'ksh']: ++ sh = os.path.join(prefix, name) ++ if os.path.isfile(sh): ++ shells.append(sh) ++ if not shells: # Will probably work for any shell but csh. ++ self.skipTest("bash or ksh required for this test") ++ sh = '/bin/sh' ++ if os.path.isfile(sh) and not os.path.islink(sh): ++ # Test will fail if /bin/sh is a symlink to csh. ++ shells.append(sh) ++ for sh in shells: ++ p = subprocess.Popen("echo $0", executable=sh, shell=True, ++ stdout=subprocess.PIPE) ++ self.assertEqual(p.stdout.read().strip(), sh) ++ + def _kill_process(self, method, *args): + # Do not inherit file handles from the parent. + # It should fix failures on some platforms. +- p = subprocess.Popen([sys.executable, "-c", "input()"], close_fds=True, +- stdin=subprocess.PIPE, stderr=subprocess.PIPE) +- +- # Let the process initialize (Issue #3137) +- time.sleep(0.1) +- # The process should not terminate prematurely +- self.assertIsNone(p.poll()) +- # Retry if the process do not receive the signal. +- count, maxcount = 0, 3 +- while count < maxcount and p.poll() is None: +- getattr(p, method)(*args) +- time.sleep(0.1) +- count += 1 +- +- self.assertIsNotNone(p.poll(), "the subprocess did not terminate") +- if count > 1: +- print >>sys.stderr, ("p.{}{} succeeded after " +- "{} attempts".format(method, args, count)) ++ p = subprocess.Popen([sys.executable, "-c", """if 1: ++ import sys, time ++ sys.stdout.write('x\\n') ++ sys.stdout.flush() ++ time.sleep(30) ++ """], ++ close_fds=True, ++ stdin=subprocess.PIPE, ++ stdout=subprocess.PIPE, ++ stderr=subprocess.PIPE) ++ # Wait for the interpreter to be completely initialized before ++ # sending any signal. ++ p.stdout.read(1) ++ getattr(p, method)(*args) + return p + + def test_send_signal(self): +@@ -754,28 +823,22 @@ + + def _kill_process(self, method, *args): + # Some win32 buildbot raises EOFError if stdin is inherited +- p = subprocess.Popen([sys.executable, "-c", "input()"], +- stdin=subprocess.PIPE, stderr=subprocess.PIPE) +- +- # Let the process initialize (Issue #3137) +- time.sleep(0.1) +- # The process should not terminate prematurely +- self.assertIsNone(p.poll()) +- # Retry if the process do not receive the signal. +- count, maxcount = 0, 3 +- while count < maxcount and p.poll() is None: +- getattr(p, method)(*args) +- time.sleep(0.1) +- count += 1 +- +- returncode = p.poll() +- self.assertIsNotNone(returncode, "the subprocess did not terminate") +- if count > 1: +- print >>sys.stderr, ("p.{}{} succeeded after " +- "{} attempts".format(method, args, count)) ++ p = subprocess.Popen([sys.executable, "-c", """if 1: ++ import sys, time ++ sys.stdout.write('x\\n') ++ sys.stdout.flush() ++ time.sleep(30) ++ """], ++ stdin=subprocess.PIPE, ++ stdout=subprocess.PIPE, ++ stderr=subprocess.PIPE) ++ # Wait for the interpreter to be completely initialized before ++ # sending any signal. ++ p.stdout.read(1) ++ getattr(p, method)(*args) + _, stderr = p.communicate() + self.assertStderrEqual(stderr, '') +- self.assertEqual(p.wait(), returncode) ++ returncode = p.wait() + self.assertNotEqual(returncode, 0) + + def test_send_signal(self): +@@ -819,12 +882,55 @@ + self.assertEqual([(256, 999), (666,), (666,)], record_calls) + + ++@unittest.skipUnless(mswindows, "mswindows only") ++class CommandsWithSpaces (BaseTestCase): ++ ++ def setUp(self): ++ super(CommandsWithSpaces, self).setUp() ++ f, fname = mkstemp(".py", "te st") ++ self.fname = fname.lower () ++ os.write(f, b"import sys;" ++ b"sys.stdout.write('%d %s' % (len(sys.argv), [a.lower () for a in sys.argv]))" ++ ) ++ os.close(f) ++ ++ def tearDown(self): ++ os.remove(self.fname) ++ super(CommandsWithSpaces, self).tearDown() ++ ++ def with_spaces(self, *args, **kwargs): ++ kwargs['stdout'] = subprocess.PIPE ++ p = subprocess.Popen(*args, **kwargs) ++ self.assertEqual( ++ p.stdout.read ().decode("mbcs"), ++ "2 [%r, 'ab cd']" % self.fname ++ ) ++ ++ def test_shell_string_with_spaces(self): ++ # call() function with string argument with spaces on Windows ++ self.with_spaces('"%s" "%s" "%s"' % (sys.executable, self.fname, ++ "ab cd"), shell=1) ++ ++ def test_shell_sequence_with_spaces(self): ++ # call() function with sequence argument with spaces on Windows ++ self.with_spaces([sys.executable, self.fname, "ab cd"], shell=1) ++ ++ def test_noshell_string_with_spaces(self): ++ # call() function with string argument with spaces on Windows ++ self.with_spaces('"%s" "%s" "%s"' % (sys.executable, self.fname, ++ "ab cd")) ++ ++ def test_noshell_sequence_with_spaces(self): ++ # call() function with sequence argument with spaces on Windows ++ self.with_spaces([sys.executable, self.fname, "ab cd"]) ++ + def test_main(): + unit_tests = (ProcessTestCase, + POSIXProcessTestCase, + Win32ProcessTestCase, + ProcessTestCaseNoPoll, +- HelperFunctionTests) ++ HelperFunctionTests, ++ CommandsWithSpaces) + + test_support.run_unittest(*unit_tests) + test_support.reap_children() +--- a/Lib/test/string_tests.py ++++ b/Lib/test/string_tests.py +@@ -254,7 +254,7 @@ + r2 = j in i + self.assertEqual(r1, r2) + if loc != -1: +- self.assertEqual(i[loc:loc+len(j)], j) ++ self.assertEqual(i[loc:loc+len(j)], self.fixtype(j)) + + # issue 7458 + self.checkequal(-1, 'ab', 'rfind', 'xxx', sys.maxsize + 1, 0) +@@ -1119,7 +1119,7 @@ + format = '%%.%if' % prec + value = 0.01 + for x in xrange(60): +- value = value * 3.141592655 / 3.0 * 10.0 ++ value = value * 3.14159265359 / 3.0 * 10.0 + self.checkcall(format, "__mod__", value) + + def test_inplace_rewrites(self): +--- a/Lib/test/test_old_mailbox.py ++++ b/Lib/test/test_old_mailbox.py +@@ -48,18 +48,16 @@ + filename = os.extsep.join((str(t), str(pid), "myhostname", "mydomain")) + tmpname = os.path.join(self._dir, "tmp", filename) + newname = os.path.join(self._dir, dir, filename) +- fp = open(tmpname, "w") +- self._msgfiles.append(tmpname) +- if mbox: +- fp.write(FROM_) +- fp.write(DUMMY_MESSAGE) +- fp.close() ++ with open(tmpname, "w") as fp: ++ self._msgfiles.append(tmpname) ++ if mbox: ++ fp.write(FROM_) ++ fp.write(DUMMY_MESSAGE) + if hasattr(os, "link"): + os.link(tmpname, newname) + else: +- fp = open(newname, "w") +- fp.write(DUMMY_MESSAGE) +- fp.close() ++ with open(newname, "w") as fp: ++ fp.write(DUMMY_MESSAGE) + self._msgfiles.append(newname) + return tmpname + +@@ -102,11 +100,12 @@ + import email.parser + fname = self.createMessage("cur", True) + n = 0 +- for msg in mailbox.PortableUnixMailbox(open(fname), ++ with open(fname) as f: ++ for msg in mailbox.PortableUnixMailbox(f, + email.parser.Parser().parse): +- n += 1 +- self.assertEqual(msg["subject"], "Simple Test") +- self.assertEqual(len(str(msg)), len(FROM_)+len(DUMMY_MESSAGE)) ++ n += 1 ++ self.assertEqual(msg["subject"], "Simple Test") ++ self.assertEqual(len(str(msg)), len(FROM_)+len(DUMMY_MESSAGE)) + self.assertEqual(n, 1) + + class MboxTestCase(unittest.TestCase): +@@ -119,8 +118,8 @@ + + def test_from_regex (self): + # Testing new regex from bug #1633678 +- f = open(self._path, 'w') +- f.write("""From fred@example.com Mon May 31 13:24:50 2004 +0200 ++ with open(self._path, 'w') as f: ++ f.write("""From fred@example.com Mon May 31 13:24:50 2004 +0200 + Subject: message 1 + + body1 +@@ -137,9 +136,9 @@ + + body4 + """) +- f.close() +- box = mailbox.UnixMailbox(open(self._path, 'r')) +- self.assertTrue(len(list(iter(box))) == 4) ++ with open(self._path, 'r') as f: ++ box = mailbox.UnixMailbox(f) ++ self.assertTrue(len(list(iter(box))) == 4) + + + # XXX We still need more tests! +--- a/Lib/test/test_import.py ++++ b/Lib/test/test_import.py +@@ -3,11 +3,10 @@ + import os + import py_compile + import random +-import shutil + import stat + import sys + import unittest +-from test.test_support import (unlink, TESTFN, unload, run_unittest, ++from test.test_support import (unlink, TESTFN, unload, run_unittest, rmtree, + is_jython, check_warnings, EnvironmentVarGuard) + + +@@ -290,8 +289,7 @@ + unload(self.module_name) + unlink(self.file_name) + unlink(self.compiled_name) +- if os.path.exists(self.dir_name): +- shutil.rmtree(self.dir_name) ++ rmtree(self.dir_name) + + def import_module(self): + ns = globals() +@@ -354,7 +352,7 @@ + self.syspath = sys.path[:] + + def tearDown(self): +- shutil.rmtree(self.path) ++ rmtree(self.path) + sys.path[:] = self.syspath + + # Regression test for http://bugs.python.org/issue1293. +@@ -432,16 +430,13 @@ + self.assertRaises(ValueError, check_relative) + + def test_absolute_import_without_future(self): +- # If absolute import syntax is used, then do not try to perform +- # a relative import in the face of failure. ++ # If explicit relative import syntax is used, then do not try ++ # to perform an absolute import in the face of failure. + # Issue #7902. +- try: ++ with self.assertRaises(ImportError): + from .os import sep +- except ImportError: +- pass +- else: + self.fail("explicit relative import triggered an " +- "implicit relative import") ++ "implicit absolute import") + + + def test_main(verbose=None): +--- a/Lib/test/test_gettext.py ++++ b/Lib/test/test_gettext.py +@@ -334,6 +334,37 @@ + 'John Doe \nJane Foobar ') + + ++class DummyGNUTranslations(gettext.GNUTranslations): ++ def foo(self): ++ return 'foo' ++ ++ ++class GettextCacheTestCase(GettextBaseTest): ++ def test_cache(self): ++ self.localedir = os.curdir ++ self.mofile = MOFILE ++ ++ self.assertEqual(len(gettext._translations), 0) ++ ++ t = gettext.translation('gettext', self.localedir) ++ ++ self.assertEqual(len(gettext._translations), 1) ++ ++ t = gettext.translation('gettext', self.localedir, ++ class_=DummyGNUTranslations) ++ ++ self.assertEqual(len(gettext._translations), 2) ++ self.assertEqual(t.__class__, DummyGNUTranslations) ++ ++ # Calling it again doesn't add to the cache ++ ++ t = gettext.translation('gettext', self.localedir, ++ class_=DummyGNUTranslations) ++ ++ self.assertEqual(len(gettext._translations), 2) ++ self.assertEqual(t.__class__, DummyGNUTranslations) ++ ++ + def test_main(): + test_support.run_unittest(__name__) + +--- a/Lib/test/test_platform.py ++++ b/Lib/test/test_platform.py +@@ -195,6 +195,25 @@ + else: + self.assertEquals(res[2], 'PowerPC') + ++ ++ @unittest.skipUnless(sys.platform == 'darwin', "OSX only test") ++ def test_mac_ver_with_fork(self): ++ # Issue7895: platform.mac_ver() crashes when using fork without exec ++ # ++ # This test checks that the fix for that issue works. ++ # ++ pid = os.fork() ++ if pid == 0: ++ # child ++ info = platform.mac_ver() ++ os._exit(0) ++ ++ else: ++ # parent ++ cpid, sts = os.waitpid(pid, 0) ++ self.assertEquals(cpid, pid) ++ self.assertEquals(sts, 0) ++ + def test_dist(self): + res = platform.dist() + +--- a/Lib/test/test_bytes.py ++++ b/Lib/test/test_bytes.py +@@ -9,14 +9,28 @@ + import re + import sys + import copy ++import functools + import pickle + import tempfile + import unittest +-import warnings + import test.test_support + import test.string_tests + import test.buffer_tests + ++ ++if sys.flags.bytes_warning: ++ def check_bytes_warnings(func): ++ @functools.wraps(func) ++ def wrapper(*args, **kw): ++ with test.test_support.check_warnings(('', BytesWarning)): ++ return func(*args, **kw) ++ return wrapper ++else: ++ # no-op ++ def check_bytes_warnings(func): ++ return func ++ ++ + class Indexable: + def __init__(self, value=0): + self.value = value +@@ -26,12 +40,6 @@ + + class BaseBytesTest(unittest.TestCase): + +- def setUp(self): +- self.warning_filters = warnings.filters[:] +- +- def tearDown(self): +- warnings.filters = self.warning_filters +- + def test_basics(self): + b = self.type2test() + self.assertEqual(type(b), self.type2test) +@@ -120,8 +128,8 @@ + self.assertFalse(b3 < b2) + self.assertFalse(b3 <= b2) + ++ @check_bytes_warnings + def test_compare_to_str(self): +- warnings.simplefilter('ignore', BytesWarning) + # Byte comparisons with unicode should always fail! + # Test this for all expected byte orders and Unicode character sizes + self.assertEqual(self.type2test(b"\0a\0b\0c") == u"abc", False) +@@ -795,14 +803,8 @@ + # Test various combinations of bytes and bytearray + # + +- def setUp(self): +- self.warning_filters = warnings.filters[:] +- +- def tearDown(self): +- warnings.filters = self.warning_filters +- ++ @check_bytes_warnings + def test_repr_str(self): +- warnings.simplefilter('ignore', BytesWarning) + for f in str, repr: + self.assertEqual(f(bytearray()), "bytearray(b'')") + self.assertEqual(f(bytearray([0])), "bytearray(b'\\x00')") +@@ -853,8 +855,8 @@ + b = bytearray(buf) + self.assertEqual(b, bytearray(sample)) + ++ @check_bytes_warnings + def test_to_str(self): +- warnings.simplefilter('ignore', BytesWarning) + self.assertEqual(str(b''), "b''") + self.assertEqual(str(b'x'), "b'x'") + self.assertEqual(str(b'\x80'), "b'\\x80'") +--- a/Lib/test/test_posix.py ++++ b/Lib/test/test_posix.py +@@ -6,10 +6,12 @@ + posix = test_support.import_module('posix') + + import errno ++import sys + import time + import os + import pwd + import shutil ++import sys + import unittest + import warnings + +@@ -345,8 +347,13 @@ + os.chdir(dirname) + try: + os.getcwd() +- if current_path_length < 1027: ++ if current_path_length < 4099: + _create_and_do_getcwd(dirname, current_path_length + len(dirname) + 1) ++ except OSError as e: ++ expected_errno = errno.ENAMETOOLONG ++ if 'sunos' in sys.platform or 'openbsd' in sys.platform: ++ expected_errno = errno.ERANGE # Issue 9185 ++ self.assertEqual(e.errno, expected_errno) + finally: + os.chdir('..') + os.rmdir(dirname) +@@ -357,9 +364,57 @@ + os.chdir(curdir) + shutil.rmtree(base_path) + ++ def test_getgroups(self): ++ with os.popen('id -G') as idg: ++ groups = idg.read().strip() + ++ if not groups: ++ raise unittest.SkipTest("need working 'id -G'") ++ ++ # 'id -G' and 'os.getgroups()' should return the same ++ # groups, ignoring order and duplicates. ++ self.assertEqual( ++ set([int(x) for x in groups.split()]), ++ set(posix.getgroups())) ++ ++class PosixGroupsTester(unittest.TestCase): ++ ++ def setUp(self): ++ if posix.getuid() != 0: ++ raise unittest.SkipTest("not enough privileges") ++ if not hasattr(posix, 'getgroups'): ++ raise unittest.SkipTest("need posix.getgroups") ++ if sys.platform == 'darwin': ++ raise unittest.SkipTest("getgroups(2) is broken on OSX") ++ self.saved_groups = posix.getgroups() ++ ++ def tearDown(self): ++ if hasattr(posix, 'setgroups'): ++ posix.setgroups(self.saved_groups) ++ elif hasattr(posix, 'initgroups'): ++ name = pwd.getpwuid(posix.getuid()).pw_name ++ posix.initgroups(name, self.saved_groups[0]) ++ ++ @unittest.skipUnless(hasattr(posix, 'initgroups'), ++ "test needs posix.initgroups()") ++ def test_initgroups(self): ++ # find missing group ++ ++ g = max(self.saved_groups) + 1 ++ name = pwd.getpwuid(posix.getuid()).pw_name ++ posix.initgroups(name, g) ++ self.assertIn(g, posix.getgroups()) ++ ++ @unittest.skipUnless(hasattr(posix, 'setgroups'), ++ "test needs posix.setgroups()") ++ def test_setgroups(self): ++ for groups in [[0], range(16)]: ++ posix.setgroups(groups) ++ self.assertListEqual(groups, posix.getgroups()) ++ ++ + def test_main(): +- test_support.run_unittest(PosixTester) ++ test_support.run_unittest(PosixTester, PosixGroupsTester) + + if __name__ == '__main__': + test_main() +--- a/Lib/test/test_curses.py ++++ b/Lib/test/test_curses.py +@@ -218,8 +218,8 @@ + if availmask != 0: + curses.mouseinterval(10) + # just verify these don't cause errors ++ curses.ungetmouse(0, 0, 0, 0, curses.BUTTON1_PRESSED) + m = curses.getmouse() +- curses.ungetmouse(*m) + + if hasattr(curses, 'is_term_resized'): + curses.is_term_resized(*stdscr.getmaxyx()) +--- a/Lib/test/test_argparse.py ++++ b/Lib/test/test_argparse.py +@@ -420,7 +420,7 @@ + + + class TestOptionalsAlternatePrefixChars(ParserTestCase): +- """Test an Optional with a double-dash option string""" ++ """Test an Optional with option strings with custom prefixes""" + + parser_signature = Sig(prefix_chars='+:/', add_help=False) + argument_signatures = [ +@@ -428,7 +428,7 @@ + Sig('::bar'), + Sig('/baz', action='store_const', const=42), + ] +- failures = ['--bar', '-fbar', '-b B', 'B', '-f', '--bar B', '-baz'] ++ failures = ['--bar', '-fbar', '-b B', 'B', '-f', '--bar B', '-baz', '-h', '--help', '+h', '::help', '/help'] + successes = [ + ('', NS(f=False, bar=None, baz=None)), + ('+f', NS(f=True, bar=None, baz=None)), +@@ -439,6 +439,27 @@ + ] + + ++class TestOptionalsAlternatePrefixCharsAddedHelp(ParserTestCase): ++ """When ``-`` not in prefix_chars, default operators created for help ++ should use the prefix_chars in use rather than - or -- ++ http://bugs.python.org/issue9444""" ++ ++ parser_signature = Sig(prefix_chars='+:/', add_help=True) ++ argument_signatures = [ ++ Sig('+f', action='store_true'), ++ Sig('::bar'), ++ Sig('/baz', action='store_const', const=42), ++ ] ++ failures = ['--bar', '-fbar', '-b B', 'B', '-f', '--bar B', '-baz'] ++ successes = [ ++ ('', NS(f=False, bar=None, baz=None)), ++ ('+f', NS(f=True, bar=None, baz=None)), ++ ('::ba B', NS(f=False, bar='B', baz=None)), ++ ('+f ::bar B', NS(f=True, bar='B', baz=None)), ++ ('+f /b', NS(f=True, bar=None, baz=42)), ++ ('/ba +f', NS(f=True, bar=None, baz=42)) ++ ] ++ + class TestOptionalsShortLong(ParserTestCase): + """Test a combination of single- and double-dash option strings""" + +@@ -1666,13 +1687,19 @@ + def assertArgumentParserError(self, *args, **kwargs): + self.assertRaises(ArgumentParserError, *args, **kwargs) + +- def _get_parser(self, subparser_help=False): ++ def _get_parser(self, subparser_help=False, prefix_chars=None): + # create a parser with a subparsers argument +- parser = ErrorRaisingArgumentParser( +- prog='PROG', description='main description') ++ if prefix_chars: ++ parser = ErrorRaisingArgumentParser( ++ prog='PROG', description='main description', prefix_chars=prefix_chars) ++ parser.add_argument( ++ prefix_chars[0] * 2 + 'foo', action='store_true', help='foo help') ++ else: ++ parser = ErrorRaisingArgumentParser( ++ prog='PROG', description='main description') ++ parser.add_argument( ++ '--foo', action='store_true', help='foo help') + parser.add_argument( +- '--foo', action='store_true', help='foo help') +- parser.add_argument( + 'bar', type=float, help='bar help') + + # check that only one subparsers argument can be added +@@ -1750,6 +1777,44 @@ + --foo foo help + ''')) + ++ def test_help_extra_prefix_chars(self): ++ # Make sure - is still used for help if it is a non-first prefix char ++ parser = self._get_parser(prefix_chars='+:-') ++ self.assertEqual(parser.format_usage(), ++ 'usage: PROG [-h] [++foo] bar {1,2} ...\n') ++ self.assertEqual(parser.format_help(), textwrap.dedent('''\ ++ usage: PROG [-h] [++foo] bar {1,2} ... ++ ++ main description ++ ++ positional arguments: ++ bar bar help ++ {1,2} command help ++ ++ optional arguments: ++ -h, --help show this help message and exit ++ ++foo foo help ++ ''')) ++ ++ ++ def test_help_alternate_prefix_chars(self): ++ parser = self._get_parser(prefix_chars='+:/') ++ self.assertEqual(parser.format_usage(), ++ 'usage: PROG [+h] [++foo] bar {1,2} ...\n') ++ self.assertEqual(parser.format_help(), textwrap.dedent('''\ ++ usage: PROG [+h] [++foo] bar {1,2} ... ++ ++ main description ++ ++ positional arguments: ++ bar bar help ++ {1,2} command help ++ ++ optional arguments: ++ +h, ++help show this help message and exit ++ ++foo foo help ++ ''')) ++ + def test_parser_command_help(self): + self.assertEqual(self.command_help_parser.format_usage(), + 'usage: PROG [-h] [--foo] bar {1,2} ...\n') +@@ -4106,7 +4171,8 @@ + def _test_module_encoding(self, path): + path, _ = os.path.splitext(path) + path += ".py" +- codecs.open(path, 'r', 'utf8').read() ++ with codecs.open(path, 'r', 'utf8') as f: ++ f.read() + + def test_argparse_module_encoding(self): + self._test_module_encoding(argparse.__file__) +--- a/Lib/test/test_copy.py ++++ b/Lib/test/test_copy.py +@@ -526,6 +526,26 @@ + self.assertEqual(x.foo, y.foo) + self.assertTrue(x.foo is not y.foo) + ++ def test_deepcopy_dict_subclass(self): ++ class C(dict): ++ def __init__(self, d=None): ++ if not d: ++ d = {} ++ self._keys = list(d.keys()) ++ dict.__init__(self, d) ++ def __setitem__(self, key, item): ++ dict.__setitem__(self, key, item) ++ if key not in self._keys: ++ self._keys.append(key) ++ x = C(d={'foo':0}) ++ y = copy.deepcopy(x) ++ self.assertEqual(x, y) ++ self.assertEqual(x._keys, y._keys) ++ self.assertTrue(x is not y) ++ x['bar'] = 1 ++ self.assertNotEqual(x, y) ++ self.assertNotEqual(x._keys, y._keys) ++ + def test_copy_list_subclass(self): + class C(list): + pass +--- a/Lib/test/test_sys_setprofile.py ++++ b/Lib/test/test_sys_setprofile.py +@@ -0,0 +1,385 @@ ++import pprint ++import sys ++import unittest ++ ++from test import test_support ++ ++class TestGetProfile(unittest.TestCase): ++ def setUp(self): ++ sys.setprofile(None) ++ ++ def tearDown(self): ++ sys.setprofile(None) ++ ++ def test_empty(self): ++ assert sys.getprofile() is None ++ ++ def test_setget(self): ++ def fn(*args): ++ pass ++ ++ sys.setprofile(fn) ++ assert sys.getprofile() == fn ++ ++class HookWatcher: ++ def __init__(self): ++ self.frames = [] ++ self.events = [] ++ ++ def callback(self, frame, event, arg): ++ if (event == "call" ++ or event == "return" ++ or event == "exception"): ++ self.add_event(event, frame) ++ ++ def add_event(self, event, frame=None): ++ """Add an event to the log.""" ++ if frame is None: ++ frame = sys._getframe(1) ++ ++ try: ++ frameno = self.frames.index(frame) ++ except ValueError: ++ frameno = len(self.frames) ++ self.frames.append(frame) ++ ++ self.events.append((frameno, event, ident(frame))) ++ ++ def get_events(self): ++ """Remove calls to add_event().""" ++ disallowed = [ident(self.add_event.im_func), ident(ident)] ++ self.frames = None ++ ++ return [item for item in self.events if item[2] not in disallowed] ++ ++ ++class ProfileSimulator(HookWatcher): ++ def __init__(self, testcase): ++ self.testcase = testcase ++ self.stack = [] ++ HookWatcher.__init__(self) ++ ++ def callback(self, frame, event, arg): ++ # Callback registered with sys.setprofile()/sys.settrace() ++ self.dispatch[event](self, frame) ++ ++ def trace_call(self, frame): ++ self.add_event('call', frame) ++ self.stack.append(frame) ++ ++ def trace_return(self, frame): ++ self.add_event('return', frame) ++ self.stack.pop() ++ ++ def trace_exception(self, frame): ++ self.testcase.fail( ++ "the profiler should never receive exception events") ++ ++ def trace_pass(self, frame): ++ pass ++ ++ dispatch = { ++ 'call': trace_call, ++ 'exception': trace_exception, ++ 'return': trace_return, ++ 'c_call': trace_pass, ++ 'c_return': trace_pass, ++ 'c_exception': trace_pass, ++ } ++ ++ ++class TestCaseBase(unittest.TestCase): ++ def check_events(self, callable, expected): ++ events = capture_events(callable, self.new_watcher()) ++ if events != expected: ++ self.fail("Expected events:\n%s\nReceived events:\n%s" ++ % (pprint.pformat(expected), pprint.pformat(events))) ++ ++ ++class ProfileHookTestCase(TestCaseBase): ++ def new_watcher(self): ++ return HookWatcher() ++ ++ def test_simple(self): ++ def f(p): ++ pass ++ f_ident = ident(f) ++ self.check_events(f, [(1, 'call', f_ident), ++ (1, 'return', f_ident), ++ ]) ++ ++ def test_exception(self): ++ def f(p): ++ 1./0 ++ f_ident = ident(f) ++ self.check_events(f, [(1, 'call', f_ident), ++ (1, 'return', f_ident), ++ ]) ++ ++ def test_caught_exception(self): ++ def f(p): ++ try: 1./0 ++ except: pass ++ f_ident = ident(f) ++ self.check_events(f, [(1, 'call', f_ident), ++ (1, 'return', f_ident), ++ ]) ++ ++ def test_caught_nested_exception(self): ++ def f(p): ++ try: 1./0 ++ except: pass ++ f_ident = ident(f) ++ self.check_events(f, [(1, 'call', f_ident), ++ (1, 'return', f_ident), ++ ]) ++ ++ def test_nested_exception(self): ++ def f(p): ++ 1./0 ++ f_ident = ident(f) ++ self.check_events(f, [(1, 'call', f_ident), ++ # This isn't what I expected: ++ # (0, 'exception', protect_ident), ++ # I expected this again: ++ (1, 'return', f_ident), ++ ]) ++ ++ def test_exception_in_except_clause(self): ++ def f(p): ++ 1./0 ++ def g(p): ++ try: ++ f(p) ++ except: ++ try: f(p) ++ except: pass ++ f_ident = ident(f) ++ g_ident = ident(g) ++ self.check_events(g, [(1, 'call', g_ident), ++ (2, 'call', f_ident), ++ (2, 'return', f_ident), ++ (3, 'call', f_ident), ++ (3, 'return', f_ident), ++ (1, 'return', g_ident), ++ ]) ++ ++ def test_exception_propogation(self): ++ def f(p): ++ 1./0 ++ def g(p): ++ try: f(p) ++ finally: p.add_event("falling through") ++ f_ident = ident(f) ++ g_ident = ident(g) ++ self.check_events(g, [(1, 'call', g_ident), ++ (2, 'call', f_ident), ++ (2, 'return', f_ident), ++ (1, 'falling through', g_ident), ++ (1, 'return', g_ident), ++ ]) ++ ++ def test_raise_twice(self): ++ def f(p): ++ try: 1./0 ++ except: 1./0 ++ f_ident = ident(f) ++ self.check_events(f, [(1, 'call', f_ident), ++ (1, 'return', f_ident), ++ ]) ++ ++ def test_raise_reraise(self): ++ def f(p): ++ try: 1./0 ++ except: raise ++ f_ident = ident(f) ++ self.check_events(f, [(1, 'call', f_ident), ++ (1, 'return', f_ident), ++ ]) ++ ++ def test_raise(self): ++ def f(p): ++ raise Exception() ++ f_ident = ident(f) ++ self.check_events(f, [(1, 'call', f_ident), ++ (1, 'return', f_ident), ++ ]) ++ ++ def test_distant_exception(self): ++ def f(): ++ 1./0 ++ def g(): ++ f() ++ def h(): ++ g() ++ def i(): ++ h() ++ def j(p): ++ i() ++ f_ident = ident(f) ++ g_ident = ident(g) ++ h_ident = ident(h) ++ i_ident = ident(i) ++ j_ident = ident(j) ++ self.check_events(j, [(1, 'call', j_ident), ++ (2, 'call', i_ident), ++ (3, 'call', h_ident), ++ (4, 'call', g_ident), ++ (5, 'call', f_ident), ++ (5, 'return', f_ident), ++ (4, 'return', g_ident), ++ (3, 'return', h_ident), ++ (2, 'return', i_ident), ++ (1, 'return', j_ident), ++ ]) ++ ++ def test_generator(self): ++ def f(): ++ for i in range(2): ++ yield i ++ def g(p): ++ for i in f(): ++ pass ++ f_ident = ident(f) ++ g_ident = ident(g) ++ self.check_events(g, [(1, 'call', g_ident), ++ # call the iterator twice to generate values ++ (2, 'call', f_ident), ++ (2, 'return', f_ident), ++ (2, 'call', f_ident), ++ (2, 'return', f_ident), ++ # once more; returns end-of-iteration with ++ # actually raising an exception ++ (2, 'call', f_ident), ++ (2, 'return', f_ident), ++ (1, 'return', g_ident), ++ ]) ++ ++ def test_stop_iteration(self): ++ def f(): ++ for i in range(2): ++ yield i ++ raise StopIteration ++ def g(p): ++ for i in f(): ++ pass ++ f_ident = ident(f) ++ g_ident = ident(g) ++ self.check_events(g, [(1, 'call', g_ident), ++ # call the iterator twice to generate values ++ (2, 'call', f_ident), ++ (2, 'return', f_ident), ++ (2, 'call', f_ident), ++ (2, 'return', f_ident), ++ # once more to hit the raise: ++ (2, 'call', f_ident), ++ (2, 'return', f_ident), ++ (1, 'return', g_ident), ++ ]) ++ ++ ++class ProfileSimulatorTestCase(TestCaseBase): ++ def new_watcher(self): ++ return ProfileSimulator(self) ++ ++ def test_simple(self): ++ def f(p): ++ pass ++ f_ident = ident(f) ++ self.check_events(f, [(1, 'call', f_ident), ++ (1, 'return', f_ident), ++ ]) ++ ++ def test_basic_exception(self): ++ def f(p): ++ 1./0 ++ f_ident = ident(f) ++ self.check_events(f, [(1, 'call', f_ident), ++ (1, 'return', f_ident), ++ ]) ++ ++ def test_caught_exception(self): ++ def f(p): ++ try: 1./0 ++ except: pass ++ f_ident = ident(f) ++ self.check_events(f, [(1, 'call', f_ident), ++ (1, 'return', f_ident), ++ ]) ++ ++ def test_distant_exception(self): ++ def f(): ++ 1./0 ++ def g(): ++ f() ++ def h(): ++ g() ++ def i(): ++ h() ++ def j(p): ++ i() ++ f_ident = ident(f) ++ g_ident = ident(g) ++ h_ident = ident(h) ++ i_ident = ident(i) ++ j_ident = ident(j) ++ self.check_events(j, [(1, 'call', j_ident), ++ (2, 'call', i_ident), ++ (3, 'call', h_ident), ++ (4, 'call', g_ident), ++ (5, 'call', f_ident), ++ (5, 'return', f_ident), ++ (4, 'return', g_ident), ++ (3, 'return', h_ident), ++ (2, 'return', i_ident), ++ (1, 'return', j_ident), ++ ]) ++ ++ ++def ident(function): ++ if hasattr(function, "f_code"): ++ code = function.f_code ++ else: ++ code = function.func_code ++ return code.co_firstlineno, code.co_name ++ ++ ++def protect(f, p): ++ try: f(p) ++ except: pass ++ ++protect_ident = ident(protect) ++ ++ ++def capture_events(callable, p=None): ++ try: ++ sys.setprofile() ++ except TypeError: ++ pass ++ else: ++ raise test_support.TestFailed( ++ 'sys.setprofile() did not raise TypeError') ++ ++ if p is None: ++ p = HookWatcher() ++ sys.setprofile(p.callback) ++ protect(callable, p) ++ sys.setprofile(None) ++ return p.get_events()[1:-1] ++ ++ ++def show_events(callable): ++ import pprint ++ pprint.pprint(capture_events(callable)) ++ ++ ++def test_main(): ++ test_support.run_unittest( ++ TestGetProfile, ++ ProfileHookTestCase, ++ ProfileSimulatorTestCase ++ ) ++ ++ ++if __name__ == "__main__": ++ test_main() + +Property changes on: Lib/test/test_sys_setprofile.py +___________________________________________________________________ +Added: svn:eol-style + + native +Added: svn:keywords + + Author Date Id Revision + +--- a/Lib/test/test_modulefinder.py ++++ b/Lib/test/test_modulefinder.py +@@ -211,11 +211,17 @@ + + def create_package(source): + ofi = None +- for line in source.splitlines(): +- if line.startswith(" ") or line.startswith("\t"): +- ofi.write(line.strip() + "\n") +- else: +- ofi = open_file(os.path.join(TEST_DIR, line.strip())) ++ try: ++ for line in source.splitlines(): ++ if line.startswith(" ") or line.startswith("\t"): ++ ofi.write(line.strip() + "\n") ++ else: ++ if ofi: ++ ofi.close() ++ ofi = open_file(os.path.join(TEST_DIR, line.strip())) ++ finally: ++ if ofi: ++ ofi.close() + + class ModuleFinderTest(unittest.TestCase): + def _do_test(self, info, report=False): +--- a/Lib/test/test_threading_local.py ++++ b/Lib/test/test_threading_local.py +@@ -1,10 +1,15 @@ + import unittest + from doctest import DocTestSuite + from test import test_support +-threading = test_support.import_module('threading') + import weakref + import gc + ++# Modules under test ++_thread = test_support.import_module('thread') ++threading = test_support.import_module('threading') ++import _threading_local ++ ++ + class Weak(object): + pass + +@@ -13,7 +18,7 @@ + local.weak = weak + weaklist.append(weakref.ref(weak)) + +-class ThreadingLocalTest(unittest.TestCase): ++class BaseLocalTest: + + def test_local_refs(self): + self._local_refs(20) +@@ -21,7 +26,7 @@ + self._local_refs(100) + + def _local_refs(self, n): +- local = threading.local() ++ local = self._local() + weaklist = [] + for i in range(n): + t = threading.Thread(target=target, args=(local, weaklist)) +@@ -32,9 +37,9 @@ + gc.collect() + self.assertEqual(len(weaklist), n) + +- # XXX threading.local keeps the local of the last stopped thread alive. ++ # XXX _threading_local keeps the local of the last stopped thread alive. + deadlist = [weak for weak in weaklist if weak() is None] +- self.assertEqual(len(deadlist), n-1) ++ self.assertIn(len(deadlist), (n-1, n)) + + # Assignment to the same thread local frees it sometimes (!) + local.someothervar = None +@@ -48,7 +53,7 @@ + # is created but not correctly set on the object. + # The first member set may be bogus. + import time +- class Local(threading.local): ++ class Local(self._local): + def __init__(self): + time.sleep(0.01) + local = Local() +@@ -69,7 +74,7 @@ + + def test_derived_cycle_dealloc(self): + # http://bugs.python.org/issue6990 +- class Local(threading.local): ++ class Local(self._local): + pass + locals = None + passed = [False] +@@ -120,11 +125,93 @@ + self.assertRaises(TypeError, cls, a=1) + self.assertRaises(TypeError, cls, 1) + ++ def _test_one_class(self, c): ++ self._failed = "No error message set or cleared." ++ obj = c() ++ e1 = threading.Event() ++ e2 = threading.Event() + ++ def f1(): ++ obj.x = 'foo' ++ obj.y = 'bar' ++ del obj.y ++ e1.set() ++ e2.wait() ++ ++ def f2(): ++ try: ++ foo = obj.x ++ except AttributeError: ++ # This is expected -- we haven't set obj.x in this thread yet! ++ self._failed = "" # passed ++ else: ++ self._failed = ('Incorrectly got value %r from class %r\n' % ++ (foo, c)) ++ sys.stderr.write(self._failed) ++ ++ t1 = threading.Thread(target=f1) ++ t1.start() ++ e1.wait() ++ t2 = threading.Thread(target=f2) ++ t2.start() ++ t2.join() ++ # The test is done; just let t1 know it can exit, and wait for it. ++ e2.set() ++ t1.join() ++ ++ self.assertFalse(self._failed, self._failed) ++ ++ def test_threading_local(self): ++ self._test_one_class(self._local) ++ ++ def test_threading_local_subclass(self): ++ class LocalSubclass(self._local): ++ """To test that subclasses behave properly.""" ++ self._test_one_class(LocalSubclass) ++ ++ def _test_dict_attribute(self, cls): ++ obj = cls() ++ obj.x = 5 ++ self.assertEqual(obj.__dict__, {'x': 5}) ++ with self.assertRaises(AttributeError): ++ obj.__dict__ = {} ++ with self.assertRaises(AttributeError): ++ del obj.__dict__ ++ ++ def test_dict_attribute(self): ++ self._test_dict_attribute(self._local) ++ ++ def test_dict_attribute_subclass(self): ++ class LocalSubclass(self._local): ++ """To test that subclasses behave properly.""" ++ self._test_dict_attribute(LocalSubclass) ++ ++ ++class ThreadLocalTest(unittest.TestCase, BaseLocalTest): ++ _local = _thread._local ++ ++ # Fails for the pure Python implementation ++ def test_cycle_collection(self): ++ class X: ++ pass ++ ++ x = X() ++ x.local = self._local() ++ x.local.x = x ++ wr = weakref.ref(x) ++ del x ++ gc.collect() ++ self.assertIs(wr(), None) ++ ++class PyThreadingLocalTest(unittest.TestCase, BaseLocalTest): ++ _local = _threading_local.local ++ ++ + def test_main(): + suite = unittest.TestSuite() + suite.addTest(DocTestSuite('_threading_local')) +- suite.addTest(unittest.makeSuite(ThreadingLocalTest)) ++ suite.addTest(unittest.makeSuite(ThreadLocalTest)) ++ suite.addTest(unittest.makeSuite(PyThreadingLocalTest)) + + try: + from thread import _local +--- a/Lib/test/test_multiprocessing.py ++++ b/Lib/test/test_multiprocessing.py +@@ -34,6 +34,12 @@ + + from multiprocessing import util + ++try: ++ from multiprocessing.sharedctypes import Value, copy ++ HAS_SHAREDCTYPES = True ++except ImportError: ++ HAS_SHAREDCTYPES = False ++ + # + # + # +@@ -72,16 +78,6 @@ + Structure = object + c_int = c_double = None + +-try: +- from ctypes import Value +-except ImportError: +- Value = None +- +-try: +- from ctypes import copy as ctypes_copy +-except ImportError: +- ctypes_copy = None +- + # + # Creates a wrapper for a function which records the time it takes to finish + # +@@ -800,6 +796,8 @@ + # + # + ++@unittest.skipUnless(HAS_SHAREDCTYPES, ++ "requires multiprocessing.sharedctypes") + class _TestValue(BaseTestCase): + + ALLOWED_TYPES = ('processes',) +@@ -816,7 +814,6 @@ + sv.value = cv[2] + + +- @unittest.skipIf(c_int is None, "requires _ctypes") + def test_value(self, raw=False): + if raw: + values = [self.RawValue(code, value) +@@ -835,11 +832,9 @@ + for sv, cv in zip(values, self.codes_values): + self.assertEqual(sv.value, cv[2]) + +- @unittest.skipIf(c_int is None, "requires _ctypes") + def test_rawvalue(self): + self.test_value(raw=True) + +- @unittest.skipIf(c_int is None, "requires _ctypes") + def test_getobj_getlock(self): + val1 = self.Value('i', 5) + lock1 = val1.get_lock() +@@ -1593,6 +1588,8 @@ + ('y', c_double) + ] + ++@unittest.skipUnless(HAS_SHAREDCTYPES, ++ "requires multiprocessing.sharedctypes") + class _TestSharedCTypes(BaseTestCase): + + ALLOWED_TYPES = ('processes',) +@@ -1606,14 +1603,13 @@ + for i in range(len(arr)): + arr[i] *= 2 + +- @unittest.skipIf(Value is None, "requires ctypes.Value") + def test_sharedctypes(self, lock=False): + x = Value('i', 7, lock=lock) + y = Value(c_double, 1.0/3.0, lock=lock) + foo = Value(_Foo, 3, 2, lock=lock) + arr = self.Array('d', range(10), lock=lock) + string = self.Array('c', 20, lock=lock) +- string.value = 'hello' ++ string.value = latin('hello') + + p = self.Process(target=self._double, args=(x, y, foo, arr, string)) + p.start() +@@ -1627,14 +1623,12 @@ + self.assertAlmostEqual(arr[i], i*2) + self.assertEqual(string.value, latin('hellohello')) + +- @unittest.skipIf(Value is None, "requires ctypes.Value") + def test_synchronize(self): + self.test_sharedctypes(lock=True) + +- @unittest.skipIf(ctypes_copy is None, "requires ctypes.copy") + def test_copy(self): + foo = _Foo(2, 5.0) +- bar = ctypes_copy(foo) ++ bar = copy(foo) + foo.x = 0 + foo.y = 0 + self.assertEqual(bar.x, 2) +--- a/Lib/test/test_urllib.py ++++ b/Lib/test/test_urllib.py +@@ -381,6 +381,7 @@ + "using quote(): %s != %s" % (expected, result)) + self.assertEqual(expected, result, + "using quote_plus(): %s != %s" % (expected, result)) ++ self.assertRaises(TypeError, urllib.quote, None) + + def test_quoting_space(self): + # Make sure quote() and quote_plus() handle spaces as specified in +--- a/Lib/test/test_mailbox.py ++++ b/Lib/test/test_mailbox.py +@@ -598,12 +598,10 @@ + # Remove old files from 'tmp' + foo_path = os.path.join(self._path, 'tmp', 'foo') + bar_path = os.path.join(self._path, 'tmp', 'bar') +- f = open(foo_path, 'w') +- f.write("@") +- f.close() +- f = open(bar_path, 'w') +- f.write("@") +- f.close() ++ with open(foo_path, 'w') as f: ++ f.write("@") ++ with open(bar_path, 'w') as f: ++ f.write("@") + self._box.clean() + self.assertTrue(os.path.exists(foo_path)) + self.assertTrue(os.path.exists(bar_path)) +@@ -1088,13 +1086,12 @@ + + def test_initialize_with_file(self): + # Initialize based on contents of file +- f = open(self._path, 'w+') +- f.write(_sample_message) +- f.seek(0) +- msg = self._factory(f) +- self._post_initialize_hook(msg) +- self._check_sample(msg) +- f.close() ++ with open(self._path, 'w+') as f: ++ f.write(_sample_message) ++ f.seek(0) ++ msg = self._factory(f) ++ self._post_initialize_hook(msg) ++ self._check_sample(msg) + + def test_initialize_with_nothing(self): + # Initialize without arguments +@@ -1812,18 +1809,16 @@ + filename = os.extsep.join((str(t), str(pid), "myhostname", "mydomain")) + tmpname = os.path.join(self._dir, "tmp", filename) + newname = os.path.join(self._dir, dir, filename) +- fp = open(tmpname, "w") +- self._msgfiles.append(tmpname) +- if mbox: +- fp.write(FROM_) +- fp.write(DUMMY_MESSAGE) +- fp.close() ++ with open(tmpname, "w") as fp: ++ self._msgfiles.append(tmpname) ++ if mbox: ++ fp.write(FROM_) ++ fp.write(DUMMY_MESSAGE) + if hasattr(os, "link"): + os.link(tmpname, newname) + else: +- fp = open(newname, "w") +- fp.write(DUMMY_MESSAGE) +- fp.close() ++ with open(newname, "w") as fp: ++ fp.write(DUMMY_MESSAGE) + self._msgfiles.append(newname) + return tmpname + +--- a/Lib/test/test_urlparse.py ++++ b/Lib/test/test_urlparse.py +@@ -7,6 +7,7 @@ + RFC1808_BASE = "http://a/b/c/d;p?q#f" + RFC2396_BASE = "http://a/b/c/d;p?q" + RFC3986_BASE = 'http://a/b/c/d;p?q' ++SIMPLE_BASE = 'http://a/b/c/d' + + # A list of test cases. Each test case is a a two-tuple that contains + # a string with the query and a dictionary with the expected result. +@@ -294,6 +295,37 @@ + #self.checkJoin(RFC3986_BASE, 'http:g','http:g') # strict parser + self.checkJoin(RFC3986_BASE, 'http:g','http://a/b/c/g') # relaxed parser + ++ def test_urljoins(self): ++ self.checkJoin(SIMPLE_BASE, 'g:h','g:h') ++ self.checkJoin(SIMPLE_BASE, 'http:g','http://a/b/c/g') ++ self.checkJoin(SIMPLE_BASE, 'http:','http://a/b/c/d') ++ self.checkJoin(SIMPLE_BASE, 'g','http://a/b/c/g') ++ self.checkJoin(SIMPLE_BASE, './g','http://a/b/c/g') ++ self.checkJoin(SIMPLE_BASE, 'g/','http://a/b/c/g/') ++ self.checkJoin(SIMPLE_BASE, '/g','http://a/g') ++ self.checkJoin(SIMPLE_BASE, '//g','http://g') ++ self.checkJoin(SIMPLE_BASE, '?y','http://a/b/c/d?y') ++ self.checkJoin(SIMPLE_BASE, 'g?y','http://a/b/c/g?y') ++ self.checkJoin(SIMPLE_BASE, 'g?y/./x','http://a/b/c/g?y/./x') ++ self.checkJoin(SIMPLE_BASE, '.','http://a/b/c/') ++ self.checkJoin(SIMPLE_BASE, './','http://a/b/c/') ++ self.checkJoin(SIMPLE_BASE, '..','http://a/b/') ++ self.checkJoin(SIMPLE_BASE, '../','http://a/b/') ++ self.checkJoin(SIMPLE_BASE, '../g','http://a/b/g') ++ self.checkJoin(SIMPLE_BASE, '../..','http://a/') ++ self.checkJoin(SIMPLE_BASE, '../../g','http://a/g') ++ self.checkJoin(SIMPLE_BASE, '../../../g','http://a/../g') ++ self.checkJoin(SIMPLE_BASE, './../g','http://a/b/g') ++ self.checkJoin(SIMPLE_BASE, './g/.','http://a/b/c/g/') ++ self.checkJoin(SIMPLE_BASE, '/./g','http://a/./g') ++ self.checkJoin(SIMPLE_BASE, 'g/./h','http://a/b/c/g/h') ++ self.checkJoin(SIMPLE_BASE, 'g/../h','http://a/b/c/h') ++ self.checkJoin(SIMPLE_BASE, 'http:g','http://a/b/c/g') ++ self.checkJoin(SIMPLE_BASE, 'http:','http://a/b/c/d') ++ self.checkJoin(SIMPLE_BASE, 'http:?y','http://a/b/c/d?y') ++ self.checkJoin(SIMPLE_BASE, 'http:g?y','http://a/b/c/g?y') ++ self.checkJoin(SIMPLE_BASE, 'http:g?y/./x','http://a/b/c/g?y/./x') ++ + def test_RFC2732(self): + for url, hostname, port in [ + ('http://Test.python.org:5432/foo/', 'test.python.org', 5432), +@@ -446,8 +478,28 @@ + self.assertEqual(urlparse.urlparse("x-newscheme://foo.com/stuff"), + ('x-newscheme','foo.com','/stuff','','','')) + ++ def test_withoutscheme(self): ++ # Test urlparse without scheme ++ # Issue 754016: urlparse goes wrong with IP:port without scheme ++ # RFC 1808 specifies that netloc should start with //, urlparse expects ++ # the same, otherwise it classifies the portion of url as path. ++ self.assertEqual(urlparse.urlparse("path"), ++ ('','','path','','','')) ++ self.assertEqual(urlparse.urlparse("//www.python.org:80"), ++ ('','www.python.org:80','','','','')) ++ self.assertEqual(urlparse.urlparse("http://www.python.org:80"), ++ ('http','www.python.org:80','','','','')) + ++ def test_portseparator(self): ++ # Issue 754016 makes changes for port separator ':' from scheme separator ++ self.assertEqual(urlparse.urlparse("path:80"), ++ ('','','path:80','','','')) ++ self.assertEqual(urlparse.urlparse("http:"),('http','','','','','')) ++ self.assertEqual(urlparse.urlparse("https:"),('https','','','','','')) ++ self.assertEqual(urlparse.urlparse("http://www.python.org:80"), ++ ('http','www.python.org:80','','','','')) + ++ + def test_main(): + test_support.run_unittest(UrlParseTestCase) + +--- a/Lib/test/test_coercion.py ++++ b/Lib/test/test_coercion.py +@@ -2,6 +2,7 @@ + import unittest + from test.test_support import run_unittest, TestFailed, check_warnings + ++ + # Fake a number that implements numeric methods through __coerce__ + class CoerceNumber: + def __init__(self, arg): +@@ -222,6 +223,11 @@ + infix_results[key] = res + + ++with check_warnings(("classic (int|long) division", DeprecationWarning), ++ quiet=True): ++ process_infix_results() ++ # now infix_results has two lists of results for every pairing. ++ + prefix_binops = [ 'divmod' ] + prefix_results = [ + [(1,0), (1L,0L), (0.0,2.0), ((1+0j),0j), TE, TE, TE, TE, (1,0)], +@@ -336,9 +342,6 @@ + DeprecationWarning), + ("classic (int|long) division", DeprecationWarning), + quiet=True): +- process_infix_results() +- # now infix_results has two lists of results for every pairing. +- + run_unittest(CoercionTest) + + if __name__ == "__main__": +--- a/Lib/test/test_zipfile.py ++++ b/Lib/test/test_zipfile.py +@@ -5,6 +5,7 @@ + zlib = None + + import os ++import io + import sys + import time + import shutil +@@ -653,6 +654,27 @@ + + + class OtherTests(unittest.TestCase): ++ zips_with_bad_crc = { ++ zipfile.ZIP_STORED: ( ++ b'PK\003\004\024\0\0\0\0\0 \213\212;:r' ++ b'\253\377\f\0\0\0\f\0\0\0\005\0\0\000af' ++ b'ilehello,AworldP' ++ b'K\001\002\024\003\024\0\0\0\0\0 \213\212;:' ++ b'r\253\377\f\0\0\0\f\0\0\0\005\0\0\0\0' ++ b'\0\0\0\0\0\0\0\200\001\0\0\0\000afi' ++ b'lePK\005\006\0\0\0\0\001\0\001\0003\000' ++ b'\0\0/\0\0\0\0\0'), ++ zipfile.ZIP_DEFLATED: ( ++ b'PK\x03\x04\x14\x00\x00\x00\x08\x00n}\x0c=FA' ++ b'KE\x10\x00\x00\x00n\x00\x00\x00\x05\x00\x00\x00af' ++ b'ile\xcbH\xcd\xc9\xc9W(\xcf/\xcaI\xc9\xa0' ++ b'=\x13\x00PK\x01\x02\x14\x03\x14\x00\x00\x00\x08\x00n' ++ b'}\x0c=FAKE\x10\x00\x00\x00n\x00\x00\x00\x05' ++ b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80\x01\x00\x00\x00' ++ b'\x00afilePK\x05\x06\x00\x00\x00\x00\x01\x00' ++ b'\x01\x003\x00\x00\x003\x00\x00\x00\x00\x00'), ++ } ++ + def test_unicode_filenames(self): + with zipfile.ZipFile(TESTFN, "w") as zf: + zf.writestr(u"foo.txt", "Test for unicode filename") +@@ -864,6 +886,69 @@ + with zipfile.ZipFile(TESTFN, mode="r") as zipf: + self.assertEqual(zipf.comment, comment2) + ++ def check_testzip_with_bad_crc(self, compression): ++ """Tests that files with bad CRCs return their name from testzip.""" ++ zipdata = self.zips_with_bad_crc[compression] ++ ++ with zipfile.ZipFile(io.BytesIO(zipdata), mode="r") as zipf: ++ # testzip returns the name of the first corrupt file, or None ++ self.assertEqual('afile', zipf.testzip()) ++ ++ def test_testzip_with_bad_crc_stored(self): ++ self.check_testzip_with_bad_crc(zipfile.ZIP_STORED) ++ ++ @skipUnless(zlib, "requires zlib") ++ def test_testzip_with_bad_crc_deflated(self): ++ self.check_testzip_with_bad_crc(zipfile.ZIP_DEFLATED) ++ ++ def check_read_with_bad_crc(self, compression): ++ """Tests that files with bad CRCs raise a BadZipfile exception when read.""" ++ zipdata = self.zips_with_bad_crc[compression] ++ ++ # Using ZipFile.read() ++ with zipfile.ZipFile(io.BytesIO(zipdata), mode="r") as zipf: ++ self.assertRaises(zipfile.BadZipfile, zipf.read, 'afile') ++ ++ # Using ZipExtFile.read() ++ with zipfile.ZipFile(io.BytesIO(zipdata), mode="r") as zipf: ++ with zipf.open('afile', 'r') as corrupt_file: ++ self.assertRaises(zipfile.BadZipfile, corrupt_file.read) ++ ++ # Same with small reads (in order to exercise the buffering logic) ++ with zipfile.ZipFile(io.BytesIO(zipdata), mode="r") as zipf: ++ with zipf.open('afile', 'r') as corrupt_file: ++ corrupt_file.MIN_READ_SIZE = 2 ++ with self.assertRaises(zipfile.BadZipfile): ++ while corrupt_file.read(2): ++ pass ++ ++ def test_read_with_bad_crc_stored(self): ++ self.check_read_with_bad_crc(zipfile.ZIP_STORED) ++ ++ @skipUnless(zlib, "requires zlib") ++ def test_read_with_bad_crc_deflated(self): ++ self.check_read_with_bad_crc(zipfile.ZIP_DEFLATED) ++ ++ def check_read_return_size(self, compression): ++ # Issue #9837: ZipExtFile.read() shouldn't return more bytes ++ # than requested. ++ for test_size in (1, 4095, 4096, 4097, 16384): ++ file_size = test_size + 1 ++ junk = b''.join(struct.pack('B', randint(0, 255)) ++ for x in range(file_size)) ++ with zipfile.ZipFile(io.BytesIO(), "w", compression) as zipf: ++ zipf.writestr('foo', junk) ++ with zipf.open('foo', 'r') as fp: ++ buf = fp.read(test_size) ++ self.assertEqual(len(buf), test_size) ++ ++ def test_read_return_size_stored(self): ++ self.check_read_return_size(zipfile.ZIP_STORED) ++ ++ @skipUnless(zlib, "requires zlib") ++ def test_read_return_size_deflated(self): ++ self.check_read_return_size(zipfile.ZIP_DEFLATED) ++ + def tearDown(self): + unlink(TESTFN) + unlink(TESTFN2) +@@ -963,6 +1048,11 @@ + for f in (TESTFN2, TemporaryFile(), StringIO()): + self.zip_test(f, zipfile.ZIP_STORED) + ++ @skipUnless(zlib, "requires zlib") ++ def test_deflated(self): ++ for f in (TESTFN2, TemporaryFile(), io.BytesIO()): ++ self.zip_test(f, zipfile.ZIP_DEFLATED) ++ + def zip_open_test(self, f, compression): + self.make_test_archive(f, compression) + +@@ -996,6 +1086,11 @@ + for f in (TESTFN2, TemporaryFile(), StringIO()): + self.zip_open_test(f, zipfile.ZIP_STORED) + ++ @skipUnless(zlib, "requires zlib") ++ def test_open_deflated(self): ++ for f in (TESTFN2, TemporaryFile(), io.BytesIO()): ++ self.zip_open_test(f, zipfile.ZIP_DEFLATED) ++ + def zip_random_open_test(self, f, compression): + self.make_test_archive(f, compression) + +@@ -1017,7 +1112,12 @@ + for f in (TESTFN2, TemporaryFile(), StringIO()): + self.zip_random_open_test(f, zipfile.ZIP_STORED) + ++ @skipUnless(zlib, "requires zlib") ++ def test_random_open_deflated(self): ++ for f in (TESTFN2, TemporaryFile(), io.BytesIO()): ++ self.zip_random_open_test(f, zipfile.ZIP_DEFLATED) + ++ + @skipUnless(zlib, "requires zlib") + class TestsWithMultipleOpens(unittest.TestCase): + def setUp(self): +--- a/Lib/test/test_class.py ++++ b/Lib/test/test_class.py +@@ -513,7 +513,7 @@ + + callLst[:] = [] + as_long = long(mixIntAndLong) +- self.assertEquals(type(as_long), int) ++ self.assertEquals(type(as_long), long) + self.assertEquals(as_long, 64) + self.assertCallStack([('__long__', (mixIntAndLong,))]) + +--- a/Lib/test/test_cookie.py ++++ b/Lib/test/test_cookie.py +@@ -62,6 +62,16 @@ + + """) + ++ # loading 'expires' ++ C = Cookie.SimpleCookie() ++ C.load('Customer="W"; expires=Wed, 01-Jan-2010 00:00:00 GMT') ++ self.assertEqual(C['Customer']['expires'], ++ 'Wed, 01-Jan-2010 00:00:00 GMT') ++ C = Cookie.SimpleCookie() ++ C.load('Customer="W"; expires=Wed, 01-Jan-98 00:00:00 GMT') ++ self.assertEqual(C['Customer']['expires'], ++ 'Wed, 01-Jan-98 00:00:00 GMT') ++ + def test_quoted_meta(self): + # Try cookie with quoted meta-data + C = Cookie.SimpleCookie() +--- a/Lib/test/test_urllib2.py ++++ b/Lib/test/test_urllib2.py +@@ -726,6 +726,8 @@ + ("file://ftp.example.com///foo.txt", False), + # XXXX bug: fails with OSError, should be URLError + ("file://ftp.example.com/foo.txt", False), ++ ("file://somehost//foo/something.txt", True), ++ ("file://localhost//foo/something.txt", False), + ]: + req = Request(url) + try: +@@ -736,6 +738,7 @@ + else: + self.assertTrue(o.req is req) + self.assertEqual(req.type, "ftp") ++ self.assertEqual(req.type is "ftp", ftp) + + def test_http(self): + +@@ -1234,7 +1237,17 @@ + self.assertEqual("www.python.org", self.get.get_origin_req_host()) + self.assertEqual("www.perl.org", self.get.get_host()) + ++ def test_wrapped_url(self): ++ req = Request("") ++ self.assertEqual("www.python.org", req.get_host()) + ++ def test_urlwith_fragment(self): ++ req = Request("http://www.python.org/?qs=query#fragment=true") ++ self.assertEqual("/?qs=query", req.get_selector()) ++ req = Request("http://www.python.org/#fun=true") ++ self.assertEqual("/", req.get_selector()) ++ ++ + def test_main(verbose=None): + from test import test_urllib2 + test_support.run_doctest(test_urllib2, verbose) +--- a/Lib/test/data/README ++++ b/Lib/test/data/README +@@ -0,0 +1,2 @@ ++This empty directory serves as destination for temporary files ++created by some tests. +--- a/Lib/test/test_trace.py ++++ b/Lib/test/test_trace.py +@@ -1,789 +1,341 @@ +-# Testing the line trace facility. +- +-from test import test_support +-import unittest ++import os + import sys +-import difflib +-import gc ++from test.test_support import (run_unittest, TESTFN, rmtree, unlink, ++ captured_stdout) ++import unittest + +-# A very basic example. If this fails, we're in deep trouble. +-def basic(): +- return 1 ++import trace ++from trace import CoverageResults, Trace + +-basic.events = [(0, 'call'), +- (1, 'line'), +- (1, 'return')] ++from test.tracedmodules import testmod + +-# Many of the tests below are tricky because they involve pass statements. +-# If there is implicit control flow around a pass statement (in an except +-# clause or else caluse) under what conditions do you set a line number +-# following that clause? + ++#------------------------------- Utilities -----------------------------------# + +-# The entire "while 0:" statement is optimized away. No code +-# exists for it, so the line numbers skip directly from "del x" +-# to "x = 1". +-def arigo_example(): +- x = 1 +- del x +- while 0: +- pass +- x = 1 ++def fix_ext_py(filename): ++ """Given a .pyc/.pyo filename converts it to the appropriate .py""" ++ if filename.endswith(('.pyc', '.pyo')): ++ filename = filename[:-1] ++ return filename + +-arigo_example.events = [(0, 'call'), +- (1, 'line'), +- (2, 'line'), +- (5, 'line'), +- (5, 'return')] ++def my_file_and_modname(): ++ """The .py file and module name of this file (__file__)""" ++ modname = os.path.splitext(os.path.basename(__file__))[0] ++ return fix_ext_py(__file__), modname + +-# check that lines consisting of just one instruction get traced: +-def one_instr_line(): +- x = 1 +- del x +- x = 1 ++def get_firstlineno(func): ++ return func.__code__.co_firstlineno + +-one_instr_line.events = [(0, 'call'), +- (1, 'line'), +- (2, 'line'), +- (3, 'line'), +- (3, 'return')] ++#-------------------- Target functions for tracing ---------------------------# ++# ++# The relative line numbers of lines in these functions matter for verifying ++# tracing. Please modify the appropriate tests if you change one of the ++# functions. Absolute line numbers don't matter. ++# + +-def no_pop_tops(): # 0 +- x = 1 # 1 +- for a in range(2): # 2 +- if a: # 3 +- x = 1 # 4 +- else: # 5 +- x = 1 # 6 ++def traced_func_linear(x, y): ++ a = x ++ b = y ++ c = a + b ++ return c + +-no_pop_tops.events = [(0, 'call'), +- (1, 'line'), +- (2, 'line'), +- (3, 'line'), +- (6, 'line'), +- (2, 'line'), +- (3, 'line'), +- (4, 'line'), +- (2, 'line'), +- (2, 'return')] ++def traced_func_loop(x, y): ++ c = x ++ for i in range(5): ++ c += y ++ return c + +-def no_pop_blocks(): +- y = 1 +- while not y: +- bla +- x = 1 ++def traced_func_importing(x, y): ++ return x + y + testmod.func(1) + +-no_pop_blocks.events = [(0, 'call'), +- (1, 'line'), +- (2, 'line'), +- (4, 'line'), +- (4, 'return')] ++def traced_func_simple_caller(x): ++ c = traced_func_linear(x, x) ++ return c + x + +-def called(): # line -3 +- x = 1 ++def traced_func_importing_caller(x): ++ k = traced_func_simple_caller(x) ++ k += traced_func_importing(k, x) ++ return k + +-def call(): # line 0 +- called() ++def traced_func_generator(num): ++ c = 5 # executed once ++ for i in range(num): ++ yield i + c + +-call.events = [(0, 'call'), +- (1, 'line'), +- (-3, 'call'), +- (-2, 'line'), +- (-2, 'return'), +- (1, 'return')] ++def traced_func_calling_generator(): ++ k = 0 ++ for i in traced_func_generator(10): ++ k += i + +-def raises(): +- raise Exception ++def traced_doubler(num): ++ return num * 2 + +-def test_raise(): +- try: +- raises() +- except Exception, exc: +- x = 1 ++def traced_caller_list_comprehension(): ++ k = 10 ++ mylist = [traced_doubler(i) for i in range(k)] ++ return mylist + +-test_raise.events = [(0, 'call'), +- (1, 'line'), +- (2, 'line'), +- (-3, 'call'), +- (-2, 'line'), +- (-2, 'exception'), +- (-2, 'return'), +- (2, 'exception'), +- (3, 'line'), +- (4, 'line'), +- (4, 'return')] + +-def _settrace_and_return(tracefunc): +- sys.settrace(tracefunc) +- sys._getframe().f_back.f_trace = tracefunc +-def settrace_and_return(tracefunc): +- _settrace_and_return(tracefunc) ++class TracedClass(object): ++ def __init__(self, x): ++ self.a = x + +-settrace_and_return.events = [(1, 'return')] ++ def inst_method_linear(self, y): ++ return self.a + y + +-def _settrace_and_raise(tracefunc): +- sys.settrace(tracefunc) +- sys._getframe().f_back.f_trace = tracefunc +- raise RuntimeError +-def settrace_and_raise(tracefunc): +- try: +- _settrace_and_raise(tracefunc) +- except RuntimeError, exc: +- pass ++ def inst_method_calling(self, x): ++ c = self.inst_method_linear(x) ++ return c + traced_func_linear(x, c) + +-settrace_and_raise.events = [(2, 'exception'), +- (3, 'line'), +- (4, 'line'), +- (4, 'return')] ++ @classmethod ++ def class_method_linear(cls, y): ++ return y * 2 + +-# implicit return example +-# This test is interesting because of the else: pass +-# part of the code. The code generate for the true +-# part of the if contains a jump past the else branch. +-# The compiler then generates an implicit "return None" +-# Internally, the compiler visits the pass statement +-# and stores its line number for use on the next instruction. +-# The next instruction is the implicit return None. +-def ireturn_example(): +- a = 5 +- b = 5 +- if a == b: +- b = a+1 +- else: +- pass ++ @staticmethod ++ def static_method_linear(y): ++ return y * 2 + +-ireturn_example.events = [(0, 'call'), +- (1, 'line'), +- (2, 'line'), +- (3, 'line'), +- (4, 'line'), +- (6, 'line'), +- (6, 'return')] + +-# Tight loop with while(1) example (SF #765624) +-def tightloop_example(): +- items = range(0, 3) +- try: +- i = 0 +- while 1: +- b = items[i]; i+=1 +- except IndexError: +- pass ++#------------------------------ Test cases -----------------------------------# + +-tightloop_example.events = [(0, 'call'), +- (1, 'line'), +- (2, 'line'), +- (3, 'line'), +- (4, 'line'), +- (5, 'line'), +- (5, 'line'), +- (5, 'line'), +- (5, 'line'), +- (5, 'exception'), +- (6, 'line'), +- (7, 'line'), +- (7, 'return')] + +-def tighterloop_example(): +- items = range(1, 4) +- try: +- i = 0 +- while 1: i = items[i] +- except IndexError: +- pass +- +-tighterloop_example.events = [(0, 'call'), +- (1, 'line'), +- (2, 'line'), +- (3, 'line'), +- (4, 'line'), +- (4, 'line'), +- (4, 'line'), +- (4, 'line'), +- (4, 'exception'), +- (5, 'line'), +- (6, 'line'), +- (6, 'return')] +- +-def generator_function(): +- try: +- yield True +- "continued" +- finally: +- "finally" +-def generator_example(): +- # any() will leave the generator before its end +- x = any(generator_function()) +- +- # the following lines were not traced +- for x in range(10): +- y = x +- +-generator_example.events = ([(0, 'call'), +- (2, 'line'), +- (-6, 'call'), +- (-5, 'line'), +- (-4, 'line'), +- (-4, 'return'), +- (-4, 'call'), +- (-4, 'exception'), +- (-1, 'line'), +- (-1, 'return')] + +- [(5, 'line'), (6, 'line')] * 10 + +- [(5, 'line'), (5, 'return')]) +- +- +-class Tracer: +- def __init__(self): +- self.events = [] +- def trace(self, frame, event, arg): +- self.events.append((frame.f_lineno, event)) +- return self.trace +- def traceWithGenexp(self, frame, event, arg): +- (o for o in [1]) +- self.events.append((frame.f_lineno, event)) +- return self.trace +- +-class TraceTestCase(unittest.TestCase): +- +- # Disable gc collection when tracing, otherwise the +- # deallocators may be traced as well. ++class TestLineCounts(unittest.TestCase): ++ """White-box testing of line-counting, via runfunc""" + def setUp(self): +- self.using_gc = gc.isenabled() +- gc.disable() ++ self.tracer = Trace(count=1, trace=0, countfuncs=0, countcallers=0) ++ self.my_py_filename = fix_ext_py(__file__) + +- def tearDown(self): +- if self.using_gc: +- gc.enable() ++ def test_traced_func_linear(self): ++ result = self.tracer.runfunc(traced_func_linear, 2, 5) ++ self.assertEqual(result, 7) + +- def compare_events(self, line_offset, events, expected_events): +- events = [(l - line_offset, e) for (l, e) in events] +- if events != expected_events: +- self.fail( +- "events did not match expectation:\n" + +- "\n".join(difflib.ndiff([str(x) for x in expected_events], +- [str(x) for x in events]))) ++ # all lines are executed once ++ expected = {} ++ firstlineno = get_firstlineno(traced_func_linear) ++ for i in range(1, 5): ++ expected[(self.my_py_filename, firstlineno + i)] = 1 + +- def run_and_compare(self, func, events): +- tracer = Tracer() +- sys.settrace(tracer.trace) +- func() +- sys.settrace(None) +- self.compare_events(func.func_code.co_firstlineno, +- tracer.events, events) ++ self.assertEqual(self.tracer.results().counts, expected) + +- def run_test(self, func): +- self.run_and_compare(func, func.events) ++ def test_traced_func_loop(self): ++ self.tracer.runfunc(traced_func_loop, 2, 3) + +- def run_test2(self, func): +- tracer = Tracer() +- func(tracer.trace) +- sys.settrace(None) +- self.compare_events(func.func_code.co_firstlineno, +- tracer.events, func.events) ++ firstlineno = get_firstlineno(traced_func_loop) ++ expected = { ++ (self.my_py_filename, firstlineno + 1): 1, ++ (self.my_py_filename, firstlineno + 2): 6, ++ (self.my_py_filename, firstlineno + 3): 5, ++ (self.my_py_filename, firstlineno + 4): 1, ++ } ++ self.assertEqual(self.tracer.results().counts, expected) + +- def set_and_retrieve_none(self): +- sys.settrace(None) +- assert sys.gettrace() is None ++ def test_traced_func_importing(self): ++ self.tracer.runfunc(traced_func_importing, 2, 5) + +- def set_and_retrieve_func(self): +- def fn(*args): +- pass ++ firstlineno = get_firstlineno(traced_func_importing) ++ expected = { ++ (self.my_py_filename, firstlineno + 1): 1, ++ (fix_ext_py(testmod.__file__), 2): 1, ++ (fix_ext_py(testmod.__file__), 3): 1, ++ } + +- sys.settrace(fn) +- try: +- assert sys.gettrace() is fn +- finally: +- sys.settrace(None) ++ self.assertEqual(self.tracer.results().counts, expected) + +- def test_01_basic(self): +- self.run_test(basic) +- def test_02_arigo(self): +- self.run_test(arigo_example) +- def test_03_one_instr(self): +- self.run_test(one_instr_line) +- def test_04_no_pop_blocks(self): +- self.run_test(no_pop_blocks) +- def test_05_no_pop_tops(self): +- self.run_test(no_pop_tops) +- def test_06_call(self): +- self.run_test(call) +- def test_07_raise(self): +- self.run_test(test_raise) ++ def test_trace_func_generator(self): ++ self.tracer.runfunc(traced_func_calling_generator) + +- def test_08_settrace_and_return(self): +- self.run_test2(settrace_and_return) +- def test_09_settrace_and_raise(self): +- self.run_test2(settrace_and_raise) +- def test_10_ireturn(self): +- self.run_test(ireturn_example) +- def test_11_tightloop(self): +- self.run_test(tightloop_example) +- def test_12_tighterloop(self): +- self.run_test(tighterloop_example) ++ firstlineno_calling = get_firstlineno(traced_func_calling_generator) ++ firstlineno_gen = get_firstlineno(traced_func_generator) ++ expected = { ++ (self.my_py_filename, firstlineno_calling + 1): 1, ++ (self.my_py_filename, firstlineno_calling + 2): 11, ++ (self.my_py_filename, firstlineno_calling + 3): 10, ++ (self.my_py_filename, firstlineno_gen + 1): 1, ++ (self.my_py_filename, firstlineno_gen + 2): 11, ++ (self.my_py_filename, firstlineno_gen + 3): 10, ++ } ++ self.assertEqual(self.tracer.results().counts, expected) + +- def test_13_genexp(self): +- self.run_test(generator_example) +- # issue1265: if the trace function contains a generator, +- # and if the traced function contains another generator +- # that is not completely exhausted, the trace stopped. +- # Worse: the 'finally' clause was not invoked. +- tracer = Tracer() +- sys.settrace(tracer.traceWithGenexp) +- generator_example() +- sys.settrace(None) +- self.compare_events(generator_example.__code__.co_firstlineno, +- tracer.events, generator_example.events) ++ def test_trace_list_comprehension(self): ++ self.tracer.runfunc(traced_caller_list_comprehension) + +- def test_14_onliner_if(self): +- def onliners(): +- if True: False +- else: True +- return 0 +- self.run_and_compare( +- onliners, +- [(0, 'call'), +- (1, 'line'), +- (3, 'line'), +- (3, 'return')]) ++ firstlineno_calling = get_firstlineno(traced_caller_list_comprehension) ++ firstlineno_called = get_firstlineno(traced_doubler) ++ expected = { ++ (self.my_py_filename, firstlineno_calling + 1): 1, ++ (self.my_py_filename, firstlineno_calling + 2): 11, ++ (self.my_py_filename, firstlineno_calling + 3): 1, ++ (self.my_py_filename, firstlineno_called + 1): 10, ++ } ++ self.assertEqual(self.tracer.results().counts, expected) + +- def test_15_loops(self): +- # issue1750076: "while" expression is skipped by debugger +- def for_example(): +- for x in range(2): +- pass +- self.run_and_compare( +- for_example, +- [(0, 'call'), +- (1, 'line'), +- (2, 'line'), +- (1, 'line'), +- (2, 'line'), +- (1, 'line'), +- (1, 'return')]) + +- def while_example(): +- # While expression should be traced on every loop +- x = 2 +- while x > 0: +- x -= 1 +- self.run_and_compare( +- while_example, +- [(0, 'call'), +- (2, 'line'), +- (3, 'line'), +- (4, 'line'), +- (3, 'line'), +- (4, 'line'), +- (3, 'line'), +- (3, 'return')]) ++ def test_linear_methods(self): ++ # XXX todo: later add 'static_method_linear' and 'class_method_linear' ++ # here, once issue1764286 is resolved ++ # ++ for methname in ['inst_method_linear',]: ++ tracer = Trace(count=1, trace=0, countfuncs=0, countcallers=0) ++ traced_obj = TracedClass(25) ++ method = getattr(traced_obj, methname) ++ tracer.runfunc(method, 20) + +- def test_16_blank_lines(self): +- exec("def f():\n" + "\n" * 256 + " pass") +- self.run_and_compare( +- f, +- [(0, 'call'), +- (257, 'line'), +- (257, 'return')]) ++ firstlineno = get_firstlineno(method) ++ expected = { ++ (self.my_py_filename, firstlineno + 1): 1, ++ } ++ self.assertEqual(tracer.results().counts, expected) + ++class TestRunExecCounts(unittest.TestCase): ++ """A simple sanity test of line-counting, via runctx (exec)""" ++ def setUp(self): ++ self.my_py_filename = fix_ext_py(__file__) + +-class RaisingTraceFuncTestCase(unittest.TestCase): +- def trace(self, frame, event, arg): +- """A trace function that raises an exception in response to a +- specific trace event.""" +- if event == self.raiseOnEvent: +- raise ValueError # just something that isn't RuntimeError +- else: +- return self.trace ++ def test_exec_counts(self): ++ self.tracer = Trace(count=1, trace=0, countfuncs=0, countcallers=0) ++ code = r'''traced_func_loop(2, 5)''' ++ code = compile(code, __file__, 'exec') ++ self.tracer.runctx(code, globals(), vars()) + +- def f(self): +- """The function to trace; raises an exception if that's the case +- we're testing, so that the 'exception' trace event fires.""" +- if self.raiseOnEvent == 'exception': +- x = 0 +- y = 1 // x +- else: +- return 1 ++ firstlineno = get_firstlineno(traced_func_loop) ++ expected = { ++ (self.my_py_filename, firstlineno + 1): 1, ++ (self.my_py_filename, firstlineno + 2): 6, ++ (self.my_py_filename, firstlineno + 3): 5, ++ (self.my_py_filename, firstlineno + 4): 1, ++ } + +- def run_test_for_event(self, event): +- """Tests that an exception raised in response to the given event is +- handled OK.""" +- self.raiseOnEvent = event +- try: +- for i in xrange(sys.getrecursionlimit() + 1): +- sys.settrace(self.trace) +- try: +- self.f() +- except ValueError: +- pass +- else: +- self.fail("exception not thrown!") +- except RuntimeError: +- self.fail("recursion counter not reset") ++ # When used through 'run', some other spurios counts are produced, like ++ # the settrace of threading, which we ignore, just making sure that the ++ # counts fo traced_func_loop were right. ++ # ++ for k in expected.keys(): ++ self.assertEqual(self.tracer.results().counts[k], expected[k]) + +- # Test the handling of exceptions raised by each kind of trace event. +- def test_call(self): +- self.run_test_for_event('call') +- def test_line(self): +- self.run_test_for_event('line') +- def test_return(self): +- self.run_test_for_event('return') +- def test_exception(self): +- self.run_test_for_event('exception') + +- def test_trash_stack(self): +- def f(): +- for i in range(5): +- print i # line tracing will raise an exception at this line ++class TestFuncs(unittest.TestCase): ++ """White-box testing of funcs tracing""" ++ def setUp(self): ++ self.tracer = Trace(count=0, trace=0, countfuncs=1) ++ self.filemod = my_file_and_modname() + +- def g(frame, why, extra): +- if (why == 'line' and +- frame.f_lineno == f.func_code.co_firstlineno + 2): +- raise RuntimeError, "i am crashing" +- return g ++ def test_simple_caller(self): ++ self.tracer.runfunc(traced_func_simple_caller, 1) + +- sys.settrace(g) +- try: +- f() +- except RuntimeError: +- # the test is really that this doesn't segfault: +- import gc +- gc.collect() +- else: +- self.fail("exception not propagated") ++ expected = { ++ self.filemod + ('traced_func_simple_caller',): 1, ++ self.filemod + ('traced_func_linear',): 1, ++ } ++ self.assertEqual(self.tracer.results().calledfuncs, expected) + ++ def test_loop_caller_importing(self): ++ self.tracer.runfunc(traced_func_importing_caller, 1) + +-# 'Jump' tests: assigning to frame.f_lineno within a trace function +-# moves the execution position - it's how debuggers implement a Jump +-# command (aka. "Set next statement"). ++ expected = { ++ self.filemod + ('traced_func_simple_caller',): 1, ++ self.filemod + ('traced_func_linear',): 1, ++ self.filemod + ('traced_func_importing_caller',): 1, ++ self.filemod + ('traced_func_importing',): 1, ++ (fix_ext_py(testmod.__file__), 'testmod', 'func'): 1, ++ } ++ self.assertEqual(self.tracer.results().calledfuncs, expected) + +-class JumpTracer: +- """Defines a trace function that jumps from one place to another, +- with the source and destination lines of the jump being defined by +- the 'jump' property of the function under test.""" ++ def test_inst_method_calling(self): ++ obj = TracedClass(20) ++ self.tracer.runfunc(obj.inst_method_calling, 1) + +- def __init__(self, function): +- self.function = function +- self.jumpFrom = function.jump[0] +- self.jumpTo = function.jump[1] +- self.done = False ++ expected = { ++ self.filemod + ('TracedClass.inst_method_calling',): 1, ++ self.filemod + ('TracedClass.inst_method_linear',): 1, ++ self.filemod + ('traced_func_linear',): 1, ++ } ++ self.assertEqual(self.tracer.results().calledfuncs, expected) + +- def trace(self, frame, event, arg): +- if not self.done and frame.f_code == self.function.func_code: +- firstLine = frame.f_code.co_firstlineno +- if event == 'line' and frame.f_lineno == firstLine + self.jumpFrom: +- # Cope with non-integer self.jumpTo (because of +- # no_jump_to_non_integers below). +- try: +- frame.f_lineno = firstLine + self.jumpTo +- except TypeError: +- frame.f_lineno = self.jumpTo +- self.done = True +- return self.trace + +-# The first set of 'jump' tests are for things that are allowed: ++class TestCallers(unittest.TestCase): ++ """White-box testing of callers tracing""" ++ def setUp(self): ++ self.tracer = Trace(count=0, trace=0, countcallers=1) ++ self.filemod = my_file_and_modname() + +-def jump_simple_forwards(output): +- output.append(1) +- output.append(2) +- output.append(3) ++ def test_loop_caller_importing(self): ++ self.tracer.runfunc(traced_func_importing_caller, 1) + +-jump_simple_forwards.jump = (1, 3) +-jump_simple_forwards.output = [3] ++ expected = { ++ ((os.path.splitext(trace.__file__)[0] + '.py', 'trace', 'Trace.runfunc'), ++ (self.filemod + ('traced_func_importing_caller',))): 1, ++ ((self.filemod + ('traced_func_simple_caller',)), ++ (self.filemod + ('traced_func_linear',))): 1, ++ ((self.filemod + ('traced_func_importing_caller',)), ++ (self.filemod + ('traced_func_simple_caller',))): 1, ++ ((self.filemod + ('traced_func_importing_caller',)), ++ (self.filemod + ('traced_func_importing',))): 1, ++ ((self.filemod + ('traced_func_importing',)), ++ (fix_ext_py(testmod.__file__), 'testmod', 'func')): 1, ++ } ++ self.assertEqual(self.tracer.results().callers, expected) + +-def jump_simple_backwards(output): +- output.append(1) +- output.append(2) + +-jump_simple_backwards.jump = (2, 1) +-jump_simple_backwards.output = [1, 1, 2] ++# Created separately for issue #3821 ++class TestCoverage(unittest.TestCase): ++ def tearDown(self): ++ rmtree(TESTFN) ++ unlink(TESTFN) + +-def jump_out_of_block_forwards(output): +- for i in 1, 2: +- output.append(2) +- for j in [3]: # Also tests jumping over a block +- output.append(4) +- output.append(5) ++ def _coverage(self, tracer, ++ cmd='from test import test_pprint; test_pprint.test_main()'): ++ tracer.run(cmd) ++ r = tracer.results() ++ r.write_results(show_missing=True, summary=True, coverdir=TESTFN) + +-jump_out_of_block_forwards.jump = (3, 5) +-jump_out_of_block_forwards.output = [2, 5] ++ def test_coverage(self): ++ tracer = trace.Trace(trace=0, count=1) ++ with captured_stdout() as stdout: ++ self._coverage(tracer) ++ stdout = stdout.getvalue() ++ self.assertTrue("pprint.py" in stdout) ++ self.assertTrue("case.py" in stdout) # from unittest ++ files = os.listdir(TESTFN) ++ self.assertTrue("pprint.cover" in files) ++ self.assertTrue("unittest.case.cover" in files) + +-def jump_out_of_block_backwards(output): +- output.append(1) +- for i in [1]: +- output.append(3) +- for j in [2]: # Also tests jumping over a block +- output.append(5) +- output.append(6) +- output.append(7) ++ def test_coverage_ignore(self): ++ # Ignore all files, nothing should be traced nor printed ++ libpath = os.path.normpath(os.path.dirname(os.__file__)) ++ # sys.prefix does not work when running from a checkout ++ tracer = trace.Trace(ignoredirs=[sys.prefix, sys.exec_prefix, libpath], ++ trace=0, count=1) ++ with captured_stdout() as stdout: ++ self._coverage(tracer) ++ if os.path.exists(TESTFN): ++ files = os.listdir(TESTFN) ++ self.assertEquals(files, []) + +-jump_out_of_block_backwards.jump = (6, 1) +-jump_out_of_block_backwards.output = [1, 3, 5, 1, 3, 5, 6, 7] ++ def test_issue9936(self): ++ tracer = trace.Trace(trace=0, count=1) ++ modname = 'test.tracedmodules.testmod' ++ # Ensure that the module is executed in import ++ if modname in sys.modules: ++ del sys.modules[modname] ++ cmd = ("import test.tracedmodules.testmod as t;" ++ "t.func(0); t.func2();") ++ with captured_stdout() as stdout: ++ self._coverage(tracer, cmd) ++ stdout.seek(0) ++ stdout.readline() ++ coverage = {} ++ for line in stdout: ++ lines, cov, module = line.split()[:3] ++ coverage[module] = (int(lines), int(cov[:-1])) ++ # XXX This is needed to run regrtest.py as a script ++ modname = trace.fullmodname(sys.modules[modname].__file__) ++ self.assertIn(modname, coverage) ++ self.assertEqual(coverage[modname], (5, 100)) + +-def jump_to_codeless_line(output): +- output.append(1) +- # Jumping to this line should skip to the next one. +- output.append(3) + +-jump_to_codeless_line.jump = (1, 2) +-jump_to_codeless_line.output = [3] +- +-def jump_to_same_line(output): +- output.append(1) +- output.append(2) +- output.append(3) +- +-jump_to_same_line.jump = (2, 2) +-jump_to_same_line.output = [1, 2, 3] +- +-# Tests jumping within a finally block, and over one. +-def jump_in_nested_finally(output): +- try: +- output.append(2) +- finally: +- output.append(4) +- try: +- output.append(6) +- finally: +- output.append(8) +- output.append(9) +- +-jump_in_nested_finally.jump = (4, 9) +-jump_in_nested_finally.output = [2, 9] +- +-# The second set of 'jump' tests are for things that are not allowed: +- +-def no_jump_too_far_forwards(output): +- try: +- output.append(2) +- output.append(3) +- except ValueError, e: +- output.append('after' in str(e)) +- +-no_jump_too_far_forwards.jump = (3, 6) +-no_jump_too_far_forwards.output = [2, True] +- +-def no_jump_too_far_backwards(output): +- try: +- output.append(2) +- output.append(3) +- except ValueError, e: +- output.append('before' in str(e)) +- +-no_jump_too_far_backwards.jump = (3, -1) +-no_jump_too_far_backwards.output = [2, True] +- +-# Test each kind of 'except' line. +-def no_jump_to_except_1(output): +- try: +- output.append(2) +- except: +- e = sys.exc_info()[1] +- output.append('except' in str(e)) +- +-no_jump_to_except_1.jump = (2, 3) +-no_jump_to_except_1.output = [True] +- +-def no_jump_to_except_2(output): +- try: +- output.append(2) +- except ValueError: +- e = sys.exc_info()[1] +- output.append('except' in str(e)) +- +-no_jump_to_except_2.jump = (2, 3) +-no_jump_to_except_2.output = [True] +- +-def no_jump_to_except_3(output): +- try: +- output.append(2) +- except ValueError, e: +- output.append('except' in str(e)) +- +-no_jump_to_except_3.jump = (2, 3) +-no_jump_to_except_3.output = [True] +- +-def no_jump_to_except_4(output): +- try: +- output.append(2) +- except (ValueError, RuntimeError), e: +- output.append('except' in str(e)) +- +-no_jump_to_except_4.jump = (2, 3) +-no_jump_to_except_4.output = [True] +- +-def no_jump_forwards_into_block(output): +- try: +- output.append(2) +- for i in 1, 2: +- output.append(4) +- except ValueError, e: +- output.append('into' in str(e)) +- +-no_jump_forwards_into_block.jump = (2, 4) +-no_jump_forwards_into_block.output = [True] +- +-def no_jump_backwards_into_block(output): +- try: +- for i in 1, 2: +- output.append(3) +- output.append(4) +- except ValueError, e: +- output.append('into' in str(e)) +- +-no_jump_backwards_into_block.jump = (4, 3) +-no_jump_backwards_into_block.output = [3, 3, True] +- +-def no_jump_into_finally_block(output): +- try: +- try: +- output.append(3) +- x = 1 +- finally: +- output.append(6) +- except ValueError, e: +- output.append('finally' in str(e)) +- +-no_jump_into_finally_block.jump = (4, 6) +-no_jump_into_finally_block.output = [3, 6, True] # The 'finally' still runs +- +-def no_jump_out_of_finally_block(output): +- try: +- try: +- output.append(3) +- finally: +- output.append(5) +- output.append(6) +- except ValueError, e: +- output.append('finally' in str(e)) +- +-no_jump_out_of_finally_block.jump = (5, 1) +-no_jump_out_of_finally_block.output = [3, True] +- +-# This verifies the line-numbers-must-be-integers rule. +-def no_jump_to_non_integers(output): +- try: +- output.append(2) +- except ValueError, e: +- output.append('integer' in str(e)) +- +-no_jump_to_non_integers.jump = (2, "Spam") +-no_jump_to_non_integers.output = [True] +- +-# This verifies that you can't set f_lineno via _getframe or similar +-# trickery. +-def no_jump_without_trace_function(): +- try: +- previous_frame = sys._getframe().f_back +- previous_frame.f_lineno = previous_frame.f_lineno +- except ValueError, e: +- # This is the exception we wanted; make sure the error message +- # talks about trace functions. +- if 'trace' not in str(e): +- raise +- else: +- # Something's wrong - the expected exception wasn't raised. +- raise RuntimeError, "Trace-function-less jump failed to fail" +- +- +-class JumpTestCase(unittest.TestCase): +- def compare_jump_output(self, expected, received): +- if received != expected: +- self.fail( "Outputs don't match:\n" + +- "Expected: " + repr(expected) + "\n" + +- "Received: " + repr(received)) +- +- def run_test(self, func): +- tracer = JumpTracer(func) +- sys.settrace(tracer.trace) +- output = [] +- func(output) +- sys.settrace(None) +- self.compare_jump_output(func.output, output) +- +- def test_01_jump_simple_forwards(self): +- self.run_test(jump_simple_forwards) +- def test_02_jump_simple_backwards(self): +- self.run_test(jump_simple_backwards) +- def test_03_jump_out_of_block_forwards(self): +- self.run_test(jump_out_of_block_forwards) +- def test_04_jump_out_of_block_backwards(self): +- self.run_test(jump_out_of_block_backwards) +- def test_05_jump_to_codeless_line(self): +- self.run_test(jump_to_codeless_line) +- def test_06_jump_to_same_line(self): +- self.run_test(jump_to_same_line) +- def test_07_jump_in_nested_finally(self): +- self.run_test(jump_in_nested_finally) +- def test_08_no_jump_too_far_forwards(self): +- self.run_test(no_jump_too_far_forwards) +- def test_09_no_jump_too_far_backwards(self): +- self.run_test(no_jump_too_far_backwards) +- def test_10_no_jump_to_except_1(self): +- self.run_test(no_jump_to_except_1) +- def test_11_no_jump_to_except_2(self): +- self.run_test(no_jump_to_except_2) +- def test_12_no_jump_to_except_3(self): +- self.run_test(no_jump_to_except_3) +- def test_13_no_jump_to_except_4(self): +- self.run_test(no_jump_to_except_4) +- def test_14_no_jump_forwards_into_block(self): +- self.run_test(no_jump_forwards_into_block) +- def test_15_no_jump_backwards_into_block(self): +- self.run_test(no_jump_backwards_into_block) +- def test_16_no_jump_into_finally_block(self): +- self.run_test(no_jump_into_finally_block) +- def test_17_no_jump_out_of_finally_block(self): +- self.run_test(no_jump_out_of_finally_block) +- def test_18_no_jump_to_non_integers(self): +- self.run_test(no_jump_to_non_integers) +- def test_19_no_jump_without_trace_function(self): +- no_jump_without_trace_function() +- +- def test_20_large_function(self): +- d = {} +- exec("""def f(output): # line 0 +- x = 0 # line 1 +- y = 1 # line 2 +- ''' # line 3 +- %s # lines 4-1004 +- ''' # line 1005 +- x += 1 # line 1006 +- output.append(x) # line 1007 +- return""" % ('\n' * 1000,), d) +- f = d['f'] +- +- f.jump = (2, 1007) +- f.output = [0] +- self.run_test(f) +- +- def test_jump_to_firstlineno(self): +- # This tests that PDB can jump back to the first line in a +- # file. See issue #1689458. It can only be triggered in a +- # function call if the function is defined on a single line. +- code = compile(""" +-# Comments don't count. +-output.append(2) # firstlineno is here. +-output.append(3) +-output.append(4) +-""", "", "exec") +- class fake_function: +- func_code = code +- jump = (2, 0) +- tracer = JumpTracer(fake_function) +- sys.settrace(tracer.trace) +- namespace = {"output": []} +- exec code in namespace +- sys.settrace(None) +- self.compare_jump_output([2, 3, 2, 3, 4], namespace["output"]) +- +- + def test_main(): +- test_support.run_unittest( +- TraceTestCase, +- RaisingTraceFuncTestCase, +- JumpTestCase +- ) ++ run_unittest(__name__) + +-if __name__ == "__main__": ++ ++if __name__ == '__main__': + test_main() + +Property changes on: Lib/test/test_trace.py +___________________________________________________________________ +Deleted: svn:keywords + - Author Date Id Revision +Deleted: svn:eol-style + - native + +--- a/Lib/test/test_threading.py ++++ b/Lib/test/test_threading.py +@@ -307,7 +307,7 @@ + # Issue1733757 + # Avoid a deadlock when sys.settrace steps into threading._shutdown + import subprocess +- rc = subprocess.call([sys.executable, "-c", """if 1: ++ p = subprocess.Popen([sys.executable, "-c", """if 1: + import sys, threading + + # A deadlock-killer, to prevent the +@@ -327,9 +327,14 @@ + return func + + sys.settrace(func) +- """]) ++ """], ++ stdout=subprocess.PIPE, ++ stderr=subprocess.PIPE) ++ stdout, stderr = p.communicate() ++ rc = p.returncode + self.assertFalse(rc == 2, "interpreted was blocked") +- self.assertTrue(rc == 0, "Unexpected error") ++ self.assertTrue(rc == 0, ++ "Unexpected error: " + repr(stderr)) + + def test_join_nondaemon_on_shutdown(self): + # Issue 1722344 +--- a/Lib/test/tracedmodules/__init__.py ++++ b/Lib/test/tracedmodules/__init__.py +@@ -0,0 +1,4 @@ ++"""This package contains modules that help testing the trace.py module. Note ++that the exact location of functions in these modules is important, as trace.py ++takes the real line numbers into account. ++""" + +Property changes on: Lib/test/tracedmodules/__init__.py +___________________________________________________________________ +Added: svn:eol-style + + native + +--- a/Lib/test/tracedmodules/testmod.py ++++ b/Lib/test/tracedmodules/testmod.py +@@ -0,0 +1,9 @@ ++def func(x): ++ b = x + 1 ++ return b + 2 ++ ++def func2(): ++ """Test function for issue 9936 """ ++ return (1, ++ 2, ++ 3) + +Property changes on: Lib/test/tracedmodules/testmod.py +___________________________________________________________________ +Added: svn:eol-style + + native + + +Property changes on: Lib/test/tracedmodules +___________________________________________________________________ +Added: svn:ignore + + *.pyc +*.pyo + + +--- a/Lib/test/test_multibytecodec_support.py ++++ b/Lib/test/test_multibytecodec_support.py +@@ -252,7 +252,7 @@ + def __init__(self, *args, **kw): + unittest.TestCase.__init__(self, *args, **kw) + try: +- self.open_mapping_file() # test it to report the error early ++ self.open_mapping_file().close() # test it to report the error early + except (IOError, HTTPException): + self.skipTest("Could not retrieve "+self.mapfileurl) + +@@ -270,36 +270,38 @@ + unichrs = lambda s: u''.join(_unichr(c) for c in s.split('+')) + urt_wa = {} + +- for line in self.open_mapping_file(): +- if not line: +- break +- data = line.split('#')[0].strip().split() +- if len(data) != 2: +- continue ++ with self.open_mapping_file() as f: ++ for line in f: ++ if not line: ++ break ++ data = line.split('#')[0].strip().split() ++ if len(data) != 2: ++ continue + +- csetval = eval(data[0]) +- if csetval <= 0x7F: +- csetch = chr(csetval & 0xff) +- elif csetval >= 0x1000000: +- csetch = chr(csetval >> 24) + chr((csetval >> 16) & 0xff) + \ +- chr((csetval >> 8) & 0xff) + chr(csetval & 0xff) +- elif csetval >= 0x10000: +- csetch = chr(csetval >> 16) + \ +- chr((csetval >> 8) & 0xff) + chr(csetval & 0xff) +- elif csetval >= 0x100: +- csetch = chr(csetval >> 8) + chr(csetval & 0xff) +- else: +- continue ++ csetval = eval(data[0]) ++ if csetval <= 0x7F: ++ csetch = chr(csetval & 0xff) ++ elif csetval >= 0x1000000: ++ csetch = chr(csetval >> 24) + chr((csetval >> 16) & 0xff) + \ ++ chr((csetval >> 8) & 0xff) + chr(csetval & 0xff) ++ elif csetval >= 0x10000: ++ csetch = chr(csetval >> 16) + \ ++ chr((csetval >> 8) & 0xff) + chr(csetval & 0xff) ++ elif csetval >= 0x100: ++ csetch = chr(csetval >> 8) + chr(csetval & 0xff) ++ else: ++ continue + +- unich = unichrs(data[1]) +- if unich == u'\ufffd' or unich in urt_wa: +- continue +- urt_wa[unich] = csetch ++ unich = unichrs(data[1]) ++ if unich == u'\ufffd' or unich in urt_wa: ++ continue ++ urt_wa[unich] = csetch + +- self._testpoint(csetch, unich) ++ self._testpoint(csetch, unich) + + def _test_mapping_file_ucm(self): +- ucmdata = self.open_mapping_file().read() ++ with self.open_mapping_file() as f: ++ ucmdata = f.read() + uc = re.findall('
', ucmdata) + for uni, coded in uc: + unich = unichr(int(uni, 16)) +--- a/Lib/test/test_support.py ++++ b/Lib/test/test_support.py +@@ -105,7 +105,7 @@ + orig_modules[name] = sys.modules[name] + except KeyError: + saved = False +- sys.modules[name] = 0 ++ sys.modules[name] = None + return saved + + +@@ -361,30 +361,30 @@ + # 2 latin characters. + TESTFN_UNICODE = unicode("@test-\xe0\xf2", "latin-1") + TESTFN_ENCODING = sys.getfilesystemencoding() +- # TESTFN_UNICODE_UNENCODEABLE is a filename that should *not* be ++ # TESTFN_UNENCODABLE is a filename that should *not* be + # able to be encoded by *either* the default or filesystem encoding. + # This test really only makes sense on Windows NT platforms + # which have special Unicode support in posixmodule. + if (not hasattr(sys, "getwindowsversion") or + sys.getwindowsversion()[3] < 2): # 0=win32s or 1=9x/ME +- TESTFN_UNICODE_UNENCODEABLE = None ++ TESTFN_UNENCODABLE = None + else: + # Japanese characters (I think - from bug 846133) +- TESTFN_UNICODE_UNENCODEABLE = eval('u"@test-\u5171\u6709\u3055\u308c\u308b"') ++ TESTFN_UNENCODABLE = eval('u"@test-\u5171\u6709\u3055\u308c\u308b"') + try: + # XXX - Note - should be using TESTFN_ENCODING here - but for + # Windows, "mbcs" currently always operates as if in + # errors=ignore' mode - hence we get '?' characters rather than + # the exception. 'Latin1' operates as we expect - ie, fails. + # See [ 850997 ] mbcs encoding ignores errors +- TESTFN_UNICODE_UNENCODEABLE.encode("Latin1") ++ TESTFN_UNENCODABLE.encode("Latin1") + except UnicodeEncodeError: + pass + else: + print \ + 'WARNING: The filename %r CAN be encoded by the filesystem. ' \ + 'Unicode filename tests may not be effective' \ +- % TESTFN_UNICODE_UNENCODEABLE ++ % TESTFN_UNENCODABLE + + + # Disambiguate TESTFN for parallel testing, while letting it remain a valid +@@ -750,32 +750,64 @@ + raise ResourceDenied("an optional resource is not available") + + +-_transients = { +- IOError: (errno.ECONNRESET, errno.ETIMEDOUT), +- socket.error: (errno.ECONNRESET,), +- socket.gaierror: [getattr(socket, t) +- for t in ('EAI_NODATA', 'EAI_NONAME') +- if hasattr(socket, t)], +- } + @contextlib.contextmanager +-def transient_internet(): ++def transient_internet(resource_name, timeout=30.0, errnos=()): + """Return a context manager that raises ResourceDenied when various issues +- with the Internet connection manifest themselves as exceptions. ++ with the Internet connection manifest themselves as exceptions.""" ++ default_errnos = [ ++ ('ECONNREFUSED', 111), ++ ('ECONNRESET', 104), ++ ('ENETUNREACH', 101), ++ ('ETIMEDOUT', 110), ++ ] ++ default_gai_errnos = [ ++ ('EAI_NONAME', -2), ++ ('EAI_NODATA', -5), ++ ] + +- Errors caught: +- timeout IOError errno = ETIMEDOUT +- socket reset socket.error, IOError errno = ECONNRESET +- dns no data socket.gaierror errno = EAI_NODATA +- dns no name socket.gaierror errno = EAI_NONAME +- """ ++ denied = ResourceDenied("Resource '%s' is not available" % resource_name) ++ captured_errnos = errnos ++ gai_errnos = [] ++ if not captured_errnos: ++ captured_errnos = [getattr(errno, name, num) ++ for (name, num) in default_errnos] ++ gai_errnos = [getattr(socket, name, num) ++ for (name, num) in default_gai_errnos] ++ ++ def filter_error(err): ++ n = getattr(err, 'errno', None) ++ if (isinstance(err, socket.timeout) or ++ (isinstance(err, socket.gaierror) and n in gai_errnos) or ++ n in captured_errnos): ++ if not verbose: ++ sys.stderr.write(denied.args[0] + "\n") ++ raise denied ++ ++ old_timeout = socket.getdefaulttimeout() + try: ++ if timeout is not None: ++ socket.setdefaulttimeout(timeout) + yield +- except tuple(_transients) as err: +- for errtype in _transients: +- if isinstance(err, errtype) and err.errno in _transients[errtype]: +- raise ResourceDenied("could not establish network " +- "connection ({})".format(err)) ++ except IOError as err: ++ # urllib can wrap original socket errors multiple times (!), we must ++ # unwrap to get at the original error. ++ while True: ++ a = err.args ++ if len(a) >= 1 and isinstance(a[0], IOError): ++ err = a[0] ++ # The error can also be wrapped as args[1]: ++ # except socket.error as msg: ++ # raise IOError('socket error', msg).with_traceback(sys.exc_info()[2]) ++ elif len(a) >= 2 and isinstance(a[1], IOError): ++ err = a[1] ++ else: ++ break ++ filter_error(err) + raise ++ # XXX should we catch generic exceptions and look for their ++ # __cause__ or __context__? ++ finally: ++ socket.setdefaulttimeout(old_timeout) + + + @contextlib.contextmanager +@@ -972,7 +1004,7 @@ + return obj + + def requires_resource(resource): +- if resource_is_enabled(resource): ++ if is_resource_enabled(resource): + return _id + else: + return unittest.skip("resource {0!r} is not enabled".format(resource)) +@@ -1167,3 +1199,23 @@ + return b"".join(chr(x) for x in b) + except TypeError: + return bytes(b) ++ ++def args_from_interpreter_flags(): ++ """Return a list of command-line arguments reproducing the current ++ settings in sys.flags.""" ++ flag_opt_map = { ++ 'bytes_warning': 'b', ++ 'dont_write_bytecode': 'B', ++ 'ignore_environment': 'E', ++ 'no_user_site': 's', ++ 'no_site': 'S', ++ 'optimize': 'O', ++ 'py3k_warning': '3', ++ 'verbose': 'v', ++ } ++ args = [] ++ for flag, opt in flag_opt_map.items(): ++ v = getattr(sys.flags, flag) ++ if v > 0: ++ args.append('-' + opt * v) ++ return args +--- a/Lib/test/test_collections.py ++++ b/Lib/test/test_collections.py +@@ -526,6 +526,21 @@ + s = MySet([5,43,2,1]) + self.assertEqual(s.pop(), 1) + ++ def test_issue8750(self): ++ empty = WithSet() ++ full = WithSet(range(10)) ++ s = WithSet(full) ++ s -= s ++ self.assertEqual(s, empty) ++ s = WithSet(full) ++ s ^= s ++ self.assertEqual(s, empty) ++ s = WithSet(full) ++ s &= s ++ self.assertEqual(s, full) ++ s |= s ++ self.assertEqual(s, full) ++ + def test_Mapping(self): + for sample in [dict]: + self.assertIsInstance(sample(), Mapping) +@@ -766,6 +781,19 @@ + od.update([('a', 1), ('b', 2), ('c', 9), ('d', 4)], c=3, e=5) + self.assertEqual(list(od.items()), pairs) # mixed input + ++ # Issue 9137: Named argument called 'other' or 'self' ++ # shouldn't be treated specially. ++ od = OrderedDict() ++ od.update(self=23) ++ self.assertEqual(list(od.items()), [('self', 23)]) ++ od = OrderedDict() ++ od.update(other={}) ++ self.assertEqual(list(od.items()), [('other', {})]) ++ od = OrderedDict() ++ od.update(red=5, blue=6, other=7, self=8) ++ self.assertEqual(sorted(list(od.items())), ++ [('blue', 6), ('other', 7), ('red', 5), ('self', 8)]) ++ + # Make sure that direct calls to update do not clear previous contents + # add that updates items are not moved to the end + d = OrderedDict([('a', 1), ('b', 2), ('c', 3), ('d', 44), ('e', 55)]) +@@ -898,6 +926,13 @@ + self.assertEqual(eval(repr(od)), od) + self.assertEqual(repr(OrderedDict()), "OrderedDict()") + ++ def test_repr_recursive(self): ++ # See issue #9826 ++ od = OrderedDict.fromkeys('abc') ++ od['x'] = od ++ self.assertEqual(repr(od), ++ "OrderedDict([('a', None), ('b', None), ('c', None), ('x', ...)])") ++ + def test_setdefault(self): + pairs = [('c', 1), ('b', 2), ('a', 3), ('d', 4), ('e', 5), ('f', 6)] + shuffle(pairs) +@@ -920,6 +955,12 @@ + od['a'] = 1 + self.assertEqual(list(od.items()), [('b', 2), ('a', 1)]) + ++ def test_views(self): ++ s = 'the quick brown fox jumped over a lazy dog yesterday before dawn'.split() ++ od = OrderedDict.fromkeys(s) ++ self.assertEqual(list(od.viewkeys()), s) ++ self.assertEqual(list(od.viewvalues()), [None for k in s]) ++ self.assertEqual(list(od.viewitems()), [(k, None) for k in s]) + + + class GeneralMappingTests(mapping_tests.BasicTestMappingProtocol): +--- a/Lib/test/test_sys.py ++++ b/Lib/test/test_sys.py +@@ -205,8 +205,8 @@ + # can't check more than the type, as the user might have changed it + self.assertIsInstance(sys.getdefaultencoding(), str) + +- # testing sys.settrace() is done in test_trace.py +- # testing sys.setprofile() is done in test_profile.py ++ # testing sys.settrace() is done in test_sys_settrace.py ++ # testing sys.setprofile() is done in test_sys_setprofile.py + + def test_setcheckinterval(self): + self.assertRaises(TypeError, sys.setcheckinterval) +--- a/Lib/test/test_urllib2net.py ++++ b/Lib/test/test_urllib2net.py +@@ -154,6 +154,36 @@ + + ## self._test_urls(urls, self._extra_handlers()+[bauth, dauth]) + ++ def test_urlwithfrag(self): ++ urlwith_frag = "http://docs.python.org/glossary.html#glossary" ++ req = urllib2.Request(urlwith_frag) ++ res = urllib2.urlopen(req) ++ self.assertEqual(res.geturl(), ++ "http://docs.python.org/glossary.html") ++ ++ def test_fileno(self): ++ req = urllib2.Request("http://www.python.org") ++ opener = urllib2.build_opener() ++ res = opener.open(req) ++ try: ++ res.fileno() ++ except AttributeError: ++ self.fail("HTTPResponse object should return a valid fileno") ++ finally: ++ res.close() ++ ++ def test_custom_headers(self): ++ url = "http://www.example.com" ++ opener = urllib2.build_opener() ++ request = urllib2.Request(url) ++ self.assertFalse(request.header_items()) ++ opener.open(request) ++ self.assertTrue(request.header_items()) ++ self.assertTrue(request.has_header('User-agent')) ++ request.add_header('User-Agent','Test-Agent') ++ opener.open(request) ++ self.assertEqual(request.get_header('User-agent'),'Test-Agent') ++ + def _test_urls(self, urls, handlers, retry=True): + import time + import logging +@@ -185,7 +215,7 @@ + raise + else: + try: +- with test_support.transient_internet(): ++ with test_support.transient_internet(url): + buf = f.read() + debug("read %d bytes" % len(buf)) + except socket.timeout: +--- a/Lib/timeit.py ++++ b/Lib/timeit.py +@@ -9,7 +9,7 @@ + Library usage: see the Timer class. + + Command line usage: +- python timeit.py [-n N] [-r N] [-s S] [-t] [-c] [-h] [statement] ++ python timeit.py [-n N] [-r N] [-s S] [-t] [-c] [-h] [--] [statement] + + Options: + -n/--number N: how many times to execute 'statement' (default: see below) +@@ -19,6 +19,7 @@ + -c/--clock: use time.clock() (default on Windows) + -v/--verbose: print raw timing results; repeat for more digits precision + -h/--help: print this usage message and exit ++ --: separate options from statement, use when statement starts with - + statement: statement to be timed (default 'pass') + + A multi-line statement may be given by specifying each line as a +--- a/Lib/urlparse.py ++++ b/Lib/urlparse.py +@@ -187,11 +187,12 @@ + v = SplitResult(scheme, netloc, url, query, fragment) + _parse_cache[key] = v + return v +- for c in url[:i]: +- if c not in scheme_chars: +- break +- else: +- scheme, url = url[:i].lower(), url[i+1:] ++ if url.endswith(':') or not url[i+1].isdigit(): ++ for c in url[:i]: ++ if c not in scheme_chars: ++ break ++ else: ++ scheme, url = url[:i].lower(), url[i+1:] + + if url[:2] == '//': + netloc, url = _splitnetloc(url, 2) +@@ -335,10 +336,10 @@ + + Arguments: + +- qs: URL-encoded query string to be parsed ++ qs: percent-encoded query string to be parsed + + keep_blank_values: flag indicating whether blank values in +- URL encoded queries should be treated as blank strings. ++ percent-encoded queries should be treated as blank strings. + A true value indicates that blanks should be retained as + blank strings. The default false value indicates that + blank values are to be ignored and treated as if they were +@@ -361,10 +362,10 @@ + + Arguments: + +- qs: URL-encoded query string to be parsed ++ qs: percent-encoded query string to be parsed + + keep_blank_values: flag indicating whether blank values in +- URL encoded queries should be treated as blank strings. A ++ percent-encoded queries should be treated as blank strings. A + true value indicates that blanks should be retained as blank + strings. The default false value indicates that blank values + are to be ignored and treated as if they were not included. +@@ -395,72 +396,3 @@ + r.append((name, value)) + + return r +- +- +-test_input = """ +- http://a/b/c/d +- +- g:h = +- http:g = +- http: = +- g = +- ./g = +- g/ = +- /g = +- //g = +- ?y = +- g?y = +- g?y/./x = +- . = +- ./ = +- .. = +- ../ = +- ../g = +- ../.. = +- ../../g = +- ../../../g = +- ./../g = +- ./g/. = +- /./g = +- g/./h = +- g/../h = +- http:g = +- http: = +- http:?y = +- http:g?y = +- http:g?y/./x = +-""" +- +-def test(): +- import sys +- base = '' +- if sys.argv[1:]: +- fn = sys.argv[1] +- if fn == '-': +- fp = sys.stdin +- else: +- fp = open(fn) +- else: +- try: +- from cStringIO import StringIO +- except ImportError: +- from StringIO import StringIO +- fp = StringIO(test_input) +- for line in fp: +- words = line.split() +- if not words: +- continue +- url = words[0] +- parts = urlparse(url) +- print '%-10s : %s' % (url, parts) +- abs = urljoin(base, url) +- if not base: +- base = abs +- wrapped = '' % abs +- print '%-10s = %s' % (url, wrapped) +- if len(words) == 3 and words[1] == '=': +- if wrapped != words[2]: +- print 'EXPECTED', words[2], '!!!!!!!!!!' +- +-if __name__ == '__main__': +- test() +--- a/Lib/xml/dom/expatbuilder.py ++++ b/Lib/xml/dom/expatbuilder.py +@@ -242,7 +242,7 @@ + doctype = self.document.implementation.createDocumentType( + doctypeName, publicId, systemId) + doctype.ownerDocument = self.document +- self.document.childNodes.append(doctype) ++ _append_child(self.document, doctype) + self.document.doctype = doctype + if self._filter and self._filter.acceptNode(doctype) == FILTER_REJECT: + self.document.doctype = None +--- a/Lib/xml/dom/minidom.py ++++ b/Lib/xml/dom/minidom.py +@@ -890,6 +890,10 @@ + raise xml.dom.NotFoundErr( + self.nodeName + " nodes do not have children") + ++ def normalize(self): ++ # For childless nodes, normalize() has nothing to do. ++ pass ++ + def replaceChild(self, newChild, oldChild): + raise xml.dom.HierarchyRequestErr( + self.nodeName + " nodes do not have children") +--- a/Lib/xml/etree/ElementInclude.py ++++ b/Lib/xml/etree/ElementInclude.py +@@ -125,7 +125,7 @@ + ) + if i: + node = elem[i-1] +- node.tail = (node.tail or "") + text ++ node.tail = (node.tail or "") + text + (e.tail or "") + else: + elem.text = (elem.text or "") + text + (e.tail or "") + del elem[i] +--- a/Makefile.pre.in ++++ b/Makefile.pre.in +@@ -105,8 +105,8 @@ + + # Symbols used for using shared libraries + SO= @SO@ +-LDSHARED= @LDSHARED@ +-BLDSHARED= @BLDSHARED@ ++LDSHARED= @LDSHARED@ $(LDFLAGS) ++BLDSHARED= @BLDSHARED@ $(LDFLAGS) + LDCXXSHARED= @LDCXXSHARED@ + DESTSHARED= $(BINLIBDEST)/lib-dynload + +@@ -404,8 +404,8 @@ + # Build the shared modules + sharedmods: $(BUILDPYTHON) + @case $$MAKEFLAGS in \ +- *s*) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' LDFLAGS='$(LDFLAGS)' OPT='$(OPT)' ./$(BUILDPYTHON) -E $(srcdir)/setup.py -q build;; \ +- *) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' LDFLAGS='$(LDFLAGS)' OPT='$(OPT)' ./$(BUILDPYTHON) -E $(srcdir)/setup.py build;; \ ++ *s*) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' ./$(BUILDPYTHON) -E $(srcdir)/setup.py -q build;; \ ++ *) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' ./$(BUILDPYTHON) -E $(srcdir)/setup.py build;; \ + esac + + # Build static library +@@ -422,10 +422,10 @@ + + libpython$(VERSION).so: $(LIBRARY_OBJS) + if test $(INSTSONAME) != $(LDLIBRARY); then \ +- $(LDSHARED) $(LDFLAGS) -Wl,-h$(INSTSONAME) -o $(INSTSONAME) $(LIBRARY_OBJS) $(MODLIBS) $(SHLIBS) $(LIBC) $(LIBM) $(LDLAST); \ ++ $(BLDSHARED) -Wl,-h$(INSTSONAME) -o $(INSTSONAME) $(LIBRARY_OBJS) $(MODLIBS) $(SHLIBS) $(LIBC) $(LIBM) $(LDLAST); \ + $(LN) -f $(INSTSONAME) $@; \ + else \ +- $(LDSHARED) $(LDFLAGS) -o $@ $(LIBRARY_OBJS) $(MODLIBS) $(SHLIBS) $(LIBC) $(LIBM) $(LDLAST); \ ++ $(BLDSHARED) -o $@ $(LIBRARY_OBJS) $(MODLIBS) $(SHLIBS) $(LIBC) $(LIBM) $(LDLAST); \ + fi + + libpython$(VERSION).dylib: $(LIBRARY_OBJS) +@@ -433,7 +433,7 @@ + + + libpython$(VERSION).sl: $(LIBRARY_OBJS) +- $(LDSHARED) $(LDFLAGS) -o $@ $(LIBRARY_OBJS) $(MODLIBS) $(SHLIBS) $(LIBC) $(LIBM) $(LDLAST) ++ $(LDSHARED) -o $@ $(LIBRARY_OBJS) $(MODLIBS) $(SHLIBS) $(LIBC) $(LIBM) $(LDLAST) + + # Copy up the gdb python hooks into a position where they can be automatically + # loaded by gdb during Lib/test/test_gdb.py +@@ -478,7 +478,7 @@ + # for a shared core library; otherwise, this rule is a noop. + $(DLLLIBRARY) libpython$(VERSION).dll.a: $(LIBRARY_OBJS) + if test -n "$(DLLLIBRARY)"; then \ +- $(LDSHARED) $(LDFLAGS) -Wl,--out-implib=$@ -o $(DLLLIBRARY) $^ \ ++ $(LDSHARED) -Wl,--out-implib=$@ -o $(DLLLIBRARY) $^ \ + $(LIBS) $(MODLIBS) $(SYSLIBS) $(LDLAST); \ + else true; \ + fi +@@ -702,7 +702,7 @@ + + TESTOPTS= -l $(EXTRATESTOPTS) + TESTPROG= $(srcdir)/Lib/test/regrtest.py +-TESTPYTHON= $(RUNSHARED) ./$(BUILDPYTHON) -Wd -3 -E -tt ++TESTPYTHON= $(RUNSHARED) ./$(BUILDPYTHON) -Wd -3 -E -tt $(TESTPYTHONOPTS) + test: all platform + -find $(srcdir)/Lib -name '*.py[co]' -print | xargs rm -f + -$(TESTPYTHON) $(TESTPROG) $(TESTOPTS) +@@ -850,6 +850,7 @@ + LIBSUBDIRS= lib-tk lib-tk/test lib-tk/test/test_tkinter \ + lib-tk/test/test_ttk site-packages test test/data \ + test/decimaltestdata test/xmltestdata \ ++ test/tracedmodules \ + encodings compiler hotshot \ + email email/mime email/test email/test/data \ + json json/tests \ +@@ -1042,7 +1043,7 @@ + + # Install the dynamically loadable modules + # This goes into $(exec_prefix) +-sharedinstall: ++sharedinstall: sharedmods + $(RUNSHARED) ./$(BUILDPYTHON) -E $(srcdir)/setup.py install \ + --prefix=$(prefix) \ + --install-scripts=$(BINDIR) \ +@@ -1171,8 +1172,9 @@ + find $(srcdir) -name '*.py[co]' -exec rm -f {} ';' + + clean: pycremoval +- find . -name '*.o' -exec rm -f {} ';' ++ find . -name '*.[oa]' -exec rm -f {} ';' + find . -name '*.s[ol]' -exec rm -f {} ';' ++ find . -name '*.so.[0-9]*.[0-9]*' -exec rm -f {} ';' + find build -name 'fficonfig.h' -exec rm -f {} ';' || true + find build -name 'fficonfig.py' -exec rm -f {} ';' || true + -rm -f Lib/lib2to3/*Grammar*.pickle +@@ -1191,10 +1193,12 @@ + # remove all generated files, even Makefile[.pre] + # Keep configure and Python-ast.[ch], it's possible they can't be generated + distclean: clobber +- -rm -f Lib/test/data/* ++ for file in Lib/test/data/* ; do \ ++ if test "$$file" != "Lib/test/data/README"; then rm "$$file"; fi; \ ++ done + -rm -f core Makefile Makefile.pre config.status \ + Modules/Setup Modules/Setup.local Modules/Setup.config \ +- Misc/python.pc ++ Modules/ld_so_aix Misc/python.pc + -rm -f python*-gdb.py + find $(srcdir) '(' -name '*.fdc' -o -name '*~' \ + -o -name '[@,#]*' -o -name '*.old' \ +--- a/Modules/ld_so_aix ++++ b/Modules/ld_so_aix +@@ -1,190 +0,0 @@ +-#!/bin/sh +-# +-# ======================================================================== +-# FILE: ld_so_aix +-# TYPE: executable, uses makexp_aix +-# SYSTEM: AIX +-# +-# DESCRIPTION: Creates a shareable .o from a set of pre-compiled +-# (unshared) .o files +-# +-# USAGE: ld_so_aix [CC] [arguments] +-# +-# ARGUMENTS: Same as for "ld". The following arguments are processed +-# or supplied by this script (those marked with an asterisk +-# can be overriden from command line): +-# +-# Argument Default value +-# (*) -o [OutputFileName] -o shr.o +-# (*) -e [EntryPointLabel] -e init[OutputBaseName] +-# (*) -bE:[ExportFile] -bE:[OutputBaseName].exp +-# (*) -bI:[ImportFile] -bI:./python.exp +-# -bM:[ModuleType] -bM:SRE +-# -bhalt:[Number] -bhalt:4 +-# -T[Number] -T512 +-# -H[Number] -H512 +-# -lm +-# +-# The compiler specific ("-lc" or "-lc_r", "-lpthreads",...) +-# arguments will be automatically passed to "ld" according +-# to the CC command provided as a first argument to this +-# script. Usually, the same CC command was used to produce +-# the pre-compiled .o file(s). +-# +-# NOTES: 1. Since "ld_so_aix" was originally written for building +-# shared modules for the Python interpreter, the -e and +-# -bI default values match Python's conventions. In +-# Python, the entry point for a shared module is based +-# on the module's name (e.g., the "mathmodule" will +-# expect an entry point of "initmath"). +-# 2. The script accepts multiple .o or .a input files and +-# creates a single (shared) output file. The export list +-# that is created is based on the output file's basename +-# with the suffix ".exp". +-# 3. The resulting shared object file is left in the +-# current directory. +-# 4. Uncommenting the "echo" lines gives detailed output +-# about the commands executed in the script. +-# +-# +-# HISTORY: Oct-1996 -- Support added for multiple .o files -- +-# -- and optional arguments processing. -- +-# Chris Myers (myers@tc.cornell.edu), Keith Kwok +-# (kkwok@tc.cornell.edu) and Vladimir Marangozov +-# +-# Aug-6-1996 -- Take care of the compiler specific -- +-# -- args by leaving CC to invoke "ld". -- +-# Vladimir Marangozov +-# +-# Jul-1-1996 -- Make sure to use /usr/ccs/bin/ld -- +-# -- Use makexp_aix for the export list. -- +-# Vladimir Marangozov (Vladimir.Marangozov@imag.fr) +-# +-# Manus Hand (mhand@csn.net) -- Initial code -- 6/24/96 +-# ======================================================================== +-# +- +-usage="Usage: ld_so_aix [CC command] [ld arguments]" +-if test ! -n "$*"; then +- echo $usage; exit 2 +-fi +- +-makexp=`dirname $0`/makexp_aix +- +-# Check for existence of compiler. +-CC=$1; shift +-whichcc=`which $CC` +- +-if test ! -x "$whichcc"; then +- echo "ld_so_aix: Compiler '$CC' not found; exiting." +- exit 2 +-fi +- +-if test ! -n "$*"; then +- echo $usage; exit 2 +-fi +- +-# Default import file for Python +-# Can be overriden by providing a -bI: argument. +-impfile="./python.exp" +- +-# Parse arguments +-while test -n "$1" +-do +- case "$1" in +- -e | -Wl,-e) +- if test -z "$2"; then +- echo "ld_so_aix: The -e flag needs a parameter; exiting."; exit 2 +- else +- shift; entry=$1 +- fi +- ;; +- -e* | -Wl,-e*) +- entry=`echo $1 | sed -e "s/-Wl,//" -e "s/-e//"` +- ;; +- -o) +- if test -z "$2"; then +- echo "ld_so_aix: The -o flag needs a parameter; exiting."; exit 2 +- else +- shift; objfile=$1 +- fi +- ;; +- -o*) +- objfile=`echo $1 | sed "s/-o//"` +- ;; +- -bI:* | -Wl,-bI:*) +- impfile=`echo $1 | sed -e "s/-Wl,//" -e "s/-bI://"` +- ;; +- -bE:* | -Wl,-bE:*) +- expfile=`echo $1 | sed -e "s/-Wl,//" -e "s/-bE://"` +- ;; +- *.o | *.a) +- objs="$objs $1" +- args="$args $1" +- ;; +- -bM:* | -Wl,-bM:* | -H* | -Wl,-H* | -T* | -Wl,-T* | -lm) +- ;; +- *) +- args="$args $1" +- ;; +- esac +- shift +-done +- +- +-if test -z "$objs"; then +- echo "ld_so_aix: No input files; exiting." +- exit 2 +-elif test ! -r "$impfile"; then +- echo "ld_so_aix: Import file '$impfile' not found or not readable; exiting." +- exit 2 +-fi +- +-# If -o wasn't specified, assume "-o shr.o" +-if test -z "$objfile"; then +- objfile=shr.o +-fi +- +-filename=`basename $objfile | sed "s/\.[^.]*$//"` +- +-# If -bE: wasn't specified, assume "-bE:$filename.exp" +-if test -z "$expfile"; then +- expfile="$filename.exp" +-fi +- +-# Default entry symbol for Python modules = init[modulename] +-# Can be overriden by providing a -e argument. +-if test -z "$entry"; then +- entry=init`echo $filename | sed "s/module.*//"` +-fi +- +-#echo "ld_so_aix: Debug info section" +-#echo " -> output file : $objfile" +-#echo " -> import file : $impfile" +-#echo " -> export file : $expfile" +-#echo " -> entry point : $entry" +-#echo " -> object files: $objs" +-#echo " -> CC arguments: $args" +- +-CCOPT="-Wl,-e$entry -Wl,-bE:$expfile -Wl,-bI:$impfile -Wl,-bhalt:4" +-CCOPT="$CCOPT -Wl,-bM:SRE -Wl,-T512 -Wl,-H512 -lm -o $objfile" +-# Note: to use dynamic libraries like libtcl8.4.so and libtk8.4.so +-# you may need to replace the second CCOPT line above with the following: +-# CCOPT="$CCOPT -Wl,-bM:SRE -Wl,-T512 -Wl,-H512 -brtl -bnortllib -lm -o $objfile" +- +-CCARGS="$args" +- +-# Export list generation. +-#echo $makexp $expfile "$objfile" $objs +-$makexp $expfile "$objfile" $objs +- +-# Perform the link. +-#echo $CC $CCOPT $CCARGS +-$CC $CCOPT $CCARGS +-retval=$? +- +-# Delete the module's export list file. +-# Comment this line if you need it. +-rm -f $expfile +- +-exit $retval +--- a/Modules/_ssl.c ++++ b/Modules/_ssl.c +@@ -680,7 +680,7 @@ + X509_EXTENSION *ext = NULL; + GENERAL_NAMES *names = NULL; + GENERAL_NAME *name; +- X509V3_EXT_METHOD *method; ++ const X509V3_EXT_METHOD *method; + BIO *biobuf = NULL; + char buf[2048]; + char *vptr; +@@ -978,6 +978,7 @@ + } + + retval = _decode_certificate(x, verbose); ++ X509_free(x); + + fail0: + +@@ -1040,7 +1041,7 @@ + static PyObject *PySSL_cipher (PySSLObject *self) { + + PyObject *retval, *v; +- SSL_CIPHER *current; ++ const SSL_CIPHER *current; + char *cipher_name; + char *cipher_protocol; + +--- a/Modules/bz2module.c ++++ b/Modules/bz2module.c +@@ -144,7 +144,23 @@ + /* ===================================================================== */ + /* Utility functions. */ + ++/* Refuse regular I/O if there's data in the iteration-buffer. ++ * Mixing them would cause data to arrive out of order, as the read* ++ * methods don't use the iteration buffer. */ + static int ++check_iterbuffered(BZ2FileObject *f) ++{ ++ if (f->f_buf != NULL && ++ (f->f_bufend - f->f_bufptr) > 0 && ++ f->f_buf[0] != '\0') { ++ PyErr_SetString(PyExc_ValueError, ++ "Mixing iteration and read methods would lose data"); ++ return -1; ++ } ++ return 0; ++} ++ ++static int + Util_CatchBZ2Error(int bzerror) + { + int ret = 0; +@@ -527,6 +543,10 @@ + goto cleanup; + } + ++ /* refuse to mix with f.next() */ ++ if (check_iterbuffered(self)) ++ goto cleanup; ++ + if (bytesrequested < 0) + buffersize = Util_NewBufferSize((size_t)0); + else +@@ -612,6 +632,10 @@ + goto cleanup; + } + ++ /* refuse to mix with f.next() */ ++ if (check_iterbuffered(self)) ++ goto cleanup; ++ + if (sizehint == 0) + ret = PyString_FromString(""); + else +@@ -669,6 +693,10 @@ + goto cleanup; + } + ++ /* refuse to mix with f.next() */ ++ if (check_iterbuffered(self)) ++ goto cleanup; ++ + if ((list = PyList_New(0)) == NULL) + goto cleanup; + +@@ -2292,9 +2320,12 @@ + { + PyObject *m; + +- Py_TYPE(&BZ2File_Type) = &PyType_Type; +- Py_TYPE(&BZ2Comp_Type) = &PyType_Type; +- Py_TYPE(&BZ2Decomp_Type) = &PyType_Type; ++ if (PyType_Ready(&BZ2File_Type) < 0) ++ return; ++ if (PyType_Ready(&BZ2Comp_Type) < 0) ++ return; ++ if (PyType_Ready(&BZ2Decomp_Type) < 0) ++ return; + + m = Py_InitModule3("bz2", bz2_methods, bz2__doc__); + if (m == NULL) +--- a/Modules/_ctypes/libffi_msvc/ffi.c ++++ b/Modules/_ctypes/libffi_msvc/ffi.c +@@ -371,10 +371,11 @@ + extern void ffi_closure_OUTER(); + + ffi_status +-ffi_prep_closure (ffi_closure* closure, +- ffi_cif* cif, +- void (*fun)(ffi_cif*,void*,void**,void*), +- void *user_data) ++ffi_prep_closure_loc (ffi_closure* closure, ++ ffi_cif* cif, ++ void (*fun)(ffi_cif*,void*,void**,void*), ++ void *user_data, ++ void *codeloc) + { + short bytes; + char *tramp; +@@ -452,6 +453,5 @@ + closure->cif = cif; + closure->user_data = user_data; + closure->fun = fun; +- + return FFI_OK; + } +--- a/Modules/_ctypes/libffi_msvc/ffi.h ++++ b/Modules/_ctypes/libffi_msvc/ffi.h +@@ -221,11 +221,15 @@ + void *user_data; + } ffi_closure; + ++void ffi_closure_free(void *); ++void *ffi_closure_alloc (size_t size, void **code); ++ + ffi_status +-ffi_prep_closure (ffi_closure*, ++ffi_prep_closure_loc (ffi_closure*, + ffi_cif *, + void (*fun)(ffi_cif*,void*,void**,void*), +- void *user_data); ++ void *user_data, ++ void *codeloc); + + typedef struct { + char tramp[FFI_TRAMPOLINE_SIZE]; +--- a/Modules/_ctypes/libffi_osx/include/ffi.h ++++ b/Modules/_ctypes/libffi_osx/include/ffi.h +@@ -264,6 +264,9 @@ + void (*fun)(ffi_cif*,void*,void**,void*), + void* user_data); + ++void ffi_closure_free(void *); ++void *ffi_closure_alloc (size_t size, void **code); ++ + typedef struct ffi_raw_closure { + char tramp[FFI_TRAMPOLINE_SIZE]; + ffi_cif* cif; +@@ -349,4 +352,4 @@ + } + #endif + +-#endif // #ifndef LIBFFI_H +\ No newline at end of file ++#endif // #ifndef LIBFFI_H +--- a/Modules/_ctypes/malloc_closure.c ++++ b/Modules/_ctypes/malloc_closure.c +@@ -93,7 +93,7 @@ + /******************************************************************/ + + /* put the item back into the free list */ +-void _ctypes_free_closure(void *p) ++void ffi_closure_free(void *p) + { + ITEM *item = (ITEM *)p; + item->next = free_list; +@@ -101,7 +101,7 @@ + } + + /* return one item from the free list, allocating more if needed */ +-void *_ctypes_alloc_closure(void) ++void *ffi_closure_alloc(size_t ignored, void** codeloc) + { + ITEM *item; + if (!free_list) +@@ -110,5 +110,6 @@ + return NULL; + item = free_list; + free_list = item->next; +- return item; ++ *codeloc = (void *)item; ++ return (void *)item; + } +--- a/Modules/_ctypes/_ctypes.c ++++ b/Modules/_ctypes/_ctypes.c +@@ -3463,7 +3463,7 @@ + self->callable = callable; + + self->thunk = thunk; +- *(void **)self->b_ptr = (void *)thunk->pcl; ++ *(void **)self->b_ptr = (void *)thunk->pcl_exec; + + Py_INCREF((PyObject *)thunk); /* for KeepRef */ + if (-1 == KeepRef((CDataObject *)self, 0, (PyObject *)thunk)) { +@@ -5541,36 +5541,42 @@ + Struct_Type.tp_base = &PyCData_Type; + if (PyType_Ready(&Struct_Type) < 0) + return; ++ Py_INCREF(&Struct_Type); + PyModule_AddObject(m, "Structure", (PyObject *)&Struct_Type); + + Py_TYPE(&Union_Type) = &UnionType_Type; + Union_Type.tp_base = &PyCData_Type; + if (PyType_Ready(&Union_Type) < 0) + return; ++ Py_INCREF(&Union_Type); + PyModule_AddObject(m, "Union", (PyObject *)&Union_Type); + + Py_TYPE(&PyCPointer_Type) = &PyCPointerType_Type; + PyCPointer_Type.tp_base = &PyCData_Type; + if (PyType_Ready(&PyCPointer_Type) < 0) + return; ++ Py_INCREF(&PyCPointer_Type); + PyModule_AddObject(m, "_Pointer", (PyObject *)&PyCPointer_Type); + + Py_TYPE(&PyCArray_Type) = &PyCArrayType_Type; + PyCArray_Type.tp_base = &PyCData_Type; + if (PyType_Ready(&PyCArray_Type) < 0) + return; ++ Py_INCREF(&PyCArray_Type); + PyModule_AddObject(m, "Array", (PyObject *)&PyCArray_Type); + + Py_TYPE(&Simple_Type) = &PyCSimpleType_Type; + Simple_Type.tp_base = &PyCData_Type; + if (PyType_Ready(&Simple_Type) < 0) + return; ++ Py_INCREF(&Simple_Type); + PyModule_AddObject(m, "_SimpleCData", (PyObject *)&Simple_Type); + + Py_TYPE(&PyCFuncPtr_Type) = &PyCFuncPtrType_Type; + PyCFuncPtr_Type.tp_base = &PyCData_Type; + if (PyType_Ready(&PyCFuncPtr_Type) < 0) + return; ++ Py_INCREF(&PyCFuncPtr_Type); + PyModule_AddObject(m, "CFuncPtr", (PyObject *)&PyCFuncPtr_Type); + + /************************************************* +--- a/Modules/_ctypes/libffi/fficonfig.py.in ++++ b/Modules/_ctypes/libffi/fficonfig.py.in +@@ -1,5 +1,7 @@ + ffi_sources = """ + src/prep_cif.c ++src/closures.c ++src/dlmalloc.c + """.split() + + ffi_platforms = { +--- a/Modules/_ctypes/ctypes.h ++++ b/Modules/_ctypes/ctypes.h +@@ -95,7 +95,8 @@ + + typedef struct { + PyObject_VAR_HEAD +- ffi_closure *pcl; /* the C callable */ ++ ffi_closure *pcl_write; /* the C callable, writeable */ ++ void *pcl_exec; /* the C callable, executable */ + ffi_cif cif; + int flags; + PyObject *converters; +@@ -428,9 +429,6 @@ + #endif + #endif + +-extern void _ctypes_free_closure(void *); +-extern void *_ctypes_alloc_closure(void); +- + extern void _ctypes_add_traceback(char *, char *, int); + + extern PyObject *PyCData_FromBaseObj(PyObject *type, PyObject *base, Py_ssize_t index, char *adr); +--- a/Modules/_ctypes/callbacks.c ++++ b/Modules/_ctypes/callbacks.c +@@ -21,8 +21,8 @@ + Py_XDECREF(self->converters); + Py_XDECREF(self->callable); + Py_XDECREF(self->restype); +- if (self->pcl) +- _ctypes_free_closure(self->pcl); ++ if (self->pcl_write) ++ ffi_closure_free(self->pcl_write); + PyObject_GC_Del(self); + } + +@@ -391,7 +391,8 @@ + return NULL; + } + +- p->pcl = NULL; ++ p->pcl_exec = NULL; ++ p->pcl_write = NULL; + memset(&p->cif, 0, sizeof(p->cif)); + p->converters = NULL; + p->callable = NULL; +@@ -421,8 +422,9 @@ + + assert(CThunk_CheckExact(p)); + +- p->pcl = _ctypes_alloc_closure(); +- if (p->pcl == NULL) { ++ p->pcl_write = ffi_closure_alloc(sizeof(ffi_closure), ++ &p->pcl_exec); ++ if (p->pcl_write == NULL) { + PyErr_NoMemory(); + goto error; + } +@@ -467,7 +469,13 @@ + "ffi_prep_cif failed with %d", result); + goto error; + } +- result = ffi_prep_closure(p->pcl, &p->cif, closure_fcn, p); ++#if defined(X86_DARWIN) || defined(POWERPC_DARWIN) ++ result = ffi_prep_closure(p->pcl_write, &p->cif, closure_fcn, p); ++#else ++ result = ffi_prep_closure_loc(p->pcl_write, &p->cif, closure_fcn, ++ p, ++ p->pcl_exec); ++#endif + if (result != FFI_OK) { + PyErr_Format(PyExc_RuntimeError, + "ffi_prep_closure failed with %d", result); +--- a/Modules/_io/bytesio.c ++++ b/Modules/_io/bytesio.c +@@ -825,7 +825,7 @@ + {"readline", (PyCFunction)bytesio_readline, METH_VARARGS, readline_doc}, + {"readlines", (PyCFunction)bytesio_readlines, METH_VARARGS, readlines_doc}, + {"read", (PyCFunction)bytesio_read, METH_VARARGS, read_doc}, +- {"getvalue", (PyCFunction)bytesio_getvalue, METH_VARARGS, getval_doc}, ++ {"getvalue", (PyCFunction)bytesio_getvalue, METH_NOARGS, getval_doc}, + {"seek", (PyCFunction)bytesio_seek, METH_VARARGS, seek_doc}, + {"truncate", (PyCFunction)bytesio_truncate, METH_VARARGS, truncate_doc}, + {"__getstate__", (PyCFunction)bytesio_getstate, METH_NOARGS, NULL}, +--- a/Modules/_io/stringio.c ++++ b/Modules/_io/stringio.c +@@ -809,7 +809,7 @@ + + static struct PyMethodDef stringio_methods[] = { + {"close", (PyCFunction)stringio_close, METH_NOARGS, stringio_close_doc}, +- {"getvalue", (PyCFunction)stringio_getvalue, METH_VARARGS, stringio_getvalue_doc}, ++ {"getvalue", (PyCFunction)stringio_getvalue, METH_NOARGS, stringio_getvalue_doc}, + {"read", (PyCFunction)stringio_read, METH_VARARGS, stringio_read_doc}, + {"readline", (PyCFunction)stringio_readline, METH_VARARGS, stringio_readline_doc}, + {"tell", (PyCFunction)stringio_tell, METH_NOARGS, stringio_tell_doc}, +--- a/Modules/_io/iobase.c ++++ b/Modules/_io/iobase.c +@@ -776,9 +776,9 @@ + return NULL; + + res = PyObject_CallMethodObjArgs(self, _PyIO_str_readinto, b, NULL); +- if (res == NULL) { ++ if (res == NULL || res == Py_None) { + Py_DECREF(b); +- return NULL; ++ return res; + } + + n = PyNumber_AsSsize_t(res, PyExc_ValueError); +--- a/Modules/_io/bufferedio.c ++++ b/Modules/_io/bufferedio.c +@@ -636,6 +636,8 @@ + return -1; + } + #ifdef WITH_THREAD ++ if (self->lock) ++ PyThread_free_lock(self->lock); + self->lock = PyThread_allocate_lock(); + if (self->lock == NULL) { + PyErr_SetString(PyExc_RuntimeError, "can't allocate read lock"); +@@ -1386,7 +1388,10 @@ + self->pos = 0; + self->raw_pos = 0; + self->read_end = 0; +- while (self->read_end < self->buffer_size) { ++ /* NOTE: when the read is satisfied, we avoid issuing any additional ++ reads, which could block indefinitely (e.g. on a socket). ++ See issue #9550. */ ++ while (remaining > 0 && self->read_end < self->buffer_size) { + Py_ssize_t r = _bufferedreader_fill_buffer(self); + if (r == -1) + goto error; +@@ -1665,6 +1670,11 @@ + self->write_pos += n; + self->raw_pos = self->write_pos; + written += Py_SAFE_DOWNCAST(n, Py_off_t, Py_ssize_t); ++ /* Partial writes can return successfully when interrupted by a ++ signal (see write(2)). We must run signal handlers before ++ blocking another time, possibly indefinitely. */ ++ if (PyErr_CheckSignals() < 0) ++ goto error; + } + + if (restore_pos) { +@@ -1802,6 +1812,11 @@ + } + written += n; + remaining -= n; ++ /* Partial writes can return successfully when interrupted by a ++ signal (see write(2)). We must run signal handlers before ++ blocking another time, possibly indefinitely. */ ++ if (PyErr_CheckSignals() < 0) ++ goto error; + } + if (self->readable) + _bufferedreader_reset_buf(self); +--- a/Modules/nismodule.c ++++ b/Modules/nismodule.c +@@ -124,6 +124,7 @@ + PyErr_Clear(); + Py_XDECREF(key); + Py_XDECREF(val); ++ indata->state = PyEval_SaveThread(); + return 1; + } + err = PyDict_SetItem(indata->dict, key, val); +--- a/Modules/mmapmodule.c ++++ b/Modules/mmapmodule.c +@@ -1280,6 +1280,11 @@ + "don't use 0 for anonymous memory"); + */ + if (fileno != -1 && fileno != 0) { ++ /* Ensure that fileno is within the CRT's valid range */ ++ if (_PyVerify_fd(fileno) == 0) { ++ PyErr_SetFromErrno(mmap_module_error); ++ return NULL; ++ } + fh = (HANDLE)_get_osfhandle(fileno); + if (fh==(HANDLE)-1) { + PyErr_SetFromErrno(mmap_module_error); +--- a/Modules/_heapqmodule.c ++++ b/Modules/_heapqmodule.c +@@ -2,7 +2,7 @@ + + C implementation derived directly from heapq.py in Py2.3 + which was written by Kevin O'Connor, augmented by Tim Peters, +-annotated by François Pinard, and converted to C by Raymond Hettinger. ++annotated by François Pinard, and converted to C by Raymond Hettinger. + + */ + +--- a/Modules/readline.c ++++ b/Modules/readline.c +@@ -356,6 +356,38 @@ + "set_completer_delims(string) -> None\n\ + set the readline word delimiters for tab-completion"); + ++/* _py_free_history_entry: Utility function to free a history entry. */ ++ ++#if defined(RL_READLINE_VERSION) && RL_READLINE_VERSION >= 0x0500 ++ ++/* Readline version >= 5.0 introduced a timestamp field into the history entry ++ structure; this needs to be freed to avoid a memory leak. This version of ++ readline also introduced the handy 'free_history_entry' function, which ++ takes care of the timestamp. */ ++ ++static void ++_py_free_history_entry(HIST_ENTRY *entry) ++{ ++ histdata_t data = free_history_entry(entry); ++ free(data); ++} ++ ++#else ++ ++/* No free_history_entry function; free everything manually. */ ++ ++static void ++_py_free_history_entry(HIST_ENTRY *entry) ++{ ++ if (entry->line) ++ free((void *)entry->line); ++ if (entry->data) ++ free(entry->data); ++ free(entry); ++} ++ ++#endif ++ + static PyObject * + py_remove_history(PyObject *self, PyObject *args) + { +@@ -377,12 +409,7 @@ + return NULL; + } + /* free memory allocated for the history entry */ +- if (entry->line) +- free((void *)entry->line); +- if (entry->data) +- free(entry->data); +- free(entry); +- ++ _py_free_history_entry(entry); + Py_RETURN_NONE; + } + +@@ -414,12 +441,7 @@ + return NULL; + } + /* free memory allocated for the old history entry */ +- if (old_entry->line) +- free((void *)old_entry->line); +- if (old_entry->data) +- free(old_entry->data); +- free(old_entry); +- ++ _py_free_history_entry(old_entry); + Py_RETURN_NONE; + } + +@@ -490,6 +512,25 @@ + \n\ + Returns current completer function."); + ++/* Private function to get current length of history. XXX It may be ++ * possible to replace this with a direct use of history_length instead, ++ * but it's not clear whether BSD's libedit keeps history_length up to date. ++ * See issue #8065.*/ ++ ++static int ++_py_get_history_length(void) ++{ ++ HISTORY_STATE *hist_st = history_get_history_state(); ++ int length = hist_st->length; ++ /* the history docs don't say so, but the address of hist_st changes each ++ time history_get_history_state is called which makes me think it's ++ freshly malloc'd memory... on the other hand, the address of the last ++ line stays the same as long as history isn't extended, so it appears to ++ be malloc'd but managed by the history package... */ ++ free(hist_st); ++ return length; ++} ++ + /* Exported function to get any element of history */ + + static PyObject * +@@ -508,9 +549,7 @@ + * code doesn't have to worry about the + * difference. + */ +- HISTORY_STATE *hist_st; +- hist_st = history_get_history_state(); +- ++ int length = _py_get_history_length(); + idx --; + + /* +@@ -518,7 +557,7 @@ + * the index is out of range, therefore + * test for that and fail gracefully. + */ +- if (idx < 0 || idx >= hist_st->length) { ++ if (idx < 0 || idx >= length) { + Py_RETURN_NONE; + } + } +@@ -540,10 +579,7 @@ + static PyObject * + get_current_history_length(PyObject *self, PyObject *noarg) + { +- HISTORY_STATE *hist_st; +- +- hist_st = history_get_history_state(); +- return PyInt_FromLong(hist_st ? (long) hist_st->length : (long) 0); ++ return PyInt_FromLong((long)_py_get_history_length()); + } + + PyDoc_STRVAR(doc_get_current_history_length, +@@ -1024,29 +1060,22 @@ + n = strlen(p); + if (n > 0) { + const char *line; +- HISTORY_STATE *state = history_get_history_state(); +- if (state->length > 0) ++ int length = _py_get_history_length(); ++ if (length > 0) + #ifdef __APPLE__ + if (using_libedit_emulation) { + /* + * Libedit's emulation uses 0-based indexes, + * the real readline uses 1-based indexes. + */ +- line = history_get(state->length - 1)->line; ++ line = history_get(length - 1)->line; + } else + #endif /* __APPLE__ */ +- line = history_get(state->length)->line; ++ line = history_get(length)->line; + else + line = ""; + if (strcmp(p, line)) + add_history(p); +- /* the history docs don't say so, but the address of state +- changes each time history_get_history_state is called +- which makes me think it's freshly malloc'd memory... +- on the other hand, the address of the last line stays the +- same as long as history isn't extended, so it appears to +- be malloc'd but managed by the history package... */ +- free(state); + } + /* Copy the malloc'ed buffer into a PyMem_Malloc'ed one and + release the original. */ +--- a/Modules/arraymodule.c ++++ b/Modules/arraymodule.c +@@ -798,7 +798,7 @@ + return -1; + + while ((v = PyIter_Next(it)) != NULL) { +- if (ins1(self, (int) Py_SIZE(self), v) != 0) { ++ if (ins1(self, Py_SIZE(self), v) != 0) { + Py_DECREF(v); + Py_DECREF(it); + return -1; +@@ -1090,7 +1090,7 @@ + static PyObject * + array_append(arrayobject *self, PyObject *v) + { +- return ins(self, (int) Py_SIZE(self), v); ++ return ins(self, Py_SIZE(self), v); + } + + PyDoc_STRVAR(append_doc, +@@ -1228,8 +1228,14 @@ + PyMem_RESIZE(item, char, Py_SIZE(self)*itemsize); + self->ob_item = item; + self->allocated = Py_SIZE(self); +- PyErr_SetString(PyExc_EOFError, +- "not enough items in file"); ++ if (ferror(fp)) { ++ PyErr_SetFromErrno(PyExc_IOError); ++ clearerr(fp); ++ } ++ else { ++ PyErr_SetString(PyExc_EOFError, ++ "not enough items in file"); ++ } + return NULL; + } + } +--- a/Modules/_randommodule.c ++++ b/Modules/_randommodule.c +@@ -6,7 +6,7 @@ + + It was modified in 2002 by Raymond Hettinger as follows: + +- * the principal computational lines untouched except for tabbing. ++ * the principal computational lines untouched. + + * renamed genrand_res53() to random_random() and wrapped + in python calling/return code. +--- a/Modules/ld_so_aix.in ++++ b/Modules/ld_so_aix.in +@@ -0,0 +1,194 @@ ++#!/bin/sh ++# ++# ======================================================================== ++# FILE: ld_so_aix ++# TYPE: executable, uses makexp_aix ++# SYSTEM: AIX ++# ++# DESCRIPTION: Creates a shareable .o from a set of pre-compiled ++# (unshared) .o files ++# ++# USAGE: ld_so_aix [CC] [arguments] ++# ++# ARGUMENTS: Same as for "ld". The following arguments are processed ++# or supplied by this script (those marked with an asterisk ++# can be overriden from command line): ++# ++# Argument Default value ++# (*) -o [OutputFileName] -o shr.o ++# (*) -e [EntryPointLabel] -e init[OutputBaseName] ++# (*) -bE:[ExportFile] -bE:[OutputBaseName].exp ++# (*) -bI:[ImportFile] -bI:./python.exp ++# -bM:[ModuleType] -bM:SRE ++# -bhalt:[Number] -bhalt:4 ++# -T[Number] -T512 ++# -H[Number] -H512 ++# -lm ++# ++# The compiler specific ("-lc" or "-lc_r", "-lpthreads",...) ++# arguments will be automatically passed to "ld" according ++# to the CC command provided as a first argument to this ++# script. Usually, the same CC command was used to produce ++# the pre-compiled .o file(s). ++# ++# NOTES: 1. Since "ld_so_aix" was originally written for building ++# shared modules for the Python interpreter, the -e and ++# -bI default values match Python's conventions. In ++# Python, the entry point for a shared module is based ++# on the module's name (e.g., the "mathmodule" will ++# expect an entry point of "initmath"). ++# 2. The script accepts multiple .o or .a input files and ++# creates a single (shared) output file. The export list ++# that is created is based on the output file's basename ++# with the suffix ".exp". ++# 3. The resulting shared object file is left in the ++# current directory. ++# 4. Uncommenting the "echo" lines gives detailed output ++# about the commands executed in the script. ++# ++# ++# HISTORY: Oct-1996 -- Support added for multiple .o files -- ++# -- and optional arguments processing. -- ++# Chris Myers (myers@tc.cornell.edu), Keith Kwok ++# (kkwok@tc.cornell.edu) and Vladimir Marangozov ++# ++# Aug-6-1996 -- Take care of the compiler specific -- ++# -- args by leaving CC to invoke "ld". -- ++# Vladimir Marangozov ++# ++# Jul-1-1996 -- Make sure to use /usr/ccs/bin/ld -- ++# -- Use makexp_aix for the export list. -- ++# Vladimir Marangozov (Vladimir.Marangozov@imag.fr) ++# ++# Manus Hand (mhand@csn.net) -- Initial code -- 6/24/96 ++# ======================================================================== ++# ++ ++usage="Usage: ld_so_aix [CC command] [ld arguments]" ++if test ! -n "$*"; then ++ echo $usage; exit 2 ++fi ++ ++makexp=`dirname $0`/makexp_aix ++ ++# Check for existence of compiler. ++CC=$1; shift ++whichcc=`which $CC` ++ ++if test ! -x "$whichcc"; then ++ echo "ld_so_aix: Compiler '$CC' not found; exiting." ++ exit 2 ++fi ++ ++if test ! -n "$*"; then ++ echo $usage; exit 2 ++fi ++ ++# Default import file for Python ++# Can be overriden by providing a -bI: argument. ++impfile="./python.exp" ++ ++# Parse arguments ++while test -n "$1" ++do ++ case "$1" in ++ -e | -Wl,-e) ++ if test -z "$2"; then ++ echo "ld_so_aix: The -e flag needs a parameter; exiting."; exit 2 ++ else ++ shift; entry=$1 ++ fi ++ ;; ++ -e* | -Wl,-e*) ++ entry=`echo $1 | sed -e "s/-Wl,//" -e "s/-e//"` ++ ;; ++ -o) ++ if test -z "$2"; then ++ echo "ld_so_aix: The -o flag needs a parameter; exiting."; exit 2 ++ else ++ shift; objfile=$1 ++ fi ++ ;; ++ -o*) ++ objfile=`echo $1 | sed "s/-o//"` ++ ;; ++ -bI:* | -Wl,-bI:*) ++ impfile=`echo $1 | sed -e "s/-Wl,//" -e "s/-bI://"` ++ ;; ++ -bE:* | -Wl,-bE:*) ++ expfile=`echo $1 | sed -e "s/-Wl,//" -e "s/-bE://"` ++ ;; ++ *.o | *.a) ++ objs="$objs $1" ++ args="$args $1" ++ ;; ++ -bM:* | -Wl,-bM:* | -H* | -Wl,-H* | -T* | -Wl,-T* | -lm) ++ ;; ++ *) ++ args="$args $1" ++ ;; ++ esac ++ shift ++done ++ ++if test "$objfile" = "libpython@VERSION@.so"; then ++ ldsocoremode="true" ++fi ++ ++if test -z "$objs"; then ++ echo "ld_so_aix: No input files; exiting." ++ exit 2 ++elif test ! -r "$impfile" -a -z "$ldsocoremode"; then ++ echo "ld_so_aix: Import file '$impfile' not found or not readable; exiting." ++ exit 2 ++fi ++ ++# If -o wasn't specified, assume "-o shr.o" ++if test -z "$objfile"; then ++ objfile=shr.o ++fi ++ ++filename=`basename $objfile | sed "s/\.[^.]*$//"` ++ ++# If -bE: wasn't specified, assume "-bE:$filename.exp" ++if test -z "$expfile"; then ++ expfile="$filename.exp" ++fi ++ ++# Default entry symbol for Python modules = init[modulename] ++# Can be overriden by providing a -e argument. ++if test -z "$entry"; then ++ entry=init`echo $filename | sed "s/module.*//"` ++fi ++ ++#echo "ld_so_aix: Debug info section" ++#echo " -> output file : $objfile" ++#echo " -> import file : $impfile" ++#echo " -> export file : $expfile" ++#echo " -> entry point : $entry" ++#echo " -> object files: $objs" ++#echo " -> CC arguments: $args" ++ ++if test -z "$ldsocoremode"; then ++ CCOPT="-Wl,-e$entry -Wl,-bE:$expfile -Wl,-bI:$impfile -Wl,-bhalt:4" ++else ++ CCOPT="-Wl,-bnoentry -Wl,-bE:$expfile -Wl,-bhalt:4" ++fi ++CCOPT="$CCOPT -Wl,-bM:SRE -Wl,-T512 -Wl,-H512 -Wl,-brtl -Wl,-bnortllib -lm -o $objfile" ++ ++CCARGS="$args" ++ ++# Export list generation. ++#echo $makexp $expfile "$objfile" $objs ++$makexp $expfile "$objfile" $objs ++ ++# Perform the link. ++#echo $CC $CCOPT $CCARGS ++$CC $CCOPT $CCARGS ++retval=$? ++ ++# Delete the module's export list file. ++# Comment this line if you need it. ++rm -f $expfile ++ ++exit $retval +--- a/Modules/selectmodule.c ++++ b/Modules/selectmodule.c +@@ -910,10 +910,9 @@ + } + + PyDoc_STRVAR(pyepoll_register_doc, +-"register(fd[, eventmask]) -> bool\n\ ++"register(fd[, eventmask]) -> None\n\ + \n\ +-Registers a new fd or modifies an already registered fd. register() returns\n\ +-True if a new fd was registered or False if the event mask for fd was modified.\n\ ++Registers a new fd or modifies an already registered fd.\n\ + fd is the target file descriptor of the operation.\n\ + events is a bit set composed of the various EPOLL constants; the default\n\ + is EPOLL_IN | EPOLL_OUT | EPOLL_PRI.\n\ +@@ -1769,6 +1768,10 @@ + PyModule_AddObject(m, "error", SelectError); + + #ifdef PIPE_BUF ++#ifdef HAVE_BROKEN_PIPE_BUF ++#undef PIPE_BUF ++#define PIPE_BUF 512 ++#endif + PyModule_AddIntConstant(m, "PIPE_BUF", PIPE_BUF); + #endif + +--- a/Modules/threadmodule.c ++++ b/Modules/threadmodule.c +@@ -14,6 +14,7 @@ + #include "pythread.h" + + static PyObject *ThreadError; ++static PyObject *str_dict; + static long nb_threads = 0; + + /* Lock objects */ +@@ -177,19 +178,160 @@ + + #include "structmember.h" + ++/* Quick overview: ++ ++ We need to be able to reclaim reference cycles as soon as possible ++ (both when a thread is being terminated, or a thread-local object ++ becomes unreachable from user data). Constraints: ++ - it must not be possible for thread-state dicts to be involved in ++ reference cycles (otherwise the cyclic GC will refuse to consider ++ objects referenced from a reachable thread-state dict, even though ++ local_dealloc would clear them) ++ - the death of a thread-state dict must still imply destruction of the ++ corresponding local dicts in all thread-local objects. ++ ++ Our implementation uses small "localdummy" objects in order to break ++ the reference chain. These trivial objects are hashable (using the ++ default scheme of identity hashing) and weakrefable. ++ Each thread-state holds a separate localdummy for each local object ++ (as a /strong reference/), ++ and each thread-local object holds a dict mapping /weak references/ ++ of localdummies to local dicts. ++ ++ Therefore: ++ - only the thread-state dict holds a strong reference to the dummies ++ - only the thread-local object holds a strong reference to the local dicts ++ - only outside objects (application- or library-level) hold strong ++ references to the thread-local objects ++ - as soon as a thread-state dict is destroyed, the weakref callbacks of all ++ dummies attached to that thread are called, and destroy the corresponding ++ local dicts from thread-local objects ++ - as soon as a thread-local object is destroyed, its local dicts are ++ destroyed and its dummies are manually removed from all thread states ++ - the GC can do its work correctly when a thread-local object is dangling, ++ without any interference from the thread-state dicts ++ ++ As an additional optimization, each localdummy holds a borrowed reference ++ to the corresponding localdict. This borrowed reference is only used ++ by the thread-local object which has created the localdummy, which should ++ guarantee that the localdict still exists when accessed. ++*/ ++ + typedef struct { + PyObject_HEAD ++ PyObject *localdict; /* Borrowed reference! */ ++ PyObject *weakreflist; /* List of weak references to self */ ++} localdummyobject; ++ ++static void ++localdummy_dealloc(localdummyobject *self) ++{ ++ if (self->weakreflist != NULL) ++ PyObject_ClearWeakRefs((PyObject *) self); ++ Py_TYPE(self)->tp_free((PyObject*)self); ++} ++ ++static PyTypeObject localdummytype = { ++ PyVarObject_HEAD_INIT(NULL, 0) ++ /* tp_name */ "_thread._localdummy", ++ /* tp_basicsize */ sizeof(localdummyobject), ++ /* tp_itemsize */ 0, ++ /* tp_dealloc */ (destructor)localdummy_dealloc, ++ /* tp_print */ 0, ++ /* tp_getattr */ 0, ++ /* tp_setattr */ 0, ++ /* tp_reserved */ 0, ++ /* tp_repr */ 0, ++ /* tp_as_number */ 0, ++ /* tp_as_sequence */ 0, ++ /* tp_as_mapping */ 0, ++ /* tp_hash */ 0, ++ /* tp_call */ 0, ++ /* tp_str */ 0, ++ /* tp_getattro */ 0, ++ /* tp_setattro */ 0, ++ /* tp_as_buffer */ 0, ++ /* tp_flags */ Py_TPFLAGS_DEFAULT, ++ /* tp_doc */ "Thread-local dummy", ++ /* tp_traverse */ 0, ++ /* tp_clear */ 0, ++ /* tp_richcompare */ 0, ++ /* tp_weaklistoffset */ offsetof(localdummyobject, weakreflist) ++}; ++ ++ ++typedef struct { ++ PyObject_HEAD + PyObject *key; + PyObject *args; + PyObject *kw; +- PyObject *dict; ++ PyObject *weakreflist; /* List of weak references to self */ ++ /* A {localdummy weakref -> localdict} dict */ ++ PyObject *dummies; ++ /* The callback for weakrefs to localdummies */ ++ PyObject *wr_callback; + } localobject; + ++/* Forward declaration */ ++static PyObject *_ldict(localobject *self); ++static PyObject *_localdummy_destroyed(PyObject *meth_self, PyObject *dummyweakref); ++ ++/* Create and register the dummy for the current thread. ++ Returns a borrowed reference of the corresponding local dict */ + static PyObject * ++_local_create_dummy(localobject *self) ++{ ++ PyObject *tdict, *ldict = NULL, *wr = NULL; ++ localdummyobject *dummy = NULL; ++ int r; ++ ++ tdict = PyThreadState_GetDict(); ++ if (tdict == NULL) { ++ PyErr_SetString(PyExc_SystemError, ++ "Couldn't get thread-state dictionary"); ++ goto err; ++ } ++ ++ ldict = PyDict_New(); ++ if (ldict == NULL) ++ goto err; ++ dummy = (localdummyobject *) localdummytype.tp_alloc(&localdummytype, 0); ++ if (dummy == NULL) ++ goto err; ++ dummy->localdict = ldict; ++ wr = PyWeakref_NewRef((PyObject *) dummy, self->wr_callback); ++ if (wr == NULL) ++ goto err; ++ ++ /* As a side-effect, this will cache the weakref's hash before the ++ dummy gets deleted */ ++ r = PyDict_SetItem(self->dummies, wr, ldict); ++ if (r < 0) ++ goto err; ++ Py_CLEAR(wr); ++ r = PyDict_SetItem(tdict, self->key, (PyObject *) dummy); ++ if (r < 0) ++ goto err; ++ Py_CLEAR(dummy); ++ ++ Py_DECREF(ldict); ++ return ldict; ++ ++err: ++ Py_XDECREF(ldict); ++ Py_XDECREF(wr); ++ Py_XDECREF(dummy); ++ return NULL; ++} ++ ++static PyObject * + local_new(PyTypeObject *type, PyObject *args, PyObject *kw) + { + localobject *self; +- PyObject *tdict; ++ PyObject *wr; ++ static PyMethodDef wr_callback_def = { ++ "_localdummy_destroyed", (PyCFunction) _localdummy_destroyed, METH_O ++ }; + + if (type->tp_init == PyBaseObject_Type.tp_init + && ((args && PyObject_IsTrue(args)) +@@ -207,23 +349,25 @@ + self->args = args; + Py_XINCREF(kw); + self->kw = kw; +- self->dict = NULL; /* making sure */ + self->key = PyString_FromFormat("thread.local.%p", self); + if (self->key == NULL) + goto err; + +- self->dict = PyDict_New(); +- if (self->dict == NULL) ++ self->dummies = PyDict_New(); ++ if (self->dummies == NULL) + goto err; + +- tdict = PyThreadState_GetDict(); +- if (tdict == NULL) { +- PyErr_SetString(PyExc_SystemError, +- "Couldn't get thread-state dictionary"); ++ /* We use a weak reference to self in the callback closure ++ in order to avoid spurious reference cycles */ ++ wr = PyWeakref_NewRef((PyObject *) self, NULL); ++ if (wr == NULL) + goto err; +- } ++ self->wr_callback = PyCFunction_New(&wr_callback_def, wr); ++ Py_DECREF(wr); ++ if (self->wr_callback == NULL) ++ goto err; + +- if (PyDict_SetItem(tdict, self->key, self->dict) < 0) ++ if (_local_create_dummy(self) == NULL) + goto err; + + return (PyObject *)self; +@@ -238,23 +382,19 @@ + { + Py_VISIT(self->args); + Py_VISIT(self->kw); +- Py_VISIT(self->dict); ++ Py_VISIT(self->dummies); + return 0; + } + + static int + local_clear(localobject *self) + { ++ PyThreadState *tstate; + Py_CLEAR(self->args); + Py_CLEAR(self->kw); +- Py_CLEAR(self->dict); +- return 0; +-} +- +-static void +-local_dealloc(localobject *self) +-{ +- PyThreadState *tstate; ++ Py_CLEAR(self->dummies); ++ Py_CLEAR(self->wr_callback); ++ /* Remove all strong references to dummies from the thread states */ + if (self->key + && (tstate = PyThreadState_Get()) + && tstate->interp) { +@@ -265,16 +405,29 @@ + PyDict_GetItem(tstate->dict, self->key)) + PyDict_DelItem(tstate->dict, self->key); + } ++ return 0; ++} + ++static void ++local_dealloc(localobject *self) ++{ ++ /* Weakrefs must be invalidated right now, otherwise they can be used ++ from code called below, which is very dangerous since Py_REFCNT(self) == 0 */ ++ if (self->weakreflist != NULL) ++ PyObject_ClearWeakRefs((PyObject *) self); ++ ++ PyObject_GC_UnTrack(self); ++ ++ local_clear(self); + Py_XDECREF(self->key); +- local_clear(self); + Py_TYPE(self)->tp_free((PyObject*)self); + } + ++/* Returns a borrowed reference to the local dict, creating it if necessary */ + static PyObject * + _ldict(localobject *self) + { +- PyObject *tdict, *ldict; ++ PyObject *tdict, *ldict, *dummy; + + tdict = PyThreadState_GetDict(); + if (tdict == NULL) { +@@ -283,23 +436,12 @@ + return NULL; + } + +- ldict = PyDict_GetItem(tdict, self->key); +- if (ldict == NULL) { +- ldict = PyDict_New(); /* we own ldict */ +- ++ dummy = PyDict_GetItem(tdict, self->key); ++ if (dummy == NULL) { ++ ldict = _local_create_dummy(self); + if (ldict == NULL) + return NULL; +- else { +- int i = PyDict_SetItem(tdict, self->key, ldict); +- Py_DECREF(ldict); /* now ldict is borrowed */ +- if (i < 0) +- return NULL; +- } + +- Py_CLEAR(self->dict); +- Py_INCREF(ldict); +- self->dict = ldict; /* still borrowed */ +- + if (Py_TYPE(self)->tp_init != PyBaseObject_Type.tp_init && + Py_TYPE(self)->tp_init((PyObject*)self, + self->args, self->kw) < 0) { +@@ -309,15 +451,10 @@ + PyDict_DelItem(tdict, self->key); + return NULL; + } +- + } +- +- /* The call to tp_init above may have caused another thread to run. +- Install our ldict again. */ +- if (self->dict != ldict) { +- Py_CLEAR(self->dict); +- Py_INCREF(ldict); +- self->dict = ldict; ++ else { ++ assert(Py_TYPE(dummy) == &localdummytype); ++ ldict = ((localdummyobject *) dummy)->localdict; + } + + return ldict; +@@ -327,32 +464,25 @@ + local_setattro(localobject *self, PyObject *name, PyObject *v) + { + PyObject *ldict; ++ int r; + + ldict = _ldict(self); + if (ldict == NULL) + return -1; + +- return PyObject_GenericSetAttr((PyObject *)self, name, v); +-} +- +-static PyObject * +-local_getdict(localobject *self, void *closure) +-{ +- if (self->dict == NULL) { +- PyErr_SetString(PyExc_AttributeError, "__dict__"); +- return NULL; ++ r = PyObject_RichCompareBool(name, str_dict, Py_EQ); ++ if (r == 1) { ++ PyErr_Format(PyExc_AttributeError, ++ "'%.50s' object attribute '__dict__' is read-only", ++ Py_TYPE(self)->tp_name); ++ return -1; + } ++ if (r == -1) ++ return -1; + +- Py_INCREF(self->dict); +- return self->dict; ++ return _PyObject_GenericSetAttrWithDict((PyObject *)self, name, v, ldict); + } + +-static PyGetSetDef local_getset[] = { +- {"__dict__", (getter)local_getdict, (setter)NULL, +- "Local-data dictionary", NULL}, +- {NULL} /* Sentinel */ +-}; +- + static PyObject *local_getattro(localobject *, PyObject *); + + static PyTypeObject localtype = { +@@ -375,22 +505,23 @@ + /* tp_getattro */ (getattrofunc)local_getattro, + /* tp_setattro */ (setattrofunc)local_setattro, + /* tp_as_buffer */ 0, +- /* tp_flags */ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, ++ /* tp_flags */ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE ++ | Py_TPFLAGS_HAVE_GC, + /* tp_doc */ "Thread-local data", + /* tp_traverse */ (traverseproc)local_traverse, + /* tp_clear */ (inquiry)local_clear, + /* tp_richcompare */ 0, +- /* tp_weaklistoffset */ 0, ++ /* tp_weaklistoffset */ offsetof(localobject, weakreflist), + /* tp_iter */ 0, + /* tp_iternext */ 0, + /* tp_methods */ 0, + /* tp_members */ 0, +- /* tp_getset */ local_getset, ++ /* tp_getset */ 0, + /* tp_base */ 0, + /* tp_dict */ 0, /* internal use */ + /* tp_descr_get */ 0, + /* tp_descr_set */ 0, +- /* tp_dictoffset */ offsetof(localobject, dict), ++ /* tp_dictoffset */ 0, + /* tp_init */ 0, + /* tp_alloc */ 0, + /* tp_new */ local_new, +@@ -402,25 +533,62 @@ + local_getattro(localobject *self, PyObject *name) + { + PyObject *ldict, *value; ++ int r; + + ldict = _ldict(self); + if (ldict == NULL) + return NULL; + ++ r = PyObject_RichCompareBool(name, str_dict, Py_EQ); ++ if (r == 1) { ++ Py_INCREF(ldict); ++ return ldict; ++ } ++ if (r == -1) ++ return NULL; ++ + if (Py_TYPE(self) != &localtype) + /* use generic lookup for subtypes */ +- return PyObject_GenericGetAttr((PyObject *)self, name); ++ return _PyObject_GenericGetAttrWithDict((PyObject *)self, name, ldict); + + /* Optimization: just look in dict ourselves */ + value = PyDict_GetItem(ldict, name); + if (value == NULL) + /* Fall back on generic to get __class__ and __dict__ */ +- return PyObject_GenericGetAttr((PyObject *)self, name); ++ return _PyObject_GenericGetAttrWithDict((PyObject *)self, name, ldict); + + Py_INCREF(value); + return value; + } + ++/* Called when a dummy is destroyed. */ ++static PyObject * ++_localdummy_destroyed(PyObject *localweakref, PyObject *dummyweakref) ++{ ++ PyObject *obj; ++ localobject *self; ++ assert(PyWeakref_CheckRef(localweakref)); ++ obj = PyWeakref_GET_OBJECT(localweakref); ++ if (obj == Py_None) ++ Py_RETURN_NONE; ++ Py_INCREF(obj); ++ assert(PyObject_TypeCheck(obj, &localtype)); ++ /* If the thread-local object is still alive and not being cleared, ++ remove the corresponding local dict */ ++ self = (localobject *) obj; ++ if (self->dummies != NULL) { ++ PyObject *ldict; ++ ldict = PyDict_GetItem(self->dummies, dummyweakref); ++ if (ldict != NULL) { ++ PyDict_DelItem(self->dummies, dummyweakref); ++ } ++ if (PyErr_Occurred()) ++ PyErr_WriteUnraisable(obj); ++ } ++ Py_DECREF(obj); ++ Py_RETURN_NONE; ++} ++ + /* Module functions */ + + struct bootstate { +@@ -579,7 +747,7 @@ + "allocate_lock() -> lock object\n\ + (allocate() is an obsolete synonym)\n\ + \n\ +-Create a new lock object. See LockType.__doc__ for information about locks."); ++Create a new lock object. See help(LockType) for information about locks."); + + static PyObject * + thread_get_ident(PyObject *self) +@@ -728,6 +896,8 @@ + PyObject *m, *d; + + /* Initialize types: */ ++ if (PyType_Ready(&localdummytype) < 0) ++ return; + if (PyType_Ready(&localtype) < 0) + return; + +@@ -752,6 +922,10 @@ + + nb_threads = 0; + ++ str_dict = PyString_InternFromString("__dict__"); ++ if (str_dict == NULL) ++ return; ++ + /* Initialize the C thread library */ + PyThread_init_thread(); + } +--- a/Modules/signalmodule.c ++++ b/Modules/signalmodule.c +@@ -257,6 +257,25 @@ + void (*func)(int); + if (!PyArg_ParseTuple(args, "iO:signal", &sig_num, &obj)) + return NULL; ++#ifdef MS_WINDOWS ++ /* Validate that sig_num is one of the allowable signals */ ++ switch (sig_num) { ++ case SIGABRT: break; ++#ifdef SIGBREAK ++ /* Issue #10003: SIGBREAK is not documented as permitted, but works ++ and corresponds to CTRL_BREAK_EVENT. */ ++ case SIGBREAK: break; ++#endif ++ case SIGFPE: break; ++ case SIGILL: break; ++ case SIGINT: break; ++ case SIGSEGV: break; ++ case SIGTERM: break; ++ default: ++ PyErr_SetString(PyExc_ValueError, "invalid signal value"); ++ return NULL; ++ } ++#endif + #ifdef WITH_THREAD + if (PyThread_get_thread_ident() != main_thread) { + PyErr_SetString(PyExc_ValueError, +--- a/Modules/pwdmodule.c ++++ b/Modules/pwdmodule.c +@@ -98,7 +98,7 @@ + "getpwuid(uid) -> (pw_name,pw_passwd,pw_uid,\n\ + pw_gid,pw_gecos,pw_dir,pw_shell)\n\ + Return the password database entry for the given numeric user ID.\n\ +-See pwd.__doc__ for more on password database entries."); ++See help(pwd) for more on password database entries."); + + static PyObject * + pwd_getpwuid(PyObject *self, PyObject *args) +@@ -119,7 +119,7 @@ + "getpwnam(name) -> (pw_name,pw_passwd,pw_uid,\n\ + pw_gid,pw_gecos,pw_dir,pw_shell)\n\ + Return the password database entry for the given user name.\n\ +-See pwd.__doc__ for more on password database entries."); ++See help(pwd) for more on password database entries."); + + static PyObject * + pwd_getpwnam(PyObject *self, PyObject *args) +@@ -141,7 +141,7 @@ + "getpwall() -> list_of_entries\n\ + Return a list of all available password database entries, \ + in arbitrary order.\n\ +-See pwd.__doc__ for more on password database entries."); ++See help(pwd) for more on password database entries."); + + static PyObject * + pwd_getpwall(PyObject *self) +--- a/Modules/parsermodule.c ++++ b/Modules/parsermodule.c +@@ -1886,8 +1886,8 @@ + return i-1; + } + +-/* 'from' ('.'* dotted_name | '.') 'import' ('*' | '(' import_as_names ')' | +- * import_as_names ++/* import_from: ('from' ('.'* dotted_name | '.'+) ++ * 'import' ('*' | '(' import_as_names ')' | import_as_names)) + */ + static int + validate_import_from(node *tree) +@@ -1897,7 +1897,8 @@ + int havename = (TYPE(CHILD(tree, ndots + 1)) == dotted_name); + int offset = ndots + havename; + int res = validate_ntype(tree, import_from) +- && (nch >= 4 + ndots) ++ && (offset >= 1) ++ && (nch >= 3 + offset) + && validate_name(CHILD(tree, 0), "from") + && (!havename || validate_dotted_name(CHILD(tree, ndots + 1))) + && validate_name(CHILD(tree, offset + 1), "import"); +@@ -2682,14 +2683,15 @@ + static int + validate_decorated(node *tree) + { +- int nch = NCH(tree); +- int ok = (validate_ntype(tree, decorated) +- && (nch == 2) +- && validate_decorators(RCHILD(tree, -2)) +- && (validate_funcdef(RCHILD(tree, -1)) +- || validate_class(RCHILD(tree, -1))) +- ); +- return ok; ++ int nch = NCH(tree); ++ int ok = (validate_ntype(tree, decorated) ++ && (nch == 2) ++ && validate_decorators(RCHILD(tree, -2))); ++ if (TYPE(RCHILD(tree, -1)) == funcdef) ++ ok = ok && validate_funcdef(RCHILD(tree, -1)); ++ else ++ ok = ok && validate_class(RCHILD(tree, -1)); ++ return ok; + } + + static int +--- a/Modules/fcntlmodule.c ++++ b/Modules/fcntlmodule.c +@@ -82,10 +82,10 @@ + Perform the requested operation on file descriptor fd. The operation\n\ + is defined by op and is operating system dependent. These constants are\n\ + available from the fcntl module. The argument arg is optional, and\n\ +-defaults to 0; it may be an int or a string. If arg is given as a string,\n\ ++defaults to 0; it may be an int or a string. If arg is given as a string,\n\ + the return value of fcntl is a string of that length, containing the\n\ +-resulting value put in the arg buffer by the operating system.The length\n\ +-of the arg string is not allowed to exceed 1024 bytes. If the arg given\n\ ++resulting value put in the arg buffer by the operating system. The length\n\ ++of the arg string is not allowed to exceed 1024 bytes. If the arg given\n\ + is an integer or if none is specified, the result value is an integer\n\ + corresponding to the return value of the fcntl call in the C code."); + +@@ -153,7 +153,7 @@ + else { + ret = ioctl(fd, code, arg); + } +- if (mutate_arg && (len < IOCTL_BUFSZ)) { ++ if (mutate_arg && (len <= IOCTL_BUFSZ)) { + memcpy(str, buf, len); + } + if (ret < 0) { +--- a/Modules/_json.c ++++ b/Modules/_json.c +@@ -564,8 +564,8 @@ + end += 6; + /* Decode 4 hex digits */ + for (; next < end; next++) { ++ Py_UNICODE digit = buf[next]; + c2 <<= 4; +- Py_UNICODE digit = buf[next]; + switch (digit) { + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': +@@ -755,8 +755,8 @@ + end += 6; + /* Decode 4 hex digits */ + for (; next < end; next++) { ++ Py_UNICODE digit = buf[next]; + c2 <<= 4; +- Py_UNICODE digit = buf[next]; + switch (digit) { + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': +@@ -2147,7 +2147,7 @@ + } + else { + /* TODO: include repr of key */ +- PyErr_SetString(PyExc_ValueError, "keys must be a string"); ++ PyErr_SetString(PyExc_TypeError, "keys must be a string"); + goto bail; + } + +--- a/Modules/getpath.c ++++ b/Modules/getpath.c +@@ -232,7 +232,11 @@ + if (p[0] == SEP) + strcpy(path, p); + else { +- getcwd(path, MAXPATHLEN); ++ if (!getcwd(path, MAXPATHLEN)) { ++ /* unable to get the current directory */ ++ strcpy(path, p); ++ return; ++ } + if (p[0] == '.' && p[1] == SEP) + p += 2; + joinpath(path, p); +@@ -471,7 +475,7 @@ + if (!ismodule(argv0_path)) { + /* We are in the build directory so use the name of the + executable - we know that the absolute path is passed */ +- strncpy(argv0_path, prog, MAXPATHLEN); ++ strncpy(argv0_path, progpath, MAXPATHLEN); + } + else { + /* Use the location of the library as the progpath */ +--- a/Modules/socketmodule.c ++++ b/Modules/socketmodule.c +@@ -379,7 +379,7 @@ + #define SOCKETCLOSE close + #endif + +-#if defined(HAVE_BLUETOOTH_H) || defined(HAVE_BLUETOOTH_BLUETOOTH_H) && !defined(__NetBSD__) ++#if (defined(HAVE_BLUETOOTH_H) || defined(HAVE_BLUETOOTH_BLUETOOTH_H)) && !defined(__NetBSD__) + #define USE_BLUETOOTH 1 + #if defined(__FreeBSD__) + #define BTPROTO_L2CAP BLUETOOTH_PROTO_L2CAP +@@ -2729,7 +2729,7 @@ + sock_sendall(PySocketSockObject *s, PyObject *args) + { + char *buf; +- int len, n = -1, flags = 0, timeout; ++ int len, n = -1, flags = 0, timeout, saved_errno; + Py_buffer pbuf; + + if (!PyArg_ParseTuple(args, "s*|i:sendall", &pbuf, &flags)) +@@ -2742,42 +2742,44 @@ + return select_error(); + } + +- Py_BEGIN_ALLOW_THREADS + do { ++ Py_BEGIN_ALLOW_THREADS + timeout = internal_select(s, 1); + n = -1; +- if (timeout) +- break; ++ if (!timeout) { + #ifdef __VMS +- n = sendsegmented(s->sock_fd, buf, len, flags); ++ n = sendsegmented(s->sock_fd, buf, len, flags); + #else +- n = send(s->sock_fd, buf, len, flags); ++ n = send(s->sock_fd, buf, len, flags); + #endif ++ } ++ Py_END_ALLOW_THREADS ++ if (timeout == 1) { ++ PyBuffer_Release(&pbuf); ++ PyErr_SetString(socket_timeout, "timed out"); ++ return NULL; ++ } ++ /* PyErr_CheckSignals() might change errno */ ++ saved_errno = errno; ++ /* We must run our signal handlers before looping again. ++ send() can return a successful partial write when it is ++ interrupted, so we can't restrict ourselves to EINTR. */ ++ if (PyErr_CheckSignals()) { ++ PyBuffer_Release(&pbuf); ++ return NULL; ++ } + if (n < 0) { +-#ifdef EINTR +- /* We must handle EINTR here as there is no way for +- * the caller to know how much was sent otherwise. */ +- if (errno == EINTR) { +- /* Run signal handlers. If an exception was +- * raised, abort and leave this socket in +- * an unknown state. */ +- if (PyErr_CheckSignals()) +- return NULL; ++ /* If interrupted, try again */ ++ if (saved_errno == EINTR) + continue; +- } +-#endif +- break; ++ else ++ break; + } + buf += n; + len -= n; + } while (len > 0); +- Py_END_ALLOW_THREADS + PyBuffer_Release(&pbuf); + +- if (timeout == 1) { +- PyErr_SetString(socket_timeout, "timed out"); +- return NULL; +- } + if (n < 0) + return s->errorhandler(); + +--- a/Modules/Setup.dist ++++ b/Modules/Setup.dist +@@ -118,6 +118,7 @@ + # if $HOME is not set + _sre _sre.c # Fredrik Lundh's new regular expressions + _codecs _codecsmodule.c # access to the builtin codecs and codec registry ++_weakref _weakref.c # weak references + + # The zipimport module is always imported at startup. Having it as a + # builtin module avoids some bootstrapping problems and reduces overhead. +@@ -173,7 +174,6 @@ + #_struct _struct.c # binary structure packing/unpacking + #time timemodule.c # -lm # time operations and variables + #operator operator.c # operator.add() and similar goodies +-#_weakref _weakref.c # basic weak reference support + #_testcapi _testcapimodule.c # Python C API test module + #_random _randommodule.c # Random number generator + #_collections _collectionsmodule.c # Container types +--- a/Modules/_math.c ++++ b/Modules/_math.c +@@ -55,14 +55,15 @@ + else if (x >= two_pow_p28) { /* x > 2**28 */ + if (Py_IS_INFINITY(x)) { + return x+x; +- } else { +- return log(x)+ln2; /* acosh(huge)=log(2x) */ + } ++ else { ++ return log(x)+ln2; /* acosh(huge)=log(2x) */ ++ } + } + else if (x == 1.) { +- return 0.0; /* acosh(1) = 0 */ ++ return 0.0; /* acosh(1) = 0 */ + } +- else if (x > 2.) { /* 2 < x < 2**28 */ ++ else if (x > 2.) { /* 2 < x < 2**28 */ + double t = x*x; + return log(2.0*x - 1.0 / (x + sqrt(t - 1.0))); + } +@@ -94,7 +95,7 @@ + return x+x; + } + if (absx < two_pow_m28) { /* |x| < 2**-28 */ +- return x; /* return x inexact except 0 */ ++ return x; /* return x inexact except 0 */ + } + if (absx > two_pow_p28) { /* |x| > 2**28 */ + w = log(absx)+ln2; +@@ -114,9 +115,9 @@ + * Method : + * 1.Reduced x to positive by atanh(-x) = -atanh(x) + * 2.For x>=0.5 +- * 1 2x x +- * atanh(x) = --- * log(1 + -------) = 0.5 * log1p(2 * --------) +- * 2 1 - x 1 - x ++ * 1 2x x ++ * atanh(x) = --- * log(1 + -------) = 0.5 * log1p(2 * -------) ++ * 2 1 - x 1 - x + * + * For x<0.5 + * atanh(x) = 0.5*log1p(2x+2x*x/(1-x)) +@@ -173,15 +174,15 @@ + */ + + if (fabs(x) < 0.7) { +- double u; +- u = exp(x); +- if (u == 1.0) +- return x; +- else +- return (u - 1.0) * x / log(u); ++ double u; ++ u = exp(x); ++ if (u == 1.0) ++ return x; ++ else ++ return (u - 1.0) * x / log(u); + } + else +- return exp(x) - 1.0; ++ return exp(x) - 1.0; + } + + /* log1p(x) = log(1+x). The log1p function is designed to avoid the +@@ -194,7 +195,7 @@ + /* For x small, we use the following approach. Let y be the nearest float + to 1+x, then + +- 1+x = y * (1 - (y-1-x)/y) ++ 1+x = y * (1 - (y-1-x)/y) + + so log(1+x) = log(y) + log(1-(y-1-x)/y). Since (y-1-x)/y is tiny, the + second term is well approximated by (y-1-x)/y. If abs(x) >= +@@ -213,17 +214,19 @@ + + double y; + if (fabs(x) < DBL_EPSILON/2.) { +- return x; +- } else if (-0.5 <= x && x <= 1.) { +- /* WARNING: it's possible than an overeager compiler +- will incorrectly optimize the following two lines +- to the equivalent of "return log(1.+x)". If this +- happens, then results from log1p will be inaccurate +- for small x. */ +- y = 1.+x; +- return log(y)-((y-1.)-x)/y; +- } else { +- /* NaNs and infinities should end up here */ +- return log(1.+x); ++ return x; + } ++ else if (-0.5 <= x && x <= 1.) { ++ /* WARNING: it's possible than an overeager compiler ++ will incorrectly optimize the following two lines ++ to the equivalent of "return log(1.+x)". If this ++ happens, then results from log1p will be inaccurate ++ for small x. */ ++ y = 1.+x; ++ return log(y)-((y-1.)-x)/y; ++ } ++ else { ++ /* NaNs and infinities should end up here */ ++ return log(1.+x); ++ } + } +--- a/Modules/zipimport.c ++++ b/Modules/zipimport.c +@@ -536,19 +536,19 @@ + "is_package(fullname) -> bool.\n\ + \n\ + Return True if the module specified by fullname is a package.\n\ +-Raise ZipImportError is the module couldn't be found."); ++Raise ZipImportError if the module couldn't be found."); + + PyDoc_STRVAR(doc_get_code, + "get_code(fullname) -> code object.\n\ + \n\ + Return the code object for the specified module. Raise ZipImportError\n\ +-is the module couldn't be found."); ++if the module couldn't be found."); + + PyDoc_STRVAR(doc_get_source, + "get_source(fullname) -> source string.\n\ + \n\ + Return the source code for the specified module. Raise ZipImportError\n\ +-is the module couldn't be found, return None if the archive does\n\ ++if the module couldn't be found, return None if the archive does\n\ + contain the module, but has no source for it."); + + +--- a/Modules/expat/COPYING ++++ b/Modules/expat/COPYING +@@ -0,0 +1,21 @@ ++Copyright (c) 1998, 1999, 2000 Thai Open Source Software Center Ltd ++ and Clark Cooper ++ ++Permission is hereby granted, free of charge, to any person obtaining ++a copy of this software and associated documentation files (the ++"Software"), to deal in the Software without restriction, including ++without limitation the rights to use, copy, modify, merge, publish, ++distribute, sublicense, and/or sell copies of the Software, and to ++permit persons to whom the Software is furnished to do so, subject to ++the following conditions: ++ ++The above copyright notice and this permission notice shall be included ++in all copies or substantial portions of the Software. ++ ++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ++EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ++MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. ++IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY ++CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, ++TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE ++SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +--- a/Modules/cStringIO.c ++++ b/Modules/cStringIO.c +@@ -339,12 +339,12 @@ + + /* Read-write object methods */ + +-PyDoc_STRVAR(O_seek__doc__, ++PyDoc_STRVAR(IO_seek__doc__, + "seek(position) -- set the current position\n" + "seek(position, mode) -- mode 0: absolute; 1: relative; 2: relative to EOF"); + + static PyObject * +-O_seek(Oobject *self, PyObject *args) { ++IO_seek(Iobject *self, PyObject *args) { + Py_ssize_t position; + int mode = 0; + +@@ -359,25 +359,10 @@ + position += self->pos; + } + +- if (position > self->buf_size) { +- char *newbuf; +- self->buf_size*=2; +- if (self->buf_size <= position) self->buf_size=position+1; +- newbuf = (char*) realloc(self->buf,self->buf_size); +- if (!newbuf) { +- free(self->buf); +- self->buf = 0; +- self->buf_size=self->pos=0; +- return PyErr_NoMemory(); +- } +- self->buf = newbuf; +- } +- else if (position < 0) position=0; ++ if (position < 0) position=0; + + self->pos=position; + +- while (--position >= self->string_size) self->buf[position]=0; +- + Py_INCREF(Py_None); + return Py_None; + } +@@ -414,6 +399,19 @@ + oself->buf = newbuf; + } + ++ if (oself->string_size < oself->pos) { ++ /* In case of overseek, pad with null bytes the buffer region between ++ the end of stream and the current position. ++ ++ 0 lo string_size hi ++ | |<---used--->|<----------available----------->| ++ | | <--to pad-->|<---to write---> | ++ 0 buf position ++ */ ++ memset(oself->buf + oself->string_size, '\0', ++ (oself->pos - oself->string_size) * sizeof(char)); ++ } ++ + memcpy(oself->buf+oself->pos,c,l); + + assert(oself->pos + l < INT_MAX); +@@ -497,12 +495,12 @@ + {"readline", (PyCFunction)IO_readline, METH_VARARGS, IO_readline__doc__}, + {"readlines", (PyCFunction)IO_readlines,METH_VARARGS, IO_readlines__doc__}, + {"reset", (PyCFunction)IO_reset, METH_NOARGS, IO_reset__doc__}, ++ {"seek", (PyCFunction)IO_seek, METH_VARARGS, IO_seek__doc__}, + {"tell", (PyCFunction)IO_tell, METH_NOARGS, IO_tell__doc__}, + {"truncate", (PyCFunction)IO_truncate, METH_VARARGS, IO_truncate__doc__}, + + /* Read-write StringIO specific methods: */ + {"close", (PyCFunction)O_close, METH_NOARGS, O_close__doc__}, +- {"seek", (PyCFunction)O_seek, METH_VARARGS, O_seek__doc__}, + {"write", (PyCFunction)O_write, METH_VARARGS, O_write__doc__}, + {"writelines", (PyCFunction)O_writelines, METH_O, O_writelines__doc__}, + {NULL, NULL} /* sentinel */ +@@ -595,26 +593,6 @@ + return Py_None; + } + +-static PyObject * +-I_seek(Iobject *self, PyObject *args) { +- Py_ssize_t position; +- int mode = 0; +- +- if (!IO__opencheck(IOOOBJECT(self))) return NULL; +- if (!PyArg_ParseTuple(args, "n|i:seek", &position, &mode)) +- return NULL; +- +- if (mode == 2) position += self->string_size; +- else if (mode == 1) position += self->pos; +- +- if (position < 0) position=0; +- +- self->pos=position; +- +- Py_INCREF(Py_None); +- return Py_None; +-} +- + static struct PyMethodDef I_methods[] = { + /* Common methods: */ + {"flush", (PyCFunction)IO_flush, METH_NOARGS, IO_flush__doc__}, +@@ -624,12 +602,12 @@ + {"readline", (PyCFunction)IO_readline, METH_VARARGS, IO_readline__doc__}, + {"readlines", (PyCFunction)IO_readlines,METH_VARARGS, IO_readlines__doc__}, + {"reset", (PyCFunction)IO_reset, METH_NOARGS, IO_reset__doc__}, ++ {"seek", (PyCFunction)IO_seek, METH_VARARGS, IO_seek__doc__}, + {"tell", (PyCFunction)IO_tell, METH_NOARGS, IO_tell__doc__}, + {"truncate", (PyCFunction)IO_truncate, METH_VARARGS, IO_truncate__doc__}, + + /* Read-only StringIO specific methods: */ + {"close", (PyCFunction)I_close, METH_NOARGS, O_close__doc__}, +- {"seek", (PyCFunction)I_seek, METH_VARARGS, O_seek__doc__}, + {NULL, NULL} + }; + +--- a/Modules/_struct.c ++++ b/Modules/_struct.c +@@ -636,9 +636,13 @@ + static int + np_bool(char *p, PyObject *v, const formatdef *f) + { +- BOOL_TYPE y; ++ int y; ++ BOOL_TYPE x; + y = PyObject_IsTrue(v); +- memcpy(p, (char *)&y, sizeof y); ++ if (y < 0) ++ return -1; ++ x = y; ++ memcpy(p, (char *)&x, sizeof x); + return 0; + } + +@@ -908,9 +912,11 @@ + static int + bp_bool(char *p, PyObject *v, const formatdef *f) + { +- char y; ++ int y; + y = PyObject_IsTrue(v); +- memcpy(p, (char *)&y, sizeof y); ++ if (y < 0) ++ return -1; ++ *p = (char)y; + return 0; + } + +@@ -1283,6 +1289,9 @@ + PyErr_NoMemory(); + return -1; + } ++ /* Free any s_codes value left over from a previous initialization. */ ++ if (self->s_codes != NULL) ++ PyMem_FREE(self->s_codes); + self->s_codes = codes; + + s = fmt; +--- a/Modules/posixmodule.c ++++ b/Modules/posixmodule.c +@@ -1957,9 +1957,27 @@ + "getcwd() -> path\n\n\ + Return a string representing the current working directory."); + ++#if (defined(__sun) && defined(__SVR4)) || defined(__OpenBSD__) ++/* Issue 9185: getcwd() returns NULL/ERANGE indefinitely. */ + static PyObject * + posix_getcwd(PyObject *self, PyObject *noargs) + { ++ char buf[PATH_MAX+2]; ++ char *res; ++ ++ Py_BEGIN_ALLOW_THREADS ++ res = getcwd(buf, sizeof buf); ++ Py_END_ALLOW_THREADS ++ ++ if (res == NULL) ++ return posix_error(); ++ ++ return PyString_FromString(buf); ++} ++#else ++static PyObject * ++posix_getcwd(PyObject *self, PyObject *noargs) ++{ + int bufsize_incr = 1024; + int bufsize = 0; + char *tmpbuf = NULL; +@@ -1993,6 +2011,7 @@ + + return dynamic_return; + } ++#endif /* getcwd() NULL/ERANGE workaround. */ + + #ifdef Py_USING_UNICODE + PyDoc_STRVAR(posix_getcwdu__doc__, +@@ -2108,7 +2127,9 @@ + free(wnamebuf); + return NULL; + } ++ Py_BEGIN_ALLOW_THREADS + hFindFile = FindFirstFileW(wnamebuf, &wFileData); ++ Py_END_ALLOW_THREADS + if (hFindFile == INVALID_HANDLE_VALUE) { + int error = GetLastError(); + if (error == ERROR_FILE_NOT_FOUND) { +@@ -2178,7 +2199,9 @@ + if ((d = PyList_New(0)) == NULL) + return NULL; + ++ Py_BEGIN_ALLOW_THREADS + hFindFile = FindFirstFile(namebuf, &FileData); ++ Py_END_ALLOW_THREADS + if (hFindFile == INVALID_HANDLE_VALUE) { + int error = GetLastError(); + if (error == ERROR_FILE_NOT_FOUND) +@@ -2310,11 +2333,16 @@ + } + if (!PyArg_ParseTuple(args, "et:listdir", Py_FileSystemDefaultEncoding, &name)) + return NULL; +- if ((dirp = opendir(name)) == NULL) { ++ Py_BEGIN_ALLOW_THREADS ++ dirp = opendir(name); ++ Py_END_ALLOW_THREADS ++ if (dirp == NULL) { + return posix_error_with_allocated_filename(name); + } + if ((d = PyList_New(0)) == NULL) { ++ Py_BEGIN_ALLOW_THREADS + closedir(dirp); ++ Py_END_ALLOW_THREADS + PyMem_Free(name); + return NULL; + } +@@ -2327,7 +2355,9 @@ + if (errno == 0) { + break; + } else { ++ Py_BEGIN_ALLOW_THREADS + closedir(dirp); ++ Py_END_ALLOW_THREADS + Py_DECREF(d); + return posix_error_with_allocated_filename(name); + } +@@ -2368,7 +2398,9 @@ + } + Py_DECREF(v); + } ++ Py_BEGIN_ALLOW_THREADS + closedir(dirp); ++ Py_END_ALLOW_THREADS + PyMem_Free(name); + + return d; +@@ -3858,17 +3890,49 @@ + #define MAX_GROUPS 64 + #endif + gid_t grouplist[MAX_GROUPS]; ++ ++ /* On MacOSX getgroups(2) can return more than MAX_GROUPS results ++ * This is a helper variable to store the intermediate result when ++ * that happens. ++ * ++ * To keep the code readable the OSX behaviour is unconditional, ++ * according to the POSIX spec this should be safe on all unix-y ++ * systems. ++ */ ++ gid_t* alt_grouplist = grouplist; + int n; + + n = getgroups(MAX_GROUPS, grouplist); +- if (n < 0) +- posix_error(); +- else { +- result = PyList_New(n); +- if (result != NULL) { ++ if (n < 0) { ++ if (errno == EINVAL) { ++ n = getgroups(0, NULL); ++ if (n == -1) { ++ return posix_error(); ++ } ++ if (n == 0) { ++ /* Avoid malloc(0) */ ++ alt_grouplist = grouplist; ++ } else { ++ alt_grouplist = PyMem_Malloc(n * sizeof(gid_t)); ++ if (alt_grouplist == NULL) { ++ errno = EINVAL; ++ return posix_error(); ++ } ++ n = getgroups(n, alt_grouplist); ++ if (n == -1) { ++ PyMem_Free(alt_grouplist); ++ return posix_error(); ++ } ++ } ++ } else { ++ return posix_error(); ++ } ++ } ++ result = PyList_New(n); ++ if (result != NULL) { + int i; + for (i = 0; i < n; ++i) { +- PyObject *o = PyInt_FromLong((long)grouplist[i]); ++ PyObject *o = PyInt_FromLong((long)alt_grouplist[i]); + if (o == NULL) { + Py_DECREF(result); + result = NULL; +@@ -3876,9 +3940,12 @@ + } + PyList_SET_ITEM(result, i, o); + } +- } + } + ++ if (alt_grouplist != grouplist) { ++ PyMem_Free(alt_grouplist); ++ } ++ + return result; + } + #endif +@@ -8552,7 +8619,7 @@ + #ifdef HAVE_GETRESGID + PyDoc_STRVAR(posix_getresgid__doc__, + "getresgid() -> (rgid, egid, sgid)\n\n\ +-Get tuple of the current process's real, effective, and saved user ids."); ++Get tuple of the current process's real, effective, and saved group ids."); + + static PyObject* + posix_getresgid (PyObject *self, PyObject *noargs) +--- a/Modules/_cursesmodule.c ++++ b/Modules/_cursesmodule.c +@@ -2047,7 +2047,7 @@ + } + } + +- if (setupterm(termstr,fd,&err) == ERR) { ++ if (!initialised_setupterm && setupterm(termstr,fd,&err) == ERR) { + char* s = "setupterm: unknown error"; + + if (err == 0) { +--- a/Modules/future_builtins.c ++++ b/Modules/future_builtins.c +@@ -14,12 +14,20 @@ + \n\ + Functions:\n\ + \n\ +-hex(arg) -- Returns the hexadecimal representation of an integer\n\ +-oct(arg) -- Returns the octal representation of an integer\n\ ++ascii(arg) -- Returns the canonical string representation of an object.\n\ ++filter(pred, iterable) -- Returns an iterator yielding those items of \n\ ++ iterable for which pred(item) is true.\n\ ++hex(arg) -- Returns the hexadecimal representation of an integer.\n\ ++map(func, *iterables) -- Returns an iterator that computes the function \n\ ++ using arguments from each of the iterables.\n\ ++oct(arg) -- Returns the octal representation of an integer.\n\ ++zip(iter1 [,iter2 [...]]) -- Returns a zip object whose .next() method \n\ ++ returns a tuple where the i-th element comes from the i-th iterable \n\ ++ argument.\n\ + \n\ + The typical usage of this module is to replace existing builtins in a\n\ + module's namespace:\n \n\ +-from future_builtins import hex, oct\n"); ++from future_builtins import ascii, filter, map, hex, oct, zip\n"); + + static PyObject * + builtin_hex(PyObject *self, PyObject *v) + +Property changes on: Modules +___________________________________________________________________ +Modified: svn:ignore + - Setup +Makefile.pre +Setup.thread +Setup.config +Setup.local +hassignal +config.c +Makefile +add2lib + + Setup +Makefile.pre +Setup.thread +Setup.config +Setup.local +hassignal +config.c +Makefile +add2lib +ld_so_aix + + +--- a/pyconfig.h.in ++++ b/pyconfig.h.in +@@ -36,6 +36,9 @@ + /* Define if --enable-ipv6 is specified */ + #undef ENABLE_IPV6 + ++/* Define if flock needs to be linked with bsd library. */ ++#undef FLOCK_NEEDS_LIBBSD ++ + /* Define if getpgrp() must be called as getpgrp(0). */ + #undef GETPGRP_HAVE_ARG + +@@ -79,6 +82,9 @@ + /* Define if nice() returns success/failure instead of the new priority. */ + #undef HAVE_BROKEN_NICE + ++/* Define if the system reports an invalid PIPE_BUF value. */ ++#undef HAVE_BROKEN_PIPE_BUF ++ + /* Define if poll() sets errno on invalid file descriptors. */ + #undef HAVE_BROKEN_POLL + +@@ -213,7 +219,7 @@ + /* Define to 1 if you have the `finite' function. */ + #undef HAVE_FINITE + +-/* Define if you have the 'flock' function. */ ++/* Define to 1 if you have the `flock' function. */ + #undef HAVE_FLOCK + + /* Define to 1 if you have the `fork' function. */ + +Property changes on: . +___________________________________________________________________ +Added: svnmerge-blocked + + /python/branches/py3k:82526,82593,82759,82767,82801,82804,82848,82873,82887,82931,82937,82949,82951,82964,82997,83025,83065,83107,83112,83157,83177,83181-83182,83188,83202,83212-83213,83217-83220,83222,83231,83234,83236,83260,83262-83263,83266,83270,83274-83275,83283-83287,83291-83294,83308,83315-83323,83325-83327,83329,83339,83342-83343,83348-83351,83355,83359-83361,83371,83375,83390,83394,83399,83404,83406,83501,83526-83528,83538,83542-83543,83560-83561,83566,83569,83580,83584,83605-83618,83649,83829,83851,83854,83863,83886-83887,83894-83895,83949,84011,84016-84017,84019-84020,84036,84038-84039,84081-84082,84142,84249,84347,84363,84394,84397,84407,84448,84467-84469,84476-84479,84481,84485,84520,84522,84528-84529,84533,84542,84552,84579,84643-84645,84684,84705-84706,84741,84747,84751,84762,84790,84807,84825-84830,84876,84897,84899,84902-84903,84949,84953,85132,85137,85197,85199,85228,85272-85273,85322,85326 +Added: svnmerge-integrated + + /python/branches/py3k:0-82507,82542,82570,82573,82587,82594-82596,82598-82599,82601,82607,82615,82628-82632,82637,82646-82650,82654,82724,82730-82731,82735,82739-82741,82757-82758,82760-82764,82766,82771,82777,82780,82785,82789-82790,82798-82800,82802-82803,82805-82816,82821,82823-82824,82826-82827,82829-82834,82836,82839-82842,82844-82847,82849-82855,82858-82872,82874-82884,82886,82888-82898,82900-82909,82911-82917,82920,82922-82926,82928-82930,82932-82936,82938-82946,82948,82950,82952-82953,82955-82956,82958-82961,82963,82965,82968-82970,82972-82977,82979-82982,82984,82986-82994,82996,82998-83004,83007-83008,83010,83012-83015,83017-83024,83026-83034,83036-83045,83047-83052,83054-83058,83060-83064,83068-83072,83074-83077,83079-83088,83093,83096-83098,83103-83106,83109-83110,83113-83114,83116-83124,83126-83138,83140-83148,83152-83153,83155-83156,83158-83161,83163-83169,83171-83172,83174-83176,83178-83180,83183,83185-83187,83189-83190,83192-83194,83198-83201,83203-83211,83221,83223-83230,83232-83233,83238-83259,83261,83264-83265,83267-83269,83271-83273,83276-83282,83290,83295,83297-83306,83309-83312,83314,83328,83330-83334,83340-83341,83344-83347,83352,83354,83356-83358,83362-83370,83372-83374,83377-83389,83391-83393,83395-83396,83398,83400-83402,83405,83407-83414,83416-83455,83457-83487,83489-83493,83495-83500,83502-83512,83514-83515,83517-83520,83522-83525,83530-83537,83539-83541,83544-83559,83562-83565,83567-83568,83570-83579,83581-83583,83585-83604,83619-83635,83637-83648,83650-83672,83674-83677,83679-83680,83682-83695,83697,83700,83702-83704,83706,83709-83711,83715-83721,83723-83725,83727-83728,83730,83732-83735,83737-83740,83743,83745-83749,83751-83754,83756-83757,83760-83761,83763-83767,83769,83771-83773,83780-83782,83786-83791,83793-83794,83796-83801,83803,83805-83807,83810-83815,83817-83827,83831-83833,83836-83844,83847-83850,83852-83853,83855-83859,83864-83868,83872-83873,83878-83879,83881,83883-83884,83893,83896-83907,83909-83931,83934-83935,83938-83946,83950,83952-83965,83967-83970,83977,83982-83985,83987,83992-83997,83999-84007,84010,84014-84015,84018,84021-84025,84027-84029,84031-84034,84037,84040-84042,84044,84046,84048-84053,84055,84061,84064-84066,84071,84073,84075,84077,84079,84086-84087,84089-84091,84093,84097,84099-84110,84114-84119,84125,84127-84128,84134-84136,84141,84148,84151-84152,84158,84160-84162,84166-84167,84169,84172-84176,84178,84187,84190,84192,84196-84198,84207,84209,84211,84213-84217,84219-84220,84230,84232-84235,84239-84246,84250-84251,84253-84255,84257,84260,84263-84264,84266,84269,84272-84276,84280,84284-84286,84289-84293,84296-84302,84305,84310-84312,84318,84320-84328,84330-84331,84334-84336,84340,84342-84346,84348-84350,84354,84358,84361,84365-84368,84371,84375,84377,84382,84385-84386,84390-84393,84395-84396,84398-84399,84402,84404,84408-84413,84416-84428,84433,84438,84441-84443,84445-84446,84451-84454,84457,84460-84461,84463,84465-84466,84470-84474,84480,84482,84484,84489-84496,84498-84499,84503,84506-84508,84521,84526-84527,84530-84531,84534-84536,84538-84539,84541,84543,84553,84556-84560,84566-84567,84572,84582-84586,84589-84594,84597-84600,84603-84606,84608-84616,84618-84619,84621-84628,84630,84635-84637,84650-84652,84654,84656,84660-84663,84665,84667-84668,84670,84674-84676,84678,84680,84682-84683,84691,84701-84702,84708,84711-84713,84715-84716,84718-84723,84725,84729,84732-84734,84736-84740,84742,84745-84746,84753-84754,84757-84761,84763-84773,84775-84779,84782-84784,84787,84793,84800-84806,84808-84812,84814-84817,84824,84831-84835,84837,84842,84845-84846,84848,84850-84851,84853-84855,84860-84863,84866,84868,84871-84873,84877-84881,84883-84886,84889-84892,84894,84896,84898,84900-84901,84904,84909-84913,84915-84916,84923-84924,84932-84935,84939-84940,84942-84943,84945-84948,84951,84954-84955,84958-84960,84964,84971-84972,84975,84980-84982,84986,84990,84994-84998,85000-85002,85004,85006-85011,85014,85016,85018-85027,85030,85032,85034-85042,85044-85046,85049-85053,85056-85069,85076,85079,85081,85083,85085,85089,85091-85092,85098-85099,85101-85110,85112,85122-85124,85126-85129,85131,85133-85136,85138-85139,85141-85145,85147-85152,85154-85171,85179-85181,85183-85196,85198,85200-85207,85210-85219,85222-85225,85227,85230-85234,85236-85238,85240,85274,85276,85291,85299,85315,85328,85342,85349,85353,85386-85389,85392,85395,85398,85400,85403-85404,85423,85429,85432,85436,85469,85472,85482,85492,85495-85500,85503,85543,85554,85562 + --- python2.7-2.7.orig/debian/patches/issue9012a.diff +++ python2.7-2.7/debian/patches/issue9012a.diff @@ -0,0 +1,15 @@ +# DP: Link _math.o only once to the static library. + +Index: b/Modules/Setup.dist +=================================================================== +--- a/Modules/Setup.dist ++++ b/Modules/Setup.dist +@@ -168,7 +168,7 @@ + # Modules that should always be present (non UNIX dependent): + + #array arraymodule.c # array objects +-#cmath cmathmodule.c _math.c # -lm # complex math library functions ++#cmath cmathmodule.c # -lm # complex math library functions + #math mathmodule.c _math.c # -lm # math library functions, e.g. sin() + #_struct _struct.c # binary structure packing/unpacking + #time timemodule.c # -lm # time operations and variables --- python2.7-2.7.orig/debian/patches/hurd-disable-nonworking-constants.diff +++ python2.7-2.7/debian/patches/hurd-disable-nonworking-constants.diff @@ -0,0 +1,38 @@ +# DP: Comment out constant exposed on the API which are not implemented on +# DP: GNU/Hurd. They would not work at runtime anyway. + +Index: python2.6-2.6.5+20100521/Modules/posixmodule.c +=================================================================== +--- python2.6-2.6.5+20100521.orig/Modules/posixmodule.c 2010-05-21 16:05:47.787739235 +0200 ++++ python2.6-2.6.5+20100521/Modules/posixmodule.c 2010-05-21 16:07:53.296710141 +0200 +@@ -8880,12 +8880,14 @@ + #ifdef O_LARGEFILE + if (ins(d, "O_LARGEFILE", (long)O_LARGEFILE)) return -1; + #endif ++#ifndef __GNU__ + #ifdef O_SHLOCK + if (ins(d, "O_SHLOCK", (long)O_SHLOCK)) return -1; + #endif + #ifdef O_EXLOCK + if (ins(d, "O_EXLOCK", (long)O_EXLOCK)) return -1; + #endif ++#endif + + /* MS Windows */ + #ifdef O_NOINHERIT +Index: python2.6-2.6.5+20100521/Modules/socketmodule.c +=================================================================== +--- python2.6-2.6.5+20100521.orig/Modules/socketmodule.c 2010-05-21 16:05:47.811711908 +0200 ++++ python2.6-2.6.5+20100521/Modules/socketmodule.c 2010-05-21 16:07:25.772711483 +0200 +@@ -4685,9 +4685,11 @@ + #ifdef SO_OOBINLINE + PyModule_AddIntConstant(m, "SO_OOBINLINE", SO_OOBINLINE); + #endif ++#ifndef __GNU__ + #ifdef SO_REUSEPORT + PyModule_AddIntConstant(m, "SO_REUSEPORT", SO_REUSEPORT); + #endif ++#endif + #ifdef SO_SNDBUF + PyModule_AddIntConstant(m, "SO_SNDBUF", SO_SNDBUF); + #endif --- python2.7-2.7.orig/debian/patches/arm-float.dpatch +++ python2.7-2.7/debian/patches/arm-float.dpatch @@ -0,0 +1,119 @@ +#! /bin/sh -e + +# DP: Support mixed-endian IEEE floating point, as found in the ARM old-ABI. + +dir= +if [ $# -eq 3 -a "$2" = '-d' ]; then + pdir="-d $3" + dir="$3/" +elif [ $# -ne 1 ]; then + echo >&2 "usage: `basename $0`: -patch|-unpatch [-d ]" + exit 1 +fi +case "$1" in + -patch) + patch $pdir -f --no-backup-if-mismatch -p0 < $0 + ;; + -unpatch) + patch $pdir -f --no-backup-if-mismatch -R -p0 < $0 + ;; + *) + echo >&2 "usage: `basename $0`: -patch|-unpatch [-d ]" + exit 1 +esac +exit 0 + +--- Objects/floatobject.c.orig 2006-05-25 10:53:30.000000000 -0500 ++++ Objects/floatobject.c 2007-07-27 06:43:15.000000000 -0500 +@@ -982,7 +982,7 @@ + /* this is for the benefit of the pack/unpack routines below */ + + typedef enum { +- unknown_format, ieee_big_endian_format, ieee_little_endian_format ++ unknown_format, ieee_big_endian_format, ieee_little_endian_format, ieee_mixed_endian_format + } float_format_type; + + static float_format_type double_format, float_format; +@@ -1021,6 +1021,8 @@ + return PyString_FromString("IEEE, little-endian"); + case ieee_big_endian_format: + return PyString_FromString("IEEE, big-endian"); ++ case ieee_mixed_endian_format: ++ return PyString_FromString("IEEE, mixed-endian"); + default: + Py_FatalError("insane float_format or double_format"); + return NULL; +@@ -1073,11 +1075,14 @@ + else if (strcmp(format, "IEEE, big-endian") == 0) { + f = ieee_big_endian_format; + } ++ else if (strcmp(format, "IEEE, mixed-endian") == 0) { ++ f = ieee_mixed_endian_format; ++ } + else { + PyErr_SetString(PyExc_ValueError, + "__setformat__() argument 2 must be " +- "'unknown', 'IEEE, little-endian' or " +- "'IEEE, big-endian'"); ++ "'unknown', 'IEEE, little-endian', " ++ "'IEEE, big-endian' or 'IEEE, mixed-endian'"); + return NULL; + + } +@@ -1230,6 +1235,8 @@ + detected_double_format = ieee_big_endian_format; + else if (memcmp(&x, "\x05\x04\x03\x02\x01\xff\x3f\x43", 8) == 0) + detected_double_format = ieee_little_endian_format; ++ else if (memcmp(&x, "\x01\xff\x3f\x43\x05\x04\x03\x02", 8) == 0) ++ detected_double_format = ieee_mixed_endian_format; + else + detected_double_format = unknown_format; + } +@@ -1565,8 +1572,19 @@ + p += 7; + incr = -1; + } ++ else if (double_format == ieee_mixed_endian_format) { ++ if (le) ++ p += 4; ++ else { ++ p += 3; ++ incr = -1; ++ } ++ } + + for (i = 0; i < 8; i++) { ++ if (double_format == ieee_mixed_endian_format && i == 4) ++ p += -8 * incr; ++ + *p = *s++; + p += incr; + } +@@ -1739,6 +1757,27 @@ + } + memcpy(&x, buf, 8); + } ++ else if (double_format == ieee_mixed_endian_format) { ++ char buf[8]; ++ char *d; ++ int i, incr = 1; ++ ++ if (le) ++ d = &buf[4]; ++ else ++ d = &buf[3]; ++ ++ for (i = 0; i < 4; i++) { ++ *d = *p++; ++ d += incr; ++ } ++ d += -8 * incr; ++ for (i = 0; i < 4; i++) { ++ *d = *p++; ++ d += incr; ++ } ++ memcpy(&x, buf, 8); ++ } + else { + memcpy(&x, p, 8); + } --- python2.7-2.7.orig/debian/source/format +++ python2.7-2.7/debian/source/format @@ -0,0 +1 @@ +1.0