\begin{funcdesc}{parse}{buf}
Returns an abstract syntax tree for the Python source code in \var{buf}.
-The function raises SyntaxError if there is an error in the source
-code. The return value is a \class{compiler.ast.Module} instance that
-contains the tree.
+The function raises \exception{SyntaxError} if there is an error in the
+source code. The return value is a \class{compiler.ast.Module} instance
+that contains the tree.
\end{funcdesc}
\begin{funcdesc}{parseFile}{path}
\end{methoddesc}
\begin{methoddesc}[array]{fromunicode}{s}
-Extends this array with data from the given unicode string.
-The array must be a type 'u' array; otherwise a ValueError
+Extends this array with data from the given unicode string. The array
+must be a type \code{'u'} array; otherwise a \exception{ValueError}
is raised. Use \samp{array.fromstring(ustr.decode(enc))} to
append Unicode data to an array of some other type.
\end{methoddesc}
\begin{methoddesc}[array]{tounicode}{}
Convert the array to a unicode string. The array must be
-a type 'u' array; otherwise a ValueError is raised. Use
-array.tostring().decode(enc) to obtain a unicode string
+a type \code{'u'} array; otherwise a \exception{ValueError} is raised.
+Use \samp{array.tostring().decode(enc)} to obtain a unicode string
from an array of some other type.
\end{methoddesc}
The optional argument \var{strict_parsing} is a flag indicating what
to do with parsing errors. If false (the default), errors
-are silently ignored. If true, errors raise a ValueError
+are silently ignored. If true, errors raise a \exception{ValueError}
exception.
Use the \function{\refmodule{urllib}.urlencode()} function to convert
The optional argument \var{strict_parsing} is a flag indicating what
to do with parsing errors. If false (the default), errors
-are silently ignored. If true, errors raise a ValueError
+are silently ignored. If true, errors raise a \exception{ValueError}
exception.
Use the \function{\refmodule{urllib}.urlencode()} function to convert
continue. The encoder will encode the replacement and continue encoding
the original input at the specified position. Negative position values
will be treated as being relative to the end of the input string. If the
-resulting position is out of bound an IndexError will be raised.
+resulting position is out of bound an \exception{IndexError} will be raised.
Decoding and translating works similar, except \exception{UnicodeDecodeError}
or \exception{UnicodeTranslateError} will be passed to the handler and
The simplest method is to map the codepoints 0-255 to the bytes
\code{0x0}-\code{0xff}. This means that a unicode object that contains
codepoints above \code{U+00FF} can't be encoded with this method (which
-is called \code{'latin-1'} or \code{'iso-8859-1'}). unicode.encode() will
-raise a UnicodeEncodeError that looks like this: \samp{UnicodeEncodeError:
-'latin-1' codec can't encode character u'\e u1234' in position 3: ordinal
-not in range(256)}.
+is called \code{'latin-1'} or \code{'iso-8859-1'}).
+\function{unicode.encode()} will raise a \exception{UnicodeEncodeError}
+that looks like this: \samp{UnicodeEncodeError: 'latin-1' codec can't
+encode character u'\e u1234' in position 3: ordinal not in range(256)}.
There's another group of encodings (the so called charmap encodings)
that choose a different subset of all unicode code points and how
ignore_discard=\constant{False}, ignore_expires=\constant{False}}
Save cookies to a file.
-This base class raises \class{NotImplementedError}. Subclasses may
+This base class raises \exception{NotImplementedError}. Subclasses may
leave this method unimplemented.
\var{filename} is the name of file in which to save cookies. If
\end{verbatim}
\versionchanged[When no iterables are specified, returns a zero length
- iterator instead of raising a TypeError exception]{2.4}
+ iterator instead of raising a \exception{TypeError}
+ exception]{2.4}
\end{funcdesc}
\begin{funcdesc}{repeat}{object\optional{, times}}
sent before authentication is performed. Reader mode is sometimes
necessary if you are connecting to an NNTP server on the local machine
and intend to call reader-specific commands, such as \samp{group}. If
-you get unexpected \code{NNTPPermanentError}s, you might need to set
+you get unexpected \exception{NNTPPermanentError}s, you might need to set
\var{readermode}. \var{readermode} defaults to \code{None}.
\var{usenetrc} defaults to \code{True}.
\versionchanged[\var{usenetrc} argument added]{2.4}
\end{classdesc}
-\begin{classdesc}{NNTPError}{}
-Derived from the standard exception \code{Exception}, this is the base
-class for all exceptions raised by the \code{nntplib} module.
-\end{classdesc}
+\begin{excdesc}{NNTPError}
+Derived from the standard exception \exception{Exception}, this is the
+base class for all exceptions raised by the \module{nntplib} module.
+\end{excdesc}
-\begin{classdesc}{NNTPReplyError}{}
+\begin{excdesc}{NNTPReplyError}
Exception raised when an unexpected reply is received from the
server. For backwards compatibility, the exception \code{error_reply}
is equivalent to this class.
-\end{classdesc}
+\end{excdesc}
-\begin{classdesc}{NNTPTemporaryError}{}
+\begin{excdesc}{NNTPTemporaryError}
Exception raised when an error code in the range 400--499 is
received. For backwards compatibility, the exception
\code{error_temp} is equivalent to this class.
-\end{classdesc}
+\end{excdesc}
-\begin{classdesc}{NNTPPermanentError}{}
+\begin{excdesc}{NNTPPermanentError}
Exception raised when an error code in the range 500--599 is
received. For backwards compatibility, the exception
\code{error_perm} is equivalent to this class.
-\end{classdesc}
+\end{excdesc}
-\begin{classdesc}{NNTPProtocolError}{}
+\begin{excdesc}{NNTPProtocolError}
Exception raised when a reply is received from the server that does
not begin with a digit in the range 1--5. For backwards
compatibility, the exception \code{error_proto} is equivalent to this
class.
-\end{classdesc}
+\end{excdesc}
-\begin{classdesc}{NNTPDataError}{}
+\begin{excdesc}{NNTPDataError}
Exception raised when there is some error in the response data. For
backwards compatibility, the exception \code{error_data} is
equivalent to this class.
-\end{classdesc}
+\end{excdesc}
\subsection{NNTP Objects \label{nntp-objects}}
single letter, e.g. \code{"-x"} or \code{"-F"}. Also, traditional \UNIX{}
syntax allows multiple options to be merged into a single argument,
e.g. \code{"-x -F"} is equivalent to \code{"-xF"}. The GNU project
-introduced \code{"-{}-"} followed by a series of hyphen-separated words,
-e.g. \code{"-{}-file"} or \code{"-{}-dry-run"}. These are the only two option
+introduced \code{"{--}"} followed by a series of hyphen-separated words,
+e.g. \code{"{--}file"} or \code{"{--}dry-run"}. These are the only two option
syntaxes provided by \module{optparse}.
Some other option syntaxes that the world has seen include:
prog -v --report /tmp/report.txt foo bar
\end{verbatim}
-\code{"-v"} and \code{"-{}-report"} are both options. Assuming that
+\code{"-v"} and \code{"{--}report"} are both options. Assuming that
\longprogramopt{report} takes one argument, \code{"/tmp/report.txt"} is an option
argument. \code{"foo"} and \code{"bar"} are positional arguments.
erroneous calls to \code{parse.add{\_}option()}, e.g. invalid option strings,
unknown option attributes, missing option attributes, etc. These are
dealt with in the usual way: raise an exception (either
-\code{optparse.OptionError} or \code{TypeError}) and let the program crash.
+\exception{optparse.OptionError} or \exception{TypeError}) and let the program crash.
Handling user errors is much more important, since they are guaranteed
to happen no matter how stable your code is. \module{optparse} can automatically
Integer arguments are passed to \code{int()} to convert them to Python
integers. If \code{int()} fails, so will \module{optparse}, although with a more
-useful error message. (Internally, \module{optparse} raises OptionValueError;
-OptionParser catches this exception higher up and terminates your
-program with a useful error message.)
+useful error message. (Internally, \module{optparse} raises
+\exception{OptionValueError}; OptionParser catches this exception higher
+up and terminates your program with a useful error message.)
Likewise, \code{float} arguments are passed to \code{float()} for conversion,
\code{long} arguments to \code{long()}, and \code{complex} arguments to
option attribute (a sequence of strings) defines the set of allowed
option arguments. \code{optparse.option.check{\_}choice()} compares
user-supplied option arguments against this master list and raises
-OptionValueError if an invalid string is given.
+\exception{OptionValueError} if an invalid string is given.
\subsubsection{Querying and manipulating your option parser\label{optparse-querying-manipulating-option-parser}}
option strings, all of those option strings become invalid.
If \code{opt{\_}str} does not occur in any option belonging to this
-OptionParser, raises ValueError.
+OptionParser, raises \exception{ValueError}.
\end{description}
\begin{description}
\item[\code{error} (default)]
assume option conflicts are a programming error and raise
-OptionConflictError
+\exception{OptionConflictError}
\item[\code{resolve}]
resolve option conflicts intelligently (see below)
\end{description}
\subsubsection{Raising errors in a callback\label{optparse-raising-errors-in-callback}}
-The callback function should raise OptionValueError if there are any
+The callback function should raise \exception{OptionValueError} if there are any
problems with the option or its argument(s). \module{optparse} catches this and
terminates the program, printing the error message you supply to
stderr. Your message should be clear, concise, accurate, and mention
\begin{methoddesc}[mixer device]{close}{}
This method closes the open mixer device file. Any further attempts to
-use the mixer after this file is closed will raise an IOError.
+use the mixer after this file is closed will raise an \exception{IOError}.
\end{methoddesc}
\begin{methoddesc}[mixer device]{fileno}{}
\code{+} \code{'c'} (\code{'o'} if optimization is enabled in the
current interpreter). If \var{dfile} is specified, it is used as
the name of the source file in error messages instead of \var{file}.
- If \var{doraise} = True, a PyCompileError is raised when an error is
- encountered while compiling \var{file}. If \var{doraise} = False (the default),
- an error string is written to sys.stderr, but no exception is raised.
+ If \var{doraise} is true, a \exception{PyCompileError} is raised when
+ an error is encountered while compiling \var{file}. If \var{doraise}
+ is false (the default), an error string is written to \code{sys.stderr},
+ but no exception is raised.
\end{funcdesc}
\begin{funcdesc}{main}{\optional{args}}
\leftline{\strong{Avoiding recursion}}
If you create regular expressions that require the engine to perform a
-lot of recursion, you may encounter a RuntimeError exception with
+lot of recursion, you may encounter a \exception{RuntimeError} exception with
the message \code{maximum recursion limit} exceeded. For example,
\begin{verbatim}
\lineiii{\var{s}.add(\var{x})}{}
{add element \var{x} to set \var{s}}
\lineiii{\var{s}.remove(\var{x})}{}
- {remove \var{x} from set \var{s}; raises KeyError if not present}
+ {remove \var{x} from set \var{s}; raises \exception{KeyError}
+ if not present}
\lineiii{\var{s}.discard(\var{x})}{}
{removes \var{x} from set \var{s} if present}
\lineiii{\var{s}.pop()}{}
{remove and return an arbitrary element from \var{s}; raises
- KeyError if empty}
+ \exception{KeyError} if empty}
\lineiii{\var{s}.clear()}{}
{remove all elements from set \var{s}}
\end{tableiii}
If \var{symlinks} is true, symbolic links in
the source tree are represented as symbolic links in the new tree;
if false or omitted, the contents of the linked files are copied to
- the new tree. If exception(s) occur, an Error is raised
+ the new tree. If exception(s) occur, an \exception{Error} is raised
with a list of reasons.
The source code for this should be considered an example rather than
a tool.
- \versionchanged[Error is raised if any exceptions occur during copying,
- rather than printing a message]{2.3}
+ \versionchanged[\exception{Error} is raised if any exceptions occur during
+ copying, rather than printing a message]{2.3}
\versionchanged[Create intermediate directories needed to create \var{dst},
- rather than raising an error. Copy permissions and times of directories using
- \function{copystat()}]{2.5}
+ rather than raising an error. Copy permissions and times of
+ directories using \function{copystat()}]{2.5}
\end{funcdesc}
\lineiii{\var{s}.add(\var{x})}{}
{add element \var{x} to set \var{s}}
\lineiii{\var{s}.remove(\var{x})}{}
- {remove \var{x} from set \var{s}; raises KeyError if not present}
+ {remove \var{x} from set \var{s}; raises \exception{KeyError}
+ if not present}
\lineiii{\var{s}.discard(\var{x})}{}
{removes \var{x} from set \var{s} if present}
\lineiii{\var{s}.pop()}{}
attribute will be \code{None} and if called, an explicit \code{self}
object must be passed as the first argument. In this case,
\code{self} must be an instance of the unbound method's class (or a
-subclass of that class), otherwise a \code{TypeError} is raised.
+subclass of that class), otherwise a \exception{TypeError} is raised.
Like function objects, methods objects support getting
arbitrary attributes. However, since method attributes are actually
stored on the underlying function object (\code{meth.im_func}),
setting method attributes on either bound or unbound methods is
disallowed. Attempting to set a method attribute results in a
-\code{TypeError} being raised. In order to set a method attribute,
+\exception{TypeError} being raised. In order to set a method attribute,
you need to explicitly set it on the underlying function object:
\begin{verbatim}
\begin{funcdesc}{check_call}{*popenargs, **kwargs}
Run command with arguments. Wait for command to complete. If the exit
-code was zero then return, otherwise raise CalledProcessError. The
-CalledProcessError object will have the return code in the
+code was zero then return, otherwise raise \exception{CalledProcessError.}
+The \exception{CalledProcessError} object will have the return code in the
\member{errno} attribute.
The arguments are the same as for the Popen constructor. Example:
\method{\var{protocol}_open()} are called to handle the request.
This stage ends when a handler either returns a
non-\constant{None} value (ie. a response), or raises an exception
- (usually URLError). Exceptions are allowed to propagate.
+ (usually \exception{URLError}). Exceptions are allowed to propagate.
In fact, the above algorithm is first tried for methods named
\method{default_open}. If all such methods return
\begin{classdesc}{zipimporter}{archivepath}
Create a new zipimporter instance. \var{archivepath} must be a path to
- a zipfile. \class{ZipImportError} is raised if \var{archivepath} doesn't
- point to a valid ZIP archive.
+ a zipfile. \exception{ZipImportError} is raised if \var{archivepath}
+ doesn't point to a valid ZIP archive.
\end{classdesc}
\begin{methoddesc}{find_module}{fullname\optional{, path}}
\begin{methoddesc}{get_code}{fullname}
Return the code object for the specified module. Raise
- \class{ZipImportError} if the module couldn't be found.
+ \exception{ZipImportError} if the module couldn't be found.
\end{methoddesc}
\begin{methoddesc}{get_data}{pathname}
\begin{methoddesc}{get_source}{fullname}
Return the source code for the specified module. Raise
- \class{ZipImportError} if the module couldn't be found, return
+ \exception{ZipImportError} if the module couldn't be found, return
\constant{None} if the archive does contain the module, but has
no source for it.
\end{methoddesc}
\begin{methoddesc}{is_package}{fullname}
Return True if the module specified by \var{fullname} is a package.
- Raise \class{ZipImportError} if the module couldn't be found.
+ Raise \exception{ZipImportError} if the module couldn't be found.
\end{methoddesc}
\begin{methoddesc}{load_module}{fullname}
Load the module specified by \var{fullname}. \var{fullname} must be the
fully qualified (dotted) module name. It returns the imported
- module, or raises \class{ZipImportError} if it wasn't found.
+ module, or raises \exception{ZipImportError} if it wasn't found.
\end{methoddesc}
\subsection{Examples}
With an explicit \var{encoding} argument, the result is a byte string
in the specified encoding. It is recommended that this argument is
-always specified. To avoid UnicodeError exceptions in case of
+always specified. To avoid \exception{UnicodeError} exceptions in case of
unrepresentable text data, the encoding argument should be specified
as "utf-8".