Commit b9eccbfe authored by Christian Heimes's avatar Christian Heimes

Merged revisions 59333-59370 via svnmerge from

svn+ssh://pythondev@svn.python.org/python/trunk

........
  r59343 | georg.brandl | 2007-12-05 08:02:47 +0100 (Wed, 05 Dec 2007) | 2 lines

  Fix typo.
........
  r59347 | christian.heimes | 2007-12-05 13:31:44 +0100 (Wed, 05 Dec 2007) | 1 line

  Fixed quoting and paths in the sqlite project file
........
  r59348 | christian.heimes | 2007-12-05 13:45:11 +0100 (Wed, 05 Dec 2007) | 1 line

  Fixed error in regrtest. I must have missed the spot.
........
  r59350 | christian.heimes | 2007-12-05 13:49:14 +0100 (Wed, 05 Dec 2007) | 1 line

  merge -r59315:59316 from py3k: Fix issue #1553: An errornous __length_hint__ can make list() raise a SystemError
........
  r59352 | christian.heimes | 2007-12-05 13:52:34 +0100 (Wed, 05 Dec 2007) | 1 line

  Added msg to Misc/NEWS
........
  r59354 | andrew.kuchling | 2007-12-05 14:27:20 +0100 (Wed, 05 Dec 2007) | 1 line

  Spelling fix
........
  r59356 | georg.brandl | 2007-12-05 18:56:50 +0100 (Wed, 05 Dec 2007) | 3 lines

  Add examples to csv, pprint and traceback docs.
  Written by Ross for GHOP.
........
  r59358 | raymond.hettinger | 2007-12-05 19:11:08 +0100 (Wed, 05 Dec 2007) | 1 line

  Error checking was too aggressive (reported by Chris Tismer)
........
  r59359 | georg.brandl | 2007-12-05 19:30:48 +0100 (Wed, 05 Dec 2007) | 2 lines

  Add examples to re docs. Written for GHOP by Dan Finnie.
........
  r59366 | georg.brandl | 2007-12-05 20:49:21 +0100 (Wed, 05 Dec 2007) | 2 lines

  Fix markup.
........
  r59367 | christian.heimes | 2007-12-05 20:57:54 +0100 (Wed, 05 Dec 2007) | 1 line

  Updated documentation and build_tkinter.py script
........
  r59368 | georg.brandl | 2007-12-05 21:03:57 +0100 (Wed, 05 Dec 2007) | 2 lines

  Another markup fix.
........
  r59369 | ronald.oussoren | 2007-12-05 21:07:36 +0100 (Wed, 05 Dec 2007) | 7 lines

  This "fixes" compilation issues for the Carbon._OSA module on OSX Leopard
  by purging bindings to OSA's debug API's. Those APIs we're completely
  unsupported on OSX 10.4 and are no longer available on OSX 10.5.

  Note that this patches a generated file. This is somewhat acceptable because
  regenerating the file is non-trivial and wouldn't use system headers anyway.
........
  r59370 | christian.heimes | 2007-12-05 21:10:38 +0100 (Wed, 05 Dec 2007) | 1 line

  Fixed bug #1557 by using popen.communicate() before popen.wait()
