From anthony at interlink.com.au Fri Apr 1 05:27:36 2005 From: anthony at interlink.com.au (Anthony Baxter) Date: Fri Apr 1 05:30:33 2005 Subject: [Python-Dev] RE: [Python-checkins] python/dist/src/Lib/logging handlers.py, 1.19, 1.19.2.1 In-Reply-To: <003101c53634$a60b87e0$d2bc958d@oemcomputer> References: <003101c53634$a60b87e0$d2bc958d@oemcomputer> Message-ID: <200504011327.37278.anthony@interlink.com.au> On Friday 01 April 2005 07:00, Raymond Hettinger wrote: > > Tag: release24-maint > > handlers.py > > Log Message: > > Added optional encoding argument to File based handlers and improved > > error handling for SysLogHandler > > Are you sure you want to backport an API change and new feature? What Raymond said. Please don't add new features to the maintenance branch. Anthony -- Anthony Baxter It's never too late to have a happy childhood. From pje at users.sourceforge.net Fri Apr 1 23:29:02 2005 From: pje at users.sourceforge.net (pje@users.sourceforge.net) Date: Fri Apr 1 23:29:05 2005 Subject: [Python-checkins] python/nondist/sandbox/setuptools/setuptools/tests __init__.py, 1.4, 1.5 Message-ID: Update of /cvsroot/python/python/nondist/sandbox/setuptools/setuptools/tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2449 Modified Files: __init__.py Log Message: Back out the addition of bogus 'if __name__=="__main__"' block; the One Obvious Way to test setuptools is to run 'setup.py test', because that also provides an integration test for the 'test' command. Index: __init__.py =================================================================== RCS file: /cvsroot/python/python/nondist/sandbox/setuptools/setuptools/tests/__init__.py,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- __init__.py 5 Apr 2004 20:21:52 -0000 1.4 +++ __init__.py 1 Apr 2005 21:28:49 -0000 1.5 @@ -1,22 +1,17 @@ """Tests for the 'setuptools' package""" -import os.path -import sys - -from unittest import TestSuite, TestCase, makeSuite, main - +from unittest import TestSuite, TestCase, makeSuite import distutils.core, distutils.cmd -from distutils.core import Extension from distutils.errors import DistutilsOptionError, DistutilsPlatformError from distutils.errors import DistutilsSetupError -from distutils.util import convert_path -from distutils.version import StrictVersion, LooseVersion - import setuptools, setuptools.dist - from setuptools import Feature +from distutils.core import Extension from setuptools.depends import extract_constant, get_module_constant from setuptools.depends import find_module, Require +from distutils.version import StrictVersion, LooseVersion +from distutils.util import convert_path +import sys, os.path def makeSetup(**args): @@ -25,7 +20,7 @@ distutils.core._setup_stop_after = "commandline" # Don't let system command line leak into tests! - args.setdefault('script_args', ['install']) + args.setdefault('script_args',['install']) try: return setuptools.setup(**args) @@ -33,9 +28,21 @@ distutils.core_setup_stop_after = None + + + + + + + + + + + class DependsTests(TestCase): def testExtractConst(self): + from setuptools.depends import extract_constant def f1(): @@ -63,14 +70,18 @@ def testModuleExtract(self): from distutils import __version__ - self.assertEqual(get_module_constant('distutils', '__version__'), - __version__) - self.assertEqual(get_module_constant('sys', 'version'), - sys.version) - self.assertEqual(get_module_constant('setuptools.tests', '__doc__'), - __doc__) + self.assertEqual( + get_module_constant('distutils','__version__'), __version__ + ) + self.assertEqual( + get_module_constant('sys','version'), sys.version + ) + self.assertEqual( + get_module_constant('setuptools.tests','__doc__'),__doc__ + ) def testRequire(self): + req = Require('Distutils','1.0.3','distutils') self.assertEqual(req.name, 'Distutils') @@ -88,8 +99,7 @@ self.failUnless(req.is_present()) self.failUnless(req.is_current()) - req = Require('Distutils 3000', '03000', 'distutils', - format=LooseVersion) + req = Require('Distutils 3000','03000','distutils',format=LooseVersion) self.failUnless(req.is_present()) self.failIf(req.is_current()) self.failIf(req.version_ok('unknown')) @@ -109,26 +119,47 @@ self.failUnless(req.is_present(paths)) self.failUnless(req.is_current(paths)) + + def testDependsCmd(self): path1 = convert_path('foo/bar/baz') path2 = convert_path('foo/bar/baz/spam') - dist = makeSetup(extra_path='spam', - script_args=['install', '--install-lib', path1, - '--prefix', path2, - 'build', '--compiler=mingw32',]) + dist = makeSetup( + extra_path='spam', + script_args=['install','--install-lib',path1] + ) cmd = dist.get_command_obj('depends') cmd.ensure_finalized() self.assertEqual(cmd.temp, dist.get_command_obj('build').build_temp) - self.assertEqual(cmd.search_path, [path2,path1] + sys.path) + self.assertEqual(cmd.search_path, [path2,path1]+sys.path) + + + + + + + + + + + + + + + + + + + + + + + + - self.assertEqual(cmd.unsafe_options, - {'install': ['--install-lib',path1]}) - self.assertEqual(cmd.safe_options, { - 'build':['--compiler','mingw32'], - 'install':['--prefix',os.path.abspath(path2)]}) class DistroTests(TestCase): @@ -141,15 +172,13 @@ packages=['a', 'a.b', 'a.b.c', 'b', 'c'], py_modules=['b.d','x'], ext_modules = (self.e1, self.e2), - script_args = [ - 'build', '-q', 'build_ext', '-i', - 'install', '--prefix=/usr/lib', '--install-lib','/test' - ], package_dir = {}, ) + def testDistroType(self): - self.failUnless(isinstance(self.dist, setuptools.dist.Distribution)) + self.failUnless(isinstance(self.dist,setuptools.dist.Distribution)) + def testExcludePackage(self): self.dist.exclude_package('a') @@ -168,6 +197,12 @@ # test removals from unspecified options makeSetup().exclude_package('x') + + + + + + def testIncludeExclude(self): # remove an extension self.dist.exclude(ext_modules=[self.e1]) @@ -206,32 +241,48 @@ self.dist.exclude_package('c') self.failIf(self.dist.has_contents_for('c')) + + + def testInvalidIncludeExclude(self): self.assertRaises(DistutilsSetupError, - self.dist.include, nonexistent_option='x') + self.dist.include, nonexistent_option='x' + ) self.assertRaises(DistutilsSetupError, - self.dist.exclude, nonexistent_option='x') + self.dist.exclude, nonexistent_option='x' + ) self.assertRaises(DistutilsSetupError, - self.dist.include, packages={'x':'y'}) + self.dist.include, packages={'x':'y'} + ) self.assertRaises(DistutilsSetupError, - self.dist.exclude, packages={'x':'y'}) + self.dist.exclude, packages={'x':'y'} + ) self.assertRaises(DistutilsSetupError, - self.dist.include, ext_modules={'x':'y'}) + self.dist.include, ext_modules={'x':'y'} + ) self.assertRaises(DistutilsSetupError, - self.dist.exclude, ext_modules={'x':'y'}) + self.dist.exclude, ext_modules={'x':'y'} + ) self.assertRaises(DistutilsSetupError, - self.dist.include, package_dir=['q']) + self.dist.include, package_dir=['q'] + ) self.assertRaises(DistutilsSetupError, - self.dist.exclude, package_dir=['q']) + self.dist.exclude, package_dir=['q'] + ) + + + + + + + + + + + + - def testCmdLineOpts(self): - self.assertEqual( - self.dist.get_cmdline_options(), - {'install':{'prefix':'/usr/lib', 'install-lib':'/test'}, - 'build': {'quiet':None}, - 'build_ext': {'inplace':None}, - }) class FeatureTests(TestCase): @@ -244,41 +295,51 @@ 'bar': Feature("bar", standard=True, packages=['pkg.bar'], py_modules=['bar_et'], remove=['bar.ext'], ), - 'baz': Feature("baz", optional=False, packages=['pkg.baz'], - scripts=['scripts/baz_it'], - libraries=[('libfoo','foo/foofoo.c')] + 'baz': Feature( + "baz", optional=False, packages=['pkg.baz'], + scripts = ['scripts/baz_it'], + libraries=[('libfoo','foo/foofoo.c')] ), 'dwim': Feature("DWIM", available=False, remove='bazish'), - }, + }, script_args=['--without-bar', 'install'], - packages=['pkg.bar', 'pkg.foo'], - py_modules=['bar_et', 'bazish'], - ext_modules=[Extension('bar.ext',['bar.c'])] + packages = ['pkg.bar', 'pkg.foo'], + py_modules = ['bar_et', 'bazish'], + ext_modules = [Extension('bar.ext',['bar.c'])] ) def testDefaults(self): self.failIf( - Feature("test",standard=True,remove='x',available=False - ).include_by_default()) + Feature( + "test",standard=True,remove='x',available=False + ).include_by_default() + ) self.failUnless( - Feature("test",standard=True,remove='x').include_by_default()) + Feature("test",standard=True,remove='x').include_by_default() + ) # Feature must have either kwargs, removes, or requires self.assertRaises(DistutilsSetupError, Feature, "test") def testAvailability(self): - self.assertRaises(DistutilsPlatformError, - self.dist.features['dwim'].include_in, self.dist) + self.assertRaises( + DistutilsPlatformError, + self.dist.features['dwim'].include_in, self.dist + ) def testFeatureOptions(self): dist = self.dist - self.failUnless(('with-dwim', None, 'include DWIM') - in dist.feature_options) - self.failUnless(('without-dwim', None, 'exclude DWIM (default)') - in dist.feature_options) - self.failUnless(('with-bar', None, 'include bar (default)') - in dist.feature_options) - self.failUnless(('without-bar', None, 'exclude bar') - in dist.feature_options) + self.failUnless( + ('with-dwim',None,'include DWIM') in dist.feature_options + ) + self.failUnless( + ('without-dwim',None,'exclude DWIM (default)') in dist.feature_options + ) + self.failUnless( + ('with-bar',None,'include bar (default)') in dist.feature_options + ) + self.failUnless( + ('without-bar',None,'exclude bar') in dist.feature_options + ) self.assertEqual(dist.feature_negopt['without-foo'],'with-foo') self.assertEqual(dist.feature_negopt['without-bar'],'with-bar') self.assertEqual(dist.feature_negopt['without-dwim'],'with-dwim') @@ -302,9 +363,9 @@ self.assertRaises(DistutilsOptionError, dist.include_feature, 'bar') def testFeatureWithInvalidRemove(self): - self.assertRaises(SystemExit, - makeSetup, features={'x': Feature('x', remove='y')}) - + self.assertRaises( + SystemExit, makeSetup, features = {'x':Feature('x', remove='y')} + ) class TestCommandTests(TestCase): @@ -327,7 +388,7 @@ ts3 = makeSetup( test_suite='bar.tests', script_args=['test','-m','foo.tests'] - ).get_command_obj('test') + ).get_command_obj('test') ts3.ensure_finalized() self.assertEqual(ts3.test_module, 'foo.tests') self.assertEqual(ts3.test_suite, 'foo.tests.test_suite') @@ -335,7 +396,7 @@ def testConflictingOptions(self): ts4 = makeSetup( script_args=['test','-m','bar.tests', '-s','foo.tests.suite'] - ).get_command_obj('test') + ).get_command_obj('test') self.assertRaises(DistutilsOptionError, ts4.ensure_finalized) def testNoSuite(self): @@ -344,13 +405,47 @@ self.assertEqual(ts5.test_suite, None) + + + testClasses = (DependsTests, DistroTests, FeatureTests, TestCommandTests) def test_suite(): return TestSuite([makeSuite(t,'test') for t in testClasses]) -if __name__ == "__main__": - # We have to run this from an imported setuptools.tests package, - # since the tests themselves rely on __path__. - import setuptools.tests - main(defaultTest="setuptools.tests.test_suite") + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From bcannon at users.sourceforge.net Sat Apr 2 03:12:59 2005 From: bcannon at users.sourceforge.net (bcannon@users.sourceforge.net) Date: Sat Apr 2 03:13:03 2005 Subject: [Python-checkins] python/dist/src/Python compile.txt, 1.1.2.10, 1.1.2.11 Message-ID: Update of /cvsroot/python/python/dist/src/Python In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31124/Python Modified Files: Tag: ast-branch compile.txt Log Message: Minor spelling mistake and change an artifact in Scope section from when it was not listing the CFG step. Thanks Terry Reedy. Index: compile.txt =================================================================== RCS file: /cvsroot/python/python/dist/src/Python/Attic/compile.txt,v retrieving revision 1.1.2.10 retrieving revision 1.1.2.11 diff -u -d -r1.1.2.10 -r1.1.2.11 --- compile.txt 23 Mar 2005 15:51:25 -0000 1.1.2.10 +++ compile.txt 2 Apr 2005 01:12:56 -0000 1.1.2.11 @@ -44,12 +44,12 @@ 4. Emit bytecode based on the Control Flow Graph (Python/newcompile.c) Starting with Python 2.5, the above steps are now used. This change -was done to simplify compilation by breaking it down to two steps. +was done to simplify compilation by breaking it into three steps. The purpose of this document is to outline how the lattter three steps of the process works. This document does not touch on how parsing works beyond what is needed -to explain what is needed for compilation. It is also not exahaustive +to explain what is needed for compilation. It is also not exhaustive in terms of the how the entire system works. You will most likely need to read some source to have an exact understanding of all details. From pje at users.sourceforge.net Sat Apr 2 04:43:23 2005 From: pje at users.sourceforge.net (pje@users.sourceforge.net) Date: Sat Apr 2 04:43:26 2005 Subject: [Python-checkins] python/nondist/sandbox/setuptools/setuptools/command bdist_egg.py, 1.5, 1.6 Message-ID: Update of /cvsroot/python/python/nondist/sandbox/setuptools/setuptools/command In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17398/setuptools/command Modified Files: bdist_egg.py Log Message: Rough draft of version requirement parser. Make bdist_egg look for a distname.egg-info directory instead of EGG-INFO.in; this will be used later to support development of egg-distributed packages that an application under development expects to 'require()'. (Thanks to Fred Drake for pointing out this use case, and Bob Ippolito for helping me figure out how to support it, although the runtime support doesn't actually exist yet.) Index: bdist_egg.py =================================================================== RCS file: /cvsroot/python/python/nondist/sandbox/setuptools/setuptools/command/bdist_egg.py,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- bdist_egg.py 22 Mar 2005 18:55:59 -0000 1.5 +++ bdist_egg.py 2 Apr 2005 02:43:20 -0000 1.6 @@ -3,7 +3,6 @@ Build .egg distributions""" # This module should be kept compatible with Python 2.3 - import os from distutils.core import Command from distutils.util import get_platform @@ -11,14 +10,15 @@ from distutils.sysconfig import get_python_version from distutils.errors import * from distutils import log +from pkg_resources import parse_requirements class bdist_egg(Command): description = "create an \"egg\" distribution" - user_options = [('egg-info=', 'e', - "directory containing EGG-INFO for the distribution " - "(default: EGG-INFO.in)"), + user_options = [('egg-base=', 'e', + "directory containing .egg-info directories" + "(default: top of the source tree)"), ('bdist-dir=', 'd', "temporary directory for creating the distribution"), ('plat-name=', 'p', @@ -40,6 +40,9 @@ def initialize_options (self): + self.egg_name = None + self.egg_version = None + self.egg_base = None self.egg_info = None self.bdist_dir = None self.plat_name = None @@ -47,27 +50,35 @@ self.dist_dir = None self.skip_build = 0 self.relative = 0 - - # initialize_options() def finalize_options (self): + self.egg_name = self.distribution.get_name().replace('-','_') + self.egg_version = self.distribution.get_version().replace('-','_') + try: + list( + parse_requirements('%s==%s' % (self.egg_name,self.egg_version)) + ) + except ValueError: + raise DistutilsOptionError( + "Invalid distribution name or version syntax: %s-%s" % + (self.egg_name,self.egg_version) + ) + if self.egg_base is None: + dirs = self.distribution.package_dir + self.egg_base = (dirs or {}).get('','.') - if self.egg_info is None and os.path.isdir('EGG-INFO.in'): - self.egg_info = 'EGG-INFO.in' - - elif self.egg_info: - self.ensure_dirname('egg_info') - + self.ensure_dirname('egg_base') + self.egg_info = os.path.join( + self.egg_base, self.egg_name+'.egg-info' + ) if self.bdist_dir is None: bdist_base = self.get_finalized_command('bdist').bdist_base self.bdist_dir = os.path.join(bdist_base, 'egg') - self.set_undefined_options('bdist', ('dist_dir', 'dist_dir'), ('plat_name', 'plat_name')) - # finalize_options() def write_stub(self, resource, pyfile): f = open(pyfile,'w') @@ -84,9 +95,33 @@ ])) f.close() - - def run (self): + + + + + + + + + + + + + + + + + + + + + + + + + + def run(self): if not self.skip_build: self.run_command('build') @@ -113,46 +148,50 @@ if to_compile: install.byte_compile(to_compile) - + # And make an archive relative to the root of the # pseudo-installation tree. - archive_basename = "%s-py%s" % (self.distribution.get_fullname(), + archive_basename = "%s-%s-py%s" % (self.egg_name, self.egg_version, get_python_version()) if ext_outputs: archive_basename += "-" + self.plat_name # OS/2 objects to any ":" characters in a filename (such as when - # a timestamp is used in a version) so change them to hyphens. + # a timestamp is used in a version) so change them to underscores. if os.name == "os2": - archive_basename = archive_basename.replace(":", "-") + archive_basename = archive_basename.replace(":", "_") pseudoinstall_root = os.path.join(self.dist_dir, archive_basename) archive_root = self.bdist_dir # Make the EGG-INFO directory - log.info("creating EGG-INFO directory") egg_info = os.path.join(archive_root,'EGG-INFO') self.mkpath(egg_info) + self.mkpath(self.egg_info) - if self.egg_info: - for filename in os.listdir(self.egg_info): - path = os.path.join(self.egg_info,filename) - if os.path.isfile(path): - self.copy_file(path,os.path.join(egg_info,filename)) - - log.info("writing EGG-INFO/PKG-INFO") + log.info("writing %s" % os.path.join(self.egg_info,'PKG-INFO')) if not self.dry_run: - self.distribution.metadata.write_pkg_info(egg_info) + self.distribution.metadata.write_pkg_info(self.egg_info) + native_libs = os.path.join(self.egg_info,"native_libs.txt") if ext_outputs: - log.info("writing EGG-INFO/native_libs.txt") + log.info("writing %s" % native_libs) if not self.dry_run: - libs_file = open( - os.path.join(egg_info,"native_libs.txt"),'wt') + libs_file = open(native_libs, 'wt') libs_file.write('\n'.join(ext_outputs)) libs_file.write('\n') libs_file.close() + elif os.path.isfile(native_libs): + log.info("removing %s" % native_libs) + if not self.dry_run: + os.unlink(native_libs) + + if self.egg_info: + for filename in os.listdir(self.egg_info): + path = os.path.join(self.egg_info,filename) + if os.path.isfile(path): + self.copy_file(path,os.path.join(egg_info,filename)) # Make the archive make_zipfile(pseudoinstall_root+'.egg', @@ -162,10 +201,6 @@ if not self.keep_temp: remove_tree(self.bdist_dir, dry_run=self.dry_run) - # run() - -# class bdist_egg - def make_zipfile (zip_filename, base_dir, verbose=0, dry_run=0): @@ -176,7 +211,7 @@ raises DistutilsExecError. Returns the name of the output zip file. """ import zipfile - + mkpath(os.path.dirname(zip_filename), dry_run=dry_run) # If zipfile module is not available, try spawning an external @@ -203,3 +238,9 @@ # make_zipfile () + + + + + + From pje at users.sourceforge.net Sat Apr 2 04:43:23 2005 From: pje at users.sourceforge.net (pje@users.sourceforge.net) Date: Sat Apr 2 04:43:27 2005 Subject: [Python-checkins] python/nondist/sandbox/setuptools/setuptools/tests test_resources.py, NONE, 1.1 __init__.py, 1.5, 1.6 Message-ID: Update of /cvsroot/python/python/nondist/sandbox/setuptools/setuptools/tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17398/setuptools/tests Modified Files: __init__.py Added Files: test_resources.py Log Message: Rough draft of version requirement parser. Make bdist_egg look for a distname.egg-info directory instead of EGG-INFO.in; this will be used later to support development of egg-distributed packages that an application under development expects to 'require()'. (Thanks to Fred Drake for pointing out this use case, and Bob Ippolito for helping me figure out how to support it, although the runtime support doesn't actually exist yet.) --- NEW FILE: test_resources.py --- from unittest import TestCase, makeSuite from pkg_resources import * import pkg_resources class DistroTests(TestCase): def testEmptyiter(self): # empty path should produce no distributions self.assertEqual(list(iter_distributions(path=[])), []) class ParseTests(TestCase): def testEmptyParse(self): self.assertEqual(list(parse_requirements('')), []) def testYielding(self): for inp,out in [ ([], []), ('x',['x']), ([[]],[]), (' x\n y', ['x','y']), (['x\n\n','y'], ['x','y']), ]: self.assertEqual(list(pkg_resources.yield_lines(inp)),out) def testSimple(self): self.assertEqual( list(parse_requirements('Twis-Ted>=1.2')), [('Twis_Ted',[('>=','1.2')])] ) self.assertEqual( list(parse_requirements('Twisted >=1.2, \ # more\n<2.0')), [('Twisted',[('>=','1.2'),('<','2.0')])] ) self.assertRaises(ValueError,lambda:list(parse_requirements(">=2.3"))) self.assertRaises(ValueError,lambda:list(parse_requirements("x\\"))) self.assertRaises(ValueError,lambda:list(parse_requirements("x==2 q"))) Index: __init__.py =================================================================== RCS file: /cvsroot/python/python/nondist/sandbox/setuptools/setuptools/tests/__init__.py,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- __init__.py 1 Apr 2005 21:28:49 -0000 1.5 +++ __init__.py 2 Apr 2005 02:43:21 -0000 1.6 @@ -1,6 +1,6 @@ """Tests for the 'setuptools' package""" -from unittest import TestSuite, TestCase, makeSuite +from unittest import TestSuite, TestCase, makeSuite, defaultTestLoader import distutils.core, distutils.cmd from distutils.errors import DistutilsOptionError, DistutilsPlatformError from distutils.errors import DistutilsSetupError @@ -409,13 +409,13 @@ testClasses = (DependsTests, DistroTests, FeatureTests, TestCommandTests) +testNames = ["setuptools.tests.test_resources"] def test_suite(): - return TestSuite([makeSuite(t,'test') for t in testClasses]) - - - - + return TestSuite( + [makeSuite(t,'test') for t in testClasses]+ + [defaultTestLoader.loadTestsFromName(n) for n in testNames] + ) From pje at users.sourceforge.net Sat Apr 2 04:43:23 2005 From: pje at users.sourceforge.net (pje@users.sourceforge.net) Date: Sat Apr 2 04:43:27 2005 Subject: [Python-checkins] python/nondist/sandbox/setuptools pkg_resources.py, 1.4, 1.5 Message-ID: Update of /cvsroot/python/python/nondist/sandbox/setuptools In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17398 Modified Files: pkg_resources.py Log Message: Rough draft of version requirement parser. Make bdist_egg look for a distname.egg-info directory instead of EGG-INFO.in; this will be used later to support development of egg-distributed packages that an application under development expects to 'require()'. (Thanks to Fred Drake for pointing out this use case, and Bob Ippolito for helping me figure out how to support it, although the runtime support doesn't actually exist yet.) Index: pkg_resources.py =================================================================== RCS file: /cvsroot/python/python/nondist/sandbox/setuptools/pkg_resources.py,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- pkg_resources.py 24 Mar 2005 20:29:19 -0000 1.4 +++ pkg_resources.py 2 Apr 2005 02:43:20 -0000 1.5 @@ -13,23 +13,14 @@ .zip files and with custom PEP 302 loaders that support the ``get_data()`` method. """ - -import sys -import os -import time -import zipimport -try: - from cStringIO import StringIO -except ImportError: - from StringIO import StringIO - __all__ = [ 'register_loader_type', 'get_provider', 'IResourceProvider', 'ResourceManager', 'iter_distributions', 'require', 'resource_string', 'resource_stream', 'resource_filename', 'set_extraction_path', - 'cleanup_resources', # 'glob_resources' + 'cleanup_resources', 'parse_requirements', # 'glob_resources' ] +import sys, os, zipimport, time, re _provider_factories = {} def register_loader_type(loader_type, provider_factory): @@ -41,7 +32,6 @@ """ _provider_factories[loader_type] = provider_factory - def get_provider(moduleName): """Return an IResourceProvider for the named module""" module = sys.modules[moduleName] @@ -50,6 +40,7 @@ class IResourceProvider: + """An object that provides access to package resources""" def get_resource_filename(manager, resource_name): @@ -77,13 +68,18 @@ """The named metadata resource as a string""" def get_metadata_lines(name): - """The named metadata resource as a filtered iterator of - stripped (of # comments and whitespace) lines - """ + """Yield named metadata resource as list of non-blank non-comment lines + + Leading and trailing whitespace is stripped from each line, and lines + with ``#`` as the first non-blank character are omitted. + """ # XXX list_resources? glob_resources? + + + class ResourceManager: """Manage resource extraction and packages""" @@ -98,18 +94,32 @@ def resource_filename(self, package_name, resource_name): """Return a true filesystem path for specified resource""" - return get_provider(package_name).get_resource_filename(self, - resource_name) + return get_provider(package_name).get_resource_filename(self,resource_name) def resource_stream(self, package_name, resource_name): """Return a readable file-like object for specified resource""" - return get_provider(package_name).get_resource_stream(self, - resource_name) + return get_provider(package_name).get_resource_stream(self,resource_name) def resource_string(self, package_name, resource_name): """Return specified resource as a string""" - return get_provider(package_name).get_resource_string(self, - resource_name) + return get_provider(package_name).get_resource_string(self,resource_name) + + + + + + + + + + + + + + + + + def get_cache_path(self, archive_name, names=()): """Return absolute location in cache for `archive_name` and `names` @@ -131,23 +141,6 @@ self.cached_files.append(target_path) return target_path - def require(self, requirement, path=None): - """Ensure a distribution matching `requirement` is on ``sys.path`` - - The `requirement` and `path` arguments are the same as for - the ``iter_distributions()`` method, but `requirement` is not optional - for `require`, since you must specify the desired distribution name. - """ - for dist in self.iter_distributions(requirement, path): - dist.require() - return - else: - pass - #raise ImportError( - # "No distributions found matching " + repr(requirement) - #) - - # XXX Not yet implemented def postprocess(self, filename): """Perform any platform-specific postprocessing of file `filename` @@ -155,24 +148,19 @@ This is where Mac header rewrites should be done; other platforms don't have anything special they should do. - Resource providers should call this method after successfully - extracting a compressed resource. They should not call it on resources + Resource providers should call this method ONLY after successfully + extracting a compressed resource. They must NOT call it on resources that are already in the filesystem. """ # XXX - # print "postprocessing", filename - def iter_distributions(self, requirement=None, path=None): - """Iterate over distributions in `path` matching `requirement` - The `path` is a sequence of ``sys.path`` items. If not supplied, - ``sys.path`` is used. - The `requirement` is an optional string specifying the name of the - desired distribution. - """ - # XXX - return () + + + + + def set_extraction_path(self, path): """Set the base path where resources will be extracted to, if needed. @@ -207,9 +195,96 @@ directory used for extractions. """ # XXX - pass + + + + + + +def iter_distributions(requirement=None, path=None): + """Iterate over distributions in `path` matching `requirement` + + The `path` is a sequence of ``sys.path`` items. If not supplied, + ``sys.path`` is used. + + The `requirement` is an optional string specifying the name of the + desired distribution. + """ + if path is None: + path = sys.path + + if requirement is not None: + requirements = list(parse_requirements(requirement)) + try: + requirement, = requirements + except ValueError: + raise ValueError("Must specify exactly one requirement") + + for item in path: + source = get_dist_source(item) + for dist in source.iter_distributions(requirement): + yield dist + + + + + + + + + + + + + + + + + + +def require(*requirements): + """Ensure that distributions matching `requirements` are on ``sys.path`` + + `requirements` must be a string or a (possibly-nested) sequence + thereof, specifying the distributions and versions required. + XXX THIS IS DRAFT CODE FOR DESIGN PURPOSES ONLY RIGHT NOW + """ + all_distros = {} + installed = {} + for dist in iter_distributions(): + key = dist.name.lower() + all_distros.setdefault(key,[]).append(dist) + if dist.installed(): + installed[key] = dist # XXX what if more than one on path? + + all_requirements = {} + + def _require(requirements,source=None): + for req in parse_requirements(requirements): + name,vers = req # XXX + key = name.lower() + all_requirements.setdefault(key,[]).append((req,source)) + if key in installed and not req.matches(installed[key]): + raise ImportError( + "The installed %s distribution does not match" # XXX + ) # XXX should this be a subclass of ImportError? + all_distros[key] = distros = [ + dist for dist in all_distros.get(key,[]) + if req.matches(dist) + ] + if not distros: + raise ImportError( + "No %s distribution matches all criteria for " % name + ) # XXX should this be a subclass of ImportError? + for key in all_requirements.keys(): # XXX sort them + pass + # find "best" distro for key and install it + # after _require()-ing its requirements + + _require(requirements) + class DefaultProvider: """Provides access to package resources in the filesystem""" @@ -243,10 +318,13 @@ return self._get(os.path.join(self.egg_info, *name.split('/'))) def get_metadata_lines(self, name): - for line in self.get_metadata(name).splitlines(): - line = line.strip() - if not line.startswith('#'): - yield line + return yield_lines(self.get_metadata(name)) + + + + + + def _has(self, path): return os.path.exists(path) @@ -265,6 +343,7 @@ register_loader_type(type(None), DefaultProvider) + class NullProvider(DefaultProvider): """Try to implement resource support for arbitrary PEP 302 loaders""" @@ -274,33 +353,36 @@ ) def _get(self, path): - get_data = getattr(self.loader, 'get_data', None) - if get_data is None: - raise NotImplementedError( - "Can't perform this operation for loaders without 'get_data()'" - ) - return get_data(path) + if hasattr(self.loader, 'get_data'): + return self.loader.get_data(path) + raise NotImplementedError( + "Can't perform this operation for loaders without 'get_data()'" + ) register_loader_type(object, NullProvider) + + + + class ZipProvider(DefaultProvider): """Resource support for zips and eggs""" egg_name = None - eagers = None + eagers = None def __init__(self, module): self.module = module self.loader = module.__loader__ self.zipinfo = zipimport._zip_directory_cache[self.loader.archive] - self.zip_pre = self.loader.archive + os.sep + self.zip_pre = self.loader.archive+os.sep path = self.module_path = os.path.dirname(module.__file__) old = None self.prefix = [] - while path != old: + while path!=old: if path.lower().endswith('.egg'): self.egg_name = os.path.basename(path) self.egg_info = os.path.join(path, 'EGG-INFO') @@ -323,22 +405,24 @@ def get_resource_stream(self, manager, resource_name): return StringIO(self.get_resource_string(manager, resource_name)) + + + def _extract_resource(self, manager, resource_name): parts = resource_name.split('/') zip_path = os.path.join(self.module_path, *parts) - zip_stat = self.zipinfo[os.path.join(*(self.prefix + parts))] - t, d, size = zip_stat[5], zip_stat[6], zip_stat[3] + zip_stat = self.zipinfo[os.path.join(*self.prefix+parts)] + t,d,size = zip_stat[5], zip_stat[6], zip_stat[3] date_time = ( - (d >> 9) + 1980, (d >> 5) & 0xF, d & 0x1F, - (t & 0xFFFF) >> 11, (t >> 5) & 0x3F, - (t & 0x1F) * 2, 0, 0, -1 + (d>>9)+1980, (d>>5)&0xF, d&0x1F, # ymd + (t&0xFFFF)>>11, (t>>5)&0x3F, (t&0x1F) * 2, 0, 0, -1 # hms, etc. ) timestamp = time.mktime(date_time) - real_path = manager.get_cache_path(self.egg_name, self.prefix + parts) + real_path = manager.get_cache_path(self.egg_name, self.prefix+parts) if os.path.isfile(real_path): stat = os.stat(real_path) - if stat.st_size == size and stat.st_mtime == timestamp: + if stat.st_size==size and stat.st_mtime==timestamp: # size and stamp match, don't bother extracting return real_path @@ -346,7 +430,7 @@ data = self.loader.get_data(zip_path) open(real_path, 'wb').write(data) - os.utime(real_path, (timestamp, timestamp)) + os.utime(real_path, (timestamp,timestamp)) manager.postprocess(real_path) return real_path @@ -359,6 +443,12 @@ self.eagers = eagers return self.eagers + + + + + + def get_resource_filename(self, manager, resource_name): if not self.egg_name: raise NotImplementedError( @@ -377,14 +467,118 @@ register_loader_type(zipimport.zipimporter, ZipProvider) +def StringIO(*args, **kw): + """Thunk to load the real StringIO on demand""" + global StringIO + try: + from cStringIO import StringIO + except ImportError: + from StringIO import StringIO + return StringIO(*args,**kw) + + +def get_distro_source(path_item): + pass # XXX + + + + + + + + + + + +def yield_lines(strs): + """Yield non-empty/non-comment lines of a ``basestring`` or sequence""" + if isinstance(strs,basestring): + for s in strs.splitlines(): + s = s.strip() + if s and not s.startswith('#'): # skip blank lines/comments + yield s + else: + for ss in strs: + for s in yield_lines(ss): + yield s + +LINE_END = re.compile(r"\s*(#.*)?$").match # whitespace and comment +CONTINUE = re.compile(r"\s*\\\s*(#.*)?$").match # line continuation +DISTRO = re.compile(r"\s*(\w+)").match # Distribution name +VERSION = re.compile(r"\s*(<=?|>=?|==|!=)\s*((\w|\.)+)").match # version info +COMMA = re.compile(r"\s*,").match # comma between items + + + + + + + + + + + + + + + + + + + + + + + + +def parse_requirements(strs): + """Yield ``Requirement`` objects for each specification in `strs` + + `strs` must be an instance of ``basestring``, or a (possibly-nested) + sequence thereof. + """ + # create a steppable iterator, so we can handle \-continuations + lines = iter(yield_lines(strs)) + for line in lines: + line = line.replace('-','_') + match = DISTRO(line) + if not match: + raise ValueError("Missing distribution spec", line) + distname = match.group(1) + p = match.end() + specs = [] + while not LINE_END(line,p): + if CONTINUE(line,p): + try: + line = lines.next().replace('-','_'); p = 0 + except StopIteration: + raise ValueError( + "\\ must not appear on the last nonblank line" + ) + match = VERSION(line,p) + if not match: + raise ValueError("Expected version spec in",line,"at",line[p:]) + specs.append(match.group(1,2)) + p = match.end() + match = COMMA(line,p) + if match: + p = match.end() # skip the comma + elif not LINE_END(line,p): + raise ValueError("Expected ',' or EOL in",line,"at",line[p:]) + + yield distname, specs + + + + + def _get_mro(cls): """Get an mro for a type or classic class""" - if not isinstance(cls, type): - cls = type('', (cls, object), {}) + if not isinstance(cls,type): + class cls(cls,object): pass return cls.__mro__[1:] return cls.__mro__ - def _find_adapter(registry, ob): """Return an adapter factory for `ob` from `registry`""" for t in _get_mro(getattr(ob, '__class__', type(ob))): @@ -407,3 +601,15 @@ if not name.startswith('_'): g[name] = getattr(_manager, name) _initialize(globals()) + + + + + + + + + + + + From nascheme at users.sourceforge.net Sat Apr 2 20:50:16 2005 From: nascheme at users.sourceforge.net (nascheme@users.sourceforge.net) Date: Sat Apr 2 20:50:21 2005 Subject: [Python-checkins] python/dist/src/Python Python-ast.c, 1.1.2.10, 1.1.2.11 ast.c, 1.1.2.56, 1.1.2.57 newcompile.c, 1.1.2.104, 1.1.2.105 symtable.c, 2.10.8.30, 2.10.8.31 Message-ID: Update of /cvsroot/python/python/dist/src/Python In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1290/Python Modified Files: Tag: ast-branch Python-ast.c ast.c newcompile.c symtable.c Log Message: Add support to the AST compiler for decorators (SF patch #1167709). Index: Python-ast.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Python/Attic/Python-ast.c,v retrieving revision 1.1.2.10 retrieving revision 1.1.2.11 diff -u -d -r1.1.2.10 -r1.1.2.11 --- Python-ast.c 20 Mar 2005 23:40:59 -0000 1.1.2.10 +++ Python-ast.c 2 Apr 2005 18:50:06 -0000 1.1.2.11 @@ -1,4 +1,4 @@ -/* File automatically generated by ./Parser/asdl_c.py */ +/* File automatically generated by ../Parser/asdl_c.py */ #include "Python.h" #include "Python-ast.h" @@ -65,7 +65,8 @@ } stmt_ty -FunctionDef(identifier name, arguments_ty args, asdl_seq * body, int lineno) +FunctionDef(identifier name, arguments_ty args, asdl_seq * body, asdl_seq * + decorators, int lineno) { stmt_ty p; if (!name) { @@ -87,6 +88,7 @@ p->v.FunctionDef.name = name; p->v.FunctionDef.args = args; p->v.FunctionDef.body = body; + p->v.FunctionDef.decorators = decorators; p->lineno = lineno; return p; } @@ -1064,6 +1066,10 @@ { int i, n; asdl_seq *seq; + + if (!o) + return; + switch (o->kind) { case Module_kind: seq = o->v.Module.body; @@ -1094,6 +1100,10 @@ { int i, n; asdl_seq *seq; + + if (!o) + return; + switch (o->kind) { case FunctionDef_kind: Py_DECREF((identifier)o->v.FunctionDef.name); @@ -1102,6 +1112,10 @@ n = asdl_seq_LEN(seq); for (i = 0; i < n; i++) free_stmt((stmt_ty)asdl_seq_GET(seq, i)); + seq = o->v.FunctionDef.decorators; + n = asdl_seq_LEN(seq); + for (i = 0; i < n; i++) + free_expr((expr_ty)asdl_seq_GET(seq, i)); break; case ClassDef_kind: Py_DECREF((identifier)o->v.ClassDef.name); @@ -1270,6 +1284,10 @@ { int i, n; asdl_seq *seq; + + if (!o) + return; + switch (o->kind) { case BoolOp_kind: free_boolop((boolop_ty)o->v.BoolOp.op); @@ -1388,6 +1406,10 @@ void free_expr_context(expr_context_ty o) { + + if (!o) + return; + } void @@ -1395,6 +1417,10 @@ { int i, n; asdl_seq *seq; + + if (!o) + return; + switch (o->kind) { case Ellipsis_kind: break; @@ -1424,21 +1450,37 @@ void free_boolop(boolop_ty o) { + + if (!o) + return; + } void free_operator(operator_ty o) { + + if (!o) + return; + } void free_unaryop(unaryop_ty o) { + + if (!o) + return; + } void free_cmpop(cmpop_ty o) { + + if (!o) + return; + } void @@ -1446,6 +1488,10 @@ { int i, n; asdl_seq *seq; + + if (!o) + return; + free_expr((expr_ty)o->target); free_expr((expr_ty)o->iter); seq = o->ifs; @@ -1459,6 +1505,10 @@ { int i, n; asdl_seq *seq; + + if (!o) + return; + if (o->type) { free_expr((expr_ty)o->type); } @@ -1476,6 +1526,10 @@ { int i, n; asdl_seq *seq; + + if (!o) + return; + seq = o->args; n = asdl_seq_LEN(seq); for (i = 0; i < n; i++) @@ -1495,6 +1549,10 @@ void free_keyword(keyword_ty o) { + + if (!o) + return; + Py_DECREF((identifier)o->arg); free_expr((expr_ty)o->value); } @@ -1502,6 +1560,10 @@ void free_alias(alias_ty o) { + + if (!o) + return; + Py_DECREF((identifier)o->name); if (o->asname) { Py_DECREF((identifier)o->asname); @@ -1561,6 +1623,14 @@ void *elt = asdl_seq_GET(o->v.FunctionDef.body, i); marshal_write_stmt(buf, off, (stmt_ty)elt); } + marshal_write_int(buf, off, + asdl_seq_LEN(o->v.FunctionDef.decorators)); + for (i = 0; i < asdl_seq_LEN(o->v.FunctionDef.decorators); i++) + { + void *elt = asdl_seq_GET(o->v.FunctionDef.decorators, + i); + marshal_write_expr(buf, off, (expr_ty)elt); + } break; case ClassDef_kind: marshal_write_int(buf, off, 2); Index: ast.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Python/Attic/ast.c,v retrieving revision 1.1.2.56 retrieving revision 1.1.2.57 diff -u -d -r1.1.2.56 -r1.1.2.57 --- ast.c 21 Mar 2005 00:00:54 -0000 1.1.2.56 +++ ast.c 2 Apr 2005 18:50:06 -0000 1.1.2.57 @@ -47,6 +47,34 @@ #define NEW_IDENTIFIER(n) PyString_InternFromString(STR(n)) +static void +asdl_stmt_seq_free(asdl_seq* seq) +{ + int n, i; + + if (!seq) + return; + + n = asdl_seq_LEN(seq); + for (i = 0; i < n; i++) + free_stmt(asdl_seq_GET(seq, i)); + asdl_seq_free(seq); +} + +static void +asdl_expr_seq_free(asdl_seq* seq) +{ + int n, i; + + if (!seq) + return; + + n = asdl_seq_LEN(seq); + for (i = 0; i < n; i++) + free_expr(asdl_seq_GET(seq, i)); + asdl_seq_free(seq); +} + /* This routine provides an invalid object for the syntax error. The outermost routine must unpack this error and create the proper object. We do this so that we don't have to pass @@ -260,7 +288,7 @@ } error: if (stmts) - asdl_seq_free(stmts); + asdl_stmt_seq_free(stmts); ast_error_finish(filename); return NULL; } @@ -615,23 +643,154 @@ return NULL; } +static expr_ty +ast_for_dotted_name(struct compiling *c, const node *n) +{ + expr_ty e = NULL; + expr_ty attrib = NULL; + identifier id = NULL; + int i; + + REQ(n, dotted_name); + + id = NEW_IDENTIFIER(CHILD(n, 0)); + if (!id) + goto error; + e = Name(id, Load); + if (!e) + goto error; + id = NULL; + + for (i = 2; i < NCH(n); i+=2) { + id = NEW_IDENTIFIER(CHILD(n, i)); + if (!id) + goto error; + attrib = Attribute(e, id, Load); + if (!attrib) + goto error; + e = attrib; + attrib = NULL; + } + + return e; + + error: + Py_XDECREF(id); + free_expr(e); + return NULL; +} + +static expr_ty +ast_for_decorator(struct compiling *c, const node *n) +{ + /* decorator: '@' dotted_name [ '(' [arglist] ')' ] NEWLINE */ + expr_ty d = NULL; + expr_ty name_expr = NULL; + + REQ(n, decorator); + + if ((NCH(n) < 3 && NCH(n) != 5 && NCH(n) != 6) + || TYPE(CHILD(n, 0)) != AT || TYPE(RCHILD(n, -1)) != NEWLINE) { + ast_error(n, "Invalid decorator node"); + goto error; + } + + name_expr = ast_for_dotted_name(c, CHILD(n, 1)); + if (!name_expr) + goto error; + + if (NCH(n) == 3) { /* No arguments */ + d = name_expr; + name_expr = NULL; + } + else if (NCH(n) == 5) { /* Call with no arguments */ + d = Call(name_expr, NULL, NULL, NULL, NULL); + if (!d) + goto error; + name_expr = NULL; + } + else { + d = ast_for_call(c, CHILD(n, 3), name_expr); + if (!d) + goto error; + name_expr = NULL; + } + + return d; + + error: + free_expr(name_expr); + free_expr(d); + return NULL; +} + +static asdl_seq* +ast_for_decorators(struct compiling *c, const node *n) +{ + asdl_seq* decorator_seq = NULL; + expr_ty d = NULL; + int i; + + REQ(n, decorators); + + decorator_seq = asdl_seq_new(NCH(n)); + if (!decorator_seq) + return NULL; + + for (i = 0; i < NCH(n); i++) { + d = ast_for_decorator(c, CHILD(n, i)); + if (!d) + goto error; + asdl_seq_APPEND(decorator_seq, d); + d = NULL; + } + return decorator_seq; + error: + asdl_expr_seq_free(decorator_seq); + free_expr(d); + return NULL; +} + static stmt_ty ast_for_funcdef(struct compiling *c, const node *n) { - /* funcdef: 'def' NAME parameters ':' suite */ - identifier name = NEW_IDENTIFIER(CHILD(n, 1)); - arguments_ty args; - asdl_seq *body; - + /* funcdef: 'def' [decorators] NAME parameters ':' suite */ + identifier name = NULL; + arguments_ty args = NULL; + asdl_seq *body = NULL; + asdl_seq *decorator_seq = NULL; + int name_i; + REQ(n, funcdef); - args = ast_for_arguments(c, CHILD(n, 2)); + + if (NCH(n) == 6) { /* decorators are present */ + decorator_seq = ast_for_decorators(c, CHILD(n, 0)); + if (!decorator_seq) + goto error; + name_i = 2; + } + else { + name_i = 1; + } + + name = NEW_IDENTIFIER(CHILD(n, name_i)); + if (!name) + goto error; + args = ast_for_arguments(c, CHILD(n, name_i + 1)); if (!args) - return NULL; - body = ast_for_suite(c, CHILD(n, 4)); + goto error; + body = ast_for_suite(c, CHILD(n, name_i + 3)); if (!body) - return NULL; + goto error; - return FunctionDef(name, args, body, LINENO(n)); + return FunctionDef(name, args, body, decorator_seq, LINENO(n)); + +error: + asdl_stmt_seq_free(body); + asdl_expr_seq_free(decorator_seq); + free_arguments(args); + Py_XDECREF(name); + return NULL; } static expr_ty Index: newcompile.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Python/Attic/newcompile.c,v retrieving revision 1.1.2.104 retrieving revision 1.1.2.105 diff -u -d -r1.1.2.104 -r1.1.2.105 --- newcompile.c 21 Mar 2005 19:27:42 -0000 1.1.2.104 +++ newcompile.c 2 Apr 2005 18:50:06 -0000 1.1.2.105 @@ -1366,15 +1366,32 @@ } static int +compiler_decorators(struct compiler *c, asdl_seq* decos) +{ + int i; + + if (!decos) + return 1; + + for (i = 0; i < asdl_seq_LEN(decos); i++) { + VISIT(c, expr, asdl_seq_GET(decos, i)); + } + return 1; +} + +static int compiler_function(struct compiler *c, stmt_ty s) { PyCodeObject *co; PyObject *first_const = Py_None; arguments_ty args = s->v.FunctionDef.args; + asdl_seq* decos = s->v.FunctionDef.decorators; stmt_ty st; int i, n, docstring; assert(s->kind == FunctionDef_kind); + if (!compiler_decorators(c, decos)) + return 0; if (args->defaults) VISIT_SEQ(c, expr, args->defaults); if (!compiler_enter_scope(c, s->v.FunctionDef.name, (void *)s, @@ -1421,6 +1438,11 @@ compiler_exit_scope(c); compiler_make_closure(c, co, asdl_seq_LEN(args->defaults)); + + for (i = 0; i < asdl_seq_LEN(decos); i++) { + ADDOP_I(c, CALL_FUNCTION, 1); + } + return compiler_nameop(c, s->v.FunctionDef.name, Store); } Index: symtable.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Python/symtable.c,v retrieving revision 2.10.8.30 retrieving revision 2.10.8.31 diff -u -d -r2.10.8.30 -r2.10.8.31 --- symtable.c 16 Jan 2005 17:09:12 -0000 2.10.8.30 +++ symtable.c 2 Apr 2005 18:50:13 -0000 2.10.8.31 @@ -756,6 +756,8 @@ return 0; if (s->v.FunctionDef.args->defaults) VISIT_SEQ(st, expr, s->v.FunctionDef.args->defaults); + if (s->v.FunctionDef.decorators) + VISIT_SEQ(st, expr, s->v.FunctionDef.decorators); if (!symtable_enter_block(st, s->v.FunctionDef.name, FunctionBlock, (void *)s, s->lineno)) return 0; From nascheme at users.sourceforge.net Sat Apr 2 20:50:39 2005 From: nascheme at users.sourceforge.net (nascheme@users.sourceforge.net) Date: Sat Apr 2 20:50:43 2005 Subject: [Python-checkins] python/dist/src/Include Python-ast.h, 1.1.2.10, 1.1.2.11 Message-ID: Update of /cvsroot/python/python/dist/src/Include In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1290/Include Modified Files: Tag: ast-branch Python-ast.h Log Message: Add support to the AST compiler for decorators (SF patch #1167709). Index: Python-ast.h =================================================================== RCS file: /cvsroot/python/python/dist/src/Include/Attic/Python-ast.h,v retrieving revision 1.1.2.10 retrieving revision 1.1.2.11 diff -u -d -r1.1.2.10 -r1.1.2.11 --- Python-ast.h 20 Mar 2005 23:40:58 -0000 1.1.2.10 +++ Python-ast.h 2 Apr 2005 18:50:05 -0000 1.1.2.11 @@ -1,4 +1,4 @@ -/* File automatically generated by ./Parser/asdl_c.py */ +/* File automatically generated by ../Parser/asdl_c.py */ #include "asdl.h" @@ -70,6 +70,7 @@ identifier name; arguments_ty args; asdl_seq *body; + asdl_seq *decorators; } FunctionDef; struct { @@ -328,8 +329,8 @@ mod_ty Interactive(asdl_seq * body); mod_ty Expression(expr_ty body); mod_ty Suite(asdl_seq * body); -stmt_ty FunctionDef(identifier name, arguments_ty args, asdl_seq * body, int - lineno); +stmt_ty FunctionDef(identifier name, arguments_ty args, asdl_seq * body, + asdl_seq * decorators, int lineno); stmt_ty ClassDef(identifier name, asdl_seq * bases, asdl_seq * body, int lineno); stmt_ty Return(expr_ty value, int lineno); From nascheme at users.sourceforge.net Sat Apr 2 20:50:41 2005 From: nascheme at users.sourceforge.net (nascheme@users.sourceforge.net) Date: Sat Apr 2 20:50:44 2005 Subject: [Python-checkins] python/dist/src/Parser Python.asdl, 1.1.2.8, 1.1.2.9 asdl_c.py, 1.1.2.5, 1.1.2.6 Message-ID: Update of /cvsroot/python/python/dist/src/Parser In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1290/Parser Modified Files: Tag: ast-branch Python.asdl asdl_c.py Log Message: Add support to the AST compiler for decorators (SF patch #1167709). Index: Python.asdl =================================================================== RCS file: /cvsroot/python/python/dist/src/Parser/Attic/Python.asdl,v retrieving revision 1.1.2.8 retrieving revision 1.1.2.9 diff -u -d -r1.1.2.8 -r1.1.2.9 --- Python.asdl 16 Jan 2005 17:09:11 -0000 1.1.2.8 +++ Python.asdl 2 Apr 2005 18:50:05 -0000 1.1.2.9 @@ -9,7 +9,8 @@ -- not really an actual node but useful in Jython's typesystem. | Suite(stmt* body) - stmt = FunctionDef(identifier name, arguments args, stmt* body) + stmt = FunctionDef(identifier name, arguments args, + stmt* body, expr* decorators) | ClassDef(identifier name, expr* bases, stmt* body) | Return(expr? value) | Yield(expr value) Index: asdl_c.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Parser/Attic/asdl_c.py,v retrieving revision 1.1.2.5 retrieving revision 1.1.2.6 diff -u -d -r1.1.2.5 -r1.1.2.6 --- asdl_c.py 20 Mar 2005 23:40:58 -0000 1.1.2.5 +++ asdl_c.py 2 Apr 2005 18:50:05 -0000 1.1.2.6 @@ -371,6 +371,10 @@ if has_seq: self.emit("int i, n;", 1) self.emit("asdl_seq *seq;", 1) + self.emit('', 0) + self.emit('if (!o)', 1) + self.emit('return;', 2) + self.emit('', 0) def func_end(self): self.emit("}", 0) From nascheme at users.sourceforge.net Sat Apr 2 21:00:39 2005 From: nascheme at users.sourceforge.net (nascheme@users.sourceforge.net) Date: Sat Apr 2 21:00:41 2005 Subject: [Python-checkins] python/dist/src/Python ast.c,1.1.2.57,1.1.2.58 Message-ID: Update of /cvsroot/python/python/dist/src/Python In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7231/Python Modified Files: Tag: ast-branch ast.c Log Message: Fix AST compiler handling of unicode literals (SF patch #1170272). Index: ast.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Python/Attic/ast.c,v retrieving revision 1.1.2.57 retrieving revision 1.1.2.58 diff -u -d -r1.1.2.57 -r1.1.2.58 --- ast.c 2 Apr 2005 18:50:06 -0000 1.1.2.57 +++ ast.c 2 Apr 2005 19:00:35 -0000 1.1.2.58 @@ -2546,6 +2546,7 @@ #else PyObject *u, *v; char *s, *t; + t = s = *sPtr; /* while (s < end && *s != '\\') s++; */ /* inefficient for u".." */ while (s < end && (*s & 0x80)) s++; *sPtr = s; @@ -2566,8 +2567,10 @@ char *p; const char *end; if (encoding == NULL) { + buf = s; u = NULL; } else if (strcmp(encoding, "iso-8859-1") == 0) { + buf = s; u = NULL; } else { /* "\XX" may become "\u005c\uHHLL" (12 bytes) */ @@ -2667,15 +2670,7 @@ } #ifdef Py_USING_UNICODE if (unicode || Py_UnicodeFlag) { -#if 0 - /* XXX currently broken */ return decode_unicode(s, len, rawmode, encoding); -#else - if (rawmode) - return PyUnicode_DecodeRawUnicodeEscape(s, len, NULL); - else - return PyUnicode_DecodeUnicodeEscape(s, len, NULL); -#endif } #endif need_encoding = (encoding != NULL && From nascheme at users.sourceforge.net Sat Apr 2 21:00:38 2005 From: nascheme at users.sourceforge.net (nascheme@users.sourceforge.net) Date: Sat Apr 2 21:00:42 2005 Subject: [Python-checkins] python/dist/src/Misc ACKS,1.185.2.2,1.185.2.3 Message-ID: Update of /cvsroot/python/python/dist/src/Misc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7231/Misc Modified Files: Tag: ast-branch ACKS Log Message: Fix AST compiler handling of unicode literals (SF patch #1170272). Index: ACKS =================================================================== RCS file: /cvsroot/python/python/dist/src/Misc/ACKS,v retrieving revision 1.185.2.2 retrieving revision 1.185.2.3 diff -u -d -r1.185.2.2 -r1.185.2.3 --- ACKS 7 Jan 2005 07:02:44 -0000 1.185.2.2 +++ ACKS 2 Apr 2005 19:00:34 -0000 1.185.2.3 @@ -163,6 +163,7 @@ Maxim Dzumanenko Hans Eckardt Grant Edwards +John Ehresman Andrew Eland Lance Ellinghaus David Ely From bcannon at users.sourceforge.net Sat Apr 2 22:14:20 2005 From: bcannon at users.sourceforge.net (bcannon@users.sourceforge.net) Date: Sat Apr 2 22:14:24 2005 Subject: [Python-checkins] python/dist/src/Python compile.txt, 1.1.2.11, 1.1.2.12 Message-ID: Update of /cvsroot/python/python/dist/src/Python In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17137/Python Modified Files: Tag: ast-branch compile.txt Log Message: Tweak todo list: * remove decorators * add mention to change "generator comprehension" to "generator expression" * mention need to explain symbol table pass in-depth Index: compile.txt =================================================================== RCS file: /cvsroot/python/python/dist/src/Python/Attic/compile.txt,v retrieving revision 1.1.2.11 retrieving revision 1.1.2.12 diff -u -d -r1.1.2.11 -r1.1.2.12 --- compile.txt 2 Apr 2005 01:12:56 -0000 1.1.2.11 +++ compile.txt 2 Apr 2005 20:14:18 -0000 1.1.2.12 @@ -446,13 +446,10 @@ ---- + Grammar support (Parser/Python.asdl, Parser/asdl_c.py) - - decorators - empty base class list (``class Class(): pass``) + parse tree->AST support (Python/ast.c) - - decorators - generator expressions + AST->bytecode support (Python/newcompile.c) - - decorators - generator expressions + Stdlib support - AST->Python access? @@ -460,7 +457,10 @@ + Documentation - flesh out this doc * byte stream output + * explanation of how symbol table pass works + Universal + - remove "generator comprehension" mentions and change to "generator + expression" - make sure entire test suite passes - fix memory leaks - make sure return types are properly checked for errors From bcannon at users.sourceforge.net Sat Apr 2 22:21:25 2005 From: bcannon at users.sourceforge.net (bcannon@users.sourceforge.net) Date: Sat Apr 2 22:21:29 2005 Subject: [Python-checkins] python/dist/src/Python compile.txt, 1.1.2.12, 1.1.2.13 Message-ID: Update of /cvsroot/python/python/dist/src/Python In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20645/Python Modified Files: Tag: ast-branch compile.txt Log Message: Fix ASDL example to include decorators. Index: compile.txt =================================================================== RCS file: /cvsroot/python/python/dist/src/Python/Attic/compile.txt,v retrieving revision 1.1.2.12 retrieving revision 1.1.2.13 diff -u -d -r1.1.2.12 -r1.1.2.13 --- compile.txt 2 Apr 2005 20:14:18 -0000 1.1.2.12 +++ compile.txt 2 Apr 2005 20:21:23 -0000 1.1.2.13 @@ -119,11 +119,10 @@ The following fragment of the Python ASDL construct demonstrates the approach and syntax:: - XXX update example once decorators in - module Python { - stmt = FunctionDef(identifier name, arguments args, stmt* body) + stmt = FunctionDef(identifier name, arguments args, stmt* body, + expr* decorators) | Return(expr? value) | Yield(expr value) attributes (int lineno) } @@ -136,8 +135,9 @@ Modifiers on the argument type specify the number of values needed; '?' means it is optional, '*' means 0 or more, no modifier means only one value for the argument and it is required. FunctionDef, for instance, -takes an identifier for the name, 'arguments' for args, and zero or more -stmt arguments for 'body'. +takes an identifier for the name, 'arguments' for args, zero or more +stmt arguments for 'body', and zero or more expr arguments for +'decorators'. Do notice that something like 'arguments', which is a node type, is represented as a single AST node and not as a sequence of nodes as with From pje at users.sourceforge.net Sun Apr 3 01:31:32 2005 From: pje at users.sourceforge.net (pje@users.sourceforge.net) Date: Sun Apr 3 01:31:35 2005 Subject: [Python-checkins] python/nondist/sandbox/setuptools/setuptools/tests test_resources.py, 1.1, 1.2 Message-ID: Update of /cvsroot/python/python/nondist/sandbox/setuptools/setuptools/tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22724/setuptools/tests Modified Files: test_resources.py Log Message: Add a simple version parser that combines the pre-release smarts of distutils' StrictVersion, with the flexibility of LooseVersion. It also deals heuristically with common concepts like alpha/beta/candidate/rc and pre/preview, as well as '-' and 'pl' branching schemes. Index: test_resources.py =================================================================== RCS file: /cvsroot/python/python/nondist/sandbox/setuptools/setuptools/tests/test_resources.py,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- test_resources.py 2 Apr 2005 02:43:21 -0000 1.1 +++ test_resources.py 2 Apr 2005 23:31:13 -0000 1.2 @@ -31,3 +31,61 @@ self.assertRaises(ValueError,lambda:list(parse_requirements("x\\"))) self.assertRaises(ValueError,lambda:list(parse_requirements("x==2 q"))) + + + + + + + + + def testVersionOrdering(self): + def c(s1,s2): + p1, p2 = parse_version(s1),parse_version(s2) + self.failUnless(p1 Update of /cvsroot/python/python/nondist/sandbox/setuptools In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22724 Modified Files: pkg_resources.py Log Message: Add a simple version parser that combines the pre-release smarts of distutils' StrictVersion, with the flexibility of LooseVersion. It also deals heuristically with common concepts like alpha/beta/candidate/rc and pre/preview, as well as '-' and 'pl' branching schemes. Index: pkg_resources.py =================================================================== RCS file: /cvsroot/python/python/nondist/sandbox/setuptools/pkg_resources.py,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- pkg_resources.py 2 Apr 2005 02:43:20 -0000 1.5 +++ pkg_resources.py 2 Apr 2005 23:31:12 -0000 1.6 @@ -17,7 +17,7 @@ 'register_loader_type', 'get_provider', 'IResourceProvider', 'ResourceManager', 'iter_distributions', 'require', 'resource_string', 'resource_stream', 'resource_filename', 'set_extraction_path', - 'cleanup_resources', 'parse_requirements', # 'glob_resources' + 'cleanup_resources', 'parse_requirements', 'parse_version'# 'glob_resources' ] import sys, os, zipimport, time, re @@ -508,8 +508,20 @@ VERSION = re.compile(r"\s*(<=?|>=?|==|!=)\s*((\w|\.)+)").match # version info COMMA = re.compile(r"\s*,").match # comma between items +component_re = re.compile(r'(\d+ | [a-z]+ | \.| -)', re.VERBOSE) +replace = {'pre':'c', 'preview':'c','-':'final-','rc':'c'}.get +def _parse_version_parts(s): + for part in component_re.split(s): + part = replace(part,part) + if not part or part=='.': + continue + if part[:1] in '0123456789': + yield part.zfill(8) # pad for numeric comparison + else: + yield '*'+part + yield '*final' # ensure that alpha/beta/candidate are before final @@ -519,12 +531,41 @@ +def parse_version(s): + """Convert a version string to a sortable key + This is a rough cross between distutils' StrictVersion and LooseVersion; + if you give it versions that would work with StrictVersion, then it behaves + the same; otherwise it acts like a slightly-smarter LooseVersion. + The returned value will be a tuple of strings. Numeric portions of the + version are padded to 8 digits so they will compare numerically, but + without relying on how numbers compare relative to strings. Dots are + dropped, but dashes are retained. Trailing zeros between alpha segments + or dashes are suppressed, so that e.g. 2.4.0 is considered the same as 2.4. + Alphanumeric parts are lower-cased. + + The algorithm assumes that strings like '-' and any alpha string > "final" + represents a "patch level". So, "2.4-1" is assumed to be a branch or patch + of "2.4", and therefore "2.4.1" is considered newer than "2.4-1". + Strings like "a", "b", "c", "alpha", "beta", "candidate" and so on (that + come before "final" alphabetically) are assumed to be pre-release versions, + and so the version "2.4" is considered newer than "2.4a1". - - + Finally, to handle miscellaneous cases, the strings "pre", "preview", and + "rc" are treated as if they were "c", i.e. as though they were release + candidates, and therefore are not as new as a version string that does not + contain them. + """ + parts = [] + for part in _parse_version_parts(s.lower()): + if part.startswith('*'): + # remove trailing zeros from each series of numeric parts + while parts and parts[-1]=='00000000': + parts.pop() + parts.append(part) + return tuple(parts) From pje at users.sourceforge.net Sun Apr 3 02:47:00 2005 From: pje at users.sourceforge.net (pje@users.sourceforge.net) Date: Sun Apr 3 02:47:03 2005 Subject: [Python-checkins] python/nondist/sandbox/setuptools pkg_resources.py, 1.6, 1.7 Message-ID: Update of /cvsroot/python/python/nondist/sandbox/setuptools In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29068 Modified Files: pkg_resources.py Log Message: Add a "Distribution" object that wraps a sys.path entry with metadata, and can extract its name/version/pythonversion/platform if built from a .egg filename. Later, distributions will be able to add themselves to sys.path and request that their dependencies be added as well. Also, added some real-life version test cases supplied by jemfinch. Index: pkg_resources.py =================================================================== RCS file: /cvsroot/python/python/nondist/sandbox/setuptools/pkg_resources.py,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- pkg_resources.py 2 Apr 2005 23:31:12 -0000 1.6 +++ pkg_resources.py 3 Apr 2005 00:46:56 -0000 1.7 @@ -17,7 +17,8 @@ 'register_loader_type', 'get_provider', 'IResourceProvider', 'ResourceManager', 'iter_distributions', 'require', 'resource_string', 'resource_stream', 'resource_filename', 'set_extraction_path', - 'cleanup_resources', 'parse_requirements', 'parse_version'# 'glob_resources' + 'cleanup_resources', 'parse_requirements', 'parse_version', + 'Distribution', # 'glob_resources' ] import sys, os, zipimport, time, re @@ -38,7 +39,6 @@ loader = getattr(module, '__loader__', None) return _find_adapter(_provider_factories, loader)(module) - class IResourceProvider: """An object that provides access to package resources""" @@ -508,6 +508,12 @@ VERSION = re.compile(r"\s*(<=?|>=?|==|!=)\s*((\w|\.)+)").match # version info COMMA = re.compile(r"\s*,").match # comma between items +EGG_NAME = re.compile( + r"(?P[^-]+)" + r"( -(?P[^-]+) (-py(?P[^-]+) (-(?P.+))? )? )?", + re.VERBOSE | re.IGNORECASE +).match + component_re = re.compile(r'(\d+ | [a-z]+ | \.| -)', re.VERBOSE) replace = {'pre':'c', 'preview':'c','-':'final-','rc':'c'}.get @@ -525,12 +531,6 @@ - - - - - - def parse_version(s): """Convert a version string to a sortable key @@ -572,6 +572,88 @@ +class Distribution(object): + """Wrap an actual or potential sys.path entry w/metadata""" + + def __init__(self, + path_str, metadata=None, name=None, version=None, + py_version=sys.version[:3] + ): + if name: + self.name = name + if version: + self.version = version + + self.py_version = py_version + self.path = path_str + self.normalized_path = os.path.normpath(os.path.normcase(path_str)) + + def installed_on(self,path=None): + """Is this distro installed on `path`? (defaults to ``sys.path``)""" + if path is None: + path = sys.path + if self.path in path or self.normalized_path in path: + return True + for item in path: + normalized = os.path.normpath(os.path.normcase(item)) + if normalized == self.normalized_path: + return True + return False + + + + + + + + + + + + + + + #@classmethod + def from_filename(cls,filename,metadata=None): + name,version,py_version,platform = [None]*4 + basename,ext = os.path.splitext(os.path.basename(filename)) + if ext.lower()==".egg": + match = EGG_NAME(basename) + if match: + name,version,py_version,platform = match.group( + 'name','ver','pyver','plat' + ) + if version and '_' in version: + version = version.replace('_','-') + return cls( + filename,metadata,name=name,version=version,py_version=py_version + ) + from_filename = classmethod(from_filename) + + # These properties have to be lazy so that we don't have to load any + # metadata until/unless it's actually needed. (i.e., some distributions + # may not know their name or version without loading PKG-INFO) + + #@property + def key(self): + try: + return self._key + except AttributeError: + self._key = key = self.name.lower() + return key + key = property(key) + + #@property + def parsed_version(self): + try: + return self._parsed_version + except AttributeError: + self._parsed_version = pv = parse_version(self.version) + return pv + + parsed_version = property(parsed_version) + + def parse_requirements(strs): """Yield ``Requirement`` objects for each specification in `strs` From pje at users.sourceforge.net Sun Apr 3 02:47:01 2005 From: pje at users.sourceforge.net (pje@users.sourceforge.net) Date: Sun Apr 3 02:47:04 2005 Subject: [Python-checkins] python/nondist/sandbox/setuptools/setuptools/tests test_resources.py, 1.2, 1.3 Message-ID: Update of /cvsroot/python/python/nondist/sandbox/setuptools/setuptools/tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29068/setuptools/tests Modified Files: test_resources.py Log Message: Add a "Distribution" object that wraps a sys.path entry with metadata, and can extract its name/version/pythonversion/platform if built from a .egg filename. Later, distributions will be able to add themselves to sys.path and request that their dependencies be added as well. Also, added some real-life version test cases supplied by jemfinch. Index: test_resources.py =================================================================== RCS file: /cvsroot/python/python/nondist/sandbox/setuptools/setuptools/tests/test_resources.py,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- test_resources.py 2 Apr 2005 23:31:13 -0000 1.2 +++ test_resources.py 3 Apr 2005 00:46:58 -0000 1.3 @@ -1,13 +1,46 @@ from unittest import TestCase, makeSuite from pkg_resources import * -import pkg_resources +import pkg_resources, sys class DistroTests(TestCase): + def testEmptyiter(self): # empty path should produce no distributions self.assertEqual(list(iter_distributions(path=[])), []) + def checkFooPkg(self,d): + self.assertEqual(d.name, "FooPkg") + self.assertEqual(d.key, "foopkg") + self.assertEqual(d.version, "1.3-1") + self.assertEqual(d.py_version, "2.4") + self.assertEqual(d.parsed_version, parse_version("1.3-1")) + + def testDistroBasics(self): + d = Distribution( + "/some/path", + name="FooPkg",version="1.3-1",py_version="2.4" + ) + self.checkFooPkg(d) + self.failUnless(d.installed_on(["/some/path"])) + self.failIf(d.installed_on([])) + + d = Distribution("/some/path") + self.assertEqual(d.py_version, sys.version[:3]) + + def testDistroParse(self): + d = Distribution.from_filename("FooPkg-1.3_1-py2.4-win32.egg") + self.checkFooPkg(d) + + + + + + + + + class ParseTests(TestCase): + def testEmptyParse(self): self.assertEqual(list(parse_requirements('')), []) @@ -39,14 +72,22 @@ + + + + + + + + def testVersionOrdering(self): def c(s1,s2): p1, p2 = parse_version(s1),parse_version(s2) self.failUnless(p1 Update of /cvsroot/python/python/nondist/sandbox/setuptools/setuptools/tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15837/setuptools/tests Modified Files: test_resources.py Log Message: Fix handling of -/_ so that they are canonicalized to '-' when doing name or version comparisons, but rendered as '_' in egg filenames. Index: test_resources.py =================================================================== RCS file: /cvsroot/python/python/nondist/sandbox/setuptools/setuptools/tests/test_resources.py,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- test_resources.py 3 Apr 2005 00:46:58 -0000 1.3 +++ test_resources.py 3 Apr 2005 01:21:08 -0000 1.4 @@ -53,8 +53,8 @@ def testSimple(self): self.assertEqual( - list(parse_requirements('Twis-Ted>=1.2')), - [('Twis_Ted',[('>=','1.2')])] + list(parse_requirements('Twis-Ted>=1.2-1')), + [('Twis-Ted',[('>=','1.2-1')])] ) self.assertEqual( list(parse_requirements('Twisted >=1.2, \ # more\n<2.0')), From pje at users.sourceforge.net Sun Apr 3 03:21:11 2005 From: pje at users.sourceforge.net (pje@users.sourceforge.net) Date: Sun Apr 3 03:21:17 2005 Subject: [Python-checkins] python/nondist/sandbox/setuptools pkg_resources.py, 1.7, 1.8 Message-ID: Update of /cvsroot/python/python/nondist/sandbox/setuptools In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15837 Modified Files: pkg_resources.py Log Message: Fix handling of -/_ so that they are canonicalized to '-' when doing name or version comparisons, but rendered as '_' in egg filenames. Index: pkg_resources.py =================================================================== RCS file: /cvsroot/python/python/nondist/sandbox/setuptools/pkg_resources.py,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- pkg_resources.py 3 Apr 2005 00:46:56 -0000 1.7 +++ pkg_resources.py 3 Apr 2005 01:21:08 -0000 1.8 @@ -623,6 +623,7 @@ name,version,py_version,platform = match.group( 'name','ver','pyver','plat' ) + name = name.replace('_','-') if version and '_' in version: version = version.replace('_','-') return cls( @@ -653,7 +654,6 @@ parsed_version = property(parsed_version) - def parse_requirements(strs): """Yield ``Requirement`` objects for each specification in `strs` @@ -681,7 +681,8 @@ match = VERSION(line,p) if not match: raise ValueError("Expected version spec in",line,"at",line[p:]) - specs.append(match.group(1,2)) + op,val = match.group(1,2) + specs.append((op,val.replace('_','-'))) p = match.end() match = COMMA(line,p) if match: @@ -689,7 +690,7 @@ elif not LINE_END(line,p): raise ValueError("Expected ',' or EOL in",line,"at",line[p:]) - yield distname, specs + yield distname.replace('_','-'), specs From pje at users.sourceforge.net Sun Apr 3 19:23:41 2005 From: pje at users.sourceforge.net (pje@users.sourceforge.net) Date: Sun Apr 3 19:23:44 2005 Subject: [Python-checkins] python/nondist/sandbox/setuptools setup.py, 1.3, 1.4 setuptools_boot.py, 1.1, NONE Message-ID: Update of /cvsroot/python/python/nondist/sandbox/setuptools In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22274 Modified Files: setup.py Removed Files: setuptools_boot.py Log Message: Remove setuptools_boot.py, as it can now be trivially replaced by including a setuptools .egg file in your source distribution, and adding it to sys.path in your setup.py. Index: setup.py =================================================================== RCS file: /cvsroot/python/python/nondist/sandbox/setuptools/setup.py,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- setup.py 23 Mar 2005 00:42:52 -0000 1.3 +++ setup.py 3 Apr 2005 17:23:22 -0000 1.4 @@ -22,6 +22,6 @@ Require('PyUnit', None, 'unittest', "http://pyunit.sf.net/"), ], packages = find_packages(), - py_modules = ['setuptools_boot', 'pkg_resources'], + py_modules = ['pkg_resources'], ) --- setuptools_boot.py DELETED --- From pje at users.sourceforge.net Sun Apr 3 20:52:24 2005 From: pje at users.sourceforge.net (pje@users.sourceforge.net) Date: Sun Apr 3 20:52:27 2005 Subject: [Python-checkins] python/nondist/sandbox/setuptools/setuptools/command bdist_egg.py, 1.6, 1.7 Message-ID: Update of /cvsroot/python/python/nondist/sandbox/setuptools/setuptools/command In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14433/setuptools/command Modified Files: bdist_egg.py Log Message: Added "AvailableDistributions" class that finds and indexes usable distributions; this replaces the previous "iter_distributions()" API. Added basic platform support to Distribution and AvailableDistributions so that platform-independent distros as well as local platform-compatible distros are acceptable. The actual platform scheme is currently delegated to distutils.util.get_platform(), but needs to be replaced with a better scheme of some kind, especially for OS X. Index: bdist_egg.py =================================================================== RCS file: /cvsroot/python/python/nondist/sandbox/setuptools/setuptools/command/bdist_egg.py,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- bdist_egg.py 2 Apr 2005 02:43:20 -0000 1.6 +++ bdist_egg.py 3 Apr 2005 18:52:21 -0000 1.7 @@ -10,7 +10,7 @@ from distutils.sysconfig import get_python_version from distutils.errors import * from distutils import log -from pkg_resources import parse_requirements +from pkg_resources import parse_requirements, get_platform class bdist_egg(Command): @@ -75,9 +75,9 @@ if self.bdist_dir is None: bdist_base = self.get_finalized_command('bdist').bdist_base self.bdist_dir = os.path.join(bdist_base, 'egg') - self.set_undefined_options('bdist', - ('dist_dir', 'dist_dir'), - ('plat_name', 'plat_name')) + if self.plat_name is None: + self.plat_name = get_platform() + self.set_undefined_options('bdist',('dist_dir', 'dist_dir')) def write_stub(self, resource, pyfile): From pje at users.sourceforge.net Sun Apr 3 20:52:23 2005 From: pje at users.sourceforge.net (pje@users.sourceforge.net) Date: Sun Apr 3 20:52:28 2005 Subject: [Python-checkins] python/nondist/sandbox/setuptools pkg_resources.py, 1.8, 1.9 Message-ID: Update of /cvsroot/python/python/nondist/sandbox/setuptools In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14433 Modified Files: pkg_resources.py Log Message: Added "AvailableDistributions" class that finds and indexes usable distributions; this replaces the previous "iter_distributions()" API. Added basic platform support to Distribution and AvailableDistributions so that platform-independent distros as well as local platform-compatible distros are acceptable. The actual platform scheme is currently delegated to distutils.util.get_platform(), but needs to be replaced with a better scheme of some kind, especially for OS X. Index: pkg_resources.py =================================================================== RCS file: /cvsroot/python/python/nondist/sandbox/setuptools/pkg_resources.py,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- pkg_resources.py 3 Apr 2005 01:21:08 -0000 1.8 +++ pkg_resources.py 3 Apr 2005 18:52:21 -0000 1.9 @@ -15,13 +15,30 @@ """ __all__ = [ 'register_loader_type', 'get_provider', 'IResourceProvider', - 'ResourceManager', 'iter_distributions', 'require', 'resource_string', + 'ResourceManager', 'AvailableDistributions', 'require', 'resource_string', 'resource_stream', 'resource_filename', 'set_extraction_path', 'cleanup_resources', 'parse_requirements', 'parse_version', + 'compatible_platforms', 'get_platform', 'Distribution', # 'glob_resources' ] import sys, os, zipimport, time, re + +def _sort_dists(dists): + tmp = [(dist.version,dist) for dist in dists] + tmp.sort() + tmp.reverse() + dists[:] = [d for v,d in tmp] + + + + + + + + + + _provider_factories = {} def register_loader_type(loader_type, provider_factory): @@ -39,6 +56,30 @@ loader = getattr(module, '__loader__', None) return _find_adapter(_provider_factories, loader)(module) +def get_platform(): + """Return this platform's string for platform-specific distributions + + XXX Currently this is the same as ``distutils.util.get_platform()``, but it + needs some hacks for Linux and Mac OS X. + """ + from distutils.util import get_platform + return get_platform() + +def compatible_platforms(provided,required): + """Can code for the `provided` platform run on the `required` platform? + + Returns true if either platform is ``None``, or the platforms are equal. + + XXX Needs compatibility checks for Linux and Mac OS X. + """ + if provided is None or required is None or provided==required: + return True # easy case + + # XXX all the tricky cases go here + + return False + + class IResourceProvider: """An object that provides access to package resources""" @@ -80,46 +121,128 @@ -class ResourceManager: - """Manage resource extraction and packages""" +class AvailableDistributions(object): + """Searchable snapshot of distributions on a search path""" - extraction_path = None + def __init__(self, search_path=None, platform=get_platform()): + """Snapshot distributions available on a search path - def __init__(self): - self.cached_files = [] + `search_path` should be a sequence of ``sys.path`` items. If not + supplied, ``sys.path`` is used. - def resource_exists(self, package_name, resource_name): - """Does the named resource exist in the named package?""" - return get_provider(package_name).has_resource(self, resource_name) + The `platform` is an optional string specifying the name of the + platform that platform-specific distributions must be compatible + with. If not specified, it defaults to the current platform + (as defined by the result of ``get_platform()`` when ``pkg_resources`` + was first imported.) - def resource_filename(self, package_name, resource_name): - """Return a true filesystem path for specified resource""" - return get_provider(package_name).get_resource_filename(self,resource_name) + You may explicitly set `platform` to ``None`` if you wish to map *all* + distributions, not just those compatible with the running platform. + """ - def resource_stream(self, package_name, resource_name): - """Return a readable file-like object for specified resource""" - return get_provider(package_name).get_resource_stream(self,resource_name) + self._distmap = {} + self._cache = {} + self.scan(search_path,platform) - def resource_string(self, package_name, resource_name): - """Return specified resource as a string""" - return get_provider(package_name).get_resource_string(self,resource_name) + def __iter__(self): + """Iterate over distribution keys""" + return iter(self._distmap.keys()) + def __contains__(self,name): + """Has a distribution named `name` ever been added to this map?""" + return name.lower() in self._distmap + def __len__(self): + return len(self._distmap) + def get(self,key,default=None): + """Return ``self[key]`` if `key` in self, otherwise return `default`""" + if key in self: + return self[key] + else: + return default + def scan(self, search_path=None, platform=get_platform()): + """Scan `search_path` for distributions usable on `platform` + Any distributions found are added to the distribution map. + `search_path` should be a sequence of ``sys.path`` items. If not + supplied, ``sys.path`` is used. `platform` is an optional string + specifying the name of the platform that platform-specific + distributions must be compatible with. If unspecified, it defaults to + the current platform. + You may explicitly set `platform` to ``None`` if you wish to map *all* + distributions, not just those compatible with the running platform. + """ + if search_path is None: + search_path = sys.path + add = self.add + for item in search_path: + source = get_dist_source(item) + for dist in source.iter_distributions(requirement): + if compatible_platforms(dist.platform, platform): + add(dist) + def __getitem__(self,key): + """Return a newest-to-oldest list of distributions for the given key + The returned list may be modified in-place, e.g. for narrowing down + usable distributions. + """ + try: + return self._cache[key] + except KeyError: + key = key.lower() + if key not in self._distmap: + raise + if key not in self._cache: + dists = self._cache[key] = self._distmap[key] + _sort_dists(dists) + return self._cache[key] + def add(self,dist): + """Add `dist` to the distribution map""" + self._distmap.setdefault(dist.key,[]).append(dist) + if dist.key in self._cache: + _sort_dists(self._cache[dist.key]) + def remove(self,dist): + """Remove `dist` from the distribution map""" + self._distmap[dist.key].remove(dist) +class ResourceManager: + """Manage resource extraction and packages""" + extraction_path = None + def __init__(self): + self.cached_files = [] + def resource_exists(self, package_name, resource_name): + """Does the named resource exist in the named package?""" + return get_provider(package_name).has_resource(self, resource_name) + + def resource_filename(self, package_name, resource_name): + """Return a true filesystem path for specified resource""" + return get_provider(package_name).get_resource_filename( + self,resource_name + ) + + def resource_stream(self, package_name, resource_name): + """Return a readable file-like object for specified resource""" + return get_provider(package_name).get_resource_stream( + self, resource_name + ) + + def resource_string(self, package_name, resource_name): + """Return specified resource as a string""" + return get_provider(package_name).get_resource_string( + self, resource_name + ) def get_cache_path(self, archive_name, names=()): """Return absolute location in cache for `archive_name` and `names` @@ -203,47 +326,6 @@ -def iter_distributions(requirement=None, path=None): - """Iterate over distributions in `path` matching `requirement` - - The `path` is a sequence of ``sys.path`` items. If not supplied, - ``sys.path`` is used. - - The `requirement` is an optional string specifying the name of the - desired distribution. - """ - if path is None: - path = sys.path - - if requirement is not None: - requirements = list(parse_requirements(requirement)) - try: - requirement, = requirements - except ValueError: - raise ValueError("Must specify exactly one requirement") - - for item in path: - source = get_dist_source(item) - for dist in source.iter_distributions(requirement): - yield dist - - - - - - - - - - - - - - - - - - def require(*requirements): """Ensure that distributions matching `requirements` are on ``sys.path`` @@ -251,14 +333,8 @@ thereof, specifying the distributions and versions required. XXX THIS IS DRAFT CODE FOR DESIGN PURPOSES ONLY RIGHT NOW """ - all_distros = {} + all_distros = AvailableDistributions() installed = {} - for dist in iter_distributions(): - key = dist.name.lower() - all_distros.setdefault(key,[]).append(dist) - if dist.installed(): - installed[key] = dist # XXX what if more than one on path? - all_requirements = {} def _require(requirements,source=None): @@ -282,9 +358,15 @@ pass # find "best" distro for key and install it # after _require()-ing its requirements - + _require(requirements) - + + + + + + + class DefaultProvider: """Provides access to package resources in the filesystem""" @@ -544,7 +626,7 @@ dropped, but dashes are retained. Trailing zeros between alpha segments or dashes are suppressed, so that e.g. 2.4.0 is considered the same as 2.4. Alphanumeric parts are lower-cased. - + The algorithm assumes that strings like '-' and any alpha string > "final" represents a "patch level". So, "2.4-1" is assumed to be a branch or patch of "2.4", and therefore "2.4.1" is considered newer than "2.4-1". @@ -556,7 +638,7 @@ Finally, to handle miscellaneous cases, the strings "pre", "preview", and "rc" are treated as if they were "c", i.e. as though they were release candidates, and therefore are not as new as a version string that does not - contain them. + contain them. """ parts = [] for part in _parse_version_parts(s.lower()): @@ -574,17 +656,18 @@ class Distribution(object): """Wrap an actual or potential sys.path entry w/metadata""" - + def __init__(self, path_str, metadata=None, name=None, version=None, - py_version=sys.version[:3] + py_version=sys.version[:3], platform=None ): if name: - self.name = name + self.name = name.replace('_','-') if version: - self.version = version + self.version = version.replace('_','-') self.py_version = py_version + self.platform = platform self.path = path_str self.normalized_path = os.path.normpath(os.path.normcase(path_str)) @@ -612,7 +695,6 @@ - #@classmethod def from_filename(cls,filename,metadata=None): name,version,py_version,platform = [None]*4 @@ -623,11 +705,9 @@ name,version,py_version,platform = match.group( 'name','ver','pyver','plat' ) - name = name.replace('_','-') - if version and '_' in version: - version = version.replace('_','-') return cls( - filename,metadata,name=name,version=version,py_version=py_version + filename, metadata, name=name, version=version, + py_version=py_version, platform=platform ) from_filename = classmethod(from_filename) @@ -653,7 +733,9 @@ return pv parsed_version = property(parsed_version) - + + + def parse_requirements(strs): """Yield ``Requirement`` objects for each specification in `strs` @@ -695,7 +777,6 @@ - def _get_mro(cls): """Get an mro for a type or classic class""" if not isinstance(cls,type): From pje at users.sourceforge.net Sun Apr 3 20:52:24 2005 From: pje at users.sourceforge.net (pje@users.sourceforge.net) Date: Sun Apr 3 20:52:28 2005 Subject: [Python-checkins] python/nondist/sandbox/setuptools/setuptools/tests test_resources.py, 1.4, 1.5 Message-ID: Update of /cvsroot/python/python/nondist/sandbox/setuptools/setuptools/tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14433/setuptools/tests Modified Files: test_resources.py Log Message: Added "AvailableDistributions" class that finds and indexes usable distributions; this replaces the previous "iter_distributions()" API. Added basic platform support to Distribution and AvailableDistributions so that platform-independent distros as well as local platform-compatible distros are acceptable. The actual platform scheme is currently delegated to distutils.util.get_platform(), but needs to be replaced with a better scheme of some kind, especially for OS X. Index: test_resources.py =================================================================== RCS file: /cvsroot/python/python/nondist/sandbox/setuptools/setuptools/tests/test_resources.py,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- test_resources.py 3 Apr 2005 01:21:08 -0000 1.4 +++ test_resources.py 3 Apr 2005 18:52:21 -0000 1.5 @@ -4,21 +4,53 @@ class DistroTests(TestCase): - def testEmptyiter(self): + def testCollection(self): # empty path should produce no distributions - self.assertEqual(list(iter_distributions(path=[])), []) + ad = AvailableDistributions([]) + self.assertEqual(list(ad), []) + self.assertEqual(len(ad),0) + self.assertEqual(ad.get('FooPkg'),None) + self.failIf('FooPkg' in ad) + ad.add(Distribution.from_filename("FooPkg-1.3_1.egg")) + ad.add(Distribution.from_filename("FooPkg-1.4-py2.4-win32.egg")) + ad.add(Distribution.from_filename("FooPkg-1.2-py2.4.egg")) + + # Name is in there now + self.failUnless('FooPkg' in ad) + + # But only 1 package + self.assertEqual(list(ad), ['foopkg']) + self.assertEqual(len(ad),1) + + # Distributions sort by version + self.assertEqual( + [dist.version for dist in ad['FooPkg']], ['1.4','1.3-1','1.2'] + ) + + # Removing a distribution leaves sequence alone + ad.remove(ad['FooPkg'][1]) + self.assertEqual( + [dist.version for dist in ad.get('FooPkg')], ['1.4','1.2'] + ) + + # And inserting adds them in order + ad.add(Distribution.from_filename("FooPkg-1.9.egg")) + self.assertEqual( + [dist.version for dist in ad['FooPkg']], ['1.9','1.4','1.2'] + ) def checkFooPkg(self,d): self.assertEqual(d.name, "FooPkg") self.assertEqual(d.key, "foopkg") self.assertEqual(d.version, "1.3-1") self.assertEqual(d.py_version, "2.4") + self.assertEqual(d.platform, "win32") self.assertEqual(d.parsed_version, parse_version("1.3-1")) - + def testDistroBasics(self): d = Distribution( "/some/path", - name="FooPkg",version="1.3-1",py_version="2.4" + name="FooPkg",version="1.3-1",py_version="2.4",platform="win32" ) self.checkFooPkg(d) self.failUnless(d.installed_on(["/some/path"])) @@ -26,11 +58,20 @@ d = Distribution("/some/path") self.assertEqual(d.py_version, sys.version[:3]) + self.assertEqual(d.platform, None) def testDistroParse(self): d = Distribution.from_filename("FooPkg-1.3_1-py2.4-win32.egg") self.checkFooPkg(d) - + + + + + + + + + @@ -107,7 +148,7 @@ 0.79.9999+0.80.0pre2-3 0.79.9999+0.80.0pre2-2 0.77.2-1 0.77.1-1 0.77.0-1 """.split() - + for p,v1 in enumerate(torture): for v2 in torture[p+1:]: c(v2,v1) From perky at users.sourceforge.net Mon Apr 4 17:21:07 2005 From: perky at users.sourceforge.net (perky@users.sourceforge.net) Date: Mon Apr 4 17:21:09 2005 Subject: [Python-checkins] python/dist/src/Lib/test test_fcntl.py,1.26,1.27 Message-ID: Update of /cvsroot/python/python/dist/src/Lib/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3285/Lib/test Modified Files: test_fcntl.py Log Message: Fix testcase for 64bit BSD systems: long is 8 bytes for those systems so there's no need to pad after off_t members. And a small typo fix. Index: test_fcntl.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Lib/test/test_fcntl.py,v retrieving revision 1.26 retrieving revision 1.27 diff -u -d -r1.26 -r1.27 --- test_fcntl.py 18 Aug 2004 15:13:41 -0000 1.26 +++ test_fcntl.py 4 Apr 2005 15:21:04 -0000 1.27 @@ -24,7 +24,13 @@ 'freebsd2', 'freebsd3', 'freebsd4', 'freebsd5', 'freebsd6', 'bsdos2', 'bsdos3', 'bsdos4', 'openbsd', 'openbsd2', 'openbsd3'): - lockdata = struct.pack('lxxxxlxxxxlhh', 0, 0, 0, fcntl.F_WRLCK, 0) + if struct.calcsize('l') == 8: + off_t = 'l' + pid_t = 'i' + else: + off_t = 'lxxxx' + pid_t = 'l' + lockdata = struct.pack(off_t+off_t+pid_t+'hh', 0, 0, 0, fcntl.F_WRLCK, 0) elif sys.platform in ['aix3', 'aix4', 'hp-uxB', 'unixware7']: lockdata = struct.pack('hhlllii', fcntl.F_WRLCK, 0, 0, 0, 0, 0, 0) elif sys.platform in ['os2emx']: @@ -39,7 +45,7 @@ f = open(filename, 'w') rv = fcntl.fcntl(f.fileno(), fcntl.F_SETFL, os.O_NONBLOCK) if verbose: - print 'Status from fnctl with O_NONBLOCK: ', rv + print 'Status from fcntl with O_NONBLOCK: ', rv if sys.platform not in ['os2emx']: rv = fcntl.fcntl(f.fileno(), fcntl.F_SETLKW, lockdata) From perky at users.sourceforge.net Mon Apr 4 17:28:22 2005 From: perky at users.sourceforge.net (perky@users.sourceforge.net) Date: Mon Apr 4 17:28:24 2005 Subject: [Python-checkins] python/dist/src/Lib/test test_fcntl.py, 1.26, 1.26.2.1 Message-ID: Update of /cvsroot/python/python/dist/src/Lib/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6228/Lib/test Modified Files: Tag: release24-maint test_fcntl.py Log Message: Backport from 1.27: Fix testcase for 64bit BSD systems: long is 8 bytes for those systems so there's no need to pad after off_t members. And a small typo fix. Index: test_fcntl.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Lib/test/test_fcntl.py,v retrieving revision 1.26 retrieving revision 1.26.2.1 diff -u -d -r1.26 -r1.26.2.1 --- test_fcntl.py 18 Aug 2004 15:13:41 -0000 1.26 +++ test_fcntl.py 4 Apr 2005 15:28:18 -0000 1.26.2.1 @@ -24,7 +24,13 @@ 'freebsd2', 'freebsd3', 'freebsd4', 'freebsd5', 'freebsd6', 'bsdos2', 'bsdos3', 'bsdos4', 'openbsd', 'openbsd2', 'openbsd3'): - lockdata = struct.pack('lxxxxlxxxxlhh', 0, 0, 0, fcntl.F_WRLCK, 0) + if struct.calcsize('l') == 8: + off_t = 'l' + pid_t = 'i' + else: + off_t = 'lxxxx' + pid_t = 'l' + lockdata = struct.pack(off_t+off_t+pid_t+'hh', 0, 0, 0, fcntl.F_WRLCK, 0) elif sys.platform in ['aix3', 'aix4', 'hp-uxB', 'unixware7']: lockdata = struct.pack('hhlllii', fcntl.F_WRLCK, 0, 0, 0, 0, 0, 0) elif sys.platform in ['os2emx']: @@ -39,7 +45,7 @@ f = open(filename, 'w') rv = fcntl.fcntl(f.fileno(), fcntl.F_SETFL, os.O_NONBLOCK) if verbose: - print 'Status from fnctl with O_NONBLOCK: ', rv + print 'Status from fcntl with O_NONBLOCK: ', rv if sys.platform not in ['os2emx']: rv = fcntl.fcntl(f.fileno(), fcntl.F_SETLKW, lockdata) From perky at users.sourceforge.net Mon Apr 4 17:49:13 2005 From: perky at users.sourceforge.net (perky@users.sourceforge.net) Date: Mon Apr 4 17:49:17 2005 Subject: [Python-checkins] python/dist/src/Python ceval.c,2.421,2.422 Message-ID: Update of /cvsroot/python/python/dist/src/Python In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10544/Python Modified Files: ceval.c Log Message: Make a handy macro, Py_DEFAULT_RECURSION_LIMIT to allow to define a default value of recursion limit from build systems. 1000 levels are still too high for some 64bit systems. Index: ceval.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Python/ceval.c,v retrieving revision 2.421 retrieving revision 2.422 diff -u -d -r2.421 -r2.422 --- ceval.c 18 Jan 2005 15:56:11 -0000 2.421 +++ ceval.c 4 Apr 2005 15:49:02 -0000 2.422 @@ -417,8 +417,11 @@ /* The interpreter's recursion limit */ -static int recursion_limit = 1000; -int _Py_CheckRecursionLimit = 1000; +#ifndef Py_DEFAULT_RECURSION_LIMIT +#define Py_DEFAULT_RECURSION_LIMIT 1000 +#endif +static int recursion_limit = Py_DEFAULT_RECURSION_LIMIT; +int _Py_CheckRecursionLimit = Py_DEFAULT_RECURSION_LIMIT; int Py_GetRecursionLimit(void) From perky at users.sourceforge.net Mon Apr 4 18:32:11 2005 From: perky at users.sourceforge.net (perky@users.sourceforge.net) Date: Mon Apr 4 18:32:15 2005 Subject: [Python-checkins] python/dist/src/Modules unicodedata.c,2.32,2.33 Message-ID: Update of /cvsroot/python/python/dist/src/Modules In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24034/Modules Modified Files: unicodedata.c Log Message: Fill docstrings for module and functions, extracted from the tex documentation. (Patch #1173245, Contributed by Jeremy Yallop) Index: unicodedata.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Modules/unicodedata.c,v retrieving revision 2.32 retrieving revision 2.33 diff -u -d -r2.32 -r2.33 --- unicodedata.c 4 Aug 2004 07:38:34 -0000 2.32 +++ unicodedata.c 4 Apr 2005 16:32:07 -0000 2.33 @@ -53,6 +53,13 @@ /* --- Module API --------------------------------------------------------- */ +PyDoc_STRVAR(unicodedata_decimal__doc__, +"decimal(unichr[, default])\n\ +\n\ +Returns the decimal value assigned to the Unicode character unichr\n\ +as integer. If no such value is defined, default is returned, or, if\n\ +not given, ValueError is raised."); + static PyObject * unicodedata_decimal(PyObject *self, PyObject *args) { @@ -82,6 +89,13 @@ return PyInt_FromLong(rc); } +PyDoc_STRVAR(unicodedata_digit__doc__, +"digit(unichr[, default])\n\ +\n\ +Returns the digit value assigned to the Unicode character unichr as\n\ +integer. If no such value is defined, default is returned, or, if\n\ +not given, ValueError is raised."); + static PyObject * unicodedata_digit(PyObject *self, PyObject *args) { @@ -110,6 +124,13 @@ return PyInt_FromLong(rc); } +PyDoc_STRVAR(unicodedata_numeric__doc__, +"numeric(unichr[, default])\n\ +\n\ +Returns the numeric value assigned to the Unicode character unichr\n\ +as float. If no such value is defined, default is returned, or, if\n\ +not given, ValueError is raised."); + static PyObject * unicodedata_numeric(PyObject *self, PyObject *args) { @@ -138,6 +159,12 @@ return PyFloat_FromDouble(rc); } +PyDoc_STRVAR(unicodedata_category__doc__, +"category(unichr)\n\ +\n\ +Returns the general category assigned to the Unicode character\n\ +unichr as string."); + static PyObject * unicodedata_category(PyObject *self, PyObject *args) { @@ -156,6 +183,13 @@ return PyString_FromString(_PyUnicode_CategoryNames[index]); } +PyDoc_STRVAR(unicodedata_bidirectional__doc__, +"bidirectional(unichr)\n\ +\n\ +Returns the bidirectional category assigned to the Unicode character\n\ +unichr as string. If no such value is defined, an empty string is\n\ +returned."); + static PyObject * unicodedata_bidirectional(PyObject *self, PyObject *args) { @@ -174,6 +208,13 @@ return PyString_FromString(_PyUnicode_BidirectionalNames[index]); } +PyDoc_STRVAR(unicodedata_combining__doc__, +"combining(unichr)\n\ +\n\ +Returns the canonical combining class assigned to the Unicode\n\ +character unichr as integer. Returns 0 if no combining class is\n\ +defined."); + static PyObject * unicodedata_combining(PyObject *self, PyObject *args) { @@ -190,6 +231,13 @@ return PyInt_FromLong((int) _getrecord(v)->combining); } +PyDoc_STRVAR(unicodedata_mirrored__doc__, +"mirrored(unichr)\n\ +\n\ +Returns the mirrored property assigned to the Unicode character\n\ +unichr as integer. Returns 1 if the character has been identified as\n\ +a \"mirrored\" character in bidirectional text, 0 otherwise."); + static PyObject * unicodedata_mirrored(PyObject *self, PyObject *args) { @@ -206,6 +254,12 @@ return PyInt_FromLong((int) _getrecord(v)->mirrored); } +PyDoc_STRVAR(unicodedata_east_asian_width__doc__, +"east_asian_width(unichr)\n\ +\n\ +Returns the east asian width assigned to the Unicode character\n\ +unichr as string."); + static PyObject * unicodedata_east_asian_width(PyObject *self, PyObject *args) { @@ -224,6 +278,13 @@ return PyString_FromString(_PyUnicode_EastAsianWidthNames[index]); } +PyDoc_STRVAR(unicodedata_decomposition__doc__, +"decomposition(unichr)\n\ +\n\ +Returns the character decomposition mapping assigned to the Unicode\n\ +character unichr as string. An empty string is returned in case no\n\ +such mapping is defined."); + static PyObject * unicodedata_decomposition(PyObject *self, PyObject *args) { @@ -525,6 +586,12 @@ return result; } +PyDoc_STRVAR(unicodedata_normalize__doc__, +"normalize(form, unistr)\n\ +\n\ +Return the normal form 'form' for the Unicode string unistr. Valid\n\ +values for form are 'NFC', 'NFKC', 'NFD', and 'NFKD'."); + static PyObject* unicodedata_normalize(PyObject *self, PyObject *args) { @@ -826,6 +893,12 @@ /* -------------------------------------------------------------------- */ /* Python bindings */ +PyDoc_STRVAR(unicodedata_name__doc__, +"name(unichr[, default])\n\ +Returns the name assigned to the Unicode character unichr as a\n\ +string. If no name is defined, default is returned, or, if not\n\ +given, ValueError is raised."); + static PyObject * unicodedata_name(PyObject* self, PyObject* args) { @@ -857,6 +930,13 @@ return Py_BuildValue("s", name); } +PyDoc_STRVAR(unicodedata_lookup__doc__, +"lookup(name)\n\ +\n\ +Look up character by name. If a character with the\n\ +given name is found, return the corresponding Unicode\n\ +character. If not found, KeyError is raised."); + static PyObject * unicodedata_lookup(PyObject* self, PyObject* args) { @@ -884,22 +964,37 @@ /* XXX Add doc strings. */ static PyMethodDef unicodedata_functions[] = { - {"decimal", unicodedata_decimal, METH_VARARGS}, - {"digit", unicodedata_digit, METH_VARARGS}, - {"numeric", unicodedata_numeric, METH_VARARGS}, - {"category", unicodedata_category, METH_VARARGS}, - {"bidirectional", unicodedata_bidirectional, METH_VARARGS}, - {"combining", unicodedata_combining, METH_VARARGS}, - {"mirrored", unicodedata_mirrored, METH_VARARGS}, - {"east_asian_width", unicodedata_east_asian_width, METH_VARARGS}, - {"decomposition",unicodedata_decomposition, METH_VARARGS}, - {"name", unicodedata_name, METH_VARARGS}, - {"lookup", unicodedata_lookup, METH_VARARGS}, - {"normalize", unicodedata_normalize, METH_VARARGS}, + {"decimal", unicodedata_decimal, METH_VARARGS, unicodedata_decimal__doc__}, + {"digit", unicodedata_digit, METH_VARARGS, unicodedata_digit__doc__}, + {"numeric", unicodedata_numeric, METH_VARARGS, unicodedata_numeric__doc__}, + {"category", unicodedata_category, METH_VARARGS, + unicodedata_category__doc__}, + {"bidirectional", unicodedata_bidirectional, METH_VARARGS, + unicodedata_bidirectional__doc__}, + {"combining", unicodedata_combining, METH_VARARGS, + unicodedata_combining__doc__}, + {"mirrored", unicodedata_mirrored, METH_VARARGS, + unicodedata_mirrored__doc__}, + {"east_asian_width", unicodedata_east_asian_width, METH_VARARGS, + unicodedata_east_asian_width__doc__}, + {"decomposition", unicodedata_decomposition, METH_VARARGS, + unicodedata_decomposition__doc__}, + {"name", unicodedata_name, METH_VARARGS, unicodedata_name__doc__}, + {"lookup", unicodedata_lookup, METH_VARARGS, unicodedata_lookup__doc__}, + {"normalize", unicodedata_normalize, METH_VARARGS, + unicodedata_normalize__doc__}, {NULL, NULL} /* sentinel */ }; -PyDoc_STRVAR(unicodedata_docstring, "unicode character database"); +PyDoc_STRVAR(unicodedata_docstring, +"This module provides access to the Unicode Character Database which\n\ +defines character properties for all Unicode characters. The data in\n\ +this database is based on the UnicodeData.txt file version\n\ +3.2.0 which is publically available from ftp://ftp.unicode.org/.\n\ +\n\ +The module uses the same names and symbols as defined by the\n\ +UnicodeData File Format 3.2.0 (see\n\ +http://www.unicode.org/Public/UNIDATA/UnicodeData.html)."); PyMODINIT_FUNC initunicodedata(void) From doerwalter at users.sourceforge.net Mon Apr 4 23:38:49 2005 From: doerwalter at users.sourceforge.net (doerwalter@users.sourceforge.net) Date: Mon Apr 4 23:38:53 2005 Subject: [Python-checkins] python/dist/src/Lib codecs.py,1.41,1.42 Message-ID: Update of /cvsroot/python/python/dist/src/Lib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10392/Lib Modified Files: codecs.py Log Message: Fix for SF bug #1175396: readline() will now read one more character, if the last character read is "\r" (and size is None, i.e. we're allowed to call read() multiple times), so that we can return the correct line ending (this additional character might be a "\n"). If the stream is temporarily exhausted, we might return the wrong line ending (if the last character read is "\r" and the next one (after the byte stream provides more data) is "\n", but at least the atcr member ensure that we get the correct number of lines (i.e. this "\n" will not be treated as another line ending.) Index: codecs.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Lib/codecs.py,v retrieving revision 1.41 retrieving revision 1.42 diff -u -d -r1.41 -r1.42 --- codecs.py 16 Mar 2005 03:51:56 -0000 1.41 +++ codecs.py 4 Apr 2005 21:38:46 -0000 1.42 @@ -310,6 +310,15 @@ data = data[1:] if data: self.atcr = data.endswith(u"\r") + # If we're at a "\r" (and are allowed to read more), read one + # extra character (which might be a "\n") to get a proper + # line ending (If the stream is temporarily exhausted we return + # the wrong line ending, but at least we won't generate a bogus + # second line. + if self.atcr and size is None: + data += self.read(size=1, chars=1) + self.atcr = data.endswith(u"\r") + line += data lines = line.splitlines(True) if lines: From doerwalter at users.sourceforge.net Mon Apr 4 23:38:49 2005 From: doerwalter at users.sourceforge.net (doerwalter@users.sourceforge.net) Date: Mon Apr 4 23:38:53 2005 Subject: [Python-checkins] python/dist/src/Lib/test test_codecs.py, 1.21, 1.22 Message-ID: Update of /cvsroot/python/python/dist/src/Lib/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10392/Lib/test Modified Files: test_codecs.py Log Message: Fix for SF bug #1175396: readline() will now read one more character, if the last character read is "\r" (and size is None, i.e. we're allowed to call read() multiple times), so that we can return the correct line ending (this additional character might be a "\n"). If the stream is temporarily exhausted, we might return the wrong line ending (if the last character read is "\r" and the next one (after the byte stream provides more data) is "\n", but at least the atcr member ensure that we get the correct number of lines (i.e. this "\n" will not be treated as another line ending.) Index: test_codecs.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Lib/test/test_codecs.py,v retrieving revision 1.21 retrieving revision 1.22 diff -u -d -r1.21 -r1.22 --- test_codecs.py 14 Mar 2005 19:06:30 -0000 1.21 +++ test_codecs.py 4 Apr 2005 21:38:47 -0000 1.22 @@ -73,15 +73,88 @@ # reader has to look ahead whether this is a lone \r or a \r\n for size in xrange(80): for lineend in u"\n \r\n \r \u2028".split(): - s = size*u"a" + lineend + u"xxx\n" - self.assertEqual( - getreader(s).readline(keepends=True), - size*u"a" + lineend, - ) - self.assertEqual( - getreader(s).readline(keepends=False), - size*u"a", - ) + s = 10*(size*u"a" + lineend + u"xxx\n") + reader = getreader(s) + for i in xrange(10): + self.assertEqual( + reader.readline(keepends=True), + size*u"a" + lineend, + ) + reader = getreader(s) + for i in xrange(10): + self.assertEqual( + reader.readline(keepends=False), + size*u"a", + ) + + def test_bug1175396(self): + s = [ + '<%!--===================================================\r\n', + ' BLOG index page: show recent articles,\r\n', + ' today\'s articles, or articles of a specific date.\r\n', + '========================================================--%>\r\n', + '<%@inputencoding="ISO-8859-1"%>\r\n', + '<%@pagetemplate=TEMPLATE.y%>\r\n', + '<%@import=import frog.util, frog%>\r\n', + '<%@import=import frog.objects%>\r\n', + '<%@import=from frog.storageerrors import StorageError%>\r\n', + '<%\r\n', + '\r\n', + 'import logging\r\n', + 'log=logging.getLogger("Snakelets.logger")\r\n', + '\r\n', + '\r\n', + 'user=self.SessionCtx.user\r\n', + 'storageEngine=self.SessionCtx.storageEngine\r\n', + '\r\n', + '\r\n', + 'def readArticlesFromDate(date, count=None):\r\n', + ' entryids=storageEngine.listBlogEntries(date)\r\n', + ' entryids.reverse() # descending\r\n', + ' if count:\r\n', + ' entryids=entryids[:count]\r\n', + ' try:\r\n', + ' return [ frog.objects.BlogEntry.load(storageEngine, date, Id) for Id in entryids ]\r\n', + ' except StorageError,x:\r\n', + ' log.error("Error loading articles: "+str(x))\r\n', + ' self.abort("cannot load articles")\r\n', + '\r\n', + 'showdate=None\r\n', + '\r\n', + 'arg=self.Request.getArg()\r\n', + 'if arg=="today":\r\n', + ' #-------------------- TODAY\'S ARTICLES\r\n', + ' self.write("

Today\'s articles

")\r\n', + ' showdate = frog.util.isodatestr() \r\n', + ' entries = readArticlesFromDate(showdate)\r\n', + 'elif arg=="active":\r\n', + ' #-------------------- ACTIVE ARTICLES redirect\r\n', + ' self.Yredirect("active.y")\r\n', + 'elif arg=="login":\r\n', + ' #-------------------- LOGIN PAGE redirect\r\n', + ' self.Yredirect("login.y")\r\n', + 'elif arg=="date":\r\n', + ' #-------------------- ARTICLES OF A SPECIFIC DATE\r\n', + ' showdate = self.Request.getParameter("date")\r\n', + ' self.write("

Articles written on %s

"% frog.util.mediumdatestr(showdate))\r\n', + ' entries = readArticlesFromDate(showdate)\r\n', + 'else:\r\n', + ' #-------------------- RECENT ARTICLES\r\n', + ' self.write("

Recent articles

")\r\n', + ' dates=storageEngine.listBlogEntryDates()\r\n', + ' if dates:\r\n', + ' entries=[]\r\n', + ' SHOWAMOUNT=10\r\n', + ' for showdate in dates:\r\n', + ' entries.extend( readArticlesFromDate(showdate, SHOWAMOUNT-len(entries)) )\r\n', + ' if len(entries)>=SHOWAMOUNT:\r\n', + ' break\r\n', + ' \r\n', + ] + stream = StringIO.StringIO("".join(s).encode(self.encoding)) + reader = codecs.getreader(self.encoding)(stream) + for (i, line) in enumerate(reader): + self.assertEqual(line, s[i]) def test_readlinequeue(self): q = Queue() From doerwalter at users.sourceforge.net Mon Apr 4 23:42:24 2005 From: doerwalter at users.sourceforge.net (doerwalter@users.sourceforge.net) Date: Mon Apr 4 23:42:27 2005 Subject: [Python-checkins] python/dist/src/Lib codecs.py,1.42,1.43 Message-ID: Update of /cvsroot/python/python/dist/src/Lib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11276/Lib Modified Files: codecs.py Log Message: Fix typos. Index: codecs.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Lib/codecs.py,v retrieving revision 1.42 retrieving revision 1.43 diff -u -d -r1.42 -r1.43 --- codecs.py 4 Apr 2005 21:38:46 -0000 1.42 +++ codecs.py 4 Apr 2005 21:42:22 -0000 1.43 @@ -312,9 +312,9 @@ self.atcr = data.endswith(u"\r") # If we're at a "\r" (and are allowed to read more), read one # extra character (which might be a "\n") to get a proper - # line ending (If the stream is temporarily exhausted we return + # line ending. (If the stream is temporarily exhausted we return # the wrong line ending, but at least we won't generate a bogus - # second line. + # second line.) if self.atcr and size is None: data += self.read(size=1, chars=1) self.atcr = data.endswith(u"\r") From doerwalter at users.sourceforge.net Mon Apr 4 23:56:30 2005 From: doerwalter at users.sourceforge.net (doerwalter@users.sourceforge.net) Date: Mon Apr 4 23:56:33 2005 Subject: [Python-checkins] python/dist/src/Lib codecs.py,1.35.2.5,1.35.2.6 Message-ID: Update of /cvsroot/python/python/dist/src/Lib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15351/Lib Modified Files: Tag: release24-maint codecs.py Log Message: Backport checkin: Fix for SF bug #1175396: readline() will now read one more character, if the last character read is "\r" (and size is None, i.e. we're allowed to call read() multiple times), so that we can return the correct line ending (this additional character might be a "\n"). If the stream is temporarily exhausted, we might return the wrong line ending (if the last character read is "\r" and the next one (after the byte stream provides more data) is "\n", but at least the atcr member ensures that we get the correct number of lines (i.e. this "\n" will not be treated as another line ending). Index: codecs.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Lib/codecs.py,v retrieving revision 1.35.2.5 retrieving revision 1.35.2.6 diff -u -d -r1.35.2.5 -r1.35.2.6 --- codecs.py 14 Mar 2005 19:26:47 -0000 1.35.2.5 +++ codecs.py 4 Apr 2005 21:56:27 -0000 1.35.2.6 @@ -310,6 +310,15 @@ data = data[1:] if data: self.atcr = data.endswith(u"\r") + # If we're at a "\r" (and are allowed to read more), read one + # extra character (which might be a "\n") to get a proper + # line ending. (If the stream is temporarily exhausted we return + # the wrong line ending, but at least we won't generate a bogus + # second line.) + if self.atcr and size is None: + data += self.read(size=1, chars=1) + self.atcr = data.endswith(u"\r") + line += data lines = line.splitlines(True) if lines: From doerwalter at users.sourceforge.net Mon Apr 4 23:56:30 2005 From: doerwalter at users.sourceforge.net (doerwalter@users.sourceforge.net) Date: Mon Apr 4 23:56:33 2005 Subject: [Python-checkins] python/dist/src/Lib/test test_codecs.py, 1.15.2.3, 1.15.2.4 Message-ID: Update of /cvsroot/python/python/dist/src/Lib/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15351/Lib/test Modified Files: Tag: release24-maint test_codecs.py Log Message: Backport checkin: Fix for SF bug #1175396: readline() will now read one more character, if the last character read is "\r" (and size is None, i.e. we're allowed to call read() multiple times), so that we can return the correct line ending (this additional character might be a "\n"). If the stream is temporarily exhausted, we might return the wrong line ending (if the last character read is "\r" and the next one (after the byte stream provides more data) is "\n", but at least the atcr member ensures that we get the correct number of lines (i.e. this "\n" will not be treated as another line ending). Index: test_codecs.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Lib/test/test_codecs.py,v retrieving revision 1.15.2.3 retrieving revision 1.15.2.4 diff -u -d -r1.15.2.3 -r1.15.2.4 --- test_codecs.py 14 Mar 2005 19:20:19 -0000 1.15.2.3 +++ test_codecs.py 4 Apr 2005 21:56:28 -0000 1.15.2.4 @@ -84,15 +84,88 @@ # reader has to look ahead whether this is a lone \r or a \r\n for size in xrange(80): for lineend in u"\n \r\n \r \u2028".split(): - s = size*u"a" + lineend + u"xxx\n" - self.assertEqual( - getreader(s).readline(keepends=True), - size*u"a" + lineend, - ) - self.assertEqual( - getreader(s).readline(keepends=False), - size*u"a", - ) + s = 10*(size*u"a" + lineend + u"xxx\n") + reader = getreader(s) + for i in xrange(10): + self.assertEqual( + reader.readline(keepends=True), + size*u"a" + lineend, + ) + reader = getreader(s) + for i in xrange(10): + self.assertEqual( + reader.readline(keepends=False), + size*u"a", + ) + + def test_bug1175396(self): + s = [ + '<%!--===================================================\r\n', + ' BLOG index page: show recent articles,\r\n', + ' today\'s articles, or articles of a specific date.\r\n', + '========================================================--%>\r\n', + '<%@inputencoding="ISO-8859-1"%>\r\n', + '<%@pagetemplate=TEMPLATE.y%>\r\n', + '<%@import=import frog.util, frog%>\r\n', + '<%@import=import frog.objects%>\r\n', + '<%@import=from frog.storageerrors import StorageError%>\r\n', + '<%\r\n', + '\r\n', + 'import logging\r\n', + 'log=logging.getLogger("Snakelets.logger")\r\n', + '\r\n', + '\r\n', + 'user=self.SessionCtx.user\r\n', + 'storageEngine=self.SessionCtx.storageEngine\r\n', + '\r\n', + '\r\n', + 'def readArticlesFromDate(date, count=None):\r\n', + ' entryids=storageEngine.listBlogEntries(date)\r\n', + ' entryids.reverse() # descending\r\n', + ' if count:\r\n', + ' entryids=entryids[:count]\r\n', + ' try:\r\n', + ' return [ frog.objects.BlogEntry.load(storageEngine, date, Id) for Id in entryids ]\r\n', + ' except StorageError,x:\r\n', + ' log.error("Error loading articles: "+str(x))\r\n', + ' self.abort("cannot load articles")\r\n', + '\r\n', + 'showdate=None\r\n', + '\r\n', + 'arg=self.Request.getArg()\r\n', + 'if arg=="today":\r\n', + ' #-------------------- TODAY\'S ARTICLES\r\n', + ' self.write("

Today\'s articles

")\r\n', + ' showdate = frog.util.isodatestr() \r\n', + ' entries = readArticlesFromDate(showdate)\r\n', + 'elif arg=="active":\r\n', + ' #-------------------- ACTIVE ARTICLES redirect\r\n', + ' self.Yredirect("active.y")\r\n', + 'elif arg=="login":\r\n', + ' #-------------------- LOGIN PAGE redirect\r\n', + ' self.Yredirect("login.y")\r\n', + 'elif arg=="date":\r\n', + ' #-------------------- ARTICLES OF A SPECIFIC DATE\r\n', + ' showdate = self.Request.getParameter("date")\r\n', + ' self.write("

Articles written on %s

"% frog.util.mediumdatestr(showdate))\r\n', + ' entries = readArticlesFromDate(showdate)\r\n', + 'else:\r\n', + ' #-------------------- RECENT ARTICLES\r\n', + ' self.write("

Recent articles

")\r\n', + ' dates=storageEngine.listBlogEntryDates()\r\n', + ' if dates:\r\n', + ' entries=[]\r\n', + ' SHOWAMOUNT=10\r\n', + ' for showdate in dates:\r\n', + ' entries.extend( readArticlesFromDate(showdate, SHOWAMOUNT-len(entries)) )\r\n', + ' if len(entries)>=SHOWAMOUNT:\r\n', + ' break\r\n', + ' \r\n', + ] + stream = StringIO.StringIO("".join(s).encode(self.encoding)) + reader = codecs.getreader(self.encoding)(stream) + for (i, line) in enumerate(reader): + self.assertEqual(line, s[i]) def test_readlinequeue(self): q = Queue() From rhettinger at users.sourceforge.net Tue Apr 5 06:31:11 2005 From: rhettinger at users.sourceforge.net (rhettinger@users.sourceforge.net) Date: Tue Apr 5 06:31:16 2005 Subject: [Python-checkins] python/dist/src/Lib ftplib.py,1.73,1.74 Message-ID: Update of /cvsroot/python/python/dist/src/Lib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18972 Modified Files: ftplib.py Log Message: SF bug #1168983: ftplib.py string index out of range * resp[:1] in '123' # after Py2.2, this allowed blank responses to pass. * replace <> with != * provide a usage message for empty command line calls Backport candidate. Index: ftplib.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Lib/ftplib.py,v retrieving revision 1.73 retrieving revision 1.74 diff -u -d -r1.73 -r1.74 --- ftplib.py 12 Feb 2004 17:35:06 -0000 1.73 +++ ftplib.py 5 Apr 2005 04:31:09 -0000 1.74 @@ -208,13 +208,13 @@ if self.debugging: print '*resp*', self.sanitize(resp) self.lastresp = resp[:3] c = resp[:1] + if c in ('1', '2', '3'): + return resp if c == '4': raise error_temp, resp if c == '5': raise error_perm, resp - if c not in '123': - raise error_proto, resp - return resp + raise error_proto, resp def voidresp(self): """Expect a response beginning with '2'.""" @@ -582,17 +582,17 @@ Raises error_proto if it does not contain '(|||port|)' Return ('host.addr.as.numbers', port#) tuple.''' - if resp[:3] <> '229': + if resp[:3] != '229': raise error_reply, resp left = resp.find('(') if left < 0: raise error_proto, resp right = resp.find(')', left + 1) if right < 0: raise error_proto, resp # should contain '(|||port|)' - if resp[left + 1] <> resp[right - 1]: + if resp[left + 1] != resp[right - 1]: raise error_proto, resp parts = resp[left + 1:right].split(resp[left+1]) - if len(parts) <> 5: + if len(parts) != 5: raise error_proto, resp host = peer[0] port = int(parts[3]) @@ -755,7 +755,16 @@ def test(): '''Test program. - Usage: ftp [-d] [-r[file]] host [-l[dir]] [-d[dir]] [-p] [file] ...''' + Usage: ftp [-d] [-r[file]] host [-l[dir]] [-d[dir]] [-p] [file] ... + + -d dir + -l list + -p password + ''' + + if len(sys.argv) < 2: + print test.__doc__ + sys.exit(0) debugging = 0 rcfile = None From rhettinger at users.sourceforge.net Wed Apr 6 00:35:18 2005 From: rhettinger at users.sourceforge.net (rhettinger@users.sourceforge.net) Date: Wed Apr 6 00:35:20 2005 Subject: [Python-checkins] python/dist/src/Misc developers,NONE,1.1 Message-ID: Update of /cvsroot/python/python/dist/src/Misc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv739 Added Files: developers Log Message: Begin a log of developer permissions. --- NEW FILE: developers --- Developer Log ============= This file is a running log of developers given permissions on SourceForge. The purpose is to provide some institutional memory of who was given access and why. The first entry starts in April 2005. In keeping with the style of Misc/NEWS, newer entries should be added to the top. Any markup should be in the form of ReST. Entries should include the initials of the project admin who made the change or granted access. Feel free to revise the format to accommodate documentation needs as they arise. Permissions History ------------------- - Nick Coghlan was given SF tracker permissions on 5 Apr 2005 by RDH. For several months, he has been active in reviewing and contributing patches. The added permissions give him greater flexibility in working with the tracker. Initials of Project Admins -------------------------- RDH: Raymond Hettinger From tim_one at users.sourceforge.net Wed Apr 6 02:59:05 2005 From: tim_one at users.sourceforge.net (tim_one@users.sourceforge.net) Date: Wed Apr 6 02:59:09 2005 Subject: [Python-checkins] python/dist/src/Misc developers.txt, NONE, 1.1 developers, 1.1, NONE Message-ID: Update of /cvsroot/python/python/dist/src/Misc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8755 Added Files: developers.txt Removed Files: developers Log Message: By popular demand from Linux-heads(!), renamed developers to developers.txt. --- NEW FILE: developers.txt --- Developer Log ============= This file is a running log of developers given permissions on SourceForge. The purpose is to provide some institutional memory of who was given access and why. The first entry starts in April 2005. In keeping with the style of Misc/NEWS, newer entries should be added to the top. Any markup should be in the form of ReST. Entries should include the initials of the project admin who made the change or granted access. Feel free to revise the format to accommodate documentation needs as they arise. Permissions History ------------------- - Nick Coghlan was given SF tracker permissions on 5 Apr 2005 by RDH. For several months, he has been active in reviewing and contributing patches. The added permissions give him greater flexibility in working with the tracker. Initials of Project Admins -------------------------- RDH: Raymond Hettinger --- developers DELETED --- From mwh at users.sourceforge.net Wed Apr 6 13:27:44 2005 From: mwh at users.sourceforge.net (mwh@users.sourceforge.net) Date: Wed Apr 6 13:27:46 2005 Subject: [Python-checkins] python/dist/src/Modules mathmodule.c,2.74,2.75 Message-ID: Update of /cvsroot/python/python/dist/src/Modules In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7780 Modified Files: mathmodule.c Log Message: Add a comment explaining the import of longintrepr.h. Index: mathmodule.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Modules/mathmodule.c,v retrieving revision 2.74 retrieving revision 2.75 diff -u -d -r2.74 -r2.75 --- mathmodule.c 22 Mar 2004 08:43:55 -0000 2.74 +++ mathmodule.c 6 Apr 2005 11:27:40 -0000 2.75 @@ -1,7 +1,7 @@ /* Math module -- standard C math library functions, pi and e */ #include "Python.h" -#include "longintrepr.h" +#include "longintrepr.h" // just for SHIFT #ifndef _MSC_VER #ifndef __STDC__ From tim.peters at gmail.com Wed Apr 6 14:50:46 2005 From: tim.peters at gmail.com (Tim Peters) Date: Wed Apr 6 14:50:51 2005 Subject: [Python-checkins] python/dist/src/Modules mathmodule.c,2.74,2.75 In-Reply-To: References: Message-ID: <1f7befae050406055026a1e00c@mail.gmail.com> [mwh@users.sourceforge.net] > Modified Files: > mathmodule.c > Log Message: > Add a comment explaining the import of longintrepr.h. > > Index: mathmodule.c ... > #include "Python.h" > -#include "longintrepr.h" > +#include "longintrepr.h" // just for SHIFT The intent is fine, but please use a standard C (not C++) comment. That is, /*...*/, not //. From mwh at users.sourceforge.net Wed Apr 6 15:05:30 2005 From: mwh at users.sourceforge.net (mwh@users.sourceforge.net) Date: Wed Apr 6 15:05:35 2005 Subject: [Python-checkins] python/dist/src/Modules mathmodule.c,2.75,2.76 Message-ID: Update of /cvsroot/python/python/dist/src/Modules In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv723 Modified Files: mathmodule.c Log Message: Make that a C, not a C++, comment. Index: mathmodule.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Modules/mathmodule.c,v retrieving revision 2.75 retrieving revision 2.76 diff -u -d -r2.75 -r2.76 --- mathmodule.c 6 Apr 2005 11:27:40 -0000 2.75 +++ mathmodule.c 6 Apr 2005 13:05:18 -0000 2.76 @@ -1,7 +1,7 @@ /* Math module -- standard C math library functions, pi and e */ #include "Python.h" -#include "longintrepr.h" // just for SHIFT +#include "longintrepr.h" /* just for SHIFT */ #ifndef _MSC_VER #ifndef __STDC__ From rhettinger at users.sourceforge.net Thu Apr 7 06:38:06 2005 From: rhettinger at users.sourceforge.net (rhettinger@users.sourceforge.net) Date: Thu Apr 7 06:38:09 2005 Subject: [Python-checkins] python/dist/src/Doc/lib liboperator.tex, 1.33, 1.34 Message-ID: Update of /cvsroot/python/python/dist/src/Doc/lib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19577 Modified Files: liboperator.tex Log Message: SF bug #1178255: 256 should read 255 in operator module docs Index: liboperator.tex =================================================================== RCS file: /cvsroot/python/python/dist/src/Doc/lib/liboperator.tex,v retrieving revision 1.33 retrieving revision 1.34 diff -u -d -r1.33 -r1.34 --- liboperator.tex 9 Mar 2005 16:38:48 -0000 1.33 +++ liboperator.tex 7 Apr 2005 04:38:04 -0000 1.34 @@ -289,7 +289,7 @@ Example: Build a dictionary that maps the ordinals from \code{0} to -\code{256} to their character equivalents. +\code{255} to their character equivalents. \begin{verbatim} >>> import operator From rhettinger at users.sourceforge.net Thu Apr 7 06:39:38 2005 From: rhettinger at users.sourceforge.net (rhettinger@users.sourceforge.net) Date: Thu Apr 7 06:39:42 2005 Subject: [Python-checkins] python/dist/src/Doc/lib liboperator.tex, 1.31.4.1, 1.31.4.2 Message-ID: Update of /cvsroot/python/python/dist/src/Doc/lib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20982 Modified Files: Tag: release24-maint liboperator.tex Log Message: SF bug #1178255: 256 should read 255 in operator module docs Index: liboperator.tex =================================================================== RCS file: /cvsroot/python/python/dist/src/Doc/lib/liboperator.tex,v retrieving revision 1.31.4.1 retrieving revision 1.31.4.2 diff -u -d -r1.31.4.1 -r1.31.4.2 --- liboperator.tex 1 Jan 2005 00:34:53 -0000 1.31.4.1 +++ liboperator.tex 7 Apr 2005 04:39:35 -0000 1.31.4.2 @@ -289,7 +289,7 @@ Example: Build a dictionary that maps the ordinals from \code{0} to -\code{256} to their character equivalents. +\code{255} to their character equivalents. \begin{verbatim} >>> import operator From rhettinger at users.sourceforge.net Thu Apr 7 07:36:28 2005 From: rhettinger at users.sourceforge.net (rhettinger@users.sourceforge.net) Date: Thu Apr 7 07:36:31 2005 Subject: [Python-checkins] python/dist/src/Doc/lib liboperator.tex, 1.34, 1.35 Message-ID: Update of /cvsroot/python/python/dist/src/Doc/lib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22093 Modified Files: liboperator.tex Log Message: SF bug #1178269 Clarify when isMappingType/isSequenceType is True. Index: liboperator.tex =================================================================== RCS file: /cvsroot/python/python/dist/src/Doc/lib/liboperator.tex,v retrieving revision 1.34 retrieving revision 1.35 diff -u -d -r1.34 -r1.35 --- liboperator.tex 7 Apr 2005 04:38:04 -0000 1.34 +++ liboperator.tex 7 Apr 2005 05:36:17 -0000 1.35 @@ -262,7 +262,8 @@ \begin{funcdesc}{isMappingType}{o} Returns true if the object \var{o} supports the mapping interface. -This is true for dictionaries and all instance objects. +This is true for dictionaries and all instance objects defining +\method{__getitem__}. \warning{There is no reliable way to test if an instance supports the complete mapping protocol since the interface itself is ill-defined. This makes this test less useful than it otherwise might @@ -271,7 +272,7 @@ \begin{funcdesc}{isNumberType}{o} Returns true if the object \var{o} represents a number. This is true -for all numeric types implemented in C, and for all instance objects. +for all numeric types implemented in C. \warning{There is no reliable way to test if an instance supports the complete numeric interface since the interface itself is ill-defined. This makes this test less useful than it otherwise might @@ -281,7 +282,8 @@ \begin{funcdesc}{isSequenceType}{o} Returns true if the object \var{o} supports the sequence protocol. This returns true for all objects which define sequence methods in C, -and for all instance objects. \warning{There is no reliable +and for all instance objects defining \method{__getitem__}. +\warning{There is no reliable way to test if an instance supports the complete sequence interface since the interface itself is ill-defined. This makes this test less useful than it otherwise might be.} From rhettinger at users.sourceforge.net Thu Apr 7 07:37:50 2005 From: rhettinger at users.sourceforge.net (rhettinger@users.sourceforge.net) Date: Thu Apr 7 07:37:52 2005 Subject: [Python-checkins] python/dist/src/Doc/lib liboperator.tex, 1.31.4.2, 1.31.4.3 Message-ID: Update of /cvsroot/python/python/dist/src/Doc/lib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22904 Modified Files: Tag: release24-maint liboperator.tex Log Message: SF bug #1178269 Clarify when isMappingType/isSequenceType is True. Index: liboperator.tex =================================================================== RCS file: /cvsroot/python/python/dist/src/Doc/lib/liboperator.tex,v retrieving revision 1.31.4.2 retrieving revision 1.31.4.3 diff -u -d -r1.31.4.2 -r1.31.4.3 --- liboperator.tex 7 Apr 2005 04:39:35 -0000 1.31.4.2 +++ liboperator.tex 7 Apr 2005 05:37:47 -0000 1.31.4.3 @@ -262,7 +262,8 @@ \begin{funcdesc}{isMappingType}{o} Returns true if the object \var{o} supports the mapping interface. -This is true for dictionaries and all instance objects. +This is true for dictionaries and all instance objects defining +\method{__getitem__}. \warning{There is no reliable way to test if an instance supports the complete mapping protocol since the interface itself is ill-defined. This makes this test less useful than it otherwise might @@ -271,7 +272,7 @@ \begin{funcdesc}{isNumberType}{o} Returns true if the object \var{o} represents a number. This is true -for all numeric types implemented in C, and for all instance objects. +for all numeric types implemented in C. \warning{There is no reliable way to test if an instance supports the complete numeric interface since the interface itself is ill-defined. This makes this test less useful than it otherwise might @@ -281,7 +282,8 @@ \begin{funcdesc}{isSequenceType}{o} Returns true if the object \var{o} supports the sequence protocol. This returns true for all objects which define sequence methods in C, -and for all instance objects. \warning{There is no reliable +and for all instance objects defining \method{__getitem__}. +\warning{There is no reliable way to test if an instance supports the complete sequence interface since the interface itself is ill-defined. This makes this test less useful than it otherwise might be.} From mwh at users.sourceforge.net Thu Apr 7 12:11:24 2005 From: mwh at users.sourceforge.net (mwh@users.sourceforge.net) Date: Thu Apr 7 12:11:27 2005 Subject: [Python-checkins] python/dist/src/Misc NEWS,1.1281,1.1282 Message-ID: Update of /cvsroot/python/python/dist/src/Misc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10399/Misc Modified Files: NEWS Log Message: In a threads-disabled build, typing Ctrl-C into a raw_input() crashed, because (essentially) I didn't realise that PY_BEGIN/END_ALLOW_THREADS actually expanded to nothing under a no-threads build, so if you somehow NULLed out the threadstate (e.g. by calling PyThread_SaveThread) it would stay NULLed when you return to Python. Argh! Backport candidate. Index: NEWS =================================================================== RCS file: /cvsroot/python/python/dist/src/Misc/NEWS,v retrieving revision 1.1281 retrieving revision 1.1282 diff -u -d -r1.1281 -r1.1282 --- NEWS 31 Mar 2005 13:57:35 -0000 1.1281 +++ NEWS 7 Apr 2005 10:11:19 -0000 1.1282 @@ -12,6 +12,9 @@ Core and builtins ----------------- +- Typing Ctrl-C whilst raw_input() was waiting in a build with threads + disabled caused a crash. + - Bug #1165306: instancemethod_new allowed the creation of a method with im_class == im_self == NULL, which caused a crash when called. From mwh at users.sourceforge.net Thu Apr 7 12:11:50 2005 From: mwh at users.sourceforge.net (mwh@users.sourceforge.net) Date: Thu Apr 7 12:11:53 2005 Subject: [Python-checkins] python/dist/src/Modules readline.c,2.83,2.84 Message-ID: Update of /cvsroot/python/python/dist/src/Modules In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10399/Modules Modified Files: readline.c Log Message: In a threads-disabled build, typing Ctrl-C into a raw_input() crashed, because (essentially) I didn't realise that PY_BEGIN/END_ALLOW_THREADS actually expanded to nothing under a no-threads build, so if you somehow NULLed out the threadstate (e.g. by calling PyThread_SaveThread) it would stay NULLed when you return to Python. Argh! Backport candidate. Index: readline.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Modules/readline.c,v retrieving revision 2.83 retrieving revision 2.84 diff -u -d -r2.83 -r2.84 --- readline.c 30 Mar 2005 11:21:53 -0000 2.83 +++ readline.c 7 Apr 2005 10:11:17 -0000 2.84 @@ -775,9 +775,13 @@ } else if (errno == EINTR) { int s; +#ifdef WITH_THREAD PyEval_RestoreThread(_PyOS_ReadlineTState); +#endif s = PyErr_CheckSignals(); +#ifdef WITH_THREAD PyEval_SaveThread(); +#endif if (s < 0) { rl_free_line_state(); rl_cleanup_after_signal(); From mwh at users.sourceforge.net Thu Apr 7 12:11:51 2005 From: mwh at users.sourceforge.net (mwh@users.sourceforge.net) Date: Thu Apr 7 12:11:54 2005 Subject: [Python-checkins] python/dist/src/Parser myreadline.c,2.33,2.34 Message-ID: Update of /cvsroot/python/python/dist/src/Parser In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10399/Parser Modified Files: myreadline.c Log Message: In a threads-disabled build, typing Ctrl-C into a raw_input() crashed, because (essentially) I didn't realise that PY_BEGIN/END_ALLOW_THREADS actually expanded to nothing under a no-threads build, so if you somehow NULLed out the threadstate (e.g. by calling PyThread_SaveThread) it would stay NULLed when you return to Python. Argh! Backport candidate. Index: myreadline.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Parser/myreadline.c,v retrieving revision 2.33 retrieving revision 2.34 diff -u -d -r2.33 -r2.34 --- myreadline.c 8 Jul 2004 15:28:26 -0000 2.33 +++ myreadline.c 7 Apr 2005 10:11:18 -0000 2.34 @@ -82,9 +82,13 @@ #ifdef EINTR if (errno == EINTR) { int s; +#ifdef WITH_THREAD PyEval_RestoreThread(_PyOS_ReadlineTState); +#endif s = PyErr_CheckSignals(); +#ifdef WITH_THREAD PyEval_SaveThread(); +#endif if (s < 0) { return 1; } From mwh at users.sourceforge.net Thu Apr 7 12:20:03 2005 From: mwh at users.sourceforge.net (mwh@users.sourceforge.net) Date: Thu Apr 7 12:20:05 2005 Subject: [Python-checkins] python/dist/src/Misc NEWS, 1.1193.2.47, 1.1193.2.48 Message-ID: Update of /cvsroot/python/python/dist/src/Misc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14793/Misc Modified Files: Tag: release24-maint NEWS Log Message: Backport my recent raw_input() vs no threads build vs SIGINT argh: In a threads-disabled build, typing Ctrl-C into a raw_input() crashed, because (essentially) I didn't realise that PY_BEGIN/END_ALLOW_THREADS actually expanded to nothing under a no-threads build, so if you somehow NULLed out the threadstate (e.g. by calling PyThread_SaveThread) it would stay NULLed when you return to Python. Argh! Index: NEWS =================================================================== RCS file: /cvsroot/python/python/dist/src/Misc/NEWS,v retrieving revision 1.1193.2.47 retrieving revision 1.1193.2.48 diff -u -d -r1.1193.2.47 -r1.1193.2.48 --- NEWS 31 Mar 2005 14:16:26 -0000 1.1193.2.47 +++ NEWS 7 Apr 2005 10:19:47 -0000 1.1193.2.48 @@ -12,6 +12,9 @@ Core and builtins ----------------- +- Typing Ctrl-C whilst raw_input() was waiting in a build with threads + disabled caused a crash. + - Bug #1165306: instancemethod_new allowed the creation of a method with im_class == im_self == NULL, which caused a crash when called. From mwh at users.sourceforge.net Thu Apr 7 12:20:19 2005 From: mwh at users.sourceforge.net (mwh@users.sourceforge.net) Date: Thu Apr 7 12:20:22 2005 Subject: [Python-checkins] python/dist/src/Modules readline.c, 2.79.2.2, 2.79.2.3 Message-ID: Update of /cvsroot/python/python/dist/src/Modules In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14793/Modules Modified Files: Tag: release24-maint readline.c Log Message: Backport my recent raw_input() vs no threads build vs SIGINT argh: In a threads-disabled build, typing Ctrl-C into a raw_input() crashed, because (essentially) I didn't realise that PY_BEGIN/END_ALLOW_THREADS actually expanded to nothing under a no-threads build, so if you somehow NULLed out the threadstate (e.g. by calling PyThread_SaveThread) it would stay NULLed when you return to Python. Argh! Index: readline.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Modules/readline.c,v retrieving revision 2.79.2.2 retrieving revision 2.79.2.3 diff -u -d -r2.79.2.2 -r2.79.2.3 --- readline.c 31 Mar 2005 10:20:33 -0000 2.79.2.2 +++ readline.c 7 Apr 2005 10:19:45 -0000 2.79.2.3 @@ -777,9 +777,13 @@ } else if (errno == EINTR) { int s; +#ifdef WITH_THREAD PyEval_RestoreThread(_PyOS_ReadlineTState); +#endif s = PyErr_CheckSignals(); +#ifdef WITH_THREAD PyEval_SaveThread(); +#endif if (s < 0) { rl_free_line_state(); rl_cleanup_after_signal(); From mwh at users.sourceforge.net Thu Apr 7 12:20:19 2005 From: mwh at users.sourceforge.net (mwh@users.sourceforge.net) Date: Thu Apr 7 12:20:22 2005 Subject: [Python-checkins] python/dist/src/Parser myreadline.c, 2.33, 2.33.4.1 Message-ID: Update of /cvsroot/python/python/dist/src/Parser In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14793/Parser Modified Files: Tag: release24-maint myreadline.c Log Message: Backport my recent raw_input() vs no threads build vs SIGINT argh: In a threads-disabled build, typing Ctrl-C into a raw_input() crashed, because (essentially) I didn't realise that PY_BEGIN/END_ALLOW_THREADS actually expanded to nothing under a no-threads build, so if you somehow NULLed out the threadstate (e.g. by calling PyThread_SaveThread) it would stay NULLed when you return to Python. Argh! Index: myreadline.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Parser/myreadline.c,v retrieving revision 2.33 retrieving revision 2.33.4.1 diff -u -d -r2.33 -r2.33.4.1 --- myreadline.c 8 Jul 2004 15:28:26 -0000 2.33 +++ myreadline.c 7 Apr 2005 10:19:46 -0000 2.33.4.1 @@ -82,9 +82,13 @@ #ifdef EINTR if (errno == EINTR) { int s; +#ifdef WITH_THREAD PyEval_RestoreThread(_PyOS_ReadlineTState); +#endif s = PyErr_CheckSignals(); +#ifdef WITH_THREAD PyEval_SaveThread(); +#endif if (s < 0) { return 1; } From rhettinger at users.sourceforge.net Fri Apr 8 05:19:25 2005 From: rhettinger at users.sourceforge.net (rhettinger@users.sourceforge.net) Date: Fri Apr 8 05:19:28 2005 Subject: [Python-checkins] python/dist/src/Misc developers.txt,1.1,1.2 Message-ID: Update of /cvsroot/python/python/dist/src/Misc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17599 Modified Files: developers.txt Log Message: Update permissions log for Reedy, Holden, Haring, and Cole. Index: developers.txt =================================================================== RCS file: /cvsroot/python/python/dist/src/Misc/developers.txt,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- developers.txt 6 Apr 2005 00:59:02 -0000 1.1 +++ developers.txt 8 Apr 2005 03:19:09 -0000 1.2 @@ -17,12 +17,21 @@ Permissions History ------------------- +- Terry Reedy was given SF tracker permissions on 7 Apr 2005 by RDH. + - Nick Coghlan was given SF tracker permissions on 5 Apr 2005 by RDH. For several months, he has been active in reviewing and contributing patches. The added permissions give him greater flexibility in working with the tracker. +Permissions Dropped on Request +------------------------------ + +- Steve Holden, Gerhard Haring, and David Cole sent email stating that + they no longer use their access. 7 Apr 2005 RDH + + Initials of Project Admins -------------------------- From tim_one at users.sourceforge.net Fri Apr 8 19:16:35 2005 From: tim_one at users.sourceforge.net (tim_one@users.sourceforge.net) Date: Fri Apr 8 19:16:38 2005 Subject: [Python-checkins] python/dist/src/Misc developers.txt,1.2,1.3 Message-ID: Update of /cvsroot/python/python/dist/src/Misc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5251 Modified Files: developers.txt Log Message: Info about Eric Price. Index: developers.txt =================================================================== RCS file: /cvsroot/python/python/dist/src/Misc/developers.txt,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- developers.txt 8 Apr 2005 03:19:09 -0000 1.2 +++ developers.txt 8 Apr 2005 17:16:28 -0000 1.3 @@ -24,16 +24,21 @@ patches. The added permissions give him greater flexibility in working with the tracker. +- Eric Price was made a developer on 2 May 2003 by TGP. This was + specifically to work on the new ``decimal`` package, which lived in + ``nondist/sandbox/decimal/`` at the time. + Permissions Dropped on Request ------------------------------ - Steve Holden, Gerhard Haring, and David Cole sent email stating that they no longer use their access. 7 Apr 2005 RDH - + Initials of Project Admins -------------------------- RDH: Raymond Hettinger +TGP: Tim Peters From tim_one at users.sourceforge.net Fri Apr 8 20:01:03 2005 From: tim_one at users.sourceforge.net (tim_one@users.sourceforge.net) Date: Fri Apr 8 20:01:07 2005 Subject: [Python-checkins] python/dist/src/Lib/test test_xmlrpc.py,1.7,1.8 Message-ID: Update of /cvsroot/python/python/dist/src/Lib/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27268/Lib/test Modified Files: test_xmlrpc.py Log Message: test_default_encoding_issues(): Fully restore sys.setdefaultencoding. test_site often failed under "regrtest.py -r", because this xmlrpc test left sys with a setdefaultencoding attribute, but loading site.py removes that attribute and test_site.py verifies the attribute is gone. Changed this test to get rid of sys.setdefaultencoding if it didn't exist when this test started. Don't know whether this is a bugfix (backport) candidate. Index: test_xmlrpc.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Lib/test/test_xmlrpc.py,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- test_xmlrpc.py 11 Feb 2005 17:59:08 -0000 1.7 +++ test_xmlrpc.py 8 Apr 2005 18:00:59 -0000 1.8 @@ -80,13 +80,20 @@ """ + + # sys.setdefaultencoding() normally doesn't exist after site.py is + # loaded. reload(sys) is the way to get it back. old_encoding = sys.getdefaultencoding() + setdefaultencoding_existed = hasattr(sys, "setdefaultencoding") reload(sys) # ugh! sys.setdefaultencoding("iso-8859-1") try: (s, d), m = xmlrpclib.loads(utf8) finally: sys.setdefaultencoding(old_encoding) + if not setdefaultencoding_existed: + del sys.setdefaultencoding + items = d.items() if have_unicode: self.assertEquals(s, u"abc \x95") From rhettinger at users.sourceforge.net Fri Apr 8 20:36:17 2005 From: rhettinger at users.sourceforge.net (rhettinger@users.sourceforge.net) Date: Fri Apr 8 20:36:20 2005 Subject: [Python-checkins] python/dist/src/Misc developers.txt,1.3,1.4 Message-ID: Update of /cvsroot/python/python/dist/src/Misc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17468 Modified Files: developers.txt Log Message: Record a drop request by Moshe Zadka. Index: developers.txt =================================================================== RCS file: /cvsroot/python/python/dist/src/Misc/developers.txt,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- developers.txt 8 Apr 2005 17:16:28 -0000 1.3 +++ developers.txt 8 Apr 2005 18:36:14 -0000 1.4 @@ -32,6 +32,8 @@ Permissions Dropped on Request ------------------------------ +- Moshe Zadka sent a drop request. 8 Apr 2005 by RDH + - Steve Holden, Gerhard Haring, and David Cole sent email stating that they no longer use their access. 7 Apr 2005 RDH From rhettinger at users.sourceforge.net Fri Apr 8 21:09:21 2005 From: rhettinger at users.sourceforge.net (rhettinger@users.sourceforge.net) Date: Fri Apr 8 21:09:24 2005 Subject: [Python-checkins] python/dist/src/Misc developers.txt,1.4,1.5 Message-ID: Update of /cvsroot/python/python/dist/src/Misc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2237 Modified Files: developers.txt Log Message: Record a drop request by Ken Manheimer. Index: developers.txt =================================================================== RCS file: /cvsroot/python/python/dist/src/Misc/developers.txt,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- developers.txt 8 Apr 2005 18:36:14 -0000 1.4 +++ developers.txt 8 Apr 2005 19:09:19 -0000 1.5 @@ -32,7 +32,7 @@ Permissions Dropped on Request ------------------------------ -- Moshe Zadka sent a drop request. 8 Apr 2005 by RDH +- Moshe Zadka and Ken Manheimer sent drop requests. 8 Apr 2005 by RDH - Steve Holden, Gerhard Haring, and David Cole sent email stating that they no longer use their access. 7 Apr 2005 RDH From tim_one at users.sourceforge.net Fri Apr 8 22:02:11 2005 From: tim_one at users.sourceforge.net (tim_one@users.sourceforge.net) Date: Fri Apr 8 22:02:13 2005 Subject: [Python-checkins] python/dist/src/Misc developers.txt,1.5,1.6 Message-ID: Update of /cvsroot/python/python/dist/src/Misc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30148 Modified Files: developers.txt Log Message: Add ESR info. Index: developers.txt =================================================================== RCS file: /cvsroot/python/python/dist/src/Misc/developers.txt,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- developers.txt 8 Apr 2005 19:09:19 -0000 1.5 +++ developers.txt 8 Apr 2005 20:02:08 -0000 1.6 @@ -28,6 +28,11 @@ specifically to work on the new ``decimal`` package, which lived in ``nondist/sandbox/decimal/`` at the time. +- Eric S. Raymond was made a developer on 2 Jul 2000 by TGP, for general + library work. His request is archived here: + + http://mail.python.org/pipermail/python-dev/2000-July/005314.html + Permissions Dropped on Request ------------------------------ From rhettinger at users.sourceforge.net Fri Apr 8 22:43:22 2005 From: rhettinger at users.sourceforge.net (rhettinger@users.sourceforge.net) Date: Fri Apr 8 22:43:25 2005 Subject: [Python-checkins] python/dist/src/Misc developers.txt,1.6,1.7 Message-ID: Update of /cvsroot/python/python/dist/src/Misc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20982 Modified Files: developers.txt Log Message: Record removal of permissions for Charles Waldman. Index: developers.txt =================================================================== RCS file: /cvsroot/python/python/dist/src/Misc/developers.txt,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- developers.txt 8 Apr 2005 20:02:08 -0000 1.6 +++ developers.txt 8 Apr 2005 20:43:19 -0000 1.7 @@ -43,6 +43,12 @@ they no longer use their access. 7 Apr 2005 RDH +Permissions Dropped after Loss of Contact +----------------------------------------- + +- Several unsuccessful efforts were made to contact Charles G Waldman. + Removed on 8 Apr 2005 by RDH. + Initials of Project Admins -------------------------- From bcannon at users.sourceforge.net Sat Apr 9 03:27:40 2005 From: bcannon at users.sourceforge.net (bcannon@users.sourceforge.net) Date: Sat Apr 9 03:27:45 2005 Subject: [Python-checkins] python/dist/src/Lib/test test_grammar.py, 1.51, 1.52 Message-ID: Update of /cvsroot/python/python/dist/src/Lib/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14958/Lib/test Modified Files: test_grammar.py Log Message: Add test for ``class B1(): pass``. Index: test_grammar.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Lib/test/test_grammar.py,v retrieving revision 1.51 retrieving revision 1.52 diff -u -d -r1.51 -r1.52 --- test_grammar.py 31 Aug 2004 10:07:09 -0000 1.51 +++ test_grammar.py 9 Apr 2005 01:27:37 -0000 1.52 @@ -685,8 +685,9 @@ ### testlist: test (',' test)* [','] # These have been exercised enough above -print 'classdef' # 'class' NAME ['(' testlist ')'] ':' suite +print 'classdef' # 'class' NAME ['(' [testlist] ')'] ':' suite class B: pass +class B2(): pass class C1(B): pass class C2(B): pass class D(C1, C2, B): pass From bcannon at users.sourceforge.net Sat Apr 9 04:30:18 2005 From: bcannon at users.sourceforge.net (bcannon@users.sourceforge.net) Date: Sat Apr 9 04:30:22 2005 Subject: [Python-checkins] python/dist/src/Lib/compiler transformer.py, 1.49, 1.50 Message-ID: Update of /cvsroot/python/python/dist/src/Lib/compiler In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10651/Lib/compiler Modified Files: transformer.py Log Message: Flush out support for ``class B(): pass`` syntax by adding support to the 'parser' module and 'compiler' package. Closes patch #1176012. Thanks logistix. Index: transformer.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Lib/compiler/transformer.py,v retrieving revision 1.49 retrieving revision 1.50 diff -u -d -r1.49 -r1.50 --- transformer.py 8 Nov 2004 12:17:34 -0000 1.49 +++ transformer.py 9 Apr 2005 02:30:16 -0000 1.50 @@ -280,12 +280,14 @@ return Lambda(names, defaults, flags, code, lineno=nodelist[1][2]) def classdef(self, nodelist): - # classdef: 'class' NAME ['(' testlist ')'] ':' suite + # classdef: 'class' NAME ['(' [testlist] ')'] ':' suite name = nodelist[1][1] doc = self.get_docstring(nodelist[-1]) if nodelist[2][0] == token.COLON: bases = [] + elif nodelist[3][0] == token.RPAR: + bases = [] else: bases = self.com_bases(nodelist[3]) From bcannon at users.sourceforge.net Sat Apr 9 04:30:18 2005 From: bcannon at users.sourceforge.net (bcannon@users.sourceforge.net) Date: Sat Apr 9 04:30:22 2005 Subject: [Python-checkins] python/dist/src/Lib/test test_parser.py, 1.20, 1.21 test_compiler.py, 1.10, 1.11 Message-ID: Update of /cvsroot/python/python/dist/src/Lib/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10651/Lib/test Modified Files: test_parser.py test_compiler.py Log Message: Flush out support for ``class B(): pass`` syntax by adding support to the 'parser' module and 'compiler' package. Closes patch #1176012. Thanks logistix. Index: test_parser.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Lib/test/test_parser.py,v retrieving revision 1.20 retrieving revision 1.21 diff -u -d -r1.20 -r1.21 --- test_parser.py 31 Aug 2004 10:07:09 -0000 1.20 +++ test_parser.py 9 Apr 2005 02:30:15 -0000 1.21 @@ -127,6 +127,9 @@ self.check_suite("@funcattrs()\n" "def f(): pass") + def test_class_defs(self): + self.check_suite("class foo():pass") + def test_import_from_statement(self): self.check_suite("from sys.path import *") self.check_suite("from sys.path import dirname") Index: test_compiler.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Lib/test/test_compiler.py,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- test_compiler.py 8 Nov 2004 16:46:02 -0000 1.10 +++ test_compiler.py 9 Apr 2005 02:30:15 -0000 1.11 @@ -33,6 +33,9 @@ else: compiler.compile(buf, basename, "exec") + def testNewClassSyntax(self): + compiler.compile("class foo():pass\n\n","","exec") + def testLineNo(self): # Test that all nodes except Module have a correct lineno attribute. filename = __file__ From bcannon at users.sourceforge.net Sat Apr 9 04:30:35 2005 From: bcannon at users.sourceforge.net (bcannon@users.sourceforge.net) Date: Sat Apr 9 04:30:38 2005 Subject: [Python-checkins] python/dist/src/Misc NEWS,1.1282,1.1283 Message-ID: Update of /cvsroot/python/python/dist/src/Misc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10651/Misc Modified Files: NEWS Log Message: Flush out support for ``class B(): pass`` syntax by adding support to the 'parser' module and 'compiler' package. Closes patch #1176012. Thanks logistix. Index: NEWS =================================================================== RCS file: /cvsroot/python/python/dist/src/Misc/NEWS,v retrieving revision 1.1282 retrieving revision 1.1283 diff -u -d -r1.1282 -r1.1283 --- NEWS 7 Apr 2005 10:11:19 -0000 1.1282 +++ NEWS 9 Apr 2005 02:30:16 -0000 1.1283 @@ -24,7 +24,9 @@ - Added two new builtins, any() and all(). - Defining a class with empty parentheses is now allowed - (e.g., ``class C(): pass`` is no longer a syntax error) + (e.g., ``class C(): pass`` is no longer a syntax error). + Patch #1176012 added support to the 'parser' module and 'compiler' package + (thanks to logistix for that added support). - Patch #1115086: Support PY_LONGLONG in structmember. From bcannon at users.sourceforge.net Sat Apr 9 04:30:47 2005 From: bcannon at users.sourceforge.net (bcannon@users.sourceforge.net) Date: Sat Apr 9 04:30:50 2005 Subject: [Python-checkins] python/dist/src/Modules parsermodule.c,2.85,2.86 Message-ID: Update of /cvsroot/python/python/dist/src/Modules In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10651/Modules Modified Files: parsermodule.c Log Message: Flush out support for ``class B(): pass`` syntax by adding support to the 'parser' module and 'compiler' package. Closes patch #1176012. Thanks logistix. Index: parsermodule.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Modules/parsermodule.c,v retrieving revision 2.85 retrieving revision 2.86 diff -u -d -r2.85 -r2.86 --- parsermodule.c 31 Aug 2004 10:07:12 -0000 2.85 +++ parsermodule.c 9 Apr 2005 02:30:14 -0000 2.86 @@ -947,7 +947,8 @@ validate_class(node *tree) { int nch = NCH(tree); - int res = validate_ntype(tree, classdef) && ((nch == 4) || (nch == 7)); + int res = (validate_ntype(tree, classdef) && + ((nch == 4) || (nch == 6) || (nch == 7))); if (res) { res = (validate_name(CHILD(tree, 0), "class") @@ -955,12 +956,20 @@ && validate_colon(CHILD(tree, nch - 2)) && validate_suite(CHILD(tree, nch - 1))); } - else + else { (void) validate_numnodes(tree, 4, "class"); - if (res && (nch == 7)) { - res = (validate_lparen(CHILD(tree, 2)) - && validate_testlist(CHILD(tree, 3)) - && validate_rparen(CHILD(tree, 4))); + } + + if (res) { + if (nch == 7) { + res = ((validate_lparen(CHILD(tree, 2)) && + validate_testlist(CHILD(tree, 3)) && + validate_rparen(CHILD(tree, 4)))); + } + else if (nch == 6) { + res = (validate_lparen(CHILD(tree,2)) && + validate_rparen(CHILD(tree,3))); + } } return (res); } From bcannon at users.sourceforge.net Sat Apr 9 05:03:02 2005 From: bcannon at users.sourceforge.net (bcannon@users.sourceforge.net) Date: Sat Apr 9 05:03:05 2005 Subject: [Python-checkins] python/dist/src/Doc/ref ref7.tex,1.43,1.44 Message-ID: Update of /cvsroot/python/python/dist/src/Doc/ref In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27923/Doc/ref Modified Files: ref7.tex Log Message: Add grammar change for allowing ``class B(): pass`` syntax. Index: ref7.tex =================================================================== RCS file: /cvsroot/python/python/dist/src/Doc/ref/ref7.tex,v retrieving revision 1.43 retrieving revision 1.44 diff -u -d -r1.43 -r1.44 --- ref7.tex 4 Mar 2005 14:33:32 -0000 1.43 +++ ref7.tex 9 Apr 2005 03:03:00 -0000 1.44 @@ -439,7 +439,7 @@ {"class" \token{classname} [\token{inheritance}] ":" \token{suite}} \production{inheritance} - {"(" \token{expression_list} ")"} + {"(" [\token{expression_list}] ")"} \production{classname} {\token{identifier}} \end{productionlist} From loewis at users.sourceforge.net Sat Apr 9 12:51:32 2005 From: loewis at users.sourceforge.net (loewis@users.sourceforge.net) Date: Sat Apr 9 12:51:35 2005 Subject: [Python-checkins] python/dist/src/Demo/classes Complex.py,1.7,1.8 Message-ID: Update of /cvsroot/python/python/dist/src/Demo/classes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6809 Modified Files: Complex.py Log Message: Patch #1177597: Correct various bugs, add comments. Index: Complex.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Demo/classes/Complex.py,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- Complex.py 12 Feb 2004 17:35:01 -0000 1.7 +++ Complex.py 9 Apr 2005 10:51:19 -0000 1.8 @@ -62,8 +62,8 @@ # Complex for +,-,cmp # Polar for *,/,pow - import types, math +import sys twopi = math.pi*2.0 halfpi = math.pi/2.0 @@ -98,14 +98,22 @@ class Complex: def __init__(self, re=0, im=0): + _re = 0 + _im = 0 if IsComplex(re): - im = i + Complex(0, re.im) - re = re.re + _re = re.re + _im = re.im + else: + _re = re if IsComplex(im): - re = re - im.im - im = im.re - self.__dict__['re'] = re - self.__dict__['im'] = im + _re = _re - im.im + _im = _im + im.re + else: + _im = _im + im + # this class is immutable, so setting self.re directly is + # not possible. + self.__dict__['re'] = _re + self.__dict__['im'] = _im def __setattr__(self, name, value): raise TypeError, 'Complex numbers are immutable' @@ -224,7 +232,6 @@ def checkop(expr, a, b, value, fuzz = 1e-6): - import sys print ' ', a, 'and', b, try: result = eval(expr) @@ -238,8 +245,28 @@ if not ok: print '!!\t!!\t!! should be', value, 'diff', abs(result - value) - def test(): + print 'test constructors' + constructor_test = ( + # "expect" is an array [re,im] "got" the Complex. + ( (0,0), Complex() ), + ( (0,0), Complex() ), + ( (1,0), Complex(1) ), + ( (0,1), Complex(0,1) ), + ( (1,2), Complex(Complex(1,2)) ), + ( (1,3), Complex(Complex(1,2),1) ), + ( (0,0), Complex(0,Complex(0,0)) ), + ( (3,4), Complex(3,Complex(4)) ), + ( (-1,3), Complex(1,Complex(3,2)) ), + ( (-7,6), Complex(Complex(1,2),Complex(4,8)) ) ) + cnt = [0,0] + for t in constructor_test: + cnt[0] += 1 + if ((t[0][0]!=t[1].re)or(t[0][1]!=t[1].im)): + print " expected", t[0], "got", t[1] + cnt[1] += 1 + print " ", cnt[1], "of", cnt[0], "tests failed" + # test operators testsuite = { 'a+b': [ (1, 10, 11), From loewis at users.sourceforge.net Sat Apr 9 12:53:47 2005 From: loewis at users.sourceforge.net (loewis@users.sourceforge.net) Date: Sat Apr 9 12:53:49 2005 Subject: [Python-checkins] python/dist/src/Misc NEWS,1.1283,1.1284 Message-ID: Update of /cvsroot/python/python/dist/src/Misc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8147/Misc Modified Files: NEWS Log Message: Patch #1177597: Fix various bugs in Demo/classes/Complex.py. Index: NEWS =================================================================== RCS file: /cvsroot/python/python/dist/src/Misc/NEWS,v retrieving revision 1.1283 retrieving revision 1.1284 diff -u -d -r1.1283 -r1.1284 --- NEWS 9 Apr 2005 02:30:16 -0000 1.1283 +++ NEWS 9 Apr 2005 10:53:34 -0000 1.1284 @@ -310,6 +310,7 @@ Tools/Demos ----------- +- Patch #1177597: Correct Complex.__init__. What's New in Python 2.4 final? From rhettinger at users.sourceforge.net Sat Apr 9 16:55:09 2005 From: rhettinger at users.sourceforge.net (rhettinger@users.sourceforge.net) Date: Sat Apr 9 16:55:13 2005 Subject: [Python-checkins] python/dist/src/Demo/classes Complex.py,1.8,1.9 Message-ID: Update of /cvsroot/python/python/dist/src/Demo/classes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4402 Modified Files: Complex.py Log Message: * Fix error in definition of Im() which returned self instead of 0 for non-complex arguments. * Replace type() comparisons with isinstance() checks. * Replace apply() calls with equivalent syntactic form. * Simplify __hash__ definition to hash the underlying tuple. * Use math.hypot() for more robust computation of __abs__(). * Use sorted() instead of the multi-step keys/sort/iter. * Update comment on the cmath module. Index: Complex.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Demo/classes/Complex.py,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- Complex.py 9 Apr 2005 10:51:19 -0000 1.8 +++ Complex.py 9 Apr 2005 14:55:07 -0000 1.9 @@ -54,7 +54,7 @@ # nor are shift and mask operations. # # The standard module math does not support complex numbers. -# (I suppose it would be easy to implement a cmath module.) +# The cmath modules should be used instead. # # Idea: # add a class Polar(r, phi) and mixed-mode arithmetic which @@ -62,7 +62,7 @@ # Complex for +,-,cmp # Polar for *,/,pow -import types, math +import math import sys twopi = math.pi*2.0 @@ -74,8 +74,8 @@ def ToComplex(obj): if IsComplex(obj): return obj - elif type(obj) == types.TupleType: - return apply(Complex, obj) + elif isinstance(obj, tuple): + return Complex(*obj) else: return Complex(obj) @@ -86,14 +86,12 @@ def Re(obj): if IsComplex(obj): return obj.re - else: - return obj + return obj def Im(obj): if IsComplex(obj): return obj.im - else: - return obj + return 0 class Complex: @@ -119,9 +117,9 @@ raise TypeError, 'Complex numbers are immutable' def __hash__(self): - if not self.im: return hash(self.re) - mod = sys.maxint + 1L - return int((hash(self.re) + 2L*hash(self.im) + mod) % (2L*mod) - mod) + if not self.im: + return hash(self.re) + return hash((self.re, self.im)) def __repr__(self): if not self.im: @@ -142,8 +140,7 @@ return self def __abs__(self): - # XXX could be done differently to avoid overflow! - return math.sqrt(self.re*self.re + self.im*self.im) + return math.hypot(self.re, self.im) def __int__(self): if self.im: @@ -238,8 +235,8 @@ except: result = sys.exc_type print '->', result - if (type(result) == type('') or type(value) == type('')): - ok = result == value + if isinstance(result, str) or isinstance(value, str): + ok = (result == value) else: ok = abs(result - value) <= fuzz if not ok: @@ -312,13 +309,11 @@ (Complex(1), Complex(0,10), 1), ], } - exprs = testsuite.keys() - exprs.sort() - for expr in exprs: + for expr in sorted(testsuite): print expr + ':' t = (expr,) for item in testsuite[expr]: - apply(checkop, t+item) + checkop(*(t+item)) if __name__ == '__main__': From akuchling at users.sourceforge.net Sat Apr 9 17:51:46 2005 From: akuchling at users.sourceforge.net (akuchling@users.sourceforge.net) Date: Sat Apr 9 17:51:49 2005 Subject: [Python-checkins] python/dist/src/Doc/whatsnew whatsnew25.tex, 1.11, 1.12 Message-ID: Update of /cvsroot/python/python/dist/src/Doc/whatsnew In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2528 Modified Files: whatsnew25.tex Log Message: Add more text Index: whatsnew25.tex =================================================================== RCS file: /cvsroot/python/python/dist/src/Doc/whatsnew/whatsnew25.tex,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- whatsnew25.tex 21 Mar 2005 05:47:11 -0000 1.11 +++ whatsnew25.tex 9 Apr 2005 15:51:44 -0000 1.12 @@ -28,18 +28,40 @@ %====================================================================== \section{PEP 309: Partial Function Application} -For programs written in a functional style, it can be useful to -construct variants of existing functions that have some of the -parameters filled in. This is called ``partial function application''. -The new \module{functional} module contains a \class{partial} class -that provides partial application. - The \module{functional} module is intended to contain tools for functional-style programming. Currently it only contains \class{partial}, but new functions will probably be added in future versions of Python. -% XXX write rest of this +For programs written in a functional style, it can be useful to +construct variants of existing functions that have some of the +parameters filled in. Consider a Python function \code{f(a, b, c)}; +you could create a new function \code{g(b, c)} that was equivalent to +\code{f(1, b, c)}. This is called ``partial function application'', +and is provided by the \class{partial} class in the new +\module{functional} module. + +The constructor for \class{partial} takes the arguments +\code{(\var{function}, \var{arg1}, \var{arg2}, ... +\var{kwarg1}=\var{value1}, \var{kwarg2}=\var{value2})}. The resulting +object is callable, so you can just call it to invoke \var{function} +with the filled-in arguments. + +Here's a small but realistic example: + +\begin{verbatim} +import functional + +def log (message, subsystem): + "Write the contents of 'message' to the specified subsystem." + print '%s: %s' % (subsystem, message) + ... + +server_log = functional.partial(log, subsystem='server') +\end{verbatim} + +Here's another example, from a program that uses PyGTk. + % XXX add example from my GTk programming From akuchling at users.sourceforge.net Sun Apr 10 00:57:42 2005 From: akuchling at users.sourceforge.net (akuchling@users.sourceforge.net) Date: Sun Apr 10 00:57:45 2005 Subject: [Python-checkins] python/nondist/peps pep-0314.txt,1.20,1.21 Message-ID: Update of /cvsroot/python/python/nondist/peps In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10992 Modified Files: pep-0314.txt Log Message: Bump Python version Index: pep-0314.txt =================================================================== RCS file: /cvsroot/python/python/nondist/peps/pep-0314.txt,v retrieving revision 1.20 retrieving revision 1.21 diff -u -d -r1.20 -r1.21 --- pep-0314.txt 20 Mar 2005 15:59:04 -0000 1.20 +++ pep-0314.txt 9 Apr 2005 22:57:29 -0000 1.21 @@ -7,7 +7,7 @@ Type: Standards Track Content-type: text/plain Created: 12-Apr-2003 -Python-Version: 2.3 +Python-Version: 2.5 Post-History: 29-Apr-2003 Replaces: 241 From akuchling at users.sourceforge.net Sun Apr 10 01:59:43 2005 From: akuchling at users.sourceforge.net (akuchling@users.sourceforge.net) Date: Sun Apr 10 01:59:46 2005 Subject: [Python-checkins] python/dist/src/Doc/whatsnew whatsnew25.tex, 1.12, 1.13 Message-ID: Update of /cvsroot/python/python/dist/src/Doc/whatsnew In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11515 Modified Files: whatsnew25.tex Log Message: Fill out one section Index: whatsnew25.tex =================================================================== RCS file: /cvsroot/python/python/dist/src/Doc/whatsnew/whatsnew25.tex,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- whatsnew25.tex 9 Apr 2005 15:51:44 -0000 1.12 +++ whatsnew25.tex 9 Apr 2005 23:59:41 -0000 1.13 @@ -77,9 +77,26 @@ %====================================================================== \section{PEP 314: Metadata for Python Software Packages v1.1} -XXX describe this PEP. - distutils \function{setup()} now supports the \var{provides}, - \var{requires}, \var{obsoletes} keywords. +Some simple dependency support was added to Distutils. The +\function{setup()} function now has \code{requires},\code{provides}, +and \code{obsoletes}. When you build a source distribution using the +\code{sdist} command, the dependency information will be recorded in +the \file{PKG-INFO} file. + +Another new keyword is \code{download_url}, which should be set to a +URL for the package's source code. This means it's now possible to +look up an entry in the package index, determine the dependencies for +a package, and download the required packages. + +% XXX put example here + +\begin{seealso} + +\seepep{314}{Metadata for Python Software Packages v1.1}{PEP proposed +and written by A.M. Kuchling, Richard Jones, and Fred Drake; +implemented by Richard Jones and Fred Drake.} + +\end{seealso} %====================================================================== From service at paypal.com Sat Apr 9 19:54:43 2005 From: service at paypal.com (PayPal Account Review Department) Date: Sun Apr 10 05:36:07 2005 Subject: [Python-checkins] Notification of Limited Account Access (Routing Code: W122-Q088-C899-T8855) Message-ID: An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-checkins/attachments/20050409/f06fd73b/attachment.htm From rhettinger at users.sourceforge.net Sun Apr 10 18:21:10 2005 From: rhettinger at users.sourceforge.net (rhettinger@users.sourceforge.net) Date: Sun Apr 10 18:21:13 2005 Subject: [Python-checkins] python/dist/src/Demo/rpc rpc.py,1.13,1.14 Message-ID: Update of /cvsroot/python/python/dist/src/Demo/rpc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6055 Modified Files: rpc.py Log Message: SF patch 1179503: Fix typos in rpc.py * Call to unpack_int() should have no arguments * Misspelled BadRPCVerspion exception * Replace <> with != Index: rpc.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Demo/rpc/rpc.py,v retrieving revision 1.13 retrieving revision 1.14 diff -u -d -r1.13 -r1.14 --- rpc.py 18 Jul 2004 05:56:08 -0000 1.13 +++ rpc.py 10 Apr 2005 16:21:07 -0000 1.14 @@ -3,6 +3,8 @@ # XXX There should be separate exceptions for the various reasons why # XXX an RPC can fail, rather than using RuntimeError for everything +# XXX Need to use class based exceptions rather than string exceptions + # XXX The UDP version of the protocol resends requests when it does # XXX not receive a timely reply -- use only for idempotent calls! @@ -90,13 +92,13 @@ return (flavor, stuff) def unpack_callheader(self): - xid = self.unpack_uint(xid) + xid = self.unpack_uint() temp = self.unpack_enum() - if temp <> CALL: + if temp != CALL: raise BadRPCFormat, 'no CALL but %r' % (temp,) temp = self.unpack_uint() - if temp <> RPCVERSION: - raise BadRPCVerspion, 'bad RPC version %r' % (temp,) + if temp != RPCVERSION: + raise BadRPCVersion, 'bad RPC version %r' % (temp,) prog = self.unpack_uint() vers = self.unpack_uint() proc = self.unpack_uint() @@ -108,7 +110,7 @@ def unpack_replyheader(self): xid = self.unpack_uint() mtype = self.unpack_enum() - if mtype <> REPLY: + if mtype != REPLY: raise RuntimeError, 'no REPLY but %r' % (mtype,) stat = self.unpack_enum() if stat == MSG_DENIED: @@ -123,7 +125,7 @@ raise RuntimeError, \ 'MSG_DENIED: AUTH_ERROR: %r' % (stat,) raise RuntimeError, 'MSG_DENIED: %r' % (stat,) - if stat <> MSG_ACCEPTED: + if stat != MSG_ACCEPTED: raise RuntimeError, \ 'Neither MSG_DENIED nor MSG_ACCEPTED: %r' % (stat,) verf = self.unpack_auth() @@ -139,7 +141,7 @@ raise RuntimeError, 'call failed: PROC_UNAVAIL' if stat == GARBAGE_ARGS: raise RuntimeError, 'call failed: GARBAGE_ARGS' - if stat <> SUCCESS: + if stat != SUCCESS: raise RuntimeError, 'call failed: %r' % (stat,) return xid, verf # Caller must get procedure-specific part of reply @@ -329,7 +331,7 @@ sock.bind((host, i)) return last_resv_port_tried except socket.error, (errno, msg): - if errno <> 114: + if errno != 114: raise socket.error, (errno, msg) raise RuntimeError, 'can\'t assign reserved port' @@ -348,7 +350,7 @@ u = self.unpacker u.reset(reply) xid, verf = u.unpack_replyheader() - if xid <> self.lastxid: + if xid != self.lastxid: # Can't really happen since this is TCP... raise RuntimeError, 'wrong xid in reply %r instead of %r' % ( xid, self.lastxid) @@ -387,7 +389,7 @@ u = self.unpacker u.reset(reply) xid, verf = u.unpack_replyheader() - if xid <> self.lastxid: + if xid != self.lastxid: ## print 'BAD xid' continue break @@ -443,7 +445,7 @@ u = self.unpacker u.reset(reply) xid, verf = u.unpack_replyheader() - if xid <> self.lastxid: + if xid != self.lastxid: ## print 'BAD xid' continue reply = unpack_func() @@ -678,11 +680,11 @@ xid = self.unpacker.unpack_uint() self.packer.pack_uint(xid) temp = self.unpacker.unpack_enum() - if temp <> CALL: + if temp != CALL: return None # Not worthy of a reply self.packer.pack_uint(REPLY) temp = self.unpacker.unpack_uint() - if temp <> RPCVERSION: + if temp != RPCVERSION: self.packer.pack_uint(MSG_DENIED) self.packer.pack_uint(RPC_MISMATCH) self.packer.pack_uint(RPCVERSION) @@ -691,11 +693,11 @@ self.packer.pack_uint(MSG_ACCEPTED) self.packer.pack_auth((AUTH_NULL, make_auth_null())) prog = self.unpacker.unpack_uint() - if prog <> self.prog: + if prog != self.prog: self.packer.pack_uint(PROG_UNAVAIL) return self.packer.get_buf() vers = self.unpacker.unpack_uint() - if vers <> self.vers: + if vers != self.vers: self.packer.pack_uint(PROG_MISMATCH) self.packer.pack_uint(self.vers) self.packer.pack_uint(self.vers) @@ -812,7 +814,7 @@ def session(self): call, host_port = self.sock.recvfrom(8192) reply = self.handle(call) - if reply <> None: + if reply != None: self.sock.sendto(reply, host_port) From rhettinger at users.sourceforge.net Sun Apr 10 18:23:52 2005 From: rhettinger at users.sourceforge.net (rhettinger@users.sourceforge.net) Date: Sun Apr 10 18:23:55 2005 Subject: [Python-checkins] python/dist/src/Demo/rpc rpc.py,1.13,1.13.4.1 Message-ID: Update of /cvsroot/python/python/dist/src/Demo/rpc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9016 Modified Files: Tag: release24-maint rpc.py Log Message: SF patch 1179503: fix typos in rpc.py Index: rpc.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Demo/rpc/rpc.py,v retrieving revision 1.13 retrieving revision 1.13.4.1 diff -u -d -r1.13 -r1.13.4.1 --- rpc.py 18 Jul 2004 05:56:08 -0000 1.13 +++ rpc.py 10 Apr 2005 16:23:49 -0000 1.13.4.1 @@ -3,6 +3,8 @@ # XXX There should be separate exceptions for the various reasons why # XXX an RPC can fail, rather than using RuntimeError for everything +# XXX Need to use class based exceptions rather than string exceptions + # XXX The UDP version of the protocol resends requests when it does # XXX not receive a timely reply -- use only for idempotent calls! @@ -90,13 +92,13 @@ return (flavor, stuff) def unpack_callheader(self): - xid = self.unpack_uint(xid) + xid = self.unpack_uint() temp = self.unpack_enum() - if temp <> CALL: + if temp != CALL: raise BadRPCFormat, 'no CALL but %r' % (temp,) temp = self.unpack_uint() - if temp <> RPCVERSION: - raise BadRPCVerspion, 'bad RPC version %r' % (temp,) + if temp != RPCVERSION: + raise BadRPCVersion, 'bad RPC version %r' % (temp,) prog = self.unpack_uint() vers = self.unpack_uint() proc = self.unpack_uint() @@ -108,7 +110,7 @@ def unpack_replyheader(self): xid = self.unpack_uint() mtype = self.unpack_enum() - if mtype <> REPLY: + if mtype != REPLY: raise RuntimeError, 'no REPLY but %r' % (mtype,) stat = self.unpack_enum() if stat == MSG_DENIED: @@ -123,7 +125,7 @@ raise RuntimeError, \ 'MSG_DENIED: AUTH_ERROR: %r' % (stat,) raise RuntimeError, 'MSG_DENIED: %r' % (stat,) - if stat <> MSG_ACCEPTED: + if stat != MSG_ACCEPTED: raise RuntimeError, \ 'Neither MSG_DENIED nor MSG_ACCEPTED: %r' % (stat,) verf = self.unpack_auth() @@ -139,7 +141,7 @@ raise RuntimeError, 'call failed: PROC_UNAVAIL' if stat == GARBAGE_ARGS: raise RuntimeError, 'call failed: GARBAGE_ARGS' - if stat <> SUCCESS: + if stat != SUCCESS: raise RuntimeError, 'call failed: %r' % (stat,) return xid, verf # Caller must get procedure-specific part of reply @@ -329,7 +331,7 @@ sock.bind((host, i)) return last_resv_port_tried except socket.error, (errno, msg): - if errno <> 114: + if errno != 114: raise socket.error, (errno, msg) raise RuntimeError, 'can\'t assign reserved port' @@ -348,7 +350,7 @@ u = self.unpacker u.reset(reply) xid, verf = u.unpack_replyheader() - if xid <> self.lastxid: + if xid != self.lastxid: # Can't really happen since this is TCP... raise RuntimeError, 'wrong xid in reply %r instead of %r' % ( xid, self.lastxid) @@ -387,7 +389,7 @@ u = self.unpacker u.reset(reply) xid, verf = u.unpack_replyheader() - if xid <> self.lastxid: + if xid != self.lastxid: ## print 'BAD xid' continue break @@ -443,7 +445,7 @@ u = self.unpacker u.reset(reply) xid, verf = u.unpack_replyheader() - if xid <> self.lastxid: + if xid != self.lastxid: ## print 'BAD xid' continue reply = unpack_func() @@ -678,11 +680,11 @@ xid = self.unpacker.unpack_uint() self.packer.pack_uint(xid) temp = self.unpacker.unpack_enum() - if temp <> CALL: + if temp != CALL: return None # Not worthy of a reply self.packer.pack_uint(REPLY) temp = self.unpacker.unpack_uint() - if temp <> RPCVERSION: + if temp != RPCVERSION: self.packer.pack_uint(MSG_DENIED) self.packer.pack_uint(RPC_MISMATCH) self.packer.pack_uint(RPCVERSION) @@ -691,11 +693,11 @@ self.packer.pack_uint(MSG_ACCEPTED) self.packer.pack_auth((AUTH_NULL, make_auth_null())) prog = self.unpacker.unpack_uint() - if prog <> self.prog: + if prog != self.prog: self.packer.pack_uint(PROG_UNAVAIL) return self.packer.get_buf() vers = self.unpacker.unpack_uint() - if vers <> self.vers: + if vers != self.vers: self.packer.pack_uint(PROG_MISMATCH) self.packer.pack_uint(self.vers) self.packer.pack_uint(self.vers) @@ -812,7 +814,7 @@ def session(self): call, host_port = self.sock.recvfrom(8192) reply = self.handle(call) - if reply <> None: + if reply != None: self.sock.sendto(reply, host_port) From rhettinger at users.sourceforge.net Sun Apr 10 18:36:18 2005 From: rhettinger at users.sourceforge.net (rhettinger@users.sourceforge.net) Date: Sun Apr 10 18:36:21 2005 Subject: [Python-checkins] python/dist/src/Misc developers.txt,1.7,1.8 Message-ID: Update of /cvsroot/python/python/dist/src/Misc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16975 Modified Files: developers.txt Log Message: Update status for Irme de Jong. Index: developers.txt =================================================================== RCS file: /cvsroot/python/python/dist/src/Misc/developers.txt,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- developers.txt 8 Apr 2005 20:43:19 -0000 1.7 +++ developers.txt 10 Apr 2005 16:36:16 -0000 1.8 @@ -37,6 +37,9 @@ Permissions Dropped on Request ------------------------------ +- Irmen de Jong requested dropping CVS access while keeping tracker + access. 10 Apr 2005 RDH + - Moshe Zadka and Ken Manheimer sent drop requests. 8 Apr 2005 by RDH - Steve Holden, Gerhard Haring, and David Cole sent email stating that From rhettinger at users.sourceforge.net Sun Apr 10 19:32:38 2005 From: rhettinger at users.sourceforge.net (rhettinger@users.sourceforge.net) Date: Sun Apr 10 19:32:41 2005 Subject: [Python-checkins] python/dist/src/Doc/lib libsets.tex, 1.16, 1.17 libstdtypes.tex, 1.175, 1.176 Message-ID: Update of /cvsroot/python/python/dist/src/Doc/lib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18846 Modified Files: libsets.tex libstdtypes.tex Log Message: SF bug #1179957: Missing def'n of equality for set elements Index: libsets.tex =================================================================== RCS file: /cvsroot/python/python/dist/src/Doc/lib/libsets.tex,v retrieving revision 1.16 retrieving revision 1.17 diff -u -d -r1.16 -r1.17 --- libsets.tex 19 Jan 2005 07:24:34 -0000 1.16 +++ libsets.tex 10 Apr 2005 17:32:35 -0000 1.17 @@ -30,7 +30,10 @@ abstract class useful for determining whether something is a set: \code{isinstance(\var{obj}, BaseSet)}. -The set classes are implemented using dictionaries. As a result, sets +The set classes are implemented using dictionaries. Accordingly, the +requirements for set elements are the same as those for dictionary keys; +namely, that the element defines both \method{__eq__} and \method{__hash__}. +As a result, sets cannot contain mutable elements such as lists or dictionaries. However, they can contain immutable collections such as tuples or instances of \class{ImmutableSet}. For convenience in implementing Index: libstdtypes.tex =================================================================== RCS file: /cvsroot/python/python/dist/src/Doc/lib/libstdtypes.tex,v retrieving revision 1.175 retrieving revision 1.176 diff -u -d -r1.175 -r1.176 --- libstdtypes.tex 9 Feb 2005 23:19:25 -0000 1.175 +++ libstdtypes.tex 10 Apr 2005 17:32:35 -0000 1.176 @@ -1220,6 +1220,9 @@ Since sets only define partial ordering (subset relationships), the output of the \method{list.sort()} method is undefined for lists of sets. +Set elements are like dictionary keys; they need to define both +\method{__hash__} and \method{__eq__} methods. + Binary operations that mix \class{set} instances with \class{frozenset} return the type of the first operand. For example: \samp{frozenset('ab') | set('bc')} returns an instance of \class{frozenset}. From rhettinger at users.sourceforge.net Sun Apr 10 19:36:28 2005 From: rhettinger at users.sourceforge.net (rhettinger@users.sourceforge.net) Date: Sun Apr 10 19:36:31 2005 Subject: [Python-checkins] python/dist/src/Doc/lib libsets.tex, 1.15.4.1, 1.15.4.2 libstdtypes.tex, 1.170.2.5, 1.170.2.6 Message-ID: Update of /cvsroot/python/python/dist/src/Doc/lib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21540 Modified Files: Tag: release24-maint libsets.tex libstdtypes.tex Log Message: SF bug #1179957: Missing def'n of equality for set element Index: libsets.tex =================================================================== RCS file: /cvsroot/python/python/dist/src/Doc/lib/libsets.tex,v retrieving revision 1.15.4.1 retrieving revision 1.15.4.2 diff -u -d -r1.15.4.1 -r1.15.4.2 --- libsets.tex 19 Jan 2005 07:23:35 -0000 1.15.4.1 +++ libsets.tex 10 Apr 2005 17:36:26 -0000 1.15.4.2 @@ -30,7 +30,10 @@ abstract class useful for determining whether something is a set: \code{isinstance(\var{obj}, BaseSet)}. -The set classes are implemented using dictionaries. As a result, sets +The set classes are implemented using dictionaries. Accordingly, the +requirements for set elements are the same as those for dictionary keys; +namely, that the element defines both \method{__eq__} and \method{__hash__}. +As a result, sets cannot contain mutable elements such as lists or dictionaries. However, they can contain immutable collections such as tuples or instances of \class{ImmutableSet}. For convenience in implementing Index: libstdtypes.tex =================================================================== RCS file: /cvsroot/python/python/dist/src/Doc/lib/libstdtypes.tex,v retrieving revision 1.170.2.5 retrieving revision 1.170.2.6 diff -u -d -r1.170.2.5 -r1.170.2.6 --- libstdtypes.tex 9 Feb 2005 23:23:10 -0000 1.170.2.5 +++ libstdtypes.tex 10 Apr 2005 17:36:26 -0000 1.170.2.6 @@ -1220,6 +1220,9 @@ Since sets only define partial ordering (subset relationships), the output of the \method{list.sort()} method is undefined for lists of sets. +Set elements are like dictionary keys; they need to define both +\method{__hash__} and \method{__eq__} methods. + Binary operations that mix \class{set} instances with \class{frozenset} return the type of the first operand. For example: \samp{frozenset('ab') | set('bc')} returns an instance of \class{frozenset}. From rhettinger at users.sourceforge.net Mon Apr 11 03:03:47 2005 From: rhettinger at users.sourceforge.net (rhettinger@users.sourceforge.net) Date: Mon Apr 11 03:03:50 2005 Subject: [Python-checkins] python/dist/src/Doc/lib libstringio.tex,1.9,1.10 Message-ID: Update of /cvsroot/python/python/dist/src/Doc/lib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19861 Modified Files: libstringio.tex Log Message: SF bug #1180392: StringIO's docs should mention overwriting of initial value * Added a note that the initial file position is zero even if the object is freshly initialized. Index: libstringio.tex =================================================================== RCS file: /cvsroot/python/python/dist/src/Doc/lib/libstringio.tex,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- libstringio.tex 8 Jan 2004 15:01:08 -0000 1.9 +++ libstringio.tex 11 Apr 2005 01:03:44 -0000 1.10 @@ -14,6 +14,7 @@ When a \class{StringIO} object is created, it can be initialized to an existing string by passing the string to the constructor. If no string is given, the \class{StringIO} will start empty. +In both cases, the initial file position starts at zero. The \class{StringIO} object can accept either Unicode or 8-bit strings, but mixing the two may take some care. If both are used, From rhettinger at users.sourceforge.net Mon Apr 11 03:04:34 2005 From: rhettinger at users.sourceforge.net (rhettinger@users.sourceforge.net) Date: Mon Apr 11 03:04:38 2005 Subject: [Python-checkins] python/dist/src/Doc/lib libstringio.tex, 1.9, 1.9.4.1 Message-ID: Update of /cvsroot/python/python/dist/src/Doc/lib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20999 Modified Files: Tag: release24-maint libstringio.tex Log Message: SF bug #1180392: StringIO's docs should mention overwriting of initial value * Added a note that the initial file position is zero even if the object is freshly initialized. Index: libstringio.tex =================================================================== RCS file: /cvsroot/python/python/dist/src/Doc/lib/libstringio.tex,v retrieving revision 1.9 retrieving revision 1.9.4.1 diff -u -d -r1.9 -r1.9.4.1 --- libstringio.tex 8 Jan 2004 15:01:08 -0000 1.9 +++ libstringio.tex 11 Apr 2005 01:04:32 -0000 1.9.4.1 @@ -14,6 +14,7 @@ When a \class{StringIO} object is created, it can be initialized to an existing string by passing the string to the constructor. If no string is given, the \class{StringIO} will start empty. +In both cases, the initial file position starts at zero. The \class{StringIO} object can accept either Unicode or 8-bit strings, but mixing the two may take some care. If both are used, From rhettinger at users.sourceforge.net Mon Apr 11 05:11:13 2005 From: rhettinger at users.sourceforge.net (rhettinger@users.sourceforge.net) Date: Mon Apr 11 05:11:16 2005 Subject: [Python-checkins] python/dist/src/Misc developers.txt,1.8,1.9 Message-ID: Update of /cvsroot/python/python/dist/src/Misc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20587 Modified Files: developers.txt Log Message: Update permissions for Eric Price. Index: developers.txt =================================================================== RCS file: /cvsroot/python/python/dist/src/Misc/developers.txt,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- developers.txt 10 Apr 2005 16:36:16 -0000 1.8 +++ developers.txt 11 Apr 2005 03:11:11 -0000 1.9 @@ -37,6 +37,8 @@ Permissions Dropped on Request ------------------------------ +- Eric Price sent a drop request. 10 Apr 2005 RDH + - Irmen de Jong requested dropping CVS access while keeping tracker access. 10 Apr 2005 RDH From perky at users.sourceforge.net Tue Apr 12 04:49:55 2005 From: perky at users.sourceforge.net (perky@users.sourceforge.net) Date: Tue Apr 12 04:49:58 2005 Subject: [Python-checkins] python/dist/src/Demo/xmlrpc xmlrpc_handler.py, 1.2, 1.3 Message-ID: Update of /cvsroot/python/python/dist/src/Demo/xmlrpc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14477 Modified Files: xmlrpc_handler.py Log Message: Fix HTTP method handler example so that method names in uppercases can be processed. (Submitted by Jooncheol Park) Index: xmlrpc_handler.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Demo/xmlrpc/xmlrpc_handler.py,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- xmlrpc_handler.py 3 Apr 2002 21:47:47 -0000 1.2 +++ xmlrpc_handler.py 12 Apr 2005 02:49:52 -0000 1.3 @@ -26,7 +26,7 @@ def handle_request (self, request): [path, params, query, fragment] = request.split_uri() - if request.command in ('post', 'put'): + if request.command.lower() in ('post', 'put'): request.collector = collector (self, request) else: request.error (400) From bcannon at users.sourceforge.net Wed Apr 13 01:19:57 2005 From: bcannon at users.sourceforge.net (bcannon@users.sourceforge.net) Date: Wed Apr 13 01:20:00 2005 Subject: [Python-checkins] python/dist/src/Parser Python.asdl, 1.1.2.9, 1.1.2.10 Message-ID: Update of /cvsroot/python/python/dist/src/Parser In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1883/Parser Modified Files: Tag: ast-branch Python.asdl Log Message: Very minor syntax nit. Index: Python.asdl =================================================================== RCS file: /cvsroot/python/python/dist/src/Parser/Attic/Python.asdl,v retrieving revision 1.1.2.9 retrieving revision 1.1.2.10 diff -u -d -r1.1.2.9 -r1.1.2.10 --- Python.asdl 2 Apr 2005 18:50:05 -0000 1.1.2.9 +++ Python.asdl 12 Apr 2005 23:19:54 -0000 1.1.2.10 @@ -52,7 +52,7 @@ | BinOp(expr left, operator op, expr right) | UnaryOp(unaryop op, expr operand) | Lambda(arguments args, expr body) - | Dict(expr* keys, expr *values) + | Dict(expr* keys, expr* values) | ListComp(expr elt, comprehension* generators) | GeneratorComp(expr elt, comprehension* generators) -- need sequences for compare to distinguish between From fdrake at users.sourceforge.net Wed Apr 13 03:08:26 2005 From: fdrake at users.sourceforge.net (fdrake@users.sourceforge.net) Date: Wed Apr 13 03:08:28 2005 Subject: [Python-checkins] python/dist/src/Doc/lib liburllib2.tex,1.21,1.22 Message-ID: Update of /cvsroot/python/python/dist/src/Doc/lib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30839/Doc/lib Modified Files: liburllib2.tex Log Message: get_method() returns a method name, not take it as an argument (backporting to release24-maint branch) Index: liburllib2.tex =================================================================== RCS file: /cvsroot/python/python/dist/src/Doc/lib/liburllib2.tex,v retrieving revision 1.21 retrieving revision 1.22 diff -u -d -r1.21 -r1.22 --- liburllib2.tex 25 Aug 2004 11:24:42 -0000 1.21 +++ liburllib2.tex 13 Apr 2005 01:08:23 -0000 1.22 @@ -254,8 +254,8 @@ \begin{methoddesc}[Request]{get_method}{} Return a string indicating the HTTP request method. This is only -meaningful for HTTP requests, and currently always takes one of the -values ("GET", "POST"). +meaningful for HTTP requests, and currently always returns +\code{'GET'} or \code{'POST'}. \end{methoddesc} \begin{methoddesc}[Request]{has_data}{} From fdrake at users.sourceforge.net Wed Apr 13 03:12:23 2005 From: fdrake at users.sourceforge.net (fdrake@users.sourceforge.net) Date: Wed Apr 13 03:12:25 2005 Subject: [Python-checkins] python/dist/src/Doc/lib liburllib2.tex, 1.21, 1.21.2.1 Message-ID: Update of /cvsroot/python/python/dist/src/Doc/lib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv657/Doc/lib Modified Files: Tag: release24-maint liburllib2.tex Log Message: get_method() returns a method name, not take it as an argument (backported from trunk revision 1.22) Index: liburllib2.tex =================================================================== RCS file: /cvsroot/python/python/dist/src/Doc/lib/liburllib2.tex,v retrieving revision 1.21 retrieving revision 1.21.2.1 diff -u -d -r1.21 -r1.21.2.1 --- liburllib2.tex 25 Aug 2004 11:24:42 -0000 1.21 +++ liburllib2.tex 13 Apr 2005 01:12:21 -0000 1.21.2.1 @@ -254,8 +254,8 @@ \begin{methoddesc}[Request]{get_method}{} Return a string indicating the HTTP request method. This is only -meaningful for HTTP requests, and currently always takes one of the -values ("GET", "POST"). +meaningful for HTTP requests, and currently always returns +\code{'GET'} or \code{'POST'}. \end{methoddesc} \begin{methoddesc}[Request]{has_data}{} From bcannon at users.sourceforge.net Wed Apr 13 21:44:44 2005 From: bcannon at users.sourceforge.net (bcannon@users.sourceforge.net) Date: Wed Apr 13 21:44:47 2005 Subject: [Python-checkins] python/dist/src/Python Python-ast.c, 1.1.2.11, 1.1.2.12 asdl.c, 1.1.2.5, 1.1.2.6 ast.c, 1.1.2.58, 1.1.2.59 compile.c, 2.247.2.2, 2.247.2.3 newcompile.c, 1.1.2.105, 1.1.2.106 symtable.c, 2.10.8.31, 2.10.8.32 compile.txt, 1.1.2.13, 1.1.2.14 Message-ID: Update of /cvsroot/python/python/dist/src/Python In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12515/Python Modified Files: Tag: ast-branch Python-ast.c asdl.c ast.c compile.c newcompile.c symtable.c compile.txt Log Message: Add support for genexps. Required changing the name to GeneratorExp for consistency in Parser/Python.asdl (and subsequent changes to other files because of this), regenerating the Python-ast.(h|c) files, and then the necessary changes to Python/ast.c and Python/newcompile.c . Also includes a tweak to asdl_seq_new() to not call malloc() with a -1 if an empty asdl_seq struct is needed. Lastly, it silences output of the results of functions while they are doing internal calls; allows doctest to work properly. Not thoroughly tested since test_grammar segfaults before it reaches genexps. But hand-testing seems to show everything works. Closes patch #1167628. Thanks Nick Coghlan. Index: Python-ast.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Python/Attic/Python-ast.c,v retrieving revision 1.1.2.11 retrieving revision 1.1.2.12 diff -u -d -r1.1.2.11 -r1.1.2.12 --- Python-ast.c 2 Apr 2005 18:50:06 -0000 1.1.2.11 +++ Python-ast.c 13 Apr 2005 19:44:37 -0000 1.1.2.12 @@ -1,4 +1,4 @@ -/* File automatically generated by ../Parser/asdl_c.py */ +/* File automatically generated by ./Parser/asdl_c.py */ #include "Python.h" #include "Python-ast.h" @@ -651,12 +651,12 @@ } expr_ty -GeneratorComp(expr_ty elt, asdl_seq * generators) +GeneratorExp(expr_ty elt, asdl_seq * generators) { expr_ty p; if (!elt) { PyErr_SetString(PyExc_ValueError, - "field elt is required for GeneratorComp"); + "field elt is required for GeneratorExp"); return NULL; } p = (expr_ty)malloc(sizeof(*p)); @@ -664,9 +664,9 @@ PyErr_SetString(PyExc_MemoryError, "no memory"); return NULL; } - p->kind = GeneratorComp_kind; - p->v.GeneratorComp.elt = elt; - p->v.GeneratorComp.generators = generators; + p->kind = GeneratorExp_kind; + p->v.GeneratorExp.elt = elt; + p->v.GeneratorExp.generators = generators; return p; } @@ -1327,9 +1327,9 @@ free_comprehension((comprehension_ty)asdl_seq_GET(seq, i)); break; - case GeneratorComp_kind: - free_expr((expr_ty)o->v.GeneratorComp.elt); - seq = o->v.GeneratorComp.generators; + case GeneratorExp_kind: + free_expr((expr_ty)o->v.GeneratorExp.elt); + seq = o->v.GeneratorExp.generators; n = asdl_seq_LEN(seq); for (i = 0; i < n; i++) free_comprehension((comprehension_ty)asdl_seq_GET(seq, @@ -1927,14 +1927,14 @@ (comprehension_ty)elt); } break; - case GeneratorComp_kind: + case GeneratorExp_kind: marshal_write_int(buf, off, 7); - marshal_write_expr(buf, off, o->v.GeneratorComp.elt); + marshal_write_expr(buf, off, o->v.GeneratorExp.elt); marshal_write_int(buf, off, - asdl_seq_LEN(o->v.GeneratorComp.generators)); - for (i = 0; i < asdl_seq_LEN(o->v.GeneratorComp.generators); + asdl_seq_LEN(o->v.GeneratorExp.generators)); + for (i = 0; i < asdl_seq_LEN(o->v.GeneratorExp.generators); i++) { - void *elt = asdl_seq_GET(o->v.GeneratorComp.generators, + void *elt = asdl_seq_GET(o->v.GeneratorExp.generators, i); marshal_write_comprehension(buf, off, (comprehension_ty)elt); Index: asdl.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Python/Attic/asdl.c,v retrieving revision 1.1.2.5 retrieving revision 1.1.2.6 diff -u -d -r1.1.2.5 -r1.1.2.6 --- asdl.c 3 Apr 2003 00:55:00 -0000 1.1.2.5 +++ asdl.c 13 Apr 2005 19:44:37 -0000 1.1.2.6 @@ -4,21 +4,24 @@ asdl_seq * asdl_seq_new(int size) { - asdl_seq *seq = (asdl_seq *)PyObject_Malloc(sizeof(asdl_seq) - + sizeof(void *) * (size - 1)); - if (!seq) { - PyErr_SetString(PyExc_MemoryError, "no memory"); - return NULL; - } - seq->size = size; - seq->offset = 0; - return seq; + asdl_seq *seq = NULL; + + seq = (asdl_seq *)PyObject_Malloc(sizeof(asdl_seq) + + (size ? (sizeof(void *) * (size - 1)) : 0)); + + if (!seq) { + PyErr_SetString(PyExc_MemoryError, "no memory"); + return NULL; + } + seq->size = size; + seq->offset = 0; + return seq; } void asdl_seq_free(asdl_seq *seq) { - PyObject_Free(seq); + PyObject_Free(seq); } #define CHECKSIZE(BUF, OFF, MIN) { \ Index: ast.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Python/Attic/ast.c,v retrieving revision 1.1.2.58 retrieving revision 1.1.2.59 diff -u -d -r1.1.2.58 -r1.1.2.59 --- ast.c 2 Apr 2005 19:00:35 -0000 1.1.2.58 +++ ast.c 13 Apr 2005 19:44:37 -0000 1.1.2.59 @@ -986,95 +986,270 @@ return ListComp(elt, listcomps); } +/* + Count the number of 'for' loops in a generator expression. + + Helper for ast_for_genexp(). +*/ + +static int +count_gen_fors(const node *n) +{ + int n_fors = 0; + node *ch = CHILD(n, 1); + + count_gen_for: + n_fors++; + REQ(ch, gen_for); + if (NCH(ch) == 5) + ch = CHILD(ch, 4); + else + return n_fors; + count_gen_iter: + REQ(ch, gen_iter); + ch = CHILD(ch, 0); + if (TYPE(ch) == gen_for) + goto count_gen_for; + else if (TYPE(ch) == gen_if) { + if (NCH(ch) == 3) { + ch = CHILD(ch, 2); + goto count_gen_iter; + } + else + return n_fors; + } + else { + /* Should never be reached */ + PyErr_SetString(PyExc_Exception, "logic error in count_gen_fors"); + return -1; + } +} + +/* Count the number of 'if' statements in a generator expression. + + Helper for ast_for_genexp(). +*/ + +static int +count_gen_ifs(const node *n) +{ + int n_ifs = 0; + + while (1) { + REQ(n, gen_iter); + if (TYPE(CHILD(n, 0)) == gen_for) + return n_ifs; + n = CHILD(n, 0); + REQ(n, gen_if); + n_ifs++; + if (NCH(n) == 2) + return n_ifs; + n = CHILD(n, 2); + } +} + +static expr_ty +ast_for_genexp(struct compiling *c, const node *n) +{ + /* testlist_gexp: test ( gen_for | (',' test)* [','] ) + argument: [test '='] test [gen_for] # Really [keyword '='] test */ + expr_ty elt; + asdl_seq *genexps; + int i, n_fors; + node *ch; + + assert(TYPE(n) == (testlist_gexp) || TYPE(n) == (argument)); + assert(NCH(n) > 1); + + elt = ast_for_expr(c, CHILD(n, 0)); + if (!elt) + return NULL; + + n_fors = count_gen_fors(n); + if (n_fors == -1) + return NULL; + + genexps = asdl_seq_new(n_fors); + if (!genexps) { + /* XXX free(elt); */ + return NULL; + } + + ch = CHILD(n, 1); + for (i = 0; i < n_fors; i++) { + comprehension_ty ge; + asdl_seq *t; + expr_ty expression; + + REQ(ch, gen_for); + + t = ast_for_exprlist(c, CHILD(ch, 1), Store); + if (!t) { + asdl_seq_free(genexps); + /* XXX free(elt); */ + return NULL; + } + expression = ast_for_testlist(c, CHILD(ch, 3)); + if (!expression) { + asdl_seq_free(genexps); + /* XXX free(elt); */ + return NULL; + } + + if (asdl_seq_LEN(t) == 1) + ge = comprehension(asdl_seq_GET(t, 0), expression, NULL); + else + ge = comprehension(Tuple(t, Store), expression, NULL); + + if (!ge) { + asdl_seq_free(genexps); + /* XXX free(elt); */ + return NULL; + } + + if (NCH(ch) == 5) { + int j, n_ifs; + asdl_seq *ifs; + + ch = CHILD(ch, 4); + n_ifs = count_gen_ifs(ch); + if (n_ifs == -1) { + asdl_seq_free(genexps); + /* XXX free(elt); */ + return NULL; + } + + ifs = asdl_seq_new(n_ifs); + if (!ifs) { + asdl_seq_free(genexps); + /* XXX free(elt); */ + return NULL; + } + + for (j = 0; j < n_ifs; j++) { + REQ(ch, gen_iter); + + ch = CHILD(ch, 0); + REQ(ch, gen_if); + + asdl_seq_APPEND(ifs, ast_for_expr(c, CHILD(ch, 1))); + if (NCH(ch) == 3) + ch = CHILD(ch, 2); + } + /* on exit, must guarantee that ch is a gen_for */ + if (TYPE(ch) == gen_iter) + ch = CHILD(ch, 0); + ge->ifs = ifs; + } + asdl_seq_APPEND(genexps, ge); + } + + return GeneratorExp(elt, genexps); +} + static expr_ty ast_for_atom(struct compiling *c, const node *n) { - /* atom: '(' [testlist] ')' | '[' [listmaker] ']' - | '{' [dictmaker] '}' | '`' testlist '`' | NAME | NUMBER | STRING+ - */ - node *ch = CHILD(n, 0); + /* atom: '(' [testlist_gexp] ')' | '[' [listmaker] ']' + | '{' [dictmaker] '}' | '`' testlist '`' | NAME | NUMBER | STRING+ + */ + node *ch = CHILD(n, 0); - switch (TYPE(ch)) { - case NAME: - /* All names start in Load context, but may later be changed. */ - return Name(NEW_IDENTIFIER(ch), Load); - case STRING: { - PyObject *str = parsestrplus(c, n); + switch (TYPE(ch)) { + case NAME: + /* All names start in Load context, but may later be + changed. */ + return Name(NEW_IDENTIFIER(ch), Load); + case STRING: { + PyObject *str = parsestrplus(c, n); - if (!str) - return NULL; + if (!str) + return NULL; - return Str(str); - } - case NUMBER: { - PyObject *pynum = parsenumber(STR(ch)); + return Str(str); + } + case NUMBER: { + PyObject *pynum = parsenumber(STR(ch)); - if (!pynum) - return NULL; + if (!pynum) + return NULL; - return Num(pynum); - } - case LPAR: /* some parenthesized expressions */ - return ast_for_testlist(c, CHILD(n, 1)); - case LSQB: /* list (or list comprehension) */ - ch = CHILD(n, 1); - if (TYPE(ch) == RSQB) - return List(NULL, Load); - REQ(ch, listmaker); - if (NCH(ch) == 1 || TYPE(CHILD(ch, 1)) == COMMA) { - asdl_seq *elts = seq_for_testlist(c, ch); + return Num(pynum); + } + case LPAR: /* some parenthesized expressions */ + ch = CHILD(n, 1); - if (!elts) - return NULL; + if (TYPE(ch) == RPAR) + return Tuple(NULL, Load); - return List(elts, Load); - } - else - return ast_for_listcomp(c, ch); - case LBRACE: { - /* dictmaker: test ':' test (',' test ':' test)* [','] */ - int i, size; - asdl_seq *keys, *values; + if ((NCH(ch) > 1) && (TYPE(CHILD(ch, 1)) == gen_for)) + return ast_for_genexp(c, ch); - ch = CHILD(n, 1); - size = (NCH(ch) + 1) / 4; /* plus one in case no trailing comma */ - keys = asdl_seq_new(size); - if (!keys) - return NULL; - values = asdl_seq_new(size); - if (!values) { - asdl_seq_free(keys); - return NULL; - } - for (i = 0; i < NCH(ch); i += 4) { - expr_ty expression; + return ast_for_testlist(c, ch); + case LSQB: /* list (or list comprehension) */ + ch = CHILD(n, 1); - expression = ast_for_expr(c, CHILD(ch, i)); - if (!expression) - return NULL; - - asdl_seq_SET(keys, i / 4, expression); + if (TYPE(ch) == RSQB) + return List(NULL, Load); - expression = ast_for_expr(c, CHILD(ch, i + 2)); - if (!expression) - return NULL; - - asdl_seq_SET(values, i / 4, expression); - } - return Dict(keys, values); - } - case BACKQUOTE: { /* repr */ - expr_ty expression = ast_for_testlist(c, CHILD(n, 1)); + REQ(ch, listmaker); + if (NCH(ch) == 1 || TYPE(CHILD(ch, 1)) == COMMA) { + asdl_seq *elts = seq_for_testlist(c, ch); - if (!expression) - return NULL; + if (!elts) + return NULL; - return Repr(expression); - } - default: - PyErr_Format(PyExc_Exception, "unhandled atom %d", TYPE(ch)); - return NULL; - } + return List(elts, Load); + } + else + return ast_for_listcomp(c, ch); + case LBRACE: { + /* dictmaker: test ':' test (',' test ':' test)* [','] */ + int i, size; + asdl_seq *keys, *values; + + ch = CHILD(n, 1); + size = (NCH(ch) + 1) / 4; /* +1 in case no trailing comma */ + keys = asdl_seq_new(size); + if (!keys) + return NULL; + + values = asdl_seq_new(size); + if (!values) { + asdl_seq_free(keys); + return NULL; + } + + for (i = 0; i < NCH(ch); i += 4) { + expr_ty expression; + + expression = ast_for_expr(c, CHILD(ch, i)); + if (!expression) + return NULL; + + asdl_seq_SET(keys, i / 4, expression); + + expression = ast_for_expr(c, CHILD(ch, i + 2)); + if (!expression) + return NULL; + + asdl_seq_SET(values, i / 4, expression); + } + return Dict(keys, values); + } + case BACKQUOTE: { /* repr */ + expr_ty expression = ast_for_testlist(c, CHILD(n, 1)); + + if (!expression) + return NULL; + + return Repr(expression); + } + default: + PyErr_Format(PyExc_Exception, "unhandled atom %d", + TYPE(ch)); + return NULL; + } } static slice_ty @@ -1451,17 +1626,22 @@ nargs = 0; nkeywords = 0; ngens = 0; - for (i = 0; i < NCH(n); i++) - if (TYPE(CHILD(n, i)) == argument) { - if (NCH(CHILD(n, i)) == 1) + for (i = 0; i < NCH(n); i++) { + node *ch = CHILD(n, i); + if (TYPE(ch) == argument) { + if (NCH(ch) == 1) nargs++; - else if (TYPE(CHILD(CHILD(n, i), 1)) == gen_for) + else if (TYPE(CHILD(ch, 1)) == gen_for) ngens++; else nkeywords++; } - - args = asdl_seq_new(nargs); + } + if (ngens > 1 || (ngens && (nargs || nkeywords))) { + ast_error(n, "Generator expression must be parenthesised if not sole argument"); + return NULL; + } + args = asdl_seq_new(nargs + ngens); if (!args) goto error; keywords = asdl_seq_new(nkeywords); @@ -1479,8 +1659,11 @@ goto error; asdl_seq_SET(args, nargs++, e); } - else if (TYPE(CHILD(CHILD(n, 0), 1)) == gen_for) { - /* XXX handle generator comp */ + else if (TYPE(CHILD(ch, 1)) == gen_for) { + e = ast_for_genexp(c, ch); + if (!e) + goto error; + asdl_seq_SET(args, nargs++, e); } else { keyword_ty kw; Index: compile.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Python/compile.c,v retrieving revision 2.247.2.2 retrieving revision 2.247.2.3 diff -u -d -r2.247.2.2 -r2.247.2.3 --- compile.c 9 Jul 2002 13:22:01 -0000 2.247.2.2 +++ compile.c 13 Apr 2005 19:44:38 -0000 2.247.2.3 @@ -1157,6 +1157,8 @@ return PyLong_FromString(s, (char **)0, 0); if (s[0] == '0') x = (long) PyOS_strtoul(s, &end, 0); + if (x < 0 && errno == 0) + return PyLong_FromString(s, (char **)0, 0); else x = PyOS_strtol(s, &end, 0); if (*end == '\0') { Index: newcompile.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Python/Attic/newcompile.c,v retrieving revision 1.1.2.105 retrieving revision 1.1.2.106 diff -u -d -r1.1.2.105 -r1.1.2.106 --- newcompile.c 2 Apr 2005 18:50:06 -0000 1.1.2.105 +++ newcompile.c 13 Apr 2005 19:44:40 -0000 1.1.2.106 @@ -1388,8 +1388,13 @@ asdl_seq* decos = s->v.FunctionDef.decorators; stmt_ty st; int i, n, docstring; + int was_interactive = c->c_interactive; + assert(s->kind == FunctionDef_kind); + /* turn off interim results from within function calls while in + interactive mode */ + c->c_interactive = 0; if (!compiler_decorators(c, decos)) return 0; if (args->defaults) @@ -1443,6 +1448,9 @@ ADDOP_I(c, CALL_FUNCTION, 1); } + /* turn flag back on if was interactive */ + c->c_interactive = was_interactive; + return compiler_nameop(c, s->v.FunctionDef.name, Store); } @@ -2558,10 +2566,114 @@ } static int -compiler_generatorcomp(struct compiler *c, expr_ty e) +compiler_genexp_generator(struct compiler *c, + asdl_seq *generators, int gen_index, + expr_ty elt) { - /* XXX handle */ + /* generate code for the iterator, then each of the ifs, + and then write to the element */ + + comprehension_ty ge; + basicblock *start, *anchor, *skip, *if_cleanup, *end; + int i, n; + + start = compiler_new_block(c); + skip = compiler_new_block(c); + if_cleanup = compiler_new_block(c); + anchor = compiler_new_block(c); + end = compiler_new_block(c); + + if (start == NULL || skip == NULL || if_cleanup == NULL || + anchor == NULL || end == NULL) + return 0; + + ge = asdl_seq_GET(generators, gen_index); + ADDOP_JREL(c, SETUP_LOOP, end); + if (!compiler_push_fblock(c, LOOP, start)) + return 0; + + if (gen_index == 0) { + /* Receive outermost iter as an implicit argument */ + c->u->u_argcount = 1; + ADDOP_I(c, LOAD_FAST, 0); + } + else { + /* Sub-iter - calculate on the fly */ + VISIT(c, expr, ge->iter); + ADDOP(c, GET_ITER); + } + compiler_use_next_block(c, start); + ADDOP_JREL(c, FOR_ITER, anchor); + NEXT_BLOCK(c); + VISIT(c, expr, ge->target); + + /* XXX this needs to be cleaned up...a lot! */ + n = asdl_seq_LEN(ge->ifs); + for (i = 0; i < n; i++) { + expr_ty e = asdl_seq_GET(ge->ifs, i); + VISIT(c, expr, e); + ADDOP_JREL(c, JUMP_IF_FALSE, if_cleanup); + NEXT_BLOCK(c); + ADDOP(c, POP_TOP); + } + + if (++gen_index < asdl_seq_LEN(generators)) + if (!compiler_genexp_generator(c, generators, gen_index, elt)) + return 0; + + /* only append after the last 'for' generator */ + if (gen_index >= asdl_seq_LEN(generators)) { + VISIT(c, expr, elt); + ADDOP(c, YIELD_VALUE); + + compiler_use_next_block(c, skip); + } + for (i = 0; i < n; i++) { + ADDOP_I(c, JUMP_FORWARD, 1); + if (i == 0) + compiler_use_next_block(c, if_cleanup); + + ADDOP(c, POP_TOP); + } + ADDOP_JABS(c, JUMP_ABSOLUTE, start); + compiler_use_next_block(c, anchor); + ADDOP(c, POP_BLOCK); + compiler_pop_fblock(c, LOOP, start); + compiler_use_next_block(c, end); + + return 1; +} + +static int +compiler_genexp(struct compiler *c, expr_ty e) +{ + PyObject *name; + PyCodeObject *co; + expr_ty outermost_iter = ((comprehension_ty) + (asdl_seq_GET(e->v.GeneratorExp.generators, + 0)))->iter; + + name = PyString_FromString(""); + if (!name) return 0; + + if (!compiler_enter_scope(c, name, (void *)e, c->u->u_lineno)) + return 0; + compiler_genexp_generator(c, e->v.GeneratorExp.generators, 0, + e->v.GeneratorExp.elt); + co = assemble(c, 1); + if (co == NULL) + return 0; + compiler_exit_scope(c); + + compiler_make_closure(c, co, 0); + VISIT(c, expr, outermost_iter); + ADDOP(c, GET_ITER); + ADDOP_I(c, CALL_FUNCTION, 1); + Py_DECREF(name); + Py_DECREF(co); + + return 1; } static int @@ -2626,8 +2738,8 @@ break; case ListComp_kind: return compiler_listcomp(c, e); - case GeneratorComp_kind: - return compiler_generatorcomp(c, e); + case GeneratorExp_kind: + return compiler_genexp(c, e); case Compare_kind: return compiler_compare(c, e); case Call_kind: Index: symtable.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Python/symtable.c,v retrieving revision 2.10.8.31 retrieving revision 2.10.8.32 diff -u -d -r2.10.8.31 -r2.10.8.32 --- symtable.c 2 Apr 2005 18:50:13 -0000 2.10.8.31 +++ symtable.c 13 Apr 2005 19:44:40 -0000 2.10.8.32 @@ -165,6 +165,7 @@ static int symtable_visit_slice(struct symtable *st, slice_ty); static int symtable_visit_params(struct symtable *st, asdl_seq *args, int top); static int symtable_visit_params_nested(struct symtable *st, asdl_seq *args); +static int symtable_implicit_arg(struct symtable *st, int pos); static identifier top = NULL, lambda = NULL; @@ -946,8 +947,7 @@ VISIT_SEQ(st, comprehension, e->v.ListComp.generators); break; } - case GeneratorComp_kind: { - char tmpname[256]; + case GeneratorExp_kind: { identifier tmp; /* XXX this is correct/complete */ @@ -955,8 +955,11 @@ if (!symtable_enter_block(st, tmp, FunctionBlock, (void *)e, 0)) return 0; - VISIT(st, expr, e->v.GeneratorComp.elt); - VISIT_SEQ(st, comprehension, e->v.GeneratorComp.generators); + if (!symtable_implicit_arg(st, 0)) + return 0; + VISIT(st, expr, e->v.GeneratorExp.elt); + VISIT_SEQ(st, comprehension, e->v.GeneratorExp.generators); + st->st_cur->ste_generator = 1; symtable_exit_block(st, (void *)e); break; } Index: compile.txt =================================================================== RCS file: /cvsroot/python/python/dist/src/Python/Attic/compile.txt,v retrieving revision 1.1.2.13 retrieving revision 1.1.2.14 diff -u -d -r1.1.2.13 -r1.1.2.14 --- compile.txt 2 Apr 2005 20:21:23 -0000 1.1.2.13 +++ compile.txt 13 Apr 2005 19:44:40 -0000 1.1.2.14 @@ -447,11 +447,7 @@ + Grammar support (Parser/Python.asdl, Parser/asdl_c.py) - empty base class list (``class Class(): pass``) -+ parse tree->AST support (Python/ast.c) - - generator expressions -+ AST->bytecode support (Python/newcompile.c) - - generator expressions -+ Stdlib support + Stdlib support - AST->Python access? - rewrite compiler package to mirror AST structure? + Documentation @@ -459,8 +455,6 @@ * byte stream output * explanation of how symbol table pass works + Universal - - remove "generator comprehension" mentions and change to "generator - expression" - make sure entire test suite passes - fix memory leaks - make sure return types are properly checked for errors From bcannon at users.sourceforge.net Wed Apr 13 21:45:10 2005 From: bcannon at users.sourceforge.net (bcannon@users.sourceforge.net) Date: Wed Apr 13 21:45:14 2005 Subject: [Python-checkins] python/dist/src/Include Python-ast.h, 1.1.2.11, 1.1.2.12 Message-ID: Update of /cvsroot/python/python/dist/src/Include In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12515/Include Modified Files: Tag: ast-branch Python-ast.h Log Message: Add support for genexps. Required changing the name to GeneratorExp for consistency in Parser/Python.asdl (and subsequent changes to other files because of this), regenerating the Python-ast.(h|c) files, and then the necessary changes to Python/ast.c and Python/newcompile.c . Also includes a tweak to asdl_seq_new() to not call malloc() with a -1 if an empty asdl_seq struct is needed. Lastly, it silences output of the results of functions while they are doing internal calls; allows doctest to work properly. Not thoroughly tested since test_grammar segfaults before it reaches genexps. But hand-testing seems to show everything works. Closes patch #1167628. Thanks Nick Coghlan. Index: Python-ast.h =================================================================== RCS file: /cvsroot/python/python/dist/src/Include/Attic/Python-ast.h,v retrieving revision 1.1.2.11 retrieving revision 1.1.2.12 diff -u -d -r1.1.2.11 -r1.1.2.12 --- Python-ast.h 2 Apr 2005 18:50:05 -0000 1.1.2.11 +++ Python-ast.h 13 Apr 2005 19:44:37 -0000 1.1.2.12 @@ -1,4 +1,4 @@ -/* File automatically generated by ../Parser/asdl_c.py */ +/* File automatically generated by ./Parser/asdl_c.py */ #include "asdl.h" @@ -178,7 +178,7 @@ struct _expr { enum { BoolOp_kind=1, BinOp_kind=2, UnaryOp_kind=3, Lambda_kind=4, - Dict_kind=5, ListComp_kind=6, GeneratorComp_kind=7, + Dict_kind=5, ListComp_kind=6, GeneratorExp_kind=7, Compare_kind=8, Call_kind=9, Repr_kind=10, Num_kind=11, Str_kind=12, Attribute_kind=13, Subscript_kind=14, Name_kind=15, List_kind=16, Tuple_kind=17 } kind; @@ -217,7 +217,7 @@ struct { expr_ty elt; asdl_seq *generators; - } GeneratorComp; + } GeneratorExp; struct { expr_ty left; @@ -362,7 +362,7 @@ expr_ty Lambda(arguments_ty args, expr_ty body); expr_ty Dict(asdl_seq * keys, asdl_seq * values); expr_ty ListComp(expr_ty elt, asdl_seq * generators); -expr_ty GeneratorComp(expr_ty elt, asdl_seq * generators); +expr_ty GeneratorExp(expr_ty elt, asdl_seq * generators); expr_ty Compare(expr_ty left, asdl_seq * ops, asdl_seq * comparators); expr_ty Call(expr_ty func, asdl_seq * args, asdl_seq * keywords, expr_ty starargs, expr_ty kwargs); From bcannon at users.sourceforge.net Wed Apr 13 21:59:24 2005 From: bcannon at users.sourceforge.net (bcannon@users.sourceforge.net) Date: Wed Apr 13 21:59:27 2005 Subject: [Python-checkins] python/dist/src/Parser Python.asdl, 1.1.2.10, 1.1.2.11 asdl_c.py, 1.1.2.6, 1.1.2.7 Message-ID: Update of /cvsroot/python/python/dist/src/Parser In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23001/Parser Modified Files: Tag: ast-branch Python.asdl asdl_c.py Log Message: Last part of checkin to change over from the name "GeneratorComp" to "GeneratorExp". Index: Python.asdl =================================================================== RCS file: /cvsroot/python/python/dist/src/Parser/Attic/Python.asdl,v retrieving revision 1.1.2.10 retrieving revision 1.1.2.11 diff -u -d -r1.1.2.10 -r1.1.2.11 --- Python.asdl 12 Apr 2005 23:19:54 -0000 1.1.2.10 +++ Python.asdl 13 Apr 2005 19:59:20 -0000 1.1.2.11 @@ -54,7 +54,7 @@ | Lambda(arguments args, expr body) | Dict(expr* keys, expr* values) | ListComp(expr elt, comprehension* generators) - | GeneratorComp(expr elt, comprehension* generators) + | GeneratorExp(expr elt, comprehension* generators) -- need sequences for compare to distinguish between -- x < 4 < 3 and (x < 4) < 3 | Compare(expr left, cmpop* ops, expr* comparators) Index: asdl_c.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Parser/Attic/asdl_c.py,v retrieving revision 1.1.2.6 retrieving revision 1.1.2.7 diff -u -d -r1.1.2.6 -r1.1.2.7 --- asdl_c.py 2 Apr 2005 18:50:05 -0000 1.1.2.6 +++ asdl_c.py 13 Apr 2005 19:59:20 -0000 1.1.2.7 @@ -45,7 +45,7 @@ while len(cur) > size: i = cur.rfind(' ', 0, size) # XXX this should be fixed for real - if i == -1 and 'GeneratorComp' in cur: + if i == -1 and 'GeneratorExp' in cur: i = size + 3 assert i != -1, "Impossible line %d to reflow: %s" % (size, `s`) lines.append(padding + cur[:i]) From rhettinger at users.sourceforge.net Thu Apr 14 00:04:26 2005 From: rhettinger at users.sourceforge.net (rhettinger@users.sourceforge.net) Date: Thu Apr 14 00:04:30 2005 Subject: [Python-checkins] python/dist/src/Misc developers.txt,1.9,1.10 Message-ID: Update of /cvsroot/python/python/dist/src/Misc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25125 Modified Files: developers.txt Log Message: Update permissions for Finn Bock. Index: developers.txt =================================================================== RCS file: /cvsroot/python/python/dist/src/Misc/developers.txt,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- developers.txt 11 Apr 2005 03:11:11 -0000 1.9 +++ developers.txt 13 Apr 2005 22:04:21 -0000 1.10 @@ -37,6 +37,8 @@ Permissions Dropped on Request ------------------------------ +- Finn Bock sent a drop request. 13 Apr 2005 RDH + - Eric Price sent a drop request. 10 Apr 2005 RDH - Irmen de Jong requested dropping CVS access while keeping tracker From doerwalter at users.sourceforge.net Thu Apr 14 22:09:04 2005 From: doerwalter at users.sourceforge.net (doerwalter@users.sourceforge.net) Date: Thu Apr 14 22:09:07 2005 Subject: [Python-checkins] python/dist/src/Doc/lib libfunctional.tex, 1.3, 1.4 libsubprocess.tex, 1.5, 1.6 Message-ID: Update of /cvsroot/python/python/dist/src/Doc/lib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10510/Doc/lib Modified Files: libfunctional.tex libsubprocess.tex Log Message: SF patch #1180062 by George Yoshida: Doc/lib/libfunctional.tex: "in an new object" should read "in a new object" Doc/lib/libsubprocess.tex: argument name is wrong; comma is missing. Index: libfunctional.tex =================================================================== RCS file: /cvsroot/python/python/dist/src/Doc/lib/libfunctional.tex,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- libfunctional.tex 8 Mar 2005 07:15:36 -0000 1.3 +++ libfunctional.tex 14 Apr 2005 20:09:00 -0000 1.4 @@ -38,7 +38,7 @@ The \function{partial} is used for partial function application which ``freezes'' some portion of a function's arguments and/or keywords -resulting in an new object with a simplified signature. For example, +resulting in a new object with a simplified signature. For example, \function{partial} can be used to create a callable that behaves like the \function{int} function where the \var{base} argument defaults to two: Index: libsubprocess.tex =================================================================== RCS file: /cvsroot/python/python/dist/src/Doc/lib/libsubprocess.tex,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- libsubprocess.tex 1 Jan 2005 09:36:35 -0000 1.5 +++ libsubprocess.tex 14 Apr 2005 20:09:00 -0000 1.6 @@ -189,7 +189,7 @@ \begin{methoddesc}{communicate}{input=None} Interact with process: Send data to stdin. Read data from stdout and stderr, until end-of-file is reached. Wait for process to terminate. -The optional \var{stdin} argument should be a string to be sent to the +The optional \var{input} argument should be a string to be sent to the child process, or \code{None}, if no data should be sent to the child. communicate() returns a tuple (stdout, stderr). @@ -374,7 +374,7 @@ \begin{verbatim} (child_stdout, child_stdin) = popen2.popen2("somestring", bufsize, mode) ==> -p = Popen(["somestring"], shell=True, bufsize=bufsize +p = Popen(["somestring"], shell=True, bufsize=bufsize, stdin=PIPE, stdout=PIPE, close_fds=True) (child_stdout, child_stdin) = (p.stdout, p.stdin) \end{verbatim} From doerwalter at users.sourceforge.net Thu Apr 14 22:23:41 2005 From: doerwalter at users.sourceforge.net (doerwalter@users.sourceforge.net) Date: Thu Apr 14 22:23:45 2005 Subject: [Python-checkins] python/dist/src/Doc/lib libsubprocess.tex, 1.2.2.1, 1.2.2.2 Message-ID: Update of /cvsroot/python/python/dist/src/Doc/lib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17800/Doc/lib Modified Files: Tag: release24-maint libsubprocess.tex Log Message: Backport relevant part of checkin: SF patch #1180062 by George Yoshida: (Doc/lib/libfunctional.tex: "in an new object" should read "in a new object") Doc/lib/libsubprocess.tex: argument name is wrong; comma is missing Index: libsubprocess.tex =================================================================== RCS file: /cvsroot/python/python/dist/src/Doc/lib/libsubprocess.tex,v retrieving revision 1.2.2.1 retrieving revision 1.2.2.2 diff -u -d -r1.2.2.1 -r1.2.2.2 --- libsubprocess.tex 30 Nov 2004 18:11:36 -0000 1.2.2.1 +++ libsubprocess.tex 14 Apr 2005 20:23:39 -0000 1.2.2.2 @@ -173,7 +173,7 @@ \begin{methoddesc}{communicate}{input=None} Interact with process: Send data to stdin. Read data from stdout and stderr, until end-of-file is reached. Wait for process to terminate. -The optional \var{stdin} argument should be a string to be sent to the +The optional \var{input} argument should be a string to be sent to the child process, or \code{None}, if no data should be sent to the child. communicate() returns a tuple (stdout, stderr). @@ -358,7 +358,7 @@ \begin{verbatim} (child_stdout, child_stdin) = popen2.popen2("somestring", bufsize, mode) ==> -p = Popen(["somestring"], shell=True, bufsize=bufsize +p = Popen(["somestring"], shell=True, bufsize=bufsize, stdin=PIPE, stdout=PIPE, close_fds=True) (child_stdout, child_stdin) = (p.stdout, p.stdin) \end{verbatim} From nascheme at users.sourceforge.net Fri Apr 15 03:49:27 2005 From: nascheme at users.sourceforge.net (nascheme@users.sourceforge.net) Date: Fri Apr 15 03:49:31 2005 Subject: [Python-checkins] python/dist/src/Python newcompile.c, 1.1.2.106, 1.1.2.107 Message-ID: Update of /cvsroot/python/python/dist/src/Python In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27593/Python Modified Files: Tag: ast-branch newcompile.c Log Message: Fix test for interactive printing of expressions. They should be only printed at the top-level. Index: newcompile.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Python/Attic/newcompile.c,v retrieving revision 1.1.2.106 retrieving revision 1.1.2.107 diff -u -d -r1.1.2.106 -r1.1.2.107 --- newcompile.c 13 Apr 2005 19:44:40 -0000 1.1.2.106 +++ newcompile.c 15 Apr 2005 01:49:23 -0000 1.1.2.107 @@ -1388,13 +1388,9 @@ asdl_seq* decos = s->v.FunctionDef.decorators; stmt_ty st; int i, n, docstring; - int was_interactive = c->c_interactive; assert(s->kind == FunctionDef_kind); - /* turn off interim results from within function calls while in - interactive mode */ - c->c_interactive = 0; if (!compiler_decorators(c, decos)) return 0; if (args->defaults) @@ -1448,9 +1444,6 @@ ADDOP_I(c, CALL_FUNCTION, 1); } - /* turn flag back on if was interactive */ - c->c_interactive = was_interactive; - return compiler_nameop(c, s->v.FunctionDef.name, Store); } @@ -2092,7 +2085,7 @@ break; case Expr_kind: VISIT(c, expr, s->v.Expr.value); - if (c->c_interactive) { + if (c->c_interactive && c->c_nestlevel <= 1) { ADDOP(c, PRINT_EXPR); } else { From nascheme at users.sourceforge.net Fri Apr 15 04:11:26 2005 From: nascheme at users.sourceforge.net (nascheme@users.sourceforge.net) Date: Fri Apr 15 04:11:29 2005 Subject: [Python-checkins] python/dist/src/Python asdl.c,1.1.2.6,1.1.2.7 Message-ID: Update of /cvsroot/python/python/dist/src/Python In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4617/Python Modified Files: Tag: ast-branch asdl.c Log Message: Initialize asdl_seq with NULLs. That makes error handling easier since the sequence may be partly filled when an error occurs. Index: asdl.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Python/Attic/asdl.c,v retrieving revision 1.1.2.6 retrieving revision 1.1.2.7 diff -u -d -r1.1.2.6 -r1.1.2.7 --- asdl.c 13 Apr 2005 19:44:37 -0000 1.1.2.6 +++ asdl.c 15 Apr 2005 02:11:24 -0000 1.1.2.7 @@ -5,16 +5,16 @@ asdl_seq_new(int size) { asdl_seq *seq = NULL; + size_t n = sizeof(asdl_seq) + + (size ? (sizeof(void *) * (size - 1)) : 0); - seq = (asdl_seq *)PyObject_Malloc(sizeof(asdl_seq) - + (size ? (sizeof(void *) * (size - 1)) : 0)); - + seq = (asdl_seq *)PyObject_Malloc(n); if (!seq) { PyErr_SetString(PyExc_MemoryError, "no memory"); return NULL; } + memset(seq, 0, n); seq->size = size; - seq->offset = 0; return seq; } From nascheme at users.sourceforge.net Fri Apr 15 04:18:27 2005 From: nascheme at users.sourceforge.net (nascheme@users.sourceforge.net) Date: Fri Apr 15 04:18:30 2005 Subject: [Python-checkins] python/dist/src/Parser grammar.mak, 1.3.2.1, 1.3.2.2 Message-ID: Update of /cvsroot/python/python/dist/src/Parser In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7321/Parser Modified Files: Tag: ast-branch grammar.mak Log Message: Implement the new 'class foo(): pass' syntax. Tweak the grammar.mak file so graminit.c can be built on Windows machines. Closes SF patch #1176019. Index: grammar.mak =================================================================== RCS file: /cvsroot/python/python/dist/src/Parser/grammar.mak,v retrieving revision 1.3.2.1 retrieving revision 1.3.2.2 diff -u -d -r1.3.2.1 -r1.3.2.2 --- grammar.mak 7 Jan 2005 07:04:34 -0000 1.3.2.1 +++ grammar.mak 15 Apr 2005 02:18:24 -0000 1.3.2.2 @@ -15,7 +15,7 @@ # particular case --pragma in PC\pyconfig.h, which demands that # python23.lib get linked in). -LIBS= ..\PCbuild\python23.lib +LIBS= ..\PCbuild\python25.lib CFLAGS= /I ..\Include /I ..\PC /D MS_NO_COREDLL /D PGEN /MD From nascheme at users.sourceforge.net Fri Apr 15 04:18:27 2005 From: nascheme at users.sourceforge.net (nascheme@users.sourceforge.net) Date: Fri Apr 15 04:18:30 2005 Subject: [Python-checkins] python/dist/src/Python graminit.c, 2.33.2.2, 2.33.2.3 ast.c, 1.1.2.59, 1.1.2.60 Message-ID: Update of /cvsroot/python/python/dist/src/Python In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7321/Python Modified Files: Tag: ast-branch graminit.c ast.c Log Message: Implement the new 'class foo(): pass' syntax. Tweak the grammar.mak file so graminit.c can be built on Windows machines. Closes SF patch #1176019. Index: graminit.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Python/graminit.c,v retrieving revision 2.33.2.2 retrieving revision 2.33.2.3 diff -u -d -r2.33.2.2 -r2.33.2.3 --- graminit.c 7 Jan 2005 07:04:39 -0000 2.33.2.2 +++ graminit.c 15 Apr 2005 02:18:23 -0000 2.33.2.3 @@ -1426,26 +1426,27 @@ {13, 3}, {21, 4}, }; -static arc arcs_67_3[1] = { +static arc arcs_67_3[2] = { {9, 5}, + {15, 6}, }; static arc arcs_67_4[1] = { - {22, 6}, + {22, 7}, }; static arc arcs_67_5[1] = { - {15, 7}, + {15, 6}, }; static arc arcs_67_6[1] = { - {0, 6}, + {21, 4}, }; static arc arcs_67_7[1] = { - {21, 4}, + {0, 7}, }; static state states_67[8] = { {1, arcs_67_0}, {1, arcs_67_1}, {2, arcs_67_2}, - {1, arcs_67_3}, + {2, arcs_67_3}, {1, arcs_67_4}, {1, arcs_67_5}, {1, arcs_67_6}, Index: ast.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Python/Attic/ast.c,v retrieving revision 1.1.2.59 retrieving revision 1.1.2.60 diff -u -d -r1.1.2.59 -r1.1.2.60 --- ast.c 13 Apr 2005 19:44:37 -0000 1.1.2.59 +++ ast.c 15 Apr 2005 02:18:24 -0000 1.1.2.60 @@ -2576,6 +2576,13 @@ return NULL; return ClassDef(NEW_IDENTIFIER(CHILD(n, 1)), NULL, s, LINENO(n)); } + /* check for empty base list */ + if (TYPE(CHILD(n,3)) == RPAR) { + s = ast_for_suite(c, CHILD(n,5)); + if (!s) + return NULL; + return ClassDef(NEW_IDENTIFIER(CHILD(n, 1)),NULL,s,LINENO(n)); + } /* else handle the base class list */ _bases = ast_for_testlist(c, CHILD(n, 3)); if (!_bases) From nascheme at users.sourceforge.net Fri Apr 15 04:18:28 2005 From: nascheme at users.sourceforge.net (nascheme@users.sourceforge.net) Date: Fri Apr 15 04:18:31 2005 Subject: [Python-checkins] python/dist/src/Grammar Grammar, 1.47.2.2, 1.47.2.3 Message-ID: Update of /cvsroot/python/python/dist/src/Grammar In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7321/Grammar Modified Files: Tag: ast-branch Grammar Log Message: Implement the new 'class foo(): pass' syntax. Tweak the grammar.mak file so graminit.c can be built on Windows machines. Closes SF patch #1176019. Index: Grammar =================================================================== RCS file: /cvsroot/python/python/dist/src/Grammar/Grammar,v retrieving revision 1.47.2.2 retrieving revision 1.47.2.3 diff -u -d -r1.47.2.2 -r1.47.2.3 --- Grammar 7 Jan 2005 06:57:41 -0000 1.47.2.2 +++ Grammar 15 Apr 2005 02:18:25 -0000 1.47.2.3 @@ -99,7 +99,7 @@ testlist_safe: test [(',' test)+ [',']] dictmaker: test ':' test (',' test ':' test)* [','] -classdef: 'class' NAME ['(' testlist ')'] ':' suite +classdef: 'class' NAME ['(' [testlist] ')'] ':' suite arglist: (argument ',')* (argument [',']| '*' test [',' '**' test] | '**' test) argument: [test '='] test [gen_for] # Really [keyword '='] test From anthonybaxter at users.sourceforge.net Fri Apr 15 08:17:23 2005 From: anthonybaxter at users.sourceforge.net (anthonybaxter@users.sourceforge.net) Date: Fri Apr 15 08:17:25 2005 Subject: [Python-checkins] python/dist/src/Lib/distutils/command bdist_rpm.py, 1.51, 1.52 Message-ID: Update of /cvsroot/python/python/dist/src/Lib/distutils/command In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31367/command Modified Files: bdist_rpm.py Log Message: typo fix, thanks Jeremy Sanders Index: bdist_rpm.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Lib/distutils/command/bdist_rpm.py,v retrieving revision 1.51 retrieving revision 1.52 diff -u -d -r1.51 -r1.52 --- bdist_rpm.py 28 Mar 2005 01:05:48 -0000 1.51 +++ bdist_rpm.py 15 Apr 2005 06:17:20 -0000 1.52 @@ -298,7 +298,7 @@ # Make a source distribution and copy to SOURCES directory with # optional icon. - saved_dist_files = self.distributuion.dist_files[:] + saved_dist_files = self.distribution.dist_files[:] sdist = self.reinitialize_command('sdist') if self.use_bzip2: sdist.formats = ['bztar'] From rhettinger at users.sourceforge.net Fri Apr 15 17:58:46 2005 From: rhettinger at users.sourceforge.net (rhettinger@users.sourceforge.net) Date: Fri Apr 15 17:58:50 2005 Subject: [Python-checkins] python/dist/src/Objects dictobject.c,2.163,2.164 Message-ID: Update of /cvsroot/python/python/dist/src/Objects In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10801 Modified Files: dictobject.c Log Message: SF bug #1183742: PyDict_Copy() can return non-NULL value on error Index: dictobject.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Objects/dictobject.c,v retrieving revision 2.163 retrieving revision 2.164 diff -u -d -r2.163 -r2.164 --- dictobject.c 5 Feb 2005 23:42:57 -0000 2.163 +++ dictobject.c 15 Apr 2005 15:58:42 -0000 2.164 @@ -1291,7 +1291,7 @@ if (PyDict_Merge(copy, o, 1) == 0) return copy; Py_DECREF(copy); - return copy; + return NULL; } int From rhettinger at users.sourceforge.net Fri Apr 15 18:07:12 2005 From: rhettinger at users.sourceforge.net (rhettinger@users.sourceforge.net) Date: Fri Apr 15 18:07:15 2005 Subject: [Python-checkins] python/dist/src/Objects dictobject.c, 2.162, 2.162.4.1 Message-ID: Update of /cvsroot/python/python/dist/src/Objects In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14038 Modified Files: Tag: release24-maint dictobject.c Log Message: SF bug #1183742: PyDict_Copy() can return non-NULL value on error Index: dictobject.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Objects/dictobject.c,v retrieving revision 2.162 retrieving revision 2.162.4.1 diff -u -d -r2.162 -r2.162.4.1 --- dictobject.c 15 Jul 2004 15:54:04 -0000 2.162 +++ dictobject.c 15 Apr 2005 16:07:09 -0000 2.162.4.1 @@ -1289,7 +1289,7 @@ if (PyDict_Merge(copy, o, 1) == 0) return copy; Py_DECREF(copy); - return copy; + return NULL; } int From bcannon at users.sourceforge.net Fri Apr 15 22:32:43 2005 From: bcannon at users.sourceforge.net (bcannon@users.sourceforge.net) Date: Fri Apr 15 22:32:46 2005 Subject: [Python-checkins] python/dist/src setup.py,1.216,1.217 Message-ID: Update of /cvsroot/python/python/dist/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28803 Modified Files: setup.py Log Message: Fix building of spwd; was incorrectly checking for the needed HAVE_* values to properly build the module. Also moved up the creation of config_h_vars (from distutils.sysconfig.parse_config_h()) higher on up in detect_modules() so that it can be used sooner). Index: setup.py =================================================================== RCS file: /cvsroot/python/python/dist/src/setup.py,v retrieving revision 1.216 retrieving revision 1.217 diff -u -d -r1.216 -r1.217 --- setup.py 9 Mar 2005 22:21:08 -0000 1.216 +++ setup.py 15 Apr 2005 20:32:39 -0000 1.217 @@ -295,6 +295,9 @@ inc_dirs = self.compiler.include_dirs + ['/usr/include'] exts = [] + config_h = sysconfig.get_config_h_filename() + config_h_vars = sysconfig.parse_config_h(open(config_h)) + platform = self.get_platform() (srcdir,) = sysconfig.get_config_vars('srcdir') @@ -391,8 +394,8 @@ # grp(3) exts.append( Extension('grp', ['grpmodule.c']) ) # spwd, shadow passwords - if (sysconfig.get_config_var('HAVE_GETSPNAM') or - sysconfig.get_config_var('HAVE_GETSPENT')): + if (config_h_vars.get('HAVE_GETSPNAM', False) or + config_h_vars.get('HAVE_GETSPENT', False)): exts.append( Extension('spwd', ['spwdmodule.c']) ) # select(2); not on ancient System V exts.append( Extension('select', ['selectmodule.c']) ) @@ -785,8 +788,6 @@ ('BYTEORDER', xmlbo), ('XML_CONTEXT_BYTES','1024'), ] - config_h = sysconfig.get_config_h_filename() - config_h_vars = sysconfig.parse_config_h(open(config_h)) for feature_macro in ['HAVE_MEMMOVE', 'HAVE_BCOPY']: if config_h_vars.has_key(feature_macro): define_macros.append((feature_macro, '1')) From jackjansen at users.sourceforge.net Sun Apr 17 23:30:59 2005 From: jackjansen at users.sourceforge.net (jackjansen@users.sourceforge.net) Date: Sun Apr 17 23:31:02 2005 Subject: [Python-checkins] python/dist/src/Mac/OSX/Doc README, NONE, 1.1 setup.py, 1.5, 1.6 Message-ID: Update of /cvsroot/python/python/dist/src/Mac/OSX/Doc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12125 Modified Files: setup.py Added Files: README Log Message: Updated to work with current Python docs setup, and added a minimal README. --- NEW FILE: README --- In this directory you can build the Python documentation in a form that is suitable for access with Apple Help Viewer. This will enable the "Python Documentation" menu entries in the MacPython IDE Help menu. Unfortunately the procedure to build the docs is not very streamlined. First, edit setup.py. At the top, edit MAJOR_VERSION and MINOR_VERSION, and check that DESTDIR makes sense. The documentation will be installed inside PythonIDE.app. In DocBuild.initialize_options, set self.download to True if you want to download the docs. Set it to False if you want to build the docs from the source tree, but this requires LaTex and lots of other stuff. Doable, but not easy. Second, if you want to download the docs you may need to do a couple more edits. The way the docs are packaged will often change between major releases. Fiddle DocBuild.downloadDocs to make it do the right thing (download the docs from python.org, unpack them, rename the directory to "build/html"). After these edits you should be ready to roll. "pythonw setup.py build" should download and unpack (or build) the docs. Next, it will do some magic to make the docs indexable. Finally, it will run the Apple Help Indexing Tool. (This last step is the reason you must use "pythonw" as opposed to "python"). Usually it will time out while waiting for AHIT to do its work. Wait until AHIT is done. Now you're ready to install with "python setup.py install". After this is done test your work. Fire up PythonIDE, and check that Help->Python Documentation brings up the documentation in the Help Viewer. Also open an IDE edit window, type something like "import sys", select "import", and use Help->Lookup in Python Documentation to check that the index has been generated correctly. Index: setup.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Mac/OSX/Doc/setup.py,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- setup.py 18 Jul 2004 05:58:13 -0000 1.5 +++ setup.py 17 Apr 2005 21:30:55 -0000 1.6 @@ -28,13 +28,17 @@ import Carbon.File import time +MAJOR_VERSION='2.4' +MINOR_VERSION='2.4.1' +DESTDIR='/Applications/MacPython-%s/PythonIDE.app/Contents/Resources/English.lproj/PythonDocumentation' % MAJOR_VERSION + class DocBuild(build): def initialize_options(self): build.initialize_options(self) self.build_html = None self.build_dest = None - self.download = 0 - self.doc_version = '2.3b1' # Only needed if download is true + self.download = 1 + self.doc_version = MINOR_VERSION # Only needed if download is true def finalize_options(self): build.finalize_options(self) @@ -48,20 +52,22 @@ def downloadDocs(self): workdir = os.getcwd() - url = 'http://www.python.org/ftp/python/doc/%s/html-%s.tgz' % \ + # XXX Note: the next strings may change from version to version + url = 'http://www.python.org/ftp/python/doc/%s/html-%s.tar.bz2' % \ (self.doc_version,self.doc_version) + tarfile = 'html-%s.tar.bz2' % self.doc_version + dirname = 'Python-Docs-%s' % self.doc_version + + if os.path.exists(self.build_html): + raise RuntimeError, '%s: already exists, please remove and try again' % self.build_html os.chdir(self.build_base) self.spawn('curl','-O', url) + self.spawn('tar', '-xjf', tarfile) + os.rename(dirname, 'html') os.chdir(workdir) - tarfile = 'html-%s.tgz' % self.doc_version -## This no longer works due to name changes -## self.mkpath(self.build_html) -## os.chdir(self.build_html) -## self.spawn('tar', '-xzf', '../' + tarfile) -## os.chdir(workdir) - print "** Please unpack %s" % os.path.join(self.build_base, tarfile) - print "** Unpack the files into %s" % self.build_html - raise RuntimeError, "You need to unpack the docs manually" +## print "** Please unpack %s" % os.path.join(self.build_base, tarfile) +## print "** Unpack the files into %s" % self.build_html +## raise RuntimeError, "You need to unpack the docs manually" def buildDocsFromSource(self): srcdir = '../../..' @@ -173,7 +179,7 @@ build_cmd = self.get_finalized_command('build') self.build_dest = build_cmd.build_dest if self.install_doc == None: - self.install_doc = os.path.join(self.prefix, 'Resources/Python.app/Contents/Resources/English.lproj/PythonDocumentation') + self.install_doc = os.path.join(self.prefix, DESTDIR) print 'INSTALL', self.build_dest, '->', self.install_doc def run(self): From jackjansen at users.sourceforge.net Sun Apr 17 23:32:01 2005 From: jackjansen at users.sourceforge.net (jackjansen@users.sourceforge.net) Date: Sun Apr 17 23:32:05 2005 Subject: [Python-checkins] python/dist/src/Mac/OSX/Doc README, NONE, 1.1.2.1 setup.py, 1.5, 1.5.4.1 Message-ID: Update of /cvsroot/python/python/dist/src/Mac/OSX/Doc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13118 Modified Files: Tag: release24-maint setup.py Added Files: Tag: release24-maint README Log Message: Backport: Updated to work with current Python docs setup, and added a minimal README. --- NEW FILE: README --- In this directory you can build the Python documentation in a form that is suitable for access with Apple Help Viewer. This will enable the "Python Documentation" menu entries in the MacPython IDE Help menu. Unfortunately the procedure to build the docs is not very streamlined. First, edit setup.py. At the top, edit MAJOR_VERSION and MINOR_VERSION, and check that DESTDIR makes sense. The documentation will be installed inside PythonIDE.app. In DocBuild.initialize_options, set self.download to True if you want to download the docs. Set it to False if you want to build the docs from the source tree, but this requires LaTex and lots of other stuff. Doable, but not easy. Second, if you want to download the docs you may need to do a couple more edits. The way the docs are packaged will often change between major releases. Fiddle DocBuild.downloadDocs to make it do the right thing (download the docs from python.org, unpack them, rename the directory to "build/html"). After these edits you should be ready to roll. "pythonw setup.py build" should download and unpack (or build) the docs. Next, it will do some magic to make the docs indexable. Finally, it will run the Apple Help Indexing Tool. (This last step is the reason you must use "pythonw" as opposed to "python"). Usually it will time out while waiting for AHIT to do its work. Wait until AHIT is done. Now you're ready to install with "python setup.py install". After this is done test your work. Fire up PythonIDE, and check that Help->Python Documentation brings up the documentation in the Help Viewer. Also open an IDE edit window, type something like "import sys", select "import", and use Help->Lookup in Python Documentation to check that the index has been generated correctly. Index: setup.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Mac/OSX/Doc/setup.py,v retrieving revision 1.5 retrieving revision 1.5.4.1 diff -u -d -r1.5 -r1.5.4.1 --- setup.py 18 Jul 2004 05:58:13 -0000 1.5 +++ setup.py 17 Apr 2005 21:31:58 -0000 1.5.4.1 @@ -28,13 +28,17 @@ import Carbon.File import time +MAJOR_VERSION='2.4' +MINOR_VERSION='2.4.1' +DESTDIR='/Applications/MacPython-%s/PythonIDE.app/Contents/Resources/English.lproj/PythonDocumentation' % MAJOR_VERSION + class DocBuild(build): def initialize_options(self): build.initialize_options(self) self.build_html = None self.build_dest = None - self.download = 0 - self.doc_version = '2.3b1' # Only needed if download is true + self.download = 1 + self.doc_version = MINOR_VERSION # Only needed if download is true def finalize_options(self): build.finalize_options(self) @@ -48,20 +52,22 @@ def downloadDocs(self): workdir = os.getcwd() - url = 'http://www.python.org/ftp/python/doc/%s/html-%s.tgz' % \ + # XXX Note: the next strings may change from version to version + url = 'http://www.python.org/ftp/python/doc/%s/html-%s.tar.bz2' % \ (self.doc_version,self.doc_version) + tarfile = 'html-%s.tar.bz2' % self.doc_version + dirname = 'Python-Docs-%s' % self.doc_version + + if os.path.exists(self.build_html): + raise RuntimeError, '%s: already exists, please remove and try again' % self.build_html os.chdir(self.build_base) self.spawn('curl','-O', url) + self.spawn('tar', '-xjf', tarfile) + os.rename(dirname, 'html') os.chdir(workdir) - tarfile = 'html-%s.tgz' % self.doc_version -## This no longer works due to name changes -## self.mkpath(self.build_html) -## os.chdir(self.build_html) -## self.spawn('tar', '-xzf', '../' + tarfile) -## os.chdir(workdir) - print "** Please unpack %s" % os.path.join(self.build_base, tarfile) - print "** Unpack the files into %s" % self.build_html - raise RuntimeError, "You need to unpack the docs manually" +## print "** Please unpack %s" % os.path.join(self.build_base, tarfile) +## print "** Unpack the files into %s" % self.build_html +## raise RuntimeError, "You need to unpack the docs manually" def buildDocsFromSource(self): srcdir = '../../..' @@ -173,7 +179,7 @@ build_cmd = self.get_finalized_command('build') self.build_dest = build_cmd.build_dest if self.install_doc == None: - self.install_doc = os.path.join(self.prefix, 'Resources/Python.app/Contents/Resources/English.lproj/PythonDocumentation') + self.install_doc = os.path.join(self.prefix, DESTDIR) print 'INSTALL', self.build_dest, '->', self.install_doc def run(self): From mwh at users.sourceforge.net Mon Apr 18 10:46:19 2005 From: mwh at users.sourceforge.net (mwh@users.sourceforge.net) Date: Mon Apr 18 10:46:22 2005 Subject: [Python-checkins] python/dist/src/Misc NEWS,1.1284,1.1285 Message-ID: Update of /cvsroot/python/python/dist/src/Misc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26324/Misc Modified Files: NEWS Log Message: Fix: [ 1176893 ] Readline segfault by unsilly-ing PyGILState_Release(). Backport candidate. Index: NEWS =================================================================== RCS file: /cvsroot/python/python/dist/src/Misc/NEWS,v retrieving revision 1.1284 retrieving revision 1.1285 diff -u -d -r1.1284 -r1.1285 --- NEWS 9 Apr 2005 10:53:34 -0000 1.1284 +++ NEWS 18 Apr 2005 08:46:07 -0000 1.1285 @@ -12,6 +12,12 @@ Core and builtins ----------------- +- It is now safe to call PyGILState_Release() before + PyEval_InitThreads() (note that if there is reason to believe there + are multiple threads around you still must call PyEval_InitThreads() + before using the Python API; this fix is for extension modules that + have no way of knowing if Python is multi-threaded yet). + - Typing Ctrl-C whilst raw_input() was waiting in a build with threads disabled caused a crash. From mwh at users.sourceforge.net Mon Apr 18 10:46:19 2005 From: mwh at users.sourceforge.net (mwh@users.sourceforge.net) Date: Mon Apr 18 10:46:24 2005 Subject: [Python-checkins] python/dist/src/Python pystate.c,2.39,2.40 Message-ID: Update of /cvsroot/python/python/dist/src/Python In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26324/Python Modified Files: pystate.c Log Message: Fix: [ 1176893 ] Readline segfault by unsilly-ing PyGILState_Release(). Backport candidate. Index: pystate.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Python/pystate.c,v retrieving revision 2.39 retrieving revision 2.40 diff -u -d -r2.39 -r2.40 --- pystate.c 8 Feb 2005 02:07:57 -0000 2.39 +++ pystate.c 18 Apr 2005 08:46:17 -0000 2.40 @@ -503,6 +503,6 @@ } /* Release the lock if necessary */ else if (oldstate == PyGILState_UNLOCKED) - PyEval_ReleaseThread(tcur); + PyEval_SaveThread(); } #endif /* WITH_THREAD */ From rhettinger at users.sourceforge.net Tue Apr 19 06:29:46 2005 From: rhettinger at users.sourceforge.net (rhettinger@users.sourceforge.net) Date: Tue Apr 19 06:29:50 2005 Subject: [Python-checkins] python/dist/src/Doc/lib libstdtypes.tex, 1.176, 1.177 Message-ID: Update of /cvsroot/python/python/dist/src/Doc/lib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2424 Modified Files: libstdtypes.tex Log Message: Correct swapped descriptions of empty string splits. Index: libstdtypes.tex =================================================================== RCS file: /cvsroot/python/python/dist/src/Doc/lib/libstdtypes.tex,v retrieving revision 1.176 retrieving revision 1.177 diff -u -d -r1.176 -r1.177 --- libstdtypes.tex 10 Apr 2005 17:32:35 -0000 1.176 +++ libstdtypes.tex 19 Apr 2005 04:29:44 -0000 1.177 @@ -764,7 +764,7 @@ returns \samp{['1', '', '2']}). The \var{sep} argument may consist of multiple characters (for example, \samp{'1, 2, 3'.split(', ')} returns \samp{['1', '2', '3']}). Splitting an empty string with a specified -separator returns an empty list. +separator returns \samp{['']}. If \var{sep} is not specified or is \code{None}, a different splitting algorithm is applied. First, whitespace characters (spaces, tabs, @@ -773,7 +773,7 @@ characters. Consecutive whitespace delimiters are treated as a single delimiter (\samp{'1 2 3'.split()} returns \samp{['1', '2', '3']}). Splitting an empty string or a string consisting of just whitespace -will return \samp{['']}. +returns an empty list. \end{methoddesc} \begin{methoddesc}[string]{splitlines}{\optional{keepends}} From rhettinger at users.sourceforge.net Tue Apr 19 06:31:40 2005 From: rhettinger at users.sourceforge.net (rhettinger@users.sourceforge.net) Date: Tue Apr 19 06:31:48 2005 Subject: [Python-checkins] python/dist/src/Doc/lib libstdtypes.tex, 1.170.2.6, 1.170.2.7 Message-ID: Update of /cvsroot/python/python/dist/src/Doc/lib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3942 Modified Files: Tag: release24-maint libstdtypes.tex Log Message: Correct swapped descriptions of empty string splits. Index: libstdtypes.tex =================================================================== RCS file: /cvsroot/python/python/dist/src/Doc/lib/libstdtypes.tex,v retrieving revision 1.170.2.6 retrieving revision 1.170.2.7 diff -u -d -r1.170.2.6 -r1.170.2.7 --- libstdtypes.tex 10 Apr 2005 17:36:26 -0000 1.170.2.6 +++ libstdtypes.tex 19 Apr 2005 04:31:38 -0000 1.170.2.7 @@ -764,7 +764,7 @@ returns \samp{['1', '', '2']}). The \var{sep} argument may consist of multiple characters (for example, \samp{'1, 2, 3'.split(', ')} returns \samp{['1', '2', '3']}). Splitting an empty string with a specified -separator returns an empty list. +separator returns \samp{['']}. If \var{sep} is not specified or is \code{None}, a different splitting algorithm is applied. First, whitespace characters (spaces, tabs, @@ -773,7 +773,7 @@ characters. Consecutive whitespace delimiters are treated as a single delimiter (\samp{'1 2 3'.split()} returns \samp{['1', '2', '3']}). Splitting an empty string or a string consisting of just whitespace -will return \samp{['']}. +returns an empty list. \end{methoddesc} \begin{methoddesc}[string]{splitlines}{\optional{keepends}} From bcannon at users.sourceforge.net Tue Apr 19 07:42:18 2005 From: bcannon at users.sourceforge.net (bcannon@users.sourceforge.net) Date: Tue Apr 19 07:42:22 2005 Subject: [Python-checkins] python/dist/src/Python compile.txt, 1.1.2.14, 1.1.2.15 Message-ID: Update of /cvsroot/python/python/dist/src/Python In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9424/Python Modified Files: Tag: ast-branch compile.txt Log Message: Add a note to remind people to clear out old .py(c|o) files if a change is made that will modify how bytecode was outputted previously. Index: compile.txt =================================================================== RCS file: /cvsroot/python/python/dist/src/Python/Attic/compile.txt,v retrieving revision 1.1.2.14 retrieving revision 1.1.2.15 diff -u -d -r1.1.2.14 -r1.1.2.15 --- compile.txt 13 Apr 2005 19:44:40 -0000 1.1.2.14 +++ compile.txt 19 Apr 2005 05:42:00 -0000 1.1.2.15 @@ -176,6 +176,10 @@ FunctionDef() constructor function sets 'kind' to FunctionDef_kind and initializes the 'name', 'args', 'body', and 'attributes' fields. +*** NOTE: if you make a change here that can affect the output of bytecode that +is already in existence, make sure to delete your old .py(c|o) files! Running +``find . -name '*.py[co]' -exec rm -f {} ';'`` should do the trick. + Parse Tree to AST ----------------- @@ -379,6 +383,10 @@ PyCodeObject * assemble(struct compiler *, int); +*** NOTE: if you make a change here that can affect the output of bytecode that +is already in existence, make sure to delete your old .py(c|o) files! Running +``find . -name '*.py[co]' -exec rm -f {} ';'`` should do the trick. + Code Objects ------------ @@ -445,9 +453,7 @@ ToDo ---- -+ Grammar support (Parser/Python.asdl, Parser/asdl_c.py) - - empty base class list (``class Class(): pass``) - Stdlib support ++ Stdlib support - AST->Python access? - rewrite compiler package to mirror AST structure? + Documentation From bcannon at users.sourceforge.net Tue Apr 19 21:05:32 2005 From: bcannon at users.sourceforge.net (bcannon@users.sourceforge.net) Date: Tue Apr 19 21:05:35 2005 Subject: [Python-checkins] python/dist/src/Python symtable.c, 2.10.8.32, 2.10.8.33 Message-ID: Update of /cvsroot/python/python/dist/src/Python In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2582/Python Modified Files: Tag: ast-branch symtable.c Log Message: Fix detection of when a variable is a free or local variable. Closes bug #1166714. Thanks John Ehresman. Index: symtable.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Python/symtable.c,v retrieving revision 2.10.8.32 retrieving revision 2.10.8.33 diff -u -d -r2.10.8.32 -r2.10.8.33 --- symtable.c 13 Apr 2005 19:44:40 -0000 2.10.8.32 +++ symtable.c 19 Apr 2005 19:05:14 -0000 2.10.8.33 @@ -510,7 +510,7 @@ PyObject *global) { PyObject *name, *v, *local = NULL, *scope = NULL, *newbound = NULL; - PyObject *newglobal = NULL; + PyObject *newglobal = NULL, *newfree = NULL; int i, flags, pos = 0, success = 0; local = PyDict_New(); @@ -522,6 +522,9 @@ newglobal = PyDict_New(); if (!newglobal) goto error; + newfree = PyDict_New(); + if (!newfree) + goto error; newbound = PyDict_New(); if (!newbound) goto error; @@ -563,22 +566,26 @@ for (i = 0; i < PyList_GET_SIZE(ste->ste_children); ++i) { PyObject *c = PyList_GET_ITEM(ste->ste_children, i); assert(c && PySTEntry_Check(c)); - if (!analyze_block((PySTEntryObject *)c, newbound, free, + if (!analyze_block((PySTEntryObject *)c, newbound, newfree, newglobal)) goto error; } - if (ste->ste_type == FunctionBlock && !analyze_cells(scope, free)) + if (ste->ste_type == FunctionBlock && !analyze_cells(scope, newfree)) goto error; - if (!update_symbols(ste->ste_symbols, scope, bound, free, + if (!update_symbols(ste->ste_symbols, scope, bound, newfree, ste->ste_type == ClassBlock)) goto error; + + if (PyDict_Update(free, newfree) < 0) + goto error; success = 1; error: Py_XDECREF(local); Py_XDECREF(scope); Py_XDECREF(newbound); Py_XDECREF(newglobal); + Py_XDECREF(newfree); if (!success) assert(PyErr_Occurred()); return success; From bcannon at users.sourceforge.net Tue Apr 19 22:28:13 2005 From: bcannon at users.sourceforge.net (bcannon@users.sourceforge.net) Date: Tue Apr 19 22:28:16 2005 Subject: [Python-checkins] python/dist/src/Misc SpecialBuilds.txt,1.17,1.18 Message-ID: Update of /cvsroot/python/python/dist/src/Misc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15723/Misc Modified Files: SpecialBuilds.txt Log Message: Add a line explaining what env var to use to set the compiler flags and an example of how to do it so that it is passed directly to ./configure . Index: SpecialBuilds.txt =================================================================== RCS file: /cvsroot/python/python/dist/src/Misc/SpecialBuilds.txt,v retrieving revision 1.17 retrieving revision 1.18 diff -u -d -r1.17 -r1.18 --- SpecialBuilds.txt 18 Jan 2005 15:53:59 -0000 1.17 +++ SpecialBuilds.txt 19 Apr 2005 20:28:09 -0000 1.18 @@ -1,6 +1,9 @@ This file describes some special Python build types enabled via compile-time preprocessor defines. +It is best to define these options in the OPT environment variable; +``OPT="-DPy_REF_DEBUG" ./configure``. + --------------------------------------------------------------------------- Py_REF_DEBUG introduced in 1.4 named REF_DEBUG before 1.4 From bwarsaw at users.sourceforge.net Wed Apr 20 01:43:43 2005 From: bwarsaw at users.sourceforge.net (bwarsaw@users.sourceforge.net) Date: Wed Apr 20 01:43:45 2005 Subject: [Python-checkins] python/dist/src/Objects descrobject.c,2.38,2.39 Message-ID: Update of /cvsroot/python/python/dist/src/Objects In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21640/Objects Modified Files: descrobject.c Log Message: As per discussion on python-dev, descriptors defined in C with a NULL setter now raise AttributeError instead of TypeError, for consistency with their pure-Python equivalent. Index: descrobject.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Objects/descrobject.c,v retrieving revision 2.38 retrieving revision 2.39 diff -u -d -r2.38 -r2.39 --- descrobject.c 13 Dec 2003 11:58:56 -0000 2.38 +++ descrobject.c 19 Apr 2005 23:43:40 -0000 2.39 @@ -144,7 +144,7 @@ return res; if (descr->d_getset->get != NULL) return descr->d_getset->get(obj, descr->d_getset->closure); - PyErr_Format(PyExc_TypeError, + PyErr_Format(PyExc_AttributeError, "attribute '%.300s' of '%.100s' objects is not readable", descr_name((PyDescrObject *)descr), descr->d_type->tp_name); @@ -199,7 +199,7 @@ if (descr->d_getset->set != NULL) return descr->d_getset->set(obj, value, descr->d_getset->closure); - PyErr_Format(PyExc_TypeError, + PyErr_Format(PyExc_AttributeError, "attribute '%.300s' of '%.100s' objects is not writable", descr_name((PyDescrObject *)descr), descr->d_type->tp_name); From bwarsaw at users.sourceforge.net Wed Apr 20 01:43:42 2005 From: bwarsaw at users.sourceforge.net (bwarsaw@users.sourceforge.net) Date: Wed Apr 20 01:43:46 2005 Subject: [Python-checkins] python/dist/src/Misc NEWS,1.1285,1.1286 Message-ID: Update of /cvsroot/python/python/dist/src/Misc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21640/Misc Modified Files: NEWS Log Message: As per discussion on python-dev, descriptors defined in C with a NULL setter now raise AttributeError instead of TypeError, for consistency with their pure-Python equivalent. Index: NEWS =================================================================== RCS file: /cvsroot/python/python/dist/src/Misc/NEWS,v retrieving revision 1.1285 retrieving revision 1.1286 diff -u -d -r1.1285 -r1.1286 --- NEWS 18 Apr 2005 08:46:07 -0000 1.1285 +++ NEWS 19 Apr 2005 23:43:37 -0000 1.1286 @@ -12,6 +12,11 @@ Core and builtins ----------------- +- Descriptors defined in C with a PyGetSetDef structure, where the setter is + NULL, now raise an AttributeError when attempting to set or delete the + attribute. Previously a TypeError was raised, but this was inconsistent + with the equivalent pure-Python implementation. + - It is now safe to call PyGILState_Release() before PyEval_InitThreads() (note that if there is reason to believe there are multiple threads around you still must call PyEval_InitThreads() From tim_one at users.sourceforge.net Wed Apr 20 19:45:16 2005 From: tim_one at users.sourceforge.net (tim_one@users.sourceforge.net) Date: Wed Apr 20 19:45:19 2005 Subject: [Python-checkins] python/dist/src/Mac/OSX/Doc setup.py,1.6,1.7 Message-ID: Update of /cvsroot/python/python/dist/src/Mac/OSX/Doc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8309/Mac/OSX/Doc Modified Files: setup.py Log Message: Whitespace normalization. Index: setup.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Mac/OSX/Doc/setup.py,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- setup.py 17 Apr 2005 21:30:55 -0000 1.6 +++ setup.py 20 Apr 2005 17:45:13 -0000 1.7 @@ -57,7 +57,7 @@ (self.doc_version,self.doc_version) tarfile = 'html-%s.tar.bz2' % self.doc_version dirname = 'Python-Docs-%s' % self.doc_version - + if os.path.exists(self.build_html): raise RuntimeError, '%s: already exists, please remove and try again' % self.build_html os.chdir(self.build_base) From tim_one at users.sourceforge.net Wed Apr 20 19:45:16 2005 From: tim_one at users.sourceforge.net (tim_one@users.sourceforge.net) Date: Wed Apr 20 19:45:20 2005 Subject: [Python-checkins] python/dist/src/Lib/test test_compiler.py, 1.11, 1.12 test_parser.py, 1.21, 1.22 Message-ID: Update of /cvsroot/python/python/dist/src/Lib/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8309/Lib/test Modified Files: test_compiler.py test_parser.py Log Message: Whitespace normalization. Index: test_compiler.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Lib/test/test_compiler.py,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- test_compiler.py 9 Apr 2005 02:30:15 -0000 1.11 +++ test_compiler.py 20 Apr 2005 17:45:12 -0000 1.12 @@ -35,7 +35,7 @@ def testNewClassSyntax(self): compiler.compile("class foo():pass\n\n","","exec") - + def testLineNo(self): # Test that all nodes except Module have a correct lineno attribute. filename = __file__ Index: test_parser.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Lib/test/test_parser.py,v retrieving revision 1.21 retrieving revision 1.22 diff -u -d -r1.21 -r1.22 --- test_parser.py 9 Apr 2005 02:30:15 -0000 1.21 +++ test_parser.py 20 Apr 2005 17:45:12 -0000 1.22 @@ -129,7 +129,7 @@ def test_class_defs(self): self.check_suite("class foo():pass") - + def test_import_from_statement(self): self.check_suite("from sys.path import *") self.check_suite("from sys.path import dirname") From bwarsaw at users.sourceforge.net Wed Apr 20 21:41:38 2005 From: bwarsaw at users.sourceforge.net (bwarsaw@users.sourceforge.net) Date: Wed Apr 20 21:41:42 2005 Subject: [Python-checkins] python/dist/src/Lib/test test_csv.py, 1.27, 1.28 test_descr.py, 1.204, 1.205 test_file.py, 1.15, 1.16 Message-ID: Update of /cvsroot/python/python/dist/src/Lib/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9668/Lib/test Modified Files: test_csv.py test_descr.py test_file.py Log Message: Fix tests dependent on the exception raised by non-settable descriptors. Index: test_csv.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Lib/test/test_csv.py,v retrieving revision 1.27 retrieving revision 1.28 diff -u -d -r1.27 -r1.28 --- test_csv.py 13 Jan 2005 17:37:38 -0000 1.27 +++ test_csv.py 20 Apr 2005 19:41:24 -0000 1.28 @@ -55,8 +55,9 @@ # Try deleting or changing attributes (they are read-only) self.assertRaises(TypeError, delattr, obj.dialect, 'delimiter') self.assertRaises(TypeError, setattr, obj.dialect, 'delimiter', ':') - self.assertRaises(TypeError, delattr, obj.dialect, 'quoting') - self.assertRaises(TypeError, setattr, obj.dialect, 'quoting', None) + self.assertRaises(AttributeError, delattr, obj.dialect, 'quoting') + self.assertRaises(AttributeError, setattr, obj.dialect, + 'quoting', None) def test_reader_attrs(self): self._test_default_attrs(csv.reader, []) Index: test_descr.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Lib/test/test_descr.py,v retrieving revision 1.204 retrieving revision 1.205 diff -u -d -r1.204 -r1.205 --- test_descr.py 3 Mar 2005 16:45:19 -0000 1.204 +++ test_descr.py 20 Apr 2005 19:41:35 -0000 1.205 @@ -2712,7 +2712,7 @@ def cant(x, dict): try: x.__dict__ = dict - except TypeError: + except (AttributeError, TypeError): pass else: raise TestFailed, "shouldn't allow %r.__dict__ = %r" % (x, dict) Index: test_file.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Lib/test/test_file.py,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- test_file.py 31 May 2004 00:35:52 -0000 1.15 +++ test_file.py 20 Apr 2005 19:41:36 -0000 1.16 @@ -34,10 +34,10 @@ for attr in 'name', 'mode', 'closed': try: setattr(f, attr, 'oops') - except TypeError: + except (AttributeError, TypeError): pass else: - raise TestFailed('expected TypeError setting file attr %r' % attr) + raise TestFailed('expected exception setting file attr %r' % attr) f.close() # verify writelines with instance sequence From bcannon at users.sourceforge.net Wed Apr 20 22:49:43 2005 From: bcannon at users.sourceforge.net (bcannon@users.sourceforge.net) Date: Wed Apr 20 22:49:47 2005 Subject: [Python-checkins] python/dist/src/Misc SpecialBuilds.txt,1.18,1.19 Message-ID: Update of /cvsroot/python/python/dist/src/Misc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10160/Misc Modified Files: SpecialBuilds.txt Log Message: Clarify usage of OPT by noting that if it is set the default values will be left out. Index: SpecialBuilds.txt =================================================================== RCS file: /cvsroot/python/python/dist/src/Misc/SpecialBuilds.txt,v retrieving revision 1.18 retrieving revision 1.19 diff -u -d -r1.18 -r1.19 --- SpecialBuilds.txt 19 Apr 2005 20:28:09 -0000 1.18 +++ SpecialBuilds.txt 20 Apr 2005 20:49:39 -0000 1.19 @@ -2,7 +2,8 @@ compile-time preprocessor defines. It is best to define these options in the OPT environment variable; -``OPT="-DPy_REF_DEBUG" ./configure``. +``OPT="-DPy_REF_DEBUG" ./configure``. If you want the default values of +OPT to also be included you will need to add them in yourself manually. --------------------------------------------------------------------------- Py_REF_DEBUG introduced in 1.4 From doerwalter at users.sourceforge.net Thu Apr 21 23:32:06 2005 From: doerwalter at users.sourceforge.net (doerwalter@users.sourceforge.net) Date: Thu Apr 21 23:32:09 2005 Subject: [Python-checkins] python/dist/src/Misc NEWS,1.1286,1.1287 Message-ID: Update of /cvsroot/python/python/dist/src/Misc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20403/Misc Modified Files: NEWS Log Message: If the data read from the bytestream in readline() ends in a '\r' read one more byte, even if the user has passed a size parameter. This extra byte shouldn't cause a buffer overflow in the tokenizer. The original plan was to return a line ending in '\r', which might be recognizable as a complete line and skip any '\n' that was read afterwards. Unfortunately this didn't work, as the tokenizer only recognizes '\n' as line ends, which in turn lead to joined lines and SyntaxErrors, so this special treatment of a split '\r\n' has been dropped. (It can only happen with a temporarily exhausted bytestream now anyway.) Fixes parts of SF bugs #1163244 and #1175396. Index: NEWS =================================================================== RCS file: /cvsroot/python/python/dist/src/Misc/NEWS,v retrieving revision 1.1286 retrieving revision 1.1287 diff -u -d -r1.1286 -r1.1287 --- NEWS 19 Apr 2005 23:43:37 -0000 1.1286 +++ NEWS 21 Apr 2005 21:32:00 -0000 1.1287 @@ -266,6 +266,12 @@ - Bug #1149508: ``textwrap`` now handles hyphenated numbers (eg. "2004-03-05") correctly. +- Partial fixes for SF bugs #1163244 and #1175396: If a chunk read by + ``codecs.StreamReader.readline()`` has a trailing "\r", read one more + character even if the user has passed a size parameter to get a proper + line ending. Remove the special handling of a "\r\n" that has been split + between two lines. + Build ----- From doerwalter at users.sourceforge.net Thu Apr 21 23:32:06 2005 From: doerwalter at users.sourceforge.net (doerwalter@users.sourceforge.net) Date: Thu Apr 21 23:32:10 2005 Subject: [Python-checkins] python/dist/src/Lib codecs.py,1.43,1.44 Message-ID: Update of /cvsroot/python/python/dist/src/Lib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20403/Lib Modified Files: codecs.py Log Message: If the data read from the bytestream in readline() ends in a '\r' read one more byte, even if the user has passed a size parameter. This extra byte shouldn't cause a buffer overflow in the tokenizer. The original plan was to return a line ending in '\r', which might be recognizable as a complete line and skip any '\n' that was read afterwards. Unfortunately this didn't work, as the tokenizer only recognizes '\n' as line ends, which in turn lead to joined lines and SyntaxErrors, so this special treatment of a split '\r\n' has been dropped. (It can only happen with a temporarily exhausted bytestream now anyway.) Fixes parts of SF bugs #1163244 and #1175396. Index: codecs.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Lib/codecs.py,v retrieving revision 1.43 retrieving revision 1.44 diff -u -d -r1.43 -r1.44 --- codecs.py 4 Apr 2005 21:42:22 -0000 1.43 +++ codecs.py 21 Apr 2005 21:32:03 -0000 1.44 @@ -230,7 +230,6 @@ self.errors = errors self.bytebuffer = "" self.charbuffer = u"" - self.atcr = False def decode(self, input, errors='strict'): raise NotImplementedError @@ -306,18 +305,12 @@ # If size is given, we call read() only once while True: data = self.read(readsize) - if self.atcr and data.startswith(u"\n"): - data = data[1:] if data: - self.atcr = data.endswith(u"\r") - # If we're at a "\r" (and are allowed to read more), read one - # extra character (which might be a "\n") to get a proper - # line ending. (If the stream is temporarily exhausted we return - # the wrong line ending, but at least we won't generate a bogus - # second line.) - if self.atcr and size is None: + # If we're at a "\r" read one # extra character # (which might + # be a "\n") to get a proper # line ending. If the stream is + # temporarily exhausted we return the wrong line ending. + if data.endswith(u"\r"): data += self.read(size=1, chars=1) - self.atcr = data.endswith(u"\r") line += data lines = line.splitlines(True) @@ -367,7 +360,6 @@ """ self.bytebuffer = "" self.charbuffer = u"" - self.atcr = False def seek(self, offset, whence=0): """ Set the input stream's current position. From doerwalter at users.sourceforge.net Thu Apr 21 23:42:38 2005 From: doerwalter at users.sourceforge.net (doerwalter@users.sourceforge.net) Date: Thu Apr 21 23:42:41 2005 Subject: [Python-checkins] python/dist/src/Lib codecs.py,1.44,1.45 Message-ID: Update of /cvsroot/python/python/dist/src/Lib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27873/Lib Modified Files: codecs.py Log Message: Fix comment. Index: codecs.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Lib/codecs.py,v retrieving revision 1.44 retrieving revision 1.45 diff -u -d -r1.44 -r1.45 --- codecs.py 21 Apr 2005 21:32:03 -0000 1.44 +++ codecs.py 21 Apr 2005 21:42:35 -0000 1.45 @@ -306,8 +306,8 @@ while True: data = self.read(readsize) if data: - # If we're at a "\r" read one # extra character # (which might - # be a "\n") to get a proper # line ending. If the stream is + # If we're at a "\r" read one extra character (which might + # be a "\n") to get a proper line ending. If the stream is # temporarily exhausted we return the wrong line ending. if data.endswith(u"\r"): data += self.read(size=1, chars=1) From doerwalter at users.sourceforge.net Thu Apr 21 23:45:38 2005 From: doerwalter at users.sourceforge.net (doerwalter@users.sourceforge.net) Date: Thu Apr 21 23:45:40 2005 Subject: [Python-checkins] python/dist/src/Lib/test test_codecs.py, 1.22, 1.23 Message-ID: Update of /cvsroot/python/python/dist/src/Lib/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29279/Lib/test Modified Files: test_codecs.py Log Message: Update test to the current readline() behaviour. Index: test_codecs.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Lib/test/test_codecs.py,v retrieving revision 1.22 retrieving revision 1.23 diff -u -d -r1.22 -r1.23 --- test_codecs.py 4 Apr 2005 21:38:47 -0000 1.22 +++ test_codecs.py 21 Apr 2005 21:45:36 -0000 1.23 @@ -165,6 +165,7 @@ writer.write(u"foo\r") self.assertEqual(reader.readline(keepends=False), u"foo") writer.write(u"\nbar\r") + self.assertEqual(reader.readline(keepends=False), u"") self.assertEqual(reader.readline(keepends=False), u"bar") writer.write(u"baz") self.assertEqual(reader.readline(keepends=False), u"baz") @@ -174,6 +175,7 @@ writer.write(u"foo\r") self.assertEqual(reader.readline(keepends=True), u"foo\r") writer.write(u"\nbar\r") + self.assertEqual(reader.readline(keepends=True), u"\n") self.assertEqual(reader.readline(keepends=True), u"bar\r") writer.write(u"baz") self.assertEqual(reader.readline(keepends=True), u"baz") From doerwalter at users.sourceforge.net Thu Apr 21 23:53:45 2005 From: doerwalter at users.sourceforge.net (doerwalter@users.sourceforge.net) Date: Thu Apr 21 23:53:48 2005 Subject: [Python-checkins] python/dist/src/Misc NEWS, 1.1193.2.48, 1.1193.2.49 Message-ID: Update of /cvsroot/python/python/dist/src/Misc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32723/Misc Modified Files: Tag: release24-maint NEWS Log Message: Backport checkin (and the appropriate fix to the test): If the data read from the bytestream in readline() ends in a '\r' read one more byte, even if the user has passed a size parameter. This extra byte shouldn't cause a buffer overflow in the tokenizer. The original plan was to return a line ending in '\r', which might be recognizable as a complete line and skip any '\n' that was read afterwards. Unfortunately this didn't work, as the tokenizer only recognizes '\n' as line ends, which in turn lead to joined lines and SyntaxErrors, so this special treatment of a split '\r\n' has been dropped. (It can only happen with a temporarily exhausted bytestream now anyway.) Fixes parts of SF bugs #1163244 and #1175396. Index: NEWS =================================================================== RCS file: /cvsroot/python/python/dist/src/Misc/NEWS,v retrieving revision 1.1193.2.48 retrieving revision 1.1193.2.49 diff -u -d -r1.1193.2.48 -r1.1193.2.49 --- NEWS 7 Apr 2005 10:19:47 -0000 1.1193.2.48 +++ NEWS 21 Apr 2005 21:53:28 -0000 1.1193.2.49 @@ -32,6 +32,12 @@ - distutils.commands.register now encodes the data as UTF-8 before posting them to PyPI. +- Partial fixes for SF bugs #1163244 and #1175396: If a chunk read by + ``codecs.StreamReader.readline()`` has a trailing "\r", read one more + character even if the user has passed a size parameter to get a proper + line ending. Remove the special handling of a "\r\n" that has been split + between two lines. + What's New in Python 2.4.1 final? ================================= From doerwalter at users.sourceforge.net Thu Apr 21 23:53:45 2005 From: doerwalter at users.sourceforge.net (doerwalter@users.sourceforge.net) Date: Thu Apr 21 23:53:49 2005 Subject: [Python-checkins] python/dist/src/Lib codecs.py,1.35.2.6,1.35.2.7 Message-ID: Update of /cvsroot/python/python/dist/src/Lib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32723/Lib Modified Files: Tag: release24-maint codecs.py Log Message: Backport checkin (and the appropriate fix to the test): If the data read from the bytestream in readline() ends in a '\r' read one more byte, even if the user has passed a size parameter. This extra byte shouldn't cause a buffer overflow in the tokenizer. The original plan was to return a line ending in '\r', which might be recognizable as a complete line and skip any '\n' that was read afterwards. Unfortunately this didn't work, as the tokenizer only recognizes '\n' as line ends, which in turn lead to joined lines and SyntaxErrors, so this special treatment of a split '\r\n' has been dropped. (It can only happen with a temporarily exhausted bytestream now anyway.) Fixes parts of SF bugs #1163244 and #1175396. Index: codecs.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Lib/codecs.py,v retrieving revision 1.35.2.6 retrieving revision 1.35.2.7 diff -u -d -r1.35.2.6 -r1.35.2.7 --- codecs.py 4 Apr 2005 21:56:27 -0000 1.35.2.6 +++ codecs.py 21 Apr 2005 21:53:43 -0000 1.35.2.7 @@ -230,7 +230,6 @@ self.errors = errors self.bytebuffer = "" self.charbuffer = u"" - self.atcr = False def decode(self, input, errors='strict'): raise NotImplementedError @@ -306,18 +305,12 @@ # If size is given, we call read() only once while True: data = self.read(readsize) - if self.atcr and data.startswith(u"\n"): - data = data[1:] if data: - self.atcr = data.endswith(u"\r") - # If we're at a "\r" (and are allowed to read more), read one - # extra character (which might be a "\n") to get a proper - # line ending. (If the stream is temporarily exhausted we return - # the wrong line ending, but at least we won't generate a bogus - # second line.) - if self.atcr and size is None: + # If we're at a "\r" read one extra character (which might + # be a "\n") to get a proper line ending. If the stream is + # temporarily exhausted we return the wrong line ending. + if data.endswith(u"\r"): data += self.read(size=1, chars=1) - self.atcr = data.endswith(u"\r") line += data lines = line.splitlines(True) @@ -367,7 +360,6 @@ """ self.bytebuffer = "" self.charbuffer = u"" - self.atcr = False def seek(self, offset, whence=0): """ Set the input stream's current position. From doerwalter at users.sourceforge.net Thu Apr 21 23:53:45 2005 From: doerwalter at users.sourceforge.net (doerwalter@users.sourceforge.net) Date: Thu Apr 21 23:53:49 2005 Subject: [Python-checkins] python/dist/src/Lib/test test_codecs.py, 1.15.2.4, 1.15.2.5 Message-ID: Update of /cvsroot/python/python/dist/src/Lib/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32723/Lib/test Modified Files: Tag: release24-maint test_codecs.py Log Message: Backport checkin (and the appropriate fix to the test): If the data read from the bytestream in readline() ends in a '\r' read one more byte, even if the user has passed a size parameter. This extra byte shouldn't cause a buffer overflow in the tokenizer. The original plan was to return a line ending in '\r', which might be recognizable as a complete line and skip any '\n' that was read afterwards. Unfortunately this didn't work, as the tokenizer only recognizes '\n' as line ends, which in turn lead to joined lines and SyntaxErrors, so this special treatment of a split '\r\n' has been dropped. (It can only happen with a temporarily exhausted bytestream now anyway.) Fixes parts of SF bugs #1163244 and #1175396. Index: test_codecs.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Lib/test/test_codecs.py,v retrieving revision 1.15.2.4 retrieving revision 1.15.2.5 diff -u -d -r1.15.2.4 -r1.15.2.5 --- test_codecs.py 4 Apr 2005 21:56:28 -0000 1.15.2.4 +++ test_codecs.py 21 Apr 2005 21:53:43 -0000 1.15.2.5 @@ -176,6 +176,7 @@ writer.write(u"foo\r") self.assertEqual(reader.readline(keepends=False), u"foo") writer.write(u"\nbar\r") + self.assertEqual(reader.readline(keepends=False), u"") self.assertEqual(reader.readline(keepends=False), u"bar") writer.write(u"baz") self.assertEqual(reader.readline(keepends=False), u"baz") @@ -185,6 +186,7 @@ writer.write(u"foo\r") self.assertEqual(reader.readline(keepends=True), u"foo\r") writer.write(u"\nbar\r") + self.assertEqual(reader.readline(keepends=True), u"\n") self.assertEqual(reader.readline(keepends=True), u"bar\r") writer.write(u"baz") self.assertEqual(reader.readline(keepends=True), u"baz") From mwh at users.sourceforge.net Fri Apr 22 10:52:52 2005 From: mwh at users.sourceforge.net (mwh@users.sourceforge.net) Date: Fri Apr 22 10:52:55 2005 Subject: [Python-checkins] python/nondist/peps pep-0310.txt,1.4,1.5 Message-ID: Update of /cvsroot/python/python/nondist/peps In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12983 Modified Files: pep-0310.txt Log Message: Fix typo Guido just rubbed my eyes into on python-dev. Index: pep-0310.txt =================================================================== RCS file: /cvsroot/python/python/nondist/peps/pep-0310.txt,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- pep-0310.txt 18 Jun 2004 11:41:03 -0000 1.4 +++ pep-0310.txt 22 Apr 2005 08:52:49 -0000 1.5 @@ -157,7 +157,7 @@ __exit__ method is found, to increase the "out-of-the-box utility" of the "with ..." construct. - There are some simiralities in concept between 'with ...' blocks + There are some similarities in concept between 'with ...' blocks and generators, which have led to proposals that for loops could implement the with block functionality[3]. While neat on some levels, we think that for loops should stick to being loops. From jackjansen at users.sourceforge.net Sat Apr 23 00:36:51 2005 From: jackjansen at users.sourceforge.net (jackjansen@users.sourceforge.net) Date: Sat Apr 23 00:36:54 2005 Subject: [Python-checkins] python/dist/src/Mac/OSX/Dist/resources.tiger - New directory Message-ID: Update of /cvsroot/python/python/dist/src/Mac/OSX/Dist/resources.tiger In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20064/Dist/resources.tiger Log Message: Directory /cvsroot/python/python/dist/src/Mac/OSX/Dist/resources.tiger added to the repository --> Using per-directory sticky tag `release23-maint' From jackjansen at users.sourceforge.net Sat Apr 23 00:38:15 2005 From: jackjansen at users.sourceforge.net (jackjansen@users.sourceforge.net) Date: Sat Apr 23 00:38:19 2005 Subject: [Python-checkins] python/dist/src/Mac/OSX Makefile.tiger, NONE, 1.1.2.1 setup.tiger.py, NONE, 1.1.2.1 Message-ID: Update of /cvsroot/python/python/dist/src/Mac/OSX In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20364 Added Files: Tag: release23-maint Makefile.tiger setup.tiger.py Log Message: Started on MacPython additions for Tiger. --- NEW FILE: Makefile.tiger --- # This Makefile is to be used *only* on Tiger. # It installs the things that are available in MacPython but that are # ommitted from Apple's installation of Python 2.3.5. # all: install_waste install_IDE install_PackageManager \ install_BuildApplet installextras install_PythonLauncher srcdir=../.. VERSION=2.3 DESTDIR= PYTHONAPPSDIR=/Applications/MacPython-$(VERSION) APPLE_prefix=/System/Library/Frameworks/Python.framework/Versions/$(VERSION) BUILDPYTHON=/usr/bin/python$(VERSION) APPLE_LIBDEST=$(APPLE_prefix)/lib/python$(VERSION) INSTALLED_PYTHONW=$(APPLE_prefix)/Resources/Python.app/Contents/MacOS/Python APPLE_PYTHONLAUNCHER=$(APPLE_prefix)/Resources/PythonLauncher.app bundlebuilder=$(srcdir)/Lib/plat-mac/bundlebuilder.py install_waste: $(BUILDPYTHON) setup.panther.py install \ --prefix=$(APPLE_prefix) --root=/$(DESTDIR) install_IDE: $(BUILDPYTHON) $(srcdir)/Mac/scripts/BuildApplet.py \ --python $(INSTALLED_PYTHONW) \ --output $(DESTDIR)$(PYTHONAPPSDIR)/PythonIDE.app --noargv \ $(srcdir)/Mac/Tools/IDE/PythonIDE.py # # Add the extra files to the resources. This is to work around bugs in # # them in the original 2.3. # cp ../Tools/IDE/PythonIDEMain.py $(DESTDIR)$(PYTHONAPPSDIR)/PythonIDE.app/Contents/Resources # cp ../Tools/IDE/Wapplication.py $(DESTDIR)$(PYTHONAPPSDIR)/PythonIDE.app/Contents/Resources # cp ../Tools/IDE/Wcontrols.py $(DESTDIR)$(PYTHONAPPSDIR)/PythonIDE.app/Contents/Resources # cp ../Tools/IDE/PyEdit.py $(DESTDIR)$(PYTHONAPPSDIR)/PythonIDE.app/Contents/Resources install_PackageManager: $(BUILDPYTHON) $(bundlebuilder) \ --builddir $(DESTDIR)$(PYTHONAPPSDIR)/ \ --python $(INSTALLED_PYTHONW) \ --resource $(srcdir)/Mac/Tools/IDE/PythonIDE.rsrc \ --mainprogram $(srcdir)/Mac/Tools/IDE/PackageManager.py \ --iconfile $(srcdir)/Mac/Tools/IDE/PackageManager.icns \ --plist $(srcdir)/Mac/Tools/IDE/PackageManager.plist \ --creator Pimp build install_BuildApplet: $(BUILDPYTHON) $(srcdir)/Mac/scripts/BuildApplet.py \ --python $(INSTALLED_PYTHONW) \ --output $(DESTDIR)$(PYTHONAPPSDIR)/BuildApplet.app \ $(srcdir)/Mac/scripts/BuildApplet.py installextras: $(MAKE) -f Makefile installextras \ BUILDPYTHON=$(BUILDPYTHON) INSTALLED_PYTHONW=$(INSTALLED_PYTHONW) \ DESTDIR=$(DESTDIR) PYTHONAPPSDIR=$(PYTHONAPPSDIR) install_PythonLauncher: ln -fsn $(APPLE_PYTHONLAUNCHER) $(DESTDIR)$(PYTHONAPPSDIR)/PythonLauncher install_pimpupdate: cp ../../Lib/plat-mac/pimp.py $(DESTDIR)/Library/Python/2.3/pimp_update.py --- NEW FILE: setup.tiger.py --- from distutils.core import Extension, setup from distutils import sysconfig import os SRCDIR=os.path.realpath(os.path.join(os.getcwd(), "../..")) def find_file(filename, std_dirs, paths): """Searches for the directory where a given file is located, and returns a possibly-empty list of additional directories, or None if the file couldn't be found at all. 'filename' is the name of a file, such as readline.h or libcrypto.a. 'std_dirs' is the list of standard system directories; if the file is found in one of them, no additional directives are needed. 'paths' is a list of additional locations to check; if the file is found in one of them, the resulting list will contain the directory. """ # Check the standard locations for dir in std_dirs: f = os.path.join(dir, filename) if os.path.exists(f): return [] # Check the additional directories for dir in paths: f = os.path.join(dir, filename) if os.path.exists(f): return [dir] # Not found anywhere return None def find_library_file(compiler, libname, std_dirs, paths): filename = compiler.library_filename(libname, lib_type='shared') result = find_file(filename, std_dirs, paths) if result is not None: return result filename = compiler.library_filename(libname, lib_type='static') result = find_file(filename, std_dirs, paths) return result def waste_Extension(): waste_incs = find_file("WASTE.h", [], ['../'*n + 'waste/C_C++ Headers' for n in (0,1,2,3,4)]) if waste_incs != None: waste_libs = [os.path.join(os.path.split(waste_incs[0])[0], "Static Libraries")] srcdir = SRCDIR return [ Extension('waste', [os.path.join(srcdir, d) for d in 'Mac/Modules/waste/wastemodule.c', 'Mac/Wastemods/WEObjectHandlers.c', 'Mac/Wastemods/WETabHooks.c', 'Mac/Wastemods/WETabs.c' ], include_dirs = waste_incs + [ os.path.join(srcdir, 'Mac/Include'), os.path.join(srcdir, 'Mac/Wastemods') ], library_dirs = waste_libs, libraries = ['WASTE'], extra_link_args = ['-framework', 'Carbon'], ) ] return [] setup(name="MacPython for Tiger extensions", version="2.3", ext_modules=waste_Extension() ) From jackjansen at users.sourceforge.net Sat Apr 23 00:38:16 2005 From: jackjansen at users.sourceforge.net (jackjansen@users.sourceforge.net) Date: Sat Apr 23 00:38:19 2005 Subject: [Python-checkins] python/dist/src/Mac/OSX/Dist/resources.tiger ReadMe.txt, NONE, 1.1.2.1 Welcome.rtf, NONE, 1.1.2.1 Message-ID: Update of /cvsroot/python/python/dist/src/Mac/OSX/Dist/resources.tiger In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20364/Dist/resources.tiger Added Files: Tag: release23-maint ReadMe.txt Welcome.rtf Log Message: Started on MacPython additions for Tiger. --- NEW FILE: ReadMe.txt --- This package will install the MacPython 2.3.5 additions for Mac OS X 10.4. Installation requires approximately 3.3 MB of disk space, ignore the message that it will take zero bytes. You must install onto your current boot disk, even though the installer does not enforce this, otherwise things will not work. This installer does not contain a Python engine, as Apple already includes that in 10.4. It does contain a set of programs to allow easy access to it for Mac users (an integrated development environment, a Python extension package manager) and the waste module. The installer puts the applications in MacPython-2.3 in your Applications folder. The PythonIDE application has a Help command that gets you started quickly with MacPython and contains references to other documentation. More information on MacPython can be found at http://www.cwi.nl/~jack/macpython, more information on Python in general at http://www.python.org. --- NEW FILE: Welcome.rtf --- {\rtf1\mac\ansicpg10000\cocoartf822 {\fonttbl\f0\fswiss\fcharset77 Helvetica;\f1\fswiss\fcharset77 Helvetica-Bold;} {\colortbl;\red255\green255\blue255;} \paperw11900\paperh16840\margl1440\margr1440\vieww9920\viewh10660\viewkind0 \pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural \f0\fs24 \cf0 This package will install the third build of the \f1\b MacPython 2.3.5 \f0\b0 additions for \f1\b Mac OS X 10.4 \f0\b0 . \ \ MacPython consists of the programs to allow easy access to Python for Mac users (an integrated development environment, a Python extension package manager), and uses the Python 2.3.5 interpreter core that comes pre-installed on 10.4.\ \ See the ReadMe file for more information.} From jackjansen at users.sourceforge.net Sat Apr 23 00:38:15 2005 From: jackjansen at users.sourceforge.net (jackjansen@users.sourceforge.net) Date: Sat Apr 23 00:38:20 2005 Subject: [Python-checkins] python/dist/src/Mac/OSX/Dist build.tiger, NONE, 1.1.2.1 Message-ID: Update of /cvsroot/python/python/dist/src/Mac/OSX/Dist In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20364/Dist Added Files: Tag: release23-maint build.tiger Log Message: Started on MacPython additions for Tiger. --- NEW FILE: build.tiger --- #!/bin/sh -e #---------------------------------------------------------------------- # Build the MacPython 2.3 extensions for an installation to run # on the pre-installed 2.3.5 framework build on OSX 10.4 # TODO: Parameterize the versions, builddirs, etc... # Script configs PYVERSION=2.3.5 PYVER=2.3 BUILDNUM=1 DOCLEANUP=no PROGDIR="`dirname \"$0\"`" case x$PROGDIR in x|x.) PROGDIR=`pwd` ;; x/*) ;; *) echo "Please run with a full pathname" exit 1 ;; esac if [ ! -e /usr/bin/python ]; then echo "No /usr/bin/python; this script expects to be run on 10.4 only" exit 1 fi vers=`/usr/bin/python -V 2>&1` if [ "$vers" != "Python 2.3.5" ]; then echo "/usr/bin/python is not version 2.3.5; this script expects to be run on 10.3 only" exit 1 fi TMPDIR=/tmp/_py #TMPDIR=/projects/_py INSTALLROOT=$TMPDIR/install DMGDIR=$TMPDIR/dmg RESOURCEDIR=$PROGDIR/resources.tiger DESTDIR=$TMPDIR/dist PYTHONSRC=$PROGDIR/../../.. PYTHONOSXDIR=$PYTHONSRC/Mac/OSX WASTEDIR=$PYTHONSRC/../waste rm -rf $DMGDIR if [ ! -e $TMPDIR ]; then mkdir $TMPDIR fi chgrp admin $TMPDIR mkdir -p $DMGDIR/root # Ask the user whether s/he has edited Welcome.txt read -p "Have you updated $RESOURCEDIR/Welcome.txt (Y/n)? " welcome if [ "$welcome" = "n" -o "$welcome" = "N" ]; then echo "Please do so and retry" exit fi # Make the installation directories mkdir -p $INSTALLROOT/Applications mkdir -p $INSTALLROOT/Library/Python/$PYVER # Make a temporary site-packages symlink mkdir -p $INSTALLROOT/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/ ln -s $INSTALLROOT/Library/Python/$PYVER $INSTALLROOT/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages pushd $PYTHONOSXDIR make -f Makefile.tiger DIRMODE=775 EXEMODE=775 FILEMODE=664 DESTDIR=$INSTALLROOT # Remove the temporary symlink rm -r $INSTALLROOT/System # Unfortunately all the ...MODE arguments above still don't do the trick. # Cop out, and recursively set everything group-writeable. chmod -R ug+w $INSTALLROOT popd # Make the Installer package: # Finally, build the package... rm -rf MacPython-Tiger.pkg python $PYTHONSRC/Mac/scripts/buildpkg.py \ --Title=MacPython-Tiger \ --Version=$PYVERSION-$BUILDNUM \ --Description="MacPython $PYVERSION tools and additions for Mac OS X 10.4" \ --NeedsAuthorization="YES" \ --Relocatable="NO" \ --InstallOnly="YES" \ --UseUserMask="NO" \ $INSTALLROOT \ $RESOURCEDIR # --RootVolumeOnly="YES" \ # ...and then make a disk image containing the package. mv MacPython-Tiger.pkg $DMGDIR/root cp $RESOURCEDIR/ReadMe.txt $DMGDIR/root/ReadMe.txt $PROGDIR/makedmg $DMGDIR/root $DMGDIR MacPython-Tiger-$PYVERSION-$BUILDNUM echo Moving $DMGDIR/MacPython-Tiger-$PYVERSION-$BUILDNUM to $DESTDIR if [ ! -e $DESTDIR ]; then mkdir $DESTDIR fi mv $DMGDIR/MacPython-Tiger-$PYVERSION-$BUILDNUM.dmg $DESTDIR # Cleanup build/install dirs if [ $DOCLEANUP = yes ]; then echo "Cleaning up..." rm -rf $INSTALLROOT rm -rf $DMGDIR else echo "Cleanup is disabled. You should remove these dirs when done:" echo " $INSTALLROOT" echo " $DMGDIR" fi echo "Your installer can be found in $DESTDIR" From mwh at users.sourceforge.net Sun Apr 24 21:32:36 2005 From: mwh at users.sourceforge.net (mwh@users.sourceforge.net) Date: Sun Apr 24 21:32:40 2005 Subject: [Python-checkins] python/dist/src/Misc NEWS, 1.1193.2.49, 1.1193.2.50 Message-ID: Update of /cvsroot/python/python/dist/src/Misc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27864/Misc Modified Files: Tag: release24-maint NEWS Log Message: Backport my recent fix (rev. 2.40 of Python/pystate.c): Fix: [ 1176893 ] Readline segfault by unsilly-ing PyGILState_Release(). Backport candidate. Index: NEWS =================================================================== RCS file: /cvsroot/python/python/dist/src/Misc/NEWS,v retrieving revision 1.1193.2.49 retrieving revision 1.1193.2.50 diff -u -d -r1.1193.2.49 -r1.1193.2.50 --- NEWS 21 Apr 2005 21:53:28 -0000 1.1193.2.49 +++ NEWS 24 Apr 2005 19:32:27 -0000 1.1193.2.50 @@ -12,6 +12,12 @@ Core and builtins ----------------- +- It is now safe to call PyGILState_Release() before + PyEval_InitThreads() (note that if there is reason to believe there + are multiple threads around you still must call PyEval_InitThreads() + before using the Python API; this fix is for extension modules that + have no way of knowing if Python is multi-threaded yet). + - Typing Ctrl-C whilst raw_input() was waiting in a build with threads disabled caused a crash. From mwh at users.sourceforge.net Sun Apr 24 21:32:36 2005 From: mwh at users.sourceforge.net (mwh@users.sourceforge.net) Date: Sun Apr 24 21:32:41 2005 Subject: [Python-checkins] python/dist/src/Python pystate.c, 2.38.2.1, 2.38.2.2 Message-ID: Update of /cvsroot/python/python/dist/src/Python In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27864/Python Modified Files: Tag: release24-maint pystate.c Log Message: Backport my recent fix (rev. 2.40 of Python/pystate.c): Fix: [ 1176893 ] Readline segfault by unsilly-ing PyGILState_Release(). Backport candidate. Index: pystate.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Python/pystate.c,v retrieving revision 2.38.2.1 retrieving revision 2.38.2.2 diff -u -d -r2.38.2.1 -r2.38.2.2 --- pystate.c 8 Feb 2005 15:01:35 -0000 2.38.2.1 +++ pystate.c 24 Apr 2005 19:32:34 -0000 2.38.2.2 @@ -503,6 +503,6 @@ } /* Release the lock if necessary */ else if (oldstate == PyGILState_UNLOCKED) - PyEval_ReleaseThread(tcur); + PyEval_SaveThread(); } #endif /* WITH_THREAD */ From bcannon at users.sourceforge.net Mon Apr 25 00:06:14 2005 From: bcannon at users.sourceforge.net (bcannon@users.sourceforge.net) Date: Mon Apr 25 00:06:17 2005 Subject: [Python-checkins] python/dist/src/Lib/test test_compile.py, 1.10.10.3, 1.10.10.4 Message-ID: Update of /cvsroot/python/python/dist/src/Lib/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17237/Lib/test Modified Files: Tag: ast-branch test_compile.py Log Message: Backport test_compile from the 2.4 branch by copying that version over and committing. Index: test_compile.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Lib/test/test_compile.py,v retrieving revision 1.10.10.3 retrieving revision 1.10.10.4 diff -u -d -r1.10.10.3 -r1.10.10.4 --- test_compile.py 23 Apr 2004 04:35:57 -0000 1.10.10.3 +++ test_compile.py 24 Apr 2005 22:05:56 -0000 1.10.10.4 @@ -1,199 +1,268 @@ -"""Test a variety of compilation edge cases. - -Several ways to assign to __debug__ ------------------------------------ - ->>> __debug__ = 1 -Traceback (most recent call last): - ... -SyntaxError: can not assign to __debug__ (, line 1) - ->>> import __debug__ -Traceback (most recent call last): - ... -SyntaxError: can not assign to __debug__ (, line 1) - ->>> try: -... 1 -... except MemoryError, __debug__: -... pass -Traceback (most recent call last): - ... -SyntaxError: can not assign to __debug__ (, line 2) - -Shouldn't that be line 3? - ->>> def __debug__(): -... pass -Traceback (most recent call last): - ... -SyntaxError: can not assign to __debug__ (, line 1) - -Not sure what the next few lines is trying to test. - ->>> import __builtin__ ->>> prev = __builtin__.__debug__ ->>> setattr(__builtin__, "__debug__", "sure") ->>> setattr(__builtin__, "__debug__", prev) - -Parameter passing ------------------ - ->>> def f(a = 0, a = 1): -... pass -Traceback (most recent call last): - ... -SyntaxError: duplicate argument 'a' in function definition (, line 1) - ->>> def f(a): -... global a -... a = 1 -Traceback (most recent call last): - ... -SyntaxError: name 'a' is local and global +import unittest +import warnings +import sys +from test import test_support -XXX How hard would it be to get the location in the error? +class TestSpecifics(unittest.TestCase): ->>> def f(a=1, (b, c)): -... pass -Traceback (most recent call last): - ... -SyntaxError: non-default argument follows default argument (, line 1) + def test_debug_assignment(self): + # catch assignments to __debug__ + self.assertRaises(SyntaxError, compile, '__debug__ = 1', '?', 'single') + import __builtin__ + prev = __builtin__.__debug__ + setattr(__builtin__, '__debug__', 'sure') + setattr(__builtin__, '__debug__', prev) + def test_argument_handling(self): + # detect duplicate positional and keyword arguments + self.assertRaises(SyntaxError, eval, 'lambda a,a:0') + self.assertRaises(SyntaxError, eval, 'lambda a,a=1:0') + self.assertRaises(SyntaxError, eval, 'lambda a=1,a=1:0') + try: + exec 'def f(a, a): pass' + self.fail("duplicate arguments") + except SyntaxError: + pass + try: + exec 'def f(a = 0, a = 1): pass' + self.fail("duplicate keyword arguments") + except SyntaxError: + pass + try: + exec 'def f(a): global a; a = 1' + self.fail("variable is global and local") + except SyntaxError: + pass -Details of SyntaxError object ------------------------------ + def test_syntax_error(self): + self.assertRaises(SyntaxError, compile, "1+*3", "filename", "exec") ->>> 1+*3 -Traceback (most recent call last): - ... -SyntaxError: invalid syntax + def test_duplicate_global_local(self): + try: + exec 'def f(a): global a; a = 1' + self.fail("variable is global and local") + except SyntaxError: + pass -In this case, let's explore the details fields of the exception object. ->>> try: -... compile("1+*3", "filename", "exec") -... except SyntaxError, err: -... pass ->>> err.filename, err.lineno, err.offset -('filename', 1, 3) ->>> err.text, err.msg -('1+*3', 'invalid syntax') + def test_exec_with_general_mapping_for_locals(self): -Complex parameter passing -------------------------- + class M: + "Test mapping interface versus possible calls from eval()." + def __getitem__(self, key): + if key == 'a': + return 12 + raise KeyError + def __setitem__(self, key, value): + self.results = (key, value) + def keys(self): + return list('xyz') ->>> def comp_params((a, b)): -... print a, b ->>> comp_params((1, 2)) -1 2 + m = M() + g = globals() + exec 'z = a' in g, m + self.assertEqual(m.results, ('z', 12)) + try: + exec 'z = b' in g, m + except NameError: + pass + else: + self.fail('Did not detect a KeyError') + exec 'z = dir()' in g, m + self.assertEqual(m.results, ('z', list('xyz'))) + exec 'z = globals()' in g, m + self.assertEqual(m.results, ('z', g)) + exec 'z = locals()' in g, m + self.assertEqual(m.results, ('z', m)) + try: + exec 'z = b' in m + except TypeError: + pass + else: + self.fail('Did not validate globals as a real dict') ->>> def comp_params((a, b)=(3, 4)): -... print a, b ->>> comp_params((1, 2)) -1 2 ->>> comp_params() -3 4 + class A: + "Non-mapping" + pass + m = A() + try: + exec 'z = a' in g, m + except TypeError: + pass + else: + self.fail('Did not validate locals as a mapping') ->>> def comp_params(a, (b, c)): -... print a, b, c ->>> comp_params(1, (2, 3)) -1 2 3 + # Verify that dict subclasses work as well + class D(dict): + def __getitem__(self, key): + if key == 'a': + return 12 + return dict.__getitem__(self, key) + d = D() + exec 'z = a' in g, d + self.assertEqual(d['z'], 12) ->>> def comp_params(a=2, (b, c)=(3, 4)): -... print a, b, c ->>> comp_params(1, (2, 3)) -1 2 3 ->>> comp_params() -2 3 4 + def test_complex_args(self): -""" + def comp_args((a, b)): + return a,b + self.assertEqual(comp_args((1, 2)), (1, 2)) -from test.test_support import verbose, TestFailed, run_doctest + def comp_args((a, b)=(3, 4)): + return a, b + self.assertEqual(comp_args((1, 2)), (1, 2)) + self.assertEqual(comp_args(), (3, 4)) -# It takes less space to deal with bad float literals using a helper -# function than it does with doctest. The doctest needs to include -# the exception every time. + def comp_args(a, (b, c)): + return a, b, c + self.assertEqual(comp_args(1, (2, 3)), (1, 2, 3)) -def expect_error(s): - try: - eval(s) - raise TestFailed("%r accepted" % s) - except SyntaxError: - pass + def comp_args(a=2, (b, c)=(3, 4)): + return a, b, c + self.assertEqual(comp_args(1, (2, 3)), (1, 2, 3)) + self.assertEqual(comp_args(), (2, 3, 4)) -expect_error("2e") -expect_error("2.0e+") -expect_error("1e-") -expect_error("3-4e/21") + def test_argument_order(self): + try: + exec 'def f(a=1, (b, c)): pass' + self.fail("non-default args after default") + except SyntaxError: + pass -if verbose: - print "testing compile() of indented block w/o trailing newline" + def test_float_literals(self): + # testing bad float literals + self.assertRaises(SyntaxError, eval, "2e") + self.assertRaises(SyntaxError, eval, "2.0e+") + self.assertRaises(SyntaxError, eval, "1e-") + self.assertRaises(SyntaxError, eval, "3-4e/21") -s = """ + def test_indentation(self): + # testing compile() of indented block w/o trailing newline" + s = """ if 1: if 2: pass""" -compile(s, "", "exec") + compile(s, "", "exec") + def test_literals_with_leading_zeroes(self): + for arg in ["077787", "0xj", "0x.", "0e", "090000000000000", + "080000000000000", "000000000000009", "000000000000008"]: + self.assertRaises(SyntaxError, eval, arg) -if verbose: - print "testing literals with leading zeroes" + self.assertEqual(eval("0777"), 511) + self.assertEqual(eval("0777L"), 511) + self.assertEqual(eval("000777"), 511) + self.assertEqual(eval("0xff"), 255) + self.assertEqual(eval("0xffL"), 255) + self.assertEqual(eval("0XfF"), 255) + self.assertEqual(eval("0777."), 777) + self.assertEqual(eval("0777.0"), 777) + self.assertEqual(eval("000000000000000000000000000000000000000000000000000777e0"), 777) + self.assertEqual(eval("0777e1"), 7770) + self.assertEqual(eval("0e0"), 0) + self.assertEqual(eval("0000E-012"), 0) + self.assertEqual(eval("09.5"), 9.5) + self.assertEqual(eval("0777j"), 777j) + self.assertEqual(eval("00j"), 0j) + self.assertEqual(eval("00.0"), 0) + self.assertEqual(eval("0e3"), 0) + self.assertEqual(eval("090000000000000."), 90000000000000.) + self.assertEqual(eval("090000000000000.0000000000000000000000"), 90000000000000.) + self.assertEqual(eval("090000000000000e0"), 90000000000000.) + self.assertEqual(eval("090000000000000e-0"), 90000000000000.) + self.assertEqual(eval("090000000000000j"), 90000000000000j) + self.assertEqual(eval("000000000000007"), 7) + self.assertEqual(eval("000000000000008."), 8.) + self.assertEqual(eval("000000000000009."), 9.) -def expect_same(test_source, expected): - got = eval(test_source) - if got != expected: - raise TestFailed("eval(%r) gave %r, but expected %r" % - (test_source, got, expected)) + def test_unary_minus(self): + # Verify treatment of unary minus on negative numbers SF bug #660455 + if sys.maxint == 2147483647: + # 32-bit machine + all_one_bits = '0xffffffff' + self.assertEqual(eval(all_one_bits), 4294967295L) + self.assertEqual(eval("-" + all_one_bits), -4294967295L) + elif sys.maxint == 9223372036854775807: + # 64-bit machine + all_one_bits = '0xffffffffffffffff' + self.assertEqual(eval(all_one_bits), 18446744073709551615L) + self.assertEqual(eval("-" + all_one_bits), -18446744073709551615L) + else: + self.fail("How many bits *does* this machine have???") -expect_error("077787") -expect_error("0xj") -expect_error("0x.") -expect_error("0e") -expect_same("0777", 511) -expect_same("0777L", 511) -expect_same("000777", 511) -expect_same("0xff", 255) -expect_same("0xffL", 255) -expect_same("0XfF", 255) -expect_same("0777.", 777) -expect_same("0777.0", 777) -expect_same("000000000000000000000000000000000000000000000000000777e0", 777) -expect_same("0777e1", 7770) -expect_same("0e0", 0) -expect_same("0000E-012", 0) -expect_same("09.5", 9.5) -expect_same("0777j", 777j) -expect_same("00j", 0j) -expect_same("00.0", 0) -expect_same("0e3", 0) -expect_same("090000000000000.", 90000000000000.) -expect_same("090000000000000.0000000000000000000000", 90000000000000.) -expect_same("090000000000000e0", 90000000000000.) -expect_same("090000000000000e-0", 90000000000000.) -expect_same("090000000000000j", 90000000000000j) -expect_error("090000000000000") # plain octal literal w/ decimal digit -expect_error("080000000000000") # plain octal literal w/ decimal digit -expect_error("000000000000009") # plain octal literal w/ decimal digit -expect_error("000000000000008") # plain octal literal w/ decimal digit -expect_same("000000000000007", 7) -expect_same("000000000000008.", 8.) -expect_same("000000000000009.", 9.) + def test_sequence_unpacking_error(self): + # Verify sequence packing/unpacking with "or". SF bug #757818 + i,j = (1, -1) or (-1, 1) + self.assertEqual(i, 1) + self.assertEqual(j, -1) -# Verify treatment of unary minus on negative numbers SF bug #660455 -import warnings -warnings.filterwarnings("ignore", "hex/oct constants", FutureWarning) -warnings.filterwarnings("ignore", "hex.* of negative int", FutureWarning) -# XXX Of course the following test will have to be changed in Python 2.4 -# This test is in a so the filterwarnings() can affect it -import sys -all_one_bits = '0xffffffff' -if sys.maxint != 2147483647: - all_one_bits = '0xffffffffffffffff' -exec """ -expect_same(all_one_bits, -1) -expect_same("-" + all_one_bits, 1) -""" + def test_none_assignment(self): + stmts = [ + 'None = 0', + 'None += 0', + '__builtins__.None = 0', + 'def None(): pass', + 'class None: pass', + '(a, None) = 0, 0', + 'for None in range(10): pass', + 'def f(None): pass', + ] + for stmt in stmts: + stmt += "\n" + self.assertRaises(SyntaxError, compile, stmt, 'tmp', 'single') + self.assertRaises(SyntaxError, compile, stmt, 'tmp', 'exec') -def test_main(verbose=None): - from test import test_compile - run_doctest(test_compile, verbose) + def test_import(self): + succeed = [ + 'import sys', + 'import os, sys', + 'from __future__ import nested_scopes, generators', + 'from __future__ import (nested_scopes,\ngenerators)', + 'from __future__ import (nested_scopes,\ngenerators,)', + 'from sys import stdin, stderr, stdout', + 'from sys import (stdin, stderr,\nstdout)', + 'from sys import (stdin, stderr,\nstdout,)', + 'from sys import (stdin\n, stderr, stdout)', + 'from sys import (stdin\n, stderr, stdout,)', + 'from sys import stdin as si, stdout as so, stderr as se', + 'from sys import (stdin as si, stdout as so, stderr as se)', + 'from sys import (stdin as si, stdout as so, stderr as se,)', + ] + fail = [ + 'import (os, sys)', + 'import (os), (sys)', + 'import ((os), (sys))', + 'import (sys', + 'import sys)', + 'import (os,)', + 'from (sys) import stdin', + 'from __future__ import (nested_scopes', + 'from __future__ import nested_scopes)', + 'from __future__ import nested_scopes,\ngenerators', + 'from sys import (stdin', + 'from sys import stdin)', + 'from sys import stdin, stdout,\nstderr', + 'from sys import stdin si', + 'from sys import stdin,' + 'from sys import (*)', + 'from sys import (stdin,, stdout, stderr)', + 'from sys import (stdin, stdout),', + ] + for stmt in succeed: + compile(stmt, 'tmp', 'exec') + for stmt in fail: + self.assertRaises(SyntaxError, compile, stmt, 'tmp', 'exec') + + def test_for_distinct_code_objects(self): + # SF bug 1048870 + def f(): + f1 = lambda x=1: x + f2 = lambda x=2: x + return f1, f2 + f1, f2 = f() + self.assertNotEqual(id(f1.func_code), id(f2.func_code)) + +def test_main(): + test_support.run_unittest(TestSpecifics) + +if __name__ == "__main__": + test_main() From bcannon at users.sourceforge.net Mon Apr 25 00:26:40 2005 From: bcannon at users.sourceforge.net (bcannon@users.sourceforge.net) Date: Mon Apr 25 00:26:43 2005 Subject: [Python-checkins] python/dist/src/Lib/distutils sysconfig.py, 1.63, 1.64 Message-ID: Update of /cvsroot/python/python/dist/src/Lib/distutils In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25974/Lib/distutils Modified Files: sysconfig.py Log Message: Introduced EXTRA_CFLAGS as an environment variable used by the Makefile. Meant to be used for flags that change binary compatibility. Distutils was tweaked to also use the variable if used during compilation of the interpreter. Index: sysconfig.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Lib/distutils/sysconfig.py,v retrieving revision 1.63 retrieving revision 1.64 diff -u -d -r1.63 -r1.64 --- sysconfig.py 3 Mar 2005 11:08:02 -0000 1.63 +++ sysconfig.py 24 Apr 2005 22:26:38 -0000 1.64 @@ -146,8 +146,9 @@ varies across Unices and is stored in Python's Makefile. """ if compiler.compiler_type == "unix": - (cc, cxx, opt, basecflags, ccshared, ldshared, so_ext) = \ - get_config_vars('CC', 'CXX', 'OPT', 'BASECFLAGS', 'CCSHARED', 'LDSHARED', 'SO') + (cc, cxx, opt, extra_cflags, basecflags, ccshared, ldshared, so_ext) = \ + get_config_vars('CC', 'CXX', 'OPT', 'EXTRA_CFLAGS', 'BASECFLAGS', + 'CCSHARED', 'LDSHARED', 'SO') if os.environ.has_key('CC'): cc = os.environ['CC'] @@ -171,7 +172,7 @@ opt = opt + ' ' + os.environ['CPPFLAGS'] ldshared = ldshared + ' ' + os.environ['CPPFLAGS'] - cc_cmd = cc + ' ' + opt + cc_cmd = ' '.join(str(x) for x in (cc, opt, extra_cflags) if x) compiler.set_executables( preprocessor=cpp, compiler=cc_cmd, From bcannon at users.sourceforge.net Mon Apr 25 00:26:59 2005 From: bcannon at users.sourceforge.net (bcannon@users.sourceforge.net) Date: Mon Apr 25 00:27:02 2005 Subject: [Python-checkins] python/dist/src/Misc SpecialBuilds.txt, 1.19, 1.20 NEWS, 1.1287, 1.1288 Message-ID: Update of /cvsroot/python/python/dist/src/Misc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25974/Misc Modified Files: SpecialBuilds.txt NEWS Log Message: Introduced EXTRA_CFLAGS as an environment variable used by the Makefile. Meant to be used for flags that change binary compatibility. Distutils was tweaked to also use the variable if used during compilation of the interpreter. Index: SpecialBuilds.txt =================================================================== RCS file: /cvsroot/python/python/dist/src/Misc/SpecialBuilds.txt,v retrieving revision 1.19 retrieving revision 1.20 diff -u -d -r1.19 -r1.20 --- SpecialBuilds.txt 20 Apr 2005 20:49:39 -0000 1.19 +++ SpecialBuilds.txt 24 Apr 2005 22:26:38 -0000 1.20 @@ -1,9 +1,8 @@ This file describes some special Python build types enabled via compile-time preprocessor defines. -It is best to define these options in the OPT environment variable; -``OPT="-DPy_REF_DEBUG" ./configure``. If you want the default values of -OPT to also be included you will need to add them in yourself manually. +It is best to define these options in the EXTRA_FLAGS environment variable; +``EXTRA_CFLAGS="-DPy_REF_DEBUG" ./configure``. --------------------------------------------------------------------------- Py_REF_DEBUG introduced in 1.4 Index: NEWS =================================================================== RCS file: /cvsroot/python/python/dist/src/Misc/NEWS,v retrieving revision 1.1287 retrieving revision 1.1288 diff -u -d -r1.1287 -r1.1288 --- NEWS 21 Apr 2005 21:32:00 -0000 1.1287 +++ NEWS 24 Apr 2005 22:26:38 -0000 1.1288 @@ -276,6 +276,11 @@ Build ----- +- EXTRA_CFLAGS has been introduced as an environment variable to hold compiler + flags that change binary compatibility. Changes were also made to + distutils.sysconfig to also use the environment variable when used during + compilation of the interpreter. + - SF patch 1171735: Darwin 8's headers are anal about POSIX compliance, and linking has changed (prebinding is now deprecated, and libcc_dynamic no longer exists). This configure patch makes things right. From bcannon at users.sourceforge.net Mon Apr 25 00:27:10 2005 From: bcannon at users.sourceforge.net (bcannon@users.sourceforge.net) Date: Mon Apr 25 00:27:13 2005 Subject: [Python-checkins] python/dist/src Makefile.pre.in, 1.151, 1.152 README, 1.187, 1.188 Message-ID: Update of /cvsroot/python/python/dist/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25974 Modified Files: Makefile.pre.in README Log Message: Introduced EXTRA_CFLAGS as an environment variable used by the Makefile. Meant to be used for flags that change binary compatibility. Distutils was tweaked to also use the variable if used during compilation of the interpreter. Index: Makefile.pre.in =================================================================== RCS file: /cvsroot/python/python/dist/src/Makefile.pre.in,v retrieving revision 1.151 retrieving revision 1.152 diff -u -d -r1.151 -r1.152 --- Makefile.pre.in 28 Mar 2005 23:23:46 -0000 1.151 +++ Makefile.pre.in 24 Apr 2005 22:26:37 -0000 1.152 @@ -55,7 +55,7 @@ # Compiler options OPT= @OPT@ BASECFLAGS= @BASECFLAGS@ -CFLAGS= $(BASECFLAGS) $(OPT) +CFLAGS= $(BASECFLAGS) $(OPT) $(EXTRA_CFLAGS) # Both CPPFLAGS and LDFLAGS need to contain the shell's value for setup.py to # be able to build extension modules using the directories specified in the # environment variables Index: README =================================================================== RCS file: /cvsroot/python/python/dist/src/README,v retrieving revision 1.187 retrieving revision 1.188 diff -u -d -r1.187 -r1.188 --- README 22 Feb 2005 15:33:26 -0000 1.187 +++ README 24 Apr 2005 22:26:37 -0000 1.188 @@ -827,6 +827,9 @@ Additional debugging code to help debug memory management problems can be enabled by using the --with-pydebug option to the configure script. +For flags that change binary compatibility, use the EXTRA_CFLAGS +variable. + Profiling --------- From loewis at users.sourceforge.net Mon Apr 25 09:14:06 2005 From: loewis at users.sourceforge.net (loewis@users.sourceforge.net) Date: Mon Apr 25 09:14:09 2005 Subject: [Python-checkins] python/dist/src/Misc NEWS,1.1288,1.1289 Message-ID: Update of /cvsroot/python/python/dist/src/Misc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28704/Misc Modified Files: NEWS Log Message: Make parse_makefile fallback to environment variables if nothing is defined in the makefile. Get CFLAGS from the Makefile, instead of getting OPT, BASE_CFLAGS and EXTRA_CFLAGS individually. Index: NEWS =================================================================== RCS file: /cvsroot/python/python/dist/src/Misc/NEWS,v retrieving revision 1.1288 retrieving revision 1.1289 diff -u -d -r1.1288 -r1.1289 --- NEWS 24 Apr 2005 22:26:38 -0000 1.1288 +++ NEWS 25 Apr 2005 07:13:45 -0000 1.1289 @@ -279,7 +279,7 @@ - EXTRA_CFLAGS has been introduced as an environment variable to hold compiler flags that change binary compatibility. Changes were also made to distutils.sysconfig to also use the environment variable when used during - compilation of the interpreter. + compilation of the interpreter and of C extensions through distutils. - SF patch 1171735: Darwin 8's headers are anal about POSIX compliance, and linking has changed (prebinding is now deprecated, and libcc_dynamic From loewis at users.sourceforge.net Mon Apr 25 09:14:06 2005 From: loewis at users.sourceforge.net (loewis@users.sourceforge.net) Date: Mon Apr 25 09:14:10 2005 Subject: [Python-checkins] python/dist/src/Lib/distutils sysconfig.py, 1.64, 1.65 Message-ID: Update of /cvsroot/python/python/dist/src/Lib/distutils In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28704/Lib/distutils Modified Files: sysconfig.py Log Message: Make parse_makefile fallback to environment variables if nothing is defined in the makefile. Get CFLAGS from the Makefile, instead of getting OPT, BASE_CFLAGS and EXTRA_CFLAGS individually. Index: sysconfig.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Lib/distutils/sysconfig.py,v retrieving revision 1.64 retrieving revision 1.65 diff -u -d -r1.64 -r1.65 --- sysconfig.py 24 Apr 2005 22:26:38 -0000 1.64 +++ sysconfig.py 25 Apr 2005 07:14:03 -0000 1.65 @@ -146,8 +146,8 @@ varies across Unices and is stored in Python's Makefile. """ if compiler.compiler_type == "unix": - (cc, cxx, opt, extra_cflags, basecflags, ccshared, ldshared, so_ext) = \ - get_config_vars('CC', 'CXX', 'OPT', 'EXTRA_CFLAGS', 'BASECFLAGS', + (cc, cxx, opt, cflags, ccshared, ldshared, so_ext) = \ + get_config_vars('CC', 'CXX', 'OPT', 'CFLAGS', 'CCSHARED', 'LDSHARED', 'SO') if os.environ.has_key('CC'): @@ -162,17 +162,15 @@ cpp = cc + " -E" # not always if os.environ.has_key('LDFLAGS'): ldshared = ldshared + ' ' + os.environ['LDFLAGS'] - if basecflags: - opt = basecflags + ' ' + opt if os.environ.has_key('CFLAGS'): - opt = opt + ' ' + os.environ['CFLAGS'] + cflags = opt + ' ' + os.environ['CFLAGS'] ldshared = ldshared + ' ' + os.environ['CFLAGS'] if os.environ.has_key('CPPFLAGS'): cpp = cpp + ' ' + os.environ['CPPFLAGS'] - opt = opt + ' ' + os.environ['CPPFLAGS'] + cflags = cflags + ' ' + os.environ['CPPFLAGS'] ldshared = ldshared + ' ' + os.environ['CPPFLAGS'] - cc_cmd = ' '.join(str(x) for x in (cc, opt, extra_cflags) if x) + cc_cmd = cc + ' ' + cflags compiler.set_executables( preprocessor=cpp, compiler=cc_cmd, @@ -278,25 +276,20 @@ m = _findvar1_rx.search(value) or _findvar2_rx.search(value) if m: n = m.group(1) + found = True if done.has_key(n): - after = value[m.end():] - value = value[:m.start()] + str(done[n]) + after - if "$" in after: - notdone[name] = value - else: - try: value = int(value) - except ValueError: - done[name] = string.strip(value) - else: - done[name] = value - del notdone[name] + item = str(done[n]) elif notdone.has_key(n): # get it on a subsequent round - pass + found = False + elif os.environ.has_key(n): + # do it like make: fall back to environment + item = os.environ[n] else: - done[n] = "" + done[n] = item = "" + if found: after = value[m.end():] - value = value[:m.start()] + after + value = value[:m.start()] + item + after if "$" in after: notdone[name] = value else: From loewis at users.sourceforge.net Mon Apr 25 09:14:18 2005 From: loewis at users.sourceforge.net (loewis@users.sourceforge.net) Date: Mon Apr 25 09:14:21 2005 Subject: [Python-checkins] python/dist/src setup.py,1.217,1.218 Message-ID: Update of /cvsroot/python/python/dist/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28704 Modified Files: setup.py Log Message: Make parse_makefile fallback to environment variables if nothing is defined in the makefile. Get CFLAGS from the Makefile, instead of getting OPT, BASE_CFLAGS and EXTRA_CFLAGS individually. Index: setup.py =================================================================== RCS file: /cvsroot/python/python/dist/src/setup.py,v retrieving revision 1.217 retrieving revision 1.218 diff -u -d -r1.217 -r1.218 --- setup.py 15 Apr 2005 20:32:39 -0000 1.217 +++ setup.py 25 Apr 2005 07:13:42 -0000 1.218 @@ -171,8 +171,8 @@ # unfortunately, distutils doesn't let us provide separate C and C++ # compilers if compiler is not None: - (ccshared,opt,base) = sysconfig.get_config_vars('CCSHARED','OPT','BASECFLAGS') - args['compiler_so'] = compiler + ' ' + opt + ' ' + ccshared + ' ' + base + (ccshared,cflags) = sysconfig.get_config_vars('CCSHARED','CFLAGS') + args['compiler_so'] = compiler + ' ' + ccshared + ' ' + cflags self.compiler.set_executables(**args) build_ext.build_extensions(self) From bcannon at users.sourceforge.net Tue Apr 26 05:45:32 2005 From: bcannon at users.sourceforge.net (bcannon@users.sourceforge.net) Date: Tue Apr 26 05:45:35 2005 Subject: [Python-checkins] python/dist/src/Misc NEWS,1.1289,1.1290 Message-ID: Update of /cvsroot/python/python/dist/src/Misc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16821/Misc Modified Files: NEWS Log Message: Make subclasses of int, long, complex, float, and unicode perform type conversion using the proper magic slot (e.g., __int__()). Also move conversion code out of PyNumber_*() functions in the C API into the nb_* function. Applied patch #1109424. Thanks Walter Doewald. Index: NEWS =================================================================== RCS file: /cvsroot/python/python/dist/src/Misc/NEWS,v retrieving revision 1.1289 retrieving revision 1.1290 diff -u -d -r1.1289 -r1.1290 --- NEWS 25 Apr 2005 07:13:45 -0000 1.1289 +++ NEWS 26 Apr 2005 03:45:26 -0000 1.1290 @@ -12,6 +12,14 @@ Core and builtins ----------------- +- patch #1109424: int, long, float, complex, and unicode now check for the + proper magic slot for type conversions when subclassed. Previously the + magic slot was ignored during conversion. Semantics now match the way + subclasses of str always behaved. int/long/float, conversion of an instance + to the base class has been moved the prroper nb_* magic slot and out of + PyNumber_*(). + Thanks Walter Dörwald. + - Descriptors defined in C with a PyGetSetDef structure, where the setter is NULL, now raise an AttributeError when attempting to set or delete the attribute. Previously a TypeError was raised, but this was inconsistent From bcannon at users.sourceforge.net Tue Apr 26 05:46:03 2005 From: bcannon at users.sourceforge.net (bcannon@users.sourceforge.net) Date: Tue Apr 26 05:46:07 2005 Subject: [Python-checkins] python/dist/src/Objects abstract.c, 2.135, 2.136 floatobject.c, 2.134, 2.135 intobject.c, 2.113, 2.114 longobject.c, 1.166, 1.167 object.c, 2.225, 2.226 Message-ID: Update of /cvsroot/python/python/dist/src/Objects In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16821/Objects Modified Files: abstract.c floatobject.c intobject.c longobject.c object.c Log Message: Make subclasses of int, long, complex, float, and unicode perform type conversion using the proper magic slot (e.g., __int__()). Also move conversion code out of PyNumber_*() functions in the C API into the nb_* function. Applied patch #1109424. Thanks Walter Doewald. Index: abstract.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Objects/abstract.c,v retrieving revision 2.135 retrieving revision 2.136 diff -u -d -r2.135 -r2.136 --- abstract.c 18 Dec 2004 19:00:59 -0000 2.135 +++ abstract.c 26 Apr 2005 03:45:25 -0000 2.136 @@ -951,7 +951,19 @@ Py_INCREF(o); return o; } - if (PyInt_Check(o)) { + m = o->ob_type->tp_as_number; + if (m && m->nb_int) { /* This should include subclasses of int */ + PyObject *res = m->nb_int(o); + if (res && (!PyInt_Check(res) && !PyLong_Check(res))) { + PyErr_Format(PyExc_TypeError, + "__int__ returned non-int (type %.200s)", + res->ob_type->tp_name); + Py_DECREF(res); + return NULL; + } + return res; + } + if (PyInt_Check(o)) { /* A int subclass without nb_int */ PyIntObject *io = (PyIntObject*)o; return PyInt_FromLong(io->ob_ival); } @@ -964,18 +976,6 @@ PyUnicode_GET_SIZE(o), 10); #endif - m = o->ob_type->tp_as_number; - if (m && m->nb_int) { - PyObject *res = m->nb_int(o); - if (res && (!PyInt_Check(res) && !PyLong_Check(res))) { - PyErr_Format(PyExc_TypeError, - "__int__ returned non-int (type %.200s)", - res->ob_type->tp_name); - Py_DECREF(res); - return NULL; - } - return res; - } if (!PyObject_AsCharBuffer(o, &buffer, &buffer_len)) return int_from_string((char*)buffer, buffer_len); @@ -1010,11 +1010,19 @@ if (o == NULL) return null_error(); - if (PyLong_CheckExact(o)) { - Py_INCREF(o); - return o; + m = o->ob_type->tp_as_number; + if (m && m->nb_long) { /* This should include subclasses of long */ + PyObject *res = m->nb_long(o); + if (res && (!PyInt_Check(res) && !PyLong_Check(res))) { + PyErr_Format(PyExc_TypeError, + "__long__ returned non-long (type %.200s)", + res->ob_type->tp_name); + Py_DECREF(res); + return NULL; + } + return res; } - if (PyLong_Check(o)) + if (PyLong_Check(o)) /* A long subclass without nb_long */ return _PyLong_Copy((PyLongObject *)o); if (PyString_Check(o)) /* need to do extra error checking that PyLong_FromString() @@ -1030,18 +1038,6 @@ PyUnicode_GET_SIZE(o), 10); #endif - m = o->ob_type->tp_as_number; - if (m && m->nb_long) { - PyObject *res = m->nb_long(o); - if (res && (!PyInt_Check(res) && !PyLong_Check(res))) { - PyErr_Format(PyExc_TypeError, - "__long__ returned non-long (type %.200s)", - res->ob_type->tp_name); - Py_DECREF(res); - return NULL; - } - return res; - } if (!PyObject_AsCharBuffer(o, &buffer, &buffer_len)) return long_from_string(buffer, buffer_len); @@ -1055,28 +1051,22 @@ if (o == NULL) return null_error(); - if (PyFloat_CheckExact(o)) { - Py_INCREF(o); - return o; + m = o->ob_type->tp_as_number; + if (m && m->nb_float) { /* This should include subclasses of float */ + PyObject *res = m->nb_float(o); + if (res && !PyFloat_Check(res)) { + PyErr_Format(PyExc_TypeError, + "__float__ returned non-float (type %.200s)", + res->ob_type->tp_name); + Py_DECREF(res); + return NULL; + } + return res; } - if (PyFloat_Check(o)) { + if (PyFloat_Check(o)) { /* A float subclass with nb_float == NULL */ PyFloatObject *po = (PyFloatObject *)o; return PyFloat_FromDouble(po->ob_fval); } - if (!PyString_Check(o)) { - m = o->ob_type->tp_as_number; - if (m && m->nb_float) { - PyObject *res = m->nb_float(o); - if (res && !PyFloat_Check(res)) { - PyErr_Format(PyExc_TypeError, - "__float__ returned non-float (type %.200s)", - res->ob_type->tp_name); - Py_DECREF(res); - return NULL; - } - return res; - } - } return PyFloat_FromString(o, NULL); } Index: floatobject.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Objects/floatobject.c,v retrieving revision 2.134 retrieving revision 2.135 diff -u -d -r2.134 -r2.135 --- floatobject.c 23 Sep 2004 19:22:41 -0000 2.134 +++ floatobject.c 26 Apr 2005 03:45:25 -0000 2.135 @@ -926,7 +926,10 @@ static PyObject * float_float(PyObject *v) { - Py_INCREF(v); + if (PyFloat_CheckExact(v)) + Py_INCREF(v); + else + v = PyFloat_FromDouble(((PyFloatObject *)v)->ob_fval); return v; } Index: intobject.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Objects/intobject.c,v retrieving revision 2.113 retrieving revision 2.114 diff -u -d -r2.113 -r2.114 --- intobject.c 25 Aug 2004 02:14:08 -0000 2.113 +++ intobject.c 26 Apr 2005 03:45:25 -0000 2.114 @@ -826,7 +826,10 @@ static PyObject * int_int(PyIntObject *v) { - Py_INCREF(v); + if (PyInt_CheckExact(v)) + Py_INCREF(v); + else + v = (PyIntObject *)PyInt_FromLong(v->ob_ival); return (PyObject *)v; } Index: longobject.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Objects/longobject.c,v retrieving revision 1.166 retrieving revision 1.167 diff -u -d -r1.166 -r1.167 --- longobject.c 3 Mar 2005 12:26:34 -0000 1.166 +++ longobject.c 26 Apr 2005 03:45:25 -0000 1.167 @@ -2861,7 +2861,10 @@ static PyObject * long_long(PyObject *v) { - Py_INCREF(v); + if (PyLong_CheckExact(v)) + Py_INCREF(v); + else + v = _PyLong_Copy((PyLongObject *)v); return v; } Index: object.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Objects/object.c,v retrieving revision 2.225 retrieving revision 2.226 diff -u -d -r2.225 -r2.226 --- object.c 23 Dec 2004 22:13:13 -0000 2.225 +++ object.c 26 Apr 2005 03:45:25 -0000 2.226 @@ -373,6 +373,8 @@ PyObject_Unicode(PyObject *v) { PyObject *res; + PyObject *func; + static PyObject *unicodestr; if (v == NULL) res = PyString_FromString(""); @@ -380,35 +382,32 @@ Py_INCREF(v); return v; } - if (PyUnicode_Check(v)) { - /* For a Unicode subtype that's not a Unicode object, - return a true Unicode object with the same data. */ - return PyUnicode_FromUnicode(PyUnicode_AS_UNICODE(v), - PyUnicode_GET_SIZE(v)); + /* XXX As soon as we have a tp_unicode slot, we should + check this before trying the __unicode__ + method. */ + if (unicodestr == NULL) { + unicodestr= PyString_InternFromString("__unicode__"); + if (unicodestr == NULL) + return NULL; + } + func = PyObject_GetAttr(v, unicodestr); + if (func != NULL) { + res = PyEval_CallObject(func, (PyObject *)NULL); + Py_DECREF(func); } - if (PyString_Check(v)) { - Py_INCREF(v); - res = v; - } else { - PyObject *func; - static PyObject *unicodestr; - /* XXX As soon as we have a tp_unicode slot, we should - check this before trying the __unicode__ - method. */ - if (unicodestr == NULL) { - unicodestr= PyString_InternFromString( - "__unicode__"); - if (unicodestr == NULL) - return NULL; + PyErr_Clear(); + if (PyUnicode_Check(v)) { + /* For a Unicode subtype that's didn't overwrite __unicode__, + return a true Unicode object with the same data. */ + return PyUnicode_FromUnicode(PyUnicode_AS_UNICODE(v), + PyUnicode_GET_SIZE(v)); } - func = PyObject_GetAttr(v, unicodestr); - if (func != NULL) { - res = PyEval_CallObject(func, (PyObject *)NULL); - Py_DECREF(func); + if (PyString_CheckExact(v)) { + Py_INCREF(v); + res = v; } else { - PyErr_Clear(); if (v->ob_type->tp_str != NULL) res = (*v->ob_type->tp_str)(v); else @@ -424,7 +423,7 @@ if (str) res = str; else - return NULL; + return NULL; } return res; } From bcannon at users.sourceforge.net Tue Apr 26 05:46:03 2005 From: bcannon at users.sourceforge.net (bcannon@users.sourceforge.net) Date: Tue Apr 26 05:46:08 2005 Subject: [Python-checkins] python/dist/src/Lib/test test_builtin.py, 1.40, 1.41 test_complex.py, 1.15, 1.16 test_str.py, 1.4, 1.5 test_unicode.py, 1.93, 1.94 Message-ID: Update of /cvsroot/python/python/dist/src/Lib/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16821/Lib/test Modified Files: test_builtin.py test_complex.py test_str.py test_unicode.py Log Message: Make subclasses of int, long, complex, float, and unicode perform type conversion using the proper magic slot (e.g., __int__()). Also move conversion code out of PyNumber_*() functions in the C API into the nb_* function. Applied patch #1109424. Thanks Walter Doewald. Index: test_builtin.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Lib/test/test_builtin.py,v retrieving revision 1.40 retrieving revision 1.41 diff -u -d -r1.40 -r1.41 --- test_builtin.py 11 Mar 2005 06:49:33 -0000 1.40 +++ test_builtin.py 26 Apr 2005 03:45:26 -0000 1.41 @@ -545,6 +545,37 @@ self.assertEqual(float(unicode(" 3.14 ")), 3.14) self.assertEqual(float(unicode(" \u0663.\u0661\u0664 ",'raw-unicode-escape')), 3.14) + def test_floatconversion(self): + # Make sure that calls to __float__() work properly + class Foo0: + def __float__(self): + return 42. + + class Foo1(object): + def __float__(self): + return 42. + + class Foo2(float): + def __float__(self): + return 42. + + class Foo3(float): + def __new__(cls, value=0.): + return float.__new__(cls, 2*value) + + def __float__(self): + return self + + class Foo4(float): + def __float__(self): + return 42 + + self.assertAlmostEqual(float(Foo0()), 42.) + self.assertAlmostEqual(float(Foo1()), 42.) + self.assertAlmostEqual(float(Foo2()), 42.) + self.assertAlmostEqual(float(Foo3(21)), 42.) + self.assertRaises(TypeError, float, Foo4(42)) + def test_getattr(self): import sys self.assert_(getattr(sys, 'stdout') is sys.stdout) @@ -650,6 +681,39 @@ self.assertEqual(int('0123', 0), 83) + def test_intconversion(self): + # Test __int__() + class Foo0: + def __int__(self): + return 42 + + class Foo1(object): + def __int__(self): + return 42 + + class Foo2(int): + def __int__(self): + return 42 + + class Foo3(int): + def __int__(self): + return self + + class Foo4(int): + def __int__(self): + return 42L + + class Foo5(int): + def __int__(self): + return 42. + + self.assertEqual(int(Foo0()), 42) + self.assertEqual(int(Foo1()), 42) + self.assertEqual(int(Foo2()), 42) + self.assertEqual(int(Foo3()), 0) + self.assertEqual(int(Foo4()), 42L) + self.assertRaises(TypeError, int, Foo5()) + def test_intern(self): self.assertRaises(TypeError, intern) s = "never interned before" @@ -810,6 +874,39 @@ self.assertRaises(ValueError, long, '53', 40) self.assertRaises(TypeError, long, 1, 12) + def test_longconversion(self): + # Test __long__() + class Foo0: + def __long__(self): + return 42L + + class Foo1(object): + def __long__(self): + return 42L + + class Foo2(long): + def __long__(self): + return 42L + + class Foo3(long): + def __long__(self): + return self + + class Foo4(long): + def __long__(self): + return 42 + + class Foo5(long): + def __long__(self): + return 42. + + self.assertEqual(long(Foo0()), 42L) + self.assertEqual(long(Foo1()), 42L) + self.assertEqual(long(Foo2()), 42L) + self.assertEqual(long(Foo3()), 0) + self.assertEqual(long(Foo4()), 42) + self.assertRaises(TypeError, long, Foo5()) + def test_map(self): self.assertEqual( map(None, 'hello world'), Index: test_complex.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Lib/test/test_complex.py,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- test_complex.py 22 Aug 2004 21:09:14 -0000 1.15 +++ test_complex.py 26 Apr 2005 03:45:26 -0000 1.16 @@ -273,6 +273,28 @@ self.assertAlmostEqual(complex(real=float2(17.), imag=float2(23.)), 17+23j) self.assertRaises(TypeError, complex, float2(None)) + class complex0(complex): + """Test usage of __complex__() when inheriting from 'complex'""" + def __complex__(self): + return 42j + + class complex1(complex): + """Test usage of __complex__() with a __new__() method""" + def __new__(self, value=0j): + return complex.__new__(self, 2*value) + def __complex__(self): + return self + + class complex2(complex): + """Make sure that __complex__() calls fail if anything other than a + complex is returned""" + def __complex__(self): + return None + + self.assertAlmostEqual(complex(complex0(1j)), 42j) + self.assertAlmostEqual(complex(complex1(1j)), 2j) + self.assertRaises(TypeError, complex, complex2(1j)) + def test_hash(self): for x in xrange(-30, 30): self.assertEqual(hash(x), hash(complex(x, 0))) Index: test_str.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Lib/test/test_str.py,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- test_str.py 26 Aug 2004 16:53:04 -0000 1.4 +++ test_str.py 26 Apr 2005 03:45:26 -0000 1.5 @@ -19,6 +19,69 @@ string_tests.MixinStrUnicodeUserStringTest.test_formatting(self) self.assertRaises(OverflowError, '%c'.__mod__, 0x1234) + def test_conversion(self): + # Make sure __str__() behaves properly + class Foo0: + def __unicode__(self): + return u"foo" + + class Foo1: + def __str__(self): + return "foo" + + class Foo2(object): + def __str__(self): + return "foo" + + class Foo3(object): + def __str__(self): + return u"foo" + + class Foo4(unicode): + def __str__(self): + return u"foo" + + class Foo5(str): + def __str__(self): + return u"foo" + + class Foo6(str): + def __str__(self): + return "foos" + + def __unicode__(self): + return u"foou" + + class Foo7(unicode): + def __str__(self): + return "foos" + def __unicode__(self): + return u"foou" + + class Foo8(str): + def __new__(cls, content=""): + return str.__new__(cls, 2*content) + def __str__(self): + return self + + class Foo9(str): + def __str__(self): + return "string" + def __unicode__(self): + return "not unicode" + + self.assert_(str(Foo0()).startswith("<")) # this is different from __unicode__ + self.assertEqual(str(Foo1()), "foo") + self.assertEqual(str(Foo2()), "foo") + self.assertEqual(str(Foo3()), "foo") + self.assertEqual(str(Foo4("bar")), "foo") + self.assertEqual(str(Foo5("bar")), "foo") + self.assertEqual(str(Foo6("bar")), "foos") + self.assertEqual(str(Foo7("bar")), "foos") + self.assertEqual(str(Foo8("foo")), "foofoo") + self.assertEqual(str(Foo9("foo")), "string") + self.assertEqual(unicode(Foo9("foo")), u"not unicode") + def test_main(): test_support.run_unittest(StrTest) Index: test_unicode.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Lib/test/test_unicode.py,v retrieving revision 1.93 retrieving revision 1.94 diff -u -d -r1.93 -r1.94 --- test_unicode.py 26 Aug 2004 16:53:04 -0000 1.93 +++ test_unicode.py 26 Apr 2005 03:45:26 -0000 1.94 @@ -389,7 +389,6 @@ self.assertEqual('%i%s %*.*s' % (10, 3, 5, 3, u'abc',), u'103 abc') self.assertEqual('%c' % u'a', u'a') - def test_constructor(self): # unicode(obj) tests (this maps to PyObject_Unicode() at C level) @@ -725,6 +724,69 @@ y = x.encode("raw-unicode-escape").decode("raw-unicode-escape") self.assertEqual(x, y) + def test_conversion(self): + # Make sure __unicode__() works properly + class Foo0: + def __str__(self): + return "foo" + + class Foo1: + def __unicode__(self): + return u"foo" + + class Foo2(object): + def __unicode__(self): + return u"foo" + + class Foo3(object): + def __unicode__(self): + return "foo" + + class Foo4(str): + def __unicode__(self): + return "foo" + + class Foo5(unicode): + def __unicode__(self): + return "foo" + + class Foo6(str): + def __str__(self): + return "foos" + + def __unicode__(self): + return u"foou" + + class Foo7(unicode): + def __str__(self): + return "foos" + def __unicode__(self): + return u"foou" + + class Foo8(unicode): + def __new__(cls, content=""): + return unicode.__new__(cls, 2*content) + def __unicode__(self): + return self + + class Foo9(unicode): + def __str__(self): + return "string" + def __unicode__(self): + return "not unicode" + + self.assertEqual(unicode(Foo0()), u"foo") + self.assertEqual(unicode(Foo1()), u"foo") + self.assertEqual(unicode(Foo2()), u"foo") + self.assertEqual(unicode(Foo3()), u"foo") + self.assertEqual(unicode(Foo4("bar")), u"foo") + self.assertEqual(unicode(Foo5("bar")), u"foo") + self.assertEqual(unicode(Foo6("bar")), u"foou") + self.assertEqual(unicode(Foo7("bar")), u"foou") + self.assertEqual(unicode(Foo8("foo")), u"foofoo") + self.assertEqual(str(Foo9("foo")), "string") + self.assertEqual(unicode(Foo9("foo")), u"not unicode") + def test_main(): test_support.run_unittest(UnicodeTest) From bcannon at users.sourceforge.net Tue Apr 26 05:53:15 2005 From: bcannon at users.sourceforge.net (bcannon@users.sourceforge.net) Date: Tue Apr 26 05:53:17 2005 Subject: [Python-checkins] python/dist/src/Python ast.c,1.1.2.60,1.1.2.61 Message-ID: Update of /cvsroot/python/python/dist/src/Python In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21189/Python Modified Files: Tag: ast-branch ast.c Log Message: Make sure non-SyntaxError exceptions propagate up the call chain. Also allow ast_for_atom() to return NULL. Applies patch #1189210 which fixes bug #1186345. Thanks John Ehresman. Index: ast.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Python/Attic/ast.c,v retrieving revision 1.1.2.60 retrieving revision 1.1.2.61 diff -u -d -r1.1.2.60 -r1.1.2.61 --- ast.c 15 Apr 2005 02:18:24 -0000 1.1.2.60 +++ ast.c 26 Apr 2005 03:53:12 -0000 1.1.2.61 @@ -101,6 +101,9 @@ int lineno; assert(PyErr_Occurred()); + if (!PyErr_ExceptionMatches(PyExc_SyntaxError)) + return; + PyErr_Fetch(&type, &value, &tback); errstr = PyTuple_GetItem(value, 0); if (!errstr) @@ -1512,7 +1515,8 @@ } case power: { expr_ty e = ast_for_atom(c, CHILD(n, 0)); - assert(e); + if (!e) + return NULL; if (NCH(n) == 1) return e; /* power: atom trailer* ('**' factor)* From rhettinger at users.sourceforge.net Tue Apr 26 07:18:55 2005 From: rhettinger at users.sourceforge.net (rhettinger@users.sourceforge.net) Date: Tue Apr 26 07:18:58 2005 Subject: [Python-checkins] python/dist/src/Doc/ref ref3.tex,1.123,1.124 Message-ID: Update of /cvsroot/python/python/dist/src/Doc/ref In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv845 Modified Files: ref3.tex Log Message: Fix typo. Index: ref3.tex =================================================================== RCS file: /cvsroot/python/python/dist/src/Doc/ref/ref3.tex,v retrieving revision 1.123 retrieving revision 1.124 diff -u -d -r1.123 -r1.124 --- ref3.tex 8 Mar 2005 01:10:20 -0000 1.123 +++ ref3.tex 26 Apr 2005 05:18:53 -0000 1.124 @@ -450,7 +450,7 @@ \lineiii{__module__}{The name of the module the function was defined in, or \code{None} if unavailable.}{Writable} - \lineiii{func_defaults}{Atuple containing default argument values + \lineiii{func_defaults}{A tuple containing default argument values for those arguments that have defaults, or \code{None} if no arguments have a default value}{Writable} From rhettinger at users.sourceforge.net Tue Apr 26 07:20:06 2005 From: rhettinger at users.sourceforge.net (rhettinger@users.sourceforge.net) Date: Tue Apr 26 07:20:21 2005 Subject: [Python-checkins] python/dist/src/Doc/ref ref3.tex, 1.121.2.2, 1.121.2.3 Message-ID: Update of /cvsroot/python/python/dist/src/Doc/ref In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1751 Modified Files: Tag: release24-maint ref3.tex Log Message: Fix typo. Index: ref3.tex =================================================================== RCS file: /cvsroot/python/python/dist/src/Doc/ref/ref3.tex,v retrieving revision 1.121.2.2 retrieving revision 1.121.2.3 diff -u -d -r1.121.2.2 -r1.121.2.3 --- ref3.tex 8 Mar 2005 01:08:42 -0000 1.121.2.2 +++ ref3.tex 26 Apr 2005 05:20:03 -0000 1.121.2.3 @@ -450,7 +450,7 @@ \lineiii{__module__}{The name of the module the function was defined in, or \code{None} if unavailable.}{Writable} - \lineiii{func_defaults}{Atuple containing default argument values + \lineiii{func_defaults}{A tuple containing default argument values for those arguments that have defaults, or \code{None} if no arguments have a default value}{Writable} From gvanrossum at users.sourceforge.net Wed Apr 27 09:21:41 2005 From: gvanrossum at users.sourceforge.net (gvanrossum@users.sourceforge.net) Date: Wed Apr 27 09:21:44 2005 Subject: [Python-checkins] python/nondist/peps pep-0340.txt,NONE,1.1 Message-ID: Update of /cvsroot/python/python/nondist/peps In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8461 Added Files: pep-0340.txt Log Message: Initial draft. --- NEW FILE: pep-0340.txt --- PEP: 340 Title: Anonymous Block Statements Version: $Revision: 1.1 $ Last-Modified: $Date: 2005/04/27 07:21:38 $ Author: Guido van Rossum Status: Draft Type: Standards Track Content-Type: text/plain Created: 27-Apr-2005 Post-History: Introduction This PEP proposes a new type of compound statement which can be used for resource management purposes, and a new iterator API to go with it. The new statement type is provisionally called the block-statement because the keyword to be used has not yet been chosen. This PEP competes with several other PEPs: PEP 288 (Generators Attributes and Exceptions; only the second part), PEP 310 (Reliable Acquisition/Release Pairs), and PEP 325 (Resource-Release Support for Generators). This proposal is just a strawman; we've had a heated debate about this on python-dev recently [1], and I figured it would be time to write up a precise spec in PEP form. Motivation and Use Cases TBD. Specification: the Iteration Exception Hierarchy Two new built-in exceptions are defined, and StopIteration is moved in the exception hierarchy: class Iteration(Exception): pass class StopIteration(Iteration): pass class ContinueIteration(Iteration): def __init__(self, value=None): self.value = None Specification: the __next__() Method A new method for iterators is proposed, called __next__(). It takes one optional argument, which defaults to None. If not None, the argument must be an Iteration instance. Calling the __next__() method without argument or with None is equivalent to using the old iterator API, next(). For backwards compatibility, it is recommended that iterators also implement a next() method as an alias for calling the __next__() method without an argument. Calling the __next__() method with a StopIteration instance signals the iterator that the caller wants to abort the iteration sequence; the iterator should respond by doing any necessary cleanup and raising StopIteration. Calling it with a ContinueIteration instance signals the iterator that the caller wants to continue the iteration; the ContinueIteration exception has a 'value' attribute which may be used by the iterator as a hint on what to do next. Calling it with a (base class) Iteration instance is the same as calling it with None. Specification: the next() Built-in Function This is a built-in function defined as follows: def next(itr, arg=None): nxt = getattr(itr, "__next__", None) if nxt is not None: return nxt(arg) if arg is None: return itr.next() raise TypeError("next() with arg for old-style iterator") Specification: the 'for' Loop A small change in the translation of the for-loop is proposed. The statement for VAR1 in EXPR1: BLOCK1 else: BLOCK2 will be translated as follows: itr = iter(EXPR1) arg = None while True: try: VAR1 = next(itr, arg) finally: break arg = None BLOCK1 else: BLOCK2 (However, 'it' and 'arg' are hidden from the user, their scope ends when the while-loop is exited, and they are not shared with nested or outer for-loops, and the user cannot override the built-ins referenced.) Specification: the Extended 'continue' Statement In the translation of the for-loop, inside BLOCK1, the new syntax continue EXPR2 is legal and is translated into arg = ContinueIteration(EXPR2) continue (Where 'arg' references the corresponding hidden variable from the previous section.) This is also the case in the body of the block-statement proposed below. Specification: the Anonymous Block Statement A new statement is proposed with the syntax block EXPR1 as VAR1: BLOCK1 Here, 'block' and 'as' are new keywords; EXPR1 is an arbitrary expression (but not an expression-list) and VAR1 is an arbitrary assignment target (which may be a comma-separated list). The "as VAR1" part is optional; if omitted, the assignment to VAR1 in the translation below is omitted (but the next() call is not!). The choice of the 'block' keyword is contentious; it has even been proposed not to use a keyword at all. PEP 310 uses 'with' for similar semantics, but I would like to reserve that for a with-statement similar to the one found in Pascal and VB. To sidestep this issue momentarily I'm using 'block' until we can agree on a keyword. (I just found that the C# designers don't like 'with' [2].) Note that it is left in the middle whether a block-statement represents a loop or not; this is up to the iterator, but in the most common case BLOCK1 is executed exactly once. The translation is subtly different from the translation of a for-loop: iter() is not called, so EXPR1 should already be an iterator (not just an iterable); and the iterator is guaranteed to be exhausted when the block-statement is left: itr = EXPR1 exc = arg = None ret = False while True: try: VAR1 = next(itr, arg) except StopIteration: if exc is not None: if ret: return exc else: raise exc # XXX See below break try: exc = arg = None BLOCK1 except Exception, exc: arg = StopIteration() (Again, 'it' etc. are hidden, and the user cannot override the built-ins.) The "raise exc" translation is inexact; this is supposed to re-raise the exact exception that was raised inside BLOCK1, with the same traceback. We can't use a bare raise-statement because we've just caught StopIteration. Inside BLOCK1, the following special translations apply: - "continue" and "continue EXPR2" are always legal; the latter is translated as shown earlier: arg = ContinueIteration(EXPR2) continue - "break" is always legal; it is translated into: arg = StopIteration() continue - "return EXPR3" is only legal when the block-statement is contained in a function definition; it is translated into: exc = EXPR3 ret = True arg = StopIteration() continue The net effect is that break, continue and return behave much the same as if the block-statement were a for-loop, except that the iterator gets a chance at resource cleanup before the block-statement is left. The iterator also gets a chance if the block-statement is left through raising an exception. Specification: Generator Exception Handling Generators will implement the new __next__() method API, as well as the old argument-less next() method. Generators will be allowed to have a yield statement inside a try-finally statement. The expression argument to the yield-statement will become optional (defaulting to None). The yield-statement will be allowed to be used on the right-hand side of an assignment; in that case it is referred to as yield-expression. The value of this yield-expression is None unless __next__() was called with a ContinueIteration argument; see below. A yield-expression must always be parenthesized except when it occurs at the top-level expression on the right-hand side of an assignment. So x = yield 42 x = yield x = 12 + (yield 42) x = 12 + (yield) foo(yield 42) foo(yield) are all legal, but x = 12 + yield 42 x = 12 + yield foo(yield 42, 12) foo(yield, 12) are all illegal. (Some of the edge cases are motivated by the current legality of "yield 12, 42".) When __next__() is called with a StopIteration instance argument, the yield statement that is resumed by the __next__() call will raise this StopIteration exception. The generator should re-raise this exception; it should not yield another value. When the *initial* call to __next__() receives a StopIteration instance argument, the generator's execution is aborted and the exception is re-raised without passing control to the generator's body. When __next__() is called with a ContinueIteration instance argument, the yield-expression that it resumes will return the value attribute of the argument. If it resumes a yield-statement, the value is ignored. When the *initial* call to __next__() receives a ContinueIteration instance argument, the generator's execution is started normally; the argument's value attribute is ignored. When a generator that has not yet terminated is garbage-collected (either through reference counting or by the cyclical garbage collector), its __next__() method is called once with a StopIteration instance argument. Together with the requirement that __next__() should always re-raise a StopIteration argument, this guarantees the eventual activation of any finally-clauses that were active when the generator was last suspended. Of course, under certain circumstances the generator may never be garbage-collected. This is no different than the guarantees that are made about finalizers (__del__() methods) of other objects. Note: the syntactic extensions to yield make it use very similar to that in Ruby. This is intentional. Do note that in Python the block passes a value to the generator using "continue EXPR" rather than "return EXPR", and the underlying mechanism whereby control is passed between the generator and the block is completely different. Blocks in Python are not compiled into thunks; rather, yield suspends execution of the generator's frame. Some edge cases work differently; in Python, you cannot save the block for later use, and you cannot test whether there is a block or not. Alternatives Considered TBD. Examples TBD. Acknowledgements In no useful order: Alex Martelli, Barry Warsaw, Bob Ippolito, Brett Cannon, Brian Sabbey, Doug Landauer, Fredrik Lundh, Greg Ewing, Holger Krekel, Jason Diamond, Jim Jewett, Josiah Carlson, Ka-Ping Yee, Michael Chermside, Michael Hudson, Nick Coghlan, Paul Moore, Phillip Eby, Raymond Hettinger, Samuele Pedroni, Shannon Behrens, Steven Bethard, Terry Reedy, Tim Delaney, Aahz, and others. Thanks all for a valuable discussion and ideas. References [1] http://mail.python.org/pipermail/python-dev/2005-April/052821.html [2] http://msdn.microsoft.com/vcsharp/programming/language/ask/withstatement/ From gvanrossum at users.sourceforge.net Wed Apr 27 09:26:57 2005 From: gvanrossum at users.sourceforge.net (gvanrossum@users.sourceforge.net) Date: Wed Apr 27 09:27:00 2005 Subject: [Python-checkins] python/nondist/peps pep-0000.txt,1.302,1.303 Message-ID: Update of /cvsroot/python/python/nondist/peps In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11525 Modified Files: pep-0000.txt Log Message: Add PEP 340. Index: pep-0000.txt =================================================================== RCS file: /cvsroot/python/python/nondist/peps/pep-0000.txt,v retrieving revision 1.302 retrieving revision 1.303 diff -u -d -r1.302 -r1.303 --- pep-0000.txt 20 Mar 2005 18:30:12 -0000 1.302 +++ pep-0000.txt 27 Apr 2005 07:26:55 -0000 1.303 @@ -117,6 +117,7 @@ S 336 Make None Callable McClelland S 337 Logging Usage in the Standard Library Dubner S 338 Executing modules inside packages with '-m' Coghlan + S 340 Anonymous Block Statements GvR S 754 IEEE 754 Floating Point Special Values Warnes Finished PEPs (done, implemented in CVS) @@ -374,6 +375,7 @@ S 337 Logging Usage in the Standard Library Dubner S 338 Executing modules inside packages with '-m' Coghlan I 339 How to Change CPython's Bytecode Cannon + S 340 Anonymous Block Statements GvR SR 666 Reject Foolish Indentation Creighton S 754 IEEE 754 Floating Point Special Values Warnes I 3000 Python 3.0 Plans Kuchling, Cannon From mwh at users.sourceforge.net Wed Apr 27 11:41:26 2005 From: mwh at users.sourceforge.net (mwh@users.sourceforge.net) Date: Wed Apr 27 11:41:28 2005 Subject: [Python-checkins] python/dist/src/Doc/tut tut.tex,1.269,1.270 Message-ID: Update of /cvsroot/python/python/dist/src/Doc/tut In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17764 Modified Files: tut.tex Log Message: Fix [ python-Bugs-1190599 ] dir() docs show incorrect output though not entirely how it's suggested in the bug report. Index: tut.tex =================================================================== RCS file: /cvsroot/python/python/dist/src/Doc/tut/tut.tex,v retrieving revision 1.269 retrieving revision 1.270 diff -u -d -r1.269 -r1.270 --- tut.tex 13 Feb 2005 22:50:04 -0000 1.269 +++ tut.tex 27 Apr 2005 09:41:23 -0000 1.270 @@ -2637,10 +2637,10 @@ \begin{verbatim} >>> a = [1, 2, 3, 4, 5] ->>> import fibo, sys +>>> import fibo >>> fib = fibo.fib >>> dir() -['__builtins__', '__doc__', '__file__', '__name__', 'fib', 'fib2'] +['__builtins__', '__doc__', '__file__', '__name__', 'a', 'fib'] \end{verbatim} Note that it lists all types of names: variables, modules, functions, etc. From gvanrossum at users.sourceforge.net Wed Apr 27 18:50:56 2005 From: gvanrossum at users.sourceforge.net (gvanrossum@users.sourceforge.net) Date: Wed Apr 27 18:50:59 2005 Subject: [Python-checkins] python/nondist/peps pep-0340.txt,1.1,1.2 Message-ID: Update of /cvsroot/python/python/nondist/peps In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14209 Modified Files: pep-0340.txt Log Message: Fix the logic for deciding whether to return, raise or break; renaming 'exc' to 'val'. Add public domain copyright notice. Index: pep-0340.txt =================================================================== RCS file: /cvsroot/python/python/nondist/peps/pep-0340.txt,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- pep-0340.txt 27 Apr 2005 07:21:38 -0000 1.1 +++ pep-0340.txt 27 Apr 2005 16:50:53 -0000 1.2 @@ -155,28 +155,27 @@ be exhausted when the block-statement is left: itr = EXPR1 - exc = arg = None + val = arg = None ret = False while True: try: VAR1 = next(itr, arg) except StopIteration: - if exc is not None: - if ret: - return exc - else: - raise exc # XXX See below + if ret: + return val + if val is not None: + raise val break try: - exc = arg = None + val = arg = None BLOCK1 - except Exception, exc: + except Exception, val: arg = StopIteration() - (Again, 'it' etc. are hidden, and the user cannot override the + (Again, 'itr' etc. are hidden, and the user cannot override the built-ins.) - The "raise exc" translation is inexact; this is supposed to + The "raise val" translation is inexact; this is supposed to re-raise the exact exception that was raised inside BLOCK1, with the same traceback. We can't use a bare raise-statement because we've just caught StopIteration. @@ -197,7 +196,7 @@ - "return EXPR3" is only legal when the block-statement is contained in a function definition; it is translated into: - exc = EXPR3 + val = EXPR3 ret = True arg = StopIteration() continue @@ -306,3 +305,7 @@ [1] http://mail.python.org/pipermail/python-dev/2005-April/052821.html [2] http://msdn.microsoft.com/vcsharp/programming/language/ask/withstatement/ + +Copyright + + This document has been placed in the public domain. From gvanrossum at users.sourceforge.net Wed Apr 27 19:41:48 2005 From: gvanrossum at users.sourceforge.net (gvanrossum@users.sourceforge.net) Date: Wed Apr 27 19:41:52 2005 Subject: [Python-checkins] python/nondist/peps pep-0340.txt,1.2,1.3 Message-ID: Update of /cvsroot/python/python/nondist/peps In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7012 Modified Files: pep-0340.txt Log Message: Fix a bug in the translation of a classic 'for' loop. Index: pep-0340.txt =================================================================== RCS file: /cvsroot/python/python/nondist/peps/pep-0340.txt,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- pep-0340.txt 27 Apr 2005 16:50:53 -0000 1.2 +++ pep-0340.txt 27 Apr 2005 17:41:44 -0000 1.3 @@ -94,7 +94,7 @@ while True: try: VAR1 = next(itr, arg) - finally: + except StopIteration: break arg = None BLOCK1 From gvanrossum at users.sourceforge.net Wed Apr 27 23:12:52 2005 From: gvanrossum at users.sourceforge.net (gvanrossum@users.sourceforge.net) Date: Wed Apr 27 23:12:55 2005 Subject: [Python-checkins] python/nondist/peps pep-0340.txt,1.3,1.4 Message-ID: Update of /cvsroot/python/python/nondist/peps In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29289 Modified Files: pep-0340.txt Log Message: Add an alternative __next__() API to pass arbitrary exceptions in. I like this better. Index: pep-0340.txt =================================================================== RCS file: /cvsroot/python/python/nondist/peps/pep-0340.txt,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- pep-0340.txt 27 Apr 2005 17:41:44 -0000 1.3 +++ pep-0340.txt 27 Apr 2005 21:12:49 -0000 1.4 @@ -282,6 +282,57 @@ cases work differently; in Python, you cannot save the block for later use, and you cannot test whether there is a block or not. +Specification: Alternative __next__() and Generator Exception Handling + + The above specification doesn't let the generator handle general + exceptions. If we want that, we could modify the __next__() API + to take either a value or an exception argument. When it is an + Exception instance, it is raised at the point of the resuming + yield; otherwise it is returned from the yield-expression (or + ignored by a yield-statement). Wrapping a regular value in a + ContinueIteration is then no longer necessary. The translation of + a block-statement would become: + + itr = EXPR1 + arg = val = None + ret = False + while True: + try: + VAR1 = next(itr, arg) + except StopIteration: + if ret: + return val + break + try: + arg = val = None + ret = False + BLOCK1 + except Exception, arg: + pass + + The translation of "continue EXPR2" would become: + + arg = EXPR2 + continue + + The translation of "break" inside a block-statement would become: + + arg = StopIteration() + continue + + The translation of "return EXPR3" inside a block-statement would + become: + + val = EXPR3 + arg = StopIteration() + ret = True + continue + + The translation of a for-loop would be the same as indicated + earlier (inside a for-loop only the translation of "continue + EXPR2" is changed; break and return translate to themselves in + that case). + Alternatives Considered TBD. From gvanrossum at users.sourceforge.net Wed Apr 27 23:54:30 2005 From: gvanrossum at users.sourceforge.net (gvanrossum@users.sourceforge.net) Date: Wed Apr 27 23:54:33 2005 Subject: [Python-checkins] python/nondist/peps pep-0340.txt,1.4,1.5 Message-ID: Update of /cvsroot/python/python/nondist/peps In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21381 Modified Files: pep-0340.txt Log Message: In the original translation for block-statement, reset ret = False each time before executing BLOCK1. (Thanks to Duncan Booth.) Index: pep-0340.txt =================================================================== RCS file: /cvsroot/python/python/nondist/peps/pep-0340.txt,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- pep-0340.txt 27 Apr 2005 21:12:49 -0000 1.4 +++ pep-0340.txt 27 Apr 2005 21:54:27 -0000 1.5 @@ -168,6 +168,7 @@ break try: val = arg = None + ret = False BLOCK1 except Exception, val: arg = StopIteration() @@ -344,12 +345,13 @@ Acknowledgements In no useful order: Alex Martelli, Barry Warsaw, Bob Ippolito, - Brett Cannon, Brian Sabbey, Doug Landauer, Fredrik Lundh, Greg - Ewing, Holger Krekel, Jason Diamond, Jim Jewett, Josiah Carlson, - Ka-Ping Yee, Michael Chermside, Michael Hudson, Nick Coghlan, Paul - Moore, Phillip Eby, Raymond Hettinger, Samuele Pedroni, Shannon - Behrens, Steven Bethard, Terry Reedy, Tim Delaney, Aahz, and - others. Thanks all for a valuable discussion and ideas. + Brett Cannon, Brian Sabbey, Doug Landauer, Duncan Booth, Fredrik + Lundh, Greg Ewing, Holger Krekel, Jason Diamond, Jim Jewett, + Josiah Carlson, Ka-Ping Yee, Michael Chermside, Michael Hudson, + Nick Coghlan, Paul Moore, Phillip Eby, Raymond Hettinger, Samuele + Pedroni, Shannon Behrens, Steven Bethard, Terry Reedy, Tim + Delaney, Aahz, and others. Thanks all for a valuable discussion + and ideas. References From gvanrossum at users.sourceforge.net Thu Apr 28 00:41:50 2005 From: gvanrossum at users.sourceforge.net (gvanrossum@users.sourceforge.net) Date: Thu Apr 28 00:41:57 2005 Subject: [Python-checkins] python/nondist/peps pep-0340.txt,1.5,1.6 Message-ID: Update of /cvsroot/python/python/nondist/peps In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13254 Modified Files: pep-0340.txt Log Message: Settled on an extra argument to __next__() and next() to distinguish between values and exceptions. Index: pep-0340.txt =================================================================== RCS file: /cvsroot/python/python/nondist/peps/pep-0340.txt,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- pep-0340.txt 27 Apr 2005 21:54:27 -0000 1.5 +++ pep-0340.txt 27 Apr 2005 22:41:48 -0000 1.6 @@ -287,29 +287,42 @@ The above specification doesn't let the generator handle general exceptions. If we want that, we could modify the __next__() API - to take either a value or an exception argument. When it is an - Exception instance, it is raised at the point of the resuming - yield; otherwise it is returned from the yield-expression (or - ignored by a yield-statement). Wrapping a regular value in a - ContinueIteration is then no longer necessary. The translation of - a block-statement would become: + to take either a value or an exception argument, with an + additional flag argument to distinguish between the two. When the + second argument is True, the first must be an Exception instance, + which raised at the point of the resuming yield; otherwise the + first argument is the value that is returned from the + yield-expression (or ignored by a yield-statement). Wrapping a + regular value in a ContinueIteration is then no longer necessary. + + The next() built-in would be modified likewise: + + def next(itr, arg=None, exc=False): + nxt = getattr(itr, "__next__", None) + if nxt is not None: + return nxt(arg, exc) + if arg is None and not exc: + return itr.next() + raise TypeError("next() with args for old-style iterator") + + The translation of a block-statement would become: itr = EXPR1 arg = val = None - ret = False + ret = exc = False while True: try: - VAR1 = next(itr, arg) + VAR1 = next(itr, arg, exc) except StopIteration: if ret: return val break try: arg = val = None - ret = False + ret = exc = False BLOCK1 except Exception, arg: - pass + exc = True The translation of "continue EXPR2" would become: @@ -319,6 +332,7 @@ The translation of "break" inside a block-statement would become: arg = StopIteration() + exc = True continue The translation of "return EXPR3" inside a block-statement would @@ -326,7 +340,7 @@ val = EXPR3 arg = StopIteration() - ret = True + ret = exc = True continue The translation of a for-loop would be the same as indicated From gvanrossum at users.sourceforge.net Thu Apr 28 01:10:47 2005 From: gvanrossum at users.sourceforge.net (gvanrossum@users.sourceforge.net) Date: Thu Apr 28 01:10:50 2005 Subject: [Python-checkins] python/nondist/peps pep-0340.txt,1.6,1.7 Message-ID: Update of /cvsroot/python/python/nondist/peps In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28210 Modified Files: pep-0340.txt Log Message: Advanced warning that another rewrite of the exception handling mechanics is pending. Index: pep-0340.txt =================================================================== RCS file: /cvsroot/python/python/nondist/peps/pep-0340.txt,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- pep-0340.txt 27 Apr 2005 22:41:48 -0000 1.6 +++ pep-0340.txt 27 Apr 2005 23:10:42 -0000 1.7 @@ -26,6 +26,28 @@ this on python-dev recently [1], and I figured it would be time to write up a precise spec in PEP form. +Proposal Evolution + + The discussion on python-dev has changed my mind slightly on how + exceptions should be handled, but I don't have the time to do a + full update of the PEP right now. Basically, I'm now in favor of + a variation on the exception handling proposed in the section + "Alternative __next__() and Generator Exception Handling" below. + + The added twist is that instead of adding a flag argument to + next() and __next__() to indicate whether the previous argument is + a value or an exception, we use a separate API (an __error__() + method taking an exception and perhaps a traceback) for the + exception. If an iterator doesn't implement __error__(), the + exception is just re-raised. It is expected that, apart from + generators, very few iterators will implement __error__(); one use + case would be a fast implementation of synchronized() written in + C. + + The built-in next() function only interfaces to the next() and + __next__() methods; there is no user-friendly API to call + __error__(). + Motivation and Use Cases TBD. From rhettinger at users.sourceforge.net Thu Apr 28 02:21:21 2005 From: rhettinger at users.sourceforge.net (rhettinger@users.sourceforge.net) Date: Thu Apr 28 02:21:24 2005 Subject: [Python-checkins] python/dist/src/Doc/tut tut.tex, 1.261.2.4, 1.261.2.5 Message-ID: Update of /cvsroot/python/python/dist/src/Doc/tut In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2446 Modified Files: Tag: release24-maint tut.tex Log Message: Backport 1.270 Index: tut.tex =================================================================== RCS file: /cvsroot/python/python/dist/src/Doc/tut/tut.tex,v retrieving revision 1.261.2.4 retrieving revision 1.261.2.5 diff -u -d -r1.261.2.4 -r1.261.2.5 --- tut.tex 13 Feb 2005 22:56:41 -0000 1.261.2.4 +++ tut.tex 28 Apr 2005 00:21:16 -0000 1.261.2.5 @@ -2637,10 +2637,10 @@ \begin{verbatim} >>> a = [1, 2, 3, 4, 5] ->>> import fibo, sys +>>> import fibo >>> fib = fibo.fib >>> dir() -['__builtins__', '__doc__', '__file__', '__name__', 'fib', 'fib2'] +['__builtins__', '__doc__', '__file__', '__name__', 'a', 'fib'] \end{verbatim} Note that it lists all types of names: variables, modules, functions, etc. From bcannon at users.sourceforge.net Thu Apr 28 05:32:42 2005 From: bcannon at users.sourceforge.net (bcannon@users.sourceforge.net) Date: Thu Apr 28 05:32:45 2005 Subject: [Python-checkins] python/dist/src/Python ast.c,1.1.2.61,1.1.2.62 Message-ID: Update of /cvsroot/python/python/dist/src/Python In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6295/Python Modified Files: Tag: ast-branch ast.c Log Message: Makes assignment to None (at least according to test_compile) a SyntaxError. Closes bug #1190010. Index: ast.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Python/Attic/ast.c,v retrieving revision 1.1.2.61 retrieving revision 1.1.2.62 diff -u -d -r1.1.2.61 -r1.1.2.62 --- ast.c 26 Apr 2005 03:53:12 -0000 1.1.2.61 +++ ast.c 28 Apr 2005 03:32:39 -0000 1.1.2.62 @@ -338,23 +338,6 @@ If e is a sequential type, items in sequence will also have their context set. - XXX: Exception got thrown when called with context 8 (Call_kind) while - running ``make``: - - Traceback (most recent call last): - File "./setup.py", line 4, in - __version__ = "$Revision$" - Exception: can't set context for 8 - - Another exception from running regrtest.py: - - code Lib/test/regrtest.py - XXX undetected error - Traceback (most recent call last): - File "Lib/test/regrtest.py", line 71, in - import sys - SyntaxError: can't set context for 8 - */ static int @@ -364,12 +347,20 @@ switch (e->kind) { case Attribute_kind: + if (ctx == Store && + !strcmp(PyString_AS_STRING(e->v.Attribute.attr), "None")) { + return ast_error(n, "assignment to None"); + } e->v.Attribute.ctx = ctx; break; case Subscript_kind: e->v.Subscript.ctx = ctx; break; case Name_kind: + if (ctx == Store && + !strcmp(PyString_AS_STRING(e->v.Name.id), "None")) { + return ast_error(n, "assignment to None"); + } e->v.Name.ctx = ctx; break; case List_kind: @@ -532,8 +523,13 @@ for (i = 0; i < len; i++) { const node *child = CHILD(CHILD(n, 2*i), 0); expr_ty arg; - if (TYPE(child) == NAME) + if (TYPE(child) == NAME) { + if (!strcmp(STR(child), "None")) { + ast_error(child, "assignment to None"); + return NULL; + } arg = Name(NEW_IDENTIFIER(child), Store); + } else arg = compiler_complex_args(CHILD(CHILD(n, 2*i), 1)); set_context(arg, Store, n); @@ -614,6 +610,10 @@ compiler_complex_args(CHILD(ch, 1))); } else if (TYPE(CHILD(ch, 0)) == NAME) { + if (!strcmp(STR(CHILD(ch, 0)), "None")) { + ast_error(CHILD(ch, 0), "assignment to None"); + goto error; + } /* XXX check return value of Name call */ asdl_seq_APPEND(args, Name(NEW_IDENTIFIER(CHILD(ch, 0)), Param)); @@ -621,10 +621,18 @@ i += 2; /* the name and the comma */ break; case STAR: + if (!strcmp(STR(CHILD(n, i+1)), "None")) { + ast_error(CHILD(n, i+1), "assignment to None"); + goto error; + } vararg = NEW_IDENTIFIER(CHILD(n, i+1)); i += 3; break; case DOUBLESTAR: + if (!strcmp(STR(CHILD(n, i+1)), "None")) { + ast_error(CHILD(n, i+1), "assignment to None"); + goto error; + } kwarg = NEW_IDENTIFIER(CHILD(n, i+1)); i += 3; break; @@ -779,6 +787,10 @@ name = NEW_IDENTIFIER(CHILD(n, name_i)); if (!name) goto error; + else if (!strcmp(STR(CHILD(n, name_i)), "None")) { + ast_error(CHILD(n, name_i), "assignment to None"); + goto error; + } args = ast_for_arguments(c, CHILD(n, name_i + 1)); if (!args) goto error; @@ -1752,6 +1764,13 @@ expr1 = ast_for_testlist(c, CHILD(n, 0)); if (!expr1) return NULL; + if (expr1->kind == Name_kind) { + char *var_name = PyString_AS_STRING(expr1->v.Name.id); + if (var_name[0] == 'N' && !strcmp(var_name, "None")) { + ast_error(CHILD(n, 0), "assignment to None"); + return NULL; + } + } expr2 = ast_for_testlist(c, CHILD(n, 2)); if (!expr2) @@ -1775,6 +1794,7 @@ return NULL; for (i = 0; i < NCH(n) - 2; i += 2) { expr_ty e = ast_for_testlist(c, CHILD(n, i)); + /* set context to assign */ if (!e) { asdl_seq_free(targets); @@ -2574,6 +2594,11 @@ REQ(n, classdef); + if (!strcmp(STR(CHILD(n, 1)), "None")) { + ast_error(n, "assignment to None"); + return NULL; + } + if (NCH(n) == 4) { s = ast_for_suite(c, CHILD(n, 3)); if (!s) @@ -2740,7 +2765,7 @@ #else PyObject *u, *v; char *s, *t; - t = s = *sPtr; + t = s = (char *)*sPtr; /* while (s < end && *s != '\\') s++; */ /* inefficient for u".." */ while (s < end && (*s & 0x80)) s++; *sPtr = s; @@ -2761,10 +2786,10 @@ char *p; const char *end; if (encoding == NULL) { - buf = s; + buf = (char *)s; u = NULL; } else if (strcmp(encoding, "iso-8859-1") == 0) { - buf = s; + buf = (char *)s; u = NULL; } else { /* "\XX" may become "\u005c\uHHLL" (12 bytes) */ From rhettinger at users.sourceforge.net Thu Apr 28 09:18:50 2005 From: rhettinger at users.sourceforge.net (rhettinger@users.sourceforge.net) Date: Thu Apr 28 09:18:54 2005 Subject: [Python-checkins] python/dist/src/Doc/ref ref6.tex,1.75,1.76 Message-ID: Update of /cvsroot/python/python/dist/src/Doc/ref In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23428 Modified Files: ref6.tex Log Message: SF bug #1190451: 6.9 First sentence is confusing * Fixed incorrect wording: expression->exception * Noted the specific exception reported by "raise" when the is nothing to re-raise. * Eliminated several instances of "e.g." as recommended in the style guide. Index: ref6.tex =================================================================== RCS file: /cvsroot/python/python/dist/src/Doc/ref/ref6.tex,v retrieving revision 1.75 retrieving revision 1.76 diff -u -d -r1.75 -r1.76 --- ref6.tex 1 Jan 2005 00:28:44 -0000 1.75 +++ ref6.tex 28 Apr 2005 07:18:47 -0000 1.76 @@ -204,12 +204,12 @@ \item If the target is a subscription: The primary expression in the reference is evaluated. It should yield either a mutable sequence -object (e.g., a list) or a mapping object (e.g., a dictionary). Next, +object (such as a list) or a mapping object (such as a dictionary). Next, the subscript expression is evaluated. \indexii{subscription}{assignment} \obindex{mutable} -If the primary is a mutable sequence object (e.g., a list), the subscript +If the primary is a mutable sequence object (such as a list), the subscript must yield a plain integer. If it is negative, the sequence's length is added to it. The resulting value must be a nonnegative integer less than the sequence's length, and the sequence is asked to assign @@ -219,7 +219,7 @@ \obindex{sequence} \obindex{list} -If the primary is a mapping object (e.g., a dictionary), the subscript must +If the primary is a mapping object (such as a dictionary), the subscript must have a type compatible with the mapping's key type, and the mapping is then asked to create a key/datum pair which maps the subscript to the assigned object. This can either replace an existing key/value @@ -230,7 +230,7 @@ \item If the target is a slicing: The primary expression in the reference is -evaluated. It should yield a mutable sequence object (e.g., a list). The +evaluated. It should yield a mutable sequence object (such as a list). The assigned object should be a sequence object of the same type. Next, the lower and upper bound expressions are evaluated, insofar they are present; defaults are zero and the sequence's length. The bounds @@ -251,7 +251,7 @@ messages.) WARNING: Although the definition of assignment implies that overlaps -between the left-hand side and the right-hand side are `safe' (e.g., +between the left-hand side and the right-hand side are `safe' (for example \samp{a, b = b, a} swaps two variables), overlaps \emph{within} the collection of assigned-to variables are not safe! For instance, the following program prints \samp{[0, 2]}: @@ -523,8 +523,9 @@ \end{productionlist} If no expressions are present, \keyword{raise} re-raises the last -expression that was active in the current scope. If no exception is -active in the current scope, an exception is raised indicating this error. +exception that was active in the current scope. If no exception is +active in the current scope, a \exception{Queue.Empty} exception is +raised indicating this error. \index{exception} \indexii{raising}{exception} From rhettinger at users.sourceforge.net Thu Apr 28 09:19:42 2005 From: rhettinger at users.sourceforge.net (rhettinger@users.sourceforge.net) Date: Thu Apr 28 09:19:46 2005 Subject: [Python-checkins] python/dist/src/Doc/ref ref6.tex, 1.73.2.2, 1.73.2.3 Message-ID: Update of /cvsroot/python/python/dist/src/Doc/ref In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25524 Modified Files: Tag: release24-maint ref6.tex Log Message: SF bug #1190451: 6.9 First sentence is confusing * Fixed incorrect wording: expression->exception * Noted the specific exception reported by "raise" when the is nothing to re-raise. * Eliminated several instances of "e.g." as recommended in the style guide. Index: ref6.tex =================================================================== RCS file: /cvsroot/python/python/dist/src/Doc/ref/ref6.tex,v retrieving revision 1.73.2.2 retrieving revision 1.73.2.3 diff -u -d -r1.73.2.2 -r1.73.2.3 --- ref6.tex 1 Jan 2005 00:34:55 -0000 1.73.2.2 +++ ref6.tex 28 Apr 2005 07:19:39 -0000 1.73.2.3 @@ -204,12 +204,12 @@ \item If the target is a subscription: The primary expression in the reference is evaluated. It should yield either a mutable sequence -object (e.g., a list) or a mapping object (e.g., a dictionary). Next, +object (such as a list) or a mapping object (such as a dictionary). Next, the subscript expression is evaluated. \indexii{subscription}{assignment} \obindex{mutable} -If the primary is a mutable sequence object (e.g., a list), the subscript +If the primary is a mutable sequence object (such as a list), the subscript must yield a plain integer. If it is negative, the sequence's length is added to it. The resulting value must be a nonnegative integer less than the sequence's length, and the sequence is asked to assign @@ -219,7 +219,7 @@ \obindex{sequence} \obindex{list} -If the primary is a mapping object (e.g., a dictionary), the subscript must +If the primary is a mapping object (such as a dictionary), the subscript must have a type compatible with the mapping's key type, and the mapping is then asked to create a key/datum pair which maps the subscript to the assigned object. This can either replace an existing key/value @@ -230,7 +230,7 @@ \item If the target is a slicing: The primary expression in the reference is -evaluated. It should yield a mutable sequence object (e.g., a list). The +evaluated. It should yield a mutable sequence object (such as a list). The assigned object should be a sequence object of the same type. Next, the lower and upper bound expressions are evaluated, insofar they are present; defaults are zero and the sequence's length. The bounds @@ -251,7 +251,7 @@ messages.) WARNING: Although the definition of assignment implies that overlaps -between the left-hand side and the right-hand side are `safe' (e.g., +between the left-hand side and the right-hand side are `safe' (for example \samp{a, b = b, a} swaps two variables), overlaps \emph{within} the collection of assigned-to variables are not safe! For instance, the following program prints \samp{[0, 2]}: @@ -523,8 +523,9 @@ \end{productionlist} If no expressions are present, \keyword{raise} re-raises the last -expression that was active in the current scope. If no exception is -active in the current scope, an exception is raised indicating this error. +exception that was active in the current scope. If no exception is +active in the current scope, a \exception{Queue.Empty} exception is +raised indicating this error. \index{exception} \indexii{raising}{exception} From bcannon at users.sourceforge.net Thu Apr 28 22:04:35 2005 From: bcannon at users.sourceforge.net (bcannon@users.sourceforge.net) Date: Fri Apr 29 02:33:04 2005 Subject: [Python-checkins] python/nondist/peps pep-3000.txt,1.16,1.17 Message-ID: Update of /cvsroot/python/python/nondist/peps In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18799 Modified Files: pep-3000.txt Log Message: Add mention of exceptions getting a traceback attribute. Index: pep-3000.txt =================================================================== RCS file: /cvsroot/python/python/nondist/peps/pep-3000.txt,v retrieving revision 1.16 retrieving revision 1.17 diff -u -d -r1.16 -r1.17 --- pep-3000.txt 28 Apr 2005 18:57:40 -0000 1.16 +++ pep-3000.txt 28 Apr 2005 20:04:32 -0000 1.17 @@ -61,6 +61,7 @@ loop variable will no longer be exposed [12]_ * Comparisons other than ``==`` and ``!=`` between disparate types will raise an exception unless explicitly supported by the type [6]_ +* Exceptions will grow an attribute to store the traceback [13]_ To be removed: @@ -149,6 +150,9 @@ .. [12] PEP 289 ("Generator Expressions") http://www.python.org/peps/pep-0289.html +.. [13] python-dev email ("anonymous blocks") + http://mail.python.org/pipermail/python-dev/2005-April/053060.html + Copyright ========= From bcannon at users.sourceforge.net Thu Apr 28 20:57:43 2005 From: bcannon at users.sourceforge.net (bcannon@users.sourceforge.net) Date: Fri Apr 29 02:33:05 2005 Subject: [Python-checkins] python/nondist/peps pep-3000.txt,1.15,1.16 Message-ID: Update of /cvsroot/python/python/nondist/peps In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14436 Modified Files: pep-3000.txt Log Message: Fill out some references for existing points. Index: pep-3000.txt =================================================================== RCS file: /cvsroot/python/python/nondist/peps/pep-3000.txt,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- pep-3000.txt 15 Mar 2005 19:43:34 -0000 1.15 +++ pep-3000.txt 28 Apr 2005 18:57:40 -0000 1.16 @@ -41,23 +41,14 @@ Core language ============= -* Remove distinction between int and long types. [1]_ -* True division becomes default behavior -* Make all strings be Unicode, and have a separate bytes() type. [1]_ +* Remove distinction between int and long types [1]_ +* True division becomes default behavior [10]_ +* Make all strings be Unicode, and have a separate bytes() type [1]_ * ``exec`` as a statement is not worth it -- make it a function -* Add optional declarations for static typing -* Support only new-style classes; classic classes will be gone. [1]_ -* Add a 'with' statement:: - - with self: - .foo = [1, 2, 3] - .bar(4, .foo) - -* Return iterators instead of lists - - - ``dict.keys()``, ``.values()``, ``.items()`` - - ``range()``, ``zip()`` - +* Add optional declarations for static typing [11]_ +* Support only new-style classes; classic classes will be gone [1]_ +* Return iterators instead of lists where appropriate for atomic type methods + (e.g. ``dict.keys()``, ``dict.values()``, ``dict.items()``, etc.) * Replace ``print`` by a function: ``write(x,y,z)``, ``writeln(x,y,z)`` [2]_ * Do something so you can catch multiple exceptions using ``except E1, @@ -67,13 +58,13 @@ * ``as`` becomes a keyword [5]_ * Have list comprehensions be syntactic sugar for passing an equivalent generator expression to ``list()``; as a consequence the - loop variable will no longer be exposed. + loop variable will no longer be exposed [12]_ * Comparisons other than ``==`` and ``!=`` between disparate types will raise an exception unless explicitly supported by the type [6]_ To be removed: -* The ``lambda`` statement: use nested functions [1]_, [9]_ +* The ``lambda`` statement: use nested or named functions [1]_, [9]_ * String exceptions: use instances of an Exception class [2]_ * ```x```: use ``repr(x)`` [2]_ * The ``<>`` operator: use ``!=`` instead [3]_ @@ -83,11 +74,12 @@ Built-ins ========= -* Make ``range()`` return an iterator +* Make built-ins return an iterator where appropriate (e.g. ``range()``, + ``zip()``, etc.) * Relevant functions should consume iterators (e.g. ``min()``, ``max()``) * Introduce ``trunc()``, which would call the ``__trunc__()`` method on its - argument; suggested use if for objects like float where calling ``__int__()`` + argument; suggested use is for objects like float where calling ``__int__()`` has data loss, but an integral representation is still desired [8]_ To be removed: @@ -148,6 +140,15 @@ .. [9] Guido's blog ("The fate of reduce() in Python 3000") http://www.artima.com/weblogs/viewpost.jsp?thread=98196 +.. [10] PEP 238 ("Changing the Division Operator") + http://www.python.org/peps/pep-0238.html + +.. [11] Guido's blog ("Python Optional Typechecking Redux") + http://www.artima.com/weblogs/viewpost.jsp?thread=89161 + +.. [12] PEP 289 ("Generator Expressions") + http://www.python.org/peps/pep-0289.html + Copyright ========= From gvanrossum at users.sourceforge.net Fri Apr 29 07:12:41 2005 From: gvanrossum at users.sourceforge.net (gvanrossum@users.sourceforge.net) Date: Fri Apr 29 07:12:45 2005 Subject: [Python-checkins] python/nondist/peps pep-0340.txt,1.7,1.8 Message-ID: Update of /cvsroot/python/python/nondist/peps In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7169 Modified Files: pep-0340.txt Log Message: Add motivation (supplied by Shane Hathaway). Explain what happens when a block contains a yield. Add comparison to thunks. Add examples. Index: pep-0340.txt =================================================================== RCS file: /cvsroot/python/python/nondist/peps/pep-0340.txt,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- pep-0340.txt 27 Apr 2005 23:10:42 -0000 1.7 +++ pep-0340.txt 29 Apr 2005 05:12:38 -0000 1.8 @@ -48,9 +48,53 @@ __next__() methods; there is no user-friendly API to call __error__(). -Motivation and Use Cases + Perhaps __error__() should be named __exit__(). - TBD. +Motivation and Summary + + (Thanks to Shane Hathaway -- Hi Shane!) + + Good programmers move commonly used code into reusable functions. + Sometimes, however, patterns arise in the structure of the + functions rather than the actual sequence of statements. For + example, many functions acquire a lock, execute some code specific + to that function, and unconditionally release the lock. Repeating + the locking code in every function that uses it is error prone and + makes refactoring difficult. + + Block statements provide a mechanism for encapsulating patterns of + structure. Code inside the block statement runs under the control + of an object called a block iterator. Simple block iterators + execute code before and after the code inside the block statement. + Block iterators also have the opportunity to execute the + controlled code more than once (or not at all), catch exceptions, + or receive data from the body of the block statement. + + A convenient way to write block iterators is to write a generator + (PEP 255). A generator looks a lot like a Python function, but + instead of returning a value immediately, generators pause their + execution at "yield" statements. When a generator is used as a + block iterator, the yield statement tells the Python interpreter + to suspend the block iterator, execute the block statement body, + and resume the block iterator when the body has executed. + + The Python interpreter behaves as follows when it encounters a + block statement based on a generator. First, the interpreter + instantiates the generator and begins executing it. The generator + does setup work appropriate to the pattern it encapsulates, such + as acquiring a lock, opening a file, starting a database + transaction, or starting a loop. Then the generator yields + execution to the body of the block statement using a yield + statement. When the block statement body completes, raises an + uncaught exception, or sends data back to the generator using a + continue statement, the generator resumes. At this point, the + generator can either clean up and stop or yield again, causing the + block statement body to execute again. When the generator + finishes, the interpreter leaves the block statement. + +Use Cases + + TBD. For now, see the Examples section near the end. Specification: the Iteration Exception Hierarchy @@ -230,6 +274,18 @@ block-statement is left. The iterator also gets a chance if the block-statement is left through raising an exception. + Note that a yield-statement (or a yield-expression, see below) in + a block-statement is not treated differently. It suspends the + function containing the block *without* notifying the block's + iterator. The blocks's iterator is entirely unaware of this + yield, since the local control flow doesn't actually leave the + block. In other words, it is *not* like a break, continue or + return statement. When the loop that was resumed by the yield + calls next(), the block is resumed right after the yield. The + generator finalization semantics described below guarantee (within + the limitations of all finalization semantics) that the block will + be resumed eventually. + Specification: Generator Exception Handling Generators will implement the new __next__() method API, as well @@ -370,13 +426,190 @@ EXPR2" is changed; break and return translate to themselves in that case). +Comparison to Thunks + + Alternative semantics proposed for the block-statement turn the + block into a thunk (an anonymous function that blends into the + containing scope). + + The main advantage of thunks that I can see is that you can save + the thunk for later, like a callback for a button widget (the + thunk then becomes a closure). You can't use a yield-based block + for that (except in Ruby, which uses yield syntax with a + thunk-based implementation). But I have to say that I almost see + this as an advantage: I think I'd be slightly uncomfortable seeing + a block and not knowing whether it will be executed in the normal + control flow or later. Defining an explicit nested function for + that purpose doesn't have this problem for me, because I already + know that the 'def' keyword means its body is executed later. + + The other problem with thunks is that once we think of them as the + anonymous functions they are, we're pretty much forced to say that + a return statement in a thunk returns from the thunk rather than + from the containing function. Doing it any other way would cause + major weirdness when the thunk were to survive its containing + function as a closure (perhaps continuations would help, but I'm + not about to go there :-). + + But then an IMO important use case for the resource cleanup + template pattern is lost. I routinely write code like this: + + def findSomething(self, key, default=None): + self.lock.acquire() + try: + for item in self.elements: + if item.matches(key): + return item + return default + finally: + self.lock.release() + + and I'd be bummed if I couldn't write this as: + + def findSomething(self, key, default=None): + block synchronized(self.lock): + for item in self.elements: + if item.matches(key): + return item + return default + + This particular example can be rewritten using a break: + + def findSomething(self, key, default=None): + block synchronized(self.lock): + for item in self.elements: + if item.matches(key): + break + else: + item = default + return item + + but it looks forced and the transformation isn't always that easy; + you'd be forced to rewrite your code in a single-return style + which feels too restrictive. + + Also note the semantic conundrum of a yield in a thunk -- the only + reasonable interpretation is that this turns the thunk into a + generator! + + Greg Ewing believes that thunks "would be a lot simpler, doing + just what is required without any jiggery pokery with exceptions + and break/continue/return statements. It would be easy to explain + what it does and why it's useful." + + But in order to obtain the required local variable sharing between + the thunk and the containing function, every local variable used + or set in the thunk would have to become a 'cell' (our mechanism + for sharing variables between nested scopes). Cells slow down + access compared to regular local variables: access involves an + extra C function call (PyCell_Get() or PyCell_Set()). + + Perhaps not entirely coincidentally, the last example above + (findSomething() rewritten to avoid a return inside the block) + shows that, unlike for regular nested functions, we'll want + variables *assigned to* by the thunk also to be shared with the + containing function, even if they are not assigned to outside the + thunk. + + Greg Ewing again: "generators have turned out to be more powerful, + because you can have more than one of them on the go at once. Is + there a use for that capability here?" + + I believe there are definitely uses for this; several people have + already shown how to do asynchronous light-weight threads using + generators (e.g. David Mertz quoted in PEP 288, and Fredrik + Lundh[3]). + + And finally, Greg says: "a thunk implementation has the potential + to easily handle multiple block arguments, if a suitable syntax + could ever be devised. It's hard to see how that could be done in + a general way with the generator implementation." + + However, the use cases for multiple blocks seem elusive. + Alternatives Considered TBD. Examples - TBD. + 1. A template for ensuring that a lock, acquired at the start of a + block, is released when the block is left: + + def synchronized(lock): + lock.acquire() + try: + yield + finally: + lock.release() + + Used as follows: + + block synchronized(myLock): + # Code here executes with myLock held. The lock is + # guaranteed to be released when the block is left (even + # if by an uncaught exception). + + 2. A template for opening a file that ensures the file is closed + when the block is left: + + def opening(filename, mode="r"): + f = open(filename, mode) + try: + yield f + finally: + f.close() + + Used as follows: + + block opening("/etc/passwd") as f: + for line in f: + print line.rstrip() + + 3. A template for committing or rolling back a database + transaction: + + def transactional(db): + try: + yield + except: + db.rollback() + raise + else: + db.commit() + + 4. A template that tries something up to n times: + + def auto_retry(n=3, exc=Exception): + for i in range(n): + try: + yield + return + except Exception, err: + # perhaps log exception here + continue + raise # re-raise the exception we caught earlier + + Used as follows: + + block auto_retry(3, IOError): + f = urllib.urlopen("http://python.org/peps/pep-0340.html") + print f.read() + + 5. It is possible to nest blocks and combine templates: + + def synchronized_opening(lock, filename, mode="r"): + block synchronized(lock): + block opening(filename) as f: + yield f + + Used as follows: + + block synchronized_opening("/etc/passwd", myLock) as f: + for line in f: + print line.rstrip() + + 6. Coroutine example TBD. Acknowledgements @@ -384,10 +617,10 @@ Brett Cannon, Brian Sabbey, Doug Landauer, Duncan Booth, Fredrik Lundh, Greg Ewing, Holger Krekel, Jason Diamond, Jim Jewett, Josiah Carlson, Ka-Ping Yee, Michael Chermside, Michael Hudson, - Nick Coghlan, Paul Moore, Phillip Eby, Raymond Hettinger, Samuele - Pedroni, Shannon Behrens, Steven Bethard, Terry Reedy, Tim - Delaney, Aahz, and others. Thanks all for a valuable discussion - and ideas. + Neil Schemenauer, Nick Coghlan, Paul Moore, Phillip Eby, Raymond + Hettinger, Samuele Pedroni, Shannon Behrens, Steven Bethard, Terry + Reedy, Tim Delaney, Aahz, and others. Thanks all for the valuable + discussion and ideas! References @@ -395,6 +628,9 @@ [2] http://msdn.microsoft.com/vcsharp/programming/language/ask/withstatement/ + [3] http://effbot.org/zone/asyncore-generators.htm + + Copyright This document has been placed in the public domain. From bwarsaw at users.sourceforge.net Fri Apr 29 14:12:04 2005 From: bwarsaw at users.sourceforge.net (bwarsaw@users.sourceforge.net) Date: Fri Apr 29 14:12:07 2005 Subject: [Python-checkins] python/dist/src/Lib/email Message.py, 1.32.10.6, 1.32.10.7 __init__.py, 1.29.10.2, 1.29.10.3 Message-ID: Update of /cvsroot/python/python/dist/src/Lib/email In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31703 Modified Files: Tag: release23-maint Message.py __init__.py Log Message: get_filename(), get_content_charset(): It's possible that the charset named in an RFC 2231-style header could be bogus or unknown to Python. In that case, we return the the text part of the parameter undecoded. However, in get_content_charset(), if that is not ascii, then it is an illegal charset and so we return failobj. Test cases and a version bump are included. Committing this to the Python 2.3 branch because I need to generate an email 2.5.6 release that contains these patches. I will port these fixes to Python 2.4 and 2.5 for email 3.x. Index: Message.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Lib/email/Message.py,v retrieving revision 1.32.10.6 retrieving revision 1.32.10.7 diff -u -d -r1.32.10.6 -r1.32.10.7 --- Message.py 6 Nov 2004 00:14:05 -0000 1.32.10.6 +++ Message.py 29 Apr 2005 12:12:01 -0000 1.32.10.7 @@ -1,8 +1,7 @@ -# Copyright (C) 2001,2002 Python Software Foundation -# Author: barry@zope.com (Barry Warsaw) +# Copyright (C) 2001-2005 Python Software Foundation +# Author: barry@python.org (Barry Warsaw) -"""Basic message object for the email package object model. -""" +"""Basic message object for the email package object model.""" import re import uu @@ -728,7 +727,13 @@ if isinstance(filename, TupleType): # It's an RFC 2231 encoded parameter newvalue = _unquotevalue(filename) - return unicode(newvalue[2], newvalue[0] or 'us-ascii') + try: + return unicode(newvalue[2], newvalue[0] or 'us-ascii') + # LookupError can get raised if the charset isn't known to Python. + # UnicodeError can get raised if the encoded text contains a + # character not in the charset. + except (LookupError, UnicodeError): + return newvalue[2] else: newvalue = _unquotevalue(filename.strip()) return newvalue @@ -815,7 +820,18 @@ if isinstance(charset, TupleType): # RFC 2231 encoded, so decode it, and it better end up as ascii. pcharset = charset[0] or 'us-ascii' - charset = unicode(charset[2], pcharset).encode('us-ascii') + try: + charset = unicode(charset[2], pcharset).encode('us-ascii') + # LookupError can get raised if the charset isn't known to Python. + # UnicodeError can get raised if the encoded text contains a + # character not in the charset. + except (LookupError, UnicodeError): + charset = charset[2] + # charset characters should be in us-ascii range + try: + charset = unicode(charset, 'us-ascii').encode('us-ascii') + except UnicodeError: + return failobj # RFC 2046, $4.1.2 says charsets are not case sensitive return charset.lower() Index: __init__.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Lib/email/__init__.py,v retrieving revision 1.29.10.2 retrieving revision 1.29.10.3 diff -u -d -r1.29.10.2 -r1.29.10.3 --- __init__.py 13 May 2004 22:53:25 -0000 1.29.10.2 +++ __init__.py 29 Apr 2005 12:12:02 -0000 1.29.10.3 @@ -1,10 +1,10 @@ -# Copyright (C) 2001-2004 Python Software Foundation +# Copyright (C) 2001-2005 Python Software Foundation # Author: barry@python.org (Barry Warsaw) """A package for parsing, handling, and generating email messages. """ -__version__ = '2.5.5' +__version__ = '2.5.6' __all__ = [ 'base64MIME', From bwarsaw at users.sourceforge.net Fri Apr 29 14:12:05 2005 From: bwarsaw at users.sourceforge.net (bwarsaw@users.sourceforge.net) Date: Fri Apr 29 14:12:08 2005 Subject: [Python-checkins] python/dist/src/Lib/email/test test_email.py, 1.50.10.6, 1.50.10.7 Message-ID: Update of /cvsroot/python/python/dist/src/Lib/email/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31703/test Modified Files: Tag: release23-maint test_email.py Log Message: get_filename(), get_content_charset(): It's possible that the charset named in an RFC 2231-style header could be bogus or unknown to Python. In that case, we return the the text part of the parameter undecoded. However, in get_content_charset(), if that is not ascii, then it is an illegal charset and so we return failobj. Test cases and a version bump are included. Committing this to the Python 2.3 branch because I need to generate an email 2.5.6 release that contains these patches. I will port these fixes to Python 2.4 and 2.5 for email 3.x. Index: test_email.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Lib/email/test/test_email.py,v retrieving revision 1.50.10.6 retrieving revision 1.50.10.7 diff -u -d -r1.50.10.6 -r1.50.10.7 --- test_email.py 6 Nov 2004 00:13:46 -0000 1.50.10.6 +++ test_email.py 29 Apr 2005 12:12:02 -0000 1.50.10.7 @@ -1,4 +1,4 @@ -# Copyright (C) 2001,2002,2003 Python Software Foundation +# Copyright (C) 2001-2005 Python Software Foundation # email package unit tests import os @@ -2758,6 +2758,50 @@ self.assertEqual(msg.get_content_charset(), 'this is even more ***fun*** is it not.pdf') + def test_rfc2231_bad_encoding_in_filename(self): + m = '''\ +Content-Disposition: inline; +\tfilename*0="bogus'xx'This%20is%20even%20more%20"; +\tfilename*1="%2A%2A%2Afun%2A%2A%2A%20"; +\tfilename*2="is it not.pdf" + +''' + msg = email.message_from_string(m) + self.assertEqual(msg.get_filename(), + 'This is even more ***fun*** is it not.pdf') + + def test_rfc2231_bad_encoding_in_charset(self): + m = """\ +Content-Type: text/plain; charset*=bogus''utf-8%E2%80%9D + +""" + msg = email.message_from_string(m) + # This should return None because non-ascii characters in the charset + # are not allowed. + self.assertEqual(msg.get_content_charset(), None) + + def test_rfc2231_bad_character_in_charset(self): + m = """\ +Content-Type: text/plain; charset*=ascii''utf-8%E2%80%9D + +""" + msg = email.message_from_string(m) + # This should return None because non-ascii characters in the charset + # are not allowed. + self.assertEqual(msg.get_content_charset(), None) + + def test_rfc2231_bad_character_in_filename(self): + m = '''\ +Content-Disposition: inline; +\tfilename*0="ascii'xx'This%20is%20even%20more%20"; +\tfilename*1="%2A%2A%2Afun%2A%2A%2A%20"; +\tfilename*2="is it not.pdf%E2" + +''' + msg = email.message_from_string(m) + self.assertEqual(msg.get_filename(), + 'This is even more ***fun*** is it not.pdf\xe2') + def _testclasses(): From montanaro at users.sourceforge.net Fri Apr 29 16:44:33 2005 From: montanaro at users.sourceforge.net (montanaro@users.sourceforge.net) Date: Fri Apr 29 16:44:37 2005 Subject: [Python-checkins] python/nondist/peps pep-0340.txt,1.8,1.9 Message-ID: Update of /cvsroot/python/python/nondist/peps In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16592 Modified Files: pep-0340.txt Log Message: typo Index: pep-0340.txt =================================================================== RCS file: /cvsroot/python/python/nondist/peps/pep-0340.txt,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- pep-0340.txt 29 Apr 2005 05:12:38 -0000 1.8 +++ pep-0340.txt 29 Apr 2005 14:44:31 -0000 1.9 @@ -167,7 +167,7 @@ else: BLOCK2 - (However, 'it' and 'arg' are hidden from the user, their scope + (However, 'itr' and 'arg' are hidden from the user, their scope ends when the while-loop is exited, and they are not shared with nested or outer for-loops, and the user cannot override the built-ins referenced.) From montanaro at users.sourceforge.net Fri Apr 29 17:23:36 2005 From: montanaro at users.sourceforge.net (montanaro@users.sourceforge.net) Date: Fri Apr 29 17:23:39 2005 Subject: [Python-checkins] python/nondist/peps pep-0340.txt,1.9,1.10 Message-ID: Update of /cvsroot/python/python/nondist/peps In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4754 Modified Files: pep-0340.txt Log Message: typos Index: pep-0340.txt =================================================================== RCS file: /cvsroot/python/python/nondist/peps/pep-0340.txt,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- pep-0340.txt 29 Apr 2005 14:44:31 -0000 1.9 +++ pep-0340.txt 29 Apr 2005 15:23:34 -0000 1.10 @@ -277,7 +277,7 @@ Note that a yield-statement (or a yield-expression, see below) in a block-statement is not treated differently. It suspends the function containing the block *without* notifying the block's - iterator. The blocks's iterator is entirely unaware of this + iterator. The block's iterator is entirely unaware of this yield, since the local control flow doesn't actually leave the block. In other words, it is *not* like a break, continue or return statement. When the loop that was resumed by the yield @@ -351,7 +351,7 @@ garbage-collected. This is no different than the guarantees that are made about finalizers (__del__() methods) of other objects. - Note: the syntactic extensions to yield make it use very similar + Note: the syntactic extensions to yield make its use very similar to that in Ruby. This is intentional. Do note that in Python the block passes a value to the generator using "continue EXPR" rather than "return EXPR", and the underlying mechanism whereby control From gvanrossum at users.sourceforge.net Fri Apr 29 19:13:26 2005 From: gvanrossum at users.sourceforge.net (gvanrossum@users.sourceforge.net) Date: Fri Apr 29 19:13:29 2005 Subject: [Python-checkins] python/nondist/peps pep-0340.txt,1.10,1.11 Message-ID: Update of /cvsroot/python/python/nondist/peps In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31649 Modified Files: pep-0340.txt Log Message: Mention else-clauses; the else-clause on the translation of the for-loop was broken, and the break-statement probabyl shouldn't have one. Index: pep-0340.txt =================================================================== RCS file: /cvsroot/python/python/nondist/peps/pep-0340.txt,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- pep-0340.txt 29 Apr 2005 15:23:34 -0000 1.10 +++ pep-0340.txt 29 Apr 2005 17:13:08 -0000 1.11 @@ -150,8 +150,6 @@ for VAR1 in EXPR1: BLOCK1 - else: - BLOCK2 will be translated as follows: @@ -164,14 +162,16 @@ break arg = None BLOCK1 - else: - BLOCK2 (However, 'itr' and 'arg' are hidden from the user, their scope ends when the while-loop is exited, and they are not shared with nested or outer for-loops, and the user cannot override the built-ins referenced.) + I'm leaving the translation of an else-clause up to the reader; + note that you can't simply affix the else-clause to the while-loop + since it is always broken out. + Specification: the Extended 'continue' Statement In the translation of the for-loop, inside BLOCK1, the new syntax @@ -286,6 +286,12 @@ the limitations of all finalization semantics) that the block will be resumed eventually. + I haven't decided yet whether the block-statement should also + allow an optional else-clause, like the for-loop. I think it + would be confusing, and emphasize the "loopiness" of the + block-statement, while I want to emphasize its *difference* from a + for-loop. + Specification: Generator Exception Handling Generators will implement the new __next__() method API, as well @@ -618,9 +624,9 @@ Lundh, Greg Ewing, Holger Krekel, Jason Diamond, Jim Jewett, Josiah Carlson, Ka-Ping Yee, Michael Chermside, Michael Hudson, Neil Schemenauer, Nick Coghlan, Paul Moore, Phillip Eby, Raymond - Hettinger, Samuele Pedroni, Shannon Behrens, Steven Bethard, Terry - Reedy, Tim Delaney, Aahz, and others. Thanks all for the valuable - discussion and ideas! + Hettinger, Samuele Pedroni, Shannon Behrens, Skip Montanaro, + Steven Bethard, Terry Reedy, Tim Delaney, Aahz, and others. + Thanks all for the valuable contributions! References From gvanrossum at users.sourceforge.net Fri Apr 29 20:51:06 2005 From: gvanrossum at users.sourceforge.net (gvanrossum@users.sourceforge.net) Date: Fri Apr 29 20:51:09 2005 Subject: [Python-checkins] python/nondist/peps pep-0340.txt,1.11,1.12 Message-ID: Update of /cvsroot/python/python/nondist/peps In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26665 Modified Files: pep-0340.txt Log Message: Add a section of loose ends. Index: pep-0340.txt =================================================================== RCS file: /cvsroot/python/python/nondist/peps/pep-0340.txt,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- pep-0340.txt 29 Apr 2005 17:13:08 -0000 1.11 +++ pep-0340.txt 29 Apr 2005 18:51:03 -0000 1.12 @@ -36,19 +36,19 @@ The added twist is that instead of adding a flag argument to next() and __next__() to indicate whether the previous argument is - a value or an exception, we use a separate API (an __error__() + a value or an exception, we use a separate API (an __exit__() method taking an exception and perhaps a traceback) for the - exception. If an iterator doesn't implement __error__(), the + exception. If an iterator doesn't implement __exit__(), the exception is just re-raised. It is expected that, apart from - generators, very few iterators will implement __error__(); one use + generators, very few iterators will implement __exit__(); one use case would be a fast implementation of synchronized() written in C. The built-in next() function only interfaces to the next() and __next__() methods; there is no user-friendly API to call - __error__(). - - Perhaps __error__() should be named __exit__(). + __exit__(). (Or perhaps calling next(itr, exc, traceback) would + call itr.__exit__(exc, traceback) if itr has an __exit__ method + and otherwise raise exc.__class__, exc, traceback?) Motivation and Summary @@ -432,6 +432,32 @@ EXPR2" is changed; break and return translate to themselves in that case). +Loose Ends + + These are things that need to be resolved before accepting the + PEP. + + - Fill in the remaining TBD sections. + + - Address Phillip Eby's proposal to have the block-statement use + an entirely different API than the for-loop, to differentiate + between the two (a generator would have to be wrapped in a + decorator to make it support the block API). + + - Decide on the keyword ('block', 'with', '@', nothing, or + something else?). + + - Phillip Eby wants a way to pass tracebacks along with + exceptions. + + - The translation for the for-loop's else-clause. + + - Whether a block-statement should allow an else-clause. + + - Which API to use to pass in an exception: itr.__next__(exc), + itr.__next__(exc, True) or itr.__exit__(exc[, traceback]). + Hmm..., perhaps itr.__next__(exc, traceback)? + Comparison to Thunks Alternative semantics proposed for the block-statement turn the From gvanrossum at users.sourceforge.net Sat Apr 30 02:20:38 2005 From: gvanrossum at users.sourceforge.net (gvanrossum@users.sourceforge.net) Date: Sat Apr 30 02:20:41 2005 Subject: [Python-checkins] python/dist/src/Lib SocketServer.py,1.38,1.39 Message-ID: Update of /cvsroot/python/python/dist/src/Lib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15954 Modified Files: SocketServer.py Log Message: Fixed a typo in docstring I happened upon. Index: SocketServer.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Lib/SocketServer.py,v retrieving revision 1.38 retrieving revision 1.39 diff -u -d -r1.38 -r1.39 --- SocketServer.py 31 Dec 2004 19:15:26 -0000 1.38 +++ SocketServer.py 30 Apr 2005 00:20:35 -0000 1.39 @@ -50,7 +50,7 @@ unix server classes. Forking and threading versions of each type of server can be created -using the ForkingServer and ThreadingServer mix-in classes. For +using the ForkingMixIn and ThreadingMixIn mix-in classes. For instance, a threading UDP server class is created as follows: class ThreadingUDPServer(ThreadingMixIn, UDPServer): pass From bcannon at users.sourceforge.net Sat Apr 30 07:50:21 2005 From: bcannon at users.sourceforge.net (bcannon@users.sourceforge.net) Date: Sat Apr 30 07:50:24 2005 Subject: [Python-checkins] python/dist/src/Lib/test test_binop.py,1.7,1.8 Message-ID: Update of /cvsroot/python/python/dist/src/Lib/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19751/Lib/test Modified Files: test_binop.py Log Message: Fix error in a docstring where a single quote started the docstring but triple quote ended it. Closes bug #1192777. Thanks Christopher Smith. Index: test_binop.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Lib/test/test_binop.py,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- test_binop.py 23 Jul 2002 19:03:45 -0000 1.7 +++ test_binop.py 30 Apr 2005 05:50:19 -0000 1.8 @@ -178,7 +178,7 @@ return (x, self - other * x) def __rdivmod__(self, other): - "Divide two Rats, returning quotient and remainder (reversed args).""" + """Divide two Rats, returning quotient and remainder (reversed args).""" if isint(other): other = Rat(other) elif not isRat(other): From bcannon at users.sourceforge.net Sat Apr 30 07:52:16 2005 From: bcannon at users.sourceforge.net (bcannon@users.sourceforge.net) Date: Sat Apr 30 07:52:20 2005 Subject: [Python-checkins] python/dist/src/Lib/test test_binop.py, 1.7, 1.7.20.1 Message-ID: Update of /cvsroot/python/python/dist/src/Lib/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20701/Lib/test Modified Files: Tag: release24-maint test_binop.py Log Message: Fix a docstring with mismatched opening and closing quotes. Backport of fix for bug #1192777. Index: test_binop.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Lib/test/test_binop.py,v retrieving revision 1.7 retrieving revision 1.7.20.1 diff -u -d -r1.7 -r1.7.20.1 --- test_binop.py 23 Jul 2002 19:03:45 -0000 1.7 +++ test_binop.py 30 Apr 2005 05:51:59 -0000 1.7.20.1 @@ -178,7 +178,7 @@ return (x, self - other * x) def __rdivmod__(self, other): - "Divide two Rats, returning quotient and remainder (reversed args).""" + """Divide two Rats, returning quotient and remainder (reversed args).""" if isint(other): other = Rat(other) elif not isRat(other): From rhettinger at users.sourceforge.net Sat Apr 30 11:02:54 2005 From: rhettinger at users.sourceforge.net (rhettinger@users.sourceforge.net) Date: Sat Apr 30 11:02:55 2005 Subject: [Python-checkins] python/dist/src/Lib random.py,1.70,1.71 Message-ID: Update of /cvsroot/python/python/dist/src/Lib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15004 Modified Files: random.py Log Message: SF patch #1191489: Simplify logic in random.py Index: random.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Lib/random.py,v retrieving revision 1.70 retrieving revision 1.71 diff -u -d -r1.70 -r1.71 --- random.py 3 Jan 2005 07:33:16 -0000 1.70 +++ random.py 30 Apr 2005 09:02:51 -0000 1.71 @@ -345,7 +345,7 @@ # Math Software, 3, (1977), pp257-260. random = self.random - while True: + while 1: u1 = random() u2 = 1.0 - random() z = NV_MAGICCONST*(u1-0.5)/u2 @@ -415,7 +415,7 @@ b = (a - _sqrt(2.0 * a))/(2.0 * kappa) r = (1.0 + b * b)/(2.0 * b) - while True: + while 1: u1 = random() z = _cos(_pi * u1) @@ -424,7 +424,7 @@ u2 = random() - if not (u2 >= c * (2.0 - c) and u2 > c * _exp(1.0 - c)): + if u2 < c * (2.0 - c) or u2 <= c * _exp(1.0 - c): break u3 = random() @@ -462,7 +462,7 @@ bbb = alpha - LOG4 ccc = alpha + ainv - while True: + while 1: u1 = random() if not 1e-7 < u1 < .9999999: continue @@ -485,18 +485,19 @@ # Uses ALGORITHM GS of Statistical Computing - Kennedy & Gentle - while True: + while 1: u = random() b = (_e + alpha)/_e p = b*u if p <= 1.0: - x = pow(p, 1.0/alpha) + x = p ** (1.0/alpha) else: - # p > 1 x = -_log((b-p)/alpha) u1 = random() - if not (((p <= 1.0) and (u1 > _exp(-x))) or - ((p > 1) and (u1 > pow(x, alpha - 1.0)))): + if p > 1.0: + if u1 <= x ** (alpha - 1.0): + break + elif u1 <= _exp(-x): break return x * beta From rhettinger at users.sourceforge.net Sat Apr 30 23:25:22 2005 From: rhettinger at users.sourceforge.net (rhettinger@users.sourceforge.net) Date: Sat Apr 30 23:25:24 2005 Subject: [Python-checkins] python/dist/src/Misc developers.txt,1.10,1.11 Message-ID: Update of /cvsroot/python/python/dist/src/Misc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5865 Modified Files: developers.txt Log Message: Update Paul Prescod's permissions. Index: developers.txt =================================================================== RCS file: /cvsroot/python/python/dist/src/Misc/developers.txt,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- developers.txt 13 Apr 2005 22:04:21 -0000 1.10 +++ developers.txt 30 Apr 2005 21:25:19 -0000 1.11 @@ -37,6 +37,8 @@ Permissions Dropped on Request ------------------------------ +- Paul Prescod sent a drop request. 30 Apr 2005 RDH + - Finn Bock sent a drop request. 13 Apr 2005 RDH - Eric Price sent a drop request. 10 Apr 2005 RDH