mirror of
				https://github.com/python/cpython.git
				synced 2025-11-04 03:44:55 +00:00 
			
		
		
		
	svn+ssh://pythondev@svn.python.org/python/trunk
................
  r62425 | andrew.kuchling | 2008-04-21 03:45:57 +0200 (Mon, 21 Apr 2008) | 1 line
  Comment typo
................
  r62426 | mark.dickinson | 2008-04-21 03:55:50 +0200 (Mon, 21 Apr 2008) | 2 lines
  Silence 'r may be used uninitialized' compiler warning.
................
  r62427 | andrew.kuchling | 2008-04-21 04:08:00 +0200 (Mon, 21 Apr 2008) | 1 line
  Markup fix
................
  r62428 | andrew.kuchling | 2008-04-21 04:08:13 +0200 (Mon, 21 Apr 2008) | 1 line
  Wording changes
................
  r62429 | andrew.kuchling | 2008-04-21 04:14:24 +0200 (Mon, 21 Apr 2008) | 1 line
  Add various items
................
  r62434 | thomas.heller | 2008-04-21 15:46:55 +0200 (Mon, 21 Apr 2008) | 1 line
  Fix typo.
................
  r62435 | david.goodger | 2008-04-21 16:40:22 +0200 (Mon, 21 Apr 2008) | 1 line
  corrections ("reStructuredText" is one word)
................
  r62436 | david.goodger | 2008-04-21 16:43:33 +0200 (Mon, 21 Apr 2008) | 1 line
  capitalization
................
  r62441 | gregory.p.smith | 2008-04-21 19:46:40 +0200 (Mon, 21 Apr 2008) | 2 lines
  explicitly flush after the ... since there wasn't a newline
................
  r62444 | jeroen.ruigrok | 2008-04-21 22:15:39 +0200 (Mon, 21 Apr 2008) | 2 lines
  Windows x64 also falls under VER_PLATFORM_WIN32_NT.
................
  r62446 | gregory.p.smith | 2008-04-21 23:31:08 +0200 (Mon, 21 Apr 2008) | 3 lines
  If sys.stdin is not a tty, fall back to default_getpass after printing
  a warning instead of failing with a termios.error.
................
  r62447 | mark.dickinson | 2008-04-22 00:32:24 +0200 (Tue, 22 Apr 2008) | 8 lines
  test_math and test_cmath are failing on the FreeBSD 6.2 trunk buildbot,
  apparently because tanh(-0.) loses the sign of zero on that platform.
  If true, this is a bug in FreeBSD.
  Added a configure test to verify this.  I still need to figure out
  how best to deal with this failure.
................
  r62448 | amaury.forgeotdarc | 2008-04-22 00:35:30 +0200 (Tue, 22 Apr 2008) | 7 lines
  Issue 2665: On Windows, sys.stderr does not contain a valid file when running without a console.
  It seems to work, but will fail at the first flush.
  This causes IDLE to crash when too many warnings are printed.
  Will backport.
................
  r62450 | benjamin.peterson | 2008-04-22 00:57:00 +0200 (Tue, 22 Apr 2008) | 2 lines
  Fix Sphinx warnings
