Commit 7131fd95 authored by Christian Heimes's avatar Christian Heimes

Merged revisions...

Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60849,60852-60854,60856-60859,60861-60870,60874-60878,60880-60892,60894-60898 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r60876 | georg.brandl | 2008-02-17 16:14:10 +0100 (Sun, 17 Feb 2008) | 2 lines

  Fix function name.
........
  r60877 | facundo.batista | 2008-02-17 17:21:13 +0100 (Sun, 17 Feb 2008) | 4 lines


  Now we handle different the backup copy, because of security
  issues regarding user/group and permissions. Fixes 1050828.
........
  r60878 | facundo.batista | 2008-02-17 19:59:29 +0100 (Sun, 17 Feb 2008) | 4 lines


  Issue 2112. mmap does not raises EnvironmentError no more, but
  a subclass of it. Thanks John Lenton.
........
  r60882 | amaury.forgeotdarc | 2008-02-17 21:56:31 +0100 (Sun, 17 Feb 2008) | 5 lines

  Compilation was broken on Windows since the introduction of Advanced String Formatting.

  Only PCBuild (vs9) was really tested.
  Changes for older compilers were done manually.
........
  r60883 | georg.brandl | 2008-02-17 22:18:55 +0100 (Sun, 17 Feb 2008) | 2 lines

  #2133: fix HTML color spec.
........
  r60884 | facundo.batista | 2008-02-18 04:43:43 +0100 (Mon, 18 Feb 2008) | 5 lines


  Issue #1916. Added isgenerator() and isgeneratorfunction() to
  inspect.py.  Thanks Javi Mansilla for patch review and
  corrections.
........
  r60885 | facundo.batista | 2008-02-18 13:48:43 +0100 (Mon, 18 Feb 2008) | 4 lines


  Issue 1224. Now we support again the double slash in the URL.
  Thanks Anthony Lenton.
........
  r60887 | eric.smith | 2008-02-18 15:25:02 +0100 (Mon, 18 Feb 2008) | 1 line

  Temporarily removed float tests.  See issue 1600.
........
  r60891 | kristjan.jonsson | 2008-02-18 18:40:47 +0100 (Mon, 18 Feb 2008) | 1 line

  Perform correct handling of stack overflow for windows: Catch the correct exception code and reset the overflow condition when handled.
