[Python-checkins] r73134 - in python/branches/tk_and_idle_maintenance: Doc/howto/regex.rst Lib/distutils/dist.py Lib/distutils/tests/test_dist.py Lib/ipaddr.py Lib/test/test_trace.py Misc/NEWS Objects/frameobject.c Tools/msi/msi.py

guilherme.polo python-checkins at python.org
Tue Jun 2 03:25:38 CEST 2009


Author: guilherme.polo
Date: Tue Jun  2 03:25:38 2009
New Revision: 73134

Log:
Merged revisions 73089,73101,73109,73114,73121,73129 via svnmerge from 
svn+ssh://pythondev/python/trunk

........
  r73089 | andrew.kuchling | 2009-05-31 21:14:19 -0300 (Sun, 31 May 2009) | 1 line
  
  The class for regexes isn't called RegexObject any more; correct the text
........
  r73101 | martin.v.loewis | 2009-06-01 01:10:03 -0300 (Mon, 01 Jun 2009) | 2 lines
  
  Issue #6158: package Sine-1000Hz-300ms.aif.
........
  r73109 | gregory.p.smith | 2009-06-01 14:40:41 -0300 (Mon, 01 Jun 2009) | 6 lines
  
  Sync up __version__ number with the version of the ipaddr-py project this
  library came from that it matches.
  
  Remove the former apache license text now that its been contributed to PSF to
  avoid confusion.
........
  r73114 | amaury.forgeotdarc | 2009-06-01 17:53:18 -0300 (Mon, 01 Jun 2009) | 3 lines
  
  #4547: When debugging a very large function, it was not always
  possible to update the lineno attribute of the current frame.
........
  r73121 | tarek.ziade | 2009-06-01 19:22:13 -0300 (Mon, 01 Jun 2009) | 1 line
  
  improved distutils.dist test coverage, pep-8 compliancy
........
  r73129 | antoine.pitrou | 2009-06-01 20:23:16 -0300 (Mon, 01 Jun 2009) | 3 lines
  
  Fix compilation error with gcc 4.3.2
........


Modified:
   python/branches/tk_and_idle_maintenance/   (props changed)
   python/branches/tk_and_idle_maintenance/Doc/howto/regex.rst
   python/branches/tk_and_idle_maintenance/Lib/distutils/dist.py
   python/branches/tk_and_idle_maintenance/Lib/distutils/tests/test_dist.py
   python/branches/tk_and_idle_maintenance/Lib/ipaddr.py
   python/branches/tk_and_idle_maintenance/Lib/test/test_trace.py
   python/branches/tk_and_idle_maintenance/Misc/NEWS
   python/branches/tk_and_idle_maintenance/Objects/frameobject.c
   python/branches/tk_and_idle_maintenance/Tools/msi/msi.py

Modified: python/branches/tk_and_idle_maintenance/Doc/howto/regex.rst
==============================================================================
--- python/branches/tk_and_idle_maintenance/Doc/howto/regex.rst	(original)
+++ python/branches/tk_and_idle_maintenance/Doc/howto/regex.rst	Tue Jun  2 03:25:38 2009
@@ -257,7 +257,7 @@
 Compiling Regular Expressions
 -----------------------------
 
-Regular expressions are compiled into :class:`RegexObject` instances, which have
+Regular expressions are compiled into pattern objects, which have
 methods for various operations such as searching for pattern matches or
 performing string substitutions. ::
 
@@ -336,7 +336,7 @@
 ------------------
 
 Once you have an object representing a compiled regular expression, what do you
-do with it?  :class:`RegexObject` instances have several methods and attributes.
+do with it?  Pattern objects have several methods and attributes.
 Only the most significant ones will be covered here; consult the :mod:`re` docs
 for a complete listing.
 
@@ -427,8 +427,8 @@
 and :meth:`end` return the starting and ending index of the match. :meth:`span`
 returns both start and end indexes in a single tuple.  Since the :meth:`match`
 method only checks if the RE matches at the start of a string, :meth:`start`
-will always be zero.  However, the :meth:`search` method of :class:`RegexObject`
-instances scans through the string, so  the match may not start at zero in that
+will always be zero.  However, the :meth:`search` method of patterns
+scans through the string, so  the match may not start at zero in that
 case. ::
 
    >>> print p.match('::: message')