................
  r62451 | mark.dickinson | 2008-04-22 02:54:27 +0200 (Tue, 22 Apr 2008) | 3 lines
  Make configure test for tanh(-0.) == -0. committed in r62447 actually
  work.  (The test wasn't properly linked with libm.  Sigh.)
................
  r62452 | benjamin.peterson | 2008-04-22 04:16:03 +0200 (Tue, 22 Apr 2008) | 2 lines
  Various io doc updates
................
  r62453 | neal.norwitz | 2008-04-22 07:07:47 +0200 (Tue, 22 Apr 2008) | 1 line
  Add Thomas Lee
................
  r62454 | gregory.p.smith | 2008-04-22 10:08:41 +0200 (Tue, 22 Apr 2008) | 8 lines
  Major improvements:
  * Default to using /dev/tty for the password prompt and input before
    falling back to sys.stdin and sys.stderr.
  * Use sys.stderr instead of sys.stdout.
  * print the 'password may be echoed' warning to stream used to display
    the prompt rather than always sys.stderr.
  * warn() with GetPassWarning when input may be echoed.
................
  r62455 | gregory.p.smith | 2008-04-22 10:11:33 +0200 (Tue, 22 Apr 2008) | 2 lines
  update the getpass entry
................
  r62463 | amaury.forgeotdarc | 2008-04-22 23:14:41 +0200 (Tue, 22 Apr 2008) | 5 lines
  Issue #2670: urllib2.build_opener() failed when two handlers
  derive the same default base class.
  Will backport.
................
  r62465 | skip.montanaro | 2008-04-23 00:45:09 +0200 (Wed, 23 Apr 2008) | 3 lines
  Factor in documentation changes from issue 1753732.
................
  r62466 | gregory.p.smith | 2008-04-23 03:06:42 +0200 (Wed, 23 Apr 2008) | 2 lines
  syntax fixup
................
  r62469 | benjamin.peterson | 2008-04-23 22:38:06 +0200 (Wed, 23 Apr 2008) | 2 lines
  #2673 Fix example typo in optparse docs
................
  r62474 | martin.v.loewis | 2008-04-24 11:50:50 +0200 (Thu, 24 Apr 2008) | 2 lines
  Add Guilherme Polo.
................
  r62476 | martin.v.loewis | 2008-04-24 15:16:36 +0200 (Thu, 24 Apr 2008) | 3 lines
  Remove Py_Refcnt, Py_Type, Py_Size, as they were added only
  for backwards compatibility, yet 2.5 did not have them at all.
................
  r62477 | martin.v.loewis | 2008-04-24 15:17:24 +0200 (Thu, 24 Apr 2008) | 2 lines
  Fix typo.
................
  r62478 | martin.v.loewis | 2008-04-24 15:18:03 +0200 (Thu, 24 Apr 2008) | 2 lines
  Add Jesus Cea.
................
  r62480 | amaury.forgeotdarc | 2008-04-24 20:07:05 +0200 (Thu, 24 Apr 2008) | 4 lines
  Issue2681: the literal 0o8 was wrongly accepted, and evaluated as float(0.0).
  This happened only when 8 is the first digit.
  Credits go to Lukas Meuser.
................
  r62485 | amaury.forgeotdarc | 2008-04-24 22:10:26 +0200 (Thu, 24 Apr 2008) | 5 lines
  Disable gc when running test_trace, or we may record the __del__ of collected objects.
  See http://mail.python.org/pipermail/python-checkins/2008-April/068633.html
  the extra events perfectly match several calls to socket._fileobject.__del__()
................
  r62492 | neal.norwitz | 2008-04-25 05:40:17 +0200 (Fri, 25 Apr 2008) | 1 line
  Fix typo (now -> no)
................
  r62497 | armin.rigo | 2008-04-25 11:35:18 +0200 (Fri, 25 Apr 2008) | 2 lines
  A new crasher.
................
  r62498 | thomas.heller | 2008-04-25 17:44:16 +0200 (Fri, 25 Apr 2008) | 1 line
  Add from_buffer and from_buffer_copy class methods to ctypes types.
................
  r62500 | mark.dickinson | 2008-04-25 18:59:09 +0200 (Fri, 25 Apr 2008) | 3 lines
  Issue 2635: fix bug in the fix_sentence_endings option to textwrap.fill.
................
  r62507 | benjamin.peterson | 2008-04-25 23:43:56 +0200 (Fri, 25 Apr 2008) | 2 lines
  Allow test_import to work when it is invoked directly
................
  r62513 | georg.brandl | 2008-04-26 20:31:07 +0200 (Sat, 26 Apr 2008) | 2 lines
  #2691: document PyLong (s)size_t APIs, patch by Alexander Belopolsky.
................
  r62514 | georg.brandl | 2008-04-26 20:32:17 +0200 (Sat, 26 Apr 2008) | 2 lines
  Add missing return type to dealloc.
................
  r62516 | alexandre.vassalotti | 2008-04-27 02:52:24 +0200 (Sun, 27 Apr 2008) | 2 lines
  Fixed URL of PEP 205 in weakref's module docstring.
................
  r62521 | georg.brandl | 2008-04-27 11:39:59 +0200 (Sun, 27 Apr 2008) | 2 lines
  #2677: add note that not all functions may accept keyword args.
................
  r62531 | georg.brandl | 2008-04-27 19:38:55 +0200 (Sun, 27 Apr 2008) | 2 lines
  Use correct XHTML tags.
................
  r62535 | benjamin.peterson | 2008-04-27 20:14:39 +0200 (Sun, 27 Apr 2008) | 2 lines
  #2700 Document PyNumber_ToBase
................
  r62545 | skip.montanaro | 2008-04-27 22:53:57 +0200 (Sun, 27 Apr 2008) | 1 line
  minor wording changes, rewrap a few lines
................
  r62546 | kurt.kaiser | 2008-04-27 23:07:41 +0200 (Sun, 27 Apr 2008) | 7 lines
  Home / Control-A toggles between left margin and end of leading white
  space.  Patch 1196903 Jeff Shute.
  M    idlelib/PyShell.py
  M    idlelib/EditorWindow.py
  M    idlelib/NEWS.txt
................
  r62548 | kurt.kaiser | 2008-04-27 23:38:05 +0200 (Sun, 27 Apr 2008) | 2 lines
  Improved AutoCompleteWindow logic.  Patch 2062 Tal Einat.
................
  r62549 | kurt.kaiser | 2008-04-27 23:52:19 +0200 (Sun, 27 Apr 2008) | 4 lines
  Autocompletion of filenames now support alternate separators, e.g. the
  '/' char on Windows.  Patch 2061 Tal Einat.
................
  r62550 | skip.montanaro | 2008-04-28 00:49:56 +0200 (Mon, 28 Apr 2008) | 6 lines
  A few small changes:
  * The only exception we should catch when trying to import cStringIO is an
    ImportError.
  * Delete the function signatures embedded in the mk*temp docstrings.
  * The tempdir global variable was initialized twice.
................
  r62551 | skip.montanaro | 2008-04-28 00:52:02 +0200 (Mon, 28 Apr 2008) | 4 lines
  Wrap some long paragraphs and include the default values for optional
  function parameters.
................
  r62553 | skip.montanaro | 2008-04-28 04:57:23 +0200 (Mon, 28 Apr 2008) | 7 lines
  Minor cleanups:
  * Avoid creating unused local variables where we can.  Where we can't prefix
    the unused variables with '_'.
  * Avoid shadowing builtins where it won't change the external interface of a
    function.
  * Use None as default path arg to readmodule and readmodule_ex.
................
  r62554 | skip.montanaro | 2008-04-28 04:59:45 +0200 (Mon, 28 Apr 2008) | 6 lines
  Correct documentation to match implementation: "Class" instead of
  "class_descriptor", "Function" instead of "function_descriptor".  Note
  default path value for readmodule*.  Wrap some long paragraphs.  Don't
  mention 'inpackage' which isn't part of the public API.
................
  r62555 | brett.cannon | 2008-04-28 05:23:50 +0200 (Mon, 28 Apr 2008) | 5 lines
  Fix a bug introduced by the warnings rewrite where tracebacks were being
  improperly indented.
  Closes issue #2699.
................
  r62556 | skip.montanaro | 2008-04-28 05:25:37 +0200 (Mon, 28 Apr 2008) | 2 lines
  Wrap some long lines.
................
  r62557 | skip.montanaro | 2008-04-28 05:27:53 +0200 (Mon, 28 Apr 2008) | 6 lines
  Get rid of _test(), _main(), _debug() and _check().  Tests are no longer
  needed (better set available in Lib/test/test_robotparser.py).  Clean up a
  few PEP 8 nits (compound statements on a single line, whitespace around
  operators).
................
  r62558 | brett.cannon | 2008-04-28 06:50:06 +0200 (Mon, 28 Apr 2008) | 3 lines
  Rename the test_traceback_print() function to traceback_print() to prevent
  test_capi from automatically calling the function.
................
  r62559 | georg.brandl | 2008-04-28 07:16:30 +0200 (Mon, 28 Apr 2008) | 2 lines
  Fix markup.
................
  r62569 | amaury.forgeotdarc | 2008-04-28 23:07:06 +0200 (Mon, 28 Apr 2008) | 5 lines
  test_sundry performs minimal tests (a simple import...) on modules that are not tested otherwise.
  Some of them now have tests and can be removed.
  Only 70 to go...
................
  r62574 | andrew.kuchling | 2008-04-29 04:03:54 +0200 (Tue, 29 Apr 2008) | 1 line
  Strip down SSL docs; I'm not managing to get test programs working, so I'll just give a minimal description
................
  r62577 | martin.v.loewis | 2008-04-29 08:10:53 +0200 (Tue, 29 Apr 2008) | 2 lines
  Add Rodrigo and Heiko.
................
  r62593 | nick.coghlan | 2008-04-30 16:23:36 +0200 (Wed, 30 Apr 2008) | 1 line
  Update command line usage documentation to reflect 2.6 changes (also includes some minor cleanups). Addresses TODO list issue 2258
................
  r62595 | andrew.kuchling | 2008-04-30 18:19:55 +0200 (Wed, 30 Apr 2008) | 1 line
  Typo fix
................
  r62604 | benjamin.peterson | 2008-04-30 23:03:58 +0200 (Wed, 30 Apr 2008) | 2 lines
  make test_support's captured_output a bit more robust when exceptions happen
................
  r62605 | georg.brandl | 2008-04-30 23:08:42 +0200 (Wed, 30 Apr 2008) | 2 lines
  #1748: use functools.wraps instead of rolling own metadata update.
................
  r62606 | benjamin.peterson | 2008-04-30 23:25:55 +0200 (Wed, 30 Apr 2008) | 2 lines
  Remove some from __future__ import with_statements
................
  r62608 | benjamin.peterson | 2008-05-01 00:03:36 +0200 (Thu, 01 May 2008) | 2 lines
  Fix typo in whatsnew
................
  r62616 | georg.brandl | 2008-05-01 20:24:32 +0200 (Thu, 01 May 2008) | 2 lines
  Fix synopsis.
................
  r62626 | brett.cannon | 2008-05-02 04:25:09 +0200 (Fri, 02 May 2008) | 6 lines
  Fix a backwards-compatibility mistake where a new optional argument for
  warnings.showwarning() was being used. This broke pre-existing replacements for
  the function since they didn't support the extra argument.
  Closes issue 2705.
................
  r62627 | gregory.p.smith | 2008-05-02 09:26:52 +0200 (Fri, 02 May 2008) | 20 lines
  This should fix issue2632.  A long description of the two competing
  problems is in the bug report (one old, one recently introduced trying
  to fix the old one).  In short:
  buffer data during socket._fileobject.read() and readlines() within a
  cStringIO object instead of a [] of str()s returned from the recv()
  call.
  This prevents excessive memory use due to the size parameter being
  passed to recv() being grossly larger than the actual size of the data
  returned *and* prevents excessive cpu usage due to looping in python
  calling recv() with a very tiny size value if min() is used as the
  previous memory-use bug "fix" did.
  It also documents what the socket._fileobject._rbufsize member is
  actually used for.
  This is a candidate for back porting to 2.5.
................
  r62636 | mark.hammond | 2008-05-02 14:48:15 +0200 (Fri, 02 May 2008) | 2 lines
  #2581: Vista UAC/elevation support for bdist_wininst
................
  r62638 | facundo.batista | 2008-05-02 19:39:00 +0200 (Fri, 02 May 2008) | 3 lines
  Fixed some test structures. Thanks Mark Dickinson.
................
  r62644 | ronald.oussoren | 2008-05-02 21:45:11 +0200 (Fri, 02 May 2008) | 7 lines
  Fix for issue #2573: Can't change the framework name on OS X builds
  This introduces a new configure option: --with-framework-name=NAME
  (defaulting to 'Python'). This allows you to install several copies
  of the Python framework with different names (such as a normal build
  and a debug build).
................
  r62645 | ronald.oussoren | 2008-05-02 21:58:56 +0200 (Fri, 02 May 2008) | 2 lines
  Finish fix for issue2573, previous patch was incomplete.
................
  r62647 | martin.v.loewis | 2008-05-02 23:30:20 +0200 (Fri, 02 May 2008) | 13 lines
  Merged revisions 62263-62646 via svnmerge from
  svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
  ........
    r62470 | david.wolever | 2008-04-24 02:11:07 +0200 (Do, 24 Apr 2008) | 3 lines
    Fixed up and applied the patch for #2431 -- speeding up 2to3 with a lookup table.
  ........
    r62646 | martin.v.loewis | 2008-05-02 23:29:27 +0200 (Fr, 02 Mai 2008) | 2 lines
    Fix whitespace.
  ........
................
  r62648 | ronald.oussoren | 2008-05-02 23:42:35 +0200 (Fri, 02 May 2008) | 4 lines
  Fix for #1905: PythonLauncher not working correctly on OSX 10.5/Leopard
  This fixes both Python Launchar and the terminalcommand module.
................
  r62651 | ronald.oussoren | 2008-05-02 23:54:56 +0200 (Fri, 02 May 2008) | 2 lines
  Fix for issue #2520 (cannot import macerrors)
................
  r62652 | benjamin.peterson | 2008-05-03 00:12:58 +0200 (Sat, 03 May 2008) | 2 lines
  capitalization nit for reStructuredText
................
  r62653 | brett.cannon | 2008-05-03 03:02:41 +0200 (Sat, 03 May 2008) | 2 lines
  Fix some indentation errors.
................
  r62656 | brett.cannon | 2008-05-03 05:19:39 +0200 (Sat, 03 May 2008) | 6 lines
  Fix the C implementation of 'warnings' to infer the filename of the module that
  raised an exception properly when __file__ is not set, __name__ == '__main__',
  and sys.argv[0] is a false value.
  Closes issue2743.
................
  r62661 | amaury.forgeotdarc | 2008-05-03 14:21:13 +0200 (Sat, 03 May 2008) | 8 lines
  In test_io, StatefulIncrementalDecoderTest was not part of the test suite.
  And of course, the test failed:
  a bytearray was used without reason in io.TextIOWrapper.tell().
  The difference is that iterating over bytes (i.e. str in python2.6) returns 1-char bytes,
  whereas bytearrays yield integers.
  This code should still work with python3.0
................
  r62663 | benjamin.peterson | 2008-05-03 17:56:42 +0200 (Sat, 03 May 2008) | 2 lines
  The compiling struct is now passed around to all AST helpers (see issue 2720)
................
  r62680 | benjamin.peterson | 2008-05-03 23:35:18 +0200 (Sat, 03 May 2008) | 2 lines
  Moved testing of builtin types out of test_builtin and into type specific modules
................
  r62686 | mark.dickinson | 2008-05-04 04:25:46 +0200 (Sun, 04 May 2008) | 4 lines
  Make sure that Context traps and flags dictionaries have values 0 and 1
  (as documented) rather than True and False.
................
  r62687 | benjamin.peterson | 2008-05-04 05:05:49 +0200 (Sun, 04 May 2008) | 2 lines
  Fix typo in whatsnew
................
  r62696 | georg.brandl | 2008-05-04 11:15:04 +0200 (Sun, 04 May 2008) | 2 lines
  #2752: wrong meaning of '' for socket host.
................
  r62699 | christian.heimes | 2008-05-04 13:50:53 +0200 (Sun, 04 May 2008) | 1 line
  Added note that Python requires at least Win2k SP4
................
  r62700 | gerhard.haering | 2008-05-04 14:59:57 +0200 (Sun, 04 May 2008) | 3 lines
  SQLite requires 64-bit integers in order to build. So the whole HAVE_LONG_LONG
  #ifdefing was useless.
................
  r62701 | gerhard.haering | 2008-05-04 15:15:12 +0200 (Sun, 04 May 2008) | 3 lines
  Applied sqliterow-richcmp.diff patch from Thomas Heller in Issue2152. The
  sqlite3.Row type is now correctly hashable.
................
  r62702 | gerhard.haering | 2008-05-04 15:42:44 +0200 (Sun, 04 May 2008) | 5 lines
  Implemented feature request 2157: Converter names are cut off at '('
  characters. This avoids the common case of something like 'NUMBER(10)' not
  being parsed as 'NUMBER', like expected. Also corrected the docs about
  converter names being case-sensitive. They aren't any longer.
................
  r62703 | georg.brandl | 2008-05-04 17:45:05 +0200 (Sun, 04 May 2008) | 2 lines
  #2757: Remove spare newline.
................
  r62711 | benjamin.peterson | 2008-05-04 21:10:02 +0200 (Sun, 04 May 2008) | 2 lines
  Fix typo in bugs.rst
................
		
	
			
		
			
				
	
	
		
			618 lines
		
	
	
	
		
			23 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			618 lines
		
	
	
	
		
			23 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
import base64
 | 
						|
import datetime
 | 
						|
import sys
 | 
						|
import time
 | 
						|
import unittest
 | 
						|
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',
 | 
						|
          'afloat': 7283.43,
 | 
						|
          'anint': 2**20,
 | 
						|
          'ashortlong': 2,
 | 
						|
          'anotherlist': ['.zyx.41'],
 | 
						|
          'abase64': xmlrpclib.Binary(b"my dog has fleas"),
 | 
						|
          'boolean': False,
 | 
						|
          'unicode': '\u4000\u6000\u8000',
 | 
						|
          'ukey\u4000': 'regular value',
 | 
						|
          'datetime1': xmlrpclib.DateTime('20050210T11:41:23'),
 | 
						|
          'datetime2': xmlrpclib.DateTime(
 | 
						|
                        (2005, 2, 10, 11, 41, 23, 0, 1, -1)),
 | 
						|
          'datetime3': xmlrpclib.DateTime(
 | 
						|
                        datetime.datetime(2005, 2, 10, 11, 41, 23)),
 | 
						|
          }]
 | 
						|
 | 
						|