........
parent 5edc1c29
...@@ -106,6 +106,6 @@ Tuple Objects ...@@ -106,6 +106,6 @@ Tuple Objects
``*p`` is destroyed. On failure, returns ``-1`` and sets ``*p`` to *NULL*, and ``*p`` is destroyed. On failure, returns ``-1`` and sets ``*p`` to *NULL*, and
raises :exc:`MemoryError` or :exc:`SystemError`. raises :exc:`MemoryError` or :exc:`SystemError`.
.. cfunction:: int PyMethod_ClearFreeList(void) .. cfunction:: int PyTuple_ClearFreeList(void)
Clear the free list. Return the total number of freed items. Clear the free list. Return the total number of freed items.
...@@ -26,7 +26,7 @@ Types and members ...@@ -26,7 +26,7 @@ Types and members
----------------- -----------------
The :func:`getmembers` function retrieves the members of an object such as a The :func:`getmembers` function retrieves the members of an object such as a
class or module. The eleven functions whose names begin with "is" are mainly class or module. The fifteen functions whose names begin with "is" are mainly
provided as convenient choices for the second argument to :func:`getmembers`. provided as convenient choices for the second argument to :func:`getmembers`.
They also help you determine when you can expect to find the following special They also help you determine when you can expect to find the following special
attributes: attributes:
...@@ -229,6 +229,16 @@ attributes: ...@@ -229,6 +229,16 @@ attributes:
Return true if the object is a Python function or unnamed (:term:`lambda`) function. Return true if the object is a Python function or unnamed (:term:`lambda`) function.
.. function:: isgeneratorfunction(object)
Return true if the object is a Python generator function.
.. function:: isgenerator(object)
Return true if the object is a generator.
.. function:: istraceback(object) .. function:: istraceback(object)
Return true if the object is a traceback. Return true if the object is a traceback.
......
...@@ -143,7 +143,8 @@ class SimpleHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): ...@@ -143,7 +143,8 @@ class SimpleHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
""" """
# abandon query parameters # abandon query parameters
path = urlparse.urlparse(path)[2] path = path.split('?',1)[0]
path = path.split('#',1)[0]
path = posixpath.normpath(urllib.unquote(path)) path = posixpath.normpath(urllib.unquote(path))
words = path.split('/') words = path.split('/')
words = filter(None, words) words = filter(None, words)
......
...@@ -7,8 +7,9 @@ It also provides some help for examining source code and class layout. ...@@ -7,8 +7,9 @@ It also provides some help for examining source code and class layout.
Here are some of the useful functions provided by this module: Here are some of the useful functions provided by this module:
ismodule(), isclass(), ismethod(), isfunction(), istraceback(), ismodule(), isclass(), ismethod(), isfunction(), isgeneratorfunction(),
isframe(), iscode(), isbuiltin(), isroutine() - check object types isgenerator(), istraceback(), isframe(), iscode(), isbuiltin(),
isroutine() - check object types
getmembers() - get members of an object that satisfy a given condition getmembers() - get members of an object that satisfy a given condition
getfile(), getsourcefile(), getsource() - find an object's source code getfile(), getsourcefile(), getsource() - find an object's source code
...@@ -29,9 +30,20 @@ Here are some of the useful functions provided by this module: ...@@ -29,9 +30,20 @@ Here are some of the useful functions provided by this module:
__author__ = 'Ka-Ping Yee <ping@lfw.org>' __author__ = 'Ka-Ping Yee <ping@lfw.org>'
__date__ = '1 Jan 2001' __date__ = '1 Jan 2001'
import sys, os, types, re, dis, imp, tokenize, linecache import sys
import os
import types
import string
import re
import dis
import imp
import tokenize
import linecache
from operator import attrgetter from operator import attrgetter
from collections import namedtuple from collections import namedtuple
# These constants are from Include/code.h.
CO_OPTIMIZED, CO_NEWLOCALS, CO_VARARGS, CO_VARKEYWORDS = 0x1, 0x2, 0x4, 0x8
CO_NESTED, CO_GENERATOR, CO_NOFREE = 0x10, 0x20, 0x40
# ----------------------------------------------------------- type-checking # ----------------------------------------------------------- type-checking
def ismodule(object): def ismodule(object):
...@@ -137,6 +149,33 @@ def isfunction(object): ...@@ -137,6 +149,33 @@ def isfunction(object):
__kwdefaults__ dict of keyword only parameters with defaults""" __kwdefaults__ dict of keyword only parameters with defaults"""
return isinstance(object, types.FunctionType) return isinstance(object, types.FunctionType)
def isgeneratorfunction(object):
"""Return true if the object is a user-defined generator function.
Generator function objects provides same attributes as functions.
See isfunction.__doc__ for attributes listing."""
if (isfunction(object) or ismethod(object)) and \
object.__code__.co_flags & CO_GENERATOR:
return True
def isgenerator(object):
"""Return true if the object is a generator.
Generator objects provide these attributes:
__iter__ defined to support interation over container
close raises a new GeneratorExit exception inside the
generator to terminate the iteration
gi_code code object
gi_frame frame object or possibly None once the generator has
been exhausted
gi_running set to 1 when generator is executing, 0 otherwise
next return the next item from the container
send resumes the generator and "sends" a value that becomes
the result of the current yield-expression
throw used to raise an exception inside the generator"""
return isinstance(object, types.GeneratorType)
def istraceback(object): def istraceback(object):
"""Return true if the object is a traceback. """Return true if the object is a traceback.
...@@ -198,6 +237,10 @@ def isroutine(object): ...@@ -198,6 +237,10 @@ def isroutine(object):
or ismethod(object) or ismethod(object)
or ismethoddescriptor(object)) or ismethoddescriptor(object))
def isgenerator(object):
"""Return true if the object is a generator object."""
return isinstance(object, types.GeneratorType)
def getmembers(object, predicate=None): def getmembers(object, predicate=None):
"""Return all members of an object as (name, value) pairs sorted by name. """Return all members of an object as (name, value) pairs sorted by name.
Optionally, only return members that satisfy a given predicate.""" Optionally, only return members that satisfy a given predicate."""
...@@ -670,9 +713,6 @@ def getclasstree(classes, unique=0): ...@@ -670,9 +713,6 @@ def getclasstree(classes, unique=0):
return walktree(roots, children, None) return walktree(roots, children, None)
# ------------------------------------------------ argument list extraction # ------------------------------------------------ argument list extraction
# These constants are from Python's compile.h.
CO_OPTIMIZED, CO_NEWLOCALS, CO_VARARGS, CO_VARKEYWORDS = 1, 2, 4, 8
Arguments = namedtuple('Arguments', 'args, varargs, varkw') Arguments = namedtuple('Arguments', 'args, varargs, varkw')
def getargs(co): def getargs(co):
......
...@@ -660,7 +660,7 @@ class HTMLDoc(Doc): ...@@ -660,7 +660,7 @@ class HTMLDoc(Doc):
contents = self.multicolumn( contents = self.multicolumn(
modules, lambda t: self.modulelink(t[1])) modules, lambda t: self.modulelink(t[1]))
result = result + self.bigsection( result = result + self.bigsection(
'Modules', '#fffff', '#aa55cc', contents) 'Modules', '#ffffff', '#aa55cc', contents)
if classes: if classes:
classlist = [value for (key, value) in classes] classlist = [value for (key, value) in classes]
......
"""
These tests only check url parsing for now.
We don't want to require the 'network' resource.
"""
import os, unittest
from SimpleHTTPServer import SimpleHTTPRequestHandler
from test import test_support
class SocketlessRequestHandler (SimpleHTTPRequestHandler):
def __init__(self):
pass
class SimpleHTTPRequestHandlerTestCase(unittest.TestCase):
""" Test url parsing """
def setUp (self):
self.translated = os.getcwd()
self.translated = os.path.join(self.translated, 'filename')
self.handler = SocketlessRequestHandler ()
def test_queryArguments (self):
path = self.handler.translate_path ('/filename')
self.assertEquals (path, self.translated)
path = self.handler.translate_path ('/filename?foo=bar')
self.assertEquals (path, self.translated)
path = self.handler.translate_path ('/filename?a=b&spam=eggs#zot')
self.assertEquals (path, self.translated)
def test_startWithDoubleSlash (self):
path = self.handler.translate_path ('//filename')
self.assertEquals (path, self.translated)
path = self.handler.translate_path ('//filename?foo=bar')
self.assertEquals (path, self.translated)
def test_main():
test_support.run_unittest(SimpleHTTPRequestHandlerTestCase)
if __name__ == "__main__":
test_main()
...@@ -13,10 +13,10 @@ from test import inspect_fodder2 as mod2 ...@@ -13,10 +13,10 @@ from test import inspect_fodder2 as mod2
# Functions tested in this suite: # Functions tested in this suite:
# ismodule, isclass, ismethod, isfunction, istraceback, isframe, iscode, # ismodule, isclass, ismethod, isfunction, istraceback, isframe, iscode,
# isbuiltin, isroutine, getmembers, getdoc, getfile, getmodule, # isbuiltin, isroutine, isgenerator, isgeneratorfunction, getmembers,
# getsourcefile, getcomments, getsource, getclasstree, getargspec, # getdoc, getfile, getmodule, getsourcefile, getcomments, getsource,
# getargvalues, formatargspec, formatargvalues, currentframe, stack, trace # getclasstree, getargspec, getargvalues, formatargspec, formatargvalues,
# isdatadescriptor # currentframe, stack, trace, isdatadescriptor
modfile = mod.__file__ modfile = mod.__file__
if modfile.endswith(('c', 'o')): if modfile.endswith(('c', 'o')):
...@@ -41,23 +41,33 @@ git = mod.StupidGit() ...@@ -41,23 +41,33 @@ git = mod.StupidGit()
class IsTestBase(unittest.TestCase): class IsTestBase(unittest.TestCase):
predicates = set([inspect.isbuiltin, inspect.isclass, inspect.iscode, predicates = set([inspect.isbuiltin, inspect.isclass, inspect.iscode,
inspect.isframe, inspect.isfunction, inspect.ismethod, inspect.isframe, inspect.isfunction, inspect.ismethod,
inspect.ismodule, inspect.istraceback]) inspect.ismodule, inspect.istraceback,
inspect.isgenerator, inspect.isgeneratorfunction])
def istest(self, predicate, exp): def istest(self, predicate, exp):
obj = eval(exp) obj = eval(exp)
self.failUnless(predicate(obj), '%s(%s)' % (predicate.__name__, exp)) self.failUnless(predicate(obj), '%s(%s)' % (predicate.__name__, exp))
for other in self.predicates - set([predicate]): for other in self.predicates - set([predicate]):
if predicate == inspect.isgeneratorfunction and\
other == inspect.isfunction:
continue
self.failIf(other(obj), 'not %s(%s)' % (other.__name__, exp)) self.failIf(other(obj), 'not %s(%s)' % (other.__name__, exp))
def generator_function_example(self):
for i in range(2):
yield i
class TestPredicates(IsTestBase): class TestPredicates(IsTestBase):
def test_thirteen(self): def test_fifteen(self):
count = len([x for x in dir(inspect) if x.startswith('is')]) count = len([x for x in dir(inspect) if x.startswith('is')])
# Doc/lib/libinspect.tex claims there are 13 such functions # This test is here for remember you to update Doc/library/inspect.rst
expected = 13 # which claims there are 15 such functions
expected = 15
err_msg = "There are %d (not %d) is* functions" % (count, expected) err_msg = "There are %d (not %d) is* functions" % (count, expected)
self.assertEqual(count, expected, err_msg) self.assertEqual(count, expected, err_msg)
def test_excluding_predicates(self): def test_excluding_predicates(self):
self.istest(inspect.isbuiltin, 'sys.exit') self.istest(inspect.isbuiltin, 'sys.exit')
self.istest(inspect.isbuiltin, '[].append') self.istest(inspect.isbuiltin, '[].append')
...@@ -70,6 +80,8 @@ class TestPredicates(IsTestBase): ...@@ -70,6 +80,8 @@ class TestPredicates(IsTestBase):
self.istest(inspect.ismodule, 'mod') self.istest(inspect.ismodule, 'mod')
self.istest(inspect.istraceback, 'tb') self.istest(inspect.istraceback, 'tb')
self.istest(inspect.isdatadescriptor, 'collections.defaultdict.default_factory') self.istest(inspect.isdatadescriptor, 'collections.defaultdict.default_factory')
self.istest(inspect.isgenerator, '(x for x in range(2))')
self.istest(inspect.isgeneratorfunction, 'generator_function_example')
if hasattr(types, 'GetSetDescriptorType'): if hasattr(types, 'GetSetDescriptorType'):
self.istest(inspect.isgetsetdescriptor, self.istest(inspect.isgetsetdescriptor,
'type(tb.tb_frame).f_locals') 'type(tb.tb_frame).f_locals')
......
...@@ -435,6 +435,11 @@ class MmapTests(unittest.TestCase): ...@@ -435,6 +435,11 @@ class MmapTests(unittest.TestCase):
self.assertRaises(TypeError, m.write, "foo") self.assertRaises(TypeError, m.write, "foo")
def test_error(self):
self.assert_(issubclass(mmap.error, EnvironmentError))
self.assert_("mmap.error" in str(mmap.error))
def test_main(): def test_main():
run_unittest(MmapTests) run_unittest(MmapTests)
......
This diff is collapsed.
This diff is collapsed.
...@@ -1326,7 +1326,10 @@ initmmap(void) ...@@ -1326,7 +1326,10 @@ initmmap(void)
dict = PyModule_GetDict(module); dict = PyModule_GetDict(module);
if (!dict) if (!dict)
return; return;
mmap_module_error = PyExc_EnvironmentError; mmap_module_error = PyErr_NewException("mmap.error",
PyExc_EnvironmentError , NULL);
if (mmap_module_error == NULL)
return;
PyDict_SetItemString(dict, "error", mmap_module_error); PyDict_SetItemString(dict, "error", mmap_module_error);
PyDict_SetItemString(dict, "mmap", (PyObject*) &mmap_object_type); PyDict_SetItemString(dict, "mmap", (PyObject*) &mmap_object_type);
#ifdef PROT_EXEC #ifdef PROT_EXEC
......
...@@ -125,6 +125,10 @@ SOURCE=..\..\Modules\_codecsmodule.c ...@@ -125,6 +125,10 @@ SOURCE=..\..\Modules\_codecsmodule.c
# End Source File # End Source File
# Begin Source File # Begin Source File
SOURCE=..\..\Modules\_collectionsmodule.c
# End Source File
# Begin Source File
SOURCE=..\..\Modules\_csv.c SOURCE=..\..\Modules\_csv.c
# End Source File # End Source File
# Begin Source File # Begin Source File
...@@ -349,6 +353,14 @@ SOURCE=..\..\Objects\floatobject.c ...@@ -349,6 +353,14 @@ SOURCE=..\..\Objects\floatobject.c
# End Source File # End Source File
# Begin Source File # Begin Source File
SOURCE=..\..\Python\formatter_string.c
# End Source File
# Begin Source File
SOURCE=..\..\Python\formatter_unicode.c
# End Source File
# Begin Source File
SOURCE=..\..\Objects\frameobject.c SOURCE=..\..\Objects\frameobject.c
# End Source File # End Source File
# Begin Source File # Begin Source File
......
...@@ -514,6 +514,9 @@ ...@@ -514,6 +514,9 @@
<File <File
RelativePath="..\..\Objects\floatobject.c"> RelativePath="..\..\Objects\floatobject.c">
</File> </File>
<File
RelativePath="..\..\Python\formatter_unicode.c">
</File>
<File <File
RelativePath="..\..\Objects\frameobject.c"> RelativePath="..\..\Objects\frameobject.c">
</File> </File>
......
...@@ -1899,8 +1899,14 @@ PyOS_CheckStack(void) ...@@ -1899,8 +1899,14 @@ PyOS_CheckStack(void)
not enough space left on the stack */ not enough space left on the stack */
alloca(PYOS_STACK_MARGIN * sizeof(void*)); alloca(PYOS_STACK_MARGIN * sizeof(void*));
return 0; return 0;
} __except (EXCEPTION_EXECUTE_HANDLER) { } __except (GetExceptionCode() == STATUS_STACK_OVERFLOW ?
/* just ignore all errors */ EXCEPTION_EXECUTE_HANDLER :
EXCEPTION_CONTINUE_SEARCH) {
int errcode = _resetstkoflw();
if (errcode)
{
Py_FatalError("Could not reset the stack!");
}
} }
return 1; return 1;
} }
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
-d (--dryrun) Dry run. Analyze, but don't make any changes to, files. -d (--dryrun) Dry run. Analyze, but don't make any changes to, files.
-r (--recurse) Recurse. Search for all .py files in subdirectories too. -r (--recurse) Recurse. Search for all .py files in subdirectories too.
-n (--nobackup) No backup. Does not make a ".bak" file before reindenting.
-v (--verbose) Verbose. Print informative msgs; else no output. -v (--verbose) Verbose. Print informative msgs; else no output.
-h (--help) Help. Print this usage information and exit. -h (--help) Help. Print this usage information and exit.
...@@ -31,17 +32,23 @@ resulting .py file won't change it again). ...@@ -31,17 +32,23 @@ resulting .py file won't change it again).
The hard part of reindenting is figuring out what to do with comment The hard part of reindenting is figuring out what to do with comment
lines. So long as the input files get a clean bill of health from lines. So long as the input files get a clean bill of health from
tabnanny.py, reindent should do a good job. tabnanny.py, reindent should do a good job.
The backup file is a copy of the one that is being reindented. The ".bak"
file is generated with shutil.copy(), but some corner cases regarding
user/group and permissions could leave the backup file more readable that
you'd prefer. You can always use the --nobackup option to prevent this.
""" """
__version__ = "1" __version__ = "1"
import tokenize import tokenize
import os import os, shutil
import sys import sys
verbose = 0 verbose = 0
recurse = 0 recurse = 0
dryrun = 0 dryrun = 0
makebackup = True
def usage(msg=None): def usage(msg=None):
if msg is not None: if msg is not None:
...@@ -57,10 +64,10 @@ def errprint(*args): ...@@ -57,10 +64,10 @@ def errprint(*args):
def main(): def main():
import getopt import getopt
global verbose, recurse, dryrun global verbose, recurse, dryrun, makebackup
try: try:
opts, args = getopt.getopt(sys.argv[1:], "drvh", opts, args = getopt.getopt(sys.argv[1:], "drnvh",
["dryrun", "recurse", "verbose", "help"]) ["dryrun", "recurse", "nobackup", "verbose", "help"])
except getopt.error as msg: except getopt.error as msg:
usage(msg) usage(msg)
return return
...@@ -69,6 +76,8 @@ def main(): ...@@ -69,6 +76,8 @@ def main():
dryrun += 1 dryrun += 1
elif o in ('-r', '--recurse'): elif o in ('-r', '--recurse'):
recurse += 1 recurse += 1
elif o in ('-n', '--nobackup'):
makebackup = False
elif o in ('-v', '--verbose'): elif o in ('-v', '--verbose'):
verbose += 1 verbose += 1
elif o in ('-h', '--help'): elif o in ('-h', '--help'):
...@@ -112,11 +121,10 @@ def check(file): ...@@ -112,11 +121,10 @@ def check(file):
print("But this is a dry run, so leaving it alone.") print("But this is a dry run, so leaving it alone.")
if not dryrun: if not dryrun:
bak = file + ".bak" bak = file + ".bak"
if os.path.exists(bak): if makebackup:
os.remove(bak) shutil.copyfile(file, bak)
os.rename(file, bak)
if verbose: if verbose:
print("renamed", file, "to", bak) print("backed up", file, "to", bak)
f = open(file, "w") f = open(file, "w")
r.write(f) r.write(f)
f.close() f.close()
......
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