Commit c7b05920 authored by Benjamin Peterson's avatar Benjamin Peterson

reformat some documentation of classes so methods and attributes are under the class directive

parent 1c596d56
...@@ -197,10 +197,10 @@ asynchat - Auxiliary Classes and Functions ...@@ -197,10 +197,10 @@ asynchat - Auxiliary Classes and Functions
the data no larger than *buffer_size*. the data no larger than *buffer_size*.
.. method:: simple_producer.more() .. method:: more()
Produces the next chunk of information from the producer, or returns the Produces the next chunk of information from the producer, or returns the
empty string. empty string.
.. class:: fifo([list=None]) .. class:: fifo([list=None])
...@@ -212,26 +212,26 @@ asynchat - Auxiliary Classes and Functions ...@@ -212,26 +212,26 @@ asynchat - Auxiliary Classes and Functions
producers or data items to be written to the channel. producers or data items to be written to the channel.
.. method:: fifo.is_empty() .. method:: is_empty()
Returns ``True`` if and only if the fifo is empty. Returns ``True`` if and only if the fifo is empty.
.. method:: fifo.first() .. method:: first()
Returns the least-recently :meth:`push`\ ed item from the fifo. Returns the least-recently :meth:`push`\ ed item from the fifo.
.. method:: fifo.push(data) .. method:: push(data)
Adds the given data (which may be a string or a producer object) to the Adds the given data (which may be a string or a producer object) to the
producer fifo. producer fifo.
.. method:: fifo.pop() .. method:: pop()
If the fifo is not empty, returns ``True, first()``, deleting the popped If the fifo is not empty, returns ``True, first()``, deleting the popped
item. Returns ``False, None`` for an empty fifo. item. Returns ``False, None`` for an empty fifo.
The :mod:`asynchat` module also defines one utility function, which may be of The :mod:`asynchat` module also defines one utility function, which may be of
use in network and textual analysis operations. use in network and textual analysis operations.
......
...@@ -95,132 +95,132 @@ any that have been added to the map during asynchronous service) is closed. ...@@ -95,132 +95,132 @@ any that have been added to the map during asynchronous service) is closed.
should be added to the list of channels :cfunc:`select`\ ed or should be added to the list of channels :cfunc:`select`\ ed or
:cfunc:`poll`\ ed for read and write events. :cfunc:`poll`\ ed for read and write events.
Thus, the set of channel events is larger than the basic socket events. The Thus, the set of channel events is larger than the basic socket events. The
full set of methods that can be overridden in your subclass follows: full set of methods that can be overridden in your subclass follows:
.. method:: dispatcher.handle_read() .. method:: handle_read()
Called when the asynchronous loop detects that a :meth:`read` call on the Called when the asynchronous loop detects that a :meth:`read` call on the
channel's socket will succeed. channel's socket will succeed.
.. method:: dispatcher.handle_write() .. method:: handle_write()
Called when the asynchronous loop detects that a writable socket can be Called when the asynchronous loop detects that a writable socket can be
written. Often this method will implement the necessary buffering for written. Often this method will implement the necessary buffering for
performance. For example:: performance. For example::
def handle_write(self): def handle_write(self):
sent = self.send(self.buffer) sent = self.send(self.buffer)
self.buffer = self.buffer[sent:] self.buffer = self.buffer[sent:]
.. method:: dispatcher.handle_expt() .. method:: handle_expt()
Called when there is out of band (OOB) data for a socket connection. This Called when there is out of band (OOB) data for a socket connection. This
will almost never happen, as OOB is tenuously supported and rarely used. will almost never happen, as OOB is tenuously supported and rarely used.
.. method:: dispatcher.handle_connect() .. method:: handle_connect()
Called when the active opener's socket actually makes a connection. Might Called when the active opener's socket actually makes a connection. Might
send a "welcome" banner, or initiate a protocol negotiation with the remote send a "welcome" banner, or initiate a protocol negotiation with the
endpoint, for example. remote endpoint, for example.
.. method:: dispatcher.handle_close() .. method:: handle_close()
Called when the socket is closed. Called when the socket is closed.
.. method:: dispatcher.handle_error() .. method:: handle_error()
Called when an exception is raised and not otherwise handled. The default Called when an exception is raised and not otherwise handled. The default
version prints a condensed traceback. version prints a condensed traceback.
.. method:: dispatcher.handle_accept() .. method:: handle_accept()
Called on listening channels (passive openers) when a connection can be Called on listening channels (passive openers) when a connection can be
established with a new remote endpoint that has issued a :meth:`connect` established with a new remote endpoint that has issued a :meth:`connect`
call for the local endpoint. call for the local endpoint.
.. method:: dispatcher.readable() .. method:: readable()
Called each time around the asynchronous loop to determine whether a Called each time around the asynchronous loop to determine whether a
channel's socket should be added to the list on which read events can channel's socket should be added to the list on which read events can
occur. The default method simply returns ``True``, indicating that by occur. The default method simply returns ``True``, indicating that by
default, all channels will be interested in read events. default, all channels will be interested in read events.
.. method:: dispatcher.writable() .. method:: writable()
Called each time around the asynchronous loop to determine whether a Called each time around the asynchronous loop to determine whether a
channel's socket should be added to the list on which write events can channel's socket should be added to the list on which write events can
occur. The default method simply returns ``True``, indicating that by occur. The default method simply returns ``True``, indicating that by
default, all channels will be interested in write events. default, all channels will be interested in write events.
In addition, each channel delegates or extends many of the socket methods.
Most of these are nearly identical to their socket partners.
In addition, each channel delegates or extends many of the socket methods.
Most of these are nearly identical to their socket partners.
.. method:: dispatcher.create_socket(family, type)
This is identical to the creation of a normal socket, and will use the same .. method:: create_socket(family, type)
options for creation. Refer to the :mod:`socket` documentation for
information on creating sockets.
This is identical to the creation of a normal socket, and will use the
same options for creation. Refer to the :mod:`socket` documentation for
information on creating sockets.
.. method:: dispatcher.connect(address)
As with the normal socket object, *address* is a tuple with the first .. method:: connect(address)
element the host to connect to, and the second the port number.
As with the normal socket object, *address* is a tuple with the first
element the host to connect to, and the second the port number.
.. method:: dispatcher.send(data)
Send *data* to the remote end-point of the socket. .. method:: send(data)
Send *data* to the remote end-point of the socket.
.. method:: dispatcher.recv(buffer_size)
Read at most *buffer_size* bytes from the socket's remote end-point. .. method:: recv(buffer_size)
An empty string implies that the channel has been closed from the other
end.
Read at most *buffer_size* bytes from the socket's remote end-point. An
empty string implies that the channel has been closed from the other end.
.. method:: dispatcher.listen(backlog)
Listen for connections made to the socket. The *backlog* argument .. method:: listen(backlog)
specifies the maximum number of queued connections and should be at least
1; the maximum value is system-dependent (usually 5).
Listen for connections made to the socket. The *backlog* argument
specifies the maximum number of queued connections and should be at least
1; the maximum value is system-dependent (usually 5).
.. method:: dispatcher.bind(address)
Bind the socket to *address*. The socket must not already be bound. (The .. method:: bind(address)
format of *address* depends on the address family --- see above.) To mark
the socket as re-usable (setting the :const:`SO_REUSEADDR` option), call
the :class:`dispatcher` object's :meth:`set_reuse_addr` method.
Bind the socket to *address*. The socket must not already be bound. (The
format of *address* depends on the address family --- see above.) To mark
the socket as re-usable (setting the :const:`SO_REUSEADDR` option), call
the :class:`dispatcher` object's :meth:`set_reuse_addr` method.
.. method:: dispatcher.accept()
Accept a connection. The socket must be bound to an address and listening .. method:: accept()
for connections. The return value is a pair ``(conn, address)`` where
*conn* is a *new* socket object usable to send and receive data on the
connection, and *address* is the address bound to the socket on the other
end of the connection.
Accept a connection. The socket must be bound to an address and listening
for connections. The return value is a pair ``(conn, address)`` where
*conn* is a *new* socket object usable to send and receive data on the
connection, and *address* is the address bound to the socket on the other
end of the connection.
.. method:: dispatcher.close()
Close the socket. All future operations on the socket object will fail. .. method:: close()
The remote end-point will receive no more data (after queued data is
flushed). Sockets are automatically closed when they are Close the socket. All future operations on the socket object will fail.
garbage-collected. The remote end-point will receive no more data (after queued data is
flushed). Sockets are automatically closed when they are
garbage-collected.
.. _asyncore-example: .. _asyncore-example:
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -43,22 +43,22 @@ The :mod:`CGIHTTPServer` module defines the following class: ...@@ -43,22 +43,22 @@ The :mod:`CGIHTTPServer` module defines the following class:
and serve the output, instead of serving files, if the request leads to and serve the output, instead of serving files, if the request leads to
somewhere below the ``cgi_directories`` path. somewhere below the ``cgi_directories`` path.
The :class:`CGIHTTPRequestHandler` defines the following data member: The :class:`CGIHTTPRequestHandler` defines the following data member:
.. attribute:: CGIHTTPRequestHandler.cgi_directories .. attribute:: cgi_directories
This defaults to ``['/cgi-bin', '/htbin']`` and describes directories to treat This defaults to ``['/cgi-bin', '/htbin']`` and describes directories to
as containing CGI scripts. treat as containing CGI scripts.
The :class:`CGIHTTPRequestHandler` defines the following methods: The :class:`CGIHTTPRequestHandler` defines the following methods:
.. method:: CGIHTTPRequestHandler.do_POST() .. method:: do_POST()
This method serves the ``'POST'`` request type, only allowed for CGI scripts. This method serves the ``'POST'`` request type, only allowed for CGI
Error 501, "Can only POST to CGI scripts", is output when trying to POST to a scripts. Error 501, "Can only POST to CGI scripts", is output when trying
non-CGI url. to POST to a non-CGI url.
Note that CGI scripts will be run with UID of user nobody, for security reasons. Note that CGI scripts will be run with UID of user nobody, for security reasons.
Problems with the CGI script will be translated to error 403. Problems with the CGI script will be translated to error 403.
......
...@@ -66,62 +66,64 @@ instance will fail with a :exc:`EOFError` exception. ...@@ -66,62 +66,64 @@ instance will fail with a :exc:`EOFError` exception.
optional argument *inclheader* is true, the size given in the chunk header optional argument *inclheader* is true, the size given in the chunk header
includes the size of the header. The default value is false. includes the size of the header. The default value is false.
A :class:`Chunk` object supports the following methods: A :class:`Chunk` object supports the following methods:
.. method:: Chunk.getname() .. method:: getname()
Returns the name (ID) of the chunk. This is the first 4 bytes of the chunk. Returns the name (ID) of the chunk. This is the first 4 bytes of the
chunk.
.. method:: Chunk.getsize() .. method:: getsize()
Returns the size of the chunk. Returns the size of the chunk.
.. method:: Chunk.close() .. method:: close()
Close and skip to the end of the chunk. This does not close the underlying Close and skip to the end of the chunk. This does not close the
file. underlying file.
The remaining methods will raise :exc:`IOError` if called after the The remaining methods will raise :exc:`IOError` if called after the
:meth:`close` method has been called. :meth:`close` method has been called.
.. method:: Chunk.isatty() .. method:: isatty()
Returns ``False``. Returns ``False``.
.. method:: Chunk.seek(pos[, whence]) .. method:: seek(pos[, whence])
Set the chunk's current position. The *whence* argument is optional and Set the chunk's current position. The *whence* argument is optional and
defaults to ``0`` (absolute file positioning); other values are ``1`` (seek defaults to ``0`` (absolute file positioning); other values are ``1``
relative to the current position) and ``2`` (seek relative to the file's end). (seek relative to the current position) and ``2`` (seek relative to the
There is no return value. If the underlying file does not allow seek, only file's end). There is no return value. If the underlying file does not
forward seeks are allowed. allow seek, only forward seeks are allowed.
.. method:: Chunk.tell() .. method:: tell()
Return the current position into the chunk. Return the current position into the chunk.
.. method:: Chunk.read([size]) .. method:: read([size])
Read at most *size* bytes from the chunk (less if the read hits the end of the Read at most *size* bytes from the chunk (less if the read hits the end of
chunk before obtaining *size* bytes). If the *size* argument is negative or the chunk before obtaining *size* bytes). If the *size* argument is
omitted, read all data until the end of the chunk. The bytes are returned as a negative or omitted, read all data until the end of the chunk. The bytes
string object. An empty string is returned when the end of the chunk is are returned as a string object. An empty string is returned when the end
encountered immediately. of the chunk is encountered immediately.
.. method:: Chunk.skip() .. method:: skip()
Skip to the end of the chunk. All further calls to :meth:`read` for the
chunk will return ``''``. If you are not interested in the contents of
the chunk, this method should be called so that the file points to the
start of the next chunk.
Skip to the end of the chunk. All further calls to :meth:`read` for the chunk
will return ``''``. If you are not interested in the contents of the chunk,
this method should be called so that the file points to the start of the next
chunk.
.. rubric:: Footnotes .. rubric:: Footnotes
......
...@@ -435,16 +435,16 @@ define in order to be compatible with the Python codec registry. ...@@ -435,16 +435,16 @@ define in order to be compatible with the Python codec registry.
:func:`register_error`. :func:`register_error`.
.. method:: IncrementalEncoder.encode(object[, final]) .. method:: encode(object[, final])
Encodes *object* (taking the current state of the encoder into account) and Encodes *object* (taking the current state of the encoder into account)
returns the resulting encoded object. If this is the last call to :meth:`encode` and returns the resulting encoded object. If this is the last call to
*final* must be true (the default is false). :meth:`encode` *final* must be true (the default is false).
.. method:: IncrementalEncoder.reset() .. method:: reset()
Reset the encoder to the initial state. Reset the encoder to the initial state.
.. _incremental-decoder-objects: .. _incremental-decoder-objects:
...@@ -483,20 +483,21 @@ define in order to be compatible with the Python codec registry. ...@@ -483,20 +483,21 @@ define in order to be compatible with the Python codec registry.
:func:`register_error`. :func:`register_error`.
.. method:: IncrementalDecoder.decode(object[, final]) .. method:: decode(object[, final])
Decodes *object* (taking the current state of the decoder into account) and Decodes *object* (taking the current state of the decoder into account)
returns the resulting decoded object. If this is the last call to :meth:`decode` and returns the resulting decoded object. If this is the last call to
*final* must be true (the default is false). If *final* is true the decoder must :meth:`decode` *final* must be true (the default is false). If *final* is
decode the input completely and must flush all buffers. If this isn't possible true the decoder must decode the input completely and must flush all
(e.g. because of incomplete byte sequences at the end of the input) it must buffers. If this isn't possible (e.g. because of incomplete byte sequences
initiate error handling just like in the stateless case (which might raise an at the end of the input) it must initiate error handling just like in the
exception). stateless case (which might raise an exception).
.. method:: IncrementalDecoder.reset() .. method:: reset()
Reset the decoder to the initial state.
Reset the decoder to the initial state.
The :class:`StreamWriter` and :class:`StreamReader` classes provide generic The :class:`StreamWriter` and :class:`StreamReader` classes provide generic
working interfaces which can be used to implement new encoding submodules very working interfaces which can be used to implement new encoding submodules very
...@@ -544,24 +545,25 @@ compatible with the Python codec registry. ...@@ -544,24 +545,25 @@ compatible with the Python codec registry.
:func:`register_error`. :func:`register_error`.
.. method:: StreamWriter.write(object) .. method:: write(object)
Writes the object's contents encoded to the stream.
Writes the object's contents encoded to the stream.
.. method:: writelines(list)
.. method:: StreamWriter.writelines(list) Writes the concatenated list of strings to the stream (possibly by reusing
the :meth:`write` method).
Writes the concatenated list of strings to the stream (possibly by reusing the
:meth:`write` method).
.. method:: reset()
.. method:: StreamWriter.reset() Flushes and resets the codec buffers used for keeping state.
Flushes and resets the codec buffers used for keeping state. Calling this method should ensure that the data on the output is put into
a clean state that allows appending of new fresh data without having to
rescan the whole stream to recover state.
Calling this method should ensure that the data on the output is put into a
clean state that allows appending of new fresh data without having to rescan the
whole stream to recover state.
In addition to the above methods, the :class:`StreamWriter` must also inherit In addition to the above methods, the :class:`StreamWriter` must also inherit
all other methods and attributes from the underlying stream. all other methods and attributes from the underlying stream.
...@@ -604,64 +606,68 @@ compatible with the Python codec registry. ...@@ -604,64 +606,68 @@ compatible with the Python codec registry.
:func:`register_error`. :func:`register_error`.
.. method:: StreamReader.read([size[, chars, [firstline]]]) .. method:: read([size[, chars, [firstline]]])
Decodes data from the stream and returns the resulting object. Decodes data from the stream and returns the resulting object.
*chars* indicates the number of characters to read from the stream. :func:`read` *chars* indicates the number of characters to read from the
will never return more than *chars* characters, but it might return less, if stream. :func:`read` will never return more than *chars* characters, but
there are not enough characters available. it might return less, if there are not enough characters available.
*size* indicates the approximate maximum number of bytes to read from the stream *size* indicates the approximate maximum number of bytes to read from the
for decoding purposes. The decoder can modify this setting as appropriate. The stream for decoding purposes. The decoder can modify this setting as
default value -1 indicates to read and decode as much as possible. *size* is appropriate. The default value -1 indicates to read and decode as much as
intended to prevent having to decode huge files in one step. possible. *size* is intended to prevent having to decode huge files in
one step.
*firstline* indicates that it would be sufficient to only return the first line, *firstline* indicates that it would be sufficient to only return the first
if there are decoding errors on later lines. line, if there are decoding errors on later lines.
The method should use a greedy read strategy meaning that it should read as much The method should use a greedy read strategy meaning that it should read
data as is allowed within the definition of the encoding and the given size, as much data as is allowed within the definition of the encoding and the
e.g. if optional encoding endings or state markers are available on the stream, given size, e.g. if optional encoding endings or state markers are
these should be read too. available on the stream, these should be read too.
.. versionchanged:: 2.4 .. versionchanged:: 2.4
*chars* argument added. *chars* argument added.
.. versionchanged:: 2.4.2 .. versionchanged:: 2.4.2
*firstline* argument added. *firstline* argument added.
.. method:: StreamReader.readline([size[, keepends]]) .. method:: readline([size[, keepends]])
Read one line from the input stream and return the decoded data. Read one line from the input stream and return the decoded data.
*size*, if given, is passed as size argument to the stream's :meth:`readline` *size*, if given, is passed as size argument to the stream's
method. :meth:`readline` method.
If *keepends* is false line-endings will be stripped from the lines returned. If *keepends* is false line-endings will be stripped from the lines
returned.
.. versionchanged:: 2.4 .. versionchanged:: 2.4
*keepends* argument added. *keepends* argument added.
.. method:: StreamReader.readlines([sizehint[, keepends]]) .. method:: readlines([sizehint[, keepends]])
Read all lines available on the input stream and return them as a list of lines. Read all lines available on the input stream and return them as a list of
lines.
Line-endings are implemented using the codec's decoder method and are included Line-endings are implemented using the codec's decoder method and are
in the list entries if *keepends* is true. included in the list entries if *keepends* is true.
*sizehint*, if given, is passed as the *size* argument to the stream's *sizehint*, if given, is passed as the *size* argument to the stream's
:meth:`read` method. :meth:`read` method.
.. method:: StreamReader.reset() .. method:: reset()
Resets the codec buffers used for keeping state. Resets the codec buffers used for keeping state.
Note that no stream repositioning should take place. This method is
primarily intended to be able to recover from decoding errors.
Note that no stream repositioning should take place. This method is primarily
intended to be able to recover from decoding errors.
In addition to the above methods, the :class:`StreamReader` must also inherit In addition to the above methods, the :class:`StreamReader` must also inherit
all other methods and attributes from the underlying stream. all other methods and attributes from the underlying stream.
...@@ -730,6 +736,7 @@ The design is such that one can use the factory functions returned by the ...@@ -730,6 +736,7 @@ The design is such that one can use the factory functions returned by the
Error handling is done in the same way as defined for the stream readers and Error handling is done in the same way as defined for the stream readers and
writers. writers.
:class:`StreamRecoder` instances define the combined interfaces of :class:`StreamRecoder` instances define the combined interfaces of
:class:`StreamReader` and :class:`StreamWriter` classes. They inherit all other :class:`StreamReader` and :class:`StreamWriter` classes. They inherit all other
methods and attributes from the underlying stream. methods and attributes from the underlying stream.
......
...@@ -179,62 +179,63 @@ Notes on using :class:`Set` and :class:`MutableSet` as a mixin: ...@@ -179,62 +179,63 @@ Notes on using :class:`Set` and :class:`MutableSet` as a mixin:
.. versionchanged:: 2.6 .. versionchanged:: 2.6
Added *maxlen* parameter. Added *maxlen* parameter.
Deque objects support the following methods: Deque objects support the following methods:
.. method:: deque.append(x) .. method:: append(x)
Add *x* to the right side of the deque. Add *x* to the right side of the deque.
.. method:: deque.appendleft(x) .. method:: appendleft(x)
Add *x* to the left side of the deque. Add *x* to the left side of the deque.
.. method:: deque.clear() .. method:: clear()
Remove all elements from the deque leaving it with length 0. Remove all elements from the deque leaving it with length 0.
.. method:: deque.extend(iterable) .. method:: extend(iterable)
Extend the right side of the deque by appending elements from the iterable Extend the right side of the deque by appending elements from the iterable
argument. argument.
.. method:: deque.extendleft(iterable) .. method:: extendleft(iterable)
Extend the left side of the deque by appending elements from *iterable*. Note, Extend the left side of the deque by appending elements from *iterable*.
the series of left appends results in reversing the order of elements in the Note, the series of left appends results in reversing the order of
iterable argument. elements in the iterable argument.
.. method:: deque.pop() .. method:: pop()
Remove and return an element from the right side of the deque. If no elements Remove and return an element from the right side of the deque. If no
are present, raises an :exc:`IndexError`. elements are present, raises an :exc:`IndexError`.
.. method:: deque.popleft() .. method:: popleft()
Remove and return an element from the left side of the deque. If no elements are Remove and return an element from the left side of the deque. If no
present, raises an :exc:`IndexError`. elements are present, raises an :exc:`IndexError`.
.. method:: deque.remove(value) .. method:: remove(value)
Removed the first occurrence of *value*. If not found, raises a Removed the first occurrence of *value*. If not found, raises a
:exc:`ValueError`. :exc:`ValueError`.
.. versionadded:: 2.5
.. versionadded:: 2.5
.. method:: rotate(n)
.. method:: deque.rotate(n) Rotate the deque *n* steps to the right. If *n* is negative, rotate to
the left. Rotating one step to the right is equivalent to:
``d.appendleft(d.pop())``.
Rotate the deque *n* steps to the right. If *n* is negative, rotate to the
left. Rotating one step to the right is equivalent to:
``d.appendleft(d.pop())``.
In addition to the above, deques support iteration, pickling, ``len(d)``, In addition to the above, deques support iteration, pickling, ``len(d)``,
``reversed(d)``, ``copy.copy(d)``, ``copy.deepcopy(d)``, membership testing with ``reversed(d)``, ``copy.copy(d)``, ``copy.deepcopy(d)``, membership testing with
...@@ -365,33 +366,35 @@ in Unix:: ...@@ -365,33 +366,35 @@ in Unix::
.. versionadded:: 2.5 .. versionadded:: 2.5
:class:`defaultdict` objects support the following method in addition to the :class:`defaultdict` objects support the following method in addition to the
standard :class:`dict` operations: standard :class:`dict` operations:
.. method:: defaultdict.__missing__(key)
.. method:: defaultdict.__missing__(key) If the :attr:`default_factory` attribute is ``None``, this raises an
:exc:`KeyError` exception with the *key* as argument.
If the :attr:`default_factory` attribute is ``None``, this raises an If :attr:`default_factory` is not ``None``, it is called without arguments
:exc:`KeyError` exception with the *key* as argument. to provide a default value for the given *key*, this value is inserted in
the dictionary for the *key*, and returned.
If :attr:`default_factory` is not ``None``, it is called without arguments to If calling :attr:`default_factory` raises an exception this exception is
provide a default value for the given *key*, this value is inserted in the propagated unchanged.
dictionary for the *key*, and returned.
If calling :attr:`default_factory` raises an exception this exception is This method is called by the :meth:`__getitem__` method of the
propagated unchanged. :class:`dict` class when the requested key is not found; whatever it
returns or raises is then returned or raised by :meth:`__getitem__`.
This method is called by the :meth:`__getitem__` method of the :class:`dict`
class when the requested key is not found; whatever it returns or raises is then
returned or raised by :meth:`__getitem__`.
:class:`defaultdict` objects support the following instance variable: :class:`defaultdict` objects support the following instance variable:
.. attribute:: defaultdict.default_factory .. attribute:: defaultdict.default_factory
This attribute is used by the :meth:`__missing__` method; it is initialized from This attribute is used by the :meth:`__missing__` method; it is
the first argument to the constructor, if present, or to ``None``, if absent. initialized from the first argument to the constructor, if present, or to
``None``, if absent.
.. _defaultdict-examples: .. _defaultdict-examples:
......
...@@ -153,22 +153,24 @@ set of named attributes for child nodes. ...@@ -153,22 +153,24 @@ set of named attributes for child nodes.
``None``. XXX Not sure what the rules are for which nodes will have a useful ``None``. XXX Not sure what the rules are for which nodes will have a useful
lineno. lineno.
All :class:`Node` objects offer the following methods: All :class:`Node` objects offer the following methods:
.. method:: Node.getChildren() .. method:: getChildren()
Returns a flattened list of the child nodes and objects in the order they occur. Returns a flattened list of the child nodes and objects in the order they
Specifically, the order of the nodes is the order in which they appear in the occur. Specifically, the order of the nodes is the order in which they
Python grammar. Not all of the children are :class:`Node` instances. The names appear in the Python grammar. Not all of the children are :class:`Node`
of functions and classes, for example, are plain strings. instances. The names of functions and classes, for example, are plain
strings.
.. method:: Node.getChildNodes() .. method:: getChildNodes()
Returns a flattened list of the child nodes in the order they occur. This
method is like :meth:`getChildren`, except that it only returns those
children that are :class:`Node` instances.
Returns a flattened list of the child nodes in the order they occur. This
method is like :meth:`getChildren`, except that it only returns those children
that are :class:`Node` instances.
Two examples illustrate the general structure of :class:`Node` classes. The Two examples illustrate the general structure of :class:`Node` classes. The
:keyword:`while` statement is defined by the following grammar production:: :keyword:`while` statement is defined by the following grammar production::
...@@ -613,18 +615,18 @@ XXX The magic :meth:`visit` method for visitors. ...@@ -613,18 +615,18 @@ XXX The magic :meth:`visit` method for visitors.
particular child node. If no visitor is found for a particular node type, the particular child node. If no visitor is found for a particular node type, the
:meth:`default` method is called. :meth:`default` method is called.
:class:`ASTVisitor` objects have the following methods: :class:`ASTVisitor` objects have the following methods:
XXX describe extra arguments XXX describe extra arguments
.. method:: ASTVisitor.default(node[, ...]) .. method:: default(node[, ...])
.. method:: ASTVisitor.dispatch(node[, ...]) .. method:: dispatch(node[, ...])
.. method:: ASTVisitor.preorder(tree, visitor) .. method:: preorder(tree, visitor)
Bytecode Generation Bytecode Generation
......
...@@ -218,19 +218,20 @@ The :mod:`csv` module defines the following classes: ...@@ -218,19 +218,20 @@ The :mod:`csv` module defines the following classes:
The :class:`Sniffer` class is used to deduce the format of a CSV file. The :class:`Sniffer` class is used to deduce the format of a CSV file.
The :class:`Sniffer` class provides two methods: The :class:`Sniffer` class provides two methods:
.. method:: Sniffer.sniff(sample[, delimiters=None]) .. method:: sniff(sample[, delimiters=None])
Analyze the given *sample* and return a :class:`Dialect` subclass reflecting the Analyze the given *sample* and return a :class:`Dialect` subclass
parameters found. If the optional *delimiters* parameter is given, it is reflecting the parameters found. If the optional *delimiters* parameter
interpreted as a string containing possible valid delimiter characters. is given, it is interpreted as a string containing possible valid
delimiter characters.
.. method:: Sniffer.has_header(sample) .. method:: has_header(sample)
Analyze the sample text (presumed to be in CSV format) and return :const:`True` Analyze the sample text (presumed to be in CSV format) and return
if the first row appears to be a series of column headers. :const:`True` if the first row appears to be a series of column headers.
An example for :class:`Sniffer` use:: An example for :class:`Sniffer` use::
......
This diff is collapsed.
...@@ -1572,92 +1572,94 @@ You can instantiate a :class:`Textbox` object as follows: ...@@ -1572,92 +1572,94 @@ You can instantiate a :class:`Textbox` object as follows:
containing window, with coordinates ``(0, 0)``. The instance's containing window, with coordinates ``(0, 0)``. The instance's
:attr:`stripspaces` flag is initially on. :attr:`stripspaces` flag is initially on.
:class:`Textbox` objects have the following methods: :class:`Textbox` objects have the following methods:
.. method:: Textbox.edit([validator]) .. method:: edit([validator])
This is the entry point you will normally use. It accepts editing keystrokes This is the entry point you will normally use. It accepts editing
until one of the termination keystrokes is entered. If *validator* is supplied, keystrokes until one of the termination keystrokes is entered. If
it must be a function. It will be called for each keystroke entered with the *validator* is supplied, it must be a function. It will be called for
keystroke as a parameter; command dispatch is done on the result. This method each keystroke entered with the keystroke as a parameter; command dispatch
returns the window contents as a string; whether blanks in the window are is done on the result. This method returns the window contents as a
included is affected by the :attr:`stripspaces` member. string; whether blanks in the window are included is affected by the
:attr:`stripspaces` member.
.. method:: Textbox.do_command(ch)
.. method:: do_command(ch)
Process a single command keystroke. Here are the supported special keystrokes:
Process a single command keystroke. Here are the supported special
+------------------+-------------------------------------------+ keystrokes:
| Keystroke | Action |
+==================+===========================================+ +------------------+-------------------------------------------+
| :kbd:`Control-A` | Go to left edge of window. | | Keystroke | Action |
+------------------+-------------------------------------------+ +==================+===========================================+
| :kbd:`Control-B` | Cursor left, wrapping to previous line if | | :kbd:`Control-A` | Go to left edge of window. |
| | appropriate. | +------------------+-------------------------------------------+
+------------------+-------------------------------------------+ | :kbd:`Control-B` | Cursor left, wrapping to previous line if |
| :kbd:`Control-D` | Delete character under cursor. | | | appropriate. |
+------------------+-------------------------------------------+ +------------------+-------------------------------------------+
| :kbd:`Control-E` | Go to right edge (stripspaces off) or end | | :kbd:`Control-D` | Delete character under cursor. |
| | of line (stripspaces on). | +------------------+-------------------------------------------+
+------------------+-------------------------------------------+ | :kbd:`Control-E` | Go to right edge (stripspaces off) or end |
| :kbd:`Control-F` | Cursor right, wrapping to next line when | | | of line (stripspaces on). |
| | appropriate. | +------------------+-------------------------------------------+
+------------------+-------------------------------------------+ | :kbd:`Control-F` | Cursor right, wrapping to next line when |
| :kbd:`Control-G` | Terminate, returning the window contents. | | | appropriate. |
+------------------+-------------------------------------------+ +------------------+-------------------------------------------+
| :kbd:`Control-H` | Delete character backward. | | :kbd:`Control-G` | Terminate, returning the window contents. |
+------------------+-------------------------------------------+ +------------------+-------------------------------------------+
| :kbd:`Control-J` | Terminate if the window is 1 line, | | :kbd:`Control-H` | Delete character backward. |
| | otherwise insert newline. | +------------------+-------------------------------------------+
+------------------+-------------------------------------------+ | :kbd:`Control-J` | Terminate if the window is 1 line, |
| :kbd:`Control-K` | If line is blank, delete it, otherwise | | | otherwise insert newline. |
| | clear to end of line. | +------------------+-------------------------------------------+
+------------------+-------------------------------------------+ | :kbd:`Control-K` | If line is blank, delete it, otherwise |
| :kbd:`Control-L` | Refresh screen. | | | clear to end of line. |
+------------------+-------------------------------------------+ +------------------+-------------------------------------------+
| :kbd:`Control-N` | Cursor down; move down one line. | | :kbd:`Control-L` | Refresh screen. |
+------------------+-------------------------------------------+ +------------------+-------------------------------------------+
| :kbd:`Control-O` | Insert a blank line at cursor location. | | :kbd:`Control-N` | Cursor down; move down one line. |
+------------------+-------------------------------------------+ +------------------+-------------------------------------------+
| :kbd:`Control-P` | Cursor up; move up one line. | | :kbd:`Control-O` | Insert a blank line at cursor location. |
+------------------+-------------------------------------------+ +------------------+-------------------------------------------+
| :kbd:`Control-P` | Cursor up; move up one line. |
Move operations do nothing if the cursor is at an edge where the movement is not +------------------+-------------------------------------------+
possible. The following synonyms are supported where possible:
Move operations do nothing if the cursor is at an edge where the movement
+------------------------+------------------+ is not possible. The following synonyms are supported where possible:
| Constant | Keystroke |
+========================+==================+ +------------------------+------------------+
| :const:`KEY_LEFT` | :kbd:`Control-B` | | Constant | Keystroke |
+------------------------+------------------+ +========================+==================+
| :const:`KEY_RIGHT` | :kbd:`Control-F` | | :const:`KEY_LEFT` | :kbd:`Control-B` |
+------------------------+------------------+ +------------------------+------------------+
| :const:`KEY_UP` | :kbd:`Control-P` | | :const:`KEY_RIGHT` | :kbd:`Control-F` |
+------------------------+------------------+ +------------------------+------------------+
| :const:`KEY_DOWN` | :kbd:`Control-N` | | :const:`KEY_UP` | :kbd:`Control-P` |
+------------------------+------------------+ +------------------------+------------------+
| :const:`KEY_BACKSPACE` | :kbd:`Control-h` | | :const:`KEY_DOWN` | :kbd:`Control-N` |
+------------------------+------------------+ +------------------------+------------------+
| :const:`KEY_BACKSPACE` | :kbd:`Control-h` |
All other keystrokes are treated as a command to insert the given character and +------------------------+------------------+
move right (with line wrapping).
All other keystrokes are treated as a command to insert the given
character and move right (with line wrapping).
.. method:: Textbox.gather()
This method returns the window contents as a string; whether blanks in the .. method:: gather()
window are included is affected by the :attr:`stripspaces` member.
This method returns the window contents as a string; whether blanks in the
window are included is affected by the :attr:`stripspaces` member.
.. attribute:: Textbox.stripspaces
This data member is a flag which controls the interpretation of blanks in the .. attribute:: stripspaces
window. When it is on, trailing blanks on each line are ignored; any cursor
motion that would land the cursor on a trailing blank goes to the end of that This data member is a flag which controls the interpretation of blanks in
line instead, and trailing blanks are stripped when the window contents are the window. When it is on, trailing blanks on each line are ignored; any
gathered. cursor motion that would land the cursor on a trailing blank goes to the
end of that line instead, and trailing blanks are stripped when the window
contents are gathered.
:mod:`curses.wrapper` --- Terminal handler for curses programs :mod:`curses.wrapper` --- Terminal handler for curses programs
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -44,39 +44,40 @@ Here are the public methods of the :class:`Generator` class, imported from the ...@@ -44,39 +44,40 @@ Here are the public methods of the :class:`Generator` class, imported from the
:mod:`email.header.Header` class. Set to zero to disable header wrapping. The :mod:`email.header.Header` class. Set to zero to disable header wrapping. The
default is 78, as recommended (but not required) by :rfc:`2822`. default is 78, as recommended (but not required) by :rfc:`2822`.
The other public :class:`Generator` methods are: The other public :class:`Generator` methods are:
.. method:: Generator.flatten(msg[, unixfrom]) .. method:: flatten(msg[, unixfrom])
Print the textual representation of the message object structure rooted at *msg* Print the textual representation of the message object structure rooted at
to the output file specified when the :class:`Generator` instance was created. *msg* to the output file specified when the :class:`Generator` instance
Subparts are visited depth-first and the resulting text will be properly MIME was created. Subparts are visited depth-first and the resulting text will
encoded. be properly MIME encoded.
Optional *unixfrom* is a flag that forces the printing of the envelope header Optional *unixfrom* is a flag that forces the printing of the envelope
delimiter before the first :rfc:`2822` header of the root message object. If header delimiter before the first :rfc:`2822` header of the root message
the root object has no envelope header, a standard one is crafted. By default, object. If the root object has no envelope header, a standard one is
this is set to ``False`` to inhibit the printing of the envelope delimiter. crafted. By default, this is set to ``False`` to inhibit the printing of
the envelope delimiter.
Note that for subparts, no envelope header is ever printed. Note that for subparts, no envelope header is ever printed.
.. versionadded:: 2.2.2 .. versionadded:: 2.2.2
.. method:: Generator.clone(fp) .. method:: clone(fp)
Return an independent clone of this :class:`Generator` instance with the exact Return an independent clone of this :class:`Generator` instance with the
same options. exact same options.
.. versionadded:: 2.2.2 .. versionadded:: 2.2.2
.. method:: Generator.write(s) .. method:: write(s)
Write the string *s* to the underlying file object, i.e. *outfp* passed to Write the string *s* to the underlying file object, i.e. *outfp* passed to
:class:`Generator`'s constructor. This provides just enough file-like API for :class:`Generator`'s constructor. This provides just enough file-like API
:class:`Generator` instances to be used in extended print statements. for :class:`Generator` instances to be used in extended print statements.
As a convenience, see the methods :meth:`Message.as_string` and As a convenience, see the methods :meth:`Message.as_string` and
``str(aMessage)``, a.k.a. :meth:`Message.__str__`, which simplify the generation ``str(aMessage)``, a.k.a. :meth:`Message.__str__`, which simplify the generation
......
...@@ -76,65 +76,67 @@ Here is the :class:`Header` class description: ...@@ -76,65 +76,67 @@ Here is the :class:`Header` class description:
and is usually either a space or a hard tab character. This character will be and is usually either a space or a hard tab character. This character will be
prepended to continuation lines. prepended to continuation lines.
Optional *errors* is passed straight through to the :meth:`append` method. Optional *errors* is passed straight through to the :meth:`append` method.
.. method:: Header.append(s[, charset[, errors]]) .. method:: append(s[, charset[, errors]])
Append the string *s* to the MIME header. Append the string *s* to the MIME header.
Optional *charset*, if given, should be a :class:`Charset` instance (see Optional *charset*, if given, should be a :class:`Charset` instance (see
:mod:`email.charset`) or the name of a character set, which will be converted to :mod:`email.charset`) or the name of a character set, which will be
a :class:`Charset` instance. A value of ``None`` (the default) means that the converted to a :class:`Charset` instance. A value of ``None`` (the
*charset* given in the constructor is used. default) means that the *charset* given in the constructor is used.
*s* may be a byte string or a Unicode string. If it is a byte string (i.e. *s* may be a byte string or a Unicode string. If it is a byte string
``isinstance(s, str)`` is true), then *charset* is the encoding of that byte (i.e. ``isinstance(s, str)`` is true), then *charset* is the encoding of
string, and a :exc:`UnicodeError` will be raised if the string cannot be decoded that byte string, and a :exc:`UnicodeError` will be raised if the string
with that character set. cannot be decoded with that character set.
If *s* is a Unicode string, then *charset* is a hint specifying the character If *s* is a Unicode string, then *charset* is a hint specifying the
set of the characters in the string. In this case, when producing an character set of the characters in the string. In this case, when
:rfc:`2822`\ -compliant header using :rfc:`2047` rules, the Unicode string will producing an :rfc:`2822`\ -compliant header using :rfc:`2047` rules, the
be encoded using the following charsets in order: ``us-ascii``, the *charset* Unicode string will be encoded using the following charsets in order:
hint, ``utf-8``. The first character set to not provoke a :exc:`UnicodeError` ``us-ascii``, the *charset* hint, ``utf-8``. The first character set to
is used. not provoke a :exc:`UnicodeError` is used.
Optional *errors* is passed through to any :func:`unicode` or Optional *errors* is passed through to any :func:`unicode` or
:func:`ustr.encode` call, and defaults to "strict". :func:`ustr.encode` call, and defaults to "strict".
.. method:: Header.encode([splitchars]) .. method:: encode([splitchars])
Encode a message header into an RFC-compliant format, possibly wrapping long Encode a message header into an RFC-compliant format, possibly wrapping
lines and encapsulating non-ASCII parts in base64 or quoted-printable encodings. long lines and encapsulating non-ASCII parts in base64 or quoted-printable
Optional *splitchars* is a string containing characters to split long ASCII encodings. Optional *splitchars* is a string containing characters to
lines on, in rough support of :rfc:`2822`'s *highest level syntactic breaks*. split long ASCII lines on, in rough support of :rfc:`2822`'s *highest
This doesn't affect :rfc:`2047` encoded lines. level syntactic breaks*. This doesn't affect :rfc:`2047` encoded lines.
The :class:`Header` class also provides a number of methods to support standard The :class:`Header` class also provides a number of methods to support
operators and built-in functions. standard operators and built-in functions.
.. method:: Header.__str__() .. method:: __str__()
A synonym for :meth:`Header.encode`. Useful for ``str(aHeader)``. A synonym for :meth:`Header.encode`. Useful for ``str(aHeader)``.
.. method:: Header.__unicode__() .. method:: __unicode__()
A helper for the built-in :func:`unicode` function. Returns the header as a A helper for the built-in :func:`unicode` function. Returns the header as
Unicode string. a Unicode string.
.. method:: Header.__eq__(other) .. method:: __eq__(other)
This method allows you to compare two :class:`Header` instances for equality. This method allows you to compare two :class:`Header` instances for
equality.
.. method:: Header.__ne__(other) .. method:: __ne__(other)
This method allows you to compare two :class:`Header` instances for inequality. This method allows you to compare two :class:`Header` instances for
inequality.
The :mod:`email.header` module also provides the following convenient functions. The :mod:`email.header` module also provides the following convenient functions.
......
This diff is collapsed.
...@@ -67,20 +67,21 @@ Here is the API for the :class:`FeedParser`: ...@@ -67,20 +67,21 @@ Here is the API for the :class:`FeedParser`:
defaults to the :class:`email.message.Message` class. defaults to the :class:`email.message.Message` class.
.. method:: FeedParser.feed(data) .. method:: feed(data)
Feed the :class:`FeedParser` some more data. *data* should be a string Feed the :class:`FeedParser` some more data. *data* should be a string
containing one or more lines. The lines can be partial and the containing one or more lines. The lines can be partial and the
:class:`FeedParser` will stitch such partial lines together properly. The lines :class:`FeedParser` will stitch such partial lines together properly. The
in the string can have any of the common three line endings, carriage return, lines in the string can have any of the common three line endings,
newline, or carriage return and newline (they can even be mixed). carriage return, newline, or carriage return and newline (they can even be
mixed).
.. method:: FeedParser.close() .. method:: close()
Closing a :class:`FeedParser` completes the parsing of all previously fed data, Closing a :class:`FeedParser` completes the parsing of all previously fed
and returns the root message object. It is undefined what happens if you feed data, and returns the root message object. It is undefined what happens
more data to a closed :class:`FeedParser`. if you feed more data to a closed :class:`FeedParser`.
Parser class API Parser class API
...@@ -119,39 +120,40 @@ class. ...@@ -119,39 +120,40 @@ class.
.. versionchanged:: 2.4 .. versionchanged:: 2.4
The *strict* flag was deprecated. The *strict* flag was deprecated.
The other public :class:`Parser` methods are: The other public :class:`Parser` methods are:
.. method:: Parser.parse(fp[, headersonly]) .. method:: parse(fp[, headersonly])
Read all the data from the file-like object *fp*, parse the resulting text, and Read all the data from the file-like object *fp*, parse the resulting
return the root message object. *fp* must support both the :meth:`readline` and text, and return the root message object. *fp* must support both the
the :meth:`read` methods on file-like objects. :meth:`readline` and the :meth:`read` methods on file-like objects.
The text contained in *fp* must be formatted as a block of :rfc:`2822` style The text contained in *fp* must be formatted as a block of :rfc:`2822`
headers and header continuation lines, optionally preceded by a envelope style headers and header continuation lines, optionally preceded by a
header. The header block is terminated either by the end of the data or by a envelope header. The header block is terminated either by the end of the
blank line. Following the header block is the body of the message (which may data or by a blank line. Following the header block is the body of the
contain MIME-encoded subparts). message (which may contain MIME-encoded subparts).
Optional *headersonly* is as with the :meth:`parse` method. Optional *headersonly* is as with the :meth:`parse` method.
.. versionchanged:: 2.2.2 .. versionchanged:: 2.2.2
The *headersonly* flag was added. The *headersonly* flag was added.
.. method:: Parser.parsestr(text[, headersonly]) .. method:: parsestr(text[, headersonly])
Similar to the :meth:`parse` method, except it takes a string object instead of Similar to the :meth:`parse` method, except it takes a string object
a file-like object. Calling this method on a string is exactly equivalent to instead of a file-like object. Calling this method on a string is exactly
wrapping *text* in a :class:`StringIO` instance first and calling :meth:`parse`. equivalent to wrapping *text* in a :class:`StringIO` instance first and
calling :meth:`parse`.
Optional *headersonly* is a flag specifying whether to stop parsing after Optional *headersonly* is a flag specifying whether to stop parsing after
reading the headers or not. The default is ``False``, meaning it parses the reading the headers or not. The default is ``False``, meaning it parses
entire contents of the file. the entire contents of the file.
.. versionchanged:: 2.2.2 .. versionchanged:: 2.2.2
The *headersonly* flag was added. The *headersonly* flag was added.
Since creating a message object structure from a string or a file object is such Since creating a message object structure from a string or a file object is such
a common task, two functions are provided as a convenience. They are available a common task, two functions are provided as a convenience. They are available
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -40,19 +40,21 @@ report of the imported modules will be printed. ...@@ -40,19 +40,21 @@ report of the imported modules will be printed.
be replaced in module paths. be replaced in module paths.
.. method:: ModuleFinder.report() .. method:: report()
Print a report to standard output that lists the modules imported by the script Print a report to standard output that lists the modules imported by the
and their paths, as well as modules that are missing or seem to be missing. script and their paths, as well as modules that are missing or seem to be
missing.
.. method:: run_script(pathname)
.. method:: ModuleFinder.run_script(pathname) Analyze the contents of the *pathname* file, which must contain Python
code.
Analyze the contents of the *pathname* file, which must contain Python code. .. attribute:: modules
.. attribute:: ModuleFinder.modules A dictionary mapping module names to modules. See
:ref:`modulefinder-example`
A dictionary mapping module names to modules. See :ref:`modulefinder-example`
.. _modulefinder-example: .. _modulefinder-example:
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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