class XMLRPCTestCase(unittest.TestCase):
 | 
						|
 | 
						|
    def test_dump_load(self):
 | 
						|
        dump = xmlrpclib.dumps((alist,))
 | 
						|
        load = xmlrpclib.loads(dump)
 | 
						|
        self.assertEquals(alist, load[0][0])
 | 
						|
 | 
						|
    def test_dump_bare_datetime(self):
 | 
						|
        # This checks that an unwrapped datetime.date object can be handled
 | 
						|
        # by the marshalling code.  This can't be done via test_dump_load()
 | 
						|
        # since with use_datetime set to 1 the unmarshaller would create
 | 
						|
        # datetime objects for the 'datetime[123]' keys as well
 | 
						|
        dt = datetime.datetime(2005, 2, 10, 11, 41, 23)
 | 
						|
        s = xmlrpclib.dumps((dt,))
 | 
						|
        (newdt,), m = xmlrpclib.loads(s, use_datetime=1)
 | 
						|
        self.assertEquals(newdt, dt)
 | 
						|
        self.assertEquals(m, None)
 | 
						|
 | 
						|
        (newdt,), m = xmlrpclib.loads(s, use_datetime=0)
 | 
						|
        self.assertEquals(newdt, xmlrpclib.DateTime('20050210T11:41:23'))
 | 
						|
 | 
						|
    def test_datetime_before_1900(self):
 | 
						|
        # same as before but with a date before 1900
 | 
						|
        dt = datetime.datetime(1,  2, 10, 11, 41, 23)
 | 
						|
        s = xmlrpclib.dumps((dt,))
 | 
						|
        (newdt,), m = xmlrpclib.loads(s, use_datetime=1)
 | 
						|
        self.assertEquals(newdt, dt)
 | 
						|
        self.assertEquals(m, None)
 | 
						|
 | 
						|
        (newdt,), m = xmlrpclib.loads(s, use_datetime=0)
 | 
						|
        self.assertEquals(newdt, xmlrpclib.DateTime('00010210T11:41:23'))
 | 
						|
 | 
						|
    def test_cmp_datetime_DateTime(self):
 | 
						|
        now = datetime.datetime.now()
 | 
						|
        dt = xmlrpclib.DateTime(now.timetuple())
 | 
						|
        self.assert_(dt == now)
 | 
						|
        self.assert_(now == dt)
 | 
						|
        then = now + datetime.timedelta(seconds=4)
 | 
						|
        self.assert_(then >= dt)
 | 
						|
        self.assert_(dt < then)
 | 
						|
 | 
						|
    def test_bug_1164912 (self):
 | 
						|
        d = xmlrpclib.DateTime()
 | 
						|
        ((new_d,), dummy) = xmlrpclib.loads(xmlrpclib.dumps((d,),
 | 
						|
                                            methodresponse=True))
 | 
						|
        self.assert_(isinstance(new_d.value, str))
 | 
						|
 | 
						|
        # Check that the output of dumps() is still an 8-bit string
 | 
						|
        s = xmlrpclib.dumps((new_d,), methodresponse=True)
 | 
						|
        self.assert_(isinstance(s, str))
 | 
						|
 | 
						|
    def test_newstyle_class(self):
 | 
						|
        class T(object):
 | 
						|
            pass
 | 
						|
        t = T()
 | 
						|
        t.x = 100
 | 
						|
        t.y = "Hello"
 | 
						|
        ((t2,), dummy) = xmlrpclib.loads(xmlrpclib.dumps((t,)))
 | 
						|
        self.assertEquals(t2, t.__dict__)
 | 
						|
 | 
						|
    def test_dump_big_long(self):
 | 
						|
        self.assertRaises(OverflowError, xmlrpclib.dumps, (2**99,))
 | 
						|
 | 
						|
    def test_dump_bad_dict(self):
 | 
						|
        self.assertRaises(TypeError, xmlrpclib.dumps, ({(1,2,3): 1},))
 | 
						|
 | 
						|
    def test_dump_recursive_seq(self):
 | 
						|
        l = [1,2,3]
 | 
						|
        t = [3,4,5,l]
 | 
						|
        l.append(t)
 | 
						|
        self.assertRaises(TypeError, xmlrpclib.dumps, (l,))
 | 
						|
 | 
						|
    def test_dump_recursive_dict(self):
 | 
						|
        d = {'1':1, '2':1}
 | 
						|
        t = {'3':3, 'd':d}
 | 
						|
        d['t'] = t
 | 
						|
        self.assertRaises(TypeError, xmlrpclib.dumps, (d,))
 | 
						|
 | 
						|
    def test_dump_big_int(self):
 | 
						|
        if sys.maxsize > 2**31-1:
 | 
						|
            self.assertRaises(OverflowError, xmlrpclib.dumps,
 | 
						|
                              (int(2**34),))
 | 
						|
 | 
						|
        xmlrpclib.dumps((xmlrpclib.MAXINT, xmlrpclib.MININT))
 | 
						|
        self.assertRaises(OverflowError, xmlrpclib.dumps, (xmlrpclib.MAXINT+1,))
 | 
						|
        self.assertRaises(OverflowError, xmlrpclib.dumps, (xmlrpclib.MININT-1,))
 | 
						|
 | 
						|
        def dummy_write(s):
 | 
						|
            pass
 | 
						|
 | 
						|
        m = xmlrpclib.Marshaller()
 | 
						|
        m.dump_int(xmlrpclib.MAXINT, dummy_write)
 | 
						|
        m.dump_int(xmlrpclib.MININT, dummy_write)
 | 
						|
        self.assertRaises(OverflowError, m.dump_int, xmlrpclib.MAXINT+1, dummy_write)
 | 
						|
        self.assertRaises(OverflowError, m.dump_int, xmlrpclib.MININT-1, dummy_write)
 | 
						|
 | 
						|
 | 
						|
    def test_dump_none(self):
 | 
						|
        value = alist + [None]
 | 
						|
        arg1 = (alist + [None],)
 | 
						|
        strg = xmlrpclib.dumps(arg1, allow_none=True)
 | 
						|
        self.assertEquals(value,
 | 
						|
                          xmlrpclib.loads(strg)[0][0])
 | 
						|
        self.assertRaises(TypeError, xmlrpclib.dumps, (arg1,))
 | 
						|
 | 
						|
 | 
						|
