Kaydet (Commit) c7b05920 authored tarafından Benjamin Peterson's avatar Benjamin Peterson

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

üst 1c596d56
......@@ -197,10 +197,10 @@ asynchat - Auxiliary Classes and Functions
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
empty string.
Produces the next chunk of information from the producer, or returns the
empty string.
.. class:: fifo([list=None])
......@@ -212,26 +212,26 @@ asynchat - Auxiliary Classes and Functions
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
producer fifo.
Adds the given data (which may be a string or a producer object) to the
producer fifo.
.. method:: fifo.pop()
.. method:: pop()
If the fifo is not empty, returns ``True, first()``, deleting the popped
item. Returns ``False, None`` for an empty fifo.
If the fifo is not empty, returns ``True, first()``, deleting the popped
item. Returns ``False, None`` for an empty fifo.
The :mod:`asynchat` module also defines one utility function, which may be of
use in network and textual analysis operations.
......
......@@ -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
:cfunc:`poll`\ ed for read and write events.
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:
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:
.. method:: dispatcher.handle_read()
.. method:: handle_read()
Called when the asynchronous loop detects that a :meth:`read` call on the
channel's socket will succeed.
Called when the asynchronous loop detects that a :meth:`read` call on the
channel's socket will succeed.
.. method:: dispatcher.handle_write()
.. method:: handle_write()
Called when the asynchronous loop detects that a writable socket can be
written. Often this method will implement the necessary buffering for
performance. For example::
Called when the asynchronous loop detects that a writable socket can be
written. Often this method will implement the necessary buffering for
performance. For example::
def handle_write(self):
sent = self.send(self.buffer)
self.buffer = self.buffer[sent:]
def handle_write(self):
sent = self.send(self.buffer)
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
will almost never happen, as OOB is tenuously supported and rarely used.
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.
.. method:: dispatcher.handle_connect()
.. method:: handle_connect()
Called when the active opener's socket actually makes a connection. Might
send a "welcome" banner, or initiate a protocol negotiation with the remote
endpoint, for example.
Called when the active opener's socket actually makes a connection. Might
send a "welcome" banner, or initiate a protocol negotiation with the
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
version prints a condensed traceback.
Called when an exception is raised and not otherwise handled. The default
version prints a condensed traceback.
.. method:: dispatcher.handle_accept()
.. method:: handle_accept()
Called on listening channels (passive openers) when a connection can be
established with a new remote endpoint that has issued a :meth:`connect`
call for the local endpoint.
Called on listening channels (passive openers) when a connection can be
established with a new remote endpoint that has issued a :meth:`connect`
call for the local endpoint.
.. method:: dispatcher.readable()
.. method:: readable()
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
occur. The default method simply returns ``True``, indicating that by
default, all channels will be interested in read events.
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
occur. The default method simply returns ``True``, indicating that by
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
channel's socket should be added to the list on which write events can
occur. The default method simply returns ``True``, indicating that by
default, all channels will be interested in write events.
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
occur. The default method simply returns ``True``, indicating that by
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
options for creation. Refer to the :mod:`socket` documentation for
information on creating sockets.
.. method:: create_socket(family, type)
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
element the host to connect to, and the second the port number.
.. method:: connect(address)
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.
An empty string implies that the channel has been closed from the other
end.
.. method:: recv(buffer_size)
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
specifies the maximum number of queued connections and should be at least
1; the maximum value is system-dependent (usually 5).
.. method:: listen(backlog)
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
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:: bind(address)
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
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:: accept()
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.
The remote end-point will receive no more data (after queued data is
flushed). Sockets are automatically closed when they are
garbage-collected.
.. method:: close()
Close the socket. All future operations on the socket object will fail.
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:
......
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:
and serve the output, instead of serving files, if the request leads to
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
as containing CGI scripts.
This defaults to ``['/cgi-bin', '/htbin']`` and describes directories to
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.
Error 501, "Can only POST to CGI scripts", is output when trying to POST to a
non-CGI url.
This method serves the ``'POST'`` request type, only allowed for CGI
scripts. Error 501, "Can only POST to CGI scripts", is output when trying
to POST to a non-CGI url.
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.
......
......@@ -66,62 +66,64 @@ instance will fail with a :exc:`EOFError` exception.
optional argument *inclheader* is true, the size given in the chunk header
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
file.
Close and skip to the end of the chunk. This does not close the
underlying file.
The remaining methods will raise :exc:`IOError` if called after the
:meth:`close` method has been called.
The remaining methods will raise :exc:`IOError` if called after the
: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
defaults to ``0`` (absolute file positioning); other values are ``1`` (seek
relative to the current position) and ``2`` (seek relative to the file's end).
There is no return value. If the underlying file does not allow seek, only
forward seeks are allowed.
Set the chunk's current position. The *whence* argument is optional and
defaults to ``0`` (absolute file positioning); other values are ``1``
(seek relative to the current position) and ``2`` (seek relative to the
file's end). There is no return value. If the underlying file does not
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
chunk before obtaining *size* bytes). If the *size* argument is negative or
omitted, read all data until the end of the chunk. The bytes are returned as a
string object. An empty string is returned when the end of the chunk is
encountered immediately.
Read at most *size* bytes from the chunk (less if the read hits the end of
the chunk before obtaining *size* bytes). If the *size* argument is
negative or omitted, read all data until the end of the chunk. The bytes
are returned as a string object. An empty string is returned when the end
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
......
......@@ -435,16 +435,16 @@ define in order to be compatible with the Python codec registry.
:func:`register_error`.
.. method:: IncrementalEncoder.encode(object[, final])
.. method:: encode(object[, final])
Encodes *object* (taking the current state of the encoder into account) and
returns the resulting encoded object. If this is the last call to :meth:`encode`
*final* must be true (the default is false).
Encodes *object* (taking the current state of the encoder into account)
and returns the resulting encoded object. If this is the last call to
: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:
......@@ -483,20 +483,21 @@ define in order to be compatible with the Python codec registry.
:func:`register_error`.
.. method:: IncrementalDecoder.decode(object[, final])
.. method:: decode(object[, final])
Decodes *object* (taking the current state of the decoder into account) and
returns the resulting decoded object. If this is the last call to :meth:`decode`
*final* must be true (the default is false). If *final* is true the decoder must
decode the input completely and must flush all buffers. If this isn't possible
(e.g. because of incomplete byte sequences at the end of the input) it must
initiate error handling just like in the stateless case (which might raise an
exception).
Decodes *object* (taking the current state of the decoder into account)
and returns the resulting decoded object. If this is the last call to
:meth:`decode` *final* must be true (the default is false). If *final* is
true the decoder must decode the input completely and must flush all
buffers. If this isn't possible (e.g. because of incomplete byte sequences
at the end of the input) it must initiate error handling just like in the
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
working interfaces which can be used to implement new encoding submodules very
......@@ -544,24 +545,25 @@ compatible with the Python codec registry.
: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
all other methods and attributes from the underlying stream.
......@@ -604,64 +606,68 @@ compatible with the Python codec registry.
: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`
will never return more than *chars* characters, but it might return less, if
there are not enough characters available.
*chars* indicates the number of characters to read from the
stream. :func:`read` will never return more than *chars* characters, but
it might return less, if there are not enough characters available.
*size* indicates the approximate maximum number of bytes to read from the stream
for decoding purposes. The decoder can modify this setting as appropriate. The
default value -1 indicates to read and decode as much as possible. *size* is
intended to prevent having to decode huge files in one step.
*size* indicates the approximate maximum number of bytes to read from the
stream for decoding purposes. The decoder can modify this setting as
appropriate. The default value -1 indicates to read and decode as much as
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,
if there are decoding errors on later lines.
*firstline* indicates that it would be sufficient to only return the first
line, if there are decoding errors on later lines.
The method should use a greedy read strategy meaning that it should read as much
data as is allowed within the definition of the encoding and the given size,
e.g. if optional encoding endings or state markers are available on the stream,
these should be read too.
The method should use a greedy read strategy meaning that it should read
as much data as is allowed within the definition of the encoding and the
given size, e.g. if optional encoding endings or state markers are
available on the stream, these should be read too.
.. versionchanged:: 2.4
*chars* argument added.
.. versionchanged:: 2.4
*chars* argument added.
.. versionchanged:: 2.4.2
*firstline* argument added.
.. versionchanged:: 2.4.2
*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`
method.
*size*, if given, is passed as size argument to the stream's
: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
*keepends* argument added.
.. versionchanged:: 2.4
*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
in the list entries if *keepends* is true.
Line-endings are implemented using the codec's decoder method and are
included in the list entries if *keepends* is true.
*sizehint*, if given, is passed as the *size* argument to the stream's
:meth:`read` method.
*sizehint*, if given, is passed as the *size* argument to the stream's
: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
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
Error handling is done in the same way as defined for the stream readers and
writers.
:class:`StreamRecoder` instances define the combined interfaces of
:class:`StreamReader` and :class:`StreamWriter` classes. They inherit all other
methods and attributes from the underlying stream.
......
......@@ -179,62 +179,63 @@ Notes on using :class:`Set` and :class:`MutableSet` as a mixin:
.. versionchanged:: 2.6
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
argument.
Extend the right side of the deque by appending elements from the iterable
argument.
.. method:: deque.extendleft(iterable)
.. method:: extendleft(iterable)
Extend the left side of the deque by appending elements from *iterable*. Note,
the series of left appends results in reversing the order of elements in the
iterable argument.
Extend the left side of the deque by appending elements from *iterable*.
Note, the series of left appends results in reversing the order of
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
are present, raises an :exc:`IndexError`.
Remove and return an element from the right side of the deque. If no
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
present, raises an :exc:`IndexError`.
Remove and return an element from the left side of the deque. If no
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
:exc:`ValueError`.
Removed the first occurrence of *value*. If not found, raises a
: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)``,
``reversed(d)``, ``copy.copy(d)``, ``copy.deepcopy(d)``, membership testing with
......@@ -365,33 +366,35 @@ in Unix::
.. versionadded:: 2.5
:class:`defaultdict` objects support the following method in addition to the
standard :class:`dict` operations:
:class:`defaultdict` objects support the following method in addition to the
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
:exc:`KeyError` exception with the *key* as argument.
If :attr:`default_factory` is not ``None``, it is called without arguments
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
provide a default value for the given *key*, this value is inserted in the
dictionary for the *key*, and returned.
If calling :attr:`default_factory` raises an exception this exception is
propagated unchanged.
If calling :attr:`default_factory` raises an exception this exception is
propagated unchanged.
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__`.
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
the first argument to the constructor, if present, or to ``None``, if absent.
This attribute is used by the :meth:`__missing__` method; it is
initialized from the first argument to the constructor, if present, or to
``None``, if absent.
.. _defaultdict-examples:
......
......@@ -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
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.
Specifically, the order of the nodes is the order in which they appear in the
Python grammar. Not all of the children are :class:`Node` instances. The names
of functions and classes, for example, are plain strings.
Returns a flattened list of the child nodes and objects in the order they
occur. Specifically, the order of the nodes is the order in which they
appear in the Python grammar. Not all of the children are :class:`Node`
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
:keyword:`while` statement is defined by the following grammar production::
......@@ -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
: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
......
......@@ -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 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
parameters found. If the optional *delimiters* parameter is given, it is
interpreted as a string containing possible valid delimiter characters.
Analyze the given *sample* and return a :class:`Dialect` subclass
reflecting the parameters found. If the optional *delimiters* parameter
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`
if the first row appears to be a series of column headers.
Analyze the sample text (presumed to be in CSV format) and return
:const:`True` if the first row appears to be a series of column headers.
An example for :class:`Sniffer` use::
......
This diff is collapsed.
......@@ -1572,92 +1572,94 @@ You can instantiate a :class:`Textbox` object as follows:
containing window, with coordinates ``(0, 0)``. The instance's
:attr:`stripspaces` flag is initially on.
:class:`Textbox` objects have the following methods:
.. method:: Textbox.edit([validator])
This is the entry point you will normally use. It accepts editing keystrokes
until one of the termination keystrokes is entered. If *validator* is supplied,
it must be a function. It will be called for each keystroke entered with the
keystroke as a parameter; command dispatch is done on the result. This method
returns the window contents as a string; whether blanks in the window are
included is affected by the :attr:`stripspaces` member.
.. method:: Textbox.do_command(ch)
Process a single command keystroke. Here are the supported special keystrokes:
+------------------+-------------------------------------------+
| Keystroke | Action |
+==================+===========================================+
| :kbd:`Control-A` | Go to left edge of window. |
+------------------+-------------------------------------------+
| :kbd:`Control-B` | Cursor left, wrapping to previous line if |
| | appropriate. |
+------------------+-------------------------------------------+
| :kbd:`Control-D` | Delete character under cursor. |
+------------------+-------------------------------------------+
| :kbd:`Control-E` | Go to right edge (stripspaces off) or end |
| | of line (stripspaces on). |
+------------------+-------------------------------------------+
| :kbd:`Control-F` | Cursor right, wrapping to next line when |
| | appropriate. |
+------------------+-------------------------------------------+
| :kbd:`Control-G` | Terminate, returning the window contents. |
+------------------+-------------------------------------------+
| :kbd:`Control-H` | Delete character backward. |
+------------------+-------------------------------------------+
| :kbd:`Control-J` | Terminate if the window is 1 line, |
| | otherwise insert newline. |
+------------------+-------------------------------------------+
| :kbd:`Control-K` | If line is blank, delete it, otherwise |
| | clear to end of line. |
+------------------+-------------------------------------------+
| :kbd:`Control-L` | Refresh screen. |
+------------------+-------------------------------------------+
| :kbd:`Control-N` | Cursor down; move down 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:
+------------------------+------------------+
| Constant | Keystroke |
+========================+==================+
| :const:`KEY_LEFT` | :kbd:`Control-B` |
+------------------------+------------------+
| :const:`KEY_RIGHT` | :kbd:`Control-F` |
+------------------------+------------------+
| :const:`KEY_UP` | :kbd:`Control-P` |
+------------------------+------------------+
| :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).
.. method:: Textbox.gather()
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
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
line instead, and trailing blanks are stripped when the window contents are
gathered.
:class:`Textbox` objects have the following methods:
.. method:: edit([validator])
This is the entry point you will normally use. It accepts editing
keystrokes until one of the termination keystrokes is entered. If
*validator* is supplied, it must be a function. It will be called for
each keystroke entered with the keystroke as a parameter; command dispatch
is done on the result. This method returns the window contents as a
string; whether blanks in the window are included is affected by the
:attr:`stripspaces` member.
.. method:: do_command(ch)
Process a single command keystroke. Here are the supported special
keystrokes:
+------------------+-------------------------------------------+
| Keystroke | Action |
+==================+===========================================+
| :kbd:`Control-A` | Go to left edge of window. |
+------------------+-------------------------------------------+
| :kbd:`Control-B` | Cursor left, wrapping to previous line if |
| | appropriate. |
+------------------+-------------------------------------------+
| :kbd:`Control-D` | Delete character under cursor. |
+------------------+-------------------------------------------+
| :kbd:`Control-E` | Go to right edge (stripspaces off) or end |
| | of line (stripspaces on). |
+------------------+-------------------------------------------+
| :kbd:`Control-F` | Cursor right, wrapping to next line when |
| | appropriate. |
+------------------+-------------------------------------------+
| :kbd:`Control-G` | Terminate, returning the window contents. |
+------------------+-------------------------------------------+
| :kbd:`Control-H` | Delete character backward. |
+------------------+-------------------------------------------+
| :kbd:`Control-J` | Terminate if the window is 1 line, |
| | otherwise insert newline. |
+------------------+-------------------------------------------+
| :kbd:`Control-K` | If line is blank, delete it, otherwise |
| | clear to end of line. |
+------------------+-------------------------------------------+
| :kbd:`Control-L` | Refresh screen. |
+------------------+-------------------------------------------+
| :kbd:`Control-N` | Cursor down; move down 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:
+------------------------+------------------+
| Constant | Keystroke |
+========================+==================+
| :const:`KEY_LEFT` | :kbd:`Control-B` |
+------------------------+------------------+
| :const:`KEY_RIGHT` | :kbd:`Control-F` |
+------------------------+------------------+
| :const:`KEY_UP` | :kbd:`Control-P` |
+------------------------+------------------+
| :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).
.. method:: gather()
This method returns the window contents as a string; whether blanks in the
window are included is affected by the :attr:`stripspaces` member.
.. attribute:: stripspaces
This data member is a flag which controls the interpretation of blanks in
the 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 line instead, and trailing blanks are stripped when the window
contents are gathered.
: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
:mod:`email.header.Header` class. Set to zero to disable header wrapping. The
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*
to the output file specified when the :class:`Generator` instance was created.
Subparts are visited depth-first and the resulting text will be properly MIME
encoded.
Print the textual representation of the message object structure rooted at
*msg* to the output file specified when the :class:`Generator` instance
was created. Subparts are visited depth-first and the resulting text will
be properly MIME encoded.
Optional *unixfrom* is a flag that forces the printing of the envelope header
delimiter before the first :rfc:`2822` header of the root message object. If
the root object has no envelope header, a standard one is crafted. By default,
this is set to ``False`` to inhibit the printing of the envelope delimiter.
Optional *unixfrom* is a flag that forces the printing of the envelope
header delimiter before the first :rfc:`2822` header of the root message
object. If the root object has no envelope header, a standard one is
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
same options.
Return an independent clone of this :class:`Generator` instance with the
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
:class:`Generator`'s constructor. This provides just enough file-like API for
:class:`Generator` instances to be used in extended print statements.
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` instances to be used in extended print statements.
As a convenience, see the methods :meth:`Message.as_string` and
``str(aMessage)``, a.k.a. :meth:`Message.__str__`, which simplify the generation
......
......@@ -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
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
:mod:`email.charset`) or the name of a character set, which will be converted to
a :class:`Charset` instance. A value of ``None`` (the default) means that the
*charset* given in the constructor is used.
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 a :class:`Charset` instance. A value of ``None`` (the
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.
``isinstance(s, str)`` is true), then *charset* is the encoding of that byte
string, and a :exc:`UnicodeError` will be raised if the string cannot be decoded
with that character set.
*s* may be a byte string or a Unicode string. If it is a byte string
(i.e. ``isinstance(s, str)`` is true), then *charset* is the encoding of
that byte string, and a :exc:`UnicodeError` will be raised if the string
cannot be decoded with that character set.
If *s* is a Unicode string, then *charset* is a hint specifying the character
set of the characters in the string. In this case, when producing an
:rfc:`2822`\ -compliant header using :rfc:`2047` rules, the Unicode string will
be encoded using the following charsets in order: ``us-ascii``, the *charset*
hint, ``utf-8``. The first character set to not provoke a :exc:`UnicodeError`
is used.
If *s* is a Unicode string, then *charset* is a hint specifying the
character set of the characters in the string. In this case, when
producing an :rfc:`2822`\ -compliant header using :rfc:`2047` rules, the
Unicode string will be encoded using the following charsets in order:
``us-ascii``, the *charset* hint, ``utf-8``. The first character set to
not provoke a :exc:`UnicodeError` is used.
Optional *errors* is passed through to any :func:`unicode` or
:func:`ustr.encode` call, and defaults to "strict".
Optional *errors* is passed through to any :func:`unicode` or
: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
lines and encapsulating non-ASCII parts in base64 or quoted-printable encodings.
Optional *splitchars* is a string containing characters to split long ASCII
lines on, in rough support of :rfc:`2822`'s *highest level syntactic breaks*.
This doesn't affect :rfc:`2047` encoded lines.
Encode a message header into an RFC-compliant format, possibly wrapping
long lines and encapsulating non-ASCII parts in base64 or quoted-printable
encodings. Optional *splitchars* is a string containing characters to
split long ASCII lines on, in rough support of :rfc:`2822`'s *highest
level syntactic breaks*. This doesn't affect :rfc:`2047` encoded lines.
The :class:`Header` class also provides a number of methods to support standard
operators and built-in functions.
The :class:`Header` class also provides a number of methods to support
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
Unicode string.
A helper for the built-in :func:`unicode` function. Returns the header as
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.
......
This diff is collapsed.
......@@ -67,20 +67,21 @@ Here is the API for the :class:`FeedParser`:
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
containing one or more lines. The lines can be partial and the
:class:`FeedParser` will stitch such partial lines together properly. The lines
in the string can have any of the common three line endings, carriage return,
newline, or carriage return and newline (they can even be mixed).
Feed the :class:`FeedParser` some more data. *data* should be a string
containing one or more lines. The lines can be partial and the
:class:`FeedParser` will stitch such partial lines together properly. The
lines in the string can have any of the common three line endings,
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,
and returns the root message object. It is undefined what happens if you feed
more data to a closed :class:`FeedParser`.
Closing a :class:`FeedParser` completes the parsing of all previously fed
data, and returns the root message object. It is undefined what happens
if you feed more data to a closed :class:`FeedParser`.
Parser class API
......@@ -119,39 +120,40 @@ class.
.. versionchanged:: 2.4
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
return the root message object. *fp* must support both the :meth:`readline` and
the :meth:`read` methods on file-like objects.
Read all the data from the file-like object *fp*, parse the resulting
text, and return the root message object. *fp* must support both the
: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
headers and header continuation lines, optionally preceded by a envelope
header. The header block is terminated either by the end of the data or by a
blank line. Following the header block is the body of the message (which may
contain MIME-encoded subparts).
The text contained in *fp* must be formatted as a block of :rfc:`2822`
style headers and header continuation lines, optionally preceded by a
envelope header. The header block is terminated either by the end of the
data or by a blank line. Following the header block is the body of the
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
The *headersonly* flag was added.
.. versionchanged:: 2.2.2
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
a file-like object. Calling this method on a string is exactly equivalent to
wrapping *text* in a :class:`StringIO` instance first and calling :meth:`parse`.
Similar to the :meth:`parse` method, except it takes a string object
instead of a file-like object. Calling this method on a string is exactly
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
reading the headers or not. The default is ``False``, meaning it parses the
entire contents of the file.
Optional *headersonly* is a flag specifying whether to stop parsing after
reading the headers or not. The default is ``False``, meaning it parses
the entire contents of the file.
.. versionchanged:: 2.2.2
The *headersonly* flag was added.
.. versionchanged:: 2.2.2
The *headersonly* flag was added.
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
......
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.
be replaced in module paths.
.. method:: ModuleFinder.report()
.. method:: report()
Print a report to standard output that lists the modules imported by the script
and their paths, as well as modules that are missing or seem to be missing.
Print a report to standard output that lists the modules imported by the
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:
......
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