mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	First merge from the trunk straight into the py3k branch. I'm not
using the message generated by svnmerge, because it contains a lot of stuff about the Doc tree, which I'm not merging this time due to the way the Doc tree was initially added. I am however adding roman.py which was added later to Doc/tools. I'll try to diff the two Doc trees separately to see if there's stuff I missed.
This commit is contained in:
		
							parent
							
								
									10c17ba299
								
							
						
					
					
						commit
						af554a0e17
					
				
					 16 changed files with 206 additions and 33 deletions
				
			
		
							
								
								
									
										80
									
								
								Doc/tools/roman.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										80
									
								
								Doc/tools/roman.py
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,80 @@ | ||||||
|  | """Convert to and from Roman numerals""" | ||||||
|  | 
 | ||||||
|  | __author__ = "Mark Pilgrim (f8dy@diveintopython.org)" | ||||||
|  | __version__ = "1.4" | ||||||
|  | __date__ = "8 August 2001" | ||||||
|  | __copyright__ = """Copyright (c) 2001 Mark Pilgrim | ||||||
|  | 
 | ||||||
|  | This program is part of "Dive Into Python", a free Python tutorial for | ||||||
|  | experienced programmers.  Visit http://diveintopython.org/ for the | ||||||
|  | latest version. | ||||||
|  | 
 | ||||||
|  | This program is free software; you can redistribute it and/or modify | ||||||
|  | it under the terms of the Python 2.1.1 license, available at | ||||||
|  | http://www.python.org/2.1.1/license.html | ||||||
|  | """ | ||||||
|  | 
 | ||||||
|  | import re | ||||||
|  | 
 | ||||||
|  | #Define exceptions | ||||||
|  | class RomanError(Exception): pass | ||||||
|  | class OutOfRangeError(RomanError): pass | ||||||
|  | class NotIntegerError(RomanError): pass | ||||||
|  | class InvalidRomanNumeralError(RomanError): pass | ||||||
|  | 
 | ||||||
|  | #Define digit mapping | ||||||
|  | romanNumeralMap = (('M',  1000), | ||||||
|  |                    ('CM', 900), | ||||||
|  |                    ('D',  500), | ||||||
|  |                    ('CD', 400), | ||||||
|  |                    ('C',  100), | ||||||
|  |                    ('XC', 90), | ||||||
|  |                    ('L',  50), | ||||||
|  |                    ('XL', 40), | ||||||
|  |                    ('X',  10), | ||||||
|  |                    ('IX', 9), | ||||||
|  |                    ('V',  5), | ||||||
|  |                    ('IV', 4), | ||||||
|  |                    ('I',  1)) | ||||||
|  | 
 | ||||||
|  | def toRoman(n): | ||||||
|  |     """convert integer to Roman numeral""" | ||||||
|  |     if not (0 < n < 5000): | ||||||
|  |         raise OutOfRangeError, "number out of range (must be 1..4999)" | ||||||
|  |     if int(n) <> n: | ||||||
|  |         raise NotIntegerError, "decimals can not be converted" | ||||||
|  | 
 | ||||||
|  |     result = "" | ||||||
|  |     for numeral, integer in romanNumeralMap: | ||||||
|  |         while n >= integer: | ||||||
|  |             result += numeral | ||||||
|  |             n -= integer | ||||||
|  |     return result | ||||||
|  | 
 | ||||||
|  | #Define pattern to detect valid Roman numerals | ||||||
|  | romanNumeralPattern = re.compile(""" | ||||||
|  |     ^                   # beginning of string | ||||||
|  |     M{0,4}              # thousands - 0 to 4 M's | ||||||
|  |     (CM|CD|D?C{0,3})    # hundreds - 900 (CM), 400 (CD), 0-300 (0 to 3 C's), | ||||||
|  |                         #            or 500-800 (D, followed by 0 to 3 C's) | ||||||
|  |     (XC|XL|L?X{0,3})    # tens - 90 (XC), 40 (XL), 0-30 (0 to 3 X's), | ||||||
|  |                         #        or 50-80 (L, followed by 0 to 3 X's) | ||||||
|  |     (IX|IV|V?I{0,3})    # ones - 9 (IX), 4 (IV), 0-3 (0 to 3 I's), | ||||||
|  |                         #        or 5-8 (V, followed by 0 to 3 I's) | ||||||
|  |     $                   # end of string | ||||||
|  |     """ ,re.VERBOSE) | ||||||
|  | 
 | ||||||
|  | def fromRoman(s): | ||||||
|  |     """convert Roman numeral to integer""" | ||||||
|  |     if not s: | ||||||
|  |         raise InvalidRomanNumeralError, 'Input can not be blank' | ||||||
|  |     if not romanNumeralPattern.search(s): | ||||||
|  |         raise InvalidRomanNumeralError, 'Invalid Roman numeral: %s' % s | ||||||
|  | 
 | ||||||
|  |     result = 0 | ||||||
|  |     index = 0 | ||||||
|  |     for numeral, integer in romanNumeralMap: | ||||||
|  |         while s[index:index+len(numeral)] == numeral: | ||||||
|  |             result += integer | ||||||
|  |             index += len(numeral) | ||||||
|  |     return result | ||||||
|  | @ -612,7 +612,8 @@ def __new__(cls, value="0", context=None): | ||||||
|             except ValueError: |             except ValueError: | ||||||
|                 self._is_special = True |                 self._is_special = True | ||||||
|                 self._sign, self._int, self._exp = \ |                 self._sign, self._int, self._exp = \ | ||||||
|                                         context._raise_error(ConversionSyntax) |                               context._raise_error(ConversionSyntax, | ||||||
|  |                                   "Invalid literal for Decimal: %r" % value) | ||||||
|             return self |             return self | ||||||
| 
 | 
 | ||||||
|         raise TypeError("Cannot convert %r to Decimal" % value) |         raise TypeError("Cannot convert %r to Decimal" % value) | ||||||
|  |  | ||||||
|  | @ -5,8 +5,7 @@ | ||||||
| import unittest | import unittest | ||||||
| import pickle | import pickle | ||||||
| 
 | 
 | ||||||
| from test.test_support import (TESTFN, unlink, run_unittest, | from test.test_support import TESTFN, unlink, run_unittest | ||||||
|                                 guard_warnings_filter) |  | ||||||
| 
 | 
 | ||||||
| # XXX This is not really enough, each *operation* should be tested! | # XXX This is not really enough, each *operation* should be tested! | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| from test.test_support import TESTFN, run_unittest, guard_warnings_filter | from test.test_support import TESTFN, run_unittest, catch_warning | ||||||
| 
 | 
 | ||||||
| import unittest | import unittest | ||||||
| import os | import os | ||||||
|  | @ -151,7 +151,7 @@ def test_import_name_binding(self): | ||||||
|         self.assert_(y is test.test_support, y.__name__) |         self.assert_(y is test.test_support, y.__name__) | ||||||
| 
 | 
 | ||||||
|     def test_import_initless_directory_warning(self): |     def test_import_initless_directory_warning(self): | ||||||
|         with guard_warnings_filter(): |         with catch_warning(): | ||||||
|             # Just a random non-package directory we always expect to be |             # Just a random non-package directory we always expect to be | ||||||
|             # somewhere in sys.path... |             # somewhere in sys.path... | ||||||
|             warnings.simplefilter('error', ImportWarning) |             warnings.simplefilter('error', ImportWarning) | ||||||
|  |  | ||||||
|  | @ -52,7 +52,7 @@ def compareData(self): | ||||||
|     def test_touched(self): |     def test_touched(self): | ||||||
|         # This really only tests that nothing unforeseen happens. |         # This really only tests that nothing unforeseen happens. | ||||||
|         import warnings |         import warnings | ||||||
|         with test_support.guard_warnings_filter(): |         with test_support.catch_warning(): | ||||||
|             warnings.filterwarnings('ignore', 'macostools.touched*', |             warnings.filterwarnings('ignore', 'macostools.touched*', | ||||||
|                                     DeprecationWarning) |                                     DeprecationWarning) | ||||||
|             macostools.touched(test_support.TESTFN) |             macostools.touched(test_support.TESTFN) | ||||||
|  |  | ||||||
|  | @ -1,7 +1,7 @@ | ||||||
| import unittest | import unittest | ||||||
| import __builtin__ | import __builtin__ | ||||||
| import warnings | import warnings | ||||||
| from test.test_support import run_unittest, guard_warnings_filter | from test.test_support import run_unittest | ||||||
| import os | import os | ||||||
| from platform import system as platform_system | from platform import system as platform_system | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -182,7 +182,7 @@ def test_gauss_with_whseed(self): | ||||||
| 
 | 
 | ||||||