class HelperTestCase(unittest.TestCase):
 | 
						|
    def test_escape(self):
 | 
						|
        self.assertEqual(xmlrpclib.escape("a&b"), "a&b")
 | 
						|
        self.assertEqual(xmlrpclib.escape("a<b"), "a<b")
 | 
						|
        self.assertEqual(xmlrpclib.escape("a>b"), "a>b")
 | 
						|
 | 
						|
class FaultTestCase(unittest.TestCase):
 | 
						|
    def test_repr(self):
 | 
						|
        f = xmlrpclib.Fault(42, 'Test Fault')
 | 
						|
        self.assertEqual(repr(f), "<Fault 42: 'Test Fault'>")
 | 
						|
        self.assertEqual(repr(f), str(f))
 | 
						|
 | 
						|
    def test_dump_fault(self):
 | 
						|
        f = xmlrpclib.Fault(42, 'Test Fault')
 | 
						|
        s = xmlrpclib.dumps((f,))
 | 
						|
        (newf,), m = xmlrpclib.loads(s)
 | 
						|
        self.assertEquals(newf, {'faultCode': 42, 'faultString': 'Test Fault'})
 | 
						|
        self.assertEquals(m, None)
 | 
						|
 | 
						|
        s = xmlrpclib.Marshaller().dumps(f)
 | 
						|
        self.assertRaises(xmlrpclib.Fault, xmlrpclib.loads, s)
 | 
						|
 | 
						|
    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'))
 | 
						|
 | 
						|