@@ -450,7 +450,7 @@
    else:
        print 'No match'
 
-Two :class:`RegexObject` methods return all of the matches for a pattern.
+Two pattern methods return all of the matches for a pattern.
 :meth:`findall` returns a list of matching strings::
 
    >>> p = re.compile('\d+')
@@ -475,10 +475,10 @@
 Module-Level Functions
 ----------------------
 
-You don't have to create a :class:`RegexObject` and call its methods; the
+You don't have to create a pattern object and call its methods; the
 :mod:`re` module also provides top-level functions called :func:`match`,
 :func:`search`, :func:`findall`, :func:`sub`, and so forth.  These functions
-take the same arguments as the corresponding :class:`RegexObject` method, with
+take the same arguments as the corresponding pattern method, with
 the RE string added as the first argument, and still return either ``None`` or a
 :class:`MatchObject` instance. ::
 
@@ -487,12 +487,12 @@
    >>> re.match(r'From\s+', 'From amk Thu May 14 19:12:10 1998')
    <re.MatchObject instance at 80c5978>
 
-Under the hood, these functions simply produce a :class:`RegexObject` for you
+Under the hood, these functions simply create a pattern object for you
 and call the appropriate method on it.  They also store the compiled object in a
 cache, so future calls using the same RE are faster.
 
 Should you use these module-level functions, or should you get the
-:class:`RegexObject` and call its methods yourself?  That choice depends on how
+pattern and call its methods yourself?  That choice depends on how
 frequently the RE will be used, and on your personal coding style.  If the RE is
 being used at only one point in the code, then the module functions are probably
 more convenient.  If a program contains a lot of regular expressions, or re-uses
@@ -1030,7 +1030,7 @@
 
 Up to this point, we've simply performed searches against a static string.
 Regular expressions are also commonly used to modify strings in various ways,
-using the following :class:`RegexObject` methods:
+using the following pattern methods:
 
 +------------------+-----------------------------------------------+
 | Method/Attribute | Purpose                                       |
@@ -1050,7 +1050,7 @@
 Splitting Strings
 -----------------
 
-The :meth:`split` method of a :class:`RegexObject` splits a string apart
+The :meth:`split` method of a pattern splits a string apart
 wherever the RE matches, returning a list of the pieces. It's similar to the
 :meth:`split` method of strings but provides much more generality in the
 delimiters that you can split by; :meth:`split` only supports splitting by
@@ -1195,10 +1195,10 @@
    'Call 0xffd2 for printing, 0xc000 for user code.'
 
 When using the module-level :func:`re.sub` function, the pattern is passed as
-the first argument.  The pattern may be a string or a :class:`RegexObject`; if
+the first argument.  The pattern may be provided as an object or as a string; if
 you need to specify regular expression flags, you must either use a
-:class:`RegexObject` as the first parameter, or use embedded modifiers in the
-pattern, e.g.  ``sub("(?i)b+", "x", "bbbb BBBB")`` returns ``'x x'``.
+pattern object as the first parameter, or use embedded modifiers in the
+pattern string, e.g. ``sub("(?i)b+", "x", "bbbb BBBB")`` returns ``'x x'``.
 
 
 Common Problems

Modified: python/branches/tk_and_idle_maintenance/Lib/distutils/dist.py
==============================================================================
--- python/branches/tk_and_idle_maintenance/Lib/distutils/dist.py	(original)
+++ python/branches/tk_and_idle_maintenance/Lib/distutils/dist.py	Tue Jun  2 03:25:38 2009
@@ -6,8 +6,7 @@
 
 __revision__ = "$Id$"
 
-import sys, os, string, re
-from types import *
+import sys, os, re
 
 try:
     import warnings
@@ -251,7 +250,7 @@
 
             # Now work on the rest of the attributes.  Any attribute that's
             # not already defined is invalid!
-            for (key,val) in attrs.items():
+            for (key, val) in attrs.items():
                 if hasattr(self.metadata, "set_" + key):
                     getattr(self.metadata, "set_" + key)(val)
                 elif hasattr(self.metadata, key):
@@ -286,22 +285,24 @@
             commands.sort()
 
         if header is not None:
