133
213
diff -r 8527427914a2 Doc/distutils/apiref.rst
134
214
--- a/Doc/distutils/apiref.rst
135
215
+++ b/Doc/distutils/apiref.rst
217
+====================+================================+=============================================================+
218
| *name* | The name of the package | a string |
219
+--------------------+--------------------------------+-------------------------------------------------------------+
220
- | *version* | The version number of the | See :mod:`distutils.version` |
222
+ | *version* | The version number of the | a string |
223
+ | | package; see | |
224
+ | | :mod:`distutils.version` | |
225
+--------------------+--------------------------------+-------------------------------------------------------------+
226
| *description* | A single line describing the | a string |
229
| | maintainer, if different from | |
231
+--------------------+--------------------------------+-------------------------------------------------------------+
232
- | *maintainer_email* | The email address of the | |
233
+ | *maintainer_email* | The email address of the | a string |
234
| | current maintainer, if | |
235
| | different from the author | |
236
+--------------------+--------------------------------+-------------------------------------------------------------+
237
- | *url* | A URL for the package | a URL |
238
+ | *url* | A URL for the package | a string |
240
+--------------------+--------------------------------+-------------------------------------------------------------+
241
- | *download_url* | A URL to download the package | a URL |
242
+ | *download_url* | A URL to download the package | a string |
243
+--------------------+--------------------------------+-------------------------------------------------------------+
244
| *packages* | A list of Python packages that | a list of strings |
245
| | distutils will manipulate | |
247
| | files to be built and | |
249
+--------------------+--------------------------------+-------------------------------------------------------------+
250
- | *ext_modules* | A list of Python extensions to | A list of instances of |
251
+ | *ext_modules* | A list of Python extensions to | a list of instances of |
137
252
| | be built | :class:`distutils.core.Extension` |
138
253
+--------------------+--------------------------------+-------------------------------------------------------------+
139
| *classifiers* | A list of categories for the | The list of available |
254
- | *classifiers* | A list of categories for the | The list of available |
140
255
- | | package | categorizations is at |
141
256
- | | | http://pypi.python.org/pypi?:action=list_classifiers. |
142
+ | | package | categorizations is available on `PyPI |
143
+ | | | <http://pypi.python.org/pypi?:action=list_classifiers>`_. |
257
+ | *classifiers* | A list of categories for the | a list of strings; valid classifiers are listed on `PyPI |
258
+ | | package | <http://pypi.python.org/pypi?:action=list_classifiers>`_. |
144
259
+--------------------+--------------------------------+-------------------------------------------------------------+
145
| *distclass* | the :class:`Distribution` | A subclass of |
260
- | *distclass* | the :class:`Distribution` | A subclass of |
261
+ | *distclass* | the :class:`Distribution` | a subclass of |
146
262
| | class to use | :class:`distutils.core.Distribution` |
147
@@ -1815,7 +1815,7 @@
263
+--------------------+--------------------------------+-------------------------------------------------------------+
264
| *script_name* | The name of the setup.py | a string |
266
| *script_args* | Arguments to supply to the | a list of strings |
268
+--------------------+--------------------------------+-------------------------------------------------------------+
269
- | *options* | default options for the setup | a string |
270
+ | *options* | default options for the setup | a dictionary |
272
+--------------------+--------------------------------+-------------------------------------------------------------+
273
| *license* | The license for the package | a string |
274
+--------------------+--------------------------------+-------------------------------------------------------------+
275
- | *keywords* | Descriptive meta-data, see | |
276
+ | *keywords* | Descriptive meta-data, see | a list of strings or a comma-separated string |
278
+--------------------+--------------------------------+-------------------------------------------------------------+
279
- | *platforms* | | |
280
+ | *platforms* | | a list of strings or a comma-separated string |
281
+--------------------+--------------------------------+-------------------------------------------------------------+
282
| *cmdclass* | A mapping of command names to | a dictionary |
283
| | :class:`Command` subclasses | |
284
@@ -165,13 +165,13 @@
285
+------------------------+--------------------------------+---------------------------+
286
| argument name | value | type |
287
+========================+================================+===========================+
288
- | *name* | the full name of the | string |
289
+ | *name* | the full name of the | a string |
290
| | extension, including any | |
291
| | packages --- ie. *not* a | |
292
| | filename or pathname, but | |
293
| | Python dotted name | |
294
+------------------------+--------------------------------+---------------------------+
295
- | *sources* | list of source filenames, | string |
296
+ | *sources* | list of source filenames, | a list of strings |
297
| | relative to the distribution | |
298
| | root (where the setup script | |
299
| | lives), in Unix form (slash- | |
300
@@ -184,12 +184,12 @@
301
| | as source for a Python | |
303
+------------------------+--------------------------------+---------------------------+
304
- | *include_dirs* | list of directories to search | string |
305
+ | *include_dirs* | list of directories to search | a list of strings |
306
| | for C/C++ header files (in | |
307
| | Unix form for portability) | |
308
+------------------------+--------------------------------+---------------------------+
309
- | *define_macros* | list of macros to define; each | (string, string) tuple or |
310
- | | macro is defined using a | (name, ``None``) |
311
+ | *define_macros* | list of macros to define; each | a list of tuples |
312
+ | | macro is defined using a | |
313
| | 2-tuple ``(name, value)``, | |
314
| | where *value* is | |
315
| | either the string to define it | |
316
@@ -200,31 +200,31 @@
317
| | on Unix C compiler command | |
319
+------------------------+--------------------------------+---------------------------+
320
- | *undef_macros* | list of macros to undefine | string |
321
+ | *undef_macros* | list of macros to undefine | a list of strings |
323
+------------------------+--------------------------------+---------------------------+
324
- | *library_dirs* | list of directories to search | string |
325
+ | *library_dirs* | list of directories to search | a list of strings |
326
| | for C/C++ libraries at link | |
328
+------------------------+--------------------------------+---------------------------+
329
- | *libraries* | list of library names (not | string |
330
+ | *libraries* | list of library names (not | a list of strings |
331
| | filenames or paths) to link | |
333
+------------------------+--------------------------------+---------------------------+
334
- | *runtime_library_dirs* | list of directories to search | string |
335
+ | *runtime_library_dirs* | list of directories to search | a list of strings |
336
| | for C/C++ libraries at run | |
337
| | time (for shared extensions, | |
338
| | this is when the extension is | |
340
+------------------------+--------------------------------+---------------------------+
341
- | *extra_objects* | list of extra files to link | string |
342
+ | *extra_objects* | list of extra files to link | a list of strings |
343
| | with (eg. object files not | |
344
| | implied by 'sources', static | |
345
| | library that must be | |
346
| | explicitly specified, binary | |
347
| | resource files, etc.) | |
348
+------------------------+--------------------------------+---------------------------+
349
- | *extra_compile_args* | any extra platform- and | string |
350
+ | *extra_compile_args* | any extra platform- and | a list of strings |
351
| | compiler-specific information | |
352
| | to use when compiling the | |
353
| | source files in 'sources'. For | |
355
| | for other platforms it could | |
357
+------------------------+--------------------------------+---------------------------+
358
- | *extra_link_args* | any extra platform- and | string |
359
+ | *extra_link_args* | any extra platform- and | a list of strings |
360
| | compiler-specific information | |
361
| | to use when linking object | |
362
| | files together to create the | |
364
| | Similar interpretation as for | |
365
| | 'extra_compile_args'. | |
366
+------------------------+--------------------------------+---------------------------+
367
- | *export_symbols* | list of symbols to be exported | string |
368
+ | *export_symbols* | list of symbols to be exported | a list of strings |
369
| | from a shared extension. Not | |
370
| | used on all platforms, and not | |
371
| | generally necessary for Python | |
372
@@ -252,15 +252,20 @@
373
| | export exactly one symbol: | |
374
| | ``init`` + extension_name. | |
375
+------------------------+--------------------------------+---------------------------+
376
- | *depends* | list of files that the | string |
377
+ | *depends* | list of files that the | a list of strings |
378
| | extension depends on | |
379
+------------------------+--------------------------------+---------------------------+
380
- | *language* | extension language (i.e. | string |
381
+ | *language* | extension language (i.e. | a string |
382
| | ``'c'``, ``'c++'``, | |
383
| | ``'objc'``). Will be detected | |
384
| | from the source extensions if | |
385
| | not provided. | |
386
+------------------------+--------------------------------+---------------------------+
387
+ | *optional* | specifies that a build failure | a boolean |
388
+ | | in the extension should not | |
389
+ | | abort the build process, but | |
390
+ | | simply skip the extension. | |
391
+ +------------------------+--------------------------------+---------------------------+
394
.. class:: Distribution
395
@@ -1736,7 +1741,7 @@
396
Set final values for all the options that this command supports. This is
397
always called as late as possible, ie. after any option assignments from the
398
command-line or from other commands have been done. Thus, this is the place
399
- to to code option dependencies: if *foo* depends on *bar*, then it is safe to
400
+ to code option dependencies: if *foo* depends on *bar*, then it is safe to
401
set *foo* from *bar* as long as *foo* still has the same value it was
402
assigned in :meth:`initialize_options`.
404
@@ -1815,7 +1820,7 @@
148
405
.. module:: distutils.command.bdist_msi
149
406
:synopsis: Build a binary distribution as a Windows MSI file
301
690
A value passed to a function or method, assigned to a named local
694
Python source code is compiled into bytecode, the internal representation
695
- of a Python program in the interpreter. The bytecode is also cached in
696
- ``.pyc`` and ``.pyo`` files so that executing the same file is faster the
697
- second time (recompilation from source to bytecode can be avoided). This
698
- "intermediate language" is said to run on a :term:`virtual machine`
699
- that executes the machine code corresponding to each bytecode.
700
+ of a Python program in the CPython interpreter. The bytecode is also
701
+ cached in ``.pyc`` and ``.pyo`` files so that executing the same file is
702
+ faster the second time (recompilation from source to bytecode can be
703
+ avoided). This "intermediate language" is said to run on a
704
+ :term:`virtual machine` that executes the machine code corresponding to
705
+ each bytecode. Do note that bytecodes are not expected to work between
706
+ different Python virtual machines, nor to be stable between Python
709
A list of bytecode instructions can be found in the documentation for
710
:ref:`the dis module <bytecodes>`.
715
- See :ref:`the documentation for function definition <function>` for more
717
+ The same concept exists for classes, but is less commonly used there. See
718
+ the documentation for :ref:`function definitions <function>` and
719
+ :ref:`class definitions <class>` for more about decorators.
722
Any *new-style* object which defines the methods :meth:`__get__`,
724
well-designed code improves its flexibility by allowing polymorphic
725
substitution. Duck-typing avoids tests using :func:`type` or
726
:func:`isinstance`. (Note, however, that duck-typing can be complemented
727
- with :term:`abstract base class`\ es.) Instead, it typically employs
728
- :func:`hasattr` tests or :term:`EAFP` programming.
729
+ with :term:`abstract base classes <abstract base class>`.) Instead, it
730
+ typically employs :func:`hasattr` tests or :term:`EAFP` programming.
733
Easier to ask for forgiveness than permission. This common Python coding
734
@@ -177,17 +185,34 @@
737
A piece of syntax which can be evaluated to some value. In other words,
738
- an expression is an accumulation of expression elements like literals, names,
739
- attribute access, operators or function calls which all return a value.
740
- In contrast to many other languages, not all language constructs are expressions.
741
- There are also :term:`statement`\s which cannot be used as expressions,
742
- such as :keyword:`print` or :keyword:`if`. Assignments are also statements,
744
+ an expression is an accumulation of expression elements like literals,
745
+ names, attribute access, operators or function calls which all return a
746
+ value. In contrast to many other languages, not all language constructs
747
+ are expressions. There are also :term:`statement`\s which cannot be used
748
+ as expressions, such as :keyword:`print` or :keyword:`if`. Assignments
749
+ are also statements, not expressions.
752
A module written in C or C++, using Python's C API to interact with the
753
core and with user code.
756
+ An object exposing a file-oriented API (with methods such as
757
+ :meth:`read()` or :meth:`write()`) to an underlying resource. Depending
758
+ on the way it was created, a file object can mediate access to a real
759
+ on-disk file or to another other type of storage or communication device
760
+ (for example standard input/output, in-memory buffers, sockets, pipes,
761
+ etc.). File objects are also called :dfn:`file-like objects` or
764
+ There are actually three categories of file objects: raw binary files,
765
+ buffered binary files and text files. Their interfaces are defined in the
766
+ :mod:`io` module. The canonical way to create a file object is by using
767
+ the :func:`open` function.
770
+ A synonym for :term:`file object`.
773
An object that tries to find the :term:`loader` for a module. It must
774
implement a method named :meth:`find_module`. See :pep:`302` for
776
slowly. See also :term:`interactive`.
779
- A container object capable of returning its members one at a
780
+ An object capable of returning its members one at a
781
time. Examples of iterables include all sequence types (such as
782
:class:`list`, :class:`str`, and :class:`tuple`) and some non-sequence
783
types like :class:`dict` and :class:`file` and objects of any classes you
785
the :term:`EAFP` approach and is characterized by the presence of many
786
:keyword:`if` statements.
788
+ In a multi-threaded environment, the LBYL approach can risk introducing a
789
+ race condition between "the looking" and "the leaping". For example, the
790
+ code, ``if key in mapping: return mapping[key]`` can fail if another
791
+ thread removes *key* from *mapping* after the test, but before the lookup.
792
+ This issue can be solved with locks or by using the EAFP approach.
795
A built-in Python :term:`sequence`. Despite its name it is more akin
796
to an array in other languages than to a linked list since access to
304
800
A container object that supports arbitrary key lookups and implements the
305
methods specified in the :class:`Mapping` or :class:`MutableMapping`
801
- methods specified in the :class:`Mapping` or :class:`MutableMapping`
306
802
- :ref:`abstract base classes <abstract-base-classes>`. Examples include
307
803
- :class:`dict`, :class:`collections.defaultdict`,
804
+ methods specified in the :class:`~collections.Mapping` or
805
+ :class:`~collections.MutableMapping`
308
806
+ :ref:`abstract base classes <collections-abstract-base-classes>`. Examples
309
807
+ include :class:`dict`, :class:`collections.defaultdict`,
310
808
:class:`collections.OrderedDict` and :class:`collections.Counter`.
812
its first :term:`argument` (which is usually called ``self``).
813
See :term:`function` and :term:`nested scope`.
815
+ method resolution order
816
+ Method Resolution Order is the order in which base classes are searched
817
+ for a member during lookup. See `The Python 2.3 Method Resolution Order
818
+ <http://www.python.org/download/releases/2.3/mro/>`_.
821
+ See :term:`method resolution order`.
824
Mutable objects can change their value but keep their :func:`id`. See
825
also :term:`immutable`.
826
@@ -479,10 +519,11 @@
828
The ability to refer to a variable in an enclosing definition. For
829
instance, a function defined inside another function can refer to
830
- variables in the outer function. Note that nested scopes work only for
831
- reference and not for assignment which will always write to the innermost
832
- scope. In contrast, local variables both read and write in the innermost
833
- scope. Likewise, global variables read and write to the global namespace.
834
+ variables in the outer function. Note that nested scopes by default work
835
+ only for reference and not for assignment. Local variables both read and
836
+ write in the innermost scope. Likewise, global variables read and write
837
+ to the global namespace. The :keyword:`nonlocal` allows writing to outer
841
Any class which inherits from :class:`object`. This includes all built-in
846
- Nickname for the next major Python version, 3.0 (coined long ago
847
- when the release of version 3 was something in the distant future.) This
848
- is also abbreviated "Py3k".
849
+ Nickname for the Python 3.x release line (coined long ago when the release
850
+ of version 3 was something in the distant future.) This is also
851
+ abbreviated "Py3k".
854
An idea or piece of code which closely follows the most common idioms
856
object drops to zero, it is deallocated. Reference counting is
857
generally not visible to Python code, but it is a key element of the
858
:term:`CPython` implementation. The :mod:`sys` module defines a
859
- :func:`getrefcount` function that programmers can call to return the
860
+ :func:`~sys.getrefcount` function that programmers can call to return the
861
reference count for a particular object.
866
A statement is part of a suite (a "block" of code). A statement is either
867
an :term:`expression` or a one of several constructs with a keyword, such
868
- as :keyword:`if`, :keyword:`while` or :keyword:`print`.
869
+ as :keyword:`if`, :keyword:`while` or :keyword:`for`.
872
+ A tuple with named elements. Struct sequences expose an interface similiar
873
+ to :term:`named tuple` in that elements can either be accessed either by
874
+ index or as an attribute. However, they do not have any of the named tuple
875
+ methods like :meth:`~collections.somenamedtuple._make` or
876
+ :meth:`~collections.somenamedtuple._asdict`. Examples of struct sequences
877
+ include :data:`sys.float_info` and the return value of :func:`os.stat`.
880
A string which is bound by three instances of either a quotation mark
881
diff -r 8527427914a2 Doc/howto/cporting.rst
882
--- a/Doc/howto/cporting.rst
883
+++ b/Doc/howto/cporting.rst
889
********************************
890
Porting Extension Modules to 3.0
891
********************************
896
+CObject replaced with Capsule
897
+=============================
899
+The :ctype:`Capsule` object was introduced in Python 3.1 and 2.7 to replace
900
+:ctype:`CObject`. CObjects were useful,
901
+but the :ctype:`CObject` API was problematic: it didn't permit distinguishing
902
+between valid CObjects, which allowed mismatched CObjects to crash the
903
+interpreter, and some of its APIs relied on undefined behavior in C.
904
+(For further reading on the rationale behind Capsules, please see :issue:`5630`.)
906
+If you're currently using CObjects, and you want to migrate to 3.1 or newer,
907
+you'll need to switch to Capsules.
908
+:ctype:`CObject` was deprecated in 3.1 and 2.7 and completely removed in
909
+Python 3.2. If you only support 2.7, or 3.1 and above, you
910
+can simply switch to :ctype:`Capsule`. If you need to support 3.0 or
911
+versions of Python earlier than 2.7 you'll have to support both CObjects
914
+The following example header file :file:`capsulethunk.h` may
915
+solve the problem for you;
916
+simply write your code against the :ctype:`Capsule` API, include
917
+this header file after ``"Python.h"``, and you'll automatically use CObjects
918
+in Python 3.0 or versions earlier than 2.7.
920
+:file:`capsulethunk.h` simulates Capsules using CObjects. However,
921
+:ctype:`CObject` provides no place to store the capsule's "name". As a
922
+result the simulated :ctype:`Capsule` objects created by :file:`capsulethunk.h`
923
+behave slightly differently from real Capsules. Specifically:
925
+ * The name parameter passed in to :cfunc:`PyCapsule_New` is ignored.
927
+ * The name parameter passed in to :cfunc:`PyCapsule_IsValid` and
928
+ :cfunc:`PyCapsule_GetPointer` is ignored, and no error checking
929
+ of the name is performed.
931
+ * :cfunc:`PyCapsule_GetName` always returns NULL.
933
+ * :cfunc:`PyCapsule_SetName` always throws an exception and
934
+ returns failure. (Since there's no way to store a name
935
+ in a CObject, noisy failure of :cfunc:`PyCapsule_SetName`
936
+ was deemed preferable to silent failure here. If this is
937
+ inconveient, feel free to modify your local
938
+ copy as you see fit.)
940
+You can find :file:`capsulethunk.h` in the Python source distribution
941
+in the :file:`Doc/includes` directory. We also include it here for
942
+your reference; here is :file:`capsulethunk.h`:
944
+.. literalinclude:: ../includes/capsulethunk.h
313
951
diff -r 8527427914a2 Doc/howto/descriptor.rst
314
952
--- a/Doc/howto/descriptor.rst
315
953
+++ b/Doc/howto/descriptor.rst
334
992
in two separate namespaces. When the binding in one namespace changes, the
335
993
binding in the other will not, so there will be a discrepancy between them. This
336
994
happens when, for example, one module is reloaded, or changes the definition of
995
diff -r 8527427914a2 Doc/howto/index.rst
996
--- a/Doc/howto/index.rst
997
+++ b/Doc/howto/index.rst
1006
diff -r 8527427914a2 Doc/howto/logging-cookbook.rst
1007
--- a/Doc/howto/logging-cookbook.rst
1008
+++ b/Doc/howto/logging-cookbook.rst
1009
@@ -610,9 +610,10 @@
1010
to have all the processes log to a :class:`SocketHandler`, and have a separate
1011
process which implements a socket server which reads from the socket and logs
1012
to file. (If you prefer, you can dedicate one thread in one of the existing
1013
-processes to perform this function.) The following section documents this
1014
-approach in more detail and includes a working socket receiver which can be
1015
-used as a starting point for you to adapt in your own applications.
1016
+processes to perform this function.) :ref:`This section <network-logging>`
1017
+documents this approach in more detail and includes a working socket receiver
1018
+which can be used as a starting point for you to adapt in your own
1021
If you are using a recent version of Python which includes the
1022
:mod:`multiprocessing` module, you could write your own handler which uses the
1023
@@ -679,6 +680,68 @@
1024
``.1``. Each of the existing backup files is renamed to increment the suffix
1025
(``.1`` becomes ``.2``, etc.) and the ``.6`` file is erased.
1027
-Obviously this example sets the log length much much too small as an extreme
1028
+Obviously this example sets the log length much too small as an extreme
1029
example. You would want to set *maxBytes* to an appropriate value.
1031
+An example dictionary-based configuration
1032
+-----------------------------------------
1034
+Below is an example of a logging configuration dictionary - it's taken from
1035
+the `documentation on the Django project <https://docs.djangoproject.com/en/1.3/topics/logging/#configuring-logging>`_.
1036
+This dictionary is passed to :func:`~logging.config.dictConfig` to put the configuration into effect::
1040
+ 'disable_existing_loggers': True,
1043
+ 'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
1046
+ 'format': '%(levelname)s %(message)s'
1051
+ '()': 'project.logging.SpecialFilter',
1058
+ 'class':'django.utils.log.NullHandler',
1062
+ 'class':'logging.StreamHandler',
1063
+ 'formatter': 'simple'
1067
+ 'class': 'django.utils.log.AdminEmailHandler',
1068
+ 'filters': ['special']
1073
+ 'handlers':['null'],
1074
+ 'propagate': True,
1077
+ 'django.request': {
1078
+ 'handlers': ['mail_admins'],
1080
+ 'propagate': False,
1082
+ 'myproject.custom': {
1083
+ 'handlers': ['console', 'mail_admins'],
1085
+ 'filters': ['special']
1090
+For more information about this configuration, you can see the `relevant
1091
+section <https://docs.djangoproject.com/en/1.3/topics/logging/#configuring-logging>`_
1092
+of the Django documentation.
1093
diff -r 8527427914a2 Doc/howto/logging.rst
1094
--- a/Doc/howto/logging.rst
1095
+++ b/Doc/howto/logging.rst
1100
- format: format=%(asctime)s - %(name)s - %(levelname)s - %(message)s
1101
+ format: '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
1104
class: logging.StreamHandler
1105
diff -r 8527427914a2 Doc/howto/pyporting.rst
1107
+++ b/Doc/howto/pyporting.rst
1109
+.. _pyporting-howto:
1111
+*********************************
1112
+Porting Python 2 Code to Python 3
1113
+*********************************
1115
+:author: Brett Cannon
1117
+.. topic:: Abstract
1119
+ With Python 3 being the future of Python while Python 2 is still in active
1120
+ use, it is good to have your project available for both major releases of
1121
+ Python. This guide is meant to help you choose which strategy works best
1122
+ for your project to support both Python 2 & 3 along with how to execute
1125
+ If you are looking to port an extension module instead of pure Python code,
1126
+ please see :ref:`cporting-howto`.
1129
+Choosing a Strategy
1130
+===================
1132
+When a project makes the decision that it's time to support both Python 2 & 3,
1133
+a decision needs to be made as to how to go about accomplishing that goal.
1134
+The chosen strategy will depend on how large the project's existing
1135
+codebase is and how much divergence you want from your Python 2 codebase from
1136
+your Python 3 one (e.g., starting a new version with Python 3).
1138
+If your project is brand-new or does not have a large codebase, then you may
1139
+want to consider writing/porting :ref:`all of your code for Python 3
1140
+and use 3to2 <use_3to2>` to port your code for Python 2.
1142
+If you would prefer to maintain a codebase which is semantically **and**
1143
+syntactically compatible with Python 2 & 3 simultaneously, you can write
1144
+:ref:`use_same_source`. While this tends to lead to somewhat non-idiomatic
1145
+code, it does mean you keep a rapid development process for you, the developer.
1147
+Finally, you do have the option of :ref:`using 2to3 <use_2to3>` to translate
1148
+Python 2 code into Python 3 code (with some manual help). This can take the
1149
+form of branching your code and using 2to3 to start a Python 3 branch. You can
1150
+also have users perform the translation as installation time automatically so
1151
+that you only have to maintain a Python 2 codebase.
1153
+Regardless of which approach you choose, porting is not as hard or
1154
+time-consuming as you might initially think. You can also tackle the problem
1155
+piece-meal as a good portion of porting is simply updating your code to follow
1156
+current best practices in a Python 2/3 compatible way.
1159
+Universal Bits of Advice
1160
+------------------------
1162
+Regardless of what strategy you pick, there are a few things you should
1165
+One is make sure you have a robust test suite. You need to make sure everything
1166
+continues to work, just like when you support a new minor version of Python.
1167
+This means making sure your test suite is thorough and is ported properly
1168
+between Python 2 & 3. You will also most likely want to use something like tox_
1169
+to automate testing between both a Python 2 and Python 3 VM.
1171
+Two, once your project has Python 3 support, make sure to add the proper
1172
+classifier on the Cheeseshop_ (PyPI_). To have your project listed as Python 3
1173
+compatible it must have the
1174
+`Python 3 classifier <http://pypi.python.org/pypi?:action=browse&c=533>`_
1176
+http://techspot.zzzeek.org/2011/01/24/zzzeek-s-guide-to-python-3-porting/)::
1179
+ name='Your Library',
1182
+ # make sure to use :: Python *and* :: Python :: 3 so
1183
+ # that pypi can list the package on the python 3 page
1184
+ 'Programming Language :: Python',
1185
+ 'Programming Language :: Python :: 3'
1187
+ packages=['yourlibrary'],
1188
+ # make sure to add custom_fixers to the MANIFEST.in
1189
+ include_package_data=True,
1194
+Doing so will cause your project to show up in the
1195
+`Python 3 packages list
1196
+<http://pypi.python.org/pypi?:action=browse&c=533&show=all>`_. You will know
1197
+you set the classifier properly as visiting your project page on the Cheeseshop
1198
+will show a Python 3 logo in the upper-left corner of the page.
1200
+Three, the six_ project provides a library which helps iron out differences
1201
+between Python 2 & 3. If you find there is a sticky point that is a continual
1202
+point of contention in your translation or maintenance of code, consider using
1203
+a source-compatible solution relying on six. If you have to create your own
1204
+Python 2/3 compatible solution, you can use ``sys.version_info[0] >= 3`` as a
1207
+Four, read all the approaches. Just because some bit of advice applies to one
1208
+approach more than another doesn't mean that some advice doesn't apply to other
1211
+Five, drop support for older Python versions if possible. `Python 2.5`_
1212
+introduced a lot of useful syntax and libraries which have become idiomatic
1213
+in Python 3. `Python 2.6`_ introduced future statements which makes
1214
+compatibility much easier if you are going from Python 2 to 3.
1215
+`Python 2.7`_ continues the trend in the stdlib. So choose the newest version
1216
+of Python which you believe can be your minimum support version
1217
+and work from there.
1220
+.. _tox: http://codespeak.net/tox/
1222
+.. _PyPI: http://pypi.python.org/
1223
+.. _six: http://packages.python.org/six
1224
+.. _Python 2.7: http://www.python.org/2.7.x
1225
+.. _Python 2.6: http://www.python.org/2.6.x
1226
+.. _Python 2.5: http://www.python.org/2.5.x
1227
+.. _Python 2.4: http://www.python.org/2.4.x
1228
+.. _Python 2.3: http://www.python.org/2.3.x
1229
+.. _Python 2.2: http://www.python.org/2.2.x
1237
+If you are starting a new project or your codebase is small enough, you may
1238
+want to consider writing your code for Python 3 and backporting to Python 2
1239
+using 3to2_. Thanks to Python 3 being more strict about things than Python 2
1240
+(e.g., bytes vs. strings), the source translation can be easier and more
1241
+straightforward than from Python 2 to 3. Plus it gives you more direct
1242
+experience developing in Python 3 which, since it is the future of Python, is a
1243
+good thing long-term.
1245
+A drawback of this approach is that 3to2 is a third-party project. This means
1246
+that the Python core developers (and thus this guide) can make no promises
1247
+about how well 3to2 works at any time. There is nothing to suggest, though,
1248
+that 3to2 is not a high-quality project.
1251
+.. _3to2: https://bitbucket.org/amentajo/lib3to2/overview
1259
+Included with Python since 2.6, the 2to3_ tool (and :mod:`lib2to3` module)
1260
+helps with porting Python 2 to Python 3 by performing various source
1261
+translations. This is a perfect solution for projects which wish to branch
1262
+their Python 3 code from their Python 2 codebase and maintain them as
1263
+independent codebases. You can even begin preparing to use this approach
1264
+today by writing future-compatible Python code which works cleanly in
1265
+Python 2 in conjunction with 2to3; all steps outlined below will work
1266
+with Python 2 code up to the point when the actual use of 2to3 occurs.
1268
+Use of 2to3 as an on-demand translation step at install time is also possible,
1269
+preventing the need to maintain a separate Python 3 codebase, but this approach
1270
+does come with some drawbacks. While users will only have to pay the
1271
+translation cost once at installation, you as a developer will need to pay the
1272
+cost regularly during development. If your codebase is sufficiently large
1273
+enough then the translation step ends up acting like a compilation step,
1274
+robbing you of the rapid development process you are used to with Python.
1275
+Obviously the time required to translate a project will vary, so do an
1276
+experimental translation just to see how long it takes to evaluate whether you
1277
+prefer this approach compared to using :ref:`use_same_source` or simply keeping
1278
+a separate Python 3 codebase.
1280
+Below are the typical steps taken by a project which uses a 2to3-based approach
1281
+to supporting Python 2 & 3.
1287
+As a first step, make sure that your project is compatible with `Python 2.7`_.
1288
+This is just good to do as Python 2.7 is the last release of Python 2 and thus
1289
+will be used for a rather long time. It also allows for use of the ``-3`` flag
1290
+to Python to help discover places in your code which 2to3 cannot handle but are
1291
+known to cause issues.
1293
+Try to Support `Python 2.6`_ and Newer Only
1294
+-------------------------------------------
1296
+While not possible for all projects, if you can support `Python 2.6`_ and newer
1297
+**only**, your life will be much easier. Various future statements, stdlib
1298
+additions, etc. exist only in Python 2.6 and later which greatly assist in
1299
+porting to Python 3. But if you project must keep support for `Python 2.5`_ (or
1300
+even `Python 2.4`_) then it is still possible to port to Python 3.
1302
+Below are the benefits you gain if you only have to support Python 2.6 and
1303
+newer. Some of these options are personal choice while others are
1304
+**strongly** recommended (the ones that are more for personal choice are
1305
+labeled as such). If you continue to support older versions of Python then you
1306
+at least need to watch out for situations that these solutions fix.
1309
+``from __future__ import print_function``
1310
+'''''''''''''''''''''''''''''''''''''''''
1312
+This is a personal choice. 2to3 handles the translation from the print
1313
+statement to the print function rather well so this is an optional step. This
1314
+future statement does help, though, with getting used to typing
1315
+``print('Hello, World')`` instead of ``print 'Hello, World'``.
1318
+``from __future__ import unicode_literals``
1319
+'''''''''''''''''''''''''''''''''''''''''''
1321
+Another personal choice. You can always mark what you want to be a (unicode)
1322
+string with a ``u`` prefix to get the same effect. But regardless of whether
1323
+you use this future statement or not, you **must** make sure you know exactly
1324
+which Python 2 strings you want to be bytes, and which are to be strings. This
1325
+means you should, **at minimum** mark all strings that are meant to be text
1326
+strings with a ``u`` prefix if you do not use this future statement.
1332
+This is a **very** important one. The ability to prefix Python 2 strings that
1333
+are meant to contain bytes with a ``b`` prefix help to very clearly delineate
1334
+what is and is not a Python 3 string. When you run 2to3 on code, all Python 2
1335
+strings become Python 3 strings **unless** they are prefixed with ``b``.
1337
+There are some differences between byte literals in Python 2 and those in
1338
+Python 3 thanks to the bytes type just being an alias to ``str`` in Python 2.
1339
+Probably the biggest "gotcha" is that indexing results in different values. In
1340
+Python 2, the value of ``b'py'[1]`` is ``'y'``, while in Python 3 it's ``121``.
1341
+You can avoid this disparity by always slicing at the size of a single element:
1342
+``b'py'[1:2]`` is ``'y'`` in Python 2 and ``b'y'`` in Python 3 (i.e., close
1345
+You cannot concatenate bytes and strings in Python 3. But since in Python
1346
+2 has bytes aliased to ``str``, it will succeed: ``b'a' + u'b'`` works in
1347
+Python 2, but ``b'a' + 'b'`` in Python 3 is a :exc:`TypeError`. A similar issue
1348
+also comes about when doing comparisons between bytes and strings.
1351
+Supporting `Python 2.5`_ and Newer Only
1352
+---------------------------------------
1354
+If you are supporting `Python 2.5`_ and newer there are still some features of
1355
+Python that you can utilize.
1358
+``from __future__ import absolute_import``
1359
+''''''''''''''''''''''''''''''''''''''''''
1361
+Implicit relative imports (e.g., importing ``spam.bacon`` from within
1362
+``spam.eggs`` with the statement ``import bacon``) does not work in Python 3.
1363
+This future statement moves away from that and allows the use of explicit
1364
+relative imports (e.g., ``from . import bacon``).
1366
+In `Python 2.5`_ you must use
1367
+the __future__ statement to get to use explicit relative imports and prevent
1368
+implicit ones. In `Python 2.6`_ explicit relative imports are available without
1369
+the statement, but you still want the __future__ statement to prevent implicit
1370
+relative imports. In `Python 2.7`_ the __future__ statement is not needed. In
1371
+other words, unless you are only supporting Python 2.7 or a version earlier
1372
+than Python 2.5, use the __future__ statement.
1376
+Handle Common "Gotchas"
1377
+-----------------------
1379
+There are a few things that just consistently come up as sticking points for
1380
+people which 2to3 cannot handle automatically or can easily be done in Python 2
1381
+to help modernize your code.
1384
+``from __future__ import division``
1385
+'''''''''''''''''''''''''''''''''''
1387
+While the exact same outcome can be had by using the ``-Qnew`` argument to
1388
+Python, using this future statement lifts the requirement that your users use
1389
+the flag to get the expected behavior of division in Python 3
1390
+(e.g., ``1/2 == 0.5; 1//2 == 0``).
1394
+Specify when opening a file as binary
1395
+'''''''''''''''''''''''''''''''''''''
1397
+Unless you have been working on Windows, there is a chance you have not always
1398
+bothered to add the ``b`` mode when opening a binary file (e.g., ``rb`` for
1399
+binary reading). Under Python 3, binary files and text files are clearly
1400
+distinct and mutually incompatible; see the :mod:`io` module for details.
1401
+Therefore, you **must** make a decision of whether a file will be used for
1402
+binary access (allowing to read and/or write bytes data) or text access
1403
+(allowing to read and/or write unicode data).
1408
+Text files created using ``open()`` under Python 2 return byte strings,
1409
+while under Python 3 they return unicode strings. Depending on your porting
1410
+strategy, this can be an issue.
1412
+If you want text files to return unicode strings in Python 2, you have two
1415
+* Under Python 2.6 and higher, use :func:`io.open`. Since :func:`io.open`
1416
+ is essentially the same function in both Python 2 and Python 3, it will
1417
+ help iron out any issues that might arise.
1419
+* If pre-2.6 compatibility is needed, then you should use :func:`codecs.open`
1420
+ instead. This will make sure that you get back unicode strings in Python 2.
1422
+Subclass ``object``
1423
+'''''''''''''''''''
1425
+New-style classes have been around since `Python 2.2`_. You need to make sure
1426
+you are subclassing from ``object`` to avoid odd edge cases involving method
1427
+resolution order, etc. This continues to be totally valid in Python 3 (although
1428
+unneeded as all classes implicitly inherit from ``object``).
1431
+Deal With the Bytes/String Dichotomy
1432
+''''''''''''''''''''''''''''''''''''
1434
+One of the biggest issues people have when porting code to Python 3 is handling
1435
+the bytes/string dichotomy. Because Python 2 allowed the ``str`` type to hold
1436
+textual data, people have over the years been rather loose in their delineation
1437
+of what ``str`` instances held text compared to bytes. In Python 3 you cannot
1438
+be so care-free anymore and need to properly handle the difference. The key
1439
+handling this issue to make sure that **every** string literal in your
1440
+Python 2 code is either syntactically of functionally marked as either bytes or
1441
+text data. After this is done you then need to make sure your APIs are designed
1442
+to either handle a specific type or made to be properly polymorphic.
1445
+Mark Up Python 2 String Literals
1446
+********************************
1448
+First thing you must do is designate every single string literal in Python 2
1449
+as either textual or bytes data. If you are only supporting Python 2.6 or
1450
+newer, this can be accomplished by marking bytes literals with a ``b`` prefix
1451
+and then designating textual data with a ``u`` prefix or using the
1452
+``unicode_literals`` future statement.
1454
+If your project supports versions of Python pre-dating 2.6, then you should use
1455
+the six_ project and its ``b()`` function to denote bytes literals. For text
1456
+literals you can either use six's ``u()`` function or use a ``u`` prefix.
1459
+Decide what APIs Will Accept
1460
+****************************
1462
+In Python 2 it was very easy to accidentally create an API that accepted both
1463
+bytes and textual data. But in Python 3, thanks to the more strict handling of
1464
+disparate types, this loose usage of bytes and text together tends to fail.
1466
+Take the dict ``{b'a': 'bytes', u'a': 'text'}`` in Python 2.6. It creates the
1467
+dict ``{u'a': 'text'}`` since ``b'a' == u'a'``. But in Python 3 the equivalent
1468
+dict creates ``{b'a': 'bytes', 'a': 'text'}``, i.e., no lost data. Similar
1469
+issues can crop up when transitioning Python 2 code to Python 3.
1471
+This means you need to choose what an API is going to accept and create and
1472
+consistently stick to that API in both Python 2 and 3.
1475
+Bytes / Unicode Comparison
1476
+**************************
1478
+In Python 3, mixing bytes and unicode is forbidden in most situations; it
1479
+will raise a :class:`TypeError` where Python 2 would have attempted an implicit
1480
+coercion between types. However, there is one case where it doesn't and
1481
+it can be very misleading::
1486
+This is because an equality comparison is required by the language to always
1487
+succeed (and return ``False`` for incompatible types). However, this also
1488
+means that code incorrectly ported to Python 3 can display buggy behaviour
1489
+if such comparisons are silently executed. To detect such situations,
1490
+Python 3 has a ``-b`` flag that will display a warning::
1494
+ __main__:1: BytesWarning: Comparison between bytes and string
1497
+To turn the warning into an exception, use the ``-bb`` flag instead::
1501
+ Traceback (most recent call last):
1502
+ File "<stdin>", line 1, in <module>
1503
+ BytesWarning: Comparison between bytes and string
1506
+Indexing bytes objects
1507
+''''''''''''''''''''''
1509
+Another potentially surprising change is the indexing behaviour of bytes
1510
+objects in Python 3::
1515
+Indeed, Python 3 bytes objects (as well as :class:`bytearray` objects)
1516
+are sequences of integers. But code converted from Python 2 will often
1517
+assume that indexing a bytestring produces another bytestring, not an
1518
+integer. To reconcile both behaviours, use slicing::
1526
+The only remaining gotcha is that an out-of-bounds slice returns an empty
1527
+bytes object instead of raising ``IndexError``:
1530
+ Traceback (most recent call last):
1531
+ File "<stdin>", line 1, in <module>
1532
+ IndexError: index out of range
1537
+``__str__()``/``__unicode__()``
1538
+'''''''''''''''''''''''''''''''
1540
+In Python 2, objects can specify both a string and unicode representation of
1541
+themselves. In Python 3, though, there is only a string representation. This
1542
+becomes an issue as people can inadvertently do things in their ``__str__()``
1543
+methods which have unpredictable results (e.g., infinite recursion if you
1544
+happen to use the ``unicode(self).encode('utf8')`` idiom as the body of your
1545
+``__str__()`` method).
1547
+There are two ways to solve this issue. One is to use a custom 2to3 fixer. The
1548
+blog post at http://lucumr.pocoo.org/2011/1/22/forwards-compatible-python/
1549
+specifies how to do this. That will allow 2to3 to change all instances of ``def
1550
+__unicode(self): ...`` to ``def __str__(self): ...``. This does require you
1551
+define your ``__str__()`` method in Python 2 before your ``__unicode__()``
1554
+The other option is to use a mixin class. This allows you to only define a
1555
+``__unicode__()`` method for your class and let the mixin derive
1556
+``__str__()`` for you (code from
1557
+http://lucumr.pocoo.org/2011/1/22/forwards-compatible-python/)::
1561
+ class UnicodeMixin(object):
1563
+ """Mixin class to handle defining the proper __str__/__unicode__
1564
+ methods in Python 2 or 3."""
1566
+ if sys.version_info[0] >= 3: # Python 3
1567
+ def __str__(self):
1568
+ return self.__unicode__()
1570
+ def __str__(self):
1571
+ return self.__unicode__().encode('utf8')
1574
+ class Spam(UnicodeMixin):
1576
+ def __unicode__(self):
1577
+ return u'spam-spam-bacon-spam' # 2to3 will remove the 'u' prefix
1580
+Don't Index on Exceptions
1581
+'''''''''''''''''''''''''
1583
+In Python 2, the following worked::
1585
+ >>> exc = Exception(1, 2, 3)
1588
+ >>> exc[1] # Python 2 only!
1591
+But in Python 3, indexing directly on an exception is an error. You need to
1592
+make sure to only index on the :attr:`BaseException.args` attribute which is a
1593
+sequence containing all arguments passed to the :meth:`__init__` method.
1595
+Even better is to use the documented attributes the exception provides.
1597
+Don't use ``__getslice__`` & Friends
1598
+''''''''''''''''''''''''''''''''''''
1600
+Been deprecated for a while, but Python 3 finally drops support for
1601
+``__getslice__()``, etc. Move completely over to :meth:`__getitem__` and
1608
+2to3_ will attempt to generate fixes for doctests that it comes across. It's
1609
+not perfect, though. If you wrote a monolithic set of doctests (e.g., a single
1610
+docstring containing all of your doctests), you should at least consider
1611
+breaking the doctests up into smaller pieces to make it more manageable to fix.
1612
+Otherwise it might very well be worth your time and effort to port your tests
1613
+to :mod:`unittest`.
1616
+Eliminate ``-3`` Warnings
1617
+-------------------------
1619
+When you run your application's test suite, run it using the ``-3`` flag passed
1620
+to Python. This will cause various warnings to be raised during execution about
1621
+things that 2to3 cannot handle automatically (e.g., modules that have been
1622
+removed). Try to eliminate those warnings to make your code even more portable
1629
+Once you have made your Python 2 code future-compatible with Python 3, it's
1630
+time to use 2to3_ to actually port your code.
1636
+To manually convert source code using 2to3_, you use the ``2to3`` script that
1637
+is installed with Python 2.6 and later.::
1639
+ 2to3 <directory or file to convert>
1641
+This will cause 2to3 to write out a diff with all of the fixers applied for the
1642
+converted source code. If you would like 2to3 to go ahead and apply the changes
1643
+you can pass it the ``-w`` flag::
1645
+ 2to3 -w <stuff to convert>
1647
+There are other flags available to control exactly which fixers are applied,
1651
+During Installation
1652
+'''''''''''''''''''
1654
+When a user installs your project for Python 3, you can have either
1655
+:mod:`distutils` or Distribute_ run 2to3_ on your behalf.
1656
+For distutils, use the following idiom::
1659
+ from distutils.command.build_py import build_py_2to3 as build_py
1660
+ except ImportError: # Python 2
1661
+ from distutils.command.build_py import build_py
1663
+ setup(cmdclass = {'build_py': build_py},
1669
+ setup(use_2to3=True,
1673
+This will allow you to not have to distribute a separate Python 3 version of
1674
+your project. It does require, though, that when you perform development that
1675
+you at least build your project and use the built Python 3 source for testing.
1681
+At this point you should (hopefully) have your project converted in such a way
1682
+that it works in Python 3. Verify it by running your unit tests and making sure
1683
+nothing has gone awry. If you miss something then figure out how to fix it in
1684
+Python 3, backport to your Python 2 code, and run your code through 2to3 again
1685
+to verify the fix transforms properly.
1688
+.. _2to3: http://docs.python.org/py3k/library/2to3.html
1689
+.. _Distribute: http://packages.python.org/distribute/
1692
+.. _use_same_source:
1694
+Python 2/3 Compatible Source
1695
+============================
1697
+While it may seem counter-intuitive, you can write Python code which is
1698
+source-compatible between Python 2 & 3. It does lead to code that is not
1699
+entirely idiomatic Python (e.g., having to extract the currently raised
1700
+exception from ``sys.exc_info()[1]``), but it can be run under Python 2
1701
+**and** Python 3 without using 2to3_ as a translation step (although the tool
1702
+should be used to help find potential portability problems). This allows you to
1703
+continue to have a rapid development process regardless of whether you are
1704
+developing under Python 2 or Python 3. Whether this approach or using
1705
+:ref:`use_2to3` works best for you will be a per-project decision.
1707
+To get a complete idea of what issues you will need to deal with, see the
1708
+`What's New in Python 3.0`_. Others have reorganized the data in other formats
1709
+such as http://docs.pythonsprints.com/python3_porting/py-porting.html .
1711
+The following are some steps to take to try to support both Python 2 & 3 from
1712
+the same source code.
1715
+.. _What's New in Python 3.0: http://docs.python.org/release/3.0/whatsnew/3.0.html
1718
+Follow The Steps for Using 2to3_
1719
+--------------------------------
1721
+All of the steps outlined in how to
1722
+:ref:`port Python 2 code with 2to3 <use_2to3>` apply
1723
+to creating a Python 2/3 codebase. This includes trying only support Python 2.6
1724
+or newer (the :mod:`__future__` statements work in Python 3 without issue),
1725
+eliminating warnings that are triggered by ``-3``, etc.
1727
+You should even consider running 2to3_ over your code (without committing the
1728
+changes). This will let you know where potential pain points are within your
1729
+code so that you can fix them properly before they become an issue.
1735
+The six_ project contains many things to help you write portable Python code.
1736
+You should make sure to read its documentation from beginning to end and use
1737
+any and all features it provides. That way you will minimize any mistakes you
1738
+might make in writing cross-version code.
1741
+Capturing the Currently Raised Exception
1742
+----------------------------------------
1744
+One change between Python 2 and 3 that will require changing how you code (if
1745
+you support `Python 2.5`_ and earlier) is
1746
+accessing the currently raised exception. In Python 2.5 and earlier the syntax
1747
+to access the current exception is::
1751
+ except Exception, exc:
1752
+ # Current exception is 'exc'
1755
+This syntax changed in Python 3 (and backported to `Python 2.6`_ and later)
1760
+ except Exception as exc:
1761
+ # Current exception is 'exc'
1762
+ # In Python 3, 'exc' is restricted to the block; Python 2.6 will "leak"
1765
+Because of this syntax change you must change to capturing the current
1772
+ exc = sys.exc_info()[1]
1773
+ # Current exception is 'exc'
1776
+You can get more information about the raised exception from
1777
+:func:`sys.exc_info` than simply the current exception instance, but you most
1778
+likely don't need it.
1781
+ In Python 3, the traceback is attached to the exception instance
1782
+ through the ``__traceback__`` attribute. If the instance is saved in
1783
+ a local variable that persists outside of the ``except`` block, the
1784
+ traceback will create a reference cycle with the current frame and its
1785
+ dictionary of local variables. This will delay reclaiming dead
1786
+ resources until the next cyclic :term:`garbage collection` pass.
1788
+ In Python 2, this problem only occurs if you save the traceback itself
1789
+ (e.g. the third element of the tuple returned by :func:`sys.exc_info`)
1796
+The authors of the following blog posts, wiki pages, and books deserve special
1797
+thanks for making public their tips for porting Python 2 code to Python 3 (and
1798
+thus helping provide information for this document):
1800
+* http://python3porting.com/
1801
+* http://docs.pythonsprints.com/python3_porting/py-porting.html
1802
+* http://techspot.zzzeek.org/2011/01/24/zzzeek-s-guide-to-python-3-porting/
1803
+* http://dabeaz.blogspot.com/2011/01/porting-py65-and-my-superboard-to.html
1804
+* http://lucumr.pocoo.org/2011/1/22/forwards-compatible-python/
1805
+* http://lucumr.pocoo.org/2010/2/11/porting-to-python-3-a-guide/
1806
+* http://wiki.python.org/moin/PortingPythonToPy3k
1808
+If you feel there is something missing from this document that should be added,
1809
+please email the python-porting_ mailing list.
1811
+.. _python-porting: http://mail.python.org/mailman/listinfo/python-porting
337
1812
diff -r 8527427914a2 Doc/howto/sorting.rst
338
1813
--- a/Doc/howto/sorting.rst
339
1814
+++ b/Doc/howto/sorting.rst
443
2080
.. _inst-platform-variations:
2083
:file:`C:\\Temp\\foo-1.0`; you can use either a archive manipulator with a
2084
graphical user interface (such as WinZip) or a command-line tool (such as
2085
:program:`unzip` or :program:`pkunzip`) to unpack the archive. Then, open a
2086
-command prompt window ("DOS box"), and run::
2087
+command prompt window and run::
2090
python setup.py install
2091
@@ -276,6 +279,12 @@
2095
+A few other placeholders are used in this document: :file:`{X.Y}` stands for the
2096
+version of Python, for example ``2.7``; :file:`{distname}` will be replaced by
2097
+the name of the module distribution being installed. Dots and capitalization
2098
+are important in the paths; for example, a value that uses ``python2.7`` on UNIX
2099
+will typically use ``Python27`` on Windows.
2101
If you don't want to install modules to the standard location, or if you don't
2102
have permission to write there, then you need to read about alternate
2103
installations in section :ref:`inst-alt-install`. If you want to customize your
2104
@@ -304,8 +313,61 @@
2105
differ across platforms, so read whichever of the following sections applies to
2108
+Note that the various alternate installation schemes are mutually exclusive: you
2109
+can pass ``--user``, or ``--home``, or ``--prefix`` and ``--exec-prefix``, or
2110
+``--install-base`` and ``--install-platbase``, but you can't mix from these
2113
-.. _inst-alt-install-prefix:
2115
+.. _inst-alt-install-user:
2117
+Alternate installation: the user scheme
2118
+---------------------------------------
2120
+This scheme is designed to be the most convenient solution for users that don't
2121
+have write permission to the global site-packages directory or don't want to
2122
+install into it. It is enabled with a simple option::
2124
+ python setup.py install --user
2126
+Files will be installed into subdirectories of :data:`site.USER_BASE` (written
2127
+as :file:`{userbase}` hereafter). This scheme installs pure Python modules and
2128
+extension modules in the same location (also known as :data:`site.USER_SITE`).
2129
+Here are the values for UNIX, including Mac OS X:
2131
+=============== ===========================================================
2132
+Type of file Installation directory
2133
+=============== ===========================================================
2134
+modules :file:`{userbase}/lib/python{X.Y}/site-packages`
2135
+scripts :file:`{userbase}/bin`
2136
+data :file:`{userbase}`
2137
+C headers :file:`{userbase}/include/python{X.Y}/{distname}`
2138
+=============== ===========================================================
2140
+And here are the values used on Windows:
2142
+=============== ===========================================================
2143
+Type of file Installation directory
2144
+=============== ===========================================================
2145
+modules :file:`{userbase}\\Python{XY}\\site-packages`
2146
+scripts :file:`{userbase}\\Scripts`
2147
+data :file:`{userbase}`
2148
+C headers :file:`{userbase}\\Python{XY}\\Include\\{distname}`
2149
+=============== ===========================================================
2151
+The advantage of using this scheme compared to the other ones described below is
2152
+that the user site-packages directory is under normal conditions always included
2153
+in :data:`sys.path` (see :mod:`site` for more information), which means that
2154
+there is no additional step to perform after running the :file:`setup.py` script
2155
+to finalize the installation.
2157
+The :command:`build_ext` command also has a ``--user`` option to add
2158
+:file:`{userbase}/include` to the compiler search path for header files and
2159
+:file:`{userbase}/lib` to the compiler search path for libraries as well as to
2160
+the runtime search path for shared C libraries (rpath).
2163
+.. _inst-alt-install-home:
2165
Alternate installation: the home scheme
2166
---------------------------------------
2167
@@ -327,26 +389,30 @@
2169
python setup.py install --home=~
2171
+To make Python find the distributions installed with this scheme, you may have
2172
+to :ref:`modify Python's search path <inst-search-path>` or edit
2173
+:mod:`sitecustomize` (see :mod:`site`) to call :func:`site.addsitedir` or edit
2176
The :option:`--home` option defines the installation base directory. Files are
2177
installed to the following directories under the installation base as follows:
2179
-+------------------------------+---------------------------+-----------------------------+
2180
-| Type of file | Installation Directory | Override option |
2181
-+==============================+===========================+=============================+
2182
-| pure module distribution | :file:`{home}/lib/python` | :option:`--install-purelib` |
2183
-+------------------------------+---------------------------+-----------------------------+
2184
-| non-pure module distribution | :file:`{home}/lib/python` | :option:`--install-platlib` |
2185
-+------------------------------+---------------------------+-----------------------------+
2186
-| scripts | :file:`{home}/bin` | :option:`--install-scripts` |
2187
-+------------------------------+---------------------------+-----------------------------+
2188
-| data | :file:`{home}/share` | :option:`--install-data` |
2189
-+------------------------------+---------------------------+-----------------------------+
2190
+=============== ===========================================================
2191
+Type of file Installation directory
2192
+=============== ===========================================================
2193
+modules :file:`{home}/lib/python`
2194
+scripts :file:`{home}/bin`
2195
+data :file:`{home}`
2196
+C headers :file:`{home}/include/python/{distname}`
2197
+=============== ===========================================================
2199
+(Mentally replace slashes with backslashes if you're on Windows.)
2201
.. versionchanged:: 2.4
2202
The :option:`--home` option used to be supported only on Unix.
2205
-.. _inst-alt-install-home:
2206
+.. _inst-alt-install-prefix-unix:
2208
Alternate installation: Unix (the prefix scheme)
2209
------------------------------------------------
2211
perform the build/install (i.e., to run the setup script), but install modules
2212
into the third-party module directory of a different Python installation (or
2213
something that looks like a different Python installation). If this sounds a
2214
-trifle unusual, it is---that's why the "home scheme" comes first. However,
2215
+trifle unusual, it is---that's why the user and home schemes come before. However,
2216
there are at least two known cases where the prefix scheme will be useful.
2218
First, consider that many Linux distributions put Python in :file:`/usr`, rather
2219
@@ -383,17 +449,15 @@
2220
executables, etc.) If :option:`--exec-prefix` is not supplied, it defaults to
2221
:option:`--prefix`. Files are installed as follows:
2223
-+------------------------------+-----------------------------------------------------+-----------------------------+
2224
-| Type of file | Installation Directory | Override option |
2225
-+==============================+=====================================================+=============================+
2226
-| pure module distribution | :file:`{prefix}/lib/python{X.Y}/site-packages` | :option:`--install-purelib` |
2227
-+------------------------------+-----------------------------------------------------+-----------------------------+
2228
-| non-pure module distribution | :file:`{exec-prefix}/lib/python{X.Y}/site-packages` | :option:`--install-platlib` |
2229
-+------------------------------+-----------------------------------------------------+-----------------------------+
2230
-| scripts | :file:`{prefix}/bin` | :option:`--install-scripts` |
2231
-+------------------------------+-----------------------------------------------------+-----------------------------+
2232
-| data | :file:`{prefix}/share` | :option:`--install-data` |
2233
-+------------------------------+-----------------------------------------------------+-----------------------------+
2234
+================= ==========================================================
2235
+Type of file Installation directory
2236
+================= ==========================================================
2237
+Python modules :file:`{prefix}/lib/python{X.Y}/site-packages`
2238
+extension modules :file:`{exec-prefix}/lib/python{X.Y}/site-packages`
2239
+scripts :file:`{prefix}/bin`
2240
+data :file:`{prefix}`
2241
+C headers :file:`{prefix}/include/python{X.Y}/{distname}`
2242
+================= ==========================================================
2244
There is no requirement that :option:`--prefix` or :option:`--exec-prefix`
2245
actually point to an alternate Python installation; if the directories listed
2247
alternate Python installation, this is immaterial.)
2250
-.. _inst-alt-install-windows:
2251
+.. _inst-alt-install-prefix-windows:
2253
Alternate installation: Windows (the prefix scheme)
2254
---------------------------------------------------
2255
@@ -433,20 +497,18 @@
2256
to install modules to the :file:`\\Temp\\Python` directory on the current drive.
2258
The installation base is defined by the :option:`--prefix` option; the
2259
-:option:`--exec-prefix` option is not supported under Windows. Files are
2260
-installed as follows:
2261
+:option:`--exec-prefix` option is not supported under Windows, which means that
2262
+pure Python modules and extension modules are installed into the same location.
2263
+Files are installed as follows:
2265
-+------------------------------+---------------------------+-----------------------------+
2266
-| Type of file | Installation Directory | Override option |
2267
-+==============================+===========================+=============================+
2268
-| pure module distribution | :file:`{prefix}` | :option:`--install-purelib` |
2269
-+------------------------------+---------------------------+-----------------------------+
2270
-| non-pure module distribution | :file:`{prefix}` | :option:`--install-platlib` |
2271
-+------------------------------+---------------------------+-----------------------------+
2272
-| scripts | :file:`{prefix}\\Scripts` | :option:`--install-scripts` |
2273
-+------------------------------+---------------------------+-----------------------------+
2274
-| data | :file:`{prefix}\\Data` | :option:`--install-data` |
2275
-+------------------------------+---------------------------+-----------------------------+
2276
+=============== ==========================================================
2277
+Type of file Installation directory
2278
+=============== ==========================================================
2279
+modules :file:`{prefix}\\Lib\\site-packages`
2280
+scripts :file:`{prefix}\\Scripts`
2281
+data :file:`{prefix}`
2282
+C headers :file:`{prefix}\\Include\\{distname}`
2283
+=============== ==========================================================
2286
.. _inst-custom-install:
2287
@@ -460,13 +522,29 @@
2288
or you might want to completely redefine the installation scheme. In either
2289
case, you're creating a *custom installation scheme*.
2291
-You probably noticed the column of "override options" in the tables describing
2292
-the alternate installation schemes above. Those options are how you define a
2293
-custom installation scheme. These override options can be relative, absolute,
2294
+To create a custom installation scheme, you start with one of the alternate
2295
+schemes and override some of the installation directories used for the various
2296
+types of files, using these options:
2298
+====================== =======================
2299
+Type of file Override option
2300
+====================== =======================
2301
+Python modules ``--install-purelib``
2302
+extension modules ``--install-platlib``
2303
+all modules ``--install-lib``
2304
+scripts ``--install-scripts``
2305
+data ``--install-data``
2306
+C headers ``--install-headers``
2307
+====================== =======================
2309
+These override options can be relative, absolute,
2310
or explicitly defined in terms of one of the installation base directories.
2311
(There are two installation base directories, and they are normally the same---
2312
they only differ when you use the Unix "prefix scheme" and supply different
2313
-:option:`--prefix` and :option:`--exec-prefix` options.)
2314
+``--prefix`` and ``--exec-prefix`` options; using ``--install-lib`` will
2315
+override values computed or given for ``--install-purelib`` and
2316
+``--install-platlib``, and is recommended for schemes that don't make a
2317
+difference between Python and extension modules.)
2319
For example, say you're installing a module distribution to your home directory
2320
under Unix---but you want scripts to go in :file:`~/scripts` rather than
2321
@@ -493,15 +571,16 @@
2322
a subdirectory of :file:`{prefix}`, rather than right in :file:`{prefix}`
2323
itself. This is almost as easy as customizing the script installation directory
2324
---you just have to remember that there are two types of modules to worry about,
2325
-pure modules and non-pure modules (i.e., modules from a non-pure distribution).
2327
+Python and extension modules, which can conveniently be both controlled by one
2330
- python setup.py install --install-purelib=Site --install-platlib=Site
2331
+ python setup.py install --install-lib=Site
2333
-The specified installation directories are relative to :file:`{prefix}`. Of
2334
-course, you also have to ensure that these directories are in Python's module
2335
-search path, such as by putting a :file:`.pth` file in :file:`{prefix}`. See
2336
-section :ref:`inst-search-path` to find out how to modify Python's search path.
2337
+The specified installation directory is relative to :file:`{prefix}`. Of
2338
+course, you also have to ensure that this directory is in Python's module
2339
+search path, such as by putting a :file:`.pth` file in a site directory (see
2340
+:mod:`site`). See section :ref:`inst-search-path` to find out how to modify
2341
+Python's search path.
2343
If you want to define an entire installation scheme, you just have to supply all
2344
of the installation directory options. The recommended way to do this is to
2347
python setup.py install --install-base=/tmp
2349
-would install pure modules to :file:`{/tmp/python/lib}` in the first case, and
2350
-to :file:`{/tmp/lib}` in the second case. (For the second case, you probably
2351
+would install pure modules to :file:`/tmp/python/lib` in the first case, and
2352
+to :file:`/tmp/lib` in the second case. (For the second case, you probably
2353
want to supply an installation base of :file:`/tmp/python`.)
2355
You probably noticed the use of ``$HOME`` and ``$PLAT`` in the sample
2357
needed on those platforms?
2360
-.. XXX I'm not sure where this section should go.
2361
+.. XXX Move this to Doc/using
2363
.. _inst-search-path:
445
2365
diff -r 8527427914a2 Doc/library/2to3.rst
446
2366
--- a/Doc/library/2to3.rst
447
2367
+++ b/Doc/library/2to3.rst
2369
.. 2to3fixer:: callable
2371
Converts ``callable(x)`` to ``isinstance(x, collections.Callable)``, adding
2372
- an import to :mod:`collections` if needed.
2373
+ an import to :mod:`collections` if needed. Note ``callable(x)`` has returned
2374
+ in Python 3.2, so if you do not intend to support Python 3.1, you can disable
450
2381
.. 2to3fixer:: long
469
2400
This module is not normally accessed explicitly by most applications, but can be
470
2401
useful in modules that provide objects with the same name as a built-in value,
2402
diff -r 8527427914a2 Doc/library/__future__.rst
2403
--- a/Doc/library/__future__.rst
2404
+++ b/Doc/library/__future__.rst
2406
.. module:: __future__
2407
:synopsis: Future statement definitions
2409
+**Source code:** :source:`Lib/__future__.py`
2413
:mod:`__future__` is a real module, and serves three purposes:
471
2415
diff -r 8527427914a2 Doc/library/abc.rst
472
2416
--- a/Doc/library/abc.rst
473
2417
+++ b/Doc/library/abc.rst
476
2420
.. versionadded:: 2.6
478
2422
-This module provides the infrastructure for defining an :term:`abstract base
479
2423
-class` (ABCs) in Python, as outlined in :pep:`3119`; see the PEP for why this
2424
+**Source code:** :source:`Lib/abc.py`
480
2428
+This module provides the infrastructure for defining :term:`abstract base
481
2429
+classes <abstract base class>` (ABCs) in Python, as outlined in :pep:`3119`; see the PEP for why this
482
2430
was added to Python. (See also :pep:`3141` and the :mod:`numbers` module
483
2431
regarding a type hierarchy for numbers based on ABCs.)
2433
diff -r 8527427914a2 Doc/library/aifc.rst
2434
--- a/Doc/library/aifc.rst
2435
+++ b/Doc/library/aifc.rst
2440
+**Source code:** :source:`Lib/aifc.py`
2444
This module provides support for reading and writing AIFF and AIFF-C files.
2445
AIFF is Audio Interchange File Format, a format for storing digital audio
2446
samples in a file. AIFF-C is a newer version of the format that includes the
485
2447
diff -r 8527427914a2 Doc/library/argparse.rst
486
2448
--- a/Doc/library/argparse.rst
487
2449
+++ b/Doc/library/argparse.rst
489
:class:`ArgumentParser` parses args through the
2451
===============================================================================
2453
.. module:: argparse
2454
- :synopsis: Command-line option and argument-parsing library.
2455
+ :synopsis: Command-line option and argument parsing library.
2456
.. moduleauthor:: Steven Bethard <steven.bethard@gmail.com>
2457
-.. versionadded:: 2.7
2458
.. sectionauthor:: Steven Bethard <steven.bethard@gmail.com>
2460
+.. versionadded:: 2.7
2462
+**Source code:** :source:`Lib/argparse.py`
2466
The :mod:`argparse` module makes it easy to write user-friendly command-line
2467
interfaces. The program defines what arguments it requires, and :mod:`argparse`
2468
@@ -103,10 +107,10 @@
2472
-:class:`ArgumentParser` parses args through the
2473
+:class:`ArgumentParser` parses arguments through the
490
2474
:meth:`~ArgumentParser.parse_args` method. This will inspect the command line,
491
convert each arg to the appropriate type and then invoke the appropriate action.
2475
-convert each arg to the appropriate type and then invoke the appropriate action.
492
2476
-In most cases, this means a simple namespace object will be built up from
2477
+convert each argument to the appropriate type and then invoke the appropriate action.
493
2478
+In most cases, this means a simple :class:`Namespace` object will be built up from
494
2479
attributes parsed out of the command line::
496
2481
>>> parser.parse_args(['--sum', '7', '-1', '42'])
2484
In a script, :meth:`~ArgumentParser.parse_args` will typically be called with no
2485
arguments, and the :class:`ArgumentParser` will automatically determine the
2486
-command-line args from :data:`sys.argv`.
2487
+command-line arguments from :data:`sys.argv`.
2490
ArgumentParser objects
2492
conflicting optionals.
2494
* prog_ - The name of the program (default:
2495
- :data:`sys.argv[0]`)
2498
* usage_ - The string describing the program usage (default: generated)
2503
The help option is typically ``-h/--help``. The exception to this is
2504
-if the ``prefix_chars=`` is specified and does not include ``'-'``, in
2505
+if the ``prefix_chars=`` is specified and does not include ``-``, in
2506
which case ``-h`` and ``--help`` are not valid options. In
2507
this case, the first character in ``prefix_chars`` is used to prefix
2513
-Most command-line options will use ``'-'`` as the prefix, e.g. ``-f/--foo``.
2514
+Most command-line options will use ``-`` as the prefix, e.g. ``-f/--foo``.
2515
Parsers that need to support different or additional prefix
2516
characters, e.g. for options
2517
like ``+f`` or ``/foo``, may specify them using the ``prefix_chars=`` argument
2519
Namespace(bar='Y', f='X')
2521
The ``prefix_chars=`` argument defaults to ``'-'``. Supplying a set of
2522
-characters that does not include ``'-'`` will cause ``-f/--foo`` options to be
2523
+characters that does not include ``-`` will cause ``-f/--foo`` options to be
2528
likewise for this epilog whose whitespace will be cleaned up and whose words
2529
will be wrapped across a couple lines
2531
-Passing :class:`~argparse.RawDescriptionHelpFormatter` as ``formatter_class=``
2532
+Passing :class:`RawDescriptionHelpFormatter` as ``formatter_class=``
2533
indicates that description_ and epilog_ are already correctly formatted and
2534
should not be line-wrapped::
2538
-h, --help show this help message and exit
2540
-:class:`RawTextHelpFormatter` maintains whitespace for all sorts of help text
2541
+:class:`RawTextHelpFormatter` maintains whitespace for all sorts of help text,
2542
including argument descriptions.
2544
The other formatter class available, :class:`ArgumentDefaultsHelpFormatter`,
2545
@@ -642,11 +646,11 @@
2549
-:class:`ArgumentParser` objects associate command-line args with actions. These
2550
-actions can do just about anything with the command-line args associated with
2551
+:class:`ArgumentParser` objects associate command-line arguments with actions. These
2552
+actions can do just about anything with the command-line arguments associated with
2553
them, though most actions simply add an attribute to the object returned by
2554
:meth:`~ArgumentParser.parse_args`. The ``action`` keyword argument specifies
2555
-how the command-line args should be handled. The supported actions are:
2556
+how the command-line arguments should be handled. The supported actions are:
2558
* ``'store'`` - This just stores the argument's value. This is the default
2559
action. For example::
2560
@@ -666,15 +670,17 @@
2561
>>> parser.parse_args('--foo'.split())
2564
-* ``'store_true'`` and ``'store_false'`` - These store the values ``True`` and
2565
- ``False`` respectively. These are special cases of ``'store_const'``. For
2567
+* ``'store_true'`` and ``'store_false'`` - These are special cases of
2568
+ ``'store_const'`` using for storing the values ``True`` and ``False``
2569
+ respectively. In addition, they create default values of *False* and *True*
2570
+ respectively. For example::
2572
>>> parser = argparse.ArgumentParser()
2573
>>> parser.add_argument('--foo', action='store_true')
2574
>>> parser.add_argument('--bar', action='store_false')
2575
+ >>> parser.add_argument('--baz', action='store_false')
2576
>>> parser.parse_args('--foo --bar'.split())
2577
- Namespace(bar=False, foo=True)
2578
+ Namespace(bar=False, baz=True, foo=True)
2580
* ``'append'`` - This stores a list, and appends each argument value to the
2581
list. This is useful to allow an option to be specified multiple times.
2582
@@ -714,12 +720,12 @@
499
2584
* ``parser`` - The ArgumentParser object which contains this action.
503
2588
:meth:`~ArgumentParser.parse_args`. Most actions add an attribute to this
506
@@ -1325,11 +1325,14 @@
2591
-* ``values`` - The associated command-line args, with any type-conversions
2592
- applied. (Type-conversions are specified with the type_ keyword argument to
2593
+* ``values`` - The associated command-line arguments, with any type conversions
2594
+ applied. (Type conversions are specified with the type_ keyword argument to
2595
:meth:`~ArgumentParser.add_argument`.
2597
* ``option_string`` - The option string that was used to invoke this action.
2599
different number of command-line arguments with a single action. The supported
2602
-* N (an integer). N args from the command line will be gathered together into a
2603
+* ``N`` (an integer). ``N`` arguments from the command line will be gathered together into a
2606
>>> parser = argparse.ArgumentParser()
2607
@@ -763,11 +769,11 @@
2608
Note that ``nargs=1`` produces a list of one item. This is different from
2609
the default, in which the item is produced by itself.
2611
-* ``'?'``. One arg will be consumed from the command line if possible, and
2612
- produced as a single item. If no command-line arg is present, the value from
2613
+* ``'?'``. One argument will be consumed from the command line if possible, and
2614
+ produced as a single item. If no command-line argument is present, the value from
2615
default_ will be produced. Note that for optional arguments, there is an
2616
additional case - the option string is present but not followed by a
2617
- command-line arg. In this case the value from const_ will be produced. Some
2618
+ command-line argument. In this case the value from const_ will be produced. Some
2619
examples to illustrate this::
2621
>>> parser = argparse.ArgumentParser()
2623
Namespace(infile=<open file '<stdin>', mode 'r' at 0x...>,
2624
outfile=<open file '<stdout>', mode 'w' at 0x...>)
2626
-* ``'*'``. All command-line args present are gathered into a list. Note that
2627
+* ``'*'``. All command-line arguments present are gathered into a list. Note that
2628
it generally doesn't make much sense to have more than one positional argument
2629
with ``nargs='*'``, but multiple optional arguments with ``nargs='*'`` is
2630
possible. For example::
2633
* ``'+'``. Just like ``'*'``, all command-line args present are gathered into a
2634
list. Additionally, an error message will be generated if there wasn't at
2635
- least one command-line arg present. For example::
2636
+ least one command-line argument present. For example::
2638
>>> parser = argparse.ArgumentParser(prog='PROG')
2639
>>> parser.add_argument('foo', nargs='+')
2641
usage: PROG [-h] foo [foo ...]
2642
PROG: error: too few arguments
2644
-If the ``nargs`` keyword argument is not provided, the number of args consumed
2645
-is determined by the action_. Generally this means a single command-line arg
2646
+If the ``nargs`` keyword argument is not provided, the number of arguments consumed
2647
+is determined by the action_. Generally this means a single command-line argument
2648
will be consumed and a single item (not a list) will be produced.
2653
* When :meth:`~ArgumentParser.add_argument` is called with option strings
2654
(like ``-f`` or ``--foo``) and ``nargs='?'``. This creates an optional
2655
- argument that can be followed by zero or one command-line args.
2656
+ argument that can be followed by zero or one command-line arguments.
2657
When parsing the command line, if the option string is encountered with no
2658
- command-line arg following it, the value of ``const`` will be assumed instead.
2659
+ command-line argument following it, the value of ``const`` will be assumed instead.
2660
See the nargs_ description for examples.
2662
The ``const`` keyword argument defaults to ``None``.
2664
All optional arguments and some positional arguments may be omitted at the
2665
command line. The ``default`` keyword argument of
2666
:meth:`~ArgumentParser.add_argument`, whose value defaults to ``None``,
2667
-specifies what value should be used if the command-line arg is not present.
2668
+specifies what value should be used if the command-line argument is not present.
2669
For optional arguments, the ``default`` value is used when the option string
2670
was not present at the command line::
2673
>>> parser.parse_args(''.split())
2676
-For positional arguments with nargs_ ``='?'`` or ``'*'``, the ``default`` value
2677
-is used when no command-line arg was present::
2678
+For positional arguments with nargs_ equal to ``?`` or ``*``, the ``default`` value
2679
+is used when no command-line argument was present::
2681
>>> parser = argparse.ArgumentParser()
2682
>>> parser.add_argument('foo', nargs='?', default=42)
2683
@@ -887,12 +893,12 @@
2687
-By default, ArgumentParser objects read command-line args in as simple strings.
2688
-However, quite often the command-line string should instead be interpreted as
2689
-another type, like a :class:`float`, :class:`int` or :class:`file`. The
2690
+By default, :class:`ArgumentParser` objects read command-line arguments in as simple
2691
+strings. However, quite often the command-line string should instead be
2692
+interpreted as another type, like a :class:`float` or :class:`int`. The
2693
``type`` keyword argument of :meth:`~ArgumentParser.add_argument` allows any
2694
-necessary type-checking and type-conversions to be performed. Many common
2695
-built-in types can be used directly as the value of the ``type`` argument::
2696
+necessary type-checking and type conversions to be performed. Common built-in
2697
+types and functions can be used directly as the value of the ``type`` argument::
2699
>>> parser = argparse.ArgumentParser()
2700
>>> parser.add_argument('foo', type=int)
2702
Namespace(bar=<open file 'out.txt', mode 'w' at 0x...>)
2704
``type=`` can take any callable that takes a single string argument and returns
2705
-the type-converted value::
2706
+the converted value::
2708
>>> def perfect_square(string):
2709
... value = int(string)
2710
@@ -946,11 +952,11 @@
2714
-Some command-line args should be selected from a restricted set of values.
2715
+Some command-line arguments should be selected from a restricted set of values.
2716
These can be handled by passing a container object as the ``choices`` keyword
2717
argument to :meth:`~ArgumentParser.add_argument`. When the command line is
2718
-parsed, arg values will be checked, and an error message will be displayed if
2719
-the arg was not one of the acceptable values::
2720
+parsed, argument values will be checked, and an error message will be displayed if
2721
+the argument was not one of the acceptable values::
2723
>>> parser = argparse.ArgumentParser(prog='PROG')
2724
>>> parser.add_argument('foo', choices='abc')
2725
@@ -1052,8 +1058,8 @@
2726
value as the "name" of each object. By default, for positional argument
2727
actions, the dest_ value is used directly, and for optional argument actions,
2728
the dest_ value is uppercased. So, a single positional argument with
2729
-``dest='bar'`` will that argument will be referred to as ``bar``. A single
2730
-optional argument ``--foo`` that should be followed by a single command-line arg
2731
+``dest='bar'`` will be referred to as ``bar``. A single
2732
+optional argument ``--foo`` that should be followed by a single command-line argument
2733
will be referred to as ``FOO``. An example::
2735
>>> parser = argparse.ArgumentParser()
2736
@@ -1125,10 +1131,10 @@
2738
For optional argument actions, the value of ``dest`` is normally inferred from
2739
the option strings. :class:`ArgumentParser` generates the value of ``dest`` by
2740
-taking the first long option string and stripping away the initial ``'--'``
2741
+taking the first long option string and stripping away the initial ``--``
2742
string. If no long option strings were supplied, ``dest`` will be derived from
2743
-the first short option string by stripping the initial ``'-'`` character. Any
2744
-internal ``'-'`` characters will be converted to ``'_'`` characters to make sure
2745
+the first short option string by stripping the initial ``-`` character. Any
2746
+internal ``-`` characters will be converted to ``_`` characters to make sure
2747
the string is a valid attribute name. The examples below illustrate this
2750
@@ -1160,7 +1166,7 @@
2751
created and how they are assigned. See the documentation for
2752
:meth:`add_argument` for details.
2754
- By default, the arg strings are taken from :data:`sys.argv`, and a new empty
2755
+ By default, the argument strings are taken from :data:`sys.argv`, and a new empty
2756
:class:`Namespace` object is created for the attributes.
2759
@@ -1231,15 +1237,15 @@
2760
PROG: error: extra arguments found: badger
2763
-Arguments containing ``"-"``
2764
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2765
+Arguments containing ``-``
2766
+^^^^^^^^^^^^^^^^^^^^^^^^^^
2768
The :meth:`~ArgumentParser.parse_args` method attempts to give errors whenever
2769
the user has clearly made a mistake, but some situations are inherently
2770
-ambiguous. For example, the command-line arg ``'-1'`` could either be an
2771
+ambiguous. For example, the command-line argument ``-1`` could either be an
2772
attempt to specify an option or an attempt to provide a positional argument.
2773
The :meth:`~ArgumentParser.parse_args` method is cautious here: positional
2774
-arguments may only begin with ``'-'`` if they look like negative numbers and
2775
+arguments may only begin with ``-`` if they look like negative numbers and
2776
there are no options in the parser that look like negative numbers::
2778
>>> parser = argparse.ArgumentParser(prog='PROG')
2779
@@ -1272,7 +1278,7 @@
2780
usage: PROG [-h] [-1 ONE] [foo]
2781
PROG: error: argument -1: expected one argument
2783
-If you have positional arguments that must begin with ``'-'`` and don't look
2784
+If you have positional arguments that must begin with ``-`` and don't look
2785
like negative numbers, you can insert the pseudo-argument ``'--'`` which tells
2786
:meth:`~ArgumentParser.parse_args` that everything after that is a positional
2788
@@ -1304,7 +1310,7 @@
2792
-Sometimes it may be useful to have an ArgumentParser parse args other than those
2793
+Sometimes it may be useful to have an ArgumentParser parse arguments other than those
2794
of :data:`sys.argv`. This can be accomplished by passing a list of strings to
2795
:meth:`~ArgumentParser.parse_args`. This is useful for testing at the
2796
interactive prompt::
2797
@@ -1325,11 +1331,14 @@
507
2798
The Namespace object
508
2799
^^^^^^^^^^^^^^^^^^^^
534
2863
.. _argparse-from-optparse:
2864
diff -r 8527427914a2 Doc/library/ast.rst
2865
--- a/Doc/library/ast.rst
2866
+++ b/Doc/library/ast.rst
2870
-Abstract Syntax Trees
2871
-=====================
2872
+:mod:`ast` --- Abstract Syntax Trees
2873
+====================================
2876
:synopsis: Abstract Syntax Tree classes and manipulation.
2878
.. versionadded:: 2.6
2879
The high-level ``ast`` module containing all helpers.
2881
+**Source code:** :source:`Lib/ast.py`
2885
The :mod:`ast` module helps Python applications to process trees of the Python
2886
abstract syntax grammar. The abstract syntax itself might change with each
2888
compiled into a Python code object using the built-in :func:`compile` function.
2893
- Latest version of the `ast module Python source code
2894
- <http://svn.python.org/view/python/branches/release27-maint/Lib/ast.py?view=markup>`_
2899
diff -r 8527427914a2 Doc/library/asynchat.rst
2900
--- a/Doc/library/asynchat.rst
2901
+++ b/Doc/library/asynchat.rst
2904
:mod:`asynchat` --- Asynchronous socket command/response handler
2905
================================================================
2908
.. moduleauthor:: Sam Rushing <rushing@nightmare.com>
2909
.. sectionauthor:: Steve Holden <sholden@holdenweb.com>
2911
+**Source code:** :source:`Lib/asynchat.py`
2915
This module builds on the :mod:`asyncore` infrastructure, simplifying
2916
asynchronous clients and servers and making it easier to handle protocols
2917
diff -r 8527427914a2 Doc/library/asyncore.rst
2918
--- a/Doc/library/asyncore.rst
2919
+++ b/Doc/library/asyncore.rst
2922
:mod:`asyncore` --- Asynchronous socket handler
2923
===============================================
2926
.. sectionauthor:: Steve Holden <sholden@holdenweb.com>
2927
.. heavily adapted from original documentation by Sam Rushing
2929
+**Source code:** :source:`Lib/asyncore.py`
2933
This module provides the basic infrastructure for writing asynchronous socket
2934
service clients and servers.
535
2935
diff -r 8527427914a2 Doc/library/atexit.rst
536
2936
--- a/Doc/library/atexit.rst
537
2937
+++ b/Doc/library/atexit.rst
2940
:mod:`atexit` --- Exit handlers
2941
===============================
2945
.. versionadded:: 2.0
2947
+**Source code:** :source:`Lib/atexit.py`
540
2951
The :mod:`atexit` module defines a single function to register cleanup
541
2952
functions. Functions thus registered are automatically executed upon normal
542
2953
-interpreter termination.
2957
- Latest version of the `atexit Python source code
2958
- <http://svn.python.org/view/python/branches/release27-maint/Lib/atexit.py?view=markup>`_
543
2959
+interpreter termination. The order in which the functions are called is not
544
2960
+defined; if you have cleanup operations that depend on each other, you should
545
2961
+wrap them in a function and register that one. This keeps :mod:`atexit` simple.
2963
Note: the functions registered via this module are not called when the program
2964
is killed by a signal not handled by Python, when a Python fatal internal error
2965
diff -r 8527427914a2 Doc/library/basehttpserver.rst
2966
--- a/Doc/library/basehttpserver.rst
2967
+++ b/Doc/library/basehttpserver.rst
2969
module: SimpleHTTPServer
2970
module: CGIHTTPServer
2972
+**Source code:** :source:`Lib/BaseHTTPServer.py`
2976
This module defines two classes for implementing HTTP servers (Web servers).
2977
Usually, this module isn't used directly, but is used as a basis for building
2978
functioning Web servers. See the :mod:`SimpleHTTPServer` and
2979
diff -r 8527427914a2 Doc/library/bdb.rst
2980
--- a/Doc/library/bdb.rst
2981
+++ b/Doc/library/bdb.rst
2984
:synopsis: Debugger framework.
2986
+**Source code:** :source:`Lib/bdb.py`
2990
The :mod:`bdb` module handles basic debugger functions, like setting breakpoints
2991
or managing execution via the debugger.
2993
diff -r 8527427914a2 Doc/library/bisect.rst
2994
--- a/Doc/library/bisect.rst
2995
+++ b/Doc/library/bisect.rst
2997
.. sectionauthor:: Raymond Hettinger <python at rcn.com>
2998
.. example based on the PyModules FAQ entry by Aaron Watters <arw@pythonpros.com>
3000
+.. versionadded:: 2.1
3002
+**Source code:** :source:`Lib/bisect.py`
3006
This module provides support for maintaining a list in sorted order without
3007
having to sort the list after each insertion. For long lists of items with
3008
expensive comparison operations, this can be an improvement over the more common
3010
algorithm to do its work. The source code may be most useful as a working
3011
example of the algorithm (the boundary conditions are already right!).
3013
-.. versionadded:: 2.1
3017
- Latest version of the `bisect module Python source code
3018
- <http://svn.python.org/view/python/branches/release27-maint/Lib/bisect.py?view=markup>`_
3020
The following functions are provided:
3023
diff -r 8527427914a2 Doc/library/calendar.rst
3024
--- a/Doc/library/calendar.rst
3025
+++ b/Doc/library/calendar.rst
3028
:mod:`calendar` --- General calendar-related functions
3029
======================================================
3033
.. sectionauthor:: Drew Csillag <drew_csillag@geocities.com>
3035
+**Source code:** :source:`Lib/calendar.py`
3039
This module allows you to output calendars like the Unix :program:`cal` program,
3040
and provides additional useful functions related to the calendar. By default,
3042
calendar in Dershowitz and Reingold's book "Calendrical Calculations", where
3043
it's the base calendar for all computations.
3047
- Latest version of the `calendar module Python source code
3048
- <http://svn.python.org/view/python/branches/release27-maint/Lib/calendar.py?view=markup>`_
3050
.. class:: Calendar([firstweekday])
3052
diff -r 8527427914a2 Doc/library/cgi.rst
3053
--- a/Doc/library/cgi.rst
3054
+++ b/Doc/library/cgi.rst
3057
single: Common Gateway Interface
3059
+**Source code:** :source:`Lib/cgi.py`
3063
Support module for Common Gateway Interface (CGI) scripts.
3065
This module defines a number of utilities for use by CGI scripts written in
549
3066
diff -r 8527427914a2 Doc/library/cmd.rst
550
3067
--- a/Doc/library/cmd.rst
551
3068
+++ b/Doc/library/cmd.rst
3071
:mod:`cmd` --- Support for line-oriented command interpreters
3072
=============================================================
3075
:synopsis: Build line-oriented command interpreters.
3076
.. sectionauthor:: Eric S. Raymond <esr@snark.thyrsus.com>
3078
+**Source code:** :source:`Lib/cmd.py`
3082
The :class:`Cmd` class provides a simple framework for writing line-oriented
3083
command interpreters. These are often useful for test harnesses, administrative
3084
tools, and prototypes that will later be wrapped in a more sophisticated
3089
- Latest version of the `cmd module Python source code
3090
- <http://svn.python.org/view/python/branches/release27-maint/Lib/cmd.py?view=markup>`_
3092
.. class:: Cmd([completekey[, stdin[, stdout]]])
3094
A :class:`Cmd` instance or subclass instance is a line-oriented interpreter
553
3096
the line as argument.
555
3098
The optional argument is a banner or intro string to be issued before the first
559
3102
If the :mod:`readline` module is loaded, input will automatically inherit
560
3103
:program:`bash`\ -like history-list editing (e.g. :kbd:`Control-P` scrolls back
3104
diff -r 8527427914a2 Doc/library/codecs.rst
3105
--- a/Doc/library/codecs.rst
3106
+++ b/Doc/library/codecs.rst
3107
@@ -782,27 +782,28 @@
3108
Windows). There's a string constant with 256 characters that shows you which
3109
character is mapped to which byte value.
3111
-All of these encodings can only encode 256 of the 65536 (or 1114111) codepoints
3112
+All of these encodings can only encode 256 of the 1114112 codepoints
3113
defined in unicode. A simple and straightforward way that can store each Unicode
3114
-code point, is to store each codepoint as two consecutive bytes. There are two
3115
-possibilities: Store the bytes in big endian or in little endian order. These
3116
-two encodings are called UTF-16-BE and UTF-16-LE respectively. Their
3117
-disadvantage is that if e.g. you use UTF-16-BE on a little endian machine you
3118
-will always have to swap bytes on encoding and decoding. UTF-16 avoids this
3119
-problem: Bytes will always be in natural endianness. When these bytes are read
3120
+code point, is to store each codepoint as four consecutive bytes. There are two
3121
+possibilities: store the bytes in big endian or in little endian order. These
3122
+two encodings are called ``UTF-32-BE`` and ``UTF-32-LE`` respectively. Their
3123
+disadvantage is that if e.g. you use ``UTF-32-BE`` on a little endian machine you
3124
+will always have to swap bytes on encoding and decoding. ``UTF-32`` avoids this
3125
+problem: bytes will always be in natural endianness. When these bytes are read
3126
by a CPU with a different endianness, then bytes have to be swapped though. To
3127
-be able to detect the endianness of a UTF-16 byte sequence, there's the so
3128
-called BOM (the "Byte Order Mark"). This is the Unicode character ``U+FEFF``.
3129
-This character will be prepended to every UTF-16 byte sequence. The byte swapped
3130
-version of this character (``0xFFFE``) is an illegal character that may not
3131
-appear in a Unicode text. So when the first character in an UTF-16 byte sequence
3132
+be able to detect the endianness of a ``UTF-16`` or ``UTF-32`` byte sequence,
3133
+there's the so called BOM ("Byte Order Mark"). This is the Unicode character
3134
+``U+FEFF``. This character can be prepended to every ``UTF-16`` or ``UTF-32``
3135
+byte sequence. The byte swapped version of this character (``0xFFFE``) is an
3136
+illegal character that may not appear in a Unicode text. So when the
3137
+first character in an ``UTF-16`` or ``UTF-32`` byte sequence
3138
appears to be a ``U+FFFE`` the bytes have to be swapped on decoding.
3139
-Unfortunately upto Unicode 4.0 the character ``U+FEFF`` had a second purpose as
3140
-a ``ZERO WIDTH NO-BREAK SPACE``: A character that has no width and doesn't allow
3141
+Unfortunately the character ``U+FEFF`` had a second purpose as
3142
+a ``ZERO WIDTH NO-BREAK SPACE``: a character that has no width and doesn't allow
3143
a word to be split. It can e.g. be used to give hints to a ligature algorithm.
3144
With Unicode 4.0 using ``U+FEFF`` as a ``ZERO WIDTH NO-BREAK SPACE`` has been
3145
deprecated (with ``U+2060`` (``WORD JOINER``) assuming this role). Nevertheless
3146
-Unicode software still must be able to handle ``U+FEFF`` in both roles: As a BOM
3147
+Unicode software still must be able to handle ``U+FEFF`` in both roles: as a BOM
3148
it's a device to determine the storage layout of the encoded bytes, and vanishes
3149
once the byte sequence has been decoded into a Unicode string; as a ``ZERO WIDTH
3150
NO-BREAK SPACE`` it's a normal character that will be decoded like any other.
3152
There's another encoding that is able to encoding the full range of Unicode
3153
characters: UTF-8. UTF-8 is an 8-bit encoding, which means there are no issues
3154
with byte order in UTF-8. Each byte in a UTF-8 byte sequence consists of two
3155
-parts: Marker bits (the most significant bits) and payload bits. The marker bits
3156
-are a sequence of zero to six 1 bits followed by a 0 bit. Unicode characters are
3157
+parts: marker bits (the most significant bits) and payload bits. The marker bits
3158
+are a sequence of zero to four ``1`` bits followed by a ``0`` bit. Unicode characters are
3159
encoded like this (with x being payload bits, which when concatenated give the
3162
@@ -824,12 +825,7 @@
3163
+-----------------------------------+----------------------------------------------+
3164
| ``U-00000800`` ... ``U-0000FFFF`` | 1110xxxx 10xxxxxx 10xxxxxx |
3165
+-----------------------------------+----------------------------------------------+
3166
-| ``U-00010000`` ... ``U-001FFFFF`` | 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx |
3167
-+-----------------------------------+----------------------------------------------+
3168
-| ``U-00200000`` ... ``U-03FFFFFF`` | 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx |
3169
-+-----------------------------------+----------------------------------------------+
3170
-| ``U-04000000`` ... ``U-7FFFFFFF`` | 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx |
3172
+| ``U-00010000`` ... ``U-0010FFFF`` | 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx |
3173
+-----------------------------------+----------------------------------------------+
3175
The least significant bit of the Unicode character is the rightmost x bit.
3176
@@ -854,13 +850,14 @@
3177
| RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK
3178
| INVERTED QUESTION MARK
3180
-in iso-8859-1), this increases the probability that a utf-8-sig encoding can be
3181
+in iso-8859-1), this increases the probability that a ``utf-8-sig`` encoding can be
3182
correctly guessed from the byte sequence. So here the BOM is not used to be able
3183
to determine the byte order used for generating the byte sequence, but as a
3184
signature that helps in guessing the encoding. On encoding the utf-8-sig codec
3185
will write ``0xef``, ``0xbb``, ``0xbf`` as the first three bytes to the file. On
3186
-decoding utf-8-sig will skip those three bytes if they appear as the first three
3188
+decoding ``utf-8-sig`` will skip those three bytes if they appear as the first
3189
+three bytes in the file. In UTF-8, the use of the BOM is discouraged and
3190
+should generally be avoided.
3193
.. _standard-encodings:
561
3194
diff -r 8527427914a2 Doc/library/collections.rst
562
3195
--- a/Doc/library/collections.rst
563
3196
+++ b/Doc/library/collections.rst
3199
:mod:`collections` --- High-performance container datatypes
3200
===========================================================
3204
__name__ = '<doctest>'
3206
+**Source code:** :source:`Lib/collections.py` and :source:`Lib/_abcoll.py`
3210
This module implements specialized container datatypes providing alternatives to
3211
Python's general purpose built-in containers, :class:`dict`, :class:`list`,
3212
:class:`set`, and :class:`tuple`.
565
3214
===================== ==================================================================== ===========================
567
3216
In addition to the concrete container classes, the collections module provides
568
3217
-:ref:`abstract-base-classes` that can be used to test whether a class provides a
569
+:ref:`collections-abstract-base-classes` that can be used to test whether a class provides a
570
particular interface, for example, whether it is hashable or a mapping.
3218
-particular interface, for example, whether it is hashable or a mapping.
3219
+:ref:`abstract base classes <collections-abstract-base-classes>` that can be
3220
+used to test whether a class provides a particular interface, for example,
3221
+whether it is hashable or a mapping.
3225
- Latest version of the `collections module Python source code
3226
- <http://svn.python.org/view/python/branches/release27-maint/Lib/collections.py?view=markup>`_
3228
:class:`Counter` objects
3229
------------------------
3231
* The multiset methods are designed only for use cases with positive values.
3232
The inputs may be negative or zero, but only outputs with positive values
3233
are created. There are no type restrictions, but the value type needs to
3234
- support support addition, subtraction, and comparison.
3235
+ support addition, subtraction, and comparison.
3237
* The :meth:`elements` method requires integer counts. It ignores zero and
3239
@@ -202,14 +202,14 @@
3240
* `Bag class <http://www.gnu.org/software/smalltalk/manual-base/html_node/Bag.html>`_
3243
- * Wikipedia entry for `Multisets <http://en.wikipedia.org/wiki/Multiset>`_\.
3244
+ * Wikipedia entry for `Multisets <http://en.wikipedia.org/wiki/Multiset>`_.
3246
* `C++ multisets <http://www.demo2s.com/Tutorial/Cpp/0380__set-multiset/Catalog0380__set-multiset.htm>`_
3247
tutorial with examples.
3249
* For mathematical operations on multisets and their use cases, see
3250
*Knuth, Donald. The Art of Computer Programming Volume II,
3251
- Section 4.6.3, Exercise 19*\.
3252
+ Section 4.6.3, Exercise 19*.
3254
* To enumerate all distinct multisets of a given size over a given set of
3255
elements, see :func:`itertools.combinations_with_replacement`.
3257
:class:`defaultdict` objects support the following method in addition to the
3258
standard :class:`dict` operations:
3261
- .. method:: defaultdict.__missing__(key)
3262
+ .. method:: __missing__(key)
3264
If the :attr:`default_factory` attribute is ``None``, this raises a
3265
:exc:`KeyError` exception with the *key* as argument.
3267
:class:`defaultdict` objects support the following instance variable:
3270
- .. attribute:: defaultdict.default_factory
3271
+ .. attribute:: default_factory
3273
This attribute is used by the :meth:`__missing__` method; it is
3274
initialized from the first argument to the constructor, if present, or to
574
3276
'Return a new OrderedDict which maps field names to their values'
575
3277
return OrderedDict(zip(self._fields, self))
2026
5513
.. attribute:: raw
5515
@@ -604,25 +604,6 @@
5516
if the buffer needs to be written out but the raw stream blocks.
5519
-.. class:: BufferedRWPair(reader, writer, buffer_size=DEFAULT_BUFFER_SIZE)
5521
- A buffered I/O object giving a combined, higher-level access to two
5522
- sequential :class:`RawIOBase` objects: one readable, the other writeable.
5523
- It is useful for pairs of unidirectional communication channels
5524
- (pipes, for instance). It inherits :class:`BufferedIOBase`.
5526
- *reader* and *writer* are :class:`RawIOBase` objects that are readable and
5527
- writeable respectively. If the *buffer_size* is omitted it defaults to
5528
- :data:`DEFAULT_BUFFER_SIZE`.
5530
- A fourth argument, *max_buffer_size*, is supported, but unused and
5533
- :class:`BufferedRWPair` implements all of :class:`BufferedIOBase`\'s methods
5534
- except for :meth:`~BufferedIOBase.detach`, which raises
5535
- :exc:`UnsupportedOperation`.
5538
.. class:: BufferedRandom(raw, buffer_size=DEFAULT_BUFFER_SIZE)
5540
A buffered interface to random access streams. It inherits
5541
@@ -639,6 +620,29 @@
5542
:class:`BufferedWriter` can do.
5545
+.. class:: BufferedRWPair(reader, writer, buffer_size=DEFAULT_BUFFER_SIZE)
5547
+ A buffered I/O object combining two unidirectional :class:`RawIOBase`
5548
+ objects -- one readable, the other writeable -- into a single bidirectional
5549
+ endpoint. It inherits :class:`BufferedIOBase`.
5551
+ *reader* and *writer* are :class:`RawIOBase` objects that are readable and
5552
+ writeable respectively. If the *buffer_size* is omitted it defaults to
5553
+ :data:`DEFAULT_BUFFER_SIZE`.
5555
+ A fourth argument, *max_buffer_size*, is supported, but unused and
5558
+ :class:`BufferedRWPair` implements all of :class:`BufferedIOBase`\'s methods
5559
+ except for :meth:`~BufferedIOBase.detach`, which raises
5560
+ :exc:`UnsupportedOperation`.
5563
+ :class:`BufferedRWPair` does not attempt to synchronize accesses to
5564
+ its underlying raw streams. You should not pass it the same object
5565
+ as reader and writer; use :class:`BufferedRandom` instead.
5571
diff -r 8527427914a2 Doc/library/itertools.rst
5572
--- a/Doc/library/itertools.rst
5573
+++ b/Doc/library/itertools.rst
5576
def izip(*iterables):
5577
# izip('ABCD', 'xy') --> Ax By
5578
- iterables = map(iter, iterables)
5580
- yield tuple(map(next, iterables))
5581
+ iterators = map(iter, iterables)
5583
+ yield tuple(map(next, iterators))
5585
.. versionchanged:: 2.4
5586
When no iterables are specified, returns a zero length iterator instead of
5587
@@ -456,17 +456,24 @@
5588
iterables are of uneven length, missing values are filled-in with *fillvalue*.
5589
Iteration continues until the longest iterable is exhausted. Equivalent to::
5591
+ class ZipExhausted(Exception):
5594
def izip_longest(*args, **kwds):
5595
# izip_longest('ABCD', 'xy', fillvalue='-') --> Ax By C- D-
5596
fillvalue = kwds.get('fillvalue')
5597
- def sentinel(counter = ([fillvalue]*(len(args)-1)).pop):
5598
- yield counter() # yields the fillvalue, or raises IndexError
5599
+ counter = [len(args) - 1]
5601
+ if not counter[0]:
5602
+ raise ZipExhausted
5605
fillers = repeat(fillvalue)
5606
- iters = [chain(it, sentinel(), fillers) for it in args]
5607
+ iterators = [chain(it, sentinel(), fillers) for it in args]
5609
- for tup in izip(*iters):
5611
- except IndexError:
5613
+ yield tuple(map(next, iterators))
5614
+ except ZipExhausted:
5617
If one of the iterables is potentially infinite, then the
5618
diff -r 8527427914a2 Doc/library/keyword.rst
5619
--- a/Doc/library/keyword.rst
5620
+++ b/Doc/library/keyword.rst
5623
:mod:`keyword` --- Testing for Python keywords
5624
==============================================
5627
:synopsis: Test whether a string is a keyword in Python.
5629
+**Source code:** :source:`Lib/keyword.py`
5633
This module allows a Python program to determine if a string is a keyword.
5636
Sequence containing all the keywords defined for the interpreter. If any
5637
keywords are defined to only be active when particular :mod:`__future__`
5638
statements are in effect, these will be included as well.
5643
- Latest version of the `keyword module Python source code
5644
- <http://svn.python.org/view/python/branches/release27-maint/Lib/keyword.py?view=markup>`_
5645
diff -r 8527427914a2 Doc/library/linecache.rst
5646
--- a/Doc/library/linecache.rst
5647
+++ b/Doc/library/linecache.rst
5649
:synopsis: This module provides random access to individual lines from text files.
5650
.. sectionauthor:: Moshe Zadka <moshez@zadka.site.co.il>
5652
+**Source code:** :source:`Lib/linecache.py`
5656
The :mod:`linecache` module allows one to get any line from any file, while
5657
attempting to optimize internally, using a cache, the common case where many
5658
lines are read from a single file. This is used by the :mod:`traceback` module
5659
to retrieve source lines for inclusion in the formatted traceback.
5663
- Latest version of the `linecache module Python source code
5664
- <http://svn.python.org/view/python/branches/release27-maint/Lib/linecache.py?view=markup>`_
5666
The :mod:`linecache` module defines the following functions:
5669
diff -r 8527427914a2 Doc/library/locale.rst
5670
--- a/Doc/library/locale.rst
5671
+++ b/Doc/library/locale.rst
5674
.. exception:: Error
5676
- Exception raised when :func:`setlocale` fails.
5677
+ Exception raised when the locale passed to :func:`setlocale` is not
5681
.. function:: setlocale(category[, locale])
5683
- If *locale* is specified, it may be a string, a tuple of the form ``(language
5684
- code, encoding)``, or ``None``. If it is a tuple, it is converted to a string
5685
- using the locale aliasing engine. If *locale* is given and not ``None``,
5686
- :func:`setlocale` modifies the locale setting for the *category*. The available
5687
- categories are listed in the data description below. The value is the name of a
5688
- locale. An empty string specifies the user's default settings. If the
5689
- modification of the locale fails, the exception :exc:`Error` is raised. If
5690
- successful, the new locale setting is returned.
5691
+ If *locale* is given and not ``None``, :func:`setlocale` modifies the locale
5692
+ setting for the *category*. The available categories are listed in the data
5693
+ description below. *locale* may be a string, or an iterable of two strings
5694
+ (language code and encoding). If it's an iterable, it's converted to a locale
5695
+ name using the locale aliasing engine. An empty string specifies the user's
5696
+ default settings. If the modification of the locale fails, the exception
5697
+ :exc:`Error` is raised. If successful, the new locale setting is returned.
5699
If *locale* is omitted or ``None``, the current setting for *category* is
5702
changed thereafter, using multithreading should not cause problems.
5704
.. versionchanged:: 2.0
5705
- Added support for tuple values of the *locale* parameter.
5706
+ Added support for iterable values of the *locale* parameter.
5709
.. function:: localeconv()
2028
5710
diff -r 8527427914a2 Doc/library/logging.config.rst
2029
5711
--- a/Doc/library/logging.config.rst
2030
5712
+++ b/Doc/library/logging.config.rst
2348
6444
===========================================
2350
6446
.. module:: Queue
6448
:term:`2to3` tool will automatically adapt imports when converting your
6451
+**Source code:** :source:`Lib/Queue.py`
6455
The :mod:`Queue` module implements multi-producer, multi-consumer queues.
6456
It is especially useful in threaded programming when information must be
6458
the entries are kept sorted (using the :mod:`heapq` module) and the
6459
lowest valued entry is retrieved first.
2355
6463
- Latest version of the `queue module Python source code
2356
+ Latest version of the `Queue module Python source code
2357
<http://svn.python.org/view/python/branches/release27-maint/Lib/Queue.py?view=markup>`_.
6464
- <http://svn.python.org/view/python/branches/release27-maint/Lib/Queue.py?view=markup>`_.
2359
6466
The :mod:`Queue` module defines the following classes and exceptions:
6468
.. class:: Queue(maxsize=0)
6469
diff -r 8527427914a2 Doc/library/quopri.rst
6470
--- a/Doc/library/quopri.rst
6471
+++ b/Doc/library/quopri.rst
6474
:mod:`quopri` --- Encode and decode MIME quoted-printable data
6475
==============================================================
6478
pair: quoted-printable; encoding
6479
single: MIME; quoted-printable encoding
6481
+**Source code:** :source:`Lib/quopri.py`
6485
This module performs quoted-printable transport encoding and decoding, as
6486
defined in :rfc:`1521`: "MIME (Multipurpose Internet Mail Extensions) Part One:
6487
Mechanisms for Specifying and Describing the Format of Internet Message Bodies".
6489
:mod:`base64` module is more compact if there are many such characters, as when
6490
sending a graphics file.
6494
- Latest version of the `quopri module Python source code
6495
- <http://svn.python.org/view/python/branches/release27-maint/Lib/quopri.py?view=markup>`_
6497
.. function:: decode(input, output[,header])
6499
Decode the contents of the *input* file and write the resulting decoded binary
6500
diff -r 8527427914a2 Doc/library/random.rst
6501
--- a/Doc/library/random.rst
6502
+++ b/Doc/library/random.rst
6505
:mod:`random` --- Generate pseudo-random numbers
6506
================================================
6509
:synopsis: Generate pseudo-random numbers with various common distributions.
6511
+**Source code:** :source:`Lib/random.py`
6515
This module implements pseudo-random number generators for various
6520
- Latest version of the `random module Python source code
6521
- <http://svn.python.org/view/python/branches/release27-maint/Lib/random.py?view=markup>`_
6523
For integers, uniform selection from a range. For sequences, uniform selection
6524
of a random element, a function to generate a random permutation of a list
6525
in-place, and a function for random sampling without replacement.
6527
The end-point value ``b`` may or may not be included in the range
6528
depending on floating-point rounding in the equation ``a + (b-a) * random()``.
6531
.. function:: triangular(low, high, mode)
6533
Return a random floating point number *N* such that ``low <= N <= high`` and
6534
@@ -229,6 +227,12 @@
6535
Gamma distribution. (*Not* the gamma function!) Conditions on the
6536
parameters are ``alpha > 0`` and ``beta > 0``.
6538
+ The probability distribution function is::
6540
+ x ** (alpha - 1) * math.exp(-x / beta)
6541
+ pdf(x) = --------------------------------------
6542
+ math.gamma(alpha) * beta ** alpha
6545
.. function:: gauss(mu, sigma)
6547
diff -r 8527427914a2 Doc/library/re.rst
6548
--- a/Doc/library/re.rst
6549
+++ b/Doc/library/re.rst
6550
@@ -156,30 +156,36 @@
6551
raw strings for all but the simplest expressions.
6554
- Used to indicate a set of characters. Characters can be listed individually, or
6555
- a range of characters can be indicated by giving two characters and separating
6556
- them by a ``'-'``. Special characters are not active inside sets. For example,
6557
- ``[akm$]`` will match any of the characters ``'a'``, ``'k'``,
6558
- ``'m'``, or ``'$'``; ``[a-z]`` will match any lowercase letter, and
6559
- ``[a-zA-Z0-9]`` matches any letter or digit. Character classes such
6560
- as ``\w`` or ``\S`` (defined below) are also acceptable inside a
6561
- range, although the characters they match depends on whether :const:`LOCALE`
6562
- or :const:`UNICODE` mode is in force. If you want to include a
6563
- ``']'`` or a ``'-'`` inside a set, precede it with a backslash, or
6564
- place it as the first character. The pattern ``[]]`` will match
6565
- ``']'``, for example.
6566
+ Used to indicate a set of characters. In a set:
6568
- You can match the characters not within a range by :dfn:`complementing` the set.
6569
- This is indicated by including a ``'^'`` as the first character of the set;
6570
- ``'^'`` elsewhere will simply match the ``'^'`` character. For example,
6571
- ``[^5]`` will match any character except ``'5'``, and ``[^^]`` will match any
6572
- character except ``'^'``.
6573
+ * Characters can be listed individually, e.g. ``[amk]`` will match ``'a'``,
6574
+ ``'m'``, or ``'k'``.
6576
- Note that inside ``[]`` the special forms and special characters lose
6577
- their meanings and only the syntaxes described here are valid. For
6578
- example, ``+``, ``*``, ``(``, ``)``, and so on are treated as
6579
- literals inside ``[]``, and backreferences cannot be used inside
6581
+ * Ranges of characters can be indicated by giving two characters and separating
6582
+ them by a ``'-'``, for example ``[a-z]`` will match any lowercase ASCII letter,
6583
+ ``[0-5][0-9]`` will match all the two-digits numbers from ``00`` to ``59``, and
6584
+ ``[0-9A-Fa-f]`` will match any hexadecimal digit. If ``-`` is escaped (e.g.
6585
+ ``[a\-z]``) or if it's placed as the first or last character (e.g. ``[a-]``),
6586
+ it will match a literal ``'-'``.
6588
+ * Special characters lose their special meaning inside sets. For example,
6589
+ ``[(+*)]`` will match any of the literal characters ``'('``, ``'+'``,
6590
+ ``'*'``, or ``')'``.
6592
+ * Character classes such as ``\w`` or ``\S`` (defined below) are also accepted
6593
+ inside a set, although the characters they match depends on whether
6594
+ :const:`LOCALE` or :const:`UNICODE` mode is in force.
6596
+ * Characters that are not within a range can be matched by :dfn:`complementing`
6597
+ the set. If the first character of the set is ``'^'``, all the characters
6598
+ that are *not* in the set will be matched. For example, ``[^5]`` will match
6599
+ any character except ``'5'``, and ``[^^]`` will match any character except
6600
+ ``'^'``. ``^`` has no special meaning if it's not the first character in
6603
+ * To match a literal ``']'`` inside a set, precede it with a backslash, or
6604
+ place it at the beginning of the set. For example, both ``[()[\]{}]`` and
6605
+ ``[]()[{}]`` will both match a parenthesis.
6608
``A|B``, where A and B can be arbitrary REs, creates a regular expression that
6613
-.. function:: compile(pattern[, flags])
6614
+.. function:: compile(pattern, flags=0)
6616
Compile a regular expression pattern into a regular expression object, which
6617
can be used for matching using its :func:`match` and :func:`search` methods,
6619
b = re.compile(r"\d+\.\d*")
6622
-.. function:: search(pattern, string[, flags])
6623
+.. function:: search(pattern, string, flags=0)
6625
Scan through *string* looking for a location where the regular expression
6626
*pattern* produces a match, and return a corresponding :class:`MatchObject`
6631
-.. function:: match(pattern, string[, flags])
6632
+.. function:: match(pattern, string, flags=0)
6634
If zero or more characters at the beginning of *string* match the regular
6635
expression *pattern*, return a corresponding :class:`MatchObject` instance.
6640
-.. function:: split(pattern, string[, maxsplit=0, flags=0])
6641
+.. function:: split(pattern, string, maxsplit=0, flags=0)
6643
Split *string* by the occurrences of *pattern*. If capturing parentheses are
6644
used in *pattern*, then the text of all groups in the pattern are also returned
6646
Added the optional flags argument.
6649
-.. function:: findall(pattern, string[, flags])
6650
+.. function:: findall(pattern, string, flags=0)
6652
Return all non-overlapping matches of *pattern* in *string*, as a list of
6653
strings. The *string* is scanned left-to-right, and matches are returned in
6655
Added the optional flags argument.
6658
-.. function:: finditer(pattern, string[, flags])
6659
+.. function:: finditer(pattern, string, flags=0)
6661
Return an :term:`iterator` yielding :class:`MatchObject` instances over all
6662
non-overlapping matches for the RE *pattern* in *string*. The *string* is
6663
@@ -607,13 +613,13 @@
6664
Added the optional flags argument.
6667
-.. function:: sub(pattern, repl, string[, count, flags])
6668
+.. function:: sub(pattern, repl, string, count=0, flags=0)
6670
Return the string obtained by replacing the leftmost non-overlapping occurrences
6671
of *pattern* in *string* by the replacement *repl*. If the pattern isn't found,
6672
*string* is returned unchanged. *repl* can be a string or a function; if it is
6673
a string, any backslash escapes in it are processed. That is, ``\n`` is
6674
- converted to a single newline character, ``\r`` is converted to a linefeed, and
6675
+ converted to a single newline character, ``\r`` is converted to a carriage return, and
6676
so forth. Unknown escapes such as ``\j`` are left alone. Backreferences, such
6677
as ``\6``, are replaced with the substring matched by group 6 in the pattern.
6680
Added the optional flags argument.
6683
-.. function:: subn(pattern, repl, string[, count, flags])
6684
+.. function:: subn(pattern, repl, string, count=0, flags=0)
6686
Perform the same operation as :func:`sub`, but return a tuple ``(new_string,
6687
number_of_subs_made)``.
6689
<_sre.SRE_Match object at ...>
6692
- .. method:: RegexObject.split(string[, maxsplit=0])
6693
+ .. method:: RegexObject.split(string, maxsplit=0)
6695
Identical to the :func:`split` function, using the compiled pattern.
6697
@@ -760,12 +766,12 @@
6698
region like for :meth:`match`.
6701
- .. method:: RegexObject.sub(repl, string[, count=0])
6702
+ .. method:: RegexObject.sub(repl, string, count=0)
6704
Identical to the :func:`sub` function, using the compiled pattern.
6707
- .. method:: RegexObject.subn(repl, string[, count=0])
6708
+ .. method:: RegexObject.subn(repl, string, count=0)
6710
Identical to the :func:`subn` function, using the compiled pattern.
2360
6712
diff -r 8527427914a2 Doc/library/repr.rst
2361
6713
--- a/Doc/library/repr.rst
2362
6714
+++ b/Doc/library/repr.rst
6717
:mod:`repr` --- Alternate :func:`repr` implementation
6718
=====================================================
6721
:term:`2to3` tool will automatically adapt imports when converting your
6724
+**Source code:** :source:`Lib/repr.py`
6728
The :mod:`repr` module provides a means for producing object representations
6729
with limits on the size of the resulting strings. This is used in the Python
6730
debugger and may be useful in other contexts as well.
6734
- Latest version of the `repr module Python source code
6735
- <http://svn.python.org/view/python/branches/release27-maint/Lib/repr.py?view=markup>`_
6737
This module provides a class, an instance, and a function:
2483
7029
will be used to invoke the archiver.
2485
7031
If given, *extra_args* is a sequence of ``(name, value)`` that will be
7032
diff -r 8527427914a2 Doc/library/simplexmlrpcserver.rst
7033
--- a/Doc/library/simplexmlrpcserver.rst
7034
+++ b/Doc/library/simplexmlrpcserver.rst
7037
.. versionadded:: 2.2
7039
+**Source code:** :source:`Lib/SimpleXMLRPCServer.py`
7043
The :mod:`SimpleXMLRPCServer` module provides a basic server framework for
7044
XML-RPC servers written in Python. Servers can either be free standing, using
7045
:class:`SimpleXMLRPCServer`, or embedded in a CGI environment, using
7046
diff -r 8527427914a2 Doc/library/site.rst
7047
--- a/Doc/library/site.rst
7048
+++ b/Doc/library/site.rst
7051
:mod:`site` --- Site-specific configuration hook
7052
================================================
7055
- :synopsis: A standard way to reference site-specific modules.
7056
+ :synopsis: Module responsible for site-specific configuration.
7058
+**Source code:** :source:`Lib/site.py`
7062
+.. highlightlang:: none
7064
**This module is automatically imported during initialization.** The automatic
7065
import can be suppressed using the interpreter's :option:`-S` option.
7067
.. index:: triple: module; search; path
7069
-Importing this module will append site-specific paths to the module search path.
7070
+Importing this module will append site-specific paths to the module search path
7071
+and add a few builtins.
7074
pair: site-python; directory
7076
if it refers to an existing directory, and if so, adds it to ``sys.path`` and
7077
also inspects the newly added path for configuration files.
7079
-A path configuration file is a file whose name has the form :file:`package.pth`
7080
+A path configuration file is a file whose name has the form :file:`{name}.pth`
7081
and exists in one of the four directories mentioned above; its contents are
7082
additional items (one per line) to be added to ``sys.path``. Non-existing items
7083
-are never added to ``sys.path``, but no check is made that the item refers to a
7084
-directory (rather than a file). No item is added to ``sys.path`` more than
7085
+are never added to ``sys.path``, and no check is made that the item refers to a
7086
+directory rather than a file. No item is added to ``sys.path`` more than
7087
once. Blank lines and lines beginning with ``#`` are skipped. Lines starting
7088
with ``import`` (followed by space or tab) are executed.
7092
For example, suppose ``sys.prefix`` and ``sys.exec_prefix`` are set to
7093
:file:`/usr/local`. The Python X.Y library is then installed in
7094
-:file:`/usr/local/lib/python{X.Y}` (where only the first three characters of
7095
-``sys.version`` are used to form the installation path name). Suppose this has
7096
+:file:`/usr/local/lib/python{X.Y}`. Suppose this has
7097
a subdirectory :file:`/usr/local/lib/python{X.Y}/site-packages` with three
7098
subsubdirectories, :file:`foo`, :file:`bar` and :file:`spam`, and two path
7099
configuration files, :file:`foo.pth` and :file:`bar.pth`. Assume
7100
@@ -77,86 +81,132 @@
7102
After these path manipulations, an attempt is made to import a module named
7103
:mod:`sitecustomize`, which can perform arbitrary site-specific customizations.
7104
-If this import fails with an :exc:`ImportError` exception, it is silently
7106
+It is typically created by a system administrator in the site-packages
7107
+directory. If this import fails with an :exc:`ImportError` exception, it is
7110
-.. index:: module: sitecustomize
7111
+.. index:: module: usercustomize
7113
+After this, an attempt is made to import a module named :mod:`usercustomize`,
7114
+which can perform arbitrary user-specific customizations, if
7115
+:data:`ENABLE_USER_SITE` is true. This file is intended to be created in the
7116
+user site-packages directory (see below), which is part of ``sys.path`` unless
7117
+disabled by :option:`-s`. An :exc:`ImportError` will be silently ignored.
7119
Note that for some non-Unix systems, ``sys.prefix`` and ``sys.exec_prefix`` are
7120
empty, and the path manipulations are skipped; however the import of
7121
-:mod:`sitecustomize` is still attempted.
7122
+:mod:`sitecustomize` and :mod:`usercustomize` is still attempted.
7127
- A list of prefixes for site package directories
7128
+ A list of prefixes for site-packages directories.
7130
.. versionadded:: 2.6
7133
.. data:: ENABLE_USER_SITE
7135
- Flag showing the status of the user site directory. True means the
7136
- user site directory is enabled and added to sys.path. When the flag
7137
- is None the user site directory is disabled for security reasons.
7138
+ Flag showing the status of the user site-packages directory. ``True`` means
7139
+ that it is enabled and was added to ``sys.path``. ``False`` means that it
7140
+ was disabled by user request (with :option:`-s` or
7141
+ :envvar:`PYTHONNOUSERSITE`). ``None`` means it was disabled for security
7142
+ reasons (mismatch between user or group id and effective id) or by an
7145
.. versionadded:: 2.6
7150
- Path to the user site directory for the current Python version or None
7151
+ Path to the user site-packages for the running Python. Can be ``None`` if
7152
+ :func:`getusersitepackages` hasn't been called yet. Default value is
7153
+ :file:`~/.local/lib/python{X.Y}/site-packages` for UNIX and non-framework Mac
7154
+ OS X builds, :file:`~/Library/Python/{X.Y}/lib/python/site-packages` for Mac
7155
+ framework builds, and :file:`{%APPDATA%}\\Python\\Python{XY}\\site-packages`
7156
+ on Windows. This directory is a site directory, which means that
7157
+ :file:`.pth` files in it will be processed.
7159
.. versionadded:: 2.6
7164
- Path to the base directory for user site directories
7165
+ Path to the base directory for the user site-packages. Can be ``None`` if
7166
+ :func:`getuserbase` hasn't been called yet. Default value is
7167
+ :file:`~/.local` for UNIX and Mac OS X non-framework builds,
7168
+ :file:`~/Library/Python/{X.Y}` for Mac framework builds, and
7169
+ :file:`{%APPDATA%}\\Python` for Windows. This value is used by Distutils to
7170
+ compute the installation directories for scripts, data files, Python modules,
7171
+ etc. for the :ref:`user installation scheme <inst-alt-install-user>`. See
7172
+ also :envvar:`PYTHONUSERBASE`.
7174
.. versionadded:: 2.6
7177
-.. envvar:: PYTHONNOUSERSITE
7179
- .. versionadded:: 2.6
7182
-.. envvar:: PYTHONUSERBASE
7184
- .. versionadded:: 2.6
7187
.. function:: addsitedir(sitedir, known_paths=None)
7189
- Adds a directory to sys.path and processes its pth files.
7190
+ Add a directory to sys.path and process its :file:`.pth` files. Typically
7191
+ used in :mod:`sitecustomize` or :mod:`usercustomize` (see above).
7194
.. function:: getsitepackages()
7196
- Returns a list containing all global site-packages directories
7197
- (and possibly site-python).
7198
+ Return a list containing all global site-packages directories (and possibly
7201
.. versionadded:: 2.7
7204
.. function:: getuserbase()
7206
- Returns the "user base" directory path.
7208
- The "user base" directory can be used to store data. If the global
7209
- variable ``USER_BASE`` is not initialized yet, this function will also set
7211
+ Return the path of the user base directory, :data:`USER_BASE`. If it is not
7212
+ initialized yet, this function will also set it, respecting
7213
+ :envvar:`PYTHONUSERBASE`.
7215
.. versionadded:: 2.7
7218
.. function:: getusersitepackages()
7220
- Returns the user-specific site-packages directory path.
7222
- If the global variable ``USER_SITE`` is not initialized yet, this
7223
- function will also set it.
7224
+ Return the path of the user-specific site-packages directory,
7225
+ :data:`USER_SITE`. If it is not initialized yet, this function will also set
7226
+ it, respecting :envvar:`PYTHONNOUSERSITE` and :data:`USER_BASE`.
7228
.. versionadded:: 2.7
7230
-.. XXX Update documentation
7231
-.. XXX document python -m site --user-base --user-site
7233
+The :mod:`site` module also provides a way to get the user directories from the
7238
+ $ python3 -m site --user-site
7239
+ /home/user/.local/lib/python3.3/site-packages
7243
+If it is called without arguments, it will print the contents of
7244
+:data:`sys.path` on the standard output, followed by the value of
7245
+:data:`USER_BASE` and whether the directory exists, then the same thing for
7246
+:data:`USER_SITE`, and finally the value of :data:`ENABLE_USER_SITE`.
7248
+.. cmdoption:: --user-base
7250
+ Print the path to the user base directory.
7252
+.. cmdoption:: --user-site
7254
+ Print the path to the user site-packages directory.
7256
+If both options are given, user base and user site will be printed (always in
7257
+this order), separated by :data:`os.pathsep`.
7259
+If any option is given, the script will exit with one of these values: ``O`` if
7260
+the user site-packages directory is enabled, ``1`` if it was disabled by the
7261
+user, ``2`` if it is disabled for security reasons or by an administrator, and a
7262
+value greater than 2 if there is an error.
7266
+ :pep:`370` -- Per user site-packages directory
7267
diff -r 8527427914a2 Doc/library/smtpd.rst
7268
--- a/Doc/library/smtpd.rst
7269
+++ b/Doc/library/smtpd.rst
7271
.. moduleauthor:: Barry Warsaw <barry@zope.com>
7272
.. sectionauthor:: Moshe Zadka <moshez@moshez.org>
7274
+**Source code:** :source:`Lib/smtpd.py`
7279
This module offers several classes to implement SMTP servers. One is a generic
7280
do-nothing implementation, which can be overridden, while the other two offer
7281
diff -r 8527427914a2 Doc/library/smtplib.rst
7282
--- a/Doc/library/smtplib.rst
7283
+++ b/Doc/library/smtplib.rst
7286
:mod:`smtplib` --- SMTP protocol client
7287
=======================================
7290
pair: SMTP; protocol
7291
single: Simple Mail Transfer Protocol
7293
+**Source code:** :source:`Lib/smtplib.py`
7297
The :mod:`smtplib` module defines an SMTP client session object that can be used
7298
to send mail to any Internet machine with an SMTP or ESMTP listener daemon. For
7299
details of SMTP and ESMTP operation, consult :rfc:`821` (Simple Mail Transfer
7300
diff -r 8527427914a2 Doc/library/sndhdr.rst
7301
--- a/Doc/library/sndhdr.rst
7302
+++ b/Doc/library/sndhdr.rst
7305
:mod:`sndhdr` --- Determine type of sound file
7306
==============================================
7312
+**Source code:** :source:`Lib/sndhdr.py`
7316
The :mod:`sndhdr` provides utility functions which attempt to determine the type
7317
of sound data which is in a file. When these functions are able to determine
7318
what type of sound data is stored in a file, they return a tuple ``(type,
2486
7319
diff -r 8527427914a2 Doc/library/socket.rst
2487
7320
--- a/Doc/library/socket.rst
2488
7321
+++ b/Doc/library/socket.rst
2839
7979
diff -r 8527427914a2 Doc/library/subprocess.rst
2840
7980
--- a/Doc/library/subprocess.rst
2841
7981
+++ b/Doc/library/subprocess.rst
2842
@@ -428,38 +428,39 @@
7983
Using the subprocess Module
7984
---------------------------
7986
-This module defines one class called :class:`Popen`:
7987
+The recommended approach to invoking subprocesses is to use the following
7988
+convenience functions for all use cases they can handle. For more advanced
7989
+use cases, the underlying :class:`Popen` interface can be used directly.
7992
+.. function:: call(args, *, stdin=None, stdout=None, stderr=None, shell=False)
7994
+ Run the command described by *args*. Wait for command to complete, then
7995
+ return the :attr:`returncode` attribute.
7997
+ The arguments shown above are merely the most common ones, described below
7998
+ in :ref:`frequently-used-arguments` (hence the slightly odd notation in
7999
+ the abbreviated signature). The full function signature is the same as
8000
+ that of the :class:`Popen` constructor - this functions passes all
8001
+ supplied arguments directly through to that interface.
8005
+ >>> subprocess.call(["ls", "-l"])
8008
+ >>> subprocess.call("exit 1", shell=True)
8013
+ Invoking the system shell with ``shell=True`` can be a security hazard
8014
+ if combined with untrusted input. See the warning under
8015
+ :ref:`frequently-used-arguments` for details.
8019
+ Do not use ``stdout=PIPE`` or ``stderr=PIPE`` with this function. As
8020
+ the pipes are not being read in the current process, the child
8021
+ process may block if it generates enough output to a pipe to fill up
8022
+ the OS pipe buffer.
8025
+.. function:: check_call(args, *, stdin=None, stdout=None, stderr=None, shell=False)
8027
+ Run command with arguments. Wait for command to complete. If the return
8028
+ code was zero then return, otherwise raise :exc:`CalledProcessError`. The
8029
+ :exc:`CalledProcessError` object will have the return code in the
8030
+ :attr:`returncode` attribute.
8032
+ The arguments shown above are merely the most common ones, described below
8033
+ in :ref:`frequently-used-arguments` (hence the slightly odd notation in
8034
+ the abbreviated signature). The full function signature is the same as
8035
+ that of the :class:`Popen` constructor - this functions passes all
8036
+ supplied arguments directly through to that interface.
8040
+ >>> subprocess.check_call(["ls", "-l"])
8043
+ >>> subprocess.check_call("exit 1", shell=True)
8044
+ Traceback (most recent call last):
8046
+ subprocess.CalledProcessError: Command 'exit 1' returned non-zero exit status 1
8048
+ .. versionadded:: 2.5
8052
+ Invoking the system shell with ``shell=True`` can be a security hazard
8053
+ if combined with untrusted input. See the warning under
8054
+ :ref:`frequently-used-arguments` for details.
8058
+ Do not use ``stdout=PIPE`` or ``stderr=PIPE`` with this function. As
8059
+ the pipes are not being read in the current process, the child
8060
+ process may block if it generates enough output to a pipe to fill up
8061
+ the OS pipe buffer.
8064
+.. function:: check_output(args, *, stdin=None, stderr=None, shell=False, universal_newlines=False)
8066
+ Run command with arguments and return its output as a byte string.
8068
+ If the return code was non-zero it raises a :exc:`CalledProcessError`. The
8069
+ :exc:`CalledProcessError` object will have the return code in the
8070
+ :attr:`returncode` attribute and any output in the :attr:`output`
8073
+ The arguments shown above are merely the most common ones, described below
8074
+ in :ref:`frequently-used-arguments` (hence the slightly odd notation in
8075
+ the abbreviated signature). The full function signature is largely the
8076
+ same as that of the :class:`Popen` constructor, except that *stdout* is
8077
+ not permitted as it is used internally. All other supplied arguments are
8078
+ passed directly through to the :class:`Popen` constructor.
8082
+ >>> subprocess.check_output(["echo", "Hello World!"])
8085
+ >>> subprocess.check_output("exit 1", shell=True)
8086
+ Traceback (most recent call last):
8088
+ subprocess.CalledProcessError: Command 'exit 1' returned non-zero exit status 1
8090
+ To also capture standard error in the result, use
8091
+ ``stderr=subprocess.STDOUT``::
8093
+ >>> subprocess.check_output(
8094
+ ... "ls non_existent_file; exit 0",
8095
+ ... stderr=subprocess.STDOUT,
8097
+ 'ls: non_existent_file: No such file or directory\n'
8099
+ .. versionadded:: 2.7
8103
+ Invoking the system shell with ``shell=True`` can be a security hazard
8104
+ if combined with untrusted input. See the warning under
8105
+ :ref:`frequently-used-arguments` for details.
8109
+ Do not use ``stderr=PIPE`` with this function. As the pipe is not being
8110
+ read in the current process, the child process may block if it
8111
+ generates enough output to the pipe to fill up the OS pipe buffer.
8116
+ Special value that can be used as the *stdin*, *stdout* or *stderr* argument
8117
+ to :class:`Popen` and indicates that a pipe to the standard stream should be
8123
+ Special value that can be used as the *stderr* argument to :class:`Popen` and
8124
+ indicates that standard error should go into the same handle as standard
8128
+.. _frequently-used-arguments:
8130
+Frequently Used Arguments
8131
+^^^^^^^^^^^^^^^^^^^^^^^^^
8133
+To support a wide variety of use cases, the :class:`Popen` constructor (and
8134
+the convenience functions) accept a large number of optional arguments. For
8135
+most typical use cases, many of these arguments can be safely left at their
8136
+default values. The arguments that are most commonly needed are:
8138
+ *args* is required for all calls and should be a string, or a sequence of
8139
+ program arguments. Providing a sequence of arguments is generally
8140
+ preferred, as it allows the module to take care of any required escaping
8141
+ and quoting of arguments (e.g. to permit spaces in file names). If passing
8142
+ a single string, either *shell* must be :const:`True` (see below) or else
8143
+ the string must simply name the program to be executed without specifying
8146
+ *stdin*, *stdout* and *stderr* specify the executed program's standard input,
8147
+ standard output and standard error file handles, respectively. Valid values
8148
+ are :data:`PIPE`, an existing file descriptor (a positive integer), an
8149
+ existing file object, and ``None``. :data:`PIPE` indicates that a new pipe
8150
+ to the child should be created. With the default settings of ``None``, no
8151
+ redirection will occur; the child's file handles will be inherited from the
8152
+ parent. Additionally, *stderr* can be :data:`STDOUT`, which indicates that
8153
+ the stderr data from the child process should be captured into the same file
8154
+ handle as for stdout.
8156
+ When *stdout* or *stderr* are pipes and *universal_newlines* is
8157
+ :const:`True` then all line endings will be converted to ``'\n'`` as
8158
+ described for the universal newlines `'U'`` mode argument to :func:`open`.
8160
+ If *shell* is :const:`True`, the specified command will be executed through
8161
+ the shell. This can be useful if you are using Python primarily for the
8162
+ enhanced control flow it offers over most system shells and still want
8163
+ access to other shell features such as filename wildcards, shell pipes and
8164
+ environment variable expansion.
8168
+ Executing shell commands that incorporate unsanitized input from an
8169
+ untrusted source makes a program vulnerable to `shell injection
8170
+ <http://en.wikipedia.org/wiki/Shell_injection#Shell_injection>`_,
8171
+ a serious security flaw which can result in arbitrary command execution.
8172
+ For this reason, the use of *shell=True* is **strongly discouraged** in cases
8173
+ where the command string is constructed from external input::
8175
+ >>> from subprocess import call
8176
+ >>> filename = input("What file would you like to display?\n")
8177
+ What file would you like to display?
8178
+ non_existent; rm -rf / #
8179
+ >>> call("cat " + filename, shell=True) # Uh-oh. This will end badly...
8181
+ ``shell=False`` disables all shell based features, but does not suffer
8182
+ from this vulnerability; see the Note in the :class:`Popen` constructor
8183
+ documentation for helpful hints in getting ``shell=False`` to work.
8185
+These options, along with all of the other options, are described in more
8186
+detail in the :class:`Popen` constructor documentation.
8192
+The underlying process creation and management in this module is handled by
8193
+the :class:`Popen` class. It offers a lot of flexibility so that developers
8194
+are able to handle the less common cases not covered by the convenience
8198
.. class:: Popen(args, bufsize=0, executable=None, stdin=None, stdout=None, stderr=None, preexec_fn=None, close_fds=False, shell=False, cwd=None, env=None, universal_newlines=False, startupinfo=None, creationflags=0)
8201
Popen(['/bin/sh', '-c', args[0], args[1], ...])
8205
- Executing shell commands that incorporate unsanitized input from an
8206
- untrusted source makes a program vulnerable to `shell injection
8207
- <http://en.wikipedia.org/wiki/Shell_injection#Shell_injection>`_,
8208
- a serious security flaw which can result in arbitrary command execution.
8209
- For this reason, the use of *shell=True* is **strongly discouraged** in cases
8210
- where the command string is constructed from external input::
8212
- >>> from subprocess import call
8213
- >>> filename = input("What file would you like to display?\n")
8214
- What file would you like to display?
8215
- non_existent; rm -rf / #
8216
- >>> call("cat " + filename, shell=True) # Uh-oh. This will end badly...
8218
- *shell=False* does not suffer from this vulnerability; the above Note may be
8219
- helpful in getting code using *shell=False* to work.
8221
On Windows: the :class:`Popen` class uses CreateProcess() to execute the child
8222
child program, which operates on strings. If *args* is a sequence, it will
8223
be converted to a string in a manner described in
8224
@@ -126,14 +316,15 @@
8225
You don't need ``shell=True`` to run a batch file, nor to run a console-based
8228
- *stdin*, *stdout* and *stderr* specify the executed programs' standard input,
8229
+ *stdin*, *stdout* and *stderr* specify the executed program's standard input,
8230
standard output and standard error file handles, respectively. Valid values
8231
are :data:`PIPE`, an existing file descriptor (a positive integer), an
8232
existing file object, and ``None``. :data:`PIPE` indicates that a new pipe
8233
- to the child should be created. With ``None``, no redirection will occur;
8234
- the child's file handles will be inherited from the parent. Additionally,
8235
- *stderr* can be :data:`STDOUT`, which indicates that the stderr data from the
8236
- applications should be captured into the same file handle as for stdout.
8237
+ to the child should be created. With the default settings of ``None``, no
8238
+ redirection will occur; the child's file handles will be inherited from the
8239
+ parent. Additionally, *stderr* can be :data:`STDOUT`, which indicates that
8240
+ the stderr data from the child process should be captured into the same file
8241
+ handle as for stdout.
8243
If *preexec_fn* is set to a callable object, this object will be called in the
8244
child process just before the child is executed. (Unix only)
8245
@@ -147,6 +338,12 @@
8246
If *shell* is :const:`True`, the specified command will be executed through the
8251
+ Enabling this option can be a security hazard if combined with untrusted
8252
+ input. See the warning under :ref:`frequently-used-arguments`
8255
If *cwd* is not ``None``, the child's current directory will be changed to *cwd*
8256
before it is executed. Note that this directory is not considered when
8257
searching the executable, so you can't specify the program's path relative to
8258
@@ -184,87 +381,6 @@
8259
:data:`CREATE_NEW_PROCESS_GROUP`. (Windows only)
8264
- Special value that can be used as the *stdin*, *stdout* or *stderr* argument
8265
- to :class:`Popen` and indicates that a pipe to the standard stream should be
8271
- Special value that can be used as the *stderr* argument to :class:`Popen` and
8272
- indicates that standard error should go into the same handle as standard
8276
-Convenience Functions
8277
-^^^^^^^^^^^^^^^^^^^^^
8279
-This module also defines the following shortcut functions:
8282
-.. function:: call(*popenargs, **kwargs)
8284
- Run command with arguments. Wait for command to complete, then return the
8285
- :attr:`returncode` attribute.
8287
- The arguments are the same as for the :class:`Popen` constructor. Example::
8289
- >>> retcode = subprocess.call(["ls", "-l"])
8293
- Like :meth:`Popen.wait`, this will deadlock when using
8294
- ``stdout=PIPE`` and/or ``stderr=PIPE`` and the child process
8295
- generates enough output to a pipe such that it blocks waiting
8296
- for the OS pipe buffer to accept more data.
8299
-.. function:: check_call(*popenargs, **kwargs)
8301
- Run command with arguments. Wait for command to complete. If the exit code was
8302
- zero then return, otherwise raise :exc:`CalledProcessError`. The
8303
- :exc:`CalledProcessError` object will have the return code in the
8304
- :attr:`returncode` attribute.
8306
- The arguments are the same as for the :class:`Popen` constructor. Example::
8308
- >>> subprocess.check_call(["ls", "-l"])
8311
- .. versionadded:: 2.5
8315
- See the warning for :func:`call`.
8318
-.. function:: check_output(*popenargs, **kwargs)
8320
- Run command with arguments and return its output as a byte string.
8322
- If the exit code was non-zero it raises a :exc:`CalledProcessError`. The
8323
- :exc:`CalledProcessError` object will have the return code in the
8324
- :attr:`returncode`
8325
- attribute and output in the :attr:`output` attribute.
8327
- The arguments are the same as for the :class:`Popen` constructor. Example::
8329
- >>> subprocess.check_output(["ls", "-l", "/dev/null"])
8330
- 'crw-rw-rw- 1 root root 1, 3 Oct 18 2007 /dev/null\n'
8332
- The stdout argument is not allowed as it is used internally.
8333
- To capture standard error in the result, use ``stderr=subprocess.STDOUT``::
8335
- >>> subprocess.check_output(
8336
- ... ["/bin/sh", "-c", "ls non_existent_file; exit 0"],
8337
- ... stderr=subprocess.STDOUT)
8338
- 'ls: non_existent_file: No such file or directory\n'
8340
- .. versionadded:: 2.7
8346
@@ -280,16 +396,19 @@
8347
A :exc:`ValueError` will be raised if :class:`Popen` is called with invalid
8350
-check_call() will raise :exc:`CalledProcessError`, if the called process returns
8351
-a non-zero return code.
8352
+:func:`check_call` and :func:`check_output` will raise
8353
+:exc:`CalledProcessError` if the called process returns a non-zero return
8360
-Unlike some other popen functions, this implementation will never call /bin/sh
8361
-implicitly. This means that all characters, including shell metacharacters, can
8362
-safely be passed to child processes.
8363
+Unlike some other popen functions, this implementation will never call a
8364
+system shell implicitly. This means that all characters, including shell
8365
+metacharacters, can safely be passed to child processes. Obviously, if the
8366
+shell is invoked explicitly, then it is the application's responsibility to
8367
+ensure that all whitespace and metacharacters are quoted appropriately.
8371
@@ -428,38 +547,39 @@
2844
8373
.. attribute:: dwFlags
3483
10392
for key in mapping:
3484
10393
if key not in seen:
3485
10394
result.append(key)
10395
diff -r 8527427914a2 Lib/HTMLParser.py
10396
--- a/Lib/HTMLParser.py
10397
+++ b/Lib/HTMLParser.py
10399
# Regular expressions used for parsing
10401
interesting_normal = re.compile('[&<]')
10402
-interesting_cdata = re.compile(r'<(/|\Z)')
10403
incomplete = re.compile('&[a-zA-Z#]')
10405
entityref = re.compile('&([a-zA-Z][-.a-zA-Z0-9]*)[^a-zA-Z0-9]')
10406
@@ -24,25 +23,28 @@
10407
piclose = re.compile('>')
10408
commentclose = re.compile(r'--\s*>')
10409
tagfind = re.compile('[a-zA-Z][-.a-zA-Z0-9:_]*')
10411
attrfind = re.compile(
10412
- r'\s*([a-zA-Z_][-.:a-zA-Z_0-9]*)(\s*=\s*'
10413
- r'(\'[^\']*\'|"[^"]*"|[^\s"\'=<>`]*))?')
10414
+ r'\s*((?<=[\'"\s])[^\s/>][^\s/=>]*)(\s*=+\s*'
10415
+ r'(\'[^\']*\'|"[^"]*"|(?![\'"])[^>\s]*))?')
10417
locatestarttagend = re.compile(r"""
10418
<[a-zA-Z][-.a-zA-Z0-9:_]* # tag name
10419
(?:\s+ # whitespace before attribute name
10420
- (?:[a-zA-Z_][-.:a-zA-Z0-9_]* # attribute name
10421
- (?:\s*=\s* # value indicator
10422
+ (?:(?<=['"\s])[^\s/>][^\s/=>]* # attribute name
10423
+ (?:\s*=+\s* # value indicator
10424
(?:'[^']*' # LITA-enclosed value
10425
- |\"[^\"]*\" # LIT-enclosed value
10426
- |[^'\">\s]+ # bare value
10427
+ |"[^"]*" # LIT-enclosed value
10428
+ |(?!['"])[^>\s]* # bare value
10436
\s* # trailing whitespace
10438
endendtag = re.compile('>')
10439
+# the HTML 5 spec, section 8.1.2.2, doesn't allow spaces between
10440
+# </ and the tag name, so maybe this should be fixed
10441
endtagfind = re.compile('</\s*([a-zA-Z][-.a-zA-Z0-9:_]*)\s*>')
10446
self.lasttag = '???'
10447
self.interesting = interesting_normal
10448
+ self.cdata_elem = None
10449
markupbase.ParserBase.reset(self)
10451
def feed(self, data):
10452
@@ -120,11 +123,13 @@
10453
"""Return full source of start tag: '<...>'."""
10454
return self.__starttag_text
10456
- def set_cdata_mode(self):
10457
- self.interesting = interesting_cdata
10458
+ def set_cdata_mode(self, elem):
10459
+ self.cdata_elem = elem.lower()
10460
+ self.interesting = re.compile(r'</\s*%s\s*>' % self.cdata_elem, re.I)
10462
def clear_cdata_mode(self):
10463
self.interesting = interesting_normal
10464
+ self.cdata_elem = None
10466
# Internal -- handle data as far as reasonable. May leave state
10467
# and data to be processed by a subsequent call. If 'end' is
10468
@@ -138,6 +143,8 @@
10472
+ if self.cdata_elem:
10475
if i < j: self.handle_data(rawdata[i:j])
10476
i = self.updatepos(i, j)
10477
@@ -206,7 +213,7 @@
10479
assert 0, "interesting.search() lied"
10481
- if end and i < n:
10482
+ if end and i < n and not self.cdata_elem:
10483
self.handle_data(rawdata[i:n])
10484
i = self.updatepos(i, n)
10485
self.rawdata = rawdata[i:]
10486
@@ -249,6 +256,7 @@
10487
elif attrvalue[:1] == '\'' == attrvalue[-1:] or \
10488
attrvalue[:1] == '"' == attrvalue[-1:]:
10489
attrvalue = attrvalue[1:-1]
10491
attrvalue = self.unescape(attrvalue)
10492
attrs.append((attrname.lower(), attrvalue))
10494
@@ -270,7 +278,7 @@
10496
self.handle_starttag(tag, attrs)
10497
if tag in self.CDATA_CONTENT_ELEMENTS:
10498
- self.set_cdata_mode()
10499
+ self.set_cdata_mode(tag)
10502
# Internal -- check to see if we have a complete starttag; return end
10503
@@ -314,9 +322,18 @@
10505
match = endtagfind.match(rawdata, i) # </ + tag + >
10507
+ if self.cdata_elem is not None:
10508
+ self.handle_data(rawdata[i:j])
10510
self.error("bad end tag: %r" % (rawdata[i:j],))
10511
- tag = match.group(1)
10512
- self.handle_endtag(tag.lower())
10514
+ elem = match.group(1).lower() # script or style
10515
+ if self.cdata_elem is not None:
10516
+ if elem != self.cdata_elem:
10517
+ self.handle_data(rawdata[i:j])
10520
+ self.handle_endtag(elem)
10521
self.clear_cdata_mode()
10524
diff -r 8527427914a2 Lib/SocketServer.py
10525
--- a/Lib/SocketServer.py
10526
+++ b/Lib/SocketServer.py
10528
data is stored externally (e.g. in the file system), a synchronous
10529
class will essentially render the service "deaf" while one request is
10530
being handled -- which may be for a very long time if a client is slow
10531
-to reqd all the data it has requested. Here a threading or forking
10532
+to read all the data it has requested. Here a threading or forking
10533
server is appropriate.
10535
In some cases, it may be appropriate to process part of a request
10536
@@ -589,8 +589,7 @@
10537
"""Start a new thread to process the request."""
10538
t = threading.Thread(target = self.process_request_thread,
10539
args = (request, client_address))
10540
- if self.daemon_threads:
10542
+ t.daemon = self.daemon_threads
10546
diff -r 8527427914a2 Lib/_pyio.py
10554
# Import thread instead of threading to reduce startup cost
10556
from thread import allocate_lock as Lock
10557
@@ -720,8 +721,11 @@
10560
if self.raw is not None and not self.closed:
10564
+ # may raise BlockingIOError or BrokenPipeError etc
10570
if self.raw is None:
10571
@@ -1074,13 +1078,9 @@
10572
# XXX we can implement some more tricks to try and avoid
10574
if len(self._write_buf) > self.buffer_size:
10575
- # We're full, so let's pre-flush the buffer
10577
- self._flush_unlocked()
10578
- except BlockingIOError as e:
10579
- # We can't accept anything else.
10580
- # XXX Why not just let the exception pass through?
10581
- raise BlockingIOError(e.errno, e.strerror, 0)
10582
+ # We're full, so let's pre-flush the buffer. (This may
10583
+ # raise BlockingIOError with characters_written == 0.)
10584
+ self._flush_unlocked()
10585
before = len(self._write_buf)
10586
self._write_buf.extend(b)
10587
written = len(self._write_buf) - before
10588
@@ -1111,24 +1111,23 @@
10589
def _flush_unlocked(self):
10591
raise ValueError("flush of closed file")
10594
- while self._write_buf:
10596
- n = self.raw.write(self._write_buf)
10597
- except IOError as e:
10598
- if e.errno != EINTR:
10601
- if n > len(self._write_buf) or n < 0:
10602
- raise IOError("write() returned incorrect number of bytes")
10603
- del self._write_buf[:n]
10605
- except BlockingIOError as e:
10606
- n = e.characters_written
10607
+ while self._write_buf:
10609
+ n = self.raw.write(self._write_buf)
10610
+ except BlockingIOError:
10611
+ raise RuntimeError("self.raw should implement RawIOBase: it "
10612
+ "should not raise BlockingIOError")
10613
+ except IOError as e:
10614
+ if e.errno != EINTR:
10618
+ raise BlockingIOError(
10620
+ "write could not complete without blocking", 0)
10621
+ if n > len(self._write_buf) or n < 0:
10622
+ raise IOError("write() returned incorrect number of bytes")
10623
del self._write_buf[:n]
10625
- raise BlockingIOError(e.errno, e.strerror, written)
10628
return _BufferedIOMixin.tell(self) + len(self._write_buf)
3486
10629
diff -r 8527427914a2 Lib/asyncore.py
3487
10630
--- a/Lib/asyncore.py
3488
10631
+++ b/Lib/asyncore.py
3950
11661
# On AIX, there are wrong paths to the linker scripts in the Makefile
3951
11662
# -- these paths are relative to the Python source, but when installed
3952
11663
# the scripts are in another directory.
11664
diff -r 8527427914a2 Lib/distutils/tests/support.py
11665
--- a/Lib/distutils/tests/support.py
11666
+++ b/Lib/distutils/tests/support.py
11668
"""Support code for distutils test cases."""
11675
from copy import deepcopy
11679
from distutils.log import DEBUG, INFO, WARN, ERROR, FATAL
11680
from distutils.core import Distribution
11683
def capture_warnings(func):
11684
def _capture_warnings(*args, **kw):
11685
with warnings.catch_warnings():
11687
return func(*args, **kw)
11688
return _capture_warnings
11691
class LoggingSilencer(object):
11695
def clear_logs(self):
11699
class TempdirManager(object):
11700
"""Mix-in class that handles temporary directories for test cases.
11705
super(TempdirManager, self).setUp()
11706
+ self.old_cwd = os.getcwd()
11709
def tearDown(self):
11710
+ # Restore working dir, for Solaris and derivatives, where rmdir()
11711
+ # on the current directory fails.
11712
+ os.chdir(self.old_cwd)
11713
super(TempdirManager, self).tearDown()
11714
while self.tempdirs:
11715
d = self.tempdirs.pop()
11716
@@ -105,6 +115,7 @@
11718
return pkg_dir, dist
11721
class DummyCommand:
11722
"""Class to store options for retrieval via set_undefined_options()."""
11724
@@ -115,6 +126,7 @@
11725
def ensure_finalized(self):
11729
class EnvironGuard(object):
11732
@@ -131,3 +143,73 @@
11733
del os.environ[key]
11735
super(EnvironGuard, self).tearDown()
11738
+def copy_xxmodule_c(directory):
11739
+ """Helper for tests that need the xxmodule.c source file.
11743
+ def test_compile(self):
11744
+ copy_xxmodule_c(self.tmpdir)
11745
+ self.assertIn('xxmodule.c', os.listdir(self.tmpdir))
11747
+ If the source file can be found, it will be copied to *directory*. If not,
11748
+ the test will be skipped. Errors during copy are not caught.
11750
+ filename = _get_xxmodule_path()
11751
+ if filename is None:
11752
+ raise unittest.SkipTest('cannot find xxmodule.c (test must run in '
11753
+ 'the python build dir)')
11754
+ shutil.copy(filename, directory)
11757
+def _get_xxmodule_path():
11758
+ # FIXME when run from regrtest, srcdir seems to be '.', which does not help
11759
+ # us find the xxmodule.c file
11760
+ srcdir = sysconfig.get_config_var('srcdir')
11762
+ # use installed copy if available
11763
+ os.path.join(os.path.dirname(__file__), 'xxmodule.c'),
11764
+ # otherwise try using copy from build directory
11765
+ os.path.join(srcdir, 'Modules', 'xxmodule.c'),
11766
+ # srcdir mysteriously can be $srcdir/Lib/distutils/tests when
11767
+ # this file is run from its parent directory, so walk up the
11768
+ # tree to find the real srcdir
11769
+ os.path.join(srcdir, '..', '..', '..', 'Modules', 'xxmodule.c'),
11771
+ for path in candidates:
11772
+ if os.path.exists(path):
11776
+def fixup_build_ext(cmd):
11777
+ """Function needed to make build_ext tests pass.
11779
+ When Python was build with --enable-shared on Unix, -L. is not good
11780
+ enough to find the libpython<blah>.so. This is because regrtest runs
11781
+ it under a tempdir, not in the top level where the .so lives. By the
11782
+ time we've gotten here, Python's already been chdir'd to the tempdir.
11784
+ When Python was built with in debug mode on Windows, build_ext commands
11785
+ need their debug attribute set, and it is not done automatically for
11788
+ This function handles both of these things. Example use:
11790
+ cmd = build_ext(dist)
11791
+ support.fixup_build_ext(cmd)
11792
+ cmd.ensure_finalized()
11794
+ if os.name == 'nt':
11795
+ cmd.debug = sys.executable.endswith('_d.exe')
11796
+ elif sysconfig.get_config_var('Py_ENABLE_SHARED'):
11797
+ # To further add to the shared builds fun on Unix, we can't just add
11798
+ # library_dirs to the Extension() instance because that doesn't get
11799
+ # plumbed through to the final compiler command.
11800
+ runshared = sysconfig.get_config_var('RUNSHARED')
11801
+ if runshared is None:
11802
+ cmd.library_dirs = ['.']
11804
+ name, equals, value = runshared.partition('=')
11805
+ cmd.library_dirs = value.split(os.pathsep)
11806
diff -r 8527427914a2 Lib/distutils/tests/test_bdist.py
11807
--- a/Lib/distutils/tests/test_bdist.py
11808
+++ b/Lib/distutils/tests/test_bdist.py
11810
"""Tests for distutils.command.bdist."""
11818
from test.test_support import run_unittest
11820
-from distutils.core import Distribution
11821
from distutils.command.bdist import bdist
11822
from distutils.tests import support
11823
-from distutils.spawn import find_executable
11824
-from distutils import spawn
11825
-from distutils.errors import DistutilsExecError
11828
class BuildTestCase(support.TempdirManager,
11829
unittest.TestCase):
11831
def test_formats(self):
11833
# let's create a command and make sure
11834
- # we can fix the format
11835
- pkg_pth, dist = self.create_dist()
11836
+ # we can set the format
11837
+ dist = self.create_dist()[1]
11839
cmd.formats = ['msi']
11840
cmd.ensure_finalized()
11841
self.assertEqual(cmd.formats, ['msi'])
11843
- # what format bdist offers ?
11844
- # XXX an explicit list in bdist is
11845
- # not the best way to bdist_* commands
11846
- # we should add a registry
11847
- formats = ['rpm', 'zip', 'gztar', 'bztar', 'ztar',
11848
- 'tar', 'wininst', 'msi']
11850
- founded = cmd.format_command.keys()
11852
- self.assertEqual(founded, formats)
11853
+ # what formats does bdist offer?
11854
+ formats = ['bztar', 'gztar', 'msi', 'rpm', 'tar',
11855
+ 'wininst', 'zip', 'ztar']
11856
+ found = sorted(cmd.format_command)
11857
+ self.assertEqual(found, formats)
11859
+ def test_skip_build(self):
11860
+ # bug #10946: bdist --skip-build should trickle down to subcommands
11861
+ dist = self.create_dist()[1]
11862
+ cmd = bdist(dist)
11863
+ cmd.skip_build = 1
11864
+ cmd.ensure_finalized()
11865
+ dist.command_obj['bdist'] = cmd
11867
+ names = ['bdist_dumb', 'bdist_wininst']
11868
+ # bdist_rpm does not support --skip-build
11869
+ if os.name == 'nt':
11870
+ names.append('bdist_msi')
11872
+ for name in names:
11873
+ subcmd = cmd.get_finalized_command(name)
11874
+ self.assertTrue(subcmd.skip_build,
11875
+ '%s should take --skip-build from bdist' % name)
11879
return unittest.makeSuite(BuildTestCase)
3953
11880
diff -r 8527427914a2 Lib/distutils/tests/test_build_ext.py
3954
11881
--- a/Lib/distutils/tests/test_build_ext.py
3955
11882
+++ b/Lib/distutils/tests/test_build_ext.py
11888
from StringIO import StringIO
3957
11892
from distutils.command.build_ext import build_ext
3958
11893
from distutils import sysconfig
3959
11894
from distutils.tests import support
4047
12116
deptarget_ext = Extension(
4049
12118
[deptarget_c],
12119
@@ -477,10 +497,8 @@
12120
cmd.build_temp = self.tmp_dir
12123
- old_stdout = sys.stdout
12124
cmd.ensure_finalized()
12127
except CompileError:
12128
self.fail("Wrong deployment target during compilation")
12130
diff -r 8527427914a2 Lib/distutils/tests/test_check.py
12131
--- a/Lib/distutils/tests/test_check.py
12132
+++ b/Lib/distutils/tests/test_check.py
12134
+# -*- encoding: utf8 -*-
12135
"""Tests for distutils.command.check."""
12137
from test.test_support import run_unittest
12139
cmd = self._run(metadata, strict=1)
12140
self.assertEqual(cmd._warnings, 0)
12142
+ # now a test with Unicode entries
12143
+ metadata = {'url': u'xxx', 'author': u'\u00c9ric',
12144
+ 'author_email': u'xxx', u'name': 'xxx',
12145
+ 'version': u'xxx',
12146
+ 'description': u'Something about esszet \u00df',
12147
+ 'long_description': u'More things about esszet \u00df'}
12148
+ cmd = self._run(metadata)
12149
+ self.assertEqual(cmd._warnings, 0)
12151
def test_check_document(self):
12152
if not HAS_DOCUTILS: # won't test without docutils
12155
self.assertRaises(DistutilsSetupError, self._run, metadata,
12156
**{'strict': 1, 'restructuredtext': 1})
12158
- # and non-broken rest
12159
- metadata['long_description'] = 'title\n=====\n\ntest'
12160
+ # and non-broken rest, including a non-ASCII character to test #12114
12161
+ metadata['long_description'] = u'title\n=====\n\ntest \u00df'
12162
cmd = self._run(metadata, strict=1, restructuredtext=1)
12163
self.assertEqual(cmd._warnings, 0)
12165
diff -r 8527427914a2 Lib/distutils/tests/test_config_cmd.py
12166
--- a/Lib/distutils/tests/test_config_cmd.py
12167
+++ b/Lib/distutils/tests/test_config_cmd.py
12168
@@ -44,10 +44,10 @@
12171
# simple pattern searches
12172
- match = cmd.search_cpp(pattern='xxx', body='// xxx')
12173
+ match = cmd.search_cpp(pattern='xxx', body='/* xxx */')
12174
self.assertEqual(match, 0)
12176
- match = cmd.search_cpp(pattern='_configtest', body='// xxx')
12177
+ match = cmd.search_cpp(pattern='_configtest', body='/* xxx */')
12178
self.assertEqual(match, 1)
12180
def test_finalize_options(self):
12181
diff -r 8527427914a2 Lib/distutils/tests/test_dist.py
12182
--- a/Lib/distutils/tests/test_dist.py
12183
+++ b/Lib/distutils/tests/test_dist.py
12188
-from distutils.dist import Distribution, fix_help_options, DistributionMetadata
12189
+from distutils.dist import Distribution, fix_help_options
12190
from distutils.cmd import Command
12191
import distutils.dist
12192
from test.test_support import TESTFN, captured_stdout, run_unittest
12193
from distutils.tests import support
12196
class test_dist(Command):
12197
"""Sample distutils extension command."""
12201
def test_debug_mode(self):
12202
with open(TESTFN, "w") as f:
12203
- f.write("[global]")
12204
+ f.write("[global]\n")
12205
f.write("command_packages = foo.bar, splat")
12209
self.assertEqual(d.get_command_packages(),
12210
["distutils.command", "foo.bar", "distutils.tests"])
12211
cmd = d.get_command_obj("test_dist")
12212
- self.assertTrue(isinstance(cmd, test_dist))
12213
+ self.assertIsInstance(cmd, test_dist)
12214
self.assertEqual(cmd.sample_option, "sometext")
12216
def test_command_packages_configfile(self):
12217
@@ -105,8 +106,8 @@
12218
self.addCleanup(os.unlink, TESTFN)
12219
f = open(TESTFN, "w")
12221
- print >>f, "[global]"
12222
- print >>f, "command_packages = foo.bar, splat"
12223
+ print >> f, "[global]"
12224
+ print >> f, "command_packages = foo.bar, splat"
12228
@@ -138,7 +139,6 @@
12229
'description': u'Café torréfié',
12230
'long_description': u'Héhéhé'})
12233
# let's make sure the file can be written
12234
# with Unicode fields. they are encoded with
12235
# PKG_INFO_ENCODING
12236
@@ -152,33 +152,28 @@
12237
'long_description': 'Hehehe'})
12239
my_file2 = os.path.join(tmp_dir, 'f2')
12240
- dist.metadata.write_pkg_file(open(my_file, 'w'))
12241
+ dist.metadata.write_pkg_file(open(my_file2, 'w'))
12243
def test_empty_options(self):
12244
# an empty options dictionary should not stay in the
12245
# list of attributes
12246
- klass = Distribution
12248
# catching warnings
12254
- old_warn = warnings.warn
12255
+ self.addCleanup(setattr, warnings, 'warn', warnings.warn)
12256
warnings.warn = _warn
12258
- dist = klass(attrs={'author': 'xxx',
12260
- 'version': 'xxx',
12264
- warnings.warn = old_warn
12265
+ dist = Distribution(attrs={'author': 'xxx', 'name': 'xxx',
12266
+ 'version': 'xxx', 'url': 'xxxx',
12269
self.assertEqual(len(warns), 0)
12270
+ self.assertNotIn('options', dir(dist))
12272
def test_finalize_options(self):
12274
attrs = {'keywords': 'one,two',
12275
'platforms': 'one,two'}
12277
@@ -201,7 +196,6 @@
12278
cmds = dist.get_command_packages()
12279
self.assertEqual(cmds, ['distutils.command', 'one', 'two'])
12282
def test_announce(self):
12283
# make sure the level is known
12284
dist = Distribution()
12285
@@ -251,15 +245,44 @@
12286
sys.argv[:] = self.argv[1]
12287
super(MetadataTestCase, self).tearDown()
12289
+ def test_classifier(self):
12290
+ attrs = {'name': 'Boa', 'version': '3.0',
12291
+ 'classifiers': ['Programming Language :: Python :: 3']}
12292
+ dist = Distribution(attrs)
12293
+ meta = self.format_metadata(dist)
12294
+ self.assertIn('Metadata-Version: 1.1', meta)
12296
+ def test_download_url(self):
12297
+ attrs = {'name': 'Boa', 'version': '3.0',
12298
+ 'download_url': 'http://example.org/boa'}
12299
+ dist = Distribution(attrs)
12300
+ meta = self.format_metadata(dist)
12301
+ self.assertIn('Metadata-Version: 1.1', meta)
12303
+ def test_long_description(self):
12304
+ long_desc = textwrap.dedent("""\
12307
+ and continue here
12308
+ and end here.""")
12309
+ attrs = {"name": "package",
12310
+ "version": "1.0",
12311
+ "long_description": long_desc}
12313
+ dist = Distribution(attrs)
12314
+ meta = self.format_metadata(dist)
12315
+ meta = meta.replace('\n' + 8 * ' ', '\n')
12316
+ self.assertIn(long_desc, meta)
12318
def test_simple_metadata(self):
12319
attrs = {"name": "package",
12321
dist = Distribution(attrs)
12322
meta = self.format_metadata(dist)
12323
- self.assertTrue("Metadata-Version: 1.0" in meta)
12324
- self.assertTrue("provides:" not in meta.lower())
12325
- self.assertTrue("requires:" not in meta.lower())
12326
- self.assertTrue("obsoletes:" not in meta.lower())
12327
+ self.assertIn("Metadata-Version: 1.0", meta)
12328
+ self.assertNotIn("provides:", meta.lower())
12329
+ self.assertNotIn("requires:", meta.lower())
12330
+ self.assertNotIn("obsoletes:", meta.lower())
12332
def test_provides(self):
12333
attrs = {"name": "package",
12334
@@ -271,9 +294,9 @@
12335
self.assertEqual(dist.get_provides(),
12336
["package", "package.sub"])
12337
meta = self.format_metadata(dist)
12338
- self.assertTrue("Metadata-Version: 1.1" in meta)
12339
- self.assertTrue("requires:" not in meta.lower())
12340
- self.assertTrue("obsoletes:" not in meta.lower())
12341
+ self.assertIn("Metadata-Version: 1.1", meta)
12342
+ self.assertNotIn("requires:", meta.lower())
12343
+ self.assertNotIn("obsoletes:", meta.lower())
12345
def test_provides_illegal(self):
12346
self.assertRaises(ValueError, Distribution,
12347
@@ -291,11 +314,11 @@
12348
self.assertEqual(dist.get_requires(),
12349
["other", "another (==1.0)"])
12350
meta = self.format_metadata(dist)
12351
- self.assertTrue("Metadata-Version: 1.1" in meta)
12352
- self.assertTrue("provides:" not in meta.lower())
12353
- self.assertTrue("Requires: other" in meta)
12354
- self.assertTrue("Requires: another (==1.0)" in meta)
12355
- self.assertTrue("obsoletes:" not in meta.lower())
12356
+ self.assertIn("Metadata-Version: 1.1", meta)
12357
+ self.assertNotIn("provides:", meta.lower())
12358
+ self.assertIn("Requires: other", meta)
12359
+ self.assertIn("Requires: another (==1.0)", meta)
12360
+ self.assertNotIn("obsoletes:", meta.lower())
12362
def test_requires_illegal(self):
12363
self.assertRaises(ValueError, Distribution,
12364
@@ -313,11 +336,11 @@
12365
self.assertEqual(dist.get_obsoletes(),
12366
["other", "another (<1.0)"])
12367
meta = self.format_metadata(dist)
12368
- self.assertTrue("Metadata-Version: 1.1" in meta)
12369
- self.assertTrue("provides:" not in meta.lower())
12370
- self.assertTrue("requires:" not in meta.lower())
12371
- self.assertTrue("Obsoletes: other" in meta)
12372
- self.assertTrue("Obsoletes: another (<1.0)" in meta)
12373
+ self.assertIn("Metadata-Version: 1.1", meta)
12374
+ self.assertNotIn("provides:", meta.lower())
12375
+ self.assertNotIn("requires:", meta.lower())
12376
+ self.assertIn("Obsoletes: other", meta)
12377
+ self.assertIn("Obsoletes: another (<1.0)", meta)
12379
def test_obsoletes_illegal(self):
12380
self.assertRaises(ValueError, Distribution,
12381
@@ -353,14 +376,14 @@
12382
if sys.platform in ('linux', 'darwin'):
12383
os.environ['HOME'] = temp_dir
12384
files = dist.find_config_files()
12385
- self.assertTrue(user_filename in files)
12386
+ self.assertIn(user_filename, files)
12389
if sys.platform == 'win32':
12390
# home drive should be found
12391
os.environ['HOME'] = temp_dir
12392
files = dist.find_config_files()
12393
- self.assertTrue(user_filename in files,
12394
+ self.assertIn(user_filename, files,
12395
'%r not found in %r' % (user_filename, files))
12397
os.remove(user_filename)
12398
@@ -382,22 +405,7 @@
12400
output = [line for line in s.getvalue().split('\n')
12401
if line.strip() != '']
12402
- self.assertTrue(len(output) > 0)
12404
- def test_long_description(self):
12405
- long_desc = textwrap.dedent("""\
12408
- and continue here
12409
- and end here.""")
12410
- attrs = {"name": "package",
12411
- "version": "1.0",
12412
- "long_description": long_desc}
12414
- dist = distutils.dist.Distribution(attrs)
12415
- meta = self.format_metadata(dist)
12416
- meta = meta.replace('\n' + 8 * ' ', '\n')
12417
- self.assertTrue(long_desc in meta)
12418
+ self.assertTrue(output)
12420
def test_read_metadata(self):
12421
attrs = {"name": "package",
12422
@@ -426,6 +434,7 @@
12423
self.assertEqual(metadata.obsoletes, None)
12424
self.assertEqual(metadata.requires, ['foo'])
12428
suite = unittest.TestSuite()
12429
suite.addTest(unittest.makeSuite(DistributionTestCase))
12430
diff -r 8527427914a2 Lib/distutils/tests/test_filelist.py
12431
--- a/Lib/distutils/tests/test_filelist.py
12432
+++ b/Lib/distutils/tests/test_filelist.py
12434
"""Tests for distutils.filelist."""
12437
from os.path import join
12439
+from distutils import debug
12440
+from distutils.log import WARN
12441
+from distutils.errors import DistutilsTemplateError
12442
+from distutils.filelist import glob_to_re, translate_pattern, FileList
12444
from test.test_support import captured_stdout, run_unittest
12446
-from distutils.filelist import glob_to_re, FileList
12447
-from distutils import debug
12448
+from distutils.tests import support
12456
-class FileListTestCase(unittest.TestCase):
12458
+class FileListTestCase(support.LoggingSilencer,
12459
+ unittest.TestCase):
12461
+ def assertNoWarnings(self):
12462
+ self.assertEqual(self.get_logs(WARN), [])
12463
+ self.clear_logs()
12465
+ def assertWarnings(self):
12466
+ self.assertGreater(len(self.get_logs(WARN)), 0)
12467
+ self.clear_logs()
12469
def test_glob_to_re(self):
12472
join('dir', 'graft-one'),
12473
join('dir', 'dir2', 'graft2'),
12474
join('dir3', 'ok'),
12475
- join('dir3', 'sub', 'ok.txt')
12476
+ join('dir3', 'sub', 'ok.txt'),
12479
for line in MANIFEST_IN.split('\n'):
12480
@@ -66,18 +80,191 @@
12481
file_list = FileList()
12482
with captured_stdout() as stdout:
12483
file_list.debug_print('xxx')
12485
- self.assertEqual(stdout.read(), '')
12486
+ self.assertEqual(stdout.getvalue(), '')
12490
with captured_stdout() as stdout:
12491
file_list.debug_print('xxx')
12493
- self.assertEqual(stdout.read(), 'xxx\n')
12494
+ self.assertEqual(stdout.getvalue(), 'xxx\n')
12496
debug.DEBUG = False
12498
+ def test_set_allfiles(self):
12499
+ file_list = FileList()
12500
+ files = ['a', 'b', 'c']
12501
+ file_list.set_allfiles(files)
12502
+ self.assertEqual(file_list.allfiles, files)
12504
+ def test_remove_duplicates(self):
12505
+ file_list = FileList()
12506
+ file_list.files = ['a', 'b', 'a', 'g', 'c', 'g']
12507
+ # files must be sorted beforehand (sdist does it)
12509
+ file_list.remove_duplicates()
12510
+ self.assertEqual(file_list.files, ['a', 'b', 'c', 'g'])
12512
+ def test_translate_pattern(self):
12514
+ self.assertTrue(hasattr(
12515
+ translate_pattern('a', anchor=True, is_regex=False),
12519
+ regex = re.compile('a')
12520
+ self.assertEqual(
12521
+ translate_pattern(regex, anchor=True, is_regex=True),
12524
+ # plain string flagged as regex
12525
+ self.assertTrue(hasattr(
12526
+ translate_pattern('a', anchor=True, is_regex=True),
12530
+ self.assertTrue(translate_pattern(
12531
+ '*.py', anchor=True, is_regex=False).search('filelist.py'))
12533
+ def test_exclude_pattern(self):
12534
+ # return False if no match
12535
+ file_list = FileList()
12536
+ self.assertFalse(file_list.exclude_pattern('*.py'))
12538
+ # return True if files match
12539
+ file_list = FileList()
12540
+ file_list.files = ['a.py', 'b.py']
12541
+ self.assertTrue(file_list.exclude_pattern('*.py'))
12544
+ file_list = FileList()
12545
+ file_list.files = ['a.py', 'a.txt']
12546
+ file_list.exclude_pattern('*.py')
12547
+ self.assertEqual(file_list.files, ['a.txt'])
12549
+ def test_include_pattern(self):
12550
+ # return False if no match
12551
+ file_list = FileList()
12552
+ file_list.set_allfiles([])
12553
+ self.assertFalse(file_list.include_pattern('*.py'))
12555
+ # return True if files match
12556
+ file_list = FileList()
12557
+ file_list.set_allfiles(['a.py', 'b.txt'])
12558
+ self.assertTrue(file_list.include_pattern('*.py'))
12560
+ # test * matches all files
12561
+ file_list = FileList()
12562
+ self.assertIsNone(file_list.allfiles)
12563
+ file_list.set_allfiles(['a.py', 'b.txt'])
12564
+ file_list.include_pattern('*')
12565
+ self.assertEqual(file_list.allfiles, ['a.py', 'b.txt'])
12567
+ def test_process_template(self):
12569
+ file_list = FileList()
12570
+ for action in ('include', 'exclude', 'global-include',
12571
+ 'global-exclude', 'recursive-include',
12572
+ 'recursive-exclude', 'graft', 'prune', 'blarg'):
12573
+ self.assertRaises(DistutilsTemplateError,
12574
+ file_list.process_template_line, action)
12577
+ file_list = FileList()
12578
+ file_list.set_allfiles(['a.py', 'b.txt', 'd/c.py'])
12580
+ file_list.process_template_line('include *.py')
12581
+ self.assertEqual(file_list.files, ['a.py'])
12582
+ self.assertNoWarnings()
12584
+ file_list.process_template_line('include *.rb')
12585
+ self.assertEqual(file_list.files, ['a.py'])
12586
+ self.assertWarnings()
12589
+ file_list = FileList()
12590
+ file_list.files = ['a.py', 'b.txt', 'd/c.py']
12592
+ file_list.process_template_line('exclude *.py')
12593
+ self.assertEqual(file_list.files, ['b.txt', 'd/c.py'])
12594
+ self.assertNoWarnings()
12596
+ file_list.process_template_line('exclude *.rb')
12597
+ self.assertEqual(file_list.files, ['b.txt', 'd/c.py'])
12598
+ self.assertWarnings()
12601
+ file_list = FileList()
12602
+ file_list.set_allfiles(['a.py', 'b.txt', 'd/c.py'])
12604
+ file_list.process_template_line('global-include *.py')
12605
+ self.assertEqual(file_list.files, ['a.py', 'd/c.py'])
12606
+ self.assertNoWarnings()
12608
+ file_list.process_template_line('global-include *.rb')
12609
+ self.assertEqual(file_list.files, ['a.py', 'd/c.py'])
12610
+ self.assertWarnings()
12613
+ file_list = FileList()
12614
+ file_list.files = ['a.py', 'b.txt', 'd/c.py']
12616
+ file_list.process_template_line('global-exclude *.py')
12617
+ self.assertEqual(file_list.files, ['b.txt'])
12618
+ self.assertNoWarnings()
12620
+ file_list.process_template_line('global-exclude *.rb')
12621
+ self.assertEqual(file_list.files, ['b.txt'])
12622
+ self.assertWarnings()
12624
+ # recursive-include
12625
+ file_list = FileList()
12626
+ file_list.set_allfiles(['a.py', 'd/b.py', 'd/c.txt', 'd/d/e.py'])
12628
+ file_list.process_template_line('recursive-include d *.py')
12629
+ self.assertEqual(file_list.files, ['d/b.py', 'd/d/e.py'])
12630
+ self.assertNoWarnings()
12632
+ file_list.process_template_line('recursive-include e *.py')
12633
+ self.assertEqual(file_list.files, ['d/b.py', 'd/d/e.py'])
12634
+ self.assertWarnings()
12636
+ # recursive-exclude
12637
+ file_list = FileList()
12638
+ file_list.files = ['a.py', 'd/b.py', 'd/c.txt', 'd/d/e.py']
12640
+ file_list.process_template_line('recursive-exclude d *.py')
12641
+ self.assertEqual(file_list.files, ['a.py', 'd/c.txt'])
12642
+ self.assertNoWarnings()
12644
+ file_list.process_template_line('recursive-exclude e *.py')
12645
+ self.assertEqual(file_list.files, ['a.py', 'd/c.txt'])
12646
+ self.assertWarnings()
12649
+ file_list = FileList()
12650
+ file_list.set_allfiles(['a.py', 'd/b.py', 'd/d/e.py', 'f/f.py'])
12652
+ file_list.process_template_line('graft d')
12653
+ self.assertEqual(file_list.files, ['d/b.py', 'd/d/e.py'])
12654
+ self.assertNoWarnings()
12656
+ file_list.process_template_line('graft e')
12657
+ self.assertEqual(file_list.files, ['d/b.py', 'd/d/e.py'])
12658
+ self.assertWarnings()
12661
+ file_list = FileList()
12662
+ file_list.files = ['a.py', 'd/b.py', 'd/d/e.py', 'f/f.py']
12664
+ file_list.process_template_line('prune d')
12665
+ self.assertEqual(file_list.files, ['a.py', 'f/f.py'])
12666
+ self.assertNoWarnings()
12668
+ file_list.process_template_line('prune e')
12669
+ self.assertEqual(file_list.files, ['a.py', 'f/f.py'])
12670
+ self.assertWarnings()
12674
return unittest.makeSuite(FileListTestCase)
12676
diff -r 8527427914a2 Lib/distutils/tests/test_install.py
12677
--- a/Lib/distutils/tests/test_install.py
12678
+++ b/Lib/distutils/tests/test_install.py
12680
"""Tests for distutils.command.install."""
12687
-from test.test_support import run_unittest
12688
+from test.test_support import captured_stdout, run_unittest
12690
+from distutils import sysconfig
12691
from distutils.command.install import install
12692
+from distutils.command import install as install_module
12693
+from distutils.command.build_ext import build_ext
12694
+from distutils.command.install import INSTALL_SCHEMES
12695
from distutils.core import Distribution
12696
+from distutils.errors import DistutilsOptionError
12697
+from distutils.extension import Extension
12699
from distutils.tests import support
12702
-class InstallTestCase(support.TempdirManager, unittest.TestCase):
12703
+def _make_ext_name(modname):
12704
+ if os.name == 'nt' and sys.executable.endswith('_d.exe'):
12706
+ return modname + sysconfig.get_config_var('SO')
12709
+class InstallTestCase(support.TempdirManager,
12710
+ support.LoggingSilencer,
12711
+ unittest.TestCase):
12713
def test_home_installation_scheme(self):
12714
# This ensure two things:
12715
@@ -49,6 +65,181 @@
12716
check_path(cmd.install_scripts, os.path.join(destination, "bin"))
12717
check_path(cmd.install_data, destination)
12719
+ def test_user_site(self):
12720
+ # site.USER_SITE was introduced in 2.6
12721
+ if sys.version < '2.6':
12724
+ # preparing the environment for the test
12725
+ self.old_user_base = site.USER_BASE
12726
+ self.old_user_site = site.USER_SITE
12727
+ self.tmpdir = self.mkdtemp()
12728
+ self.user_base = os.path.join(self.tmpdir, 'B')
12729
+ self.user_site = os.path.join(self.tmpdir, 'S')
12730
+ site.USER_BASE = self.user_base
12731
+ site.USER_SITE = self.user_site
12732
+ install_module.USER_BASE = self.user_base
12733
+ install_module.USER_SITE = self.user_site
12735
+ def _expanduser(path):
12736
+ return self.tmpdir
12737
+ self.old_expand = os.path.expanduser
12738
+ os.path.expanduser = _expanduser
12741
+ # this is the actual test
12742
+ self._test_user_site()
12744
+ site.USER_BASE = self.old_user_base
12745
+ site.USER_SITE = self.old_user_site
12746
+ install_module.USER_BASE = self.old_user_base
12747
+ install_module.USER_SITE = self.old_user_site
12748
+ os.path.expanduser = self.old_expand
12750
+ def _test_user_site(self):
12751
+ for key in ('nt_user', 'unix_user', 'os2_home'):
12752
+ self.assertTrue(key in INSTALL_SCHEMES)
12754
+ dist = Distribution({'name': 'xx'})
12755
+ cmd = install(dist)
12757
+ # making sure the user option is there
12758
+ options = [name for name, short, lable in
12759
+ cmd.user_options]
12760
+ self.assertTrue('user' in options)
12762
+ # setting a value
12765
+ # user base and site shouldn't be created yet
12766
+ self.assertTrue(not os.path.exists(self.user_base))
12767
+ self.assertTrue(not os.path.exists(self.user_site))
12769
+ # let's run finalize
12770
+ cmd.ensure_finalized()
12772
+ # now they should
12773
+ self.assertTrue(os.path.exists(self.user_base))
12774
+ self.assertTrue(os.path.exists(self.user_site))
12776
+ self.assertTrue('userbase' in cmd.config_vars)
12777
+ self.assertTrue('usersite' in cmd.config_vars)
12779
+ def test_handle_extra_path(self):
12780
+ dist = Distribution({'name': 'xx', 'extra_path': 'path,dirs'})
12781
+ cmd = install(dist)
12784
+ cmd.handle_extra_path()
12785
+ self.assertEqual(cmd.extra_path, ['path', 'dirs'])
12786
+ self.assertEqual(cmd.extra_dirs, 'dirs')
12787
+ self.assertEqual(cmd.path_file, 'path')
12790
+ cmd.extra_path = ['path']
12791
+ cmd.handle_extra_path()
12792
+ self.assertEqual(cmd.extra_path, ['path'])
12793
+ self.assertEqual(cmd.extra_dirs, 'path')
12794
+ self.assertEqual(cmd.path_file, 'path')
12797
+ dist.extra_path = cmd.extra_path = None
12798
+ cmd.handle_extra_path()
12799
+ self.assertEqual(cmd.extra_path, None)
12800
+ self.assertEqual(cmd.extra_dirs, '')
12801
+ self.assertEqual(cmd.path_file, None)
12803
+ # three elements (no way !)
12804
+ cmd.extra_path = 'path,dirs,again'
12805
+ self.assertRaises(DistutilsOptionError, cmd.handle_extra_path)
12807
+ def test_finalize_options(self):
12808
+ dist = Distribution({'name': 'xx'})
12809
+ cmd = install(dist)
12811
+ # must supply either prefix/exec-prefix/home or
12812
+ # install-base/install-platbase -- not both
12813
+ cmd.prefix = 'prefix'
12814
+ cmd.install_base = 'base'
12815
+ self.assertRaises(DistutilsOptionError, cmd.finalize_options)
12817
+ # must supply either home or prefix/exec-prefix -- not both
12818
+ cmd.install_base = None
12819
+ cmd.home = 'home'
12820
+ self.assertRaises(DistutilsOptionError, cmd.finalize_options)
12822
+ # can't combine user with with prefix/exec_prefix/home or
12823
+ # install_(plat)base
12824
+ cmd.prefix = None
12825
+ cmd.user = 'user'
12826
+ self.assertRaises(DistutilsOptionError, cmd.finalize_options)
12828
+ def test_record(self):
12829
+ install_dir = self.mkdtemp()
12830
+ project_dir, dist = self.create_dist(scripts=['hello'])
12831
+ self.addCleanup(os.chdir, os.getcwd())
12832
+ os.chdir(project_dir)
12833
+ self.write_file('hello', "print('o hai')")
12835
+ cmd = install(dist)
12836
+ dist.command_obj['install'] = cmd
12837
+ cmd.root = install_dir
12838
+ cmd.record = os.path.join(project_dir, 'RECORD')
12839
+ cmd.ensure_finalized()
12842
+ f = open(cmd.record)
12844
+ content = f.read()
12848
+ found = [os.path.basename(line) for line in content.splitlines()]
12849
+ expected = ['hello',
12850
+ 'UNKNOWN-0.0.0-py%s.%s.egg-info' % sys.version_info[:2]]
12851
+ self.assertEqual(found, expected)
12853
+ def test_record_extensions(self):
12854
+ install_dir = self.mkdtemp()
12855
+ project_dir, dist = self.create_dist(ext_modules=[
12856
+ Extension('xx', ['xxmodule.c'])])
12857
+ self.addCleanup(os.chdir, os.getcwd())
12858
+ os.chdir(project_dir)
12859
+ support.copy_xxmodule_c(project_dir)
12861
+ buildextcmd = build_ext(dist)
12862
+ support.fixup_build_ext(buildextcmd)
12863
+ buildextcmd.ensure_finalized()
12865
+ cmd = install(dist)
12866
+ dist.command_obj['install'] = cmd
12867
+ dist.command_obj['build_ext'] = buildextcmd
12868
+ cmd.root = install_dir
12869
+ cmd.record = os.path.join(project_dir, 'RECORD')
12870
+ cmd.ensure_finalized()
12873
+ f = open(cmd.record)
12875
+ content = f.read()
12879
+ found = [os.path.basename(line) for line in content.splitlines()]
12880
+ expected = [_make_ext_name('xx'),
12881
+ 'UNKNOWN-0.0.0-py%s.%s.egg-info' % sys.version_info[:2]]
12882
+ self.assertEqual(found, expected)
12884
+ def test_debug_mode(self):
12885
+ # this covers the code called when DEBUG is set
12886
+ old_logs_len = len(self.logs)
12887
+ install_module.DEBUG = True
12889
+ with captured_stdout():
12890
+ self.test_record()
12892
+ install_module.DEBUG = False
12893
+ self.assertTrue(len(self.logs) > old_logs_len)
12896
return unittest.makeSuite(InstallTestCase)
12897
diff -r 8527427914a2 Lib/distutils/tests/test_msvc9compiler.py
12898
--- a/Lib/distutils/tests/test_msvc9compiler.py
12899
+++ b/Lib/distutils/tests/test_msvc9compiler.py
12901
from distutils.tests import support
12902
from test.test_support import run_unittest
12905
+# A manifest with the only assembly reference being the msvcrt assembly, so
12906
+# should have the assembly completely stripped. Note that although the
12907
+# assembly has a <security> reference the assembly is removed - that is
12908
+# currently a "feature", not a bug :)
12909
+_MANIFEST_WITH_ONLY_MSVC_REFERENCE = """\
12910
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
12911
+<assembly xmlns="urn:schemas-microsoft-com:asm.v1"
12912
+ manifestVersion="1.0">
12913
+ <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
12915
+ <requestedPrivileges>
12916
+ <requestedExecutionLevel level="asInvoker" uiAccess="false">
12917
+ </requestedExecutionLevel>
12918
+ </requestedPrivileges>
12922
+ <dependentAssembly>
12923
+ <assemblyIdentity type="win32" name="Microsoft.VC90.CRT"
12924
+ version="9.0.21022.8" processorArchitecture="x86"
12925
+ publicKeyToken="XXXX">
12926
+ </assemblyIdentity>
12927
+ </dependentAssembly>
12932
+# A manifest with references to assemblies other than msvcrt. When processed,
12933
+# this assembly should be returned with just the msvcrt part removed.
12934
+_MANIFEST_WITH_MULTIPLE_REFERENCES = """\
12935
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
12936
<assembly xmlns="urn:schemas-microsoft-com:asm.v1"
12937
manifestVersion="1.0">
12938
@@ -115,7 +144,7 @@
12939
manifest = os.path.join(tempdir, 'manifest')
12940
f = open(manifest, 'w')
12942
- f.write(_MANIFEST)
12943
+ f.write(_MANIFEST_WITH_MULTIPLE_REFERENCES)
12947
@@ -133,6 +162,20 @@
12948
# makes sure the manifest was properly cleaned
12949
self.assertEqual(content, _CLEANED_MANIFEST)
12951
+ def test_remove_entire_manifest(self):
12952
+ from distutils.msvc9compiler import MSVCCompiler
12953
+ tempdir = self.mkdtemp()
12954
+ manifest = os.path.join(tempdir, 'manifest')
12955
+ f = open(manifest, 'w')
12957
+ f.write(_MANIFEST_WITH_ONLY_MSVC_REFERENCE)
12961
+ compiler = MSVCCompiler()
12962
+ got = compiler._remove_visual_c_ref(manifest)
12963
+ self.assertIs(got, None)
12967
return unittest.makeSuite(msvc9compilerTestCase)
12968
diff -r 8527427914a2 Lib/distutils/tests/test_register.py
12969
--- a/Lib/distutils/tests/test_register.py
12970
+++ b/Lib/distutils/tests/test_register.py
12972
+# -*- encoding: utf8 -*-
12973
"""Tests for distutils.command.register."""
12974
-# -*- encoding: utf8 -*-
12978
@@ -246,6 +246,24 @@
12980
del register_module.raw_input
12982
+ # and finally a Unicode test (bug #12114)
12983
+ metadata = {'url': u'xxx', 'author': u'\u00c9ric',
12984
+ 'author_email': u'xxx', u'name': 'xxx',
12985
+ 'version': u'xxx',
12986
+ 'description': u'Something about esszet \u00df',
12987
+ 'long_description': u'More things about esszet \u00df'}
12989
+ cmd = self._get_cmd(metadata)
12990
+ cmd.ensure_finalized()
12992
+ inputs = RawInputs('1', 'tarek', 'y')
12993
+ register_module.raw_input = inputs.__call__
12994
+ # let's run the command
12998
+ del register_module.raw_input
13000
def test_check_metadata_deprecated(self):
13001
# makes sure make_metadata is deprecated
13002
cmd = self._get_cmd()
4050
13003
diff -r 8527427914a2 Lib/distutils/tests/test_sdist.py
4051
13004
--- a/Lib/distutils/tests/test_sdist.py
4052
13005
+++ b/Lib/distutils/tests/test_sdist.py
4694
14015
from types import *
4695
14016
from copy_reg import dispatch_table
4696
diff -r 8527427914a2 Lib/plat-linux3/CDROM.py
4698
+++ b/Lib/plat-linux3/CDROM.py
4700
+# Generated by h2py from /usr/include/linux/cdrom.h
4702
+CDROMPAUSE = 0x5301
4703
+CDROMRESUME = 0x5302
4704
+CDROMPLAYMSF = 0x5303
4705
+CDROMPLAYTRKIND = 0x5304
4706
+CDROMREADTOCHDR = 0x5305
4707
+CDROMREADTOCENTRY = 0x5306
4709
+CDROMSTART = 0x5308
4710
+CDROMEJECT = 0x5309
4711
+CDROMVOLCTRL = 0x530a
4712
+CDROMSUBCHNL = 0x530b
4713
+CDROMREADMODE2 = 0x530c
4714
+CDROMREADMODE1 = 0x530d
4715
+CDROMREADAUDIO = 0x530e
4716
+CDROMEJECT_SW = 0x530f
4717
+CDROMMULTISESSION = 0x5310
4718
+CDROM_GET_MCN = 0x5311
4719
+CDROM_GET_UPC = CDROM_GET_MCN
4720
+CDROMRESET = 0x5312
4721
+CDROMVOLREAD = 0x5313
4722
+CDROMREADRAW = 0x5314
4723
+CDROMREADCOOKED = 0x5315
4725
+CDROMPLAYBLK = 0x5317
4726
+CDROMREADALL = 0x5318
4727
+CDROMGETSPINDOWN = 0x531d
4728
+CDROMSETSPINDOWN = 0x531e
4729
+CDROMCLOSETRAY = 0x5319
4730
+CDROM_SET_OPTIONS = 0x5320
4731
+CDROM_CLEAR_OPTIONS = 0x5321
4732
+CDROM_SELECT_SPEED = 0x5322
4733
+CDROM_SELECT_DISC = 0x5323
4734
+CDROM_MEDIA_CHANGED = 0x5325
4735
+CDROM_DRIVE_STATUS = 0x5326
4736
+CDROM_DISC_STATUS = 0x5327
4737
+CDROM_CHANGER_NSLOTS = 0x5328
4738
+CDROM_LOCKDOOR = 0x5329
4739
+CDROM_DEBUG = 0x5330
4740
+CDROM_GET_CAPABILITY = 0x5331
4741
+CDROMAUDIOBUFSIZ = 0x5382
4742
+DVD_READ_STRUCT = 0x5390
4743
+DVD_WRITE_STRUCT = 0x5391
4745
+CDROM_SEND_PACKET = 0x5393
4746
+CDROM_NEXT_WRITABLE = 0x5394
4747
+CDROM_LAST_WRITTEN = 0x5395
4748
+CDROM_PACKET_SIZE = 12
4749
+CGC_DATA_UNKNOWN = 0
4757
+CD_MSF_OFFSET = 150
4759
+CD_NUM_OF_CHUNKS = 98
4760
+CD_FRAMESIZE_SUB = 96
4762
+CD_SUBHEAD_SIZE = 8
4766
+CD_FRAMESIZE = 2048
4767
+CD_FRAMESIZE_RAW = 2352
4768
+CD_FRAMESIZE_RAWER = 2646
4769
+CD_FRAMESIZE_RAW1 = (CD_FRAMESIZE_RAW-CD_SYNC_SIZE)
4770
+CD_FRAMESIZE_RAW0 = (CD_FRAMESIZE_RAW-CD_SYNC_SIZE-CD_HEAD_SIZE)
4771
+CD_XA_HEAD = (CD_HEAD_SIZE+CD_SUBHEAD_SIZE)
4772
+CD_XA_TAIL = (CD_EDC_SIZE+CD_ECC_SIZE)
4773
+CD_XA_SYNC_HEAD = (CD_SYNC_SIZE+CD_XA_HEAD)
4776
+CDROM_DATA_TRACK = 0x04
4777
+CDROM_LEADOUT = 0xAA
4778
+CDROM_AUDIO_INVALID = 0x00
4779
+CDROM_AUDIO_PLAY = 0x11
4780
+CDROM_AUDIO_PAUSED = 0x12
4781
+CDROM_AUDIO_COMPLETED = 0x13
4782
+CDROM_AUDIO_ERROR = 0x14
4783
+CDROM_AUDIO_NO_STATUS = 0x15
4784
+CDC_CLOSE_TRAY = 0x1
4785
+CDC_OPEN_TRAY = 0x2
4787
+CDC_SELECT_SPEED = 0x8
4788
+CDC_SELECT_DISC = 0x10
4789
+CDC_MULTI_SESSION = 0x20
4791
+CDC_MEDIA_CHANGED = 0x80
4792
+CDC_PLAY_AUDIO = 0x100
4795
+CDC_DRIVE_STATUS = 0x800
4796
+CDC_GENERIC_PACKET = 0x1000
4800
+CDC_DVD_R = 0x10000
4801
+CDC_DVD_RAM = 0x20000
4805
+CDS_DRIVE_NOT_READY = 3
4813
+CDO_AUTO_CLOSE = 0x1
4814
+CDO_AUTO_EJECT = 0x2
4815
+CDO_USE_FFLAGS = 0x4
4817
+CDO_CHECK_TYPE = 0x10
4819
+CD_PART_MASK = (CD_PART_MAX - 1)
4821
+GPCMD_CLOSE_TRACK = 0x5b
4822
+GPCMD_FLUSH_CACHE = 0x35
4823
+GPCMD_FORMAT_UNIT = 0x04
4824
+GPCMD_GET_CONFIGURATION = 0x46
4825
+GPCMD_GET_EVENT_STATUS_NOTIFICATION = 0x4a
4826
+GPCMD_GET_PERFORMANCE = 0xac
4827
+GPCMD_INQUIRY = 0x12
4828
+GPCMD_LOAD_UNLOAD = 0xa6
4829
+GPCMD_MECHANISM_STATUS = 0xbd
4830
+GPCMD_MODE_SELECT_10 = 0x55
4831
+GPCMD_MODE_SENSE_10 = 0x5a
4832
+GPCMD_PAUSE_RESUME = 0x4b
4833
+GPCMD_PLAY_AUDIO_10 = 0x45
4834
+GPCMD_PLAY_AUDIO_MSF = 0x47
4835
+GPCMD_PLAY_AUDIO_TI = 0x48
4836
+GPCMD_PLAY_CD = 0xbc
4837
+GPCMD_PREVENT_ALLOW_MEDIUM_REMOVAL = 0x1e
4838
+GPCMD_READ_10 = 0x28
4839
+GPCMD_READ_12 = 0xa8
4840
+GPCMD_READ_CDVD_CAPACITY = 0x25
4841
+GPCMD_READ_CD = 0xbe
4842
+GPCMD_READ_CD_MSF = 0xb9
4843
+GPCMD_READ_DISC_INFO = 0x51
4844
+GPCMD_READ_DVD_STRUCTURE = 0xad
4845
+GPCMD_READ_FORMAT_CAPACITIES = 0x23
4846
+GPCMD_READ_HEADER = 0x44
4847
+GPCMD_READ_TRACK_RZONE_INFO = 0x52
4848
+GPCMD_READ_SUBCHANNEL = 0x42
4849
+GPCMD_READ_TOC_PMA_ATIP = 0x43
4850
+GPCMD_REPAIR_RZONE_TRACK = 0x58
4851
+GPCMD_REPORT_KEY = 0xa4
4852
+GPCMD_REQUEST_SENSE = 0x03
4853
+GPCMD_RESERVE_RZONE_TRACK = 0x53
4856
+GPCMD_SEND_DVD_STRUCTURE = 0xad
4857
+GPCMD_SEND_EVENT = 0xa2
4858
+GPCMD_SEND_KEY = 0xa3
4859
+GPCMD_SEND_OPC = 0x54
4860
+GPCMD_SET_READ_AHEAD = 0xa7
4861
+GPCMD_SET_STREAMING = 0xb6
4862
+GPCMD_START_STOP_UNIT = 0x1b
4863
+GPCMD_STOP_PLAY_SCAN = 0x4e
4864
+GPCMD_TEST_UNIT_READY = 0x00
4865
+GPCMD_VERIFY_10 = 0x2f
4866
+GPCMD_WRITE_10 = 0x2a
4867
+GPCMD_WRITE_AND_VERIFY_10 = 0x2e
4868
+GPCMD_SET_SPEED = 0xbb
4869
+GPCMD_PLAYAUDIO_TI = 0x48
4870
+GPCMD_GET_MEDIA_STATUS = 0xda
4871
+GPMODE_R_W_ERROR_PAGE = 0x01
4872
+GPMODE_WRITE_PARMS_PAGE = 0x05
4873
+GPMODE_AUDIO_CTL_PAGE = 0x0e
4874
+GPMODE_POWER_PAGE = 0x1a
4875
+GPMODE_FAULT_FAIL_PAGE = 0x1c
4876
+GPMODE_TO_PROTECT_PAGE = 0x1d
4877
+GPMODE_CAPABILITIES_PAGE = 0x2a
4878
+GPMODE_ALL_PAGES = 0x3f
4879
+GPMODE_CDROM_PAGE = 0x0d
4880
+DVD_STRUCT_PHYSICAL = 0x00
4881
+DVD_STRUCT_COPYRIGHT = 0x01
4882
+DVD_STRUCT_DISCKEY = 0x02
4883
+DVD_STRUCT_BCA = 0x03
4884
+DVD_STRUCT_MANUFACT = 0x04
4886
+DVD_LU_SEND_AGID = 0
4887
+DVD_HOST_SEND_CHALLENGE = 1
4888
+DVD_LU_SEND_KEY1 = 2
4889
+DVD_LU_SEND_CHALLENGE = 3
4890
+DVD_HOST_SEND_KEY2 = 4
4891
+DVD_AUTH_ESTABLISHED = 5
4892
+DVD_AUTH_FAILURE = 6
4893
+DVD_LU_SEND_TITLE_KEY = 7
4894
+DVD_LU_SEND_ASF = 8
4895
+DVD_INVALIDATE_AGID = 9
4896
+DVD_LU_SEND_RPC_STATE = 10
4897
+DVD_HOST_SEND_RPC_STATE = 11
4898
+DVD_CPM_NO_COPYRIGHT = 0
4899
+DVD_CPM_COPYRIGHTED = 1
4900
+DVD_CP_SEC_NONE = 0
4901
+DVD_CP_SEC_EXIST = 1
4902
+DVD_CGMS_UNRESTRICTED = 0
4903
+DVD_CGMS_SINGLE = 2
4904
+DVD_CGMS_RESTRICTED = 3
4906
+CDROM_MAX_SLOTS = 256
4907
diff -r 8527427914a2 Lib/plat-linux3/DLFCN.py
4909
+++ b/Lib/plat-linux3/DLFCN.py
4911
+# Generated by h2py from /usr/include/dlfcn.h
4914
+# Included from features.h
4920
+_POSIX_C_SOURCE = 199506L
4921
+_XOPEN_SOURCE = 600
4922
+_XOPEN_SOURCE_EXTENDED = 1
4923
+_LARGEFILE64_SOURCE = 1
4930
+_POSIX_C_SOURCE = 2
4931
+_POSIX_C_SOURCE = 199506L
4934
+__USE_POSIX199309 = 1
4935
+__USE_POSIX199506 = 1
4937
+__USE_XOPEN_EXTENDED = 1
4939
+_LARGEFILE_SOURCE = 1
4942
+__USE_XOPEN_EXTENDED = 1
4943
+__USE_LARGEFILE = 1
4944
+__USE_LARGEFILE64 = 1
4945
+__USE_FILE_OFFSET64 = 1
4950
+__USE_REENTRANT = 1
4951
+__STDC_IEC_559__ = 1
4952
+__STDC_IEC_559_COMPLEX__ = 1
4953
+__STDC_ISO_10646__ = 200009L
4954
+__GNU_LIBRARY__ = 6
4956
+__GLIBC_MINOR__ = 2
4958
+# Included from sys/cdefs.h
4960
+def __PMT(args): return args
4962
+def __P(args): return args
4964
+def __PMT(args): return args
4966
+def __STRING(x): return #x
4972
+def __ASMNAME(cname): return __ASMNAME2 (__USER_LABEL_PREFIX__, cname)
4974
+def __attribute__(xyz): return
4976
+def __attribute_format_arg__(x): return __attribute__ ((__format_arg__ (x)))
4978
+def __attribute_format_arg__(x): return
4980
+__USE_LARGEFILE = 1
4981
+__USE_LARGEFILE64 = 1
4982
+__USE_EXTERN_INLINES = 1
4984
+# Included from gnu/stubs.h
4986
+# Included from bits/dlfcn.h
4987
+RTLD_LAZY = 0x00001
4989
+RTLD_BINDING_MASK = 0x3
4990
+RTLD_NOLOAD = 0x00004
4991
+RTLD_GLOBAL = 0x00100
4993
+RTLD_NODELETE = 0x01000
4994
diff -r 8527427914a2 Lib/plat-linux3/IN.py
4996
+++ b/Lib/plat-linux3/IN.py
4998
+# Generated by h2py from /usr/include/netinet/in.h
5001
+# Included from features.h
5007
+_POSIX_C_SOURCE = 199506L
5008
+_XOPEN_SOURCE = 600
5009
+_XOPEN_SOURCE_EXTENDED = 1
5010
+_LARGEFILE64_SOURCE = 1
5017
+_POSIX_C_SOURCE = 2
5018
+_POSIX_C_SOURCE = 199506L
5021
+__USE_POSIX199309 = 1
5022
+__USE_POSIX199506 = 1
5024
+__USE_XOPEN_EXTENDED = 1
5026
+_LARGEFILE_SOURCE = 1
5029
+__USE_XOPEN_EXTENDED = 1
5030
+__USE_LARGEFILE = 1
5031
+__USE_LARGEFILE64 = 1
5032
+__USE_FILE_OFFSET64 = 1
5037
+__USE_REENTRANT = 1
5038
+__STDC_IEC_559__ = 1
5039
+__STDC_IEC_559_COMPLEX__ = 1
5040
+__STDC_ISO_10646__ = 200009L
5041
+__GNU_LIBRARY__ = 6
5043
+__GLIBC_MINOR__ = 2
5045
+# Included from sys/cdefs.h
5047
+def __PMT(args): return args
5049
+def __P(args): return args
5051
+def __PMT(args): return args
5053
+def __STRING(x): return #x
5059
+def __ASMNAME(cname): return __ASMNAME2 (__USER_LABEL_PREFIX__, cname)
5061
+def __attribute__(xyz): return
5063
+def __attribute_format_arg__(x): return __attribute__ ((__format_arg__ (x)))
5065
+def __attribute_format_arg__(x): return
5067
+__USE_LARGEFILE = 1
5068
+__USE_LARGEFILE64 = 1
5069
+__USE_EXTERN_INLINES = 1
5071
+# Included from gnu/stubs.h
5073
+# Included from stdint.h
5076
+# Included from bits/wchar.h
5078
+__WCHAR_MIN = (-2147483647l - 1l)
5079
+__WCHAR_MAX = (2147483647l)
5081
+# Included from bits/wordsize.h
5083
+def __INT64_C(c): return c ## L
5085
+def __UINT64_C(c): return c ## UL
5087
+def __INT64_C(c): return c ## LL
5089
+def __UINT64_C(c): return c ## ULL
5092
+INT16_MIN = (-32767-1)
5093
+INT32_MIN = (-2147483647-1)
5094
+INT64_MIN = (-__INT64_C(9223372036854775807)-1)
5096
+INT16_MAX = (32767)
5097
+INT32_MAX = (2147483647)
5098
+INT64_MAX = (__INT64_C(9223372036854775807))
5100
+UINT16_MAX = (65535)
5101
+UINT64_MAX = (__UINT64_C(18446744073709551615))
5102
+INT_LEAST8_MIN = (-128)
5103
+INT_LEAST16_MIN = (-32767-1)
5104
+INT_LEAST32_MIN = (-2147483647-1)
5105
+INT_LEAST64_MIN = (-__INT64_C(9223372036854775807)-1)
5106
+INT_LEAST8_MAX = (127)
5107
+INT_LEAST16_MAX = (32767)
5108
+INT_LEAST32_MAX = (2147483647)
5109
+INT_LEAST64_MAX = (__INT64_C(9223372036854775807))
5110
+UINT_LEAST8_MAX = (255)
5111
+UINT_LEAST16_MAX = (65535)
5112
+UINT_LEAST64_MAX = (__UINT64_C(18446744073709551615))
5113
+INT_FAST8_MIN = (-128)
5114
+INT_FAST16_MIN = (-9223372036854775807L-1)
5115
+INT_FAST32_MIN = (-9223372036854775807L-1)
5116
+INT_FAST16_MIN = (-2147483647-1)
5117
+INT_FAST32_MIN = (-2147483647-1)
5118
+INT_FAST64_MIN = (-__INT64_C(9223372036854775807)-1)
5119
+INT_FAST8_MAX = (127)
5120
+INT_FAST16_MAX = (9223372036854775807L)
5121
+INT_FAST32_MAX = (9223372036854775807L)
5122
+INT_FAST16_MAX = (2147483647)
5123
+INT_FAST32_MAX = (2147483647)
5124
+INT_FAST64_MAX = (__INT64_C(9223372036854775807))
5125
+UINT_FAST8_MAX = (255)
5126
+UINT_FAST64_MAX = (__UINT64_C(18446744073709551615))
5127
+INTPTR_MIN = (-9223372036854775807L-1)
5128
+INTPTR_MAX = (9223372036854775807L)
5129
+INTPTR_MIN = (-2147483647-1)
5130
+INTPTR_MAX = (2147483647)
5131
+INTMAX_MIN = (-__INT64_C(9223372036854775807)-1)
5132
+INTMAX_MAX = (__INT64_C(9223372036854775807))
5133
+UINTMAX_MAX = (__UINT64_C(18446744073709551615))
5134
+PTRDIFF_MIN = (-9223372036854775807L-1)
5135
+PTRDIFF_MAX = (9223372036854775807L)
5136
+PTRDIFF_MIN = (-2147483647-1)
5137
+PTRDIFF_MAX = (2147483647)
5138
+SIG_ATOMIC_MIN = (-2147483647-1)
5139
+SIG_ATOMIC_MAX = (2147483647)
5140
+WCHAR_MIN = __WCHAR_MIN
5141
+WCHAR_MAX = __WCHAR_MAX
5142
+def INT8_C(c): return c
5144
+def INT16_C(c): return c
5146
+def INT32_C(c): return c
5148
+def INT64_C(c): return c ## L
5150
+def INT64_C(c): return c ## LL
5152
+def UINT8_C(c): return c ## U
5154
+def UINT16_C(c): return c ## U
5156
+def UINT32_C(c): return c ## U
5158
+def UINT64_C(c): return c ## UL
5160
+def UINT64_C(c): return c ## ULL
5162
+def INTMAX_C(c): return c ## L
5164
+def UINTMAX_C(c): return c ## UL
5166
+def INTMAX_C(c): return c ## LL
5168
+def UINTMAX_C(c): return c ## ULL
5171
+# Included from bits/types.h
5173
+__FD_SETSIZE = 1024
5175
+# Included from bits/pthreadtypes.h
5176
+_BITS_PTHREADTYPES_H = 1
5178
+# Included from bits/sched.h
5182
+CSIGNAL = 0x000000ff
5183
+CLONE_VM = 0x00000100
5184
+CLONE_FS = 0x00000200
5185
+CLONE_FILES = 0x00000400
5186
+CLONE_SIGHAND = 0x00000800
5187
+CLONE_PID = 0x00001000
5188
+CLONE_PTRACE = 0x00002000
5189
+CLONE_VFORK = 0x00004000
5190
+__defined_schedparam = 1
5191
+def IN_CLASSA(a): return ((((in_addr_t)(a)) & (-2147483648)) == 0)
5193
+IN_CLASSA_NET = (-16777216)
5194
+IN_CLASSA_NSHIFT = 24
5195
+IN_CLASSA_HOST = ((-1) & ~IN_CLASSA_NET)
5196
+IN_CLASSA_MAX = 128
5197
+def IN_CLASSB(a): return ((((in_addr_t)(a)) & (-1073741824)) == (-2147483648))
5199
+IN_CLASSB_NET = (-65536)
5200
+IN_CLASSB_NSHIFT = 16
5201
+IN_CLASSB_HOST = ((-1) & ~IN_CLASSB_NET)
5202
+IN_CLASSB_MAX = 65536
5203
+def IN_CLASSC(a): return ((((in_addr_t)(a)) & (-536870912)) == (-1073741824))
5205
+IN_CLASSC_NET = (-256)
5206
+IN_CLASSC_NSHIFT = 8
5207
+IN_CLASSC_HOST = ((-1) & ~IN_CLASSC_NET)
5208
+def IN_CLASSD(a): return ((((in_addr_t)(a)) & (-268435456)) == (-536870912))
5210
+def IN_MULTICAST(a): return IN_CLASSD(a)
5212
+def IN_EXPERIMENTAL(a): return ((((in_addr_t)(a)) & (-536870912)) == (-536870912))
5214
+def IN_BADCLASS(a): return ((((in_addr_t)(a)) & (-268435456)) == (-268435456))
5216
+IN_LOOPBACKNET = 127
5217
+INET_ADDRSTRLEN = 16
5218
+INET6_ADDRSTRLEN = 46
5220
+# Included from bits/socket.h
5222
+# Included from limits.h
5223
+_LIBC_LIMITS_H_ = 1
5231
+CHAR_MAX = UCHAR_MAX
5232
+CHAR_MIN = SCHAR_MIN
5233
+CHAR_MAX = SCHAR_MAX
5234
+SHRT_MIN = (-32768)
5237
+INT_MAX = 2147483647
5238
+LONG_MAX = 9223372036854775807L
5239
+LONG_MAX = 2147483647L
5240
+LONG_MIN = (-LONG_MAX - 1L)
5242
+# Included from bits/posix1_lim.h
5243
+_BITS_POSIX1_LIM_H = 1
5244
+_POSIX_AIO_LISTIO_MAX = 2
5246
+_POSIX_ARG_MAX = 4096
5247
+_POSIX_CHILD_MAX = 6
5248
+_POSIX_DELAYTIMER_MAX = 32
5249
+_POSIX_LINK_MAX = 8
5250
+_POSIX_MAX_CANON = 255
5251
+_POSIX_MAX_INPUT = 255
5252
+_POSIX_MQ_OPEN_MAX = 8
5253
+_POSIX_MQ_PRIO_MAX = 32
5254
+_POSIX_NGROUPS_MAX = 0
5255
+_POSIX_OPEN_MAX = 16
5256
+_POSIX_FD_SETSIZE = _POSIX_OPEN_MAX
5257
+_POSIX_NAME_MAX = 14
5258
+_POSIX_PATH_MAX = 256
5259
+_POSIX_PIPE_BUF = 512
5260
+_POSIX_RTSIG_MAX = 8
5261
+_POSIX_SEM_NSEMS_MAX = 256
5262
+_POSIX_SEM_VALUE_MAX = 32767
5263
+_POSIX_SIGQUEUE_MAX = 32
5264
+_POSIX_SSIZE_MAX = 32767
5265
+_POSIX_STREAM_MAX = 8
5266
+_POSIX_TZNAME_MAX = 6
5268
+_POSIX_HIWAT = _POSIX_PIPE_BUF
5269
+_POSIX_UIO_MAXIOV = 16
5270
+_POSIX_TTY_NAME_MAX = 9
5271
+_POSIX_TIMER_MAX = 32
5272
+_POSIX_LOGIN_NAME_MAX = 9
5273
+_POSIX_CLOCKRES_MIN = 20000000
5275
+# Included from bits/local_lim.h
5277
+# Included from linux/limits.h
5290
+_POSIX_THREAD_KEYS_MAX = 128
5291
+PTHREAD_KEYS_MAX = 1024
5292
+_POSIX_THREAD_DESTRUCTOR_ITERATIONS = 4
5293
+PTHREAD_DESTRUCTOR_ITERATIONS = _POSIX_THREAD_DESTRUCTOR_ITERATIONS
5294
+_POSIX_THREAD_THREADS_MAX = 64
5295
+PTHREAD_THREADS_MAX = 1024
5296
+AIO_PRIO_DELTA_MAX = 20
5297
+PTHREAD_STACK_MIN = 16384
5299
+SSIZE_MAX = LONG_MAX
5300
+NGROUPS_MAX = _POSIX_NGROUPS_MAX
5302
+# Included from bits/posix2_lim.h
5303
+_BITS_POSIX2_LIM_H = 1
5304
+_POSIX2_BC_BASE_MAX = 99
5305
+_POSIX2_BC_DIM_MAX = 2048
5306
+_POSIX2_BC_SCALE_MAX = 99
5307
+_POSIX2_BC_STRING_MAX = 1000
5308
+_POSIX2_COLL_WEIGHTS_MAX = 2
5309
+_POSIX2_EXPR_NEST_MAX = 32
5310
+_POSIX2_LINE_MAX = 2048
5311
+_POSIX2_RE_DUP_MAX = 255
5312
+_POSIX2_CHARCLASS_NAME_MAX = 14
5313
+BC_BASE_MAX = _POSIX2_BC_BASE_MAX
5314
+BC_DIM_MAX = _POSIX2_BC_DIM_MAX
5315
+BC_SCALE_MAX = _POSIX2_BC_SCALE_MAX
5316
+BC_STRING_MAX = _POSIX2_BC_STRING_MAX
5317
+COLL_WEIGHTS_MAX = 255
5318
+EXPR_NEST_MAX = _POSIX2_EXPR_NEST_MAX
5319
+LINE_MAX = _POSIX2_LINE_MAX
5320
+CHARCLASS_NAME_MAX = 2048
5321
+RE_DUP_MAX = (0x7fff)
5323
+# Included from bits/xopen_lim.h
5326
+# Included from bits/stdio_lim.h
5329
+FILENAME_MAX = 4096
5334
+_XOPEN_IOV_MAX = _POSIX_UIO_MAXIOV
5335
+NL_ARGMAX = _POSIX_ARG_MAX
5336
+NL_LANGMAX = _POSIX2_LINE_MAX
5337
+NL_MSGMAX = INT_MAX
5339
+NL_SETMAX = INT_MAX
5340
+NL_TEXTMAX = INT_MAX
5355
+from TYPES import *
5375
+PF_ROUTE = PF_NETLINK
5386
+AF_UNSPEC = PF_UNSPEC
5387
+AF_LOCAL = PF_LOCAL
5393
+AF_APPLETALK = PF_APPLETALK
5394
+AF_NETROM = PF_NETROM
5395
+AF_BRIDGE = PF_BRIDGE
5396
+AF_ATMPVC = PF_ATMPVC
5398
+AF_INET6 = PF_INET6
5400
+AF_DECnet = PF_DECnet
5401
+AF_NETBEUI = PF_NETBEUI
5402
+AF_SECURITY = PF_SECURITY
5404
+AF_NETLINK = PF_NETLINK
5405
+AF_ROUTE = PF_ROUTE
5406
+AF_PACKET = PF_PACKET
5408
+AF_ECONET = PF_ECONET
5409
+AF_ATMSVC = PF_ATMSVC
5412
+AF_PPPOX = PF_PPPOX
5413
+AF_WANPIPE = PF_WANPIPE
5414
+AF_BLUETOOTH = PF_BLUETOOTH
5425
+# Included from bits/sockaddr.h
5426
+_BITS_SOCKADDR_H = 1
5427
+def __SOCKADDR_COMMON(sa_prefix): return \
5430
+def CMSG_FIRSTHDR(mhdr): return \
5433
+# Included from asm/socket.h
5435
+# Included from asm/sockios.h
5440
+SIOCATMARK = 0x8905
5441
+SIOCGSTAMP = 0x8906
5463
+SO_SECURITY_AUTHENTICATION = 22
5464
+SO_SECURITY_ENCRYPTION_TRANSPORT = 23
5465
+SO_SECURITY_ENCRYPTION_NETWORK = 24
5466
+SO_BINDTODEVICE = 25
5467
+SO_ATTACH_FILTER = 26
5468
+SO_DETACH_FILTER = 27
5471
+SCM_TIMESTAMP = SO_TIMESTAMP
5479
+SOCK_MAX = (SOCK_PACKET+1)
5481
+# Included from bits/in.h
5486
+IP_ROUTER_ALERT = 5
5492
+IP_MTU_DISCOVER = 10
5496
+IP_MULTICAST_IF = 32
5497
+IP_MULTICAST_TTL = 33
5498
+IP_MULTICAST_LOOP = 34
5499
+IP_ADD_MEMBERSHIP = 35
5500
+IP_DROP_MEMBERSHIP = 36
5501
+IP_RECVRETOPTS = IP_RETOPTS
5502
+IP_PMTUDISC_DONT = 0
5503
+IP_PMTUDISC_WANT = 1
5506
+IP_DEFAULT_MULTICAST_TTL = 1
5507
+IP_DEFAULT_MULTICAST_LOOP = 1
5508
+IP_MAX_MEMBERSHIPS = 20
5514
+IPV6_PKTOPTIONS = 6
5519
+IPV6_UNICAST_HOPS = 16
5520
+IPV6_MULTICAST_IF = 17
5521
+IPV6_MULTICAST_HOPS = 18
5522
+IPV6_MULTICAST_LOOP = 19
5523
+IPV6_JOIN_GROUP = 20
5524
+IPV6_LEAVE_GROUP = 21
5525
+IPV6_ROUTER_ALERT = 22
5526
+IPV6_MTU_DISCOVER = 23
5529
+IPV6_RXHOPOPTS = IPV6_HOPOPTS
5530
+IPV6_RXDSTOPTS = IPV6_DSTOPTS
5531
+IPV6_ADD_MEMBERSHIP = IPV6_JOIN_GROUP
5532
+IPV6_DROP_MEMBERSHIP = IPV6_LEAVE_GROUP
5533
+IPV6_PMTUDISC_DONT = 0
5534
+IPV6_PMTUDISC_WANT = 1
5535
+IPV6_PMTUDISC_DO = 2
5538
+IPV6_RTHDR_LOOSE = 0
5539
+IPV6_RTHDR_STRICT = 1
5540
+IPV6_RTHDR_TYPE_0 = 0
5542
+# Included from endian.h
5544
+__LITTLE_ENDIAN = 1234
5545
+__BIG_ENDIAN = 4321
5546
+__PDP_ENDIAN = 3412
5548
+# Included from bits/endian.h
5549
+__BYTE_ORDER = __LITTLE_ENDIAN
5550
+__FLOAT_WORD_ORDER = __BYTE_ORDER
5551
+LITTLE_ENDIAN = __LITTLE_ENDIAN
5552
+BIG_ENDIAN = __BIG_ENDIAN
5553
+PDP_ENDIAN = __PDP_ENDIAN
5554
+BYTE_ORDER = __BYTE_ORDER
5556
+# Included from bits/byteswap.h
5557
+_BITS_BYTESWAP_H = 1
5558
+def __bswap_constant_16(x): return \
5560
+def __bswap_16(x): return \
5562
+def __bswap_16(x): return __bswap_constant_16 (x)
5564
+def __bswap_constant_32(x): return \
5566
+def __bswap_32(x): return \
5568
+def __bswap_32(x): return \
5570
+def __bswap_32(x): return __bswap_constant_32 (x)
5572
+def __bswap_constant_64(x): return \
5574
+def __bswap_64(x): return \
5576
+def ntohl(x): return (x)
5578
+def ntohs(x): return (x)
5580
+def htonl(x): return (x)
5582
+def htons(x): return (x)
5584
+def ntohl(x): return __bswap_32 (x)
5586
+def ntohs(x): return __bswap_16 (x)
5588
+def htonl(x): return __bswap_32 (x)
5590
+def htons(x): return __bswap_16 (x)
5592
+def IN6_IS_ADDR_UNSPECIFIED(a): return \
5594
+def IN6_IS_ADDR_LOOPBACK(a): return \
5596
+def IN6_IS_ADDR_LINKLOCAL(a): return \
5598
+def IN6_IS_ADDR_SITELOCAL(a): return \
5600
+def IN6_IS_ADDR_V4MAPPED(a): return \
5602
+def IN6_IS_ADDR_V4COMPAT(a): return \
5604
+def IN6_IS_ADDR_MC_NODELOCAL(a): return \
5606
+def IN6_IS_ADDR_MC_LINKLOCAL(a): return \
5608
+def IN6_IS_ADDR_MC_SITELOCAL(a): return \
5610
+def IN6_IS_ADDR_MC_ORGLOCAL(a): return \
5612
+def IN6_IS_ADDR_MC_GLOBAL(a): return
5613
diff -r 8527427914a2 Lib/plat-linux3/TYPES.py
5615
+++ b/Lib/plat-linux3/TYPES.py
5617
+# Generated by h2py from /usr/include/sys/types.h
5620
+# Included from features.h
5626
+_POSIX_C_SOURCE = 199506L
5627
+_XOPEN_SOURCE = 600
5628
+_XOPEN_SOURCE_EXTENDED = 1
5629
+_LARGEFILE64_SOURCE = 1
5636
+_POSIX_C_SOURCE = 2
5637
+_POSIX_C_SOURCE = 199506L
5640
+__USE_POSIX199309 = 1
5641
+__USE_POSIX199506 = 1
5643
+__USE_XOPEN_EXTENDED = 1
5645
+_LARGEFILE_SOURCE = 1
5648
+__USE_XOPEN_EXTENDED = 1
5649
+__USE_LARGEFILE = 1
5650
+__USE_LARGEFILE64 = 1
5651
+__USE_FILE_OFFSET64 = 1
5656
+__USE_REENTRANT = 1
5657
+__STDC_IEC_559__ = 1
5658
+__STDC_IEC_559_COMPLEX__ = 1
5659
+__STDC_ISO_10646__ = 200009L
5660
+__GNU_LIBRARY__ = 6
5662
+__GLIBC_MINOR__ = 2
5664
+# Included from sys/cdefs.h
5666
+def __PMT(args): return args
5668
+def __P(args): return args
5670
+def __PMT(args): return args
5672
+def __STRING(x): return #x
5678
+def __ASMNAME(cname): return __ASMNAME2 (__USER_LABEL_PREFIX__, cname)
5680
+def __attribute__(xyz): return
5682
+def __attribute_format_arg__(x): return __attribute__ ((__format_arg__ (x)))
5684
+def __attribute_format_arg__(x): return
5686
+__USE_LARGEFILE = 1
5687
+__USE_LARGEFILE64 = 1
5688
+__USE_EXTERN_INLINES = 1
5690
+# Included from gnu/stubs.h
5692
+# Included from bits/types.h
5694
+__FD_SETSIZE = 1024
5696
+# Included from bits/pthreadtypes.h
5697
+_BITS_PTHREADTYPES_H = 1
5699
+# Included from bits/sched.h
5703
+CSIGNAL = 0x000000ff
5704
+CLONE_VM = 0x00000100
5705
+CLONE_FS = 0x00000200
5706
+CLONE_FILES = 0x00000400
5707
+CLONE_SIGHAND = 0x00000800
5708
+CLONE_PID = 0x00001000
5709
+CLONE_PTRACE = 0x00002000
5710
+CLONE_VFORK = 0x00004000
5711
+__defined_schedparam = 1
5713
+# Included from time.h
5716
+# Included from bits/time.h
5718
+CLOCKS_PER_SEC = 1000000l
5720
+CLOCK_PROCESS_CPUTIME_ID = 2
5721
+CLOCK_THREAD_CPUTIME_ID = 3
5723
+_STRUCT_TIMEVAL = 1
5724
+CLK_TCK = CLOCKS_PER_SEC
5725
+__clock_t_defined = 1
5726
+__time_t_defined = 1
5727
+__clockid_t_defined = 1
5728
+__timer_t_defined = 1
5729
+__timespec_defined = 1
5730
+def __isleap(year): return \
5732
+__BIT_TYPES_DEFINED__ = 1
5734
+# Included from endian.h
5736
+__LITTLE_ENDIAN = 1234
5737
+__BIG_ENDIAN = 4321
5738
+__PDP_ENDIAN = 3412
5740
+# Included from bits/endian.h
5741
+__BYTE_ORDER = __LITTLE_ENDIAN
5742
+__FLOAT_WORD_ORDER = __BYTE_ORDER
5743
+LITTLE_ENDIAN = __LITTLE_ENDIAN
5744
+BIG_ENDIAN = __BIG_ENDIAN
5745
+PDP_ENDIAN = __PDP_ENDIAN
5746
+BYTE_ORDER = __BYTE_ORDER
5748
+# Included from sys/select.h
5751
+# Included from bits/select.h
5752
+def __FD_ZERO(fdsp): return \
5754
+def __FD_ZERO(set): return \
5757
+# Included from bits/sigset.h
5758
+_SIGSET_H_types = 1
5760
+def __sigmask(sig): return \
5762
+def __sigemptyset(set): return \
5764
+def __sigfillset(set): return \
5766
+def __sigisemptyset(set): return \
5768
+def __FDELT(d): return ((d) / __NFDBITS)
5770
+FD_SETSIZE = __FD_SETSIZE
5771
+def FD_ZERO(fdsetp): return __FD_ZERO (fdsetp)
5774
+# Included from sys/sysmacros.h
5775
+_SYS_SYSMACROS_H = 1
5776
+def major(dev): return ((int)(((dev) >> 8) & 0xff))
5778
+def minor(dev): return ((int)((dev) & 0xff))
5780
+def major(dev): return (((dev).__val[1] >> 8) & 0xff)
5782
+def minor(dev): return ((dev).__val[1] & 0xff)
5784
+def major(dev): return (((dev).__val[0] >> 8) & 0xff)
5786
+def minor(dev): return ((dev).__val[0] & 0xff)
5787
diff -r 8527427914a2 Lib/plat-linux3/regen
5789
+++ b/Lib/plat-linux3/regen
5794
+*) echo Probably not on a Linux system 1>&2
5798
+h2py -i '(u_long)' /usr/include/sys/types.h /usr/include/netinet/in.h /usr/include/dlfcn.h
14017
@@ -286,20 +286,20 @@
14018
f(self, obj) # Call unbound method with explicit self
14021
- # Check for a class with a custom metaclass; treat as regular class
14023
- issc = issubclass(t, TypeType)
14024
- except TypeError: # t is not a class (old Boost; see SF #502085)
14027
- self.save_global(obj)
14030
# Check copy_reg.dispatch_table
14031
reduce = dispatch_table.get(t)
14035
+ # Check for a class with a custom metaclass; treat as regular class
14037
+ issc = issubclass(t, TypeType)
14038
+ except TypeError: # t is not a class (old Boost; see SF #502085)
14041
+ self.save_global(obj)
14044
# Check for a __reduce_ex__ method, fall back to __reduce__
14045
reduce = getattr(obj, "__reduce_ex__", None)
14047
diff -r 8527427914a2 Lib/pipes.py
14052
To create a new template object initialized to a given one:
14055
-For an example, see the function test() at the end of the file.
14059
diff -r 8527427914a2 Lib/pkgutil.py
14060
--- a/Lib/pkgutil.py
14061
+++ b/Lib/pkgutil.py
14062
@@ -194,8 +194,11 @@
14067
- filenames = os.listdir(self.path)
14069
+ filenames = os.listdir(self.path)
14071
+ # ignore unreadable directories like import does
14073
filenames.sort() # handle packages before same-named modules
14075
for fn in filenames:
14076
@@ -208,7 +211,12 @@
14078
if not modname and os.path.isdir(path) and '.' not in fn:
14080
- for fn in os.listdir(path):
14082
+ dircontents = os.listdir(path)
14084
+ # ignore unreadable directories like import does
14086
+ for fn in dircontents:
14087
subname = inspect.getmodulename(fn)
14088
if subname=='__init__':
14090
diff -r 8527427914a2 Lib/plat-mac/findertools.py
14091
--- a/Lib/plat-mac/findertools.py
14092
+++ b/Lib/plat-mac/findertools.py
14093
@@ -128,7 +128,7 @@
14094
def comment(object, comment=None):
14095
"""comment: get or set the Finder-comment of the item, displayed in the 'Get Info' window."""
14096
object = Carbon.File.FSRef(object)
14097
- object_alias = object.FSNewAliasMonimal()
14098
+ object_alias = object.FSNewAliasMinimal()
14099
if comment is None:
14100
return _getcomment(object_alias)
5799
14102
diff -r 8527427914a2 Lib/platform.py
5800
14103
--- a/Lib/platform.py
5801
14104
+++ b/Lib/platform.py
6575
15327
+ with self.assertRaises(TypeError):
6576
15328
+ raise MyException
15330
+ def test_assert_with_tuple_arg(self):
15332
+ assert False, (3,)
15333
+ except AssertionError as e:
15334
+ self.assertEqual(str(e), "(3,)")
6579
15337
# Helper class used by TestSameStrAndUnicodeMsg
15338
diff -r 8527427914a2 Lib/test/test_fcntl.py
15339
--- a/Lib/test/test_fcntl.py
15340
+++ b/Lib/test/test_fcntl.py
15345
- if sys.platform in ('netbsd1', 'netbsd2', 'netbsd3',
15346
- 'Darwin1.2', 'darwin',
15347
- 'freebsd2', 'freebsd3', 'freebsd4', 'freebsd5',
15348
- 'freebsd6', 'freebsd7', 'freebsd8',
15349
- 'bsdos2', 'bsdos3', 'bsdos4',
15350
- 'openbsd', 'openbsd2', 'openbsd3', 'openbsd4'):
15351
+ if (sys.platform.startswith(('netbsd', 'freebsd', 'openbsd', 'bsdos'))
15352
+ or sys.platform == 'darwin'):
15353
if struct.calcsize('l') == 8:
15356
diff -r 8527427914a2 Lib/test/test_float.py
15357
--- a/Lib/test/test_float.py
15358
+++ b/Lib/test/test_float.py
15359
@@ -164,6 +164,12 @@
15360
self.assertAlmostEqual(float(FooUnicode('8')), 9.)
15361
self.assertAlmostEqual(float(FooStr('8')), 9.)
15363
+ def test_is_integer(self):
15364
+ self.assertFalse((1.1).is_integer())
15365
+ self.assertTrue((1.).is_integer())
15366
+ self.assertFalse(float("nan").is_integer())
15367
+ self.assertFalse(float("inf").is_integer())
15369
def test_floatasratio(self):
15372
diff -r 8527427914a2 Lib/test/test_htmlparser.py
15373
--- a/Lib/test/test_htmlparser.py
15374
+++ b/Lib/test/test_htmlparser.py
15375
@@ -181,60 +181,6 @@
15376
("data", "this < text > contains < bare>pointy< brackets"),
15379
- def test_attr_syntax(self):
15381
- ("starttag", "a", [("b", "v"), ("c", "v"), ("d", "v"), ("e", None)])
15383
- self._run_check("""<a b='v' c="v" d=v e>""", output)
15384
- self._run_check("""<a b = 'v' c = "v" d = v e>""", output)
15385
- self._run_check("""<a\nb\n=\n'v'\nc\n=\n"v"\nd\n=\nv\ne>""", output)
15386
- self._run_check("""<a\tb\t=\t'v'\tc\t=\t"v"\td\t=\tv\te>""", output)
15388
- def test_attr_values(self):
15389
- self._run_check("""<a b='xxx\n\txxx' c="yyy\t\nyyy" d='\txyz\n'>""",
15390
- [("starttag", "a", [("b", "xxx\n\txxx"),
15391
- ("c", "yyy\t\nyyy"),
15392
- ("d", "\txyz\n")])
15394
- self._run_check("""<a b='' c="">""", [
15395
- ("starttag", "a", [("b", ""), ("c", "")]),
15397
- # Regression test for SF patch #669683.
15398
- self._run_check("<e a=rgb(1,2,3)>", [
15399
- ("starttag", "e", [("a", "rgb(1,2,3)")]),
15401
- # Regression test for SF bug #921657.
15402
- self._run_check("<a href=mailto:xyz@example.com>", [
15403
- ("starttag", "a", [("href", "mailto:xyz@example.com")]),
15406
- def test_attr_nonascii(self):
15408
- self._run_check(u"<img src=/foo/bar.png alt=\u4e2d\u6587>", [
15409
- ("starttag", "img", [("src", "/foo/bar.png"),
15410
- ("alt", u"\u4e2d\u6587")]),
15412
- self._run_check(u"<a title='\u30c6\u30b9\u30c8' "
15413
- u"href='\u30c6\u30b9\u30c8.html'>", [
15414
- ("starttag", "a", [("title", u"\u30c6\u30b9\u30c8"),
15415
- ("href", u"\u30c6\u30b9\u30c8.html")]),
15417
- self._run_check(u'<a title="\u30c6\u30b9\u30c8" '
15418
- u'href="\u30c6\u30b9\u30c8.html">', [
15419
- ("starttag", "a", [("title", u"\u30c6\u30b9\u30c8"),
15420
- ("href", u"\u30c6\u30b9\u30c8.html")]),
15423
- def test_attr_entity_replacement(self):
15424
- self._run_check("""<a b='&><"''>""", [
15425
- ("starttag", "a", [("b", "&><\"'")]),
15428
- def test_attr_funky_names(self):
15429
- self._run_check("""<a a.b='v' c:d=v e-f=v>""", [
15430
- ("starttag", "a", [("a.b", "v"), ("c:d", "v"), ("e-f", "v")]),
15433
def test_illegal_declarations(self):
15434
self._parse_error('<!spacer type="block" height="25">')
15436
@@ -280,13 +226,11 @@
15437
self._parse_error("<a<a>")
15438
self._parse_error("</a<a>")
15439
self._parse_error("<!")
15440
- self._parse_error("<a $>")
15441
self._parse_error("<a")
15442
self._parse_error("<a foo='bar'")
15443
self._parse_error("<a foo='bar")
15444
self._parse_error("<a foo='>'")
15445
self._parse_error("<a foo='>")
15446
- self._parse_error("<a foo=>")
15448
def test_declaration_junk_chars(self):
15449
self._parse_error("<!DOCTYPE foo $ >")
15450
@@ -312,23 +256,56 @@
15451
("starttag_text", s)])
15453
def test_cdata_content(self):
15454
- s = """<script> <!-- not a comment --> ¬-an-entity-ref; </script>"""
15455
- self._run_check(s, [
15456
- ("starttag", "script", []),
15457
- ("data", " <!-- not a comment --> ¬-an-entity-ref; "),
15458
- ("endtag", "script"),
15460
- s = """<script> <not a='start tag'> </script>"""
15461
- self._run_check(s, [
15462
- ("starttag", "script", []),
15463
- ("data", " <not a='start tag'> "),
15464
- ("endtag", "script"),
15467
+ '<!-- not a comment --> ¬-an-entity-ref;',
15468
+ "<not a='start tag'>",
15469
+ '<a href="" /> <p> <span></span>',
15470
+ 'foo = "</scr" + "ipt>";',
15471
+ 'foo = "</SCRIPT" + ">";',
15472
+ 'foo = <\n/script> ',
15473
+ '<!-- document.write("</scr" + "ipt>"); -->',
15474
+ ('\n//<![CDATA[\n'
15475
+ 'document.write(\'<s\'+\'cript type="text/javascript" '
15476
+ 'src="http://www.example.org/r=\'+new '
15477
+ 'Date().getTime()+\'"><\\/s\'+\'cript>\');\n//]]>'),
15478
+ '\n<!-- //\nvar foo = 3.14;\n// -->\n',
15479
+ 'foo = "</sty" + "le>";',
15480
+ u'<!-- \u2603 -->',
15481
+ # these two should be invalid according to the HTML 5 spec,
15482
+ # section 8.1.2.2
15483
+ #'foo = </\nscript>',
15484
+ #'foo = </ script>',
15486
+ elements = ['script', 'style', 'SCRIPT', 'STYLE', 'Script', 'Style']
15487
+ for content in contents:
15488
+ for element in elements:
15489
+ element_lower = element.lower()
15490
+ s = u'<{element}>{content}</{element}>'.format(element=element,
15492
+ self._run_check(s, [("starttag", element_lower, []),
15493
+ ("data", content),
15494
+ ("endtag", element_lower)])
15496
- def test_entityrefs_in_attributes(self):
15497
- self._run_check("<html foo='€&aa&unsupported;'>", [
15498
- ("starttag", "html", [("foo", u"\u20AC&aa&unsupported;")])
15500
+ def test_cdata_with_closing_tags(self):
15501
+ # see issue #13358
15502
+ # make sure that HTMLParser calls handle_data only once for each CDATA.
15503
+ # The normal event collector normalizes the events in get_events,
15504
+ # so we override it to return the original list of events.
15505
+ class Collector(EventCollector):
15506
+ def get_events(self):
15507
+ return self.events
15509
+ content = """<!-- not a comment --> ¬-an-entity-ref;
15510
+ <a href="" /> </p><p> & <span></span></style>
15511
+ '</script' + '>' </html> </head> </scripter>!"""
15512
+ for element in [' script', 'script ', ' script ',
15513
+ '\nscript', 'script\n', '\nscript\n']:
15514
+ s = u'<script>{content}</{element}>'.format(element=element,
15516
+ self._run_check(s, [("starttag", "script", []),
15517
+ ("data", content),
15518
+ ("endtag", "script")],
15519
+ collector=Collector)
15521
def test_malformatted_charref(self):
15522
self._run_check("<p>&#bad;</p>", [
15523
@@ -343,8 +320,138 @@
15524
self.assertEqual(parser.unescape('&'),'&')
15528
+class AttributesTestCase(TestCaseBase):
15530
+ def test_attr_syntax(self):
15532
+ ("starttag", "a", [("b", "v"), ("c", "v"), ("d", "v"), ("e", None)])
15534
+ self._run_check("""<a b='v' c="v" d=v e>""", output)
15535
+ self._run_check("""<a b = 'v' c = "v" d = v e>""", output)
15536
+ self._run_check("""<a\nb\n=\n'v'\nc\n=\n"v"\nd\n=\nv\ne>""", output)
15537
+ self._run_check("""<a\tb\t=\t'v'\tc\t=\t"v"\td\t=\tv\te>""", output)
15539
+ def test_attr_values(self):
15540
+ self._run_check("""<a b='xxx\n\txxx' c="yyy\t\nyyy" d='\txyz\n'>""",
15541
+ [("starttag", "a", [("b", "xxx\n\txxx"),
15542
+ ("c", "yyy\t\nyyy"),
15543
+ ("d", "\txyz\n")])])
15544
+ self._run_check("""<a b='' c="">""",
15545
+ [("starttag", "a", [("b", ""), ("c", "")])])
15546
+ # Regression test for SF patch #669683.
15547
+ self._run_check("<e a=rgb(1,2,3)>",
15548
+ [("starttag", "e", [("a", "rgb(1,2,3)")])])
15549
+ # Regression test for SF bug #921657.
15551
+ "<a href=mailto:xyz@example.com>",
15552
+ [("starttag", "a", [("href", "mailto:xyz@example.com")])])
15554
+ def test_attr_nonascii(self):
15557
+ u"<img src=/foo/bar.png alt=\u4e2d\u6587>",
15558
+ [("starttag", "img", [("src", "/foo/bar.png"),
15559
+ ("alt", u"\u4e2d\u6587")])])
15561
+ u"<a title='\u30c6\u30b9\u30c8' href='\u30c6\u30b9\u30c8.html'>",
15562
+ [("starttag", "a", [("title", u"\u30c6\u30b9\u30c8"),
15563
+ ("href", u"\u30c6\u30b9\u30c8.html")])])
15565
+ u'<a title="\u30c6\u30b9\u30c8" href="\u30c6\u30b9\u30c8.html">',
15566
+ [("starttag", "a", [("title", u"\u30c6\u30b9\u30c8"),
15567
+ ("href", u"\u30c6\u30b9\u30c8.html")])])
15569
+ def test_attr_entity_replacement(self):
15571
+ "<a b='&><"''>",
15572
+ [("starttag", "a", [("b", "&><\"'")])])
15574
+ def test_attr_funky_names(self):
15576
+ "<a a.b='v' c:d=v e-f=v>",
15577
+ [("starttag", "a", [("a.b", "v"), ("c:d", "v"), ("e-f", "v")])])
15579
+ "<a $><b $=%><c \=/>",
15580
+ [("starttag", "a", [("$", None)]),
15581
+ ("starttag", "b", [("$", "%")]),
15582
+ ("starttag", "c", [("\\", "/")])])
15584
+ def test_entityrefs_in_attributes(self):
15586
+ "<html foo='€&aa&unsupported;'>",
15587
+ [("starttag", "html", [("foo", u"\u20AC&aa&unsupported;")])])
15589
+ def test_entities_in_attribute_value(self):
15591
+ for entity in ['&', '&', '&', '&']:
15592
+ self._run_check('<a href="%s">' % entity,
15593
+ [("starttag", "a", [("href", "&")])])
15594
+ self._run_check("<a href='%s'>" % entity,
15595
+ [("starttag", "a", [("href", "&")])])
15596
+ self._run_check("<a href=%s>" % entity,
15597
+ [("starttag", "a", [("href", "&")])])
15599
+ def test_malformed_attributes(self):
15602
+ "<a href=test'style='color:red;bad1'>test - bad1</a>"
15603
+ "<a href=test'+style='color:red;ba2'>test - bad2</a>"
15604
+ "<a href=test' style='color:red;bad3'>test - bad3</a>"
15605
+ "<a href = test' style='color:red;bad4' >test - bad4</a>"
15608
+ ('starttag', 'a', [('href', "test'style='color:red;bad1'")]),
15609
+ ('data', 'test - bad1'), ('endtag', 'a'),
15610
+ ('starttag', 'a', [('href', "test'+style='color:red;ba2'")]),
15611
+ ('data', 'test - bad2'), ('endtag', 'a'),
15612
+ ('starttag', 'a', [('href', u"test'\xa0style='color:red;bad3'")]),
15613
+ ('data', 'test - bad3'), ('endtag', 'a'),
15614
+ ('starttag', 'a', [('href', u"test'\xa0style='color:red;bad4'")]),
15615
+ ('data', 'test - bad4'), ('endtag', 'a')
15617
+ self._run_check(html, expected)
15619
+ def test_malformed_adjacent_attributes(self):
15621
+ self._run_check('<x><y z=""o"" /></x>',
15622
+ [('starttag', 'x', []),
15623
+ ('startendtag', 'y', [('z', ''), ('o""', None)]),
15624
+ ('endtag', 'x')])
15625
+ self._run_check('<x><y z="""" /></x>',
15626
+ [('starttag', 'x', []),
15627
+ ('startendtag', 'y', [('z', ''), ('""', None)]),
15628
+ ('endtag', 'x')])
15630
+ # see #755670 for the following 3 tests
15631
+ def test_adjacent_attributes(self):
15632
+ self._run_check('<a width="100%"cellspacing=0>',
15633
+ [("starttag", "a",
15634
+ [("width", "100%"), ("cellspacing","0")])])
15636
+ self._run_check('<a id="foo"class="bar">',
15637
+ [("starttag", "a",
15638
+ [("id", "foo"), ("class","bar")])])
15640
+ def test_missing_attribute_value(self):
15641
+ self._run_check('<a v=>',
15642
+ [("starttag", "a", [("v", "")])])
15644
+ def test_javascript_attribute_value(self):
15645
+ self._run_check("<a href=javascript:popup('/popup/help.html')>",
15646
+ [("starttag", "a",
15647
+ [("href", "javascript:popup('/popup/help.html')")])])
15649
+ def test_end_tag_in_attribute_value(self):
15651
+ self._run_check("<a href='http://www.example.org/\">;'>spam</a>",
15652
+ [("starttag", "a",
15653
+ [("href", "http://www.example.org/\">;")]),
15654
+ ("data", "spam"), ("endtag", "a")])
15658
- test_support.run_unittest(HTMLParserTestCase)
15659
+ test_support.run_unittest(HTMLParserTestCase, AttributesTestCase)
15662
if __name__ == "__main__":
15663
diff -r 8527427914a2 Lib/test/test_httplib.py
15664
--- a/Lib/test/test_httplib.py
15665
+++ b/Lib/test/test_httplib.py
15666
@@ -152,13 +152,15 @@
15667
def test_host_port(self):
15668
# Check invalid host_port
15670
- for hp in ("www.python.org:abc", "www.python.org:"):
15671
+ # Note that httplib does not accept user:password@ in the host-port.
15672
+ for hp in ("www.python.org:abc", "user:password@www.python.org"):
15673
self.assertRaises(httplib.InvalidURL, httplib.HTTP, hp)
15675
for hp, h, p in (("[fe80::207:e9ff:fe9b]:8000", "fe80::207:e9ff:fe9b",
15677
("www.python.org:80", "www.python.org", 80),
15678
("www.python.org", "www.python.org", 80),
15679
+ ("www.python.org:", "www.python.org", 80),
15680
("[fe80::207:e9ff:fe9b]", "fe80::207:e9ff:fe9b", 80)):
15681
http = httplib.HTTP(hp)
15683
@@ -439,6 +441,28 @@
15684
h = httplib.HTTPSConnection(HOST, TimeoutTest.PORT, timeout=30)
15685
self.assertEqual(h.timeout, 30)
15687
+ @unittest.skipIf(not hasattr(httplib, 'HTTPS'), 'httplib.HTTPS not available')
15688
+ def test_host_port(self):
15689
+ # Check invalid host_port
15691
+ # Note that httplib does not accept user:password@ in the host-port.
15692
+ for hp in ("www.python.org:abc", "user:password@www.python.org"):
15693
+ self.assertRaises(httplib.InvalidURL, httplib.HTTP, hp)
15695
+ for hp, h, p in (("[fe80::207:e9ff:fe9b]:8000", "fe80::207:e9ff:fe9b",
15697
+ ("pypi.python.org:443", "pypi.python.org", 443),
15698
+ ("pypi.python.org", "pypi.python.org", 443),
15699
+ ("pypi.python.org:", "pypi.python.org", 443),
15700
+ ("[fe80::207:e9ff:fe9b]", "fe80::207:e9ff:fe9b", 443)):
15701
+ http = httplib.HTTPS(hp)
15704
+ self.fail("Host incorrectly parsed: %s != %s" % (h, c.host))
15706
+ self.fail("Port incorrectly parsed: %s != %s" % (p, c.host))
15709
def test_main(verbose=None):
15710
test_support.run_unittest(HeaderTests, OfflineTest, BasicTest, TimeoutTest,
15711
HTTPSTimeoutTest, SourceAddressTest)
15712
diff -r 8527427914a2 Lib/test/test_httpservers.py
15713
--- a/Lib/test/test_httpservers.py
15714
+++ b/Lib/test/test_httpservers.py
15715
@@ -324,8 +324,10 @@
15716
f = open(os.path.join(self.tempdir_name, 'index.html'), 'w')
15717
response = self.request('/' + self.tempdir_name + '/')
15718
self.check_status_and_reason(response, 200)
15719
- if os.name == 'posix':
15720
- # chmod won't work as expected on Windows platforms
15722
+ # chmod() doesn't work as expected on Windows, and filesystem
15723
+ # permissions are ignored by root on Unix.
15724
+ if os.name == 'posix' and os.geteuid() != 0:
15725
os.chmod(self.tempdir, 0)
15726
response = self.request(self.tempdir_name + '/')
15727
self.check_status_and_reason(response, 404)
15728
@@ -370,6 +372,9 @@
15729
form.getfirst("bacon"))
15733
+@unittest.skipIf(hasattr(os, 'geteuid') and os.geteuid() == 0,
15734
+ "This test can't be run reliably as root (issue #13308).")
15735
class CGIHTTPServerTestCase(BaseTestCase):
15736
class request_handler(NoLogRequestHandler, CGIHTTPRequestHandler):
15738
diff -r 8527427914a2 Lib/test/test_import.py
15739
--- a/Lib/test/test_import.py
15740
+++ b/Lib/test/test_import.py
15741
@@ -265,6 +265,15 @@
15743
script_helper.assert_python_ok(testfn)
15745
+ def test_bug7732(self):
15746
+ source = TESTFN + '.py'
15749
+ self.assertRaises((ImportError, IOError),
15750
+ imp.find_module, TESTFN, ["."])
15755
class PycRewritingTests(unittest.TestCase):
15756
# Test that the `co_filename` attribute on code objects always points
6580
15757
diff -r 8527427914a2 Lib/test/test_inspect.py
6581
15758
--- a/Lib/test/test_inspect.py
6582
15759
+++ b/Lib/test/test_inspect.py
7020
16953
def test_getcwd_long_pathnames(self):
7021
16954
if hasattr(posix, 'getcwd'):
16955
diff -r 8527427914a2 Lib/test/test_py_compile.py
16957
+++ b/Lib/test/test_py_compile.py
16966
+from test import test_support
16968
+class PyCompileTests(unittest.TestCase):
16971
+ self.directory = tempfile.mkdtemp()
16972
+ self.source_path = os.path.join(self.directory, '_test.py')
16973
+ self.pyc_path = self.source_path + 'c'
16974
+ self.cwd_drive = os.path.splitdrive(os.getcwd())[0]
16975
+ # In these tests we compute relative paths. When using Windows, the
16976
+ # current working directory path and the 'self.source_path' might be
16977
+ # on different drives. Therefore we need to switch to the drive where
16978
+ # the temporary source file lives.
16979
+ drive = os.path.splitdrive(self.source_path)[0]
16983
+ with open(self.source_path, 'w') as file:
16984
+ file.write('x = 123\n')
16986
+ def tearDown(self):
16987
+ shutil.rmtree(self.directory)
16988
+ if self.cwd_drive:
16989
+ os.chdir(self.cwd_drive)
16991
+ def test_absolute_path(self):
16992
+ py_compile.compile(self.source_path, self.pyc_path)
16993
+ self.assertTrue(os.path.exists(self.pyc_path))
16995
+ def test_cwd(self):
16996
+ cwd = os.getcwd()
16997
+ os.chdir(self.directory)
16998
+ py_compile.compile(os.path.basename(self.source_path),
16999
+ os.path.basename(self.pyc_path))
17001
+ self.assertTrue(os.path.exists(self.pyc_path))
17003
+ def test_relative_path(self):
17004
+ py_compile.compile(os.path.relpath(self.source_path),
17005
+ os.path.relpath(self.pyc_path))
17006
+ self.assertTrue(os.path.exists(self.pyc_path))
17009
+ test_support.run_unittest(PyCompileTests)
17011
+if __name__ == "__main__":
7022
17013
diff -r 8527427914a2 Lib/test/test_pydoc.py
7023
17014
--- a/Lib/test/test_pydoc.py
7024
17015
+++ b/Lib/test/test_pydoc.py
7029
17020
-import os.path
7030
17021
import difflib
7032
17023
+import __builtin__
7035
17026
import inspect
7036
@@ -357,6 +357,23 @@
17030
import test.test_support
17031
-from contextlib import contextmanager
17032
from collections import namedtuple
17033
+from test.script_helper import assert_python_ok
17034
from test.test_support import (
17035
- TESTFN, forget, rmtree, EnvironmentVarGuard, reap_children, captured_stdout)
17036
+ TESTFN, rmtree, reap_children, captured_stdout)
17038
from test import pydoc_mod
17040
@@ -176,17 +175,15 @@
17041
# output pattern for module with bad imports
17042
badimport_pattern = "problem in %s - <type 'exceptions.ImportError'>: No module named %s"
17044
-def run_pydoc(module_name, *args):
17045
+def run_pydoc(module_name, *args, **env):
17047
Runs pydoc on the specified module. Returns the stripped
17050
- cmd = [sys.executable, pydoc.__file__, " ".join(args), module_name]
17052
- output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
17053
- return output.strip()
17056
+ args = args + (module_name,)
17057
+ # do not write bytecode files to avoid caching errors
17058
+ rc, out, err = assert_python_ok('-B', pydoc.__file__, *args, **env)
17059
+ return out.strip()
17061
def get_pydoc_html(module):
17062
"Returns pydoc generated output as html"
17063
@@ -259,42 +256,6 @@
17064
self.assertEqual(expected, result,
17065
"documentation for missing module found")
17067
- def test_badimport(self):
17068
- # This tests the fix for issue 5230, where if pydoc found the module
17069
- # but the module had an internal import error pydoc would report no doc
17071
- modname = 'testmod_xyzzy'
17073
- ('i_am_not_here', 'i_am_not_here'),
17074
- ('test.i_am_not_here_either', 'i_am_not_here_either'),
17075
- ('test.i_am_not_here.neither_am_i', 'i_am_not_here.neither_am_i'),
17076
- ('i_am_not_here.{}'.format(modname), 'i_am_not_here.{}'.format(modname)),
17077
- ('test.{}'.format(modname), modname),
17081
- def newdirinpath(dir):
17083
- sys.path.insert(0, dir)
17088
- with newdirinpath(TESTFN), EnvironmentVarGuard() as env:
17089
- env['PYTHONPATH'] = TESTFN
17090
- fullmodname = os.path.join(TESTFN, modname)
17091
- sourcefn = fullmodname + os.extsep + "py"
17092
- for importstring, expectedinmsg in testpairs:
17093
- f = open(sourcefn, 'w')
17094
- f.write("import {}\n".format(importstring))
17097
- result = run_pydoc(modname)
17100
- expected = badimport_pattern % (modname, expectedinmsg)
17101
- self.assertEqual(expected, result)
17103
def test_input_strip(self):
17104
missing_module = " test.i_am_not_here "
17105
result = run_pydoc(missing_module)
17106
@@ -317,6 +278,55 @@
17107
"<type 'exceptions.Exception'>")
17110
+class PydocImportTest(unittest.TestCase):
17113
+ self.test_dir = os.mkdir(TESTFN)
17114
+ self.addCleanup(rmtree, TESTFN)
17116
+ def test_badimport(self):
17117
+ # This tests the fix for issue 5230, where if pydoc found the module
17118
+ # but the module had an internal import error pydoc would report no doc
17120
+ modname = 'testmod_xyzzy'
17122
+ ('i_am_not_here', 'i_am_not_here'),
17123
+ ('test.i_am_not_here_either', 'i_am_not_here_either'),
17124
+ ('test.i_am_not_here.neither_am_i', 'i_am_not_here.neither_am_i'),
17125
+ ('i_am_not_here.{}'.format(modname),
17126
+ 'i_am_not_here.{}'.format(modname)),
17127
+ ('test.{}'.format(modname), modname),
17130
+ sourcefn = os.path.join(TESTFN, modname) + os.extsep + "py"
17131
+ for importstring, expectedinmsg in testpairs:
17132
+ with open(sourcefn, 'w') as f:
17133
+ f.write("import {}\n".format(importstring))
17134
+ result = run_pydoc(modname, PYTHONPATH=TESTFN)
17135
+ expected = badimport_pattern % (modname, expectedinmsg)
17136
+ self.assertEqual(expected, result)
17138
+ def test_apropos_with_bad_package(self):
17139
+ # Issue 7425 - pydoc -k failed when bad package on path
17140
+ pkgdir = os.path.join(TESTFN, "syntaxerr")
17142
+ badsyntax = os.path.join(pkgdir, "__init__") + os.extsep + "py"
17143
+ with open(badsyntax, 'w') as f:
17144
+ f.write("invalid python syntax = $1\n")
17145
+ result = run_pydoc('nothing', '-k', PYTHONPATH=TESTFN)
17146
+ self.assertEqual('', result)
17148
+ def test_apropos_with_unreadable_dir(self):
17149
+ # Issue 7367 - pydoc -k failed when unreadable dir on path
17150
+ self.unreadable_dir = os.path.join(TESTFN, "unreadable")
17151
+ os.mkdir(self.unreadable_dir, 0)
17152
+ self.addCleanup(os.rmdir, self.unreadable_dir)
17153
+ # Note, on Windows the directory appears to be still
17154
+ # readable so this is not really testing the issue there
17155
+ result = run_pydoc('nothing', '-k', PYTHONPATH=TESTFN)
17156
+ self.assertEqual('', result)
17159
class TestDescriptions(unittest.TestCase):
17161
def test_module(self):
17162
@@ -357,11 +367,32 @@
7037
17163
self.assertEqual(sorted(pydoc.Helper.keywords),
7038
17164
sorted(keyword.kwlist))
7460
18062
def test_islower(self):
7461
18063
string_tests.MixinStrUnicodeUserStringTest.test_islower(self)
7462
18064
self.checkequalnofix(False, u'\u1FFc', 'islower')
18066
+ @requires_wide_build
18067
+ def test_islower_non_bmp(self):
18068
+ # non-BMP, uppercase
18069
+ self.assertFalse(u'\U00010401'.islower())
18070
+ self.assertFalse(u'\U00010427'.islower())
18071
+ # non-BMP, lowercase
18072
+ self.assertTrue(u'\U00010429'.islower())
18073
+ self.assertTrue(u'\U0001044E'.islower())
18074
+ # non-BMP, non-cased
18075
+ self.assertFalse(u'\U0001F40D'.islower())
18076
+ self.assertFalse(u'\U0001F46F'.islower())
18078
def test_isupper(self):
18079
string_tests.MixinStrUnicodeUserStringTest.test_isupper(self)
18080
if not sys.platform.startswith('java'):
18081
self.checkequalnofix(False, u'\u1FFc', 'isupper')
18083
+ @requires_wide_build
18084
+ def test_isupper_non_bmp(self):
18085
+ # non-BMP, uppercase
18086
+ self.assertTrue(u'\U00010401'.isupper())
18087
+ self.assertTrue(u'\U00010427'.isupper())
18088
+ # non-BMP, lowercase
18089
+ self.assertFalse(u'\U00010429'.isupper())
18090
+ self.assertFalse(u'\U0001044E'.isupper())
18091
+ # non-BMP, non-cased
18092
+ self.assertFalse(u'\U0001F40D'.isupper())
18093
+ self.assertFalse(u'\U0001F46F'.isupper())
18095
def test_istitle(self):
18096
- string_tests.MixinStrUnicodeUserStringTest.test_title(self)
18097
+ string_tests.MixinStrUnicodeUserStringTest.test_istitle(self)
18098
self.checkequalnofix(True, u'\u1FFc', 'istitle')
18099
self.checkequalnofix(True, u'Greek \u1FFcitlecases ...', 'istitle')
18101
+ @requires_wide_build
18102
+ def test_istitle_non_bmp(self):
18103
+ # non-BMP, uppercase + lowercase
18104
+ self.assertTrue(u'\U00010401\U00010429'.istitle())
18105
+ self.assertTrue(u'\U00010427\U0001044E'.istitle())
18106
+ # apparently there are no titlecased (Lt) non-BMP chars in Unicode 6
18107
+ for ch in [u'\U00010429', u'\U0001044E', u'\U0001F40D', u'\U0001F46F']:
18108
+ self.assertFalse(ch.istitle(), '{!r} is not title'.format(ch))
18110
def test_isspace(self):
18111
string_tests.MixinStrUnicodeUserStringTest.test_isspace(self)
18112
self.checkequalnofix(True, u'\u2000', 'isspace')
18113
self.checkequalnofix(True, u'\u200a', 'isspace')
18114
self.checkequalnofix(False, u'\u2014', 'isspace')
18116
+ @requires_wide_build
18117
+ def test_isspace_non_bmp(self):
18118
+ # apparently there are no non-BMP spaces chars in Unicode 6
18119
+ for ch in [u'\U00010401', u'\U00010427', u'\U00010429', u'\U0001044E',
18120
+ u'\U0001F40D', u'\U0001F46F']:
18121
+ self.assertFalse(ch.isspace(), '{!r} is not space.'.format(ch))
18123
+ @requires_wide_build
18124
+ def test_isalnum_non_bmp(self):
18125
+ for ch in [u'\U00010401', u'\U00010427', u'\U00010429', u'\U0001044E',
18126
+ u'\U0001D7F6', u'\U000104A0', u'\U000104A0', u'\U0001F107']:
18127
+ self.assertTrue(ch.isalnum(), '{!r} is alnum.'.format(ch))
18129
def test_isalpha(self):
18130
string_tests.MixinStrUnicodeUserStringTest.test_isalpha(self)
18131
self.checkequalnofix(True, u'\u1FFc', 'isalpha')
18133
+ @requires_wide_build
18134
+ def test_isalpha_non_bmp(self):
18136
+ self.assertTrue(u'\U00010401'.isalpha())
18137
+ self.assertTrue(u'\U00010427'.isalpha())
18138
+ self.assertTrue(u'\U00010429'.isalpha())
18139
+ self.assertTrue(u'\U0001044E'.isalpha())
18140
+ # non-BMP, non-cased
18141
+ self.assertFalse(u'\U0001F40D'.isalpha())
18142
+ self.assertFalse(u'\U0001F46F'.isalpha())
18144
def test_isdecimal(self):
18145
self.checkequalnofix(False, u'', 'isdecimal')
18146
self.checkequalnofix(False, u'a', 'isdecimal')
18147
@@ -305,12 +388,28 @@
18149
self.checkraises(TypeError, 'abc', 'isdecimal', 42)
18151
+ @requires_wide_build
18152
+ def test_isdecimal_non_bmp(self):
18153
+ for ch in [u'\U00010401', u'\U00010427', u'\U00010429', u'\U0001044E',
18154
+ u'\U0001F40D', u'\U0001F46F', u'\U00011065', u'\U0001F107']:
18155
+ self.assertFalse(ch.isdecimal(), '{!r} is not decimal.'.format(ch))
18156
+ for ch in [u'\U0001D7F6', u'\U000104A0', u'\U000104A0']:
18157
+ self.assertTrue(ch.isdecimal(), '{!r} is decimal.'.format(ch))
18159
def test_isdigit(self):
18160
string_tests.MixinStrUnicodeUserStringTest.test_isdigit(self)
18161
self.checkequalnofix(True, u'\u2460', 'isdigit')
18162
self.checkequalnofix(False, u'\xbc', 'isdigit')
18163
self.checkequalnofix(True, u'\u0660', 'isdigit')
18165
+ @requires_wide_build
18166
+ def test_isdigit_non_bmp(self):
18167
+ for ch in [u'\U00010401', u'\U00010427', u'\U00010429', u'\U0001044E',
18168
+ u'\U0001F40D', u'\U0001F46F', u'\U00011065']:
18169
+ self.assertFalse(ch.isdigit(), '{!r} is not a digit.'.format(ch))
18170
+ for ch in [u'\U0001D7F6', u'\U000104A0', u'\U000104A0', u'\U0001F107']:
18171
+ self.assertTrue(ch.isdigit(), '{!r} is a digit.'.format(ch))
18173
def test_isnumeric(self):
18174
self.checkequalnofix(False, u'', 'isnumeric')
18175
self.checkequalnofix(False, u'a', 'isnumeric')
18176
@@ -323,6 +422,109 @@
18178
self.assertRaises(TypeError, u"abc".isnumeric, 42)
18180
+ @requires_wide_build
18181
+ def test_isnumeric_non_bmp(self):
18182
+ for ch in [u'\U00010401', u'\U00010427', u'\U00010429', u'\U0001044E',
18183
+ u'\U0001F40D', u'\U0001F46F']:
18184
+ self.assertFalse(ch.isnumeric(), '{!r} is not numeric.'.format(ch))
18185
+ for ch in [u'\U00010107', u'\U0001D7F6', u'\U00023b1b',
18186
+ u'\U000104A0', u'\U0001F107']:
18187
+ self.assertTrue(ch.isnumeric(), '{!r} is numeric.'.format(ch))
18189
+ @requires_wide_build
18190
+ def test_surrogates(self):
18191
+ # this test actually passes on narrow too, but it's just by accident.
18192
+ # Surrogates are seen as non-cased chars, so u'X\uD800X' is as
18193
+ # uppercase as 'X X'
18194
+ for s in (u'a\uD800b\uDFFF', u'a\uDFFFb\uD800',
18195
+ u'a\uD800b\uDFFFa', u'a\uDFFFb\uD800a'):
18196
+ self.assertTrue(s.islower())
18197
+ self.assertFalse(s.isupper())
18198
+ self.assertFalse(s.istitle())
18199
+ for s in (u'A\uD800B\uDFFF', u'A\uDFFFB\uD800',
18200
+ u'A\uD800B\uDFFFA', u'A\uDFFFB\uD800A'):
18201
+ self.assertFalse(s.islower())
18202
+ self.assertTrue(s.isupper())
18203
+ self.assertTrue(s.istitle())
18205
+ for meth_name in ('islower', 'isupper', 'istitle'):
18206
+ meth = getattr(unicode, meth_name)
18207
+ for s in (u'\uD800', u'\uDFFF', u'\uD800\uD800', u'\uDFFF\uDFFF'):
18208
+ self.assertFalse(meth(s), '%r.%s() is False' % (s, meth_name))
18210
+ for meth_name in ('isalpha', 'isalnum', 'isdigit', 'isspace',
18211
+ 'isdecimal', 'isnumeric'):
18212
+ meth = getattr(unicode, meth_name)
18213
+ for s in (u'\uD800', u'\uDFFF', u'\uD800\uD800', u'\uDFFF\uDFFF',
18214
+ u'a\uD800b\uDFFF', u'a\uDFFFb\uD800',
18215
+ u'a\uD800b\uDFFFa', u'a\uDFFFb\uD800a'):
18216
+ self.assertFalse(meth(s), '%r.%s() is False' % (s, meth_name))
18219
+ @requires_wide_build
18220
+ def test_lower(self):
18221
+ string_tests.CommonTest.test_lower(self)
18222
+ self.assertEqual(u'\U00010427'.lower(), u'\U0001044F')
18223
+ self.assertEqual(u'\U00010427\U00010427'.lower(),
18224
+ u'\U0001044F\U0001044F')
18225
+ self.assertEqual(u'\U00010427\U0001044F'.lower(),
18226
+ u'\U0001044F\U0001044F')
18227
+ self.assertEqual(u'X\U00010427x\U0001044F'.lower(),
18228
+ u'x\U0001044Fx\U0001044F')
18230
+ @requires_wide_build
18231
+ def test_upper(self):
18232
+ string_tests.CommonTest.test_upper(self)
18233
+ self.assertEqual(u'\U0001044F'.upper(), u'\U00010427')
18234
+ self.assertEqual(u'\U0001044F\U0001044F'.upper(),
18235
+ u'\U00010427\U00010427')
18236
+ self.assertEqual(u'\U00010427\U0001044F'.upper(),
18237
+ u'\U00010427\U00010427')
18238
+ self.assertEqual(u'X\U00010427x\U0001044F'.upper(),
18239
+ u'X\U00010427X\U00010427')
18241
+ @requires_wide_build
18242
+ def test_capitalize(self):
18243
+ string_tests.CommonTest.test_capitalize(self)
18244
+ self.assertEqual(u'\U0001044F'.capitalize(), u'\U00010427')
18245
+ self.assertEqual(u'\U0001044F\U0001044F'.capitalize(),
18246
+ u'\U00010427\U0001044F')
18247
+ self.assertEqual(u'\U00010427\U0001044F'.capitalize(),
18248
+ u'\U00010427\U0001044F')
18249
+ self.assertEqual(u'\U0001044F\U00010427'.capitalize(),
18250
+ u'\U00010427\U0001044F')
18251
+ self.assertEqual(u'X\U00010427x\U0001044F'.capitalize(),
18252
+ u'X\U0001044Fx\U0001044F')
18254
+ @requires_wide_build
18255
+ def test_title(self):
18256
+ string_tests.MixinStrUnicodeUserStringTest.test_title(self)
18257
+ self.assertEqual(u'\U0001044F'.title(), u'\U00010427')
18258
+ self.assertEqual(u'\U0001044F\U0001044F'.title(),
18259
+ u'\U00010427\U0001044F')
18260
+ self.assertEqual(u'\U0001044F\U0001044F \U0001044F\U0001044F'.title(),
18261
+ u'\U00010427\U0001044F \U00010427\U0001044F')
18262
+ self.assertEqual(u'\U00010427\U0001044F \U00010427\U0001044F'.title(),
18263
+ u'\U00010427\U0001044F \U00010427\U0001044F')
18264
+ self.assertEqual(u'\U0001044F\U00010427 \U0001044F\U00010427'.title(),
18265
+ u'\U00010427\U0001044F \U00010427\U0001044F')
18266
+ self.assertEqual(u'X\U00010427x\U0001044F X\U00010427x\U0001044F'.title(),
18267
+ u'X\U0001044Fx\U0001044F X\U0001044Fx\U0001044F')
18269
+ @requires_wide_build
18270
+ def test_swapcase(self):
18271
+ string_tests.CommonTest.test_swapcase(self)
18272
+ self.assertEqual(u'\U0001044F'.swapcase(), u'\U00010427')
18273
+ self.assertEqual(u'\U00010427'.swapcase(), u'\U0001044F')
18274
+ self.assertEqual(u'\U0001044F\U0001044F'.swapcase(),
18275
+ u'\U00010427\U00010427')
18276
+ self.assertEqual(u'\U00010427\U0001044F'.swapcase(),
18277
+ u'\U0001044F\U00010427')
18278
+ self.assertEqual(u'\U0001044F\U00010427'.swapcase(),
18279
+ u'\U00010427\U0001044F')
18280
+ self.assertEqual(u'X\U00010427x\U0001044F'.swapcase(),
18281
+ u'x\U0001044FX\U00010427')
18283
def test_contains(self):
18284
# Testing Unicode contains method
18285
self.assertIn('a', u'abdb')
18286
@@ -569,10 +771,18 @@
18287
for (x, y) in utfTests:
18288
self.assertEqual(x.encode('utf-7'), y)
18290
- # Unpaired surrogates not supported
18291
- self.assertRaises(UnicodeError, unicode, '+3ADYAA-', 'utf-7')
18292
+ # Unpaired surrogates are passed through
18293
+ self.assertEqual(u'\uD801'.encode('utf-7'), '+2AE-')
18294
+ self.assertEqual(u'\uD801x'.encode('utf-7'), '+2AE-x')
18295
+ self.assertEqual(u'\uDC01'.encode('utf-7'), '+3AE-')
18296
+ self.assertEqual(u'\uDC01x'.encode('utf-7'), '+3AE-x')
18297
+ self.assertEqual('+2AE-'.decode('utf-7'), u'\uD801')
18298
+ self.assertEqual('+2AE-x'.decode('utf-7'), u'\uD801x')
18299
+ self.assertEqual('+3AE-'.decode('utf-7'), u'\uDC01')
18300
+ self.assertEqual('+3AE-x'.decode('utf-7'), u'\uDC01x')
18302
- self.assertEqual(unicode('+3ADYAA-', 'utf-7', 'replace'), u'\ufffd\ufffd')
18303
+ self.assertEqual(u'\uD801\U000abcde'.encode('utf-7'), '+2AHab9ze-')
18304
+ self.assertEqual('+2AHab9ze-'.decode('utf-7'), u'\uD801\U000abcde')
18306
# Direct encoded characters
18307
set_d = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'(),-./:?"
18308
@@ -1396,6 +1606,31 @@
18309
self.assertEqual("%s" % u, u'__unicode__ overridden')
18310
self.assertEqual("{}".format(u), '__unicode__ overridden')
18312
+ def test_encode_decimal(self):
18313
+ from _testcapi import unicode_encodedecimal
18314
+ self.assertEqual(unicode_encodedecimal(u'123'),
18316
+ self.assertEqual(unicode_encodedecimal(u'\u0663.\u0661\u0664'),
18318
+ self.assertEqual(unicode_encodedecimal(u"\N{EM SPACE}3.14\N{EN SPACE}"),
18320
+ self.assertRaises(UnicodeEncodeError,
18321
+ unicode_encodedecimal, u"123\u20ac", "strict")
18322
+ self.assertEqual(unicode_encodedecimal(u"123\u20ac", "replace"),
18324
+ self.assertEqual(unicode_encodedecimal(u"123\u20ac", "ignore"),
18326
+ self.assertEqual(unicode_encodedecimal(u"123\u20ac", "xmlcharrefreplace"),
18328
+ self.assertEqual(unicode_encodedecimal(u"123\u20ac", "backslashreplace"),
18330
+ self.assertEqual(unicode_encodedecimal(u"123\u20ac\N{EM SPACE}", "replace"),
18332
+ self.assertEqual(unicode_encodedecimal(u"123\u20ac\u20ac", "replace"),
18334
+ self.assertEqual(unicode_encodedecimal(u"123\u20ac\u0660", "replace"),
18339
test_support.run_unittest(__name__)
7463
18340
diff -r 8527427914a2 Lib/test/test_urllib.py
7464
18341
--- a/Lib/test/test_urllib.py
7465
18342
+++ b/Lib/test/test_urllib.py
18344
hex_repr = "0%s" % hex_repr
18345
return "%" + hex_repr
18348
+class FakeHTTPMixin(object):
18349
+ def fakehttp(self, fakedata):
18350
+ class FakeSocket(StringIO.StringIO):
18352
+ def sendall(self, str):
18354
+ def makefile(self, *args, **kwds):
18357
+ def read(self, amt=None):
18360
+ return StringIO.StringIO.read(self, amt)
18362
+ def readline(self, length=None):
18365
+ return StringIO.StringIO.readline(self, length)
18367
+ class FakeHTTPConnection(httplib.HTTPConnection):
18368
+ def connect(self):
18369
+ self.sock = FakeSocket(fakedata)
18370
+ assert httplib.HTTP._connection_class == httplib.HTTPConnection
18371
+ httplib.HTTP._connection_class = FakeHTTPConnection
18373
+ def unfakehttp(self):
18374
+ httplib.HTTP._connection_class = httplib.HTTPConnection
18377
class urlopen_FileTests(unittest.TestCase):
18378
"""Test urlopen() opening a temporary file.
18380
@@ -114,30 +144,14 @@
7467
18381
proxies = urllib.getproxies_environment()
7468
18382
# getproxies_environment use lowered case truncated (no '_proxy') keys
7469
18383
self.assertEqual('localhost', proxies['no'])
8304
19962
#endif /* WIN32 */
8306
19964
#if defined(DARWIN) || defined(_DARWIN)
19965
diff -r 8527427914a2 Modules/_ctypes/stgdict.c
19966
--- a/Modules/_ctypes/stgdict.c
19967
+++ b/Modules/_ctypes/stgdict.c
19968
@@ -494,14 +494,33 @@
19969
char *fieldfmt = dict->format ? dict->format : "B";
19970
char *fieldname = PyString_AsString(name);
19972
- Py_ssize_t len = strlen(fieldname) + strlen(fieldfmt);
19973
- char *buf = alloca(len + 2 + 1);
19977
+ if (fieldname == NULL)
19979
+ PyErr_Format(PyExc_TypeError,
19980
+ "structure field name must be string not %s",
19981
+ name->ob_type->tp_name);
19987
+ len = strlen(fieldname) + strlen(fieldfmt);
19989
+ buf = PyMem_Malloc(len + 2 + 1);
19990
+ if (buf == NULL) {
19992
+ PyErr_NoMemory();
19995
sprintf(buf, "%s:%s:", fieldfmt, fieldname);
19997
ptr = stgdict->format;
19998
stgdict->format = _ctypes_alloc_format_string(stgdict->format, buf);
20002
if (stgdict->format == NULL) {
20004
diff -r 8527427914a2 Modules/_elementtree.c
20005
--- a/Modules/_elementtree.c
20006
+++ b/Modules/_elementtree.c
20007
@@ -2915,19 +2915,25 @@
20009
"class ElementTree(ET.ElementTree):\n" /* public */
20010
" def parse(self, source, parser=None):\n"
20011
+ " close_source = False\n"
20012
" if not hasattr(source, 'read'):\n"
20013
" source = open(source, 'rb')\n"
20014
- " if parser is not None:\n"
20016
- " data = source.read(65536)\n"
20017
- " if not data:\n"
20019
- " parser.feed(data)\n"
20020
- " self._root = parser.close()\n"
20022
- " parser = cElementTree.XMLParser()\n"
20023
- " self._root = parser._parse(source)\n"
20024
- " return self._root\n"
20025
+ " close_source = False\n"
20027
+ " if parser is not None:\n"
20029
+ " data = source.read(65536)\n"
20030
+ " if not data:\n"
20032
+ " parser.feed(data)\n"
20033
+ " self._root = parser.close()\n"
20035
+ " parser = cElementTree.XMLParser()\n"
20036
+ " self._root = parser._parse(source)\n"
20037
+ " return self._root\n"
20039
+ " if close_source:\n"
20040
+ " source.close()\n"
20041
"cElementTree.ElementTree = ElementTree\n"
20043
"def iter(node, tag=None):\n" /* helper */
20044
@@ -2957,11 +2963,14 @@
20045
"class iterparse(object):\n"
20047
" def __init__(self, file, events=None):\n"
20048
+ " self._close_file = False\n"
20049
" if not hasattr(file, 'read'):\n"
20050
" file = open(file, 'rb')\n"
20051
+ " self._close_file = True\n"
20052
" self._file = file\n"
20053
" self._events = []\n"
20054
" self._index = 0\n"
20055
+ " self._error = None\n"
20056
" self.root = self._root = None\n"
20057
" b = cElementTree.TreeBuilder()\n"
20058
" self._parser = cElementTree.XMLParser(b)\n"
20059
@@ -2970,22 +2979,31 @@
20062
" item = self._events[self._index]\n"
20063
+ " self._index += 1\n"
20065
" except IndexError:\n"
20066
- " if self._parser is None:\n"
20067
- " self.root = self._root\n"
20068
- " raise StopIteration\n"
20069
- " # load event buffer\n"
20070
- " del self._events[:]\n"
20071
- " self._index = 0\n"
20072
- " data = self._file.read(16384)\n"
20075
+ " if self._error:\n"
20076
+ " e = self._error\n"
20077
+ " self._error = None\n"
20079
+ " if self._parser is None:\n"
20080
+ " self.root = self._root\n"
20081
+ " if self._close_file:\n"
20082
+ " self._file.close()\n"
20083
+ " raise StopIteration\n"
20084
+ " # load event buffer\n"
20085
+ " del self._events[:]\n"
20086
+ " self._index = 0\n"
20087
+ " data = self._file.read(16384)\n"
20090
" self._parser.feed(data)\n"
20092
- " self._root = self._parser.close()\n"
20093
- " self._parser = None\n"
20094
+ " except SyntaxError as exc:\n"
20095
+ " self._error = exc\n"
20097
- " self._index = self._index + 1\n"
20099
+ " self._root = self._parser.close()\n"
20100
+ " self._parser = None\n"
20101
" def __iter__(self):\n"
20103
"cElementTree.iterparse = iterparse\n"
20104
diff -r 8527427914a2 Modules/_io/bufferedio.c
20105
--- a/Modules/_io/bufferedio.c
20106
+++ b/Modules/_io/bufferedio.c
20107
@@ -550,7 +550,7 @@
20109
/* Forward decls */
20111
-_bufferedwriter_flush_unlocked(buffered *, int);
20112
+_bufferedwriter_flush_unlocked(buffered *);
20114
_bufferedreader_fill_buffer(buffered *self);
20116
@@ -571,6 +571,18 @@
20120
+/* Sets the current error to BlockingIOError */
20122
+_set_BlockingIOError(char *msg, Py_ssize_t written)
20125
+ err = PyObject_CallFunction(PyExc_BlockingIOError, "isn",
20126
+ errno, msg, written);
20128
+ PyErr_SetObject(PyExc_BlockingIOError, err);
20132
/* Returns the address of the `written` member if a BlockingIOError was
20133
raised, NULL otherwise. The error is always re-raised. */
20134
static Py_ssize_t *
20135
@@ -721,6 +733,28 @@
20139
+buffered_flush_and_rewind_unlocked(buffered *self)
20143
+ res = _bufferedwriter_flush_unlocked(self);
20148
+ if (self->readable) {
20149
+ /* Rewind the raw stream so that its position corresponds to
20150
+ the current logical position. */
20152
+ n = _buffered_raw_seek(self, -RAW_OFFSET(self), 1);
20153
+ _bufferedreader_reset_buf(self);
20161
buffered_flush(buffered *self, PyObject *args)
20164
@@ -730,16 +764,7 @@
20166
if (!ENTER_BUFFERED(self))
20168
- res = _bufferedwriter_flush_unlocked(self, 0);
20169
- if (res != NULL && self->readable) {
20170
- /* Rewind the raw stream so that its position corresponds to
20171
- the current logical position. */
20173
- n = _buffered_raw_seek(self, -RAW_OFFSET(self), 1);
20176
- _bufferedreader_reset_buf(self);
20178
+ res = buffered_flush_and_rewind_unlocked(self);
20179
LEAVE_BUFFERED(self)
20182
@@ -760,7 +785,7 @@
20185
if (self->writable) {
20186
- res = _bufferedwriter_flush_unlocked(self, 1);
20187
+ res = buffered_flush_and_rewind_unlocked(self);
20191
@@ -795,19 +820,18 @@
20192
if (!ENTER_BUFFERED(self))
20194
res = _bufferedreader_read_all(self);
20195
- LEAVE_BUFFERED(self)
20198
res = _bufferedreader_read_fast(self, n);
20199
- if (res == Py_None) {
20201
- if (!ENTER_BUFFERED(self))
20203
- res = _bufferedreader_read_generic(self, n);
20204
- LEAVE_BUFFERED(self)
20206
+ if (res != Py_None)
20209
+ if (!ENTER_BUFFERED(self))
20211
+ res = _bufferedreader_read_generic(self, n);
20214
+ LEAVE_BUFFERED(self)
20218
@@ -833,13 +857,6 @@
20219
if (!ENTER_BUFFERED(self))
20222
- if (self->writable) {
20223
- res = _bufferedwriter_flush_unlocked(self, 1);
20229
/* Return up to n bytes. If at least one byte is buffered, we
20230
only return buffered bytes. Otherwise, we do one raw read. */
20232
@@ -859,6 +876,13 @@
20236
+ if (self->writable) {
20237
+ res = buffered_flush_and_rewind_unlocked(self);
20243
/* Fill the buffer from the raw stream, and copy it to the result. */
20244
_bufferedreader_reset_buf(self);
20245
r = _bufferedreader_fill_buffer(self);
20246
@@ -881,24 +905,10 @@
20248
buffered_readinto(buffered *self, PyObject *args)
20250
- PyObject *res = NULL;
20252
CHECK_INITIALIZED(self)
20254
- /* TODO: use raw.readinto() instead! */
20255
- if (self->writable) {
20256
- if (!ENTER_BUFFERED(self))
20258
- res = _bufferedwriter_flush_unlocked(self, 0);
20259
- LEAVE_BUFFERED(self)
20264
- res = bufferediobase_readinto((PyObject *)self, args);
20268
+ /* TODO: use raw.readinto() (or a direct copy from our buffer) instead! */
20269
+ return bufferediobase_readinto((PyObject *)self, args);
20273
@@ -936,12 +946,6 @@
20276
/* Now we try to get some more from the raw stream */
20277
- if (self->writable) {
20278
- res = _bufferedwriter_flush_unlocked(self, 1);
20283
chunks = PyList_New(0);
20284
if (chunks == NULL)
20286
@@ -955,9 +959,16 @@
20294
+ if (self->writable) {
20295
+ PyObject *r = buffered_flush_and_rewind_unlocked(self);
20302
_bufferedreader_reset_buf(self);
20303
@@ -1088,7 +1099,7 @@
20305
/* Fallback: invoke raw seek() method and clear buffer */
20306
if (self->writable) {
20307
- res = _bufferedwriter_flush_unlocked(self, 0);
20308
+ res = _bufferedwriter_flush_unlocked(self);
20312
@@ -1126,20 +1137,11 @@
20315
if (self->writable) {
20316
- res = _bufferedwriter_flush_unlocked(self, 0);
20317
+ res = buffered_flush_and_rewind_unlocked(self);
20322
- if (self->readable) {
20323
- if (pos == Py_None) {
20324
- /* Rewind the raw stream so that its position corresponds to
20325
- the current logical position. */
20326
- if (_buffered_raw_seek(self, -RAW_OFFSET(self), 1) == -1)
20329
- _bufferedreader_reset_buf(self);
20331
res = PyObject_CallMethodObjArgs(self->raw, _PyIO_str_truncate, pos, NULL);
20334
@@ -1341,17 +1343,18 @@
20338
+ self->pos += current_size;
20340
- _bufferedreader_reset_buf(self);
20341
/* We're going past the buffer's bounds, flush it */
20342
if (self->writable) {
20343
- res = _bufferedwriter_flush_unlocked(self, 1);
20344
+ res = buffered_flush_and_rewind_unlocked(self);
20351
+ _bufferedreader_reset_buf(self);
20354
if (PyList_Append(chunks, data) < 0) {
20355
@@ -1434,6 +1437,14 @@
20356
memcpy(out, self->buffer + self->pos, current_size);
20357
remaining -= current_size;
20358
written += current_size;
20359
+ self->pos += current_size;
20361
+ /* Flush the write buffer if necessary */
20362
+ if (self->writable) {
20363
+ PyObject *r = buffered_flush_and_rewind_unlocked(self);
20368
_bufferedreader_reset_buf(self);
20369
while (remaining > 0) {
20370
@@ -1684,6 +1695,7 @@
20372
PyObject *memobj, *res;
20375
/* NOTE: the buffer needn't be released as its object is NULL. */
20376
if (PyBuffer_FillInfo(&buf, NULL, start, len, 1, PyBUF_CONTIG_RO) == -1)
20378
@@ -1696,11 +1708,21 @@
20379
raised (see issue #10956).
20383
res = PyObject_CallMethodObjArgs(self->raw, _PyIO_str_write, memobj, NULL);
20385
} while (res == NULL && _trap_eintr());
20389
+ if (res == Py_None) {
20390
+ /* Non-blocking stream would have blocked. Special return code!
20391
+ Being paranoid we reset errno in case it is changed by code
20392
+ triggered by a decref. errno is used by _set_BlockingIOError(). */
20397
n = PyNumber_AsSsize_t(res, PyExc_ValueError);
20399
if (n < 0 || n > len) {
20400
@@ -1717,7 +1739,7 @@
20401
/* `restore_pos` is 1 if we need to restore the raw stream position at
20402
the end, 0 otherwise. */
20404
-_bufferedwriter_flush_unlocked(buffered *self, int restore_pos)
20405
+_bufferedwriter_flush_unlocked(buffered *self)
20407
Py_ssize_t written = 0;
20408
Py_off_t n, rewind;
20409
@@ -1739,14 +1761,11 @@
20410
Py_SAFE_DOWNCAST(self->write_end - self->write_pos,
20411
Py_off_t, Py_ssize_t));
20413
- Py_ssize_t *w = _buffered_check_blocking_error();
20416
- self->write_pos += *w;
20417
- self->raw_pos = self->write_pos;
20420
- /* Already re-raised */
20423
+ else if (n == -2) {
20424
+ _set_BlockingIOError("write could not complete without blocking",
20428
self->write_pos += n;
20429
@@ -1759,16 +1778,6 @@
20433
- if (restore_pos) {
20434
- Py_off_t forward = rewind - written;
20435
- if (forward != 0) {
20436
- n = _buffered_raw_seek(self, forward, 1);
20440
- self->raw_pos += forward;
20443
_bufferedwriter_reset_buf(self);
20446
@@ -1821,7 +1830,7 @@
20449
/* First write the current buffer */
20450
- res = _bufferedwriter_flush_unlocked(self, 0);
20451
+ res = _bufferedwriter_flush_unlocked(self);
20453
Py_ssize_t *w = _buffered_check_blocking_error();
20455
@@ -1844,14 +1853,19 @@
20457
memcpy(self->buffer + self->write_end, buf.buf, buf.len);
20458
self->write_end += buf.len;
20459
+ self->pos += buf.len;
20463
/* Buffer as much as possible. */
20464
memcpy(self->buffer + self->write_end, buf.buf, avail);
20465
self->write_end += avail;
20466
- /* Already re-raised */
20468
+ self->pos += avail;
20469
+ /* XXX Modifying the existing exception e using the pointer w
20470
+ will change e.characters_written but not e.args[2].
20471
+ Therefore we just replace with a new error. */
20472
+ _set_BlockingIOError("write could not complete without blocking",
20477
@@ -1876,11 +1890,9 @@
20478
Py_ssize_t n = _bufferedwriter_raw_write(
20479
self, (char *) buf.buf + written, buf.len - written);
20481
- Py_ssize_t *w = _buffered_check_blocking_error();
20487
+ } else if (n == -2) {
20488
+ /* Write failed because raw file is non-blocking */
20489
if (remaining > self->buffer_size) {
20490
/* Can't buffer everything, still buffer as much as possible */
20491
memcpy(self->buffer,
20492
@@ -1888,8 +1900,9 @@
20494
ADJUST_POSITION(self, self->buffer_size);
20495
self->write_end = self->buffer_size;
20496
- *w = written + self->buffer_size;
20497
- /* Already re-raised */
20498
+ written += self->buffer_size;
20499
+ _set_BlockingIOError("write could not complete without "
20500
+ "blocking", written);
20504
@@ -2180,6 +2193,11 @@
20506
bufferedrwpair_closed_get(rwpair *self, void *context)
20508
+ if (self->writer == NULL) {
20509
+ PyErr_SetString(PyExc_RuntimeError,
20510
+ "the BufferedRWPair object is being garbage-collected");
20513
return PyObject_GetAttr((PyObject *) self->writer, _PyIO_str_closed);
8307
20516
diff -r 8527427914a2 Modules/_io/fileio.c
8308
20517
--- a/Modules/_io/fileio.c
8309
20518
+++ b/Modules/_io/fileio.c
20520
#define SMALLCHUNK BUFSIZ
20523
-#if SIZEOF_INT < 4
20524
-#define BIGCHUNK (512 * 32)
20526
-#define BIGCHUNK (512 * 1024)
20532
@@ -474,7 +468,7 @@
8311
20533
fileio_readinto(fileio *self, PyObject *args)
8313
20535
Py_buffer pbuf;
8394
20636
Py_TYPE(obj)->tp_name);
20639
diff -r 8527427914a2 Modules/_multiprocessing/multiprocessing.c
20640
--- a/Modules/_multiprocessing/multiprocessing.c
20641
+++ b/Modules/_multiprocessing/multiprocessing.c
20642
@@ -97,32 +97,38 @@
20643
/* Functions for transferring file descriptors between processes.
20644
Reimplements some of the functionality of the fdcred
20645
module at http://www.mca-ltd.com/resources/fdcred_1.tgz. */
20646
+/* Based in http://resin.csoft.net/cgi-bin/man.cgi?section=3&topic=CMSG_DATA */
20649
multiprocessing_sendfd(PyObject *self, PyObject *args)
20652
+ struct iovec dummy_iov;
20654
- char buf[CMSG_SPACE(sizeof(int))];
20655
- struct msghdr msg = {0};
20656
- struct iovec dummy_iov;
20657
+ struct msghdr msg;
20658
struct cmsghdr *cmsg;
20660
+ struct cmsghdr hdr;
20661
+ unsigned char buf[CMSG_SPACE(sizeof(int))];
20664
if (!PyArg_ParseTuple(args, "ii", &conn, &fd))
20667
dummy_iov.iov_base = &dummy_char;
20668
dummy_iov.iov_len = 1;
20669
- msg.msg_control = buf;
20670
- msg.msg_controllen = sizeof(buf);
20672
+ memset(&msg, 0, sizeof(msg));
20673
+ msg.msg_control = &cmsgbuf.buf;
20674
+ msg.msg_controllen = sizeof(cmsgbuf.buf);
20675
msg.msg_iov = &dummy_iov;
20676
msg.msg_iovlen = 1;
20678
cmsg = CMSG_FIRSTHDR(&msg);
20679
+ cmsg->cmsg_len = CMSG_LEN(sizeof(int));
20680
cmsg->cmsg_level = SOL_SOCKET;
20681
cmsg->cmsg_type = SCM_RIGHTS;
20682
- cmsg->cmsg_len = CMSG_LEN(sizeof(int));
20683
- msg.msg_controllen = cmsg->cmsg_len;
20684
- *CMSG_DATA(cmsg) = fd;
20685
+ * (int *) CMSG_DATA(cmsg) = fd;
20687
Py_BEGIN_ALLOW_THREADS
20688
res = sendmsg(conn, &msg, 0);
20689
@@ -138,20 +144,26 @@
20693
- char buf[CMSG_SPACE(sizeof(int))];
20694
+ struct iovec dummy_iov;
20695
struct msghdr msg = {0};
20696
- struct iovec dummy_iov;
20697
struct cmsghdr *cmsg;
20699
+ struct cmsghdr hdr;
20700
+ unsigned char buf[CMSG_SPACE(sizeof(int))];
20703
if (!PyArg_ParseTuple(args, "i", &conn))
20706
dummy_iov.iov_base = &dummy_char;
20707
dummy_iov.iov_len = 1;
20708
- msg.msg_control = buf;
20709
- msg.msg_controllen = sizeof(buf);
20711
+ memset(&msg, 0, sizeof(msg));
20712
+ msg.msg_control = &cmsgbuf.buf;
20713
+ msg.msg_controllen = sizeof(cmsgbuf.buf);
20714
msg.msg_iov = &dummy_iov;
20715
msg.msg_iovlen = 1;
20717
cmsg = CMSG_FIRSTHDR(&msg);
20718
cmsg->cmsg_level = SOL_SOCKET;
20719
cmsg->cmsg_type = SCM_RIGHTS;
20720
@@ -165,7 +177,18 @@
20722
return PyErr_SetFromErrno(PyExc_OSError);
20724
- fd = *CMSG_DATA(cmsg);
20725
+ if (msg.msg_controllen < CMSG_LEN(sizeof(int)) ||
20726
+ (cmsg = CMSG_FIRSTHDR(&msg)) == NULL ||
20727
+ cmsg->cmsg_level != SOL_SOCKET ||
20728
+ cmsg->cmsg_type != SCM_RIGHTS ||
20729
+ cmsg->cmsg_len < CMSG_LEN(sizeof(int))) {
20730
+ /* If at least one control message is present, there should be
20731
+ no room for any further data in the buffer. */
20732
+ PyErr_SetString(PyExc_RuntimeError, "No file descriptor received");
20736
+ fd = * (int *) CMSG_DATA(cmsg);
20737
return Py_BuildValue("i", fd);
20740
diff -r 8527427914a2 Modules/_sqlite/cursor.c
20741
--- a/Modules/_sqlite/cursor.c
20742
+++ b/Modules/_sqlite/cursor.c
20747
- while (isalpha(*src) && dst - buf < sizeof(buf) - 2) {
20748
- *dst++ = tolower(*src++);
20749
+ while (Py_ISALPHA(*src) && dst - buf < sizeof(buf) - 2) {
20750
+ *dst++ = Py_TOLOWER(*src++);
20754
diff -r 8527427914a2 Modules/_sre.c
20755
--- a/Modules/_sre.c
20756
+++ b/Modules/_sre.c
20757
@@ -2744,7 +2744,7 @@
20758
#if defined(VVERBOSE)
20759
#define VTRACE(v) printf v
20762
+#define VTRACE(v) do {} while(0) /* do nothing */
20765
/* Report failure */
20766
diff -r 8527427914a2 Modules/_ssl.c
20767
--- a/Modules/_ssl.c
20768
+++ b/Modules/_ssl.c
20769
@@ -702,7 +702,7 @@
20770
/* get a memory buffer */
20771
biobuf = BIO_new(BIO_s_mem());
20775
while ((i = X509_get_ext_by_NID(
20776
certificate, NID_subject_alt_name, i)) >= 0) {
20778
@@ -798,6 +798,7 @@
20782
+ sk_GENERAL_NAME_pop_free(names, GENERAL_NAME_free);
20785
if (peer_alt_names != Py_None) {
20786
@@ -1145,10 +1146,8 @@
20789
/* Guard against socket too large for select*/
20790
-#ifndef Py_SOCKET_FD_CAN_BE_GE_FD_SETSIZE
20791
- if (s->sock_fd >= FD_SETSIZE)
20792
+ if (!_PyIsSelectable_fd(s->sock_fd))
20793
return SOCKET_TOO_LARGE_FOR_SELECT;
20796
/* Construct the arguments to select */
20797
tv.tv_sec = (int)s->sock_timeout;
20798
diff -r 8527427914a2 Modules/_testcapimodule.c
20799
--- a/Modules/_testcapimodule.c
20800
+++ b/Modules/_testcapimodule.c
20801
@@ -1106,6 +1106,41 @@
20805
+unicode_encodedecimal(PyObject *self, PyObject *args)
20807
+ Py_UNICODE *unicode;
20809
+ char *errors = NULL;
20810
+ PyObject *decimal;
20811
+ Py_ssize_t decimal_length, new_length;
20814
+ if (!PyArg_ParseTuple(args, "u#|s", &unicode, &length, &errors))
20817
+ decimal_length = length * 7; /* len('€') */
20818
+ decimal = PyBytes_FromStringAndSize(NULL, decimal_length);
20819
+ if (decimal == NULL)
20822
+ res = PyUnicode_EncodeDecimal(unicode, length,
20823
+ PyBytes_AS_STRING(decimal),
20826
+ Py_DECREF(decimal);
20830
+ new_length = strlen(PyBytes_AS_STRING(decimal));
20831
+ assert(new_length <= decimal_length);
20832
+ res = _PyBytes_Resize(&decimal, new_length);
20840
test_empty_argparse(PyObject *self)
20842
/* Test that formats can begin with '|'. See issue #4720. */
20843
@@ -1639,6 +1674,19 @@
20844
return PyErr_NewExceptionWithDoc(name, doc, base, dict);
20848
+sequence_delitem(PyObject *self, PyObject *args)
20853
+ if (!PyArg_ParseTuple(args, "On", &seq, &i))
20855
+ if (PySequence_DelItem(seq, i) < 0)
20860
static PyMethodDef TestMethods[] = {
20861
{"raise_exception", raise_exception, METH_VARARGS},
20862
{"test_config", (PyCFunction)test_config, METH_NOARGS},
20863
@@ -1685,6 +1733,7 @@
20864
#ifdef Py_USING_UNICODE
20865
{"test_u_code", (PyCFunction)test_u_code, METH_NOARGS},
20866
{"test_widechar", (PyCFunction)test_widechar, METH_NOARGS},
20867
+ {"unicode_encodedecimal", unicode_encodedecimal, METH_VARARGS},
20870
{"_test_thread_state", test_thread_state, METH_VARARGS},
20871
@@ -1695,6 +1744,7 @@
20872
{"code_newempty", code_newempty, METH_VARARGS},
20873
{"make_exception_with_doc", (PyCFunction)make_exception_with_doc,
20874
METH_VARARGS | METH_KEYWORDS},
20875
+ {"sequence_delitem", (PyCFunction)sequence_delitem, METH_VARARGS},
20876
{NULL, NULL} /* sentinel */
20879
diff -r 8527427914a2 Modules/_tkinter.c
20880
--- a/Modules/_tkinter.c
20881
+++ b/Modules/_tkinter.c
20882
@@ -663,8 +663,8 @@
20885
strcpy(argv0, className);
20886
- if (isupper(Py_CHARMASK(argv0[0])))
20887
- argv0[0] = tolower(Py_CHARMASK(argv0[0]));
20888
+ if (Py_ISUPPER(Py_CHARMASK(argv0[0])))
20889
+ argv0[0] = Py_TOLOWER(Py_CHARMASK(argv0[0]));
20890
Tcl_SetVar(v->interp, "argv0", argv0, TCL_GLOBAL_ONLY);
20893
diff -r 8527427914a2 Modules/binascii.c
20894
--- a/Modules/binascii.c
20895
+++ b/Modules/binascii.c
20896
@@ -1105,8 +1105,8 @@
20902
+ if (Py_ISUPPER(c))
20903
+ c = Py_TOLOWER(c);
20904
if (c >= 'a' && c <= 'f')
20905
return c - 'a' + 10;
20907
diff -r 8527427914a2 Modules/bz2module.c
20908
--- a/Modules/bz2module.c
20909
+++ b/Modules/bz2module.c
20910
@@ -224,25 +224,14 @@
20911
#define SMALLCHUNK BUFSIZ
20914
-#if SIZEOF_INT < 4
20915
-#define BIGCHUNK (512 * 32)
20917
-#define BIGCHUNK (512 * 1024)
20920
/* This is a hacked version of Python's fileobject.c:new_buffersize(). */
20922
Util_NewBufferSize(size_t currentsize)
20924
- if (currentsize > SMALLCHUNK) {
20925
- /* Keep doubling until we reach BIGCHUNK;
20926
- then keep adding BIGCHUNK. */
20927
- if (currentsize <= BIGCHUNK)
20928
- return currentsize + currentsize;
20930
- return currentsize + BIGCHUNK;
20932
- return currentsize + SMALLCHUNK;
20933
+ /* Expand the buffer by an amount proportional to the current size,
20934
+ giving us amortized linear-time behavior. Use a less-than-double
20935
+ growth factor to avoid excessive allocation. */
20936
+ return currentsize + (currentsize >> 3) + 6;
20939
/* This is a hacked version of Python's fileobject.c:get_line(). */
20940
diff -r 8527427914a2 Modules/cPickle.c
20941
--- a/Modules/cPickle.c
20942
+++ b/Modules/cPickle.c
20943
@@ -2697,11 +2697,6 @@
20947
- if (PyType_IsSubtype(type, &PyType_Type)) {
20948
- res = save_global(self, args, NULL);
20952
/* Get a reduction callable, and call it. This may come from
20953
* copy_reg.dispatch_table, the object's __reduce_ex__ method,
20954
* or the object's __reduce__ method.
20955
@@ -2717,6 +2712,11 @@
20959
+ if (PyType_IsSubtype(type, &PyType_Type)) {
20960
+ res = save_global(self, args, NULL);
20964
/* Check for a __reduce_ex__ method. */
20965
__reduce__ = PyObject_GetAttr(args, __reduce_ex___str);
20966
if (__reduce__ != NULL) {
20967
diff -r 8527427914a2 Modules/cStringIO.c
20968
--- a/Modules/cStringIO.c
20969
+++ b/Modules/cStringIO.c
20970
@@ -661,7 +661,11 @@
20974
- if (PyObject_AsReadBuffer(s, (const void **)&buf, &size)) {
20975
+ if (PyUnicode_Check(s)) {
20976
+ if (PyObject_AsCharBuffer(s, (const char **)&buf, &size) != 0)
20979
+ else if (PyObject_AsReadBuffer(s, (const void **)&buf, &size)) {
20980
PyErr_Format(PyExc_TypeError, "expected read buffer, %.200s found",
20981
s->ob_type->tp_name);
8397
20983
diff -r 8527427914a2 Modules/cjkcodecs/_codecs_hk.c
8398
20984
--- a/Modules/cjkcodecs/_codecs_hk.c
8399
20985
+++ b/Modules/cjkcodecs/_codecs_hk.c