class DateTimeTestCase(unittest.TestCase):
 | 
						|
    def test_default(self):
 | 
						|
        t = xmlrpclib.DateTime()
 | 
						|
 | 
						|
    def test_time(self):
 | 
						|
        d = 1181399930.036952
 | 
						|
        t = xmlrpclib.DateTime(d)
 | 
						|
        self.assertEqual(str(t), time.strftime("%Y%m%dT%H:%M:%S", time.localtime(d)))
 | 
						|
 | 
						|
    def test_time_tuple(self):
 | 
						|
        d = (2007,6,9,10,38,50,5,160,0)
 | 
						|
        t = xmlrpclib.DateTime(d)
 | 
						|
        self.assertEqual(str(t), '20070609T10:38:50')
 | 
						|
 | 
						|
    def test_time_struct(self):
 | 
						|
        d = time.localtime(1181399930.036952)
 | 
						|
        t = xmlrpclib.DateTime(d)
 | 
						|
        self.assertEqual(str(t),  time.strftime("%Y%m%dT%H:%M:%S", d))
 | 
						|
 | 
						|
    def test_datetime_datetime(self):
 | 
						|
        d = datetime.datetime(2007,1,2,3,4,5)
 | 
						|
        t = xmlrpclib.DateTime(d)
 | 
						|
        self.assertEqual(str(t), '20070102T03:04:05')
 | 
						|
 | 
						|
    def test_repr(self):
 | 
						|
        d = datetime.datetime(2007,1,2,3,4,5)
 | 
						|
        t = xmlrpclib.DateTime(d)
 | 
						|
        val ="<DateTime '20070102T03:04:05' at %x>" % id(t)
 | 
						|
        self.assertEqual(repr(t), val)
 | 
						|
 | 
						|
    def test_decode(self):
 | 
						|
        d = ' 20070908T07:11:13  '
 | 
						|
        t1 = xmlrpclib.DateTime()
 | 
						|
        t1.decode(d)
 | 
						|
        tref = xmlrpclib.DateTime(datetime.datetime(2007,9,8,7,11,13))
 | 
						|
        self.assertEqual(t1, tref)
 | 
						|
 | 
						|
        t2 = xmlrpclib._datetime(d)
 | 
						|
        self.assertEqual(t1, tref)
 | 
						|
 | 
						|