-            print indent + header
+            self.announce(indent + header)
             indent = indent + "  "
 
         if not commands:
-            print indent + "no commands known yet"
+            self.announce(indent + "no commands known yet")
             return
 
         for cmd_name in commands:
             opt_dict = self.command_options.get(cmd_name)
             if opt_dict is None:
-                print indent + "no option dict for '%s' command" % cmd_name
+                self.announce(indent +
+                              "no option dict for '%s' command" % cmd_name)
             else:
-                print indent + "option dict for '%s' command:" % cmd_name
+                self.announce(indent +
+                              "option dict for '%s' command:" % cmd_name)
                 out = pformat(opt_dict)
-                for line in string.split(out, "\n"):
-                    print indent + "  " + line
+                for line in out.split('\n'):
+                    self.announce(indent + "  " + line)
 
     # -- Config file finding/parsing methods ---------------------------
 
@@ -352,11 +353,13 @@
         if filenames is None:
             filenames = self.find_config_files()
 
-        if DEBUG: print "Distribution.parse_config_files():"
+        if DEBUG:
+            self.announce("Distribution.parse_config_files():")
 
         parser = ConfigParser()
         for filename in filenames:
-            if DEBUG: print "  reading", filename
+            if DEBUG:
+                self.announce("  reading", filename)
             parser.read(filename)
             for section in parser.sections():
                 options = parser.options(section)
@@ -365,7 +368,7 @@
                 for opt in options:
                     if opt != '__name__':
                         val = parser.get(section,opt)
-                        opt = string.replace(opt, '-', '_')
+                        opt = opt.replace('-', '_')
                         opt_dict[opt] = (filename, val)
 
             # Make the ConfigParser forget everything (so we retain
@@ -503,7 +506,7 @@
         # Also make sure that the command object provides a list of its
         # known options.
         if not (hasattr(cmd_class, 'user_options') and
-                type(cmd_class.user_options) is ListType):
+                isinstance(cmd_class.user_options, list)):
             raise DistutilsClassError, \
                   ("command class %s must provide " +
                    "'user_options' attribute (a list of tuples)") % \
@@ -519,7 +522,7 @@
         # Check for help_options in command class.  They have a different
         # format (tuple of four) so we need to preprocess them here.
         if (hasattr(cmd_class, 'help_options') and
-            type(cmd_class.help_options) is ListType):
+            isinstance(cmd_class.help_options, list)):
             help_options = fix_help_options(cmd_class.help_options)
         else:
             help_options = []
@@ -537,14 +540,11 @@
             return
 
         if (hasattr(cmd_class, 'help_options') and
-            type(cmd_class.help_options) is ListType):
+            isinstance(cmd_class.help_options, list)):
             help_option_found=0
             for (help_option, short, desc, func) in cmd_class.help_options:
                 if hasattr(opts, parser.get_attr_name(help_option)):
                     help_option_found=1
-                    #print "showing help for option %s of command %s" % \
-                    #      (help_option[0],cmd_class)
-
                     if callable(func):
                         func()
                     else:
@@ -569,17 +569,13 @@
         instance, analogous to the .finalize_options() method of Command
         objects.
         """
-        keywords = self.metadata.keywords
-        if keywords is not None:
-            if type(keywords) is StringType:
-                keywordlist = string.split(keywords, ',')
-                self.metadata.keywords = map(string.strip, keywordlist)
-
-        platforms = self.metadata.platforms
-        if platforms is not None:
-            if type(platforms) is StringType:
-                platformlist = string.split(platforms, ',')
-                self.metadata.platforms = map(string.strip, platformlist)
+        for attr in ('keywords', 'platforms'):
+            value = getattr(self.metadata, attr)
+            if value is None:
+                continue
+            if isinstance(value, str):
+                value = [elm.strip() for elm in value.split(',')]
+                setattr(self.metadata, attr, value)
 
     def _show_help(self, parser, global_options=1, display_options=1,
                    commands=[]):
@@ -606,31 +602,30 @@
                 options = self.global_options
             parser.set_option_table(options)
             parser.print_help(self.common_usage + "\nGlobal options:")
-            print
+            self.announce('')
 
         if display_options:
             parser.set_option_table(self.display_options)
             parser.print_help(
                 "Information display options (just display " +
                 "information, ignore any commands)")
-            print
+            self.announce('')
 
         for command in self.commands:
-            if type(command) is ClassType and issubclass(command, Command):
+            if isinstance(command, type) and issubclass(command, Command):
                 klass = command
             else:
                 klass = self.get_command_class(command)
             if (hasattr(klass, 'help_options') and
-                type(klass.help_options) is ListType):
+                isinstance(klass.help_options, list)):
                 parser.set_option_table(klass.user_options +
                                         fix_help_options(klass.help_options))
             else:
                 parser.set_option_table(klass.user_options)
             parser.print_help("Options for '%s' command:" % klass.__name__)
-            print
+            self.announce('')
 
-        print gen_usage(self.script_name)
-        return
+        self.announce(gen_usage(self.script_name))
 
     def handle_display_options(self, option_order):
         """If there were any non-global "display-only" options
