Commit 255f53bd authored by Christian Heimes's avatar Christian Heimes

Merged revisions 59376-59406 via svnmerge from

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

........
  r59377 | georg.brandl | 2007-12-06 01:24:23 +0100 (Thu, 06 Dec 2007) | 2 lines

  Add another GHOP student to ACKS.
........
  r59378 | raymond.hettinger | 2007-12-06 01:56:53 +0100 (Thu, 06 Dec 2007) | 5 lines

  Fix Issue 1045.
  Factor-out common calling code by simplifying the length_hint API.
  Speed-up the function by caching the PyObject_String for the attribute lookup.
........
  r59380 | georg.brandl | 2007-12-06 02:52:24 +0100 (Thu, 06 Dec 2007) | 2 lines

  Diverse markup fixes.
........
  r59383 | georg.brandl | 2007-12-06 10:45:39 +0100 (Thu, 06 Dec 2007) | 2 lines

  Better re.split examples.
........
  r59386 | christian.heimes | 2007-12-06 14:15:13 +0100 (Thu, 06 Dec 2007) | 2 lines

  Fixed get_config_h_filename for Windows. Without the patch it can't find the pyconfig.h file inside a build tree.
  Added several small unit tests for sysconfig.
........
  r59387 | christian.heimes | 2007-12-06 14:30:11 +0100 (Thu, 06 Dec 2007) | 1 line

  Silence more warnings, _CRT_NONSTDC_NO_DEPRECATE is already defined in pyconfig.h but several projects don't include it.
........
  r59389 | christian.heimes | 2007-12-06 14:55:01 +0100 (Thu, 06 Dec 2007) | 1 line

  Disabled one test that is failing on Unix
........
  r59399 | christian.heimes | 2007-12-06 22:13:06 +0100 (Thu, 06 Dec 2007) | 8 lines

  Several Windows related cleanups:
  * Removed a #define from pyconfig.h. The macro was already defined a few lines higher.
  * Fixed path to tix in the build_tkinter.py script
  * Changed make_buildinfo.c to use versions of unlink and strcat which are considered safe by Windows (as suggested by MvL).
  * Removed two defines from pyproject.vsprops that are no longer required. Both are defined in pyconfig.h and make_buildinfo.c doesn't use the unsafe versions any more (as suggested by MvL).
  * Added some more information about PGO and the property files to PCbuild9/readme.txt.

  Are you fine with the changes, Martin?
........
  r59400 | raymond.hettinger | 2007-12-07 02:53:01 +0100 (Fri, 07 Dec 2007) | 4 lines

  Don't have the docs berate themselves.  Keep a professional tone.
  If a todo is needed, put it in the tracker.
........
  r59402 | georg.brandl | 2007-12-07 10:07:10 +0100 (Fri, 07 Dec 2007) | 3 lines

  Increase unit test coverage of SimpleXMLRPCServer.
  Written for GHOP by Turkay Eren.
........
  r59406 | georg.brandl | 2007-12-07 16:16:57 +0100 (Fri, 07 Dec 2007) | 2 lines

  Update to windows doc from Robert.