class BinaryTestCase(unittest.TestCase):
 | 
						|
 | 
						|
    # XXX What should str(Binary(b"\xff")) return?  I'm chosing "\xff"
 | 
						|
    # for now (i.e. interpreting the binary data as Latin-1-encoded
 | 
						|
    # text).  But this feels very unsatisfactory.  Perhaps we should
 | 
						|
    # only define repr(), and return r"Binary(b'\xff')" instead?
 | 
						|
 | 
						|
    def test_default(self):
 | 
						|
        t = xmlrpclib.Binary()
 | 
						|
        self.assertEqual(str(t), '')
 | 
						|
 | 
						|
    def test_string(self):
 | 
						|
        d = b'\x01\x02\x03abc123\xff\xfe'
 | 
						|
        t = xmlrpclib.Binary(d)
 | 
						|
        self.assertEqual(str(t), str(d, "latin-1"))
 | 
						|
 | 
						|
    def test_decode(self):
 | 
						|
        d = b'\x01\x02\x03abc123\xff\xfe'
 | 
						|
        de = base64.encodestring(d)
 | 
						|
        t1 = xmlrpclib.Binary()
 | 
						|
        t1.decode(de)
 | 
						|
        self.assertEqual(str(t1), str(d, "latin-1"))
 | 
						|
 | 
						|
        t2 = xmlrpclib._binary(de)
 | 
						|
        self.assertEqual(str(t2), str(d, "latin-1"))
 | 
						|
 | 
						|
 | 
						|
PORT = None
 | 
						|
 | 
						|