|     def test_bigrand(self): |     def test_bigrand(self): | ||||||
|         # Verify warnings are raised when randrange is too large for random() |         # Verify warnings are raised when randrange is too large for random() | ||||||
|         with test_support.guard_warnings_filter(): |         with test_support.catch_warning(): | ||||||
|             warnings.filterwarnings("error", "Underlying random") |             warnings.filterwarnings("error", "Underlying random") | ||||||
|             self.assertRaises(UserWarning, self.gen.randrange, 2**60) |             self.assertRaises(UserWarning, self.gen.randrange, 2**60) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -1,7 +1,7 @@ | ||||||
| import sys | import sys | ||||||
| sys.path = ['.'] + sys.path | sys.path = ['.'] + sys.path | ||||||
| 
 | 
 | ||||||
| from test.test_support import verbose, run_unittest, guard_warnings_filter | from test.test_support import verbose, run_unittest, catch_warning | ||||||
| import re | import re | ||||||
| from re import Scanner | from re import Scanner | ||||||
| import sys, os, traceback | import sys, os, traceback | ||||||
|  | @ -414,7 +414,7 @@ def test_pickling(self): | ||||||
|         self.pickle_test(pickle) |         self.pickle_test(pickle) | ||||||
|         # old pickles expect the _compile() reconstructor in sre module |         # old pickles expect the _compile() reconstructor in sre module | ||||||
|         import warnings |         import warnings | ||||||
|         with guard_warnings_filter(): |         with catch_warning(): | ||||||
|             warnings.filterwarnings("ignore", "The sre module is deprecated", |             warnings.filterwarnings("ignore", "The sre module is deprecated", | ||||||
|                                     DeprecationWarning) |                                     DeprecationWarning) | ||||||
|             from sre import _compile |             from sre import _compile | ||||||
|  |  | ||||||
|  | @ -50,7 +50,7 @@ def any_err(func, *args): | ||||||
| 
 | 
 | ||||||
| def with_warning_restore(func): | def with_warning_restore(func): | ||||||
|     def _with_warning_restore(*args, **kw): |     def _with_warning_restore(*args, **kw): | ||||||
|         with test.test_support.guard_warnings_filter(): |         with test.test_support.catch_warning(): | ||||||
|             # Grrr, we need this function to warn every time.  Without removing |             # Grrr, we need this function to warn every time.  Without removing | ||||||
|             # the warningregistry, running test_tarfile then test_struct would fail |             # the warningregistry, running test_tarfile then test_struct would fail | ||||||
|             # on 64-bit platforms. |             # on 64-bit platforms. | ||||||
|  |  | ||||||
|  | @ -1,10 +1,10 @@ | ||||||
| """Do a minimal test of all the modules that aren't otherwise tested.""" | """Do a minimal test of all the modules that aren't otherwise tested.""" | ||||||
| 
 | 
 | ||||||
| from test.test_support import guard_warnings_filter | from test.test_support import catch_warning | ||||||
| import sys | import sys | ||||||
| import warnings | import warnings | ||||||
| 
 | 
 | ||||||
