Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3f419af

Browse files
committed
Merged revisions 59696-59702 via svnmerge from
svn+ssh://[email protected]/python/trunk ........ r59696 | amaury.forgeotdarc | 2008-01-04 03:04:15 +0100 (Fri, 04 Jan 2008) | 11 lines Partial port of r59682 from py3k. On Windows, when import fails to load a dll module, the message says "error code 193" instead of a more informative text. It turns out that FormatMessage needs additional parameters for some error codes. For example: 193 means "%1 is not a valid Win32 application". Since it is impossible to know which parameter to pass, we use FORMAT_MESSAGE_IGNORE_INSERTS to get the raw message, which is still better than the number. ........ r59698 | andrew.kuchling | 2008-01-04 03:26:00 +0100 (Fri, 04 Jan 2008) | 1 line Typo fix ........ r59699 | andrew.kuchling | 2008-01-04 03:31:40 +0100 (Fri, 04 Jan 2008) | 1 line Add math items; other edits ........ r59700 | christian.heimes | 2008-01-04 03:46:19 +0100 (Fri, 04 Jan 2008) | 1 line Fixed refleak tests for _struct changes ........ r59701 | christian.heimes | 2008-01-04 03:54:42 +0100 (Fri, 04 Jan 2008) | 1 line Added _struct._clearcache() for regression tests ........
1 parent a34706f commit 3f419af

2 files changed

Lines changed: 46 additions & 112 deletions

File tree

Doc/whatsnew/2.6.rst

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,32 @@ PEP 3119: Abstract Base Classes
483483

484484
XXX
485485

486+
How to identify a file object?
487+
488+
ABCs are a collection of classes describing various interfaces.
489+
Classes can derive from an ABC to indicate they support that ABC's
490+
interface. Concrete classes should obey the semantics specified by
491+
an ABC, but Python can't check this; it's up to the implementor.
492+
493+
A metaclass lets you declare that an existing class or type
494+
derives from a particular ABC. You can even
495+
496+
class AppendableSequence:
497+
__metaclass__ = ABCMeta
498+
499+
AppendableSequence.register(list)
500+
assert issubclass(list, AppendableSequence)
501+
assert isinstance([], AppendableSequence)
502+
503+
@abstractmethod decorator -- you can't instantiate classes w/
504+
an abstract method.
505+
506+
@abstractproperty decorator
507+
@abstractproperty
508+
def readonly(self):
509+
return self._x
510+
511+
486512
.. seealso::
487513

488514
:pep:`3119` - Introducing Abstract Base Classes
@@ -554,12 +580,22 @@ Here are all of the changes that Python 2.6 makes to the core Python language.
554580
555581
* More floating-point features were also added. The :func:`float` function
556582
will now turn the strings ``+nan`` and ``-nan`` into the corresponding
557-
IEEE 754 Not a Number values, and ``+inf`` and ``-inf`` into
583+
IEEE 754 Not A Number values, and ``+inf`` and ``-inf`` into
558584
positive or negative infinity. This works on any platform with
559585
IEEE 754 semantics. (Contributed by Christian Heimes.)
560586

561587
.. Patch 1635.
562588
589+
Other functions in the :mod:`math` module, :func:`isinf` and
590+
:func:`isnan`, return true if their floating-point argument is
591+
infinite or Not A Number.
592+
.. Patch 1640
593+
The ``math.copysign(x, y)`` function
594+
copies the sign bit of an IEEE 754 number, returning the absolute
595+
value of *x* combined with the sign bit of *y*. For example,
596+
``math.copysign(1, -0.0)`` returns -1.0. (Contributed by Christian
597+
Heimes.)
598+
563599
* Changes to the :class:`Exception` interface
564600
as dictated by :pep:`352` continue to be made. For 2.6,
565601
the :attr:`message` attribute is being deprecated in favor of the
@@ -612,6 +648,10 @@ Here are all of the changes that Python 2.6 makes to the core Python language.
612648
Optimizations
613649
-------------
614650

651+
* All of the functions in the :mod:`struct` module have been rewritten in
652+
C, thanks to work at the Need For Speed sprint.
653+
(Contributed by Raymond Hettinger.)
654+
615655
* Internally, a bit is now set in type objects to indicate some of the standard
616656
built-in types. This speeds up checking if an object is a subclass of one of
617657
these types. (Contributed by Neal Norwitz.)
@@ -1074,12 +1114,13 @@ Changes to Python's build process and to the C API include:
10741114