# The evt is set twice.  First when the server is ready to serve.
 | 
						|
# Second when the server has been shutdown.  The user must clear
 | 
						|
# the event after it has been set the first time to catch the second set.
 | 
						|
def http_server(evt, numrequests):
 | 
						|
    class TestInstanceClass:
 | 
						|
        def div(self, 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
 | 
						|
 | 
						|
    class MyXMLRPCServer(SimpleXMLRPCServer.SimpleXMLRPCServer):
 | 
						|
        def get_request(self):
 | 
						|
            # Ensure the socket is always non-blocking.  On Linux, socket
 | 
						|
            # attributes are not inherited like they are on *BSD and Windows.
 | 
						|
            s, port = self.socket.accept()
 | 
						|
            s.setblocking(True)
 | 
						|
            return s, port
 | 
						|
 | 
						|
    try:
 | 
						|
        serv = MyXMLRPCServer(("localhost", 0),
 | 
						|
                              logRequests=False, bind_and_activate=False)
 | 
						|
        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_function(my_function)
 | 
						|
        serv.register_instance(TestInstanceClass())
 | 
						|
        evt.set()
 | 
						|
 | 
						|
        # 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()
 | 
						|
 | 
						|
# This function prevents errors like:
 | 
						|
#    <ProtocolError for localhost:57527/RPC2: 500 Internal Server Error>
 | 
						|
def is_unavailable_exception(e):
 | 
						|
    '''Returns True if the given ProtocolError is the product of a server-side
 | 
						|
       exception caused by the 'temporarily unavailable' response sometimes
 | 
						|
       given by operations on non-blocking sockets.'''
 | 
						|
 | 
						|
    # sometimes we get a -1 error code and/or empty headers
 | 
						|
    try:
 | 
						|
        if e.errcode == -1 or e.headers is None:
 | 
						|
            return True
 | 
						|
        exc_mess = e.headers.get('X-exception')
 | 
						|
    except AttributeError:
 | 
						|
        # Ignore socket.errors here.
 | 
						|
        exc_mess = str(e)
 | 
						|
 | 
						|
    if exc_mess and 'temporarily unavailable' in exc_mess.lower():
 | 
						|
        return True
 | 
						|
 | 
						|
class SimpleServerTestCase(unittest.TestCase):
 | 
						|
    def setUp(self):
 | 
						|
        # enable traceback reporting
 | 
						|
        SimpleXMLRPCServer.SimpleXMLRPCServer._send_traceback_header = True
 | 
						|
 | 
						|
        self.evt = threading.Event()
 | 
						|
        # start server thread to handle requests
 | 
						|
        serv_args = (self.evt, 1)
 | 
						|
        threading.Thread(target=http_server, args=serv_args).start()
 | 
						|
 | 
						|
        # wait for the server to be ready
 | 
						|
        self.evt.wait()
 | 
						|
        self.evt.clear()
 | 
						|
 | 
						|
    def tearDown(self):
 | 
						|
        # wait on the server thread to terminate
 | 
						|
        self.evt.wait(4.0)
 | 
						|
        if not self.evt.isSet():
 | 
						|
            self.evt.set()
 | 
						|
            stop_serving()
 | 
						|
            raise RuntimeError("timeout reached, test has failed")
 | 
						|
 | 
						|
        # disable traceback reporting
 | 
						|
        SimpleXMLRPCServer.SimpleXMLRPCServer._send_traceback_header = False
 | 
						|
 | 
						|
    def test_simple1(self):
 | 
						|
        try:
 | 
						|
            p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT)
 | 
						|
            self.assertEqual(p.pow(6,8), 6**8)
 | 
						|
        except (xmlrpclib.ProtocolError, socket.error) 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, getattr(e, "headers", "")))
 | 
						|
 | 
						|
    # [ch] The test 404 is causing lots of false alarms.
 | 
						|
    def XXXtest_404(self):
 | 
						|
        # send POST with httplib, it should return 404 header and
 | 
						|
        # 'Not Found' message.
 | 
						|
        conn = httplib.HTTPConnection('localhost', PORT)
 | 
						|
        conn.request('POST', '/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', 'my_function', 'add',
 | 
						|
                                    'system.listMethods', 'system.methodHelp',
 | 
						|
                                    'system.methodSignature', 'system.multicall'])
 | 
						|
            self.assertEqual(set(meth), expected_methods)
 | 
						|
        except (xmlrpclib.ProtocolError, socket.error) 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, getattr(e, "headers", "")))
 | 
						|
 | 
						|
 | 
						|
    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')
 | 
						|
        except (xmlrpclib.ProtocolError, socket.error) 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, getattr(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, socket.error) 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, getattr(e, "headers", "")))
 | 
						|
 | 
						|
    def test_introspection4(self):
 | 
						|
        # the SimpleXMLRPCServer doesn't support signatures, but
 | 
						|
        # at least check that we can try making the call
 | 
						|
        try:
 | 
						|
            p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT)
 | 
						|
            divsig = p.system.methodSignature('div')
 | 
						|
            self.assertEqual(divsig, 'signatures not supported')
 | 
						|
        except (xmlrpclib.ProtocolError, socket.error) 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, getattr(e, "headers", "")))
 | 
						|
 | 
						|
    def test_multicall(self):
 | 
						|
        try:
 | 
						|
            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)
 | 
						|
        except (xmlrpclib.ProtocolError, socket.error) 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, getattr(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': '<class \'exceptions.Exception\'>:'
 | 
						|
            #   'method "this_is_not_exists" is not supported'>}]
 | 
						|
 | 
						|
            self.assertEqual(result.results[0]['faultCode'], 1)
 | 
						|
            self.assertEqual(result.results[0]['faultString'],
 | 
						|
                '<class \'Exception\'>:method "this_is_not_exists" '
 | 
						|
                'is not supported')
 | 
						|
        except (xmlrpclib.ProtocolError, socket.error) 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, getattr(e, "headers", "")))
 | 
						|
 | 
						|
    def test_dotted_attribute(self):
 | 
						|
        # Raises an AttributeError because private methods are not allowed.
 | 
						|
        self.assertRaises(AttributeError,
 | 
						|
                          SimpleXMLRPCServer.resolve_dotted_attribute, str, '__add')
 | 
						|
 | 
						|
        self.assert_(SimpleXMLRPCServer.resolve_dotted_attribute(str, 'title'))
 | 
						|
        # Get the test to run faster by sending a request with test_simple1.
 | 
						|
        # This avoids waiting for the socket timeout.
 | 
						|
        self.test_simple1()
 | 
						|
 | 
						|