| with guard_warnings_filter(): | with catch_warning(): | ||||||
|     from test.test_support import verbose |     from test.test_support import verbose | ||||||
| 
 | 
 | ||||||
|     import BaseHTTPServer |     import BaseHTTPServer | ||||||
|  |  | ||||||
|  | @ -261,14 +261,6 @@ def open_urlresource(url): | ||||||
|     fn, _ = urllib.urlretrieve(url, filename) |     fn, _ = urllib.urlretrieve(url, filename) | ||||||
|     return open(fn) |     return open(fn) | ||||||
| 
 | 
 | ||||||
| @contextlib.contextmanager |  | ||||||
| def guard_warnings_filter(): |  | ||||||
|     """Guard the warnings filter from being permanently changed.""" |  | ||||||
|     original_filters = warnings.filters[:] |  | ||||||
|     try: |  | ||||||
|         yield |  | ||||||
|     finally: |  | ||||||
|         warnings.filters = original_filters |  | ||||||
| 
 | 
 | ||||||
| class WarningMessage(object): | class WarningMessage(object): | ||||||
|     "Holds the result of the latest showwarning() call" |     "Holds the result of the latest showwarning() call" | ||||||
|  | @ -292,7 +284,7 @@ def catch_warning(): | ||||||
| 
 | 
 | ||||||
|     Use like this: |     Use like this: | ||||||
| 
 | 
 | ||||||