10751115
.. Issue 1635
10761116
1077-
* Some macros were renamed. :cmacro:`Py_Size()` became :cmacro:`Py_SIZE()`,
1117+
* Some macros were renamed to make it clearer that they are macros,
1118+
not functions. :cmacro:`Py_Size()` became :cmacro:`Py_SIZE()`,
10781119
:cmacro:`Py_Type()` became :cmacro:`Py_TYPE()`, and
10791120
:cmacro:`Py_Refcnt()` became :cmacro:`Py_REFCNT()`. Macros for backward
10801121
compatibility are still available for Python 2.6.
10811122

1082-
.. Issue 1629: XXX why was this done?
1123+
.. Issue 1629
10831124
10841125
.. ======================================================================
10851126

Lib/struct.py

Lines changed: 2 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -1,109 +1,2 @@
1-
"""
2-
Functions to convert between Python values and C structs.
3-
Python strings are used to hold the data representing the C struct
4-
and also as format strings to describe the layout of data in the C struct.
5-
6-
The optional first format char indicates byte order, size and alignment:
7-
@: native order, size & alignment (default)
8-
=: native order, std. size & alignment
9-
<: little-endian, std. size & alignment
10-
>: big-endian, std. size & alignment
11-
!: same as >
12-
13-
The remaining chars indicate types of args and must match exactly;
14-
these can be preceded by a decimal repeat count:
15-
x: pad byte (no data); c:char; b:signed byte; B:unsigned byte;
16-
h:short; H:unsigned short; i:int; I:unsigned int;
17-
l:long; L:unsigned long; f:float; d:double.
18-
Special cases (preceding decimal count indicates length):
19-
s:string (array of char); p: pascal string (with count byte).
20-
Special case (only available in native format):
21-
P:an integer type that is wide enough to hold a pointer.
22-
Special case (not in native mode unless 'long long' in platform C):
23-
q:long long; Q:unsigned long long
24-
Whitespace between formats is ignored.
25-
26-
The variable struct.error is an exception raised on errors.
27-
"""
28-
29-
__version__ = '3.0'
30-
31-
32-
from _struct import Struct as _Struct, error
33-
34-
class Struct(_Struct):
35-
def __init__(self, fmt):
36-
if isinstance(fmt, str):
37-
fmt = bytes(fmt, 'ascii')
38-
elif isinstance(fmt, buffer):
39-
fmt = bytes(fmt)
40-
_Struct.__init__(self, fmt)
41-
42-
_MAXCACHE = 100
43-
_cache = {}
44-
45-
def _compile(fmt):
46-
# Internal: compile struct pattern
47-
if len(_cache) >= _MAXCACHE:
48-
_cache.clear()
49-
s = Struct(fmt)
50-
_cache[fmt] = s
51-
return s
52-
53-
def calcsize(fmt):
54-
"""
55-
Return size of C struct described by format string fmt.
56-
See struct.__doc__ for more on format strings.
57-
"""
58-
try:
59-
o = _cache[fmt]
60-
except KeyError:
61-
o = _compile(fmt)
62-
return o.size
63-
64-
def pack(fmt, *args):
65-
"""
66-
Return string containing values v1, v2, ... packed according to fmt.
67-
See struct.__doc__ for more on format strings.
68-
"""
69-
try:
70-
o = _cache[fmt]
71-
except KeyError:
72-
o = _compile(fmt)
73-
return bytes(o.pack(*args))
74-
75-
def pack_into(fmt, buf, offset, *args):
76-
"""
77-
Pack the values v1, v2, ... according to fmt, write
78-
the packed bytes into the writable buffer buf starting at offset.
79-
See struct.__doc__ for more on format strings.
80-
"""
81-
try:
82-
o = _cache[fmt]
83-
except KeyError:
84-
o = _compile(fmt)
85-
o.pack_into(buf, offset, *args)
86-
87-
def unpack(fmt, s):
88-
"""
89-
Unpack the string, containing packed C structure data, according
90-
to fmt. Requires len(string)==calcsize(fmt).
91-
See struct.__doc__ for more on format strings.
92-
"""
93-
try:
94-
o = _cache[fmt]
95-
except KeyError:
96-
o = _compile(fmt)
97-
return o.unpack(s)
98-
99-
def unpack_from(fmt, buf, offset=0):
100-
"""
101-
Unpack the buffer, containing packed C structure data, according to
102-
fmt starting at offset. Requires len(buffer[offset:]) >= calcsize(fmt).
103-
See struct.__doc__ for more on format strings.
104-
"""
105-
try:
106-
o = _cache[fmt]
107-
except KeyError:
108-
o = _compile(fmt)
109-
return o.unpack_from(buf, offset)
1+
from _struct import *
2+
from _struct import _clearcache

0 commit comments

Comments
 (0)