# 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
 | 
						|
class FailingMessageClass(mimetools.Message):
 | 
						|
    def __getitem__(self, key):
 | 
						|
        key = key.lower()
 | 
						|
        if key == 'content-length':
 | 
						|
            return 'I am broken'
 | 
						|
        return mimetools.Message.__getitem__(self, key)
 | 
						|
 | 
						|
 | 
						|
class FailingServerTestCase(unittest.TestCase):
 | 
						|
    def setUp(self):
 | 
						|
        self.evt = threading.Event()
 | 
						|
        # start server thread to handle requests
 | 
						|
        serv_args = (self.evt, 1)
 | 
						|
        threading.Thread(target=http_server, args=serv_args).start()
 | 
						|
 | 
						|
        # wait for the server to be ready
 | 
						|
        self.evt.wait()
 | 
						|
        self.evt.clear()
 | 
						|
 | 
						|
    def tearDown(self):
 | 
						|
        # wait on the server thread to terminate
 | 
						|
        self.evt.wait()
 | 
						|
        # reset flag
 | 
						|
        SimpleXMLRPCServer.SimpleXMLRPCServer._send_traceback_header = False
 | 
						|
        # reset message class
 | 
						|
        SimpleXMLRPCServer.SimpleXMLRPCRequestHandler.MessageClass = mimetools.Message
 | 
						|
 | 
						|
    def test_basic(self):
 | 
						|
        # check that flag is false by default
 | 
						|
        flagval = SimpleXMLRPCServer.SimpleXMLRPCServer._send_traceback_header
 | 
						|
        self.assertEqual(flagval, False)
 | 
						|
 | 
						|
        # enable traceback reporting
 | 
						|
        SimpleXMLRPCServer.SimpleXMLRPCServer._send_traceback_header = True
 | 
						|
 | 
						|
        # test a call that shouldn't fail just as a smoke test
 | 
						|
        try:
 | 
						|
            p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT)
 | 
						|
            self.assertEqual(p.pow(6,8), 6**8)
 | 
						|
        except (xmlrpclib.ProtocolError, socket.error) 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, getattr(e, "headers", "")))
 | 
						|
 | 
						|
    def test_fail_no_info(self):
 | 
						|
        # use the broken message class
 | 
						|
        SimpleXMLRPCServer.SimpleXMLRPCRequestHandler.MessageClass = FailingMessageClass
 | 
						|
 | 
						|
        try:
 | 
						|
            p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT)
 | 
						|
            p.pow(6,8)
 | 
						|
        except (xmlrpclib.ProtocolError, socket.error) as e:
 | 
						|
            # ignore failures due to non-blocking socket 'unavailable' errors
 | 
						|
            if not is_unavailable_exception(e) and hasattr(e, "headers"):
 | 
						|
                # The two server-side error headers shouldn't be sent back in this case
 | 
						|
                self.assertTrue(e.headers.get("X-exception") is None)
 | 
						|
                self.assertTrue(e.headers.get("X-traceback") is None)
 | 
						|
        else:
 | 
						|
            self.fail('ProtocolError not raised')
 | 
						|
 | 
						|
    def test_fail_with_info(self):
 | 
						|
        # use the broken message class
 | 
						|
        SimpleXMLRPCServer.SimpleXMLRPCRequestHandler.MessageClass = FailingMessageClass
 | 
						|
 | 
						|
        # Check that errors in the server send back exception/traceback
 | 
						|
        # info when flag is set
 | 
						|
        SimpleXMLRPCServer.SimpleXMLRPCServer._send_traceback_header = True
 | 
						|
 | 
						|
        try:
 | 
						|
            p = xmlrpclib.ServerProxy('http://localhost:%d' % PORT)
 | 
						|
            p.pow(6,8)
 | 
						|
        except (xmlrpclib.ProtocolError, socket.error) as e:
 | 
						|
            # ignore failures due to non-blocking socket 'unavailable' errors
 | 
						|
            if not is_unavailable_exception(e) and hasattr(e, "headers"):
 | 
						|
                # We should get error info in the response
 | 
						|
                expected_err = "invalid literal for int() with base 10: 'I am broken'"
 | 
						|
                self.assertEqual(e.headers.get("x-exception"), expected_err)
 | 
						|
                self.assertTrue(e.headers.get("x-traceback") is not None)
 | 
						|
        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,
 | 
						|
         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(SimpleServerTestCase)
 | 
						|
        xmlrpc_tests.append(FailingServerTestCase)
 | 
						|
        xmlrpc_tests.append(CGIHandlerTestCase)
 | 
						|
 | 
						|
    test_support.run_unittest(*xmlrpc_tests)
 | 
						|
 | 
						|
if __name__ == "__main__":
 | 
						|
    test_main()
 |