........
parent a5ea385b
......@@ -48,6 +48,7 @@ docs@python.org), and we'll be glad to correct the problem.
* Carey Evans
* Martijn Faassen
* Carl Feynman
* Dan Finnie
* Hernán Martínez Foffani
* Stefan Franke
* Jim Fulton
......
......@@ -63,9 +63,9 @@ objects.
The following functions are for runtime dynamic embedding of Python:
``Py_IncRef(PyObject \*o)``, `Py_DecRef(PyObject \*o)``. They are simply
exported function versions of :cfunc:`Py_XINCREF` and :cfunc:`Py_XDECREF`,
respectively.
``Py_IncRef(PyObject *o)``, ``Py_DecRef(PyObject *o)``. They are
simply exported function versions of :cfunc:`Py_XINCREF` and
:cfunc:`Py_XDECREF`, respectively.
The following functions or macros are only for use within the interpreter core:
:cfunc:`_Py_Dealloc`, :cfunc:`_Py_ForgetReference`, :cfunc:`_Py_NewReference`,
......
......@@ -183,8 +183,8 @@ directories renamed as follows:
* :file:`ext` -> :file:`extending`
* :file:`inst` -> :file:`installing`
* :file:`lib` -> :file:`library`
* :file:`mac` -> merged into :file:`library`, with `mac/using.tex`
moved to `howto/pythonmac.rst`
* :file:`mac` -> merged into :file:`library`, with :file:`mac/using.tex`
moved to :file:`howto/pythonmac.rst`
* :file:`ref` -> :file:`reference`
* :file:`tut` -> :file:`tutorial`, with the single TeX file split up
......
......@@ -43,8 +43,6 @@ using the :class:`DictReader` and :class:`DictWriter` classes.
.. seealso::
.. % \seemodule{array}{Arrays of uniformly types numeric values.}
:pep:`305` - CSV File API
The Python Enhancement Proposal which proposed this addition to Python.
......@@ -83,6 +81,15 @@ The :mod:`csv` module defines the following functions:
consequence, if newlines embedded within fields are important, the input should
be split into lines in a manner which preserves the newline characters.
A short usage example::
>>> import csv
>>> spamReader = csv.reader(open('eggs.csv'), delimiter=' ', quotechar='|')
>>> for row in spamReader:
... print ', '.join(row)
Spam, Spam, Spam, Spam, Spam, Baked Beans
Spam, Lovely Spam, Wonderful Spam
.. function:: writer(csvfile[, dialect='excel'][, fmtparam])
......@@ -103,6 +110,14 @@ The :mod:`csv` module defines the following functions:
CSV files without preprocessing the data returned from a ``cursor.fetch*`` call.
All other non-string data are stringified with :func:`str` before being written.
A short usage example::
>>> import csv
>>> spamWriter = csv.writer(open('eggs.csv', 'w'), delimiter=' ',
... quotechar='|', quoting=QUOTE_MINIMAL)
>>> spamWriter.writerow(['Spam'] * 5 + ['Baked Beans'])
>>> spamWriter.writerow(['Spam', 'Lovely Spam', 'Wonderful Spam'])
.. function:: register_dialect(name[, dialect][, fmtparam])
......
......@@ -45,30 +45,23 @@ The :mod:`pprint` module defines one class:
structure cannot be formatted within the constrained width, a best effort will
be made. ::
>>> import pprint, sys
>>> stuff = sys.path[:]
>>> import pprint
>>> stuff = ['spam', 'eggs', 'lumberjack', 'knights', 'ni']
>>> stuff.insert(0, stuff[:])
>>> pp = pprint.PrettyPrinter(indent=4)
>>> pp.pprint(stuff)
[ [ '',
'/usr/local/lib/python1.5',
'/usr/local/lib/python1.5/test',
'/usr/local/lib/python1.5/sunos5',
'/usr/local/lib/python1.5/sharedmodules',
'/usr/local/lib/python1.5/tkinter'],
'',
'/usr/local/lib/python1.5',
'/usr/local/lib/python1.5/test',
'/usr/local/lib/python1.5/sunos5',
'/usr/local/lib/python1.5/sharedmodules',
'/usr/local/lib/python1.5/tkinter']
>>>
>>> import parser
>>> tup = parser.ast2tuple(
... parser.suite(open('pprint.py').read()))[1][1][1]
[ ['spam', 'eggs', 'lumberjack', 'knights', 'ni'],
'spam',
'eggs',
'lumberjack',
'knights',
'ni']
>>> tup = ('spam', ('eggs', ('lumberjack', ('knights', ('ni', ('dead',
... ('parrot', ('fresh fruit',))))))))
>>> pp = pprint.PrettyPrinter(depth=6)
>>> pp.pprint(tup)
(266, (267, (307, (287, (288, (...))))))
('spam',
('eggs', ('lumberjack', ('knights', ('ni', ('dead', ('parrot', (...,))))))))
The :class:`PrettyPrinter` class supports several derivative functions:
......@@ -91,7 +84,8 @@ The :class:`PrettyPrinter` class supports several derivative functions:
within a scope). *indent*, *width* and *depth* will be passed to the
:class:`PrettyPrinter` constructor as formatting parameters. ::
>>> stuff = sys.path[:]
>>> import pprint
>>> stuff = ['spam', 'eggs', 'lumberjack', 'knights', 'ni']
>>> stuff.insert(0, stuff)
>>> pprint.pprint(stuff)
[<Recursion on list with id=869440>,
......@@ -200,3 +194,40 @@ are converted to strings. The default implementation uses the internals of the
is no requested limit. This argument should be passed unmodified to recursive
calls. The fourth argument, *level*, gives the current level; recursive calls
should be passed a value less than that of the current call.
.. _pprint-example:
pprint Example
--------------
This example demonstrates several uses of the :func:`pprint` function and its parameters.
>>> import pprint
>>> tup = ('spam', ('eggs', ('lumberjack', ('knights', ('ni', ('dead',
... ('parrot', ('fresh fruit',))))))))
>>> stuff = ['a' * 10, tup, ['a' * 30, 'b' * 30], ['c' * 20, 'd' * 20]]
>>> pprint.pprint(stuff)
['aaaaaaaaaa',
('spam',
('eggs',
('lumberjack',
('knights', ('ni', ('dead', ('parrot', ('fresh fruit',)))))))),
['aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'],
['cccccccccccccccccccc', 'dddddddddddddddddddd']]
>>> pprint.pprint(stuff, depth=3)
['aaaaaaaaaa',
('spam', ('eggs', ('lumberjack', (...)))),
['aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'],
['cccccccccccccccccccc', 'dddddddddddddddddddd']]
>>> pprint.pprint(stuff, width=60)
['aaaaaaaaaa',
('spam',
('eggs',
('lumberjack',
('knights',
('ni', ('dead', ('parrot', ('fresh fruit',)))))))),
['aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'],
['cccccccccccccccccccc', 'dddddddddddddddddddd']]
This diff is collapsed.
......@@ -132,8 +132,8 @@ The module defines the following functions:
.. _traceback-example:
Traceback Example
-----------------
Traceback Examples
------------------
This simple example implements a basic read-eval-print loop, similar to (but
less useful than) the standard Python interactive interpreter loop. For a more
......@@ -156,3 +156,124 @@ module. ::
while True:
run_user_code(envdir)
The following example demonstrates the different ways to print and format the
exception and traceback::
import sys, traceback
def lumberjack():
bright_side_of_death()
def bright_side_of_death():
return tuple()[0]
try:
lumberjack()
except:
exceptionType, exceptionValue, exceptionTraceback = sys.exc_info()
print "*** print_tb:"
traceback.print_tb(exceptionTraceback, limit=1, file=sys.stdout)
print "*** print_exception:"
traceback.print_exception(exceptionType, exceptionValue, exceptionTraceback,
limit=2, file=sys.stdout)
print "*** print_exc:"
traceback.print_exc()
print "*** format_exc, first and last line:"
formatted_lines = traceback.format_exc().splitlines()
print formatted_lines[0]
print formatted_lines[-1]
print "*** format_exception:"
print repr(traceback.format_exception(exceptionType, exceptionValue,
exceptionTraceback))
print "*** extract_tb:"
print repr(traceback.extract_tb(exceptionTraceback))
print "*** format_tb:"
print repr(traceback.format_tb(exceptionTraceback))
print "*** tb_lineno:", traceback.tb_lineno(exceptionTraceback)
print "*** print_last:"
traceback.print_last()
The output for the example would look similar to this::
*** print_tb:
File "<doctest>", line 9, in <module>
lumberjack()
*** print_exception:
Traceback (most recent call last):
File "<doctest>", line 9, in <module>
lumberjack()
File "<doctest>", line 3, in lumberjack
bright_side_of_death()
IndexError: tuple index out of range
*** print_exc:
Traceback (most recent call last):
File "<doctest>", line 9, in <module>
lumberjack()
File "<doctest>", line 3, in lumberjack
bright_side_of_death()
IndexError: tuple index out of range
*** format_exc, first and last line:
Traceback (most recent call last):
IndexError: tuple index out of range
*** format_exception:
['Traceback (most recent call last):\n',
' File "<doctest>", line 9, in <module>\n lumberjack()\n',
' File "<doctest>", line 3, in lumberjack\n bright_side_of_death()\n',
' File "<doctest>", line 6, in bright_side_of_death\n return tuple()[0]\n',
'IndexError: tuple index out of range\n']
*** extract_tb:
[('<doctest>', 9, '<module>', 'lumberjack()'),
('<doctest>', 3, 'lumberjack', 'bright_side_of_death()'),
('<doctest>', 6, 'bright_side_of_death', 'return tuple()[0]')]
*** format_tb:
[' File "<doctest>", line 9, in <module>\n lumberjack()\n',
' File "<doctest>", line 3, in lumberjack\n bright_side_of_death()\n',
' File "<doctest>", line 6, in bright_side_of_death\n return tuple()[0]\n']
*** tb_lineno: 2
*** print_last:
Traceback (most recent call last):
File "<doctest>", line 9, in <module>
lumberjack()
File "<doctest>", line 3, in lumberjack
bright_side_of_death()
IndexError: tuple index out of range
The following example shows the different ways to print and format the stack::
>>> import traceback
>>> def another_function():
... lumberstack()
...
>>> def lumberstack():
... traceback.print_stack()
... print repr(traceback.extract_stack())
... print repr(traceback.format_stack())
...
>>> another_function()
File "<doctest>", line 10, in <module>
another_function()
File "<doctest>", line 3, in another_function
lumberstack()
File "<doctest>", line 6, in lumberstack
traceback.print_stack()
[('<doctest>', 10, '<module>', 'another_function()'),
('<doctest>', 3, 'another_function', 'lumberstack()'),
('<doctest>', 7, 'lumberstack', 'print repr(traceback.extract_stack())')]
[' File "<doctest>", line 10, in <module>\n another_function()\n',
' File "<doctest>", line 3, in another_function\n lumberstack()\n',
' File "<doctest>", line 8, in lumberstack\n print repr(traceback.format_stack())\n']
This last example demonstrates the final few formatting functions::
>>> import traceback
>>> format_list([('spam.py', 3, '<module>', 'spam.eggs()'),
... ('eggs.py', 42, 'eggs', 'return "bacon"')])
[' File "spam.py", line 3, in <module>\n spam.eggs()\n',
' File "eggs.py", line 42, in eggs\n return "bacon"\n']
>>> theError = IndexError('tuple indx out of range')
>>> traceback.format_exception_only(type(theError), theError)
['IndexError: tuple index out of range\n']
......@@ -40,7 +40,7 @@ def namedtuple(typename, field_names, verbose=False):
field_names = field_names.replace(',', ' ').split() # names separated by whitespace and/or commas
field_names = tuple(field_names)
for name in (typename,) + field_names:
if not name.replace('_', '').isalnum():
if not all(c.isalnum() or c=='_' for c in name):
raise ValueError('Type names and field names can only contain alphanumeric characters and underscores: %r' % name)
if _iskeyword(name):
raise ValueError('Type names and field names cannot be a keyword: %r' % name)
......@@ -48,7 +48,7 @@ def namedtuple(typename, field_names, verbose=False):
raise ValueError('Type names and field names cannot start with a number: %r' % name)
seen_names = set()
for name in field_names:
if name.startswith('__') and name.endswith('__'):
if name.startswith('__') and name.endswith('__') and len(name) > 3:
raise ValueError('Field names cannot start and end with double underscores: %r' % name)
if name in seen_names:
raise ValueError('Encountered duplicate field name: %r' % name)
......
......@@ -254,10 +254,13 @@ def query_vcvarsall(version, arch="x86"):
popen = subprocess.Popen('"%s" %s & set' % (vcvarsall, arch),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stdout, stderr = popen.communicate()
if popen.wait() != 0:
raise IOError(popen.stderr.read())
raise IOError(stderr.decode("mbcs"))
for line in popen.stdout:
stdout = stdout.decode("mbcs")
for line in stdout.split("\n"):
line = Reg.convert_mbcs(line)
if '=' not in line:
continue
......
......@@ -32,6 +32,7 @@ class TestNamedTuple(unittest.TestCase):
self.assertRaises(ValueError, namedtuple, 'abc', 'efg efg ghi') # duplicate field
namedtuple('Point0', 'x1 y2') # Verify that numbers are allowed in names
namedtuple('_', '_ __ ___') # Verify that underscores are allowed
def test_instance(self):
Point = namedtuple('Point', 'x y')
......
This diff is collapsed.
......@@ -12,12 +12,10 @@ import shutil
here = os.path.abspath(os.path.dirname(__file__))
par = os.path.pardir
#TCL = "tcl8.4.16"
#TIX = "Tix8.4.2"
#TK = "tk8.4.16"
TCL = "tcl8.4.12"
TCL = "tcl8.4.16"
TK = "tk8.4.16"
TIX = "Tix8.4.0"
TK = "tk8.4.12"
#TIX = "Tix8.4.2"
ROOT = os.path.abspath(os.path.join(here, par, par))
NMAKE = "nmake /nologo "
......@@ -57,9 +55,9 @@ def build(platform, clean):
if True:
os.chdir(os.path.join(ROOT, TIX, "win"))
if clean:
system(NMAKE + "/f makefile.vc clean")
system(NMAKE + "/f makefile.vc MACHINE=%s" % machine)
system(NMAKE + "/f makefile.vc INSTALL_DIR=%s install" % dest)
system(NMAKE + "/f python9.mak clean")
system(NMAKE + "/f python9.mak MACHINE=%s" % machine)
system(NMAKE + "/f python9.mak install")
def main():
......
......@@ -83,10 +83,19 @@ _tkinter
svn export http://svn.python.org/projects/external/tk8.4.16
svn export http://svn.python.org/projects/external/tix-8.4.0
Build Tcl first (done here w/ MSVC 7.1 on Windows XP)
Build with build_tkinter.py
---------------------------
The PCbuild9 directory contains a Python script which automates all
steps. Run the script in a Visual Studio 2009 command prompt with
python build_tkinter.py Win32
Use x64 instead of Win32 for the x64 platform.
Build Tcl first
---------------
Use "Start -> All Programs -> Microsoft Visual Studio .NET 2003
-> Visual Studio .NET Tools -> Visual Studio .NET 2003 Command Prompt"
Use "Start -> All Programs -> Microsoft Visual Studio 2008
-> Visual Studio Tools -> Visual Studio 2008 Command Prompt"
to get a shell window with the correct environment settings
cd dist\tcl8.4.16\win
nmake -f makefile.vc
......
......@@ -625,7 +625,7 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
next opcode.
A successful prediction saves a trip through the eval-loop including
its two unpredictable branches, the HASARG test and the switch-case.
its two unpredictable branches, the HAS_ARG test and the switch-case.
If collecting opcode statistics, turn off prediction so that
statistics are accurately maintained (the predictions bypass
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment