Patch by Serhiy Storchaka.
* :c:func:`PyCapsule_GetName` always returns NULL.
- * :c:func:`PyCapsule_SetName` always throws an exception and
+ * :c:func:`PyCapsule_SetName` always raises an exception and
returns failure. (Since there's no way to store a name
in a CObject, noisy failure of :c:func:`PyCapsule_SetName`
was deemed preferable to silent failure here. If this is
else:
return data
except socket.error as why:
- # winsock sometimes throws ENOTCONN
+ # winsock sometimes raises ENOTCONN
if why.args[0] in _DISCONNECTED:
self.handle_close()
return b''
unittest.TestCase):
def test_no_compiler(self):
- # makes sure query_vcvarsall throws
+ # makes sure query_vcvarsall raises
# a DistutilsPlatformError if the compiler
# is not found
from distutils.msvc9compiler import query_vcvarsall
data. When you have no more data to push into the parser, call .close().
This completes the parsing and returns the root message object.
-The other advantage of this parser is that it will never throw a parsing
+The other advantage of this parser is that it will never raise a parsing
exception. Instead, when it finds something unexpected, it adds a 'defect' to
the current message. Defects are just instances that live on the message
object's .defects attribute.
# supposed to see in the body of the message.
self._parse_headers(headers)
# Headers-only parsing is a backwards compatibility hack, which was
- # necessary in the older parser, which could throw errors. All
+ # necessary in the older parser, which could raise errors. All
# remaining lines in the input are thrown into the message body.
if self._headersonly:
lines = []
else:
s = s.decode(input_charset, errors)
# Ensure that the bytes we're storing can be decoded to the output
- # character set, otherwise an early error is thrown.
+ # character set, otherwise an early error is raised.
output_charset = charset.output_codec or 'us-ascii'
if output_charset != _charset.UNKNOWN8BIT:
try:
source_mtime is not None):
# If e.g. Jython ever implements imp.cache_from_source to have
# their own cached file format, this block of code will most likely
- # throw an exception.
+ # raise an exception.
data = bytearray(imp.get_magic())
data.extend(marshal._w_long(source_mtime))
data.extend(marshal.dumps(code_object))
If a package is being imported, then what is listed in fromlist may be
treated as a module to be imported [module]. But once again, even if
- something in fromlist does not exist as a module, no error is thrown
+ something in fromlist does not exist as a module, no error is raised
[no module]. And this extends to what is contained in __all__ when '*' is
imported [using *]. And '*' does not need to be the only name in the
fromlist [using * with others].
At the top of the I/O hierarchy is the abstract base class IOBase. It
defines the basic interface to a stream. Note, however, that there is no
separation between reading and writing to streams; implementations are
-allowed to throw an IOError if they do not support a given operation.
+allowed to raise an IOError if they do not support a given operation.
Extending IOBase is RawIOBase which deals simply with the reading and
writing of raw bytes to a stream. FileIO subclasses RawIOBase to provide
"""
sinfo = None
if _srcfile:
- #IronPython doesn't track Python frames, so findCaller throws an
+ #IronPython doesn't track Python frames, so findCaller raises an
#exception on some versions of IronPython. We trap it here so that
#IronPython can use logging.
try:
_run_finalizers(0)
if current_process() is not None:
# We check if the current process is None here because if
- # it's None, any call to ``active_children()`` will throw an
+ # it's None, any call to ``active_children()`` will raise an
# AttributeError (active_children winds up trying to get
# attributes from util._current_process). This happens in a
# variety of shutdown circumstances that are not well-understood
pass
else:
# The following check looks a bit odd. The trick is that
- # NullImporter throws ImportError if the supplied path is a
+ # NullImporter raises ImportError if the supplied path is a
# *valid* directory entry (and hence able to be handled
# by the standard import machinery)
try:
def __init__(self, suffix="", prefix=template, dir=None):
self._closed = False
- self.name = None # Handle mkdtemp throwing an exception
+ self.name = None # Handle mkdtemp raising an exception
self.name = mkdtemp(suffix, prefix, dir)
def __repr__(self):
'''succeed iff str is the start of an invalid piece of code'''
try:
compile_command(str,symbol=symbol)
- self.fail("No exception thrown for invalid code")
+ self.fail("No exception raised for invalid code")
except SyntaxError:
self.assertTrue(is_syntax)
except OverflowError:
self.assertEqual(response.status, 200)
self.assertEqual(response.getheader("Content-type"), "text/html")
- # Server throws an exception if we don't start to read the data
+ # Server raises an exception if we don't start to read the data
response.read()
def test_invalid_get_response(self):
return
line += part
except IOError:
- # ..but SSLSockets throw exceptions.
+ # ..but SSLSockets raise exceptions.
return
if line.endswith(b'\r\n'):
break
self.assertEqual(doc.toxml('iso-8859-15'),
b'<?xml version="1.0" encoding="iso-8859-15"?><foo>\xa4</foo>')
- # Verify that character decoding errors throw exceptions instead
+ # Verify that character decoding errors raise exceptions instead
# of crashing
self.assertRaises(UnicodeDecodeError, parseString,
b'<fran\xe7ais>Comment \xe7a va ? Tr\xe8s bien ?</fran\xe7ais>')
try:
result[200]
- self.fail("No exception thrown")
+ self.fail("No exception raised")
except IndexError:
pass
# Make sure that assignment fails
try:
result.st_mode = 1
- self.fail("No exception thrown")
+ self.fail("No exception raised")
except AttributeError:
pass
try:
result.st_rdev = 1
- self.fail("No exception thrown")
+ self.fail("No exception raised")
except (AttributeError, TypeError):
pass
try:
result.parrot = 1
- self.fail("No exception thrown")
+ self.fail("No exception raised")
except AttributeError:
pass
# Use the stat_result constructor with a too-short tuple.
try:
result2 = os.stat_result((10,))
- self.fail("No exception thrown")
+ self.fail("No exception raised")
except TypeError:
pass
# Make sure that assignment really fails
try:
result.f_bfree = 1
- self.fail("No exception thrown")
+ self.fail("No exception raised")
except AttributeError:
pass
try:
result.parrot = 1
- self.fail("No exception thrown")
+ self.fail("No exception raised")
except AttributeError:
pass
# Use the constructor with a too-short tuple.
try:
result2 = os.statvfs_result((10,))
- self.fail("No exception thrown")
+ self.fail("No exception raised")
except TypeError:
pass
# platform-dependent amount of data is written to its fd. On
# Linux 2.6, it's 4000 bytes and the child won't block, but on OS
# X even the small writes in the child above will block it. Also
- # on Linux, the read() will throw an OSError (input/output error)
+ # on Linux, the read() will raise an OSError (input/output error)
# when it tries to read past the end of the buffer but the child's
# already exited, so catch and discard those exceptions. It's not
# worth checking for EIO.
def test_5027_1(self):
# The xml prefix (as in xml:lang below) is reserved and bound by
# definition to http://www.w3.org/XML/1998/namespace. XMLGenerator had
- # a bug whereby a KeyError is thrown because this namespace is missing
+ # a bug whereby a KeyError is raised because this namespace is missing
# from a dictionary.
#
# This test demonstrates the bug by parsing a document.
def test_5027_2(self):
# The xml prefix (as in xml:lang below) is reserved and bound by
# definition to http://www.w3.org/XML/1998/namespace. XMLGenerator had
- # a bug whereby a KeyError is thrown because this namespace is missing
+ # a bug whereby a KeyError is raised because this namespace is missing
# from a dictionary.
#
# This test demonstrates the bug by direct manipulation of the
# This wait should be interrupted by the signal's exception.
self.wait(child)
time.sleep(1) # Give the signal time to be delivered.
- self.fail('HandlerBCalled exception not thrown')
+ self.fail('HandlerBCalled exception not raised')
except HandlerBCalled:
self.assertTrue(self.b_called)
self.assertFalse(self.a_called)
# test-running process from all the signals. It then
# communicates with that child process over a pipe and
# re-raises information about any exceptions the child
- # throws. The real work happens in self.run_test().
+ # raises. The real work happens in self.run_test().
os_done_r, os_done_w = os.pipe()
with closing(os.fdopen(os_done_r, 'rb')) as done_r, \
closing(os.fdopen(os_done_w, 'wb')) as done_w:
def simple_subprocess(testcase):
pid = os.fork()
if pid == 0:
- # Don't throw an exception; it would be caught by the test harness.
+ # Don't raise an exception; it would be caught by the test harness.
os._exit(72)
yield None
pid2, status = os.waitpid(pid, 0)
except ValueError:
pass
else:
- self.fail("exception not thrown!")
+ self.fail("exception not raised!")
except RuntimeError:
self.fail("recursion counter not reset")
def test_strptime(self):
# Should be able to go round-trip from strftime to strptime without
- # throwing an exception.
+ # raising an exception.
tt = time.gmtime(self.t)
for directive in ('a', 'A', 'b', 'B', 'c', 'd', 'H', 'I',
'j', 'm', 'M', 'p', 'S',
out = io.BytesIO()
try:
uu.decode(inp, out)
- self.fail("No exception thrown")
+ self.fail("No exception raised")
except uu.Error as e:
self.assertEqual(str(e), "Truncated input file")
out = io.BytesIO()
try:
uu.decode(inp, out)
- self.fail("No exception thrown")
+ self.fail("No exception raised")
except uu.Error as e:
self.assertEqual(str(e), "No valid begin line found in input file")
def test_changing_value(self):
# Issue2810: A race condition in 2.6 and 3.1 may cause
- # EnumValue or QueryValue to throw "WindowsError: More data is
+ # EnumValue or QueryValue to raise "WindowsError: More data is
# available"
done = False
def test_dynamic_key(self):
# Issue2810, when the value is dynamically generated, these
- # throw "WindowsError: More data is available" in 2.6 and 3.1
+ # raise "WindowsError: More data is available" in 2.6 and 3.1
try:
EnumValue(HKEY_PERFORMANCE_DATA, 0)
except OSError as e:
with zipfile.ZipFile(data, mode="w") as zipf:
zipf.writestr("foo.txt", "O, for a Muse of Fire!")
- # This is correct; calling .read on a closed ZipFile should throw
+ # This is correct; calling .read on a closed ZipFile should raise
# a RuntimeError, and so should calling .testzip. An earlier
# version of .testzip would swallow this exception (and any other)
# and report that the first file in the archive was corrupt.
pass
def _exit(code=0):
- """Internal function. Calling it will throw the exception SystemExit."""
+ """Internal function. Calling it will raise the exception SystemExit."""
try:
code = int(code)
except ValueError:
def assertRaises(self, excClass, callableObj=None, *args, **kwargs):
- """Fail unless an exception of class excClass is thrown
+ """Fail unless an exception of class excClass is raised
by callableObj when invoked with arguments args and keyword
arguments kwargs. If a different type of exception is
- thrown, it will not be caught, and the test case will be
+ raised, it will not be caught, and the test case will be
deemed to have suffered an error, exactly as for an
unexpected exception.
When applied between a WSGI server and a WSGI application, this
middleware will check for WSGI compliancy on a number of levels.
This middleware does not modify the request or response in any
- way, but will throw an AssertionError if anything seems off
+ way, but will raise an AssertionError if anything seems off
(except for a failure to close the application iterator, which
- will be printed to stderr -- there's no way to throw an exception
+ will be printed to stderr -- there's no way to raise an exception
at that point).
"""
the application: you can subclass it to provide additional
functionality, or to add localization. Note that although you will
receive a SAXException as the argument to the handlers in the
- ErrorHandler interface, you are not actually required to throw
+ ErrorHandler interface, you are not actually required to raise
the exception; instead, you can simply read the information in
it."""
the original XML document. Note that although the application will
receive a SAXParseException as the argument to the handlers in the
ErrorHandler interface, the application is not actually required
- to throw the exception; instead, it can simply read the
+ to raise the exception; instead, it can simply read the
information in it and take a different action.
Since this exception is a subclass of SAXException, it inherits
self._locator = locator
# We need to cache this stuff at construction time.
- # If this exception is thrown, the objects through which we must
+ # If this exception is raised, the objects through which we must
# traverse to get this information may be deleted by the time
# it gets caught.
self._systemId = self._locator.getSystemId()
SAX parsers are not required to provide localization for errors
and warnings; if they cannot support the requested locale,
- however, they must throw a SAX exception. Applications may
+ however, they must raise a SAX exception. Applications may
request a locale change in the middle of a parse."""
raise SAXNotSupportedException("Locale support not implemented")
class MultiCallIterator:
"""Iterates over the results of a multicall. Exceptions are
- thrown in response to xmlrpc faults."""
+ raised in response to xmlrpc faults."""
def __init__(self, results):
self.results = results
"At the top of the I/O hierarchy is the abstract base class IOBase. It\n"
"defines the basic interface to a stream. Note, however, that there is no\n"
"separation between reading and writing to streams; implementations are\n"
-"allowed to throw an IOError if they do not support a given operation.\n"
+"allowed to raise an IOError if they do not support a given operation.\n"
"\n"
"Extending IOBase is RawIOBase which deals simply with the reading and\n"
"writing of raw bytes to a stream. FileIO subclasses RawIOBase to provide\n"
err_string("parse tree does not use a valid start symbol");
}
}
- /* Make sure we throw an exception on all errors. We should never
+ /* Make sure we raise an exception on all errors. We should never
* get this, but we'd do well to be sure something is done.
*/
if (st == NULL && !PyErr_Occurred())
else if (!ISNONTERMINAL(type)) {
/*
* It has to be one or the other; this is an error.
- * Throw an exception.
+ * Raise an exception.
*/
PyObject *err = Py_BuildValue("os", elem, "unknown node type.");
PyErr_SetObject(parser_error, err);
if (ISTERMINAL(num)) {
/*
* The tuple is simple, but it doesn't start with a start symbol.
- * Throw an exception now and be done with it.
+ * Raise an exception now and be done with it.
*/
tuple = Py_BuildValue("os", tuple,
"Illegal syntax-tree; cannot start with terminal symbol.");
#if defined _MSC_VER && _MSC_VER >= 1400
/* Microsoft CRT in VS2005 and higher will verify that a filehandle is
- * valid and throw an assertion if it isn't.
+ * valid and raise an assertion if it isn't.
* Normally, an invalid fd is likely to be a C program error and therefore
* an assertion can be useful, but it does contradict the POSIX standard
* which for write(2) states:
'''
Small wsgiref based web server. Takes a path to serve from and an
optional port number (defaults to 8000), then tries to serve files.
-Mime types are guessed from the file names, 404 errors are thrown
+Mime types are guessed from the file names, 404 errors are raised
if the file is not found. Used for the make serve target in Doc.
'''
import sys