@@ -645,8 +640,8 @@
         # we ignore "foo bar").
         if self.help_commands:
             self.print_commands()
-            print
-            print gen_usage(self.script_name)
+            self.announce('')
+            self.announce(gen_usage(self.script_name))
             return 1
 
         # If user supplied any of the "display metadata" options, then
@@ -662,12 +657,12 @@
                 opt = translate_longopt(opt)
                 value = getattr(self.metadata, "get_"+opt)()
                 if opt in ['keywords', 'platforms']:
-                    print string.join(value, ',')
+                    self.announce(','.join(value))
                 elif opt in ('classifiers', 'provides', 'requires',
                              'obsoletes'):
-                    print string.join(value, '\n')
+                    self.announce('\n'.join(value))
                 else:
-                    print value
+                    self.announce(value)
                 any_display_options = 1
 
         return any_display_options
@@ -676,7 +671,7 @@
         """Print a subset of the list of all commands -- used by
         'print_commands()'.
         """
-        print header + ":"
+        self.announce(header + ":")
 
         for cmd in commands:
             klass = self.cmdclass.get(cmd)
@@ -687,7 +682,7 @@
             except AttributeError:
                 description = "(no description available)"
 
-            print "  %-*s  %s" % (max_length, cmd, description)
+            self.announce("  %-*s  %s" % (max_length, cmd, description))
 
     def print_commands(self):
         """Print out a help message listing all available commands with a
@@ -760,11 +755,10 @@
     def get_command_packages(self):
         """Return a list of packages from which commands are loaded."""
         pkgs = self.command_packages
-        if not isinstance(pkgs, type([])):
-            pkgs = string.split(pkgs or "", ",")
-            for i in range(len(pkgs)):
-                pkgs[i] = string.strip(pkgs[i])
-            pkgs = filter(None, pkgs)
+        if not isinstance(pkgs, list):
+            if pkgs is None:
+                pkgs = ''
+            pkgs = [pkg.strip() for pkg in pkgs.split(',') if pkg != '']
             if "distutils.command" not in pkgs:
                 pkgs.insert(0, "distutils.command")
             self.command_packages = pkgs
@@ -818,8 +812,8 @@
         cmd_obj = self.command_obj.get(command)
         if not cmd_obj and create:
             if DEBUG:
-                print "Distribution.get_command_obj(): " \
-                      "creating '%s' command object" % command
+                self.announce("Distribution.get_command_obj(): " \
+                              "creating '%s' command object" % command)
 
             klass = self.get_command_class(command)
             cmd_obj = self.command_obj[command] = klass(self)
@@ -849,9 +843,12 @@
         if option_dict is None:
             option_dict = self.get_option_dict(command_name)
 
-        if DEBUG: print "  setting options for '%s' command:" % command_name
+        if DEBUG:
+            self.announce("  setting options for '%s' command:" % command_name)
         for (option, (source, value)) in option_dict.items():
-            if DEBUG: print "    %s = %s (from %s)" % (option, value, source)
+            if DEBUG:
+                self.announce("    %s = %s (from %s)" % (option, value,
+                                                         source))
             try:
                 bool_opts = map(translate_longopt, command_obj.boolean_options)
             except AttributeError:
@@ -862,7 +859,7 @@
                 neg_opt = {}
 
             try:
-                is_string = type(value) is StringType
+                is_string = isinstance(value, str)
                 if option in neg_opt and is_string:
                     setattr(command_obj, neg_opt[option], not strtobool(value))
                 elif option in bool_opts and is_string:
@@ -1044,10 +1041,10 @@
         if self.download_url:
             self._write_field(file, 'Download-URL', self.download_url)
 
-        long_desc = rfc822_escape( self.get_long_description())
+        long_desc = rfc822_escape(self.get_long_description())
         self._write_field(file, 'Description', long_desc)
 
-        keywords = string.join( self.get_keywords(), ',')
+        keywords = ','.join(self.get_keywords())
         if keywords:
             self._write_field(file, 'Keywords', keywords)
 

Modified: python/branches/tk_and_idle_maintenance/Lib/distutils/tests/test_dist.py
==============================================================================
--- python/branches/tk_and_idle_maintenance/Lib/distutils/tests/test_dist.py	(original)
+++ python/branches/tk_and_idle_maintenance/Lib/distutils/tests/test_dist.py	Tue Jun  2 03:25:38 2009
@@ -1,4 +1,4 @@
-# -*- coding: latin-1 -*-
+# -*- coding: utf8 -*-
 
 """Tests for distutils.dist."""
 import os
@@ -36,7 +36,9 @@
         return self._config_files
 
 
-class DistributionTestCase(support.TempdirManager, unittest.TestCase):
+class DistributionTestCase(support.TempdirManager,
+                           support.LoggingSilencer,
+                           unittest.TestCase):
 
     def setUp(self):
         super(DistributionTestCase, self).setUp()
@@ -106,11 +108,11 @@
         my_file = os.path.join(tmp_dir, 'f')
         klass = Distribution
 
-        dist = klass(attrs={'author': u'Mister Café',
+        dist = klass(attrs={'author': u'Mister Café',
                             'name': 'my.package',
-                            'maintainer': u'Café Junior',
-                            'description': u'Café torréfié',
-                            'long_description': u'Héhéhé'})
+                            'maintainer': u'Café Junior',
+                            'description': u'Café torréfié',
+                            'long_description': u'Héhéhé'})
 
 
         # let's make sure the file can be written
@@ -151,6 +153,49 @@
 
         self.assertEquals(len(warns), 0)
 
+    def test_finalize_options(self):
+
+        attrs = {'keywords': 'one,two',
+                 'platforms': 'one,two'}
+
+        dist = Distribution(attrs=attrs)
+        dist.finalize_options()
+
+        # finalize_option splits platforms and keywords
+        self.assertEquals(dist.metadata.platforms, ['one', 'two'])
+        self.assertEquals(dist.metadata.keywords, ['one', 'two'])
+
+    def test_show_help(self):
+        class FancyGetopt(object):
+            def __init__(self):
+                self.count = 0
+
+            def set_option_table(self, *args):
+                pass
+
+            def print_help(self, *args):
+                self.count += 1
+
+        parser = FancyGetopt()
+        dist = Distribution()
+        dist.commands = ['sdist']
+        dist.script_name = 'setup.py'
+        dist._show_help(parser)
+        self.assertEquals(parser.count, 3)
+
+    def test_get_command_packages(self):
+        dist = Distribution()
+        self.assertEquals(dist.command_packages, None)
+        cmds = dist.get_command_packages()
+        self.assertEquals(cmds, ['distutils.command'])
+        self.assertEquals(dist.command_packages,
+                          ['distutils.command'])
+
+        dist.command_packages = 'one,two'
+        cmds = dist.get_command_packages()
+        self.assertEquals(cmds, ['distutils.command', 'one', 'two'])
+
+
 class MetadataTestCase(support.TempdirManager, support.EnvironGuard,
                        unittest.TestCase):
 

Modified: python/branches/tk_and_idle_maintenance/Lib/ipaddr.py
==============================================================================
--- python/branches/tk_and_idle_maintenance/Lib/ipaddr.py	(original)
+++ python/branches/tk_and_idle_maintenance/Lib/ipaddr.py	Tue Jun  2 03:25:38 2009
@@ -1,18 +1,6 @@
 # Copyright 2007 Google Inc.
 #  Licensed to PSF under a Contributor Agreement.
 #
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
-# implied. See the License for the specific language governing
-# permissions and limitations under the License.
-#
 # See also: http://code.google.com/p/ipaddr-py/
 
 """An IPv4/IPv6 manipulation library in Python.