|         with catch_warning as w: |         with catch_warning() as w: | ||||||
|             warnings.warn("foo") |             warnings.warn("foo") | ||||||
|             assert str(w.message) == "foo" |             assert str(w.message) == "foo" | ||||||
|     """ |     """ | ||||||
|  |  | ||||||
|  | @ -61,7 +61,7 @@ def test_filtering(self): | ||||||
|     def test_options(self): |     def test_options(self): | ||||||
|         # Uses the private _setoption() function to test the parsing |         # Uses the private _setoption() function to test the parsing | ||||||
|         # of command-line warning arguments |         # of command-line warning arguments | ||||||
|         with test_support.guard_warnings_filter(): |         with test_support.catch_warning(): | ||||||
|             self.assertRaises(warnings._OptionError, |             self.assertRaises(warnings._OptionError, | ||||||
|                               warnings._setoption, '1:2:3:4:5:6') |                               warnings._setoption, '1:2:3:4:5:6') | ||||||
|             self.assertRaises(warnings._OptionError, |             self.assertRaises(warnings._OptionError, | ||||||
|  |  | ||||||
|  | @ -4,6 +4,8 @@ | ||||||
| import time | import time | ||||||
| import unittest | import unittest | ||||||
| import xmlrpclib | import xmlrpclib | ||||||
|  | import SimpleXMLRPCServer | ||||||
|  | import threading | ||||||
| from test import test_support | from test import test_support | ||||||
| 
 | 
 | ||||||
| alist = [{'astring': 'foo@bar.baz.spam', | alist = [{'astring': 'foo@bar.baz.spam', | ||||||
|  | @ -239,10 +241,108 @@ def test_decode(self): | ||||||
|         self.assertEqual(str(t2), d) |         self.assertEqual(str(t2), d) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def test_main(): | PORT = None | ||||||
|     test_support.run_unittest(XMLRPCTestCase, HelperTestCase, |  | ||||||
|             DateTimeTestCase, BinaryTestCase, FaultTestCase) |  | ||||||
| 
 | 
 | ||||||
|  | def http_server(evt, numrequests): | ||||||
|  |     class TestInstanceClass: | ||||||
|  |         def div(self, x, y): | ||||||
|  |             '''This is the div function''' | ||||||
|  |             return x // y | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     serv = SimpleXMLRPCServer.SimpleXMLRPCServer(("localhost", 0), | ||||||
|  |                     logRequests=False, bind_and_activate=False) | ||||||
|  | 
 | ||||||
|  |     try: | ||||||
|  |         serv.socket.settimeout(3) | ||||||
|  |         serv.server_bind() | ||||||
|  |         global PORT | ||||||
|  |         PORT = serv.socket.getsockname()[1] | ||||||
|  |         serv.server_activate() | ||||||
|  |         serv.register_introspection_functions() | ||||||
|  |         serv.register_multicall_functions() | ||||||
|  |         serv.register_function(pow) | ||||||
|  |         serv.register_function(lambda x,y: x+y, 'add') | ||||||
|  |         serv.register_instance(TestInstanceClass()) | ||||||
|  | 
 | ||||||
|  |         # handle up to 'numrequests' requests | ||||||
|  |         while numrequests > 0: | ||||||
|  |             serv.handle_request() | ||||||
|  |             numrequests -= 1 | ||||||
|  | 
 | ||||||
|  |     except socket.timeout: | ||||||
|  |         pass | ||||||
|  |     finally: | ||||||
|  |         serv.socket.close() | ||||||
|  |         PORT = None | ||||||
|  |         evt.set() | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | class HTTPTestCase(unittest.TestCase): | ||||||
|  |     def setUp(self): | ||||||
|  |         self.evt = threading.Event() | ||||||
|  |         # start server thread to handle just one request | ||||||
|  |         threading.Thread(target=http_server, args=(self.evt,2)).start() | ||||||
|  | 
 | ||||||
|  |         # wait for port to be assigned to server | ||||||
|  |         n = 1000 | ||||||
|  |         while n > 0 and PORT is None: | ||||||
|  |             time.sleep(0.001) | ||||||
|  |             n -= 1 | ||||||
|  | 
 | ||||||
|  |         time.sleep(0.5) | ||||||
|  | 
 | ||||||
|  |     def tearDown(self): | ||||||
|  |         # wait on the server thread to terminate | ||||||
|  |         self.evt.wait() | ||||||
|  | 
 | ||||||
|  |     def test_simple1(self): | ||||||
|  |         p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT) | ||||||
|  |         self.assertEqual(p.pow(6,8), 6**8) | ||||||
|  | 
 | ||||||
|  |     def test_introspection1(self): | ||||||
|  |         p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT) | ||||||
|  |         meth = p.system.listMethods() | ||||||
|  |         expected_methods = set(['pow', 'div', 'add', 'system.listMethods', | ||||||
|  |             'system.methodHelp', 'system.methodSignature', 'system.multicall']) | ||||||
|  |         self.assertEqual(set(meth), expected_methods) | ||||||
|  | 
 | ||||||
|  |     def test_introspection2(self): | ||||||
|  |         p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT) | ||||||
|  |         divhelp = p.system.methodHelp('div') | ||||||
|  |         self.assertEqual(divhelp, 'This is the div function') | ||||||
|  | 
 | ||||||
|  |     def test_introspection3(self): | ||||||
|  |         # the SimpleXMLRPCServer doesn't support signatures, but | ||||||
|  |         # at least check that we can try | ||||||
|  |         p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT) | ||||||
|  |         divsig = p.system.methodSignature('div') | ||||||
|  |         self.assertEqual(divsig, 'signatures not supported') | ||||||
|  | 
 | ||||||
|  |     def test_multicall(self): | ||||||
|  |         p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT) | ||||||
|  |         multicall = xmlrpclib.MultiCall(p) | ||||||
|  |         multicall.add(2,3) | ||||||
|  |         multicall.pow(6,8) | ||||||
|  |         multicall.div(127,42) | ||||||
|  |         add_result, pow_result, div_result = multicall() | ||||||
|  |         self.assertEqual(add_result, 2+3) | ||||||
|  |         self.assertEqual(pow_result, 6**8) | ||||||
|  |         self.assertEqual(div_result, 127//42) | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | def test_main(): | ||||||
|  |     xmlrpc_tests = [XMLRPCTestCase, HelperTestCase, DateTimeTestCase, | ||||||
|  |          BinaryTestCase, FaultTestCase] | ||||||
|  | 
 | ||||||
|  |     # The test cases against a SimpleXMLRPCServer raise a socket error | ||||||
|  |     # 10035 (WSAEWOULDBLOCK) in the server thread handle_request call when | ||||||
|  |     # run on Windows. This only happens on the first test to run, but it | ||||||
|  |     # fails every time and so these tests are skipped on win32 platforms. | ||||||
|  |     if sys.platform != 'win32': | ||||||
|  |         xmlrpc_tests.append(HTTPTestCase) | ||||||
|  | 
 | ||||||
|  |     test_support.run_unittest(*xmlrpc_tests) | ||||||
| 
 | 
 | ||||||
| if __name__ == "__main__": | if __name__ == "__main__": | ||||||
|     test_main() |     test_main() | ||||||
|  |  | ||||||
|  | @ -220,7 +220,6 @@ start=`current_time` | ||||||
| # after the first release of 2.6a1 or 3.0a1.  At that point, it will be clear | # after the first release of 2.6a1 or 3.0a1.  At that point, it will be clear | ||||||
| # if there will be a similar problem with the new doc system. | # if there will be a similar problem with the new doc system. | ||||||
| 
 | 
 | ||||||
| # At that point, it should be clear if this code is needed or not. |  | ||||||
| # Doc/commontex/boilerplate.tex is expected to always have an outstanding | # Doc/commontex/boilerplate.tex is expected to always have an outstanding | ||||||
| # modification for the date.  When a release is cut, a conflict occurs. | # modification for the date.  When a release is cut, a conflict occurs. | ||||||
| # This allows us to detect this problem and not try to build the docs | # This allows us to detect this problem and not try to build the docs | ||||||
|  |  | ||||||
|  | @ -17,13 +17,14 @@ the format to accommodate documentation needs as they arise. | ||||||
| Permissions History | Permissions History | ||||||
| ------------------- | ------------------- | ||||||
| 
 | 
 | ||||||
| - Senthil Kumaran  was given SVN access on June 16 2007 | - Jeffrey Yasskin was given SVN access on 9 August 2007 by NCN, | ||||||
|   by MvL, for his Summer-of-Code project, mentored by |   for his work on PEPs and other general patches.  | ||||||
|   Skip Montanaro. |  | ||||||
| 
 | 
 | ||||||
| - Alexandre Vassalotti was given SVN access on May 21 2007 | - Senthil Kumaran was given SVN access on 16 June 2007 by MvL, | ||||||
|   by MvL, for his Summer-of-Code project, mentored by |   for his Summer-of-Code project, mentored by Skip Montanaro. | ||||||
|   Brett Cannon. | 
 | ||||||
|  | - Alexandre Vassalotti was given SVN access on 21 May 2007 by MvL, | ||||||
|  |   for his Summer-of-Code project, mentored by Brett Cannon. | ||||||
| 
 | 
 | ||||||
| - Travis Oliphant was given SVN access on 17 Apr 2007 by MvL, | - Travis Oliphant was given SVN access on 17 Apr 2007 by MvL, | ||||||
|   for implementing the extended buffer protocol. |   for implementing the extended buffer protocol. | ||||||
|  |  | ||||||
|  | @ -104,6 +104,7 @@ | ||||||
| pythondll_uuid = { | pythondll_uuid = { | ||||||
|     "24":"{9B81E618-2301-4035-AC77-75D9ABEB7301}", |     "24":"{9B81E618-2301-4035-AC77-75D9ABEB7301}", | ||||||
|     "25":"{2e41b118-38bd-4c1b-a840-6977efd1b911}" |     "25":"{2e41b118-38bd-4c1b-a840-6977efd1b911}" | ||||||
|  |     "26":"{34ebecac-f046-4e1c-b0e3-9bac3cdaacfa}", | ||||||
|     } [major+minor] |     } [major+minor] | ||||||
| 
 | 
 | ||||||
| # Build the mingw import library, libpythonXY.a | # Build the mingw import library, libpythonXY.a | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Guido van Rossum
						Guido van Rossum