summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
Diffstat (limited to 'Lib')
-rw-r--r--Lib/distutils/sysconfig.py19
-rw-r--r--Lib/test/list_tests.py2
-rw-r--r--Lib/test/test_xmlrpc.py137
3 files changed, 147 insertions, 11 deletions
diff --git a/Lib/distutils/sysconfig.py b/Lib/distutils/sysconfig.py
index 70a2799..191f3d1 100644
--- a/Lib/distutils/sysconfig.py
+++ b/Lib/distutils/sysconfig.py
@@ -22,13 +22,17 @@ from .errors import DistutilsPlatformError
PREFIX = os.path.normpath(sys.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
# building an extension with an un-installed Python, so we use
# different (hard-wired) directories.
-
-argv0_path = os.path.dirname(os.path.abspath(sys.executable))
-python_build = os.path.isfile(os.path.join(argv0_path, "Modules", "Setup"))
-
+python_build = os.path.isfile(os.path.join(project_base, "Modules",
+ "Setup.dist"))
def get_python_version():
"""Return a string containing the major and minor Python version,
@@ -177,7 +181,10 @@ def customize_compiler(compiler):
def get_config_h_filename():
"""Return full pathname of installed pyconfig.h file."""
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:
inc_dir = get_python_inc(plat_specific=1)
if get_python_version() < '2.2':
@@ -402,6 +409,8 @@ def _init_nt():
g['SO'] = '.pyd'
g['EXE'] = ".exe"
+ g['VERSION'] = get_python_version().replace(".", "")
+ g['BINDIR'] = os.path.dirname(os.path.abspath(sys.executable))
global _config_vars
_config_vars = g
diff --git a/Lib/test/list_tests.py b/Lib/test/list_tests.py
index 4317316..f03cdfe 100644
--- a/Lib/test/list_tests.py
+++ b/Lib/test/list_tests.py
@@ -521,7 +521,5 @@ class CommonTest(seq_tests.CommonTest):
# Bug #1242657
class F(object):
def __iter__(self):
- yield 23
- def __len__(self):
raise KeyboardInterrupt
self.assertRaises(KeyboardInterrupt, list, F())
diff --git a/Lib/test/test_xmlrpc.py b/Lib/test/test_xmlrpc.py
index 2674716..75a69e8 100644
--- a/Lib/test/test_xmlrpc.py
+++ b/Lib/test/test_xmlrpc.py
@@ -7,6 +7,9 @@ import xmlrpclib
import SimpleXMLRPCServer
import threading
import mimetools
+import httplib
+import socket
+import os
from test import test_support
alist = [{'astring': 'foo@bar.baz.spam',
@@ -254,9 +257,16 @@ PORT = None
def http_server(evt, numrequests):
class TestInstanceClass:
def div(self, x, y):
- '''This is the div function'''
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:
serv = SimpleXMLRPCServer.SimpleXMLRPCServer(("localhost", 0),
logRequests=False, bind_and_activate=False)
@@ -268,6 +278,7 @@ def http_server(evt, numrequests):
serv.register_multicall_functions()
serv.register_function(pow)
serv.register_function(lambda x,y: x+y, 'add')
+ serv.register_function(my_function)
serv.register_instance(TestInstanceClass())
# handle up to 'numrequests' requests
@@ -284,7 +295,6 @@ def http_server(evt, numrequests):
-
class SimpleServerTestCase(unittest.TestCase):
def setUp(self):
# enable traceback reporting
@@ -318,12 +328,25 @@ class SimpleServerTestCase(unittest.TestCase):
# protocol error; provide additional information in test output
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):
try:
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'])
+ expected_methods = set(['pow', 'div', 'my_function', 'add',
+ 'system.listMethods', 'system.methodHelp',
+ 'system.methodSignature', 'system.multicall'])
self.assertEqual(set(meth), expected_methods)
except xmlrpclib.ProtocolError as e:
# protocol error; provide additional information in test output
@@ -331,6 +354,7 @@ class SimpleServerTestCase(unittest.TestCase):
def test_introspection2(self):
try:
+ # test _methodHelp()
p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT)
divhelp = p.system.methodHelp('div')
self.assertEqual(divhelp, 'This is the div function')
@@ -339,6 +363,18 @@ class SimpleServerTestCase(unittest.TestCase):
self.fail("%s\n%s" % (e, e.headers))
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
# at least check that we can try making the call
try:
@@ -364,6 +400,34 @@ class SimpleServerTestCase(unittest.TestCase):
# protocol error; provide additional information in test output
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
# in order to test the _send_traceback_header flag on the server
@@ -447,6 +511,70 @@ class FailingServerTestCase(unittest.TestCase):
else:
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():
xmlrpc_tests = [XMLRPCTestCase, HelperTestCase, DateTimeTestCase,
@@ -459,6 +587,7 @@ def test_main():
if sys.platform != 'win32':
xmlrpc_tests.append(SimpleServerTestCase)
xmlrpc_tests.append(FailingServerTestCase)
+ xmlrpc_tests.append(CGIHandlerTestCase)
test_support.run_unittest(*xmlrpc_tests)