@@ -22,7 +10,7 @@
 
 """
 
-__version__ = '1.0.2'
+__version__ = '1.1.0'
 
 import struct
 

Modified: python/branches/tk_and_idle_maintenance/Lib/test/test_trace.py
==============================================================================
--- python/branches/tk_and_idle_maintenance/Lib/test/test_trace.py	(original)
+++ python/branches/tk_and_idle_maintenance/Lib/test/test_trace.py	Tue Jun  2 03:25:38 2009
@@ -740,6 +740,23 @@
     def test_19_no_jump_without_trace_function(self):
         no_jump_without_trace_function()
 
+    def test_20_large_function(self):
+        d = {}
+        exec("""def f(output):        # line 0
+            x = 0                     # line 1
+            y = 1                     # line 2
+            '''                       # line 3
+            %s                        # lines 4-1004
+            '''                       # line 1005
+            x += 1                    # line 1006
+            output.append(x)          # line 1007
+            return""" % ('\n' * 1000,), d)
+        f = d['f']
+
+        f.jump = (2, 1007)
+        f.output = [0]
+        self.run_test(f)
+
     def test_jump_to_firstlineno(self):
         # This tests that PDB can jump back to the first line in a
         # file.  See issue #1689458.  It can only be triggered in a

Modified: python/branches/tk_and_idle_maintenance/Misc/NEWS
==============================================================================
--- python/branches/tk_and_idle_maintenance/Misc/NEWS	(original)
+++ python/branches/tk_and_idle_maintenance/Misc/NEWS	Tue Jun  2 03:25:38 2009
@@ -12,6 +12,9 @@
 Core and Builtins
 -----------------
 
+- Issue #4547: When debugging a very large function, it was not always
+  possible to update the lineno attribute of the current frame.
+
 - Issue #5330: C functions called with keyword arguments were not reported by
   the various profiling modules (profile, cProfile). Patch by Hagen Fürstenau.
 

Modified: python/branches/tk_and_idle_maintenance/Objects/frameobject.c
==============================================================================
--- python/branches/tk_and_idle_maintenance/Objects/frameobject.c	(original)
+++ python/branches/tk_and_idle_maintenance/Objects/frameobject.c	Tue Jun  2 03:25:38 2009
@@ -98,7 +98,7 @@
 	int new_iblock = 0;		/* The new value of f_iblock */
 	unsigned char *code = NULL;	/* The bytecode for the frame... */
 	Py_ssize_t code_len = 0;	/* ...and its length */
-	char *lnotab = NULL;		/* Iterating over co_lnotab */
+	unsigned char *lnotab = NULL;	/* Iterating over co_lnotab */
 	Py_ssize_t lnotab_len = 0;	/* (ditto) */
 	int offset = 0;			/* (ditto) */
 	int line = 0;			/* (ditto) */
@@ -147,8 +147,10 @@
 	else {
 		/* Find the bytecode offset for the start of the given
 		 * line, or the first code-owning line after it. */
+		char *tmp;
 		PyString_AsStringAndSize(f->f_code->co_lnotab,
-					 &lnotab, &lnotab_len);
+					 &tmp, &lnotab_len);
+		lnotab = (unsigned char *) tmp;
 		addr = 0;
 		line = f->f_code->co_firstlineno;
 		new_lasti = -1;

Modified: python/branches/tk_and_idle_maintenance/Tools/msi/msi.py
==============================================================================
--- python/branches/tk_and_idle_maintenance/Tools/msi/msi.py	(original)
+++ python/branches/tk_and_idle_maintenance/Tools/msi/msi.py	Tue Jun  2 03:25:38 2009
@@ -1008,6 +1008,7 @@
             lib.add_file("test_difflib_expect.html")
             lib.add_file("check_soundcard.vbs")
             lib.add_file("empty.vbs")
+            lib.add_file("Sine-1000Hz-300ms.aif")
             lib.glob("*.uue")
             lib.glob("*.pem")
             lib.glob("*.pck")


More information about the Python-checkins mailing list