........
parent 226679ae
...@@ -122,6 +122,7 @@ docs@python.org), and we'll be glad to correct the problem. ...@@ -122,6 +122,7 @@ docs@python.org), and we'll be glad to correct the problem.
* Vincent Marchetti * Vincent Marchetti
* Laura Matson * Laura Matson
* Daniel May * Daniel May
* Rebecca McCreary
* Doug Mennella * Doug Mennella
* Paolo Milani * Paolo Milani
* Skip Montanaro * Skip Montanaro
......
...@@ -1541,13 +1541,13 @@ Sequence Object Structures ...@@ -1541,13 +1541,13 @@ Sequence Object Structures
.. cmember:: binaryfunc PySequenceMethods.sq_concat .. cmember:: binaryfunc PySequenceMethods.sq_concat
This function is used by :cfunc:`PySequence_Concat` and has the same This function is used by :cfunc:`PySequence_Concat` and has the same
signature. It is also used by the `+` operator, after trying the numeric signature. It is also used by the ``+`` operator, after trying the numeric
addition via the :attr:`tp_as_number.nb_add` slot. addition via the :attr:`tp_as_number.nb_add` slot.
.. cmember:: ssizeargfunc PySequenceMethods.sq_repeat .. cmember:: ssizeargfunc PySequenceMethods.sq_repeat
This function is used by :cfunc:`PySequence_Repeat` and has the same This function is used by :cfunc:`PySequence_Repeat` and has the same
signature. It is also used by the `*` operator, after trying numeric signature. It is also used by the ``*`` operator, after trying numeric
multiplication via the :attr:`tp_as_number.nb_mul` slot. multiplication via the :attr:`tp_as_number.nb_mul` slot.
.. cmember:: ssizeargfunc PySequenceMethods.sq_item .. cmember:: ssizeargfunc PySequenceMethods.sq_item
......
...@@ -239,7 +239,7 @@ something went wrong, or ``None`` if all is well. ...@@ -239,7 +239,7 @@ something went wrong, or ``None`` if all is well.
.. method:: Bdb.clear_bpbynumber(arg) .. method:: Bdb.clear_bpbynumber(arg)
Delete the breakpoint which has the index *arg* in the Delete the breakpoint which has the index *arg* in the
:attr:`Breakpoint.bpbynumber`. If `arg` is not numeric or out of range, :attr:`Breakpoint.bpbynumber`. If *arg* is not numeric or out of range,
return an error message. return an error message.
.. method:: Bdb.clear_all_file_breaks(filename) .. method:: Bdb.clear_all_file_breaks(filename)
......
...@@ -741,7 +741,7 @@ functions. ...@@ -741,7 +741,7 @@ functions.
The proposal which described this feature for inclusion in the Python standard The proposal which described this feature for inclusion in the Python standard
library. library.
`Original Python :mod:`logging` package <http://www.red-dove.com/python_logging.html>`_ `Original Python logging package <http://www.red-dove.com/python_logging.html>`_
This is the original source for the :mod:`logging` package. The version of the This is the original source for the :mod:`logging` package. The version of the
package available from this site is suitable for use with Python 1.5.2, 2.1.x package available from this site is suitable for use with Python 1.5.2, 2.1.x
and 2.2.x, which do not include the :mod:`logging` package in the standard and 2.2.x, which do not include the :mod:`logging` package in the standard
......
...@@ -25,8 +25,3 @@ from left to right. (Unary operators group from right to left, but there you ...@@ -25,8 +25,3 @@ from left to right. (Unary operators group from right to left, but there you
have no real choice.) See :ref:`operator-summary` for the complete picture on have no real choice.) See :ref:`operator-summary` for the complete picture on
operator priorities. operator priorities.
.. rubric:: Footnotes
.. [#] Most descriptions sorely lack explanations of the exceptions that may be raised
--- this will be fixed in a future version of this manual.
...@@ -48,7 +48,7 @@ also available for Python: ...@@ -48,7 +48,7 @@ also available for Python:
online `tutorial <http://www.pygtk.org/pygtk2tutorial/index.html>`_ is online `tutorial <http://www.pygtk.org/pygtk2tutorial/index.html>`_ is
available. available.
`PyQt <//http://www.riverbankcomputing.co.uk/pyqt/index.php>`_ `PyQt <http://www.riverbankcomputing.co.uk/pyqt/index.php>`_
PyQt is a :program:`sip`\ -wrapped binding to the Qt toolkit. Qt is an PyQt is a :program:`sip`\ -wrapped binding to the Qt toolkit. Qt is an
extensive C++ GUI application development framework that is extensive C++ GUI application development framework that is
available for Unix, Windows and Mac OS X. :program:`sip` is a tool available for Unix, Windows and Mac OS X. :program:`sip` is a tool
......
...@@ -1078,16 +1078,21 @@ method is invaluable for converting textual data into data structures that can b ...@@ -1078,16 +1078,21 @@ method is invaluable for converting textual data into data structures that can b
easily read and modified by Python as demonstrated in the following example that easily read and modified by Python as demonstrated in the following example that
creates a phonebook. creates a phonebook.
First, get the input using triple-quoted string syntax:: First, here is the input. Normally it may come from a file, here we are using
triple-quoted string syntax::
>>> input = """Ross McFluff 834.345.1254 155 Elm Street >>> input = """Ross McFluff: 834.345.1254 155 Elm Street
Ronald Heathmore 892.345.3428 436 Finley Avenue
Frank Burger 925.541.7625 662 South Dogwood Way
Heather Albrecht 548.326.4584 919 Park Place"""
Then, convert the string into a list with each line having its own entry:: Ronald Heathmore: 892.345.3428 436 Finley Avenue
Frank Burger: 925.541.7625 662 South Dogwood Way
>>> entries = re.split("\n", input)
Heather Albrecht: 548.326.4584 919 Park Place"""
The entries are separated by one or more newlines. Now we convert the string
into a list with each nonempty line having its own entry::
>>> entries = re.split("\n+", input)
>>> entries >>> entries
['Ross McFluff 834.345.1254 155 Elm Street', ['Ross McFluff 834.345.1254 155 Elm Street',
'Ronald Heathmore 892.345.3428 436 Finley Avenue', 'Ronald Heathmore 892.345.3428 436 Finley Avenue',
...@@ -1098,16 +1103,17 @@ Finally, split each entry into a list with first name, last name, telephone ...@@ -1098,16 +1103,17 @@ Finally, split each entry into a list with first name, last name, telephone
number, and address. We use the ``maxsplit`` paramater of :func:`split` number, and address. We use the ``maxsplit`` paramater of :func:`split`
because the address has spaces, our splitting pattern, in it:: because the address has spaces, our splitting pattern, in it::
>>> [re.split(" ", entry, 3) for entry in entries] >>> [re.split(":? ", entry, 3) for entry in entries]
[['Ross', 'McFluff', '834.345.1254', '155 Elm Street'], [['Ross', 'McFluff', '834.345.1254', '155 Elm Street'],
['Ronald', 'Heathmore', '892.345.3428', '436 Finley Avenue'], ['Ronald', 'Heathmore', '892.345.3428', '436 Finley Avenue'],
['Frank', 'Burger', '925.541.7625', '662 South Dogwood Way'], ['Frank', 'Burger', '925.541.7625', '662 South Dogwood Way'],
['Heather', 'Albrecht', '548.326.4584', '919 Park Place']] ['Heather', 'Albrecht', '548.326.4584', '919 Park Place']]
With a ``maxsplit`` of ``4``, we could seperate the house number from the street The ``:?`` pattern matches the colon after the last name, so that it does not
name:: occur in the result list. With a ``maxsplit`` of ``4``, we could seperate the
house number from the street name::
>>> [re.split(" ", entry, 4) for entry in entries] >>> [re.split(":? ", entry, 4) for entry in entries]
[['Ross', 'McFluff', '834.345.1254', '155', 'Elm Street'], [['Ross', 'McFluff', '834.345.1254', '155', 'Elm Street'],
['Ronald', 'Heathmore', '892.345.3428', '436', 'Finley Avenue'], ['Ronald', 'Heathmore', '892.345.3428', '436', 'Finley Avenue'],
['Frank', 'Burger', '925.541.7625', '662', 'South Dogwood Way'], ['Frank', 'Burger', '925.541.7625', '662', 'South Dogwood Way'],
......
...@@ -109,13 +109,14 @@ Functions, Constants, and Exceptions ...@@ -109,13 +109,14 @@ Functions, Constants, and Exceptions
======================== ========= ========= ========== ========= ======================== ========= ========= ========== =========
*client* / **server** **SSLv2** **SSLv3** **SSLv23** **TLSv1** *client* / **server** **SSLv2** **SSLv3** **SSLv23** **TLSv1**
------------------------ --------- --------- ---------- ---------
*SSLv2* yes no yes* no *SSLv2* yes no yes* no
*SSLv3* yes yes yes no *SSLv3* yes yes yes no
*SSLv23* yes no yes no *SSLv23* yes no yes no
*TLSv1* no no yes yes *TLSv1* no no yes yes
======================== ========= ========= ========== ========= ======================== ========= ========= ========== =========
`*` In some older versions of OpenSSL (for instance, 0.9.7l on OS X 10.4), In some older versions of OpenSSL (for instance, 0.9.7l on OS X 10.4),
an SSLv2 client could not connect to an SSLv23 server. an SSLv2 client could not connect to an SSLv23 server.
The parameter ``do_handshake_on_connect`` specifies whether to do the SSL The parameter ``do_handshake_on_connect`` specifies whether to do the SSL
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
The :mod:`tarfile` module makes it possible to read and write tar The :mod:`tarfile` module makes it possible to read and write tar
archives, including those using gzip or bz2 compression. archives, including those using gzip or bz2 compression.
(`.zip` files can be read and written using the :mod:`zipfile` module.) (:file:`.zip` files can be read and written using the :mod:`zipfile` module.)
Some facts and figures: Some facts and figures:
......
...@@ -73,6 +73,8 @@ key features: ...@@ -73,6 +73,8 @@ key features:
Popular modules (such as PyWin32) with their respective documentation, tool Popular modules (such as PyWin32) with their respective documentation, tool
suite for building extensible python applications suite for building extensible python applications
Notice that these packages are likely to install *older* versions of Python.
Configuring Python Configuring Python
...@@ -85,10 +87,11 @@ settings in Windows. ...@@ -85,10 +87,11 @@ settings in Windows.
Excursus: Setting environment variables Excursus: Setting environment variables
--------------------------------------- ---------------------------------------
Windows has a built-in dialog for changing environment variables: Right-click Windows has a built-in dialog for changing environment variables (following
the icon for your machine (usually located on your Desktop and called "My guide applies to XP classical view): Right-click the icon for your machine
Computer") and choose :menuselection:`Properties` there. Then, open the (usually located on your Desktop and called "My Computer") and choose
:guilabel:`Advanced` tab and click the :guilabel:`Environment Variables` button. :menuselection:`Properties` there. Then, open the :guilabel:`Advanced` tab
and click the :guilabel:`Environment Variables` button.
In short, your path is: In short, your path is:
...@@ -107,7 +110,8 @@ command:: ...@@ -107,7 +110,8 @@ command::
set PYTHONPATH=%PYTHONPATH%;C:\My_python_lib set PYTHONPATH=%PYTHONPATH%;C:\My_python_lib
To make this setting permanent, you could add the corresponding command line to To make this setting permanent, you could add the corresponding command line to
your :file:`autoexec.bat`. your :file:`autoexec.bat`. :program:`msconfig` is a graphical interface to this
file.
Viewing environment variables can also be done more straight-forward: The Viewing environment variables can also be done more straight-forward: The
command prompt will expand strings wrapped into percent signs automatically:: command prompt will expand strings wrapped into percent signs automatically::
...@@ -124,6 +128,9 @@ Consult :command:`set /?` for details on this behaviour. ...@@ -124,6 +128,9 @@ Consult :command:`set /?` for details on this behaviour.
http://support.microsoft.com/kb/310519 http://support.microsoft.com/kb/310519
How To Manage Environment Variables in Windows XP How To Manage Environment Variables in Windows XP
http://www.chem.gla.ac.uk/~louis/software/faq/q1.html
Setting Environment variables, Louis J. Farrugia
Finding the Python executable Finding the Python executable
----------------------------- -----------------------------
......
...@@ -410,25 +410,12 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/ ...@@ -410,25 +410,12 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
PyAPI_FUNC(Py_ssize_t) PyObject_Length(PyObject *o); PyAPI_FUNC(Py_ssize_t) PyObject_Length(PyObject *o);
#define PyObject_Length PyObject_Size #define PyObject_Length PyObject_Size
PyAPI_FUNC(Py_ssize_t) _PyObject_LengthHint(PyObject *o); PyAPI_FUNC(Py_ssize_t) _PyObject_LengthHint(PyObject *o, Py_ssize_t);
/* /*
Return the size of object o. If the object, o, provides Guess the size of object o using len(o) or o.__length_hint__().
both sequence and mapping protocols, the sequence size is If neither of those return a non-negative value, then return the
returned. On error, -1 is returned. If the object provides default value. This function never fails. All exceptions are cleared.
a __length_hint__() method, its value is returned. This is an
internal undocumented API provided for performance reasons;
for compatibility, don't use it outside the core. This is the
equivalent to the Python expression:
try:
return len(o)
except (AttributeError, TypeError):
exc_type, exc_value, exc_tb = sys.exc_info()
try:
return o.__length_hint__()
except:
pass
raise exc_type, exc_value, exc_tb
*/ */
PyAPI_FUNC(PyObject *) PyObject_GetItem(PyObject *o, PyObject *key); PyAPI_FUNC(PyObject *) PyObject_GetItem(PyObject *o, PyObject *key);
......
...@@ -22,13 +22,17 @@ from .errors import DistutilsPlatformError ...@@ -22,13 +22,17 @@ from .errors import DistutilsPlatformError
PREFIX = os.path.normpath(sys.prefix) PREFIX = os.path.normpath(sys.prefix)
EXEC_PREFIX = os.path.normpath(sys.exec_prefix) EXEC_PREFIX = os.path.normpath(sys.exec_prefix)
# Path to the base directory of the project. On Windows the binary may
# live in project/PCBuild9
project_base = os.path.dirname(os.path.abspath(sys.executable))
if os.name == "nt" and "pcbuild" in project_base[-8:].lower():
project_base = os.path.abspath(os.path.join(project_base, os.path.pardir))
# python_build: (Boolean) if true, we're either building Python or # python_build: (Boolean) if true, we're either building Python or
# building an extension with an un-installed Python, so we use # building an extension with an un-installed Python, so we use
# different (hard-wired) directories. # different (hard-wired) directories.
python_build = os.path.isfile(os.path.join(project_base, "Modules",
argv0_path = os.path.dirname(os.path.abspath(sys.executable)) "Setup.dist"))
python_build = os.path.isfile(os.path.join(argv0_path, "Modules", "Setup"))
def get_python_version(): def get_python_version():
"""Return a string containing the major and minor Python version, """Return a string containing the major and minor Python version,
...@@ -177,7 +181,10 @@ def customize_compiler(compiler): ...@@ -177,7 +181,10 @@ def customize_compiler(compiler):
def get_config_h_filename(): def get_config_h_filename():
"""Return full pathname of installed pyconfig.h file.""" """Return full pathname of installed pyconfig.h file."""
if python_build: if python_build:
inc_dir = argv0_path if os.name == "nt":
inc_dir = os.path.join(project_base, "PC")
else:
inc_dir = project_base
else: else:
inc_dir = get_python_inc(plat_specific=1) inc_dir = get_python_inc(plat_specific=1)
if get_python_version() < '2.2': if get_python_version() < '2.2':
...@@ -402,6 +409,8 @@ def _init_nt(): ...@@ -402,6 +409,8 @@ def _init_nt():
g['SO'] = '.pyd' g['SO'] = '.pyd'
g['EXE'] = ".exe" g['EXE'] = ".exe"
g['VERSION'] = get_python_version().replace(".", "")
g['BINDIR'] = os.path.dirname(os.path.abspath(sys.executable))
global _config_vars global _config_vars
_config_vars = g _config_vars = g
......
...@@ -521,7 +521,5 @@ class CommonTest(seq_tests.CommonTest): ...@@ -521,7 +521,5 @@ class CommonTest(seq_tests.CommonTest):
# Bug #1242657 # Bug #1242657
class F(object): class F(object):
def __iter__(self): def __iter__(self):
yield 23
def __len__(self):
raise KeyboardInterrupt raise KeyboardInterrupt
self.assertRaises(KeyboardInterrupt, list, F()) self.assertRaises(KeyboardInterrupt, list, F())
...@@ -7,6 +7,9 @@ import xmlrpclib ...@@ -7,6 +7,9 @@ import xmlrpclib
import SimpleXMLRPCServer import SimpleXMLRPCServer
import threading import threading
import mimetools import mimetools
import httplib
import socket
import os
from test import test_support from test import test_support
alist = [{'astring': 'foo@bar.baz.spam', alist = [{'astring': 'foo@bar.baz.spam',
...@@ -254,9 +257,16 @@ PORT = None ...@@ -254,9 +257,16 @@ PORT = None
def http_server(evt, numrequests): def http_server(evt, numrequests):
class TestInstanceClass: class TestInstanceClass:
def div(self, x, y): def div(self, x, y):
'''This is the div function'''
return x // y return x // y
def _methodHelp(self, name):
if name == 'div':
return 'This is the div function'
def my_function():
'''This is my function'''
return True
try: try:
serv = SimpleXMLRPCServer.SimpleXMLRPCServer(("localhost", 0), serv = SimpleXMLRPCServer.SimpleXMLRPCServer(("localhost", 0),
logRequests=False, bind_and_activate=False) logRequests=False, bind_and_activate=False)
...@@ -268,6 +278,7 @@ def http_server(evt, numrequests): ...@@ -268,6 +278,7 @@ def http_server(evt, numrequests):
serv.register_multicall_functions() serv.register_multicall_functions()
serv.register_function(pow) serv.register_function(pow)
serv.register_function(lambda x,y: x+y, 'add') serv.register_function(lambda x,y: x+y, 'add')
serv.register_function(my_function)
serv.register_instance(TestInstanceClass()) serv.register_instance(TestInstanceClass())
# handle up to 'numrequests' requests # handle up to 'numrequests' requests
...@@ -284,7 +295,6 @@ def http_server(evt, numrequests): ...@@ -284,7 +295,6 @@ def http_server(evt, numrequests):
class SimpleServerTestCase(unittest.TestCase): class SimpleServerTestCase(unittest.TestCase):
def setUp(self): def setUp(self):
# enable traceback reporting # enable traceback reporting
...@@ -318,12 +328,25 @@ class SimpleServerTestCase(unittest.TestCase): ...@@ -318,12 +328,25 @@ class SimpleServerTestCase(unittest.TestCase):
# protocol error; provide additional information in test output # protocol error; provide additional information in test output
self.fail("%s\n%s" % (e, e.headers)) self.fail("%s\n%s" % (e, e.headers))
def test_404(self):
# send POST with httplib, it should return 404 header and
# 'Not Found' message.
import pdb; pdb.set_trace()
conn = httplib.HTTPConnection('localhost', PORT)
conn.request(b'POST', b'/this-is-not-valid')
response = conn.getresponse()
conn.close()
self.assertEqual(response.status, 404)
self.assertEqual(response.reason, 'Not Found')
def test_introspection1(self): def test_introspection1(self):
try: try:
p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT) p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT)
meth = p.system.listMethods() meth = p.system.listMethods()
expected_methods = set(['pow', 'div', 'add', 'system.listMethods', expected_methods = set(['pow', 'div', 'my_function', 'add',
'system.methodHelp', 'system.methodSignature', 'system.multicall']) 'system.listMethods', 'system.methodHelp',
'system.methodSignature', 'system.multicall'])
self.assertEqual(set(meth), expected_methods) self.assertEqual(set(meth), expected_methods)
except xmlrpclib.ProtocolError as e: except xmlrpclib.ProtocolError as e:
# protocol error; provide additional information in test output # protocol error; provide additional information in test output
...@@ -331,6 +354,7 @@ class SimpleServerTestCase(unittest.TestCase): ...@@ -331,6 +354,7 @@ class SimpleServerTestCase(unittest.TestCase):
def test_introspection2(self): def test_introspection2(self):
try: try:
# test _methodHelp()
p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT) p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT)
divhelp = p.system.methodHelp('div') divhelp = p.system.methodHelp('div')
self.assertEqual(divhelp, 'This is the div function') self.assertEqual(divhelp, 'This is the div function')
...@@ -339,6 +363,18 @@ class SimpleServerTestCase(unittest.TestCase): ...@@ -339,6 +363,18 @@ class SimpleServerTestCase(unittest.TestCase):
self.fail("%s\n%s" % (e, e.headers)) self.fail("%s\n%s" % (e, e.headers))
def test_introspection3(self): def test_introspection3(self):
try:
# test native doc
p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT)
myfunction = p.system.methodHelp('my_function')
self.assertEqual(myfunction, 'This is my function')
except xmlrpclib.ProtocolError as e:
# ignore failures due to non-blocking socket 'unavailable' errors
if not is_unavailable_exception(e):
# protocol error; provide additional information in test output
self.fail("%s\n%s" % (e, e.headers))
def test_introspection4(self):
# the SimpleXMLRPCServer doesn't support signatures, but # the SimpleXMLRPCServer doesn't support signatures, but
# at least check that we can try making the call # at least check that we can try making the call
try: try:
...@@ -364,6 +400,34 @@ class SimpleServerTestCase(unittest.TestCase): ...@@ -364,6 +400,34 @@ class SimpleServerTestCase(unittest.TestCase):
# protocol error; provide additional information in test output # protocol error; provide additional information in test output
self.fail("%s\n%s" % (e, e.headers)) self.fail("%s\n%s" % (e, e.headers))
def test_non_existing_multicall(self):
try:
p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT)
multicall = xmlrpclib.MultiCall(p)
multicall.this_is_not_exists()
result = multicall()
# result.results contains;
# [{'faultCode': 1, 'faultString': '<type \'exceptions.Exception\'>:'
# 'method "this_is_not_exists" is not supported'>}]
self.assertEqual(result.results[0]['faultCode'], 1)
self.assertEqual(result.results[0]['faultString'],
'<type \'exceptions.Exception\'>:method "this_is_not_exists" '
'is not supported')
except xmlrpclib.ProtocolError as e:
# ignore failures due to non-blocking socket 'unavailable' errors
if not is_unavailable_exception(e):
# protocol error; provide additional information in test output
self.fail("%s\n%s" % (e, e.headers))
def test_dotted_attribute(self):
# this will raise AttirebuteError because code don't want us to use
# private methods
self.assertRaises(AttributeError,
SimpleXMLRPCServer.resolve_dotted_attribute, str, '__add')
self.assert_(SimpleXMLRPCServer.resolve_dotted_attribute(str, 'title'))
# This is a contrived way to make a failure occur on the server side # This is a contrived way to make a failure occur on the server side
# in order to test the _send_traceback_header flag on the server # in order to test the _send_traceback_header flag on the server
...@@ -447,6 +511,70 @@ class FailingServerTestCase(unittest.TestCase): ...@@ -447,6 +511,70 @@ class FailingServerTestCase(unittest.TestCase):
else: else:
self.fail('ProtocolError not raised') self.fail('ProtocolError not raised')
class CGIHandlerTestCase(unittest.TestCase):
def setUp(self):
self.cgi = SimpleXMLRPCServer.CGIXMLRPCRequestHandler()
def tearDown(self):
self.cgi = None
def test_cgi_get(self):
os.environ['REQUEST_METHOD'] = 'GET'
# if the method is GET and no request_text is given, it runs handle_get
# get sysout output
tmp = sys.stdout
sys.stdout = open(test_support.TESTFN, "w")
self.cgi.handle_request()
sys.stdout.close()
sys.stdout = tmp
# parse Status header
handle = open(test_support.TESTFN, "r").read()
status = handle.split()[1]
message = ' '.join(handle.split()[2:4])
self.assertEqual(status, '400')
self.assertEqual(message, 'Bad Request')
os.remove(test_support.TESTFN)
os.environ['REQUEST_METHOD'] = ''
def test_cgi_xmlrpc_response(self):
data = """<?xml version='1.0'?>
<methodCall>
<methodName>test_method</methodName>
<params>
<param>
<value><string>foo</string></value>
</param>
<param>
<value><string>bar</string></value>
</param>
</params>
</methodCall>
"""
open("xmldata.txt", "w").write(data)
tmp1 = sys.stdin
tmp2 = sys.stdout
sys.stdin = open("xmldata.txt", "r")
sys.stdout = open(test_support.TESTFN, "w")
self.cgi.handle_request()
sys.stdin.close()
sys.stdout.close()
sys.stdin = tmp1
sys.stdout = tmp2
# will respond exception, if so, our goal is achieved ;)
handle = open(test_support.TESTFN, "r").read()
# start with 44th char so as not to get http header, we just need only xml
self.assertRaises(xmlrpclib.Fault, xmlrpclib.loads, handle[44:])
os.remove("xmldata.txt")
os.remove(test_support.TESTFN)
def test_main(): def test_main():
xmlrpc_tests = [XMLRPCTestCase, HelperTestCase, DateTimeTestCase, xmlrpc_tests = [XMLRPCTestCase, HelperTestCase, DateTimeTestCase,
...@@ -459,6 +587,7 @@ def test_main(): ...@@ -459,6 +587,7 @@ def test_main():
if sys.platform != 'win32': if sys.platform != 'win32':
xmlrpc_tests.append(SimpleServerTestCase) xmlrpc_tests.append(SimpleServerTestCase)
xmlrpc_tests.append(FailingServerTestCase) xmlrpc_tests.append(FailingServerTestCase)
xmlrpc_tests.append(CGIHandlerTestCase)
test_support.run_unittest(*xmlrpc_tests) test_support.run_unittest(*xmlrpc_tests)
......
...@@ -190,6 +190,7 @@ David Ely ...@@ -190,6 +190,7 @@ David Ely
Jeff Epler Jeff Epler
Tom Epperly Tom Epperly
Stoffel Erasmus Stoffel Erasmus
Turkay Eren
Jrgen A. Erhard Jrgen A. Erhard
Michael Ernst Michael Ernst
Ben Escoto Ben Escoto
......
...@@ -80,29 +80,47 @@ PyObject_Length(PyObject *o) ...@@ -80,29 +80,47 @@ PyObject_Length(PyObject *o)
} }
#define PyObject_Length PyObject_Size #define PyObject_Length PyObject_Size
/* The length hint function returns a non-negative value from o.__len__()
or o.__length_hint__(). If those methods aren't found or return a negative
value, then the defaultvalue is returned. This function never fails.
Accordingly, it will mask exceptions raised in either method.
*/
Py_ssize_t Py_ssize_t
_PyObject_LengthHint(PyObject *o) _PyObject_LengthHint(PyObject *o, Py_ssize_t defaultvalue)
{ {
Py_ssize_t rv = PyObject_Size(o); static PyObject *hintstrobj = NULL;
if (rv != -1) PyObject *ro;
Py_ssize_t rv;
/* try o.__len__() */
rv = PyObject_Size(o);
if (rv >= 0)
return rv; return rv;
if (PyErr_ExceptionMatches(PyExc_TypeError) || if (PyErr_Occurred())
PyErr_ExceptionMatches(PyExc_AttributeError)) { PyErr_Clear();
PyObject *err_type, *err_value, *err_tb, *ro;
/* cache a hashed version of the attribute string */
PyErr_Fetch(&err_type, &err_value, &err_tb); if (hintstrobj == NULL) {
ro = PyObject_CallMethod(o, "__length_hint__", NULL); hintstrobj = PyUnicode_InternFromString("__length_hint__");
if (ro != NULL) { if (hintstrobj == NULL)
rv = PyLong_AsLong(ro); goto defaultcase;
Py_DECREF(ro);
Py_XDECREF(err_type);
Py_XDECREF(err_value);
Py_XDECREF(err_tb);
return rv;
}
PyErr_Restore(err_type, err_value, err_tb);
} }
return -1;
/* try o.__length_hint__() */
ro = PyObject_CallMethodObjArgs(o, hintstrobj, NULL);
if (ro == NULL)
goto defaultcase;
rv = PyLong_AsSsize_t(ro);
Py_DECREF(ro);
if (rv >= 0)
return rv;
defaultcase:
if (PyErr_Occurred())
PyErr_Clear();
return defaultvalue;
} }
PyObject * PyObject *
...@@ -1655,17 +1673,7 @@ PySequence_Tuple(PyObject *v) ...@@ -1655,17 +1673,7 @@ PySequence_Tuple(PyObject *v)
return NULL; return NULL;
/* Guess result size and allocate space. */ /* Guess result size and allocate space. */
n = _PyObject_LengthHint(v); n = _PyObject_LengthHint(v, 10);
if (n < 0) {
if (PyErr_Occurred()
&& !PyErr_ExceptionMatches(PyExc_TypeError)
&& !PyErr_ExceptionMatches(PyExc_AttributeError)) {
Py_DECREF(it);
return NULL;
}
PyErr_Clear();
n = 10; /* arbitrary */
}
result = PyTuple_New(n); result = PyTuple_New(n);
if (result == NULL) if (result == NULL)
goto Fail; goto Fail;
......
...@@ -2598,19 +2598,8 @@ bytes_extend(PyBytesObject *self, PyObject *arg) ...@@ -2598,19 +2598,8 @@ bytes_extend(PyBytesObject *self, PyObject *arg)
if (it == NULL) if (it == NULL)
return NULL; return NULL;
/* Try to determine the length of the argument. */ /* Try to determine the length of the argument. 32 is abitrary. */
buf_size = _PyObject_LengthHint(arg); buf_size = _PyObject_LengthHint(arg, 32);
/* The length of the argument is unknown or invalid. */
if (buf_size < 0) {
if (PyErr_Occurred()
&& !PyErr_ExceptionMatches(PyExc_TypeError)
&& !PyErr_ExceptionMatches(PyExc_AttributeError)) {
Py_DECREF(it);
return NULL;
}
PyErr_Clear();
buf_size = 32; /* arbitrary */
}
buf = (char *)PyMem_Malloc(buf_size * sizeof(char)); buf = (char *)PyMem_Malloc(buf_size * sizeof(char));
if (buf == NULL) if (buf == NULL)
......
...@@ -758,17 +758,7 @@ listextend(PyListObject *self, PyObject *b) ...@@ -758,17 +758,7 @@ listextend(PyListObject *self, PyObject *b)
iternext = *it->ob_type->tp_iternext; iternext = *it->ob_type->tp_iternext;
/* Guess a result list size. */ /* Guess a result list size. */
n = _PyObject_LengthHint(b); n = _PyObject_LengthHint(b, 8);
if (n < 0) {
if (PyErr_Occurred()
&& !PyErr_ExceptionMatches(PyExc_TypeError)
&& !PyErr_ExceptionMatches(PyExc_AttributeError)) {
Py_DECREF(it);
return NULL;
}
PyErr_Clear();
n = 8; /* arbitrary */
}
m = Py_Size(self); m = Py_Size(self);
mn = m + n; mn = m + n;
if (mn >= m) { if (mn >= m) {
......
...@@ -209,12 +209,6 @@ typedef int pid_t; ...@@ -209,12 +209,6 @@ typedef int pid_t;
#define Py_IS_INFINITY(X) (!_finite(X) && !_isnan(X)) #define Py_IS_INFINITY(X) (!_finite(X) && !_isnan(X))
#define Py_IS_FINITE(X) _finite(X) #define Py_IS_FINITE(X) _finite(X)
/* Turn off warnings about deprecated C runtime functions in
VisualStudio .NET 2005 */
#if _MSC_VER >= 1400 && !defined _CRT_SECURE_NO_DEPRECATE
#define _CRT_SECURE_NO_DEPRECATE
#endif
#endif /* _MSC_VER */ #endif /* _MSC_VER */
/* define some ANSI types that are not defined in earlier Win headers */ /* define some ANSI types that are not defined in earlier Win headers */
......
...@@ -14,7 +14,7 @@ par = os.path.pardir ...@@ -14,7 +14,7 @@ par = os.path.pardir
TCL = "tcl8.4.16" TCL = "tcl8.4.16"
TK = "tk8.4.16" TK = "tk8.4.16"
TIX = "Tix8.4.0" TIX = "tix-8.4.0"
#TIX = "Tix8.4.2" #TIX = "Tix8.4.2"
ROOT = os.path.abspath(os.path.join(here, par, par)) ROOT = os.path.abspath(os.path.join(here, par, par))
NMAKE = "nmake /nologo " NMAKE = "nmake /nologo "
...@@ -53,6 +53,7 @@ def build(platform, clean): ...@@ -53,6 +53,7 @@ def build(platform, clean):
# TIX # TIX
if True: if True:
# python9.mak is available at http://svn.python.org
os.chdir(os.path.join(ROOT, TIX, "win")) os.chdir(os.path.join(ROOT, TIX, "win"))
if clean: if clean:
system(NMAKE + "/f python9.mak clean") system(NMAKE + "/f python9.mak clean")
......
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <stdio.h> #include <stdio.h>
#define CMD_SIZE 500
/* This file creates the getbuildinfo.o object, by first /* This file creates the getbuildinfo.o object, by first
invoking subwcrev.exe (if found), and then invoking cl.exe. invoking subwcrev.exe (if found), and then invoking cl.exe.
As a side effect, it might generate PCBuild\getbuildinfo2.c As a side effect, it might generate PCBuild\getbuildinfo2.c
...@@ -23,7 +25,7 @@ int make_buildinfo2() ...@@ -23,7 +25,7 @@ int make_buildinfo2()
{ {
struct _stat st; struct _stat st;
HKEY hTortoise; HKEY hTortoise;
char command[500]; char command[CMD_SIZE+1];
DWORD type, size; DWORD type, size;
if (_stat(".svn", &st) < 0) if (_stat(".svn", &st) < 0)
return 0; return 0;
...@@ -40,11 +42,11 @@ int make_buildinfo2() ...@@ -40,11 +42,11 @@ int make_buildinfo2()
type != REG_SZ) type != REG_SZ)
/* Registry corrupted */ /* Registry corrupted */
return 0; return 0;
strcat(command, "bin\\subwcrev.exe"); strcat_s(command, CMD_SIZE, "bin\\subwcrev.exe");
if (_stat(command+1, &st) < 0) if (_stat(command+1, &st) < 0)
/* subwcrev.exe not part of the release */ /* subwcrev.exe not part of the release */
return 0; return 0;
strcat(command, "\" .. ..\\Modules\\getbuildinfo.c getbuildinfo2.c"); strcat_s(command, CMD_SIZE, "\" .. ..\\Modules\\getbuildinfo.c getbuildinfo2.c");
puts(command); fflush(stdout); puts(command); fflush(stdout);
if (system(command) < 0) if (system(command) < 0)
return 0; return 0;
...@@ -60,17 +62,17 @@ int main(int argc, char*argv[]) ...@@ -60,17 +62,17 @@ int main(int argc, char*argv[])
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if (strcmp(argv[1], "Release") == 0) { if (strcmp(argv[1], "Release") == 0) {
strcat(command, "-MD "); strcat_s(command, CMD_SIZE, "-MD ");
} }
else if (strcmp(argv[1], "Debug") == 0) { else if (strcmp(argv[1], "Debug") == 0) {
strcat(command, "-D_DEBUG -MDd "); strcat_s(command, CMD_SIZE, "-D_DEBUG -MDd ");
} }
else if (strcmp(argv[1], "ReleaseItanium") == 0) { else if (strcmp(argv[1], "ReleaseItanium") == 0) {
strcat(command, "-MD /USECL:MS_ITANIUM "); strcat_s(command, CMD_SIZE, "-MD /USECL:MS_ITANIUM ");
} }
else if (strcmp(argv[1], "ReleaseAMD64") == 0) { else if (strcmp(argv[1], "ReleaseAMD64") == 0) {
strcat(command, "-MD "); strcat_s(command, CMD_SIZE, "-MD ");
strcat(command, "-MD /USECL:MS_OPTERON "); strcat_s(command, CMD_SIZE, "-MD /USECL:MS_OPTERON ");
} }
else { else {
fprintf(stderr, "unsupported configuration %s\n", argv[1]); fprintf(stderr, "unsupported configuration %s\n", argv[1]);
...@@ -78,14 +80,14 @@ int main(int argc, char*argv[]) ...@@ -78,14 +80,14 @@ int main(int argc, char*argv[])
} }
if ((do_unlink = make_buildinfo2())) if ((do_unlink = make_buildinfo2()))
strcat(command, "getbuildinfo2.c -DSUBWCREV "); strcat_s(command, CMD_SIZE, "getbuildinfo2.c -DSUBWCREV ");
else else
strcat(command, "..\\Modules\\getbuildinfo.c"); strcat_s(command, CMD_SIZE, "..\\Modules\\getbuildinfo.c");
strcat(command, " -Fogetbuildinfo.o -I..\\Include -I..\\PC"); strcat_s(command, CMD_SIZE, " -Fogetbuildinfo.o -I..\\Include -I..\\PC");
puts(command); fflush(stdout); puts(command); fflush(stdout);
result = system(command); result = system(command);
if (do_unlink) if (do_unlink)
unlink("getbuildinfo2.c"); _unlink("getbuildinfo2.c");
if (result < 0) if (result < 0)
return EXIT_FAILURE; return EXIT_FAILURE;
return 0; return 0;
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
InlineFunctionExpansion="1" InlineFunctionExpansion="1"
EnableIntrinsicFunctions="true" EnableIntrinsicFunctions="true"
AdditionalIncludeDirectories="..\Include; ..\PC" AdditionalIncludeDirectories="..\Include; ..\PC"
PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_WIN32" PreprocessorDefinitions="_WIN32"
StringPooling="true" StringPooling="true"
ExceptionHandling="0" ExceptionHandling="0"
RuntimeLibrary="0" RuntimeLibrary="0"
......
...@@ -281,6 +281,14 @@ Edition. ...@@ -281,6 +281,14 @@ Edition.
Profile Guided Optimization Profile Guided Optimization
--------------------------- ---------------------------
The solution has two configurations for PGO. The PGInstrument configuration
must be build first. The PGInstrument binaries are lniked against a profiling
library and contain extra debug information. The PGUpdate configuration takes the profiling data and generates optimized binaries.
The build_pgo.bat script automates the creation of optimized binaries. It
creates the PGI files, runs the unit test suite or PyBench with the PGI
python and finally creates the optimized files.
http://msdn2.microsoft.com/en-us/library/e7k32f4k(VS.90).aspx http://msdn2.microsoft.com/en-us/library/e7k32f4k(VS.90).aspx
Static library Static library
...@@ -300,7 +308,7 @@ The PCbuild9 solution makes heavy use of Visual Studio property files ...@@ -300,7 +308,7 @@ The PCbuild9 solution makes heavy use of Visual Studio property files
(*.vsprops). The properties can be viewed and altered in the Property (*.vsprops). The properties can be viewed and altered in the Property
Manager (View -> Other Windows -> Property Manager). Manager (View -> Other Windows -> Property Manager).
* debug (debug macros) * debug (debug macro: _DEBUG)
* pginstrument (PGO) * pginstrument (PGO)
* pgupdate (PGO) * pgupdate (PGO)
+-- pginstrument +-- pginstrument
...@@ -310,8 +318,8 @@ Manager (View -> Other Windows -> Property Manager). ...@@ -310,8 +318,8 @@ Manager (View -> Other Windows -> Property Manager).
* pyd_d (python extension, debug build) * pyd_d (python extension, debug build)
+-- debug +-- debug
+-- pyproject +-- pyproject
* pyproject (base settings for all projects) * pyproject (base settings for all projects, user macros like PyDllName)
* release (release macros) * release (release macro: NDEBUG)
* x64 (AMD64 / x64 platform specific settings) * x64 (AMD64 / x64 platform specific settings)
The pyproject propertyfile defines _WIN32 and x64 defines _WIN64 and _M_X64 The pyproject propertyfile defines _WIN32 and x64 defines _WIN64 and _M_X64
...@@ -320,6 +328,7 @@ about the macros and confuse the user with false information. ...@@ -320,6 +328,7 @@ about the macros and confuse the user with false information.
YOUR OWN EXTENSION DLLs YOUR OWN EXTENSION DLLs
----------------------- -----------------------
If you want to create your own extension module DLL, there's an example If you want to create your own extension module DLL, there's an example
with easy-to-follow instructions in ../PC/example/; read the file with easy-to-follow instructions in ../PC/example/; read the file
readme.txt there first. readme.txt there first.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment