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

Merged revisions 62490 via svnmerge from

svn+ssh://pythondev@svn.python.org/python/trunk

........
  r62490 | benjamin.peterson | 2008-04-24 20:29:10 -0500 (Thu, 24 Apr 2008) | 2 lines

  reformat some documentation of classes so methods and attributes are under the class directive
........
üst 768db92b
......@@ -197,7 +197,7 @@ 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.
......@@ -212,23 +212,23 @@ 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.
.. method:: fifo.first()
.. method:: first()
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.
.. 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.
......
......@@ -95,17 +95,17 @@ 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.
.. 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
......@@ -116,38 +116,38 @@ full set of methods that can be overridden in your subclass follows:
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.
.. 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.
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.
.. method:: dispatcher.handle_error()
.. method:: handle_error()
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.
.. 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
......@@ -155,50 +155,50 @@ full set of methods that can be overridden in your subclass follows:
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.
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
.. 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)
.. 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)
.. method:: send(data)
Send *data* to the remote end-point of the socket.
.. method:: dispatcher.recv(buffer_size)
.. 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.
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)
.. 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)
.. 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
......@@ -206,7 +206,7 @@ Most of these are nearly identical to their socket partners.
the :class:`dispatcher` object's :meth:`set_reuse_addr` method.
.. method:: dispatcher.accept()
.. 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
......@@ -215,7 +215,7 @@ Most of these are nearly identical to their socket partners.
end of the connection.
.. method:: dispatcher.close()
.. 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
......
This diff is collapsed.
This diff is collapsed.
......@@ -46,73 +46,75 @@ Handling of compressed files is offered by the :class:`BZ2File` class.
Open a bz2 file. Mode can be either ``'r'`` or ``'w'``, for reading (default)
or writing. When opened for writing, the file will be created if it doesn't
exist, and truncated otherwise. If *buffering* is given, ``0`` means unbuffered,
and larger numbers specify the buffer size; the default is ``0``. If
*compresslevel* is given, it must be a number between ``1`` and ``9``; the
default is ``9``. Add a ``'U'`` to mode to open the file for input with
universal newline support. Any line ending in the input file will be seen as a
``'\n'`` in Python. Also, a file so opened gains the attribute
exist, and truncated otherwise. If *buffering* is given, ``0`` means
unbuffered, and larger numbers specify the buffer size; the default is
``0``. If *compresslevel* is given, it must be a number between ``1`` and
``9``; the default is ``9``. Add a ``'U'`` to mode to open the file for input
with universal newline support. Any line ending in the input file will be
seen as a ``'\n'`` in Python. Also, a file so opened gains the attribute
:attr:`newlines`; the value for this attribute is one of ``None`` (no newline
read yet), ``'\r'``, ``'\n'``, ``'\r\n'`` or a tuple containing all the newline
types seen. Universal newlines are available only when reading. Instances
support iteration in the same way as normal :class:`file` instances.
read yet), ``'\r'``, ``'\n'``, ``'\r\n'`` or a tuple containing all the
newline types seen. Universal newlines are available only when
reading. Instances support iteration in the same way as normal :class:`file`
instances.
.. method:: BZ2File.close()
.. method:: close()
Close the file. Sets data attribute :attr:`closed` to true. A closed file cannot
be used for further I/O operations. :meth:`close` may be called more than once
without error.
Close the file. Sets data attribute :attr:`closed` to true. A closed file
cannot be used for further I/O operations. :meth:`close` may be called
more than once without error.
.. method:: BZ2File.read([size])
.. method:: read([size])
Read at most *size* uncompressed bytes, returned as a string. If the *size*
argument is negative or omitted, read until EOF is reached.
Read at most *size* uncompressed bytes, returned as a string. If the
*size* argument is negative or omitted, read until EOF is reached.
.. method:: BZ2File.readline([size])
.. method:: readline([size])
Return the next line from the file, as a string, retaining newline. A
non-negative *size* argument limits the maximum number of bytes to return (an
incomplete line may be returned then). Return an empty string at EOF.
non-negative *size* argument limits the maximum number of bytes to return
(an incomplete line may be returned then). Return an empty string at EOF.
.. method:: BZ2File.readlines([size])
.. method:: readlines([size])
Return a list of lines read. The optional *size* argument, if given, is an
approximate bound on the total number of bytes in the lines returned.
.. method:: BZ2File.seek(offset[, whence])
.. method:: seek(offset[, whence])
Move to new file position. Argument *offset* is a byte count. Optional argument
*whence* defaults to ``os.SEEK_SET`` or ``0`` (offset from start of file; offset
should be ``>= 0``); other values are ``os.SEEK_CUR`` or ``1`` (move relative to
current position; offset can be positive or negative), and ``os.SEEK_END`` or
``2`` (move relative to end of file; offset is usually negative, although many
platforms allow seeking beyond the end of a file).
Move to new file position. Argument *offset* is a byte count. Optional
argument *whence* defaults to ``os.SEEK_SET`` or ``0`` (offset from start
of file; offset should be ``>= 0``); other values are ``os.SEEK_CUR`` or
``1`` (move relative to current position; offset can be positive or
negative), and ``os.SEEK_END`` or ``2`` (move relative to end of file;
offset is usually negative, although many platforms allow seeking beyond
the end of a file).
Note that seeking of bz2 files is emulated, and depending on the parameters the
operation may be extremely slow.
Note that seeking of bz2 files is emulated, and depending on the
parameters the operation may be extremely slow.
.. method:: BZ2File.tell()
.. method:: tell()
Return the current file position, an integer.
.. method:: BZ2File.write(data)
.. method:: write(data)
Write string *data* to file. Note that due to buffering, :meth:`close` may be
needed before the file on disk reflects the data written.
Write string *data* to file. Note that due to buffering, :meth:`close` may
be needed before the file on disk reflects the data written.
.. method:: BZ2File.writelines(sequence_of_strings)
.. method:: writelines(sequence_of_strings)
Write the sequence of strings to the file. Note that newlines are not added. The
sequence can be any iterable object producing strings. This is equivalent to
calling write() for each string.
Write the sequence of strings to the file. Note that newlines are not
added. The sequence can be any iterable object producing strings. This is
equivalent to calling write() for each string.
Sequential (de)compression
......@@ -125,23 +127,23 @@ Sequential compression and decompression is done using the classes
.. class:: BZ2Compressor([compresslevel])
Create a new compressor object. This object may be used to compress data
sequentially. If you want to compress data in one shot, use the :func:`compress`
function instead. The *compresslevel* parameter, if given, must be a number
between ``1`` and ``9``; the default is ``9``.
sequentially. If you want to compress data in one shot, use the
:func:`compress` function instead. The *compresslevel* parameter, if given,
must be a number between ``1`` and ``9``; the default is ``9``.
.. method:: BZ2Compressor.compress(data)
.. method:: compress(data)
Provide more data to the compressor object. It will return chunks of compressed
data whenever possible. When you've finished providing data to compress, call
the :meth:`flush` method to finish the compression process, and return what is
left in internal buffers.
Provide more data to the compressor object. It will return chunks of
compressed data whenever possible. When you've finished providing data to
compress, call the :meth:`flush` method to finish the compression process,
and return what is left in internal buffers.
.. method:: BZ2Compressor.flush()
.. method:: flush()
Finish the compression process and return what is left in internal buffers. You
must not use the compressor object after calling this method.
Finish the compression process and return what is left in internal
buffers. You must not use the compressor object after calling this method.
.. class:: BZ2Decompressor()
......@@ -151,12 +153,13 @@ Sequential compression and decompression is done using the classes
:func:`decompress` function instead.
.. method:: BZ2Decompressor.decompress(data)
.. method:: decompress(data)
Provide more data to the decompressor object. It will return chunks of
decompressed data whenever possible. If you try to decompress data after the end
of stream is found, :exc:`EOFError` will be raised. If any data was found after
the end of stream, it'll be ignored and saved in :attr:`unused_data` attribute.
decompressed data whenever possible. If you try to decompress data after
the end of stream is found, :exc:`EOFError` will be raised. If any data
was found after the end of stream, it'll be ignored and saved in
:attr:`unused_data` attribute.
One-shot (de)compression
......@@ -168,13 +171,13 @@ and :func:`decompress` functions.
.. function:: compress(data[, compresslevel])
Compress *data* in one shot. If you want to compress data sequentially, use an
instance of :class:`BZ2Compressor` instead. The *compresslevel* parameter, if
given, must be a number between ``1`` and ``9``; the default is ``9``.
Compress *data* in one shot. If you want to compress data sequentially, use
an instance of :class:`BZ2Compressor` instead. The *compresslevel* parameter,
if given, must be a number between ``1`` and ``9``; the default is ``9``.
.. function:: decompress(data)
Decompress *data* in one shot. If you want to decompress data sequentially, use
an instance of :class:`BZ2Decompressor` instead.
Decompress *data* in one shot. If you want to decompress data sequentially,
use an instance of :class:`BZ2Decompressor` instead.
......@@ -33,70 +33,71 @@ it's the base calendar for all computations.
itself. This is the job of subclasses.
:class:`Calendar` instances have the following methods:
:class:`Calendar` instances have the following methods:
.. method:: Calendar.iterweekdays(weekday)
.. method:: iterweekdays(weekday)
Return an iterator for the week day numbers that will be used for one week.
The first value from the iterator will be the same as the value of the
:attr:`firstweekday` property.
Return an iterator for the week day numbers that will be used for one
week. The first value from the iterator will be the same as the value of
the :attr:`firstweekday` property.
.. method:: Calendar.itermonthdates(year, month)
.. method:: itermonthdates(year, month)
Return an iterator for the month *month* (1-12) in the year *year*. This
iterator will return all days (as :class:`datetime.date` objects) for the month
and all days before the start of the month or after the end of the month that
are required to get a complete week.
iterator will return all days (as :class:`datetime.date` objects) for the
month and all days before the start of the month or after the end of the
month that are required to get a complete week.
.. method:: Calendar.itermonthdays2(year, month)
.. method:: itermonthdays2(year, month)
Return an iterator for the month *month* in the year *year* similar to
:meth:`itermonthdates`. Days returned will be tuples consisting of a day number
and a week day number.
:meth:`itermonthdates`. Days returned will be tuples consisting of a day
number and a week day number.
.. method:: Calendar.itermonthdays(year, month)
.. method:: itermonthdays(year, month)
Return an iterator for the month *month* in the year *year* similar to
:meth:`itermonthdates`. Days returned will simply be day numbers.
.. method:: Calendar.monthdatescalendar(year, month)
.. method:: monthdatescalendar(year, month)
Return a list of the weeks in the month *month* of the *year* as full weeks.
Weeks are lists of seven :class:`datetime.date` objects.
Return a list of the weeks in the month *month* of the *year* as full
weeks. Weeks are lists of seven :class:`datetime.date` objects.
.. method:: Calendar.monthdays2calendar(year, month)
.. method:: monthdays2calendar(year, month)
Return a list of the weeks in the month *month* of the *year* as full weeks.
Weeks are lists of seven tuples of day numbers and weekday numbers.
Return a list of the weeks in the month *month* of the *year* as full
weeks. Weeks are lists of seven tuples of day numbers and weekday
numbers.
.. method:: Calendar.monthdayscalendar(year, month)
.. method:: monthdayscalendar(year, month)
Return a list of the weeks in the month *month* of the *year* as full weeks.
Weeks are lists of seven day numbers.
Return a list of the weeks in the month *month* of the *year* as full
weeks. Weeks are lists of seven day numbers.
.. method:: Calendar.yeardatescalendar(year[, width])
.. method:: yeardatescalendar(year[, width])
Return the data for the specified year ready for formatting. The return value
is a list of month rows. Each month row contains up to *width* months
(defaulting to 3). Each month contains between 4 and 6 weeks and each week
contains 1--7 days. Days are :class:`datetime.date` objects.
Return the data for the specified year ready for formatting. The return
value is a list of month rows. Each month row contains up to *width*
months (defaulting to 3). Each month contains between 4 and 6 weeks and
each week contains 1--7 days. Days are :class:`datetime.date` objects.
.. method:: Calendar.yeardays2calendar(year[, width])
.. method:: yeardays2calendar(year[, width])
Return the data for the specified year ready for formatting (similar to
:meth:`yeardatescalendar`). Entries in the week lists are tuples of day
numbers and weekday numbers. Day numbers outside this month are zero.
.. method:: Calendar.yeardayscalendar(year[, width])
.. method:: yeardayscalendar(year[, width])
Return the data for the specified year ready for formatting (similar to
:meth:`yeardatescalendar`). Entries in the week lists are day numbers. Day
......@@ -108,33 +109,33 @@ it's the base calendar for all computations.
This class can be used to generate plain text calendars.
:class:`TextCalendar` instances have the following methods:
:class:`TextCalendar` instances have the following methods:
.. method:: TextCalendar.formatmonth(theyear, themonth[, w[, l]])
.. method:: formatmonth(theyear, themonth[, w[, l]])
Return a month's calendar in a multi-line string. If *w* is provided, it
specifies the width of the date columns, which are centered. If *l* is given,
it specifies the number of lines that each week will use. Depends on the
first weekday as specified in the constructor or set by the
specifies the width of the date columns, which are centered. If *l* is
given, it specifies the number of lines that each week will use. Depends
on the first weekday as specified in the constructor or set by the
:meth:`setfirstweekday` method.
.. method:: TextCalendar.prmonth(theyear, themonth[, w[, l]])
.. method:: prmonth(theyear, themonth[, w[, l]])
Print a month's calendar as returned by :meth:`formatmonth`.
.. method:: TextCalendar.formatyear(theyear, themonth[, w[, l[, c[, m]]]])
.. method:: formatyear(theyear, themonth[, w[, l[, c[, m]]]])
Return a *m*-column calendar for an entire year as a multi-line string.
Optional parameters *w*, *l*, and *c* are for date column width, lines per
week, and number of spaces between month columns, respectively. Depends on
the first weekday as specified in the constructor or set by the
:meth:`setfirstweekday` method. The earliest year for which a calendar can
be generated is platform-dependent.
:meth:`setfirstweekday` method. The earliest year for which a calendar
can be generated is platform-dependent.
.. method:: TextCalendar.pryear(theyear[, w[, l[, c[, m]]]])
.. method:: pryear(theyear[, w[, l[, c[, m]]]])
Print the calendar for an entire year as returned by :meth:`formatyear`.
......@@ -144,43 +145,44 @@ it's the base calendar for all computations.
This class can be used to generate HTML calendars.
:class:`HTMLCalendar` instances have the following methods:
:class:`HTMLCalendar` instances have the following methods:
.. method:: HTMLCalendar.formatmonth(theyear, themonth[, withyear])
.. method:: formatmonth(theyear, themonth[, withyear])
Return a month's calendar as an HTML table. If *withyear* is true the year will
be included in the header, otherwise just the month name will be used.
Return a month's calendar as an HTML table. If *withyear* is true the year
will be included in the header, otherwise just the month name will be
used.
.. method:: HTMLCalendar.formatyear(theyear, themonth[, width])
.. method:: formatyear(theyear, themonth[, width])
Return a year's calendar as an HTML table. *width* (defaulting to 3) specifies
the number of months per row.
Return a year's calendar as an HTML table. *width* (defaulting to 3)
specifies the number of months per row.
.. method:: HTMLCalendar.formatyearpage(theyear[, width[, css[, encoding]]])
.. method:: formatyearpage(theyear[, width[, css[, encoding]]])
Return a year's calendar as a complete HTML page. *width* (defaulting to 3)
specifies the number of months per row. *css* is the name for the cascading
style sheet to be used. :const:`None` can be passed if no style sheet should be
used. *encoding* specifies the encoding to be used for the output (defaulting to
the system default encoding).
Return a year's calendar as a complete HTML page. *width* (defaulting to
3) specifies the number of months per row. *css* is the name for the
cascading style sheet to be used. :const:`None` can be passed if no style
sheet should be used. *encoding* specifies the encoding to be used for the
output (defaulting to the system default encoding).
.. class:: LocaleTextCalendar([firstweekday[, locale]])
This subclass of :class:`TextCalendar` can be passed a locale name in the
constructor and will return month and weekday names in the specified locale. If
this locale includes an encoding all strings containing month and weekday names
will be returned as unicode.
constructor and will return month and weekday names in the specified
locale. If this locale includes an encoding all strings containing month and
weekday names will be returned as unicode.
.. class:: LocaleHTMLCalendar([firstweekday[, locale]])
This subclass of :class:`HTMLCalendar` can be passed a locale name in the
constructor and will return month and weekday names in the specified locale. If
this locale includes an encoding all strings containing month and weekday names
will be returned as unicode.
constructor and will return month and weekday names in the specified
locale. If this locale includes an encoding all strings containing month and
weekday names will be returned as unicode.
For simple text calendars this module provides the following functions.
......
......@@ -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.
.. 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``.
.. 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.
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.
.. 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
......
......@@ -425,14 +425,14 @@ 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.
......@@ -488,42 +488,43 @@ 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.
.. method:: IncrementalDecoder.getstate()
.. method:: getstate()
Return the current state of the decoder. This must be a tuple with two items,
the first must be the buffer containing the still undecoded input. The second
must be an integer and can be additional state info. (The implementation should
make sure that ``0`` is the most common additional state info.) If this
additional state info is ``0`` it must be possible to set the decoder to the
state which has no input buffered and ``0`` as the additional state info, so
that feeding the previously buffered input to the decoder returns it to the
previous state without producing any output. (Additional state info that is more
complicated than integers can be converted into an integer by
marshaling/pickling the info and encoding the bytes of the resulting string into
an integer.)
Return the current state of the decoder. This must be a tuple with two
items, the first must be the buffer containing the still undecoded
input. The second must be an integer and can be additional state
info. (The implementation should make sure that ``0`` is the most common
additional state info.) If this additional state info is ``0`` it must be
possible to set the decoder to the state which has no input buffered and
``0`` as the additional state info, so that feeding the previously
buffered input to the decoder returns it to the previous state without
producing any output. (Additional state info that is more complicated than
integers can be converted into an integer by marshaling/pickling the info
and encoding the bytes of the resulting string into an integer.)
.. method:: IncrementalDecoder.setstate(state)
.. method:: setstate(state)
Set the state of the encoder to *state*. *state* must be a decoder state
returned by :meth:`getstate`.
The :class:`StreamWriter` and :class:`StreamReader` classes provide generic
working interfaces which can be used to implement new encoding submodules very
easily. See :mod:`encodings.utf_8` for an example of how this is done.
......@@ -570,24 +571,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.
.. method:: StreamWriter.writelines(list)
.. method:: 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:: StreamWriter.reset()
.. method:: reset()
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.
......@@ -630,55 +632,59 @@ 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.
*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.
.. method:: StreamReader.readline([size[, keepends]])
.. method:: readline([size[, keepends]])
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.
.. 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.
.. method:: StreamReader.reset()
.. method:: reset()
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.
......@@ -747,6 +753,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.
......
......@@ -166,60 +166,61 @@ Notes on using :class:`Set` and :class:`MutableSet` as a mixin:
where only the most recent activity is of interest.
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.
.. method:: deque.appendleft(x)
.. method:: appendleft(x)
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.
.. method:: deque.extend(iterable)
.. method:: extend(iterable)
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`.
.. method:: deque.rotate(n)
.. method:: 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:
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
the :keyword:`in` operator, and subscript references such as ``d[-1]``.
......@@ -348,32 +349,34 @@ in Unix::
arguments.
: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 :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.
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:
......
......@@ -209,19 +209,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.
......@@ -1567,22 +1567,24 @@ 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:
: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
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.
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)
.. 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 |
......@@ -1619,8 +1621,8 @@ You can instantiate a :class:`Textbox` object as follows:
| :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 |
......@@ -1636,23 +1638,23 @@ You can instantiate a :class:`Textbox` object as follows:
| :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()
.. 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:: Textbox.stripspaces
.. 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.
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,35 +44,34 @@ 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.
.. method:: clone(fp)
.. method:: Generator.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.
.. 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 the :func:`print` function.
:class:`Generator`'s constructor. This provides just enough file-like API
for :class:`Generator` instances to be used in the :func:`print` function.
As a convenience, see the methods :meth:`Message.as_string` and
``str(aMessage)``, a.k.a. :meth:`Message.__str__`, which simplify the generation
......
......@@ -74,65 +74,66 @@ 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.
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 an instance of :class:`bytes` or :class:`str`. If it is an instance
of :class:`bytes`, 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 an instance of :class:`str`, 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.
: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 an instance of :class:`bytes` or :class:`str`. If it is an
instance of :class:`bytes`, 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 an instance of :class:`str`, 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:`encode` 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)``.
.. method:: Header.__unicode__()
.. method:: __unicode__()
A helper for :class:`str`'s :func:`encode` method. Returns the header as a
Unicode string.
A helper for :class:`str`'s :func:`encode` method. Returns the header as
a Unicode string.
.. method:: __eq__(other)
.. method:: Header.__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:: __ne__(other)
.. method:: Header.__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.
......@@ -65,20 +65,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).
: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
......@@ -111,33 +112,33 @@ class.
effectively non-strict. You should simply stop passing a *strict* flag to
the :class:`Parser` constructor.
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.
.. method:: parsestr(text[, headersonly])
.. method:: Parser.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.
reading the headers or not. The default is ``False``, meaning it parses
the entire contents of the file.
Since creating a message object structure from a string or a file object is such
......
......@@ -66,88 +66,91 @@ The :class:`dircmp` class
'tags']``. *hide* is a list of names to hide, and defaults to ``[os.curdir,
os.pardir]``.
The :class:`dircmp` class provides the following methods:
The :class:`dircmp` class provides the following methods:
.. method:: dircmp.report()
.. method:: report()
Print (to ``sys.stdout``) a comparison between *a* and *b*.
.. method:: dircmp.report_partial_closure()
.. method:: report_partial_closure()
Print a comparison between *a* and *b* and common immediate subdirectories.
Print a comparison between *a* and *b* and common immediate
subdirectories.
.. method:: dircmp.report_full_closure()
.. method:: report_full_closure()
Print a comparison between *a* and *b* and common subdirectories (recursively).
Print a comparison between *a* and *b* and common subdirectories
(recursively).
The :class:`dircmp` offers a number of interesting attributes that may be used
to get various bits of information about the directory trees being compared.
The :class:`dircmp` offers a number of interesting attributes that may be
used to get various bits of information about the directory trees being
compared.
Note that via :meth:`__getattr__` hooks, all attributes are computed lazily, so
there is no speed penalty if only those attributes which are lightweight to
compute are used.
Note that via :meth:`__getattr__` hooks, all attributes are computed lazily,
so there is no speed penalty if only those attributes which are lightweight
to compute are used.
.. attribute:: dircmp.left_list
.. attribute:: left_list
Files and subdirectories in *a*, filtered by *hide* and *ignore*.
.. attribute:: dircmp.right_list
.. attribute:: right_list
Files and subdirectories in *b*, filtered by *hide* and *ignore*.
.. attribute:: dircmp.common
.. attribute:: common
Files and subdirectories in both *a* and *b*.
.. attribute:: dircmp.left_only
.. attribute:: left_only
Files and subdirectories only in *a*.
.. attribute:: dircmp.right_only
.. attribute:: right_only
Files and subdirectories only in *b*.
.. attribute:: dircmp.common_dirs
.. attribute:: common_dirs
Subdirectories in both *a* and *b*.
.. attribute:: dircmp.common_files
.. attribute:: common_files
Files in both *a* and *b*
.. attribute:: dircmp.common_funny
.. attribute:: common_funny
Names in both *a* and *b*, such that the type differs between the directories,
or names for which :func:`os.stat` reports an error.
Names in both *a* and *b*, such that the type differs between the
directories, or names for which :func:`os.stat` reports an error.
.. attribute:: dircmp.same_files
.. attribute:: same_files
Files which are identical in both *a* and *b*.
.. attribute:: dircmp.diff_files
.. attribute:: diff_files
Files which are in both *a* and *b*, whose contents differ.
.. attribute:: dircmp.funny_files
.. attribute:: funny_files
Files which are in both *a* and *b*, but could not be compared.
.. attribute:: dircmp.subdirs
.. attribute:: subdirs
A dictionary mapping names in :attr:`common_dirs` to :class:`dircmp` objects.
......@@ -30,26 +30,24 @@ Rational number class.
:class:`numbers.Rational` and is immutable and hashable.
.. method:: Fraction.from_float(flt)
.. method:: from_float(flt)
This classmethod constructs a :class:`Fraction` representing the
exact value of *flt*, which must be a :class:`float`. Beware that
``Fraction.from_float(0.3)`` is not the same value as ``Rational(3,
10)``
This classmethod constructs a :class:`Fraction` representing the exact
value of *flt*, which must be a :class:`float`. Beware that
``Fraction.from_float(0.3)`` is not the same value as ``Rational(3, 10)``
.. method:: Fraction.from_decimal(dec)
.. method:: from_decimal(dec)
This classmethod constructs a :class:`Fraction` representing the
exact value of *dec*, which must be a
:class:`decimal.Decimal`.
This classmethod constructs a :class:`Fraction` representing the exact
value of *dec*, which must be a :class:`decimal.Decimal`.
.. method:: Fraction.limit_denominator(max_denominator=1000000)
.. method:: limit_denominator(max_denominator=1000000)
Finds and returns the closest :class:`Fraction` to ``self`` that
has denominator at most max_denominator. This method is useful for
finding rational approximations to a given floating-point number:
Finds and returns the closest :class:`Fraction` to ``self`` that has
denominator at most max_denominator. This method is useful for finding
rational approximations to a given floating-point number:
>>> from fractions import Fraction
>>> Fraction('3.1415926535897932').limit_denominator(1000)
......@@ -64,26 +62,26 @@ Rational number class.
Fraction(1L, 2L)
.. method:: Fraction.__floor__()
.. method:: __floor__()
Returns the greatest :class:`int` ``<= self``. Will be accessible
through :func:`math.floor` in Py3k.
Returns the greatest :class:`int` ``<= self``. Will be accessible through
:func:`math.floor` in Py3k.
.. method:: Fraction.__ceil__()
.. method:: __ceil__()
Returns the least :class:`int` ``>= self``. Will be accessible
through :func:`math.ceil` in Py3k.
Returns the least :class:`int` ``>= self``. Will be accessible through
:func:`math.ceil` in Py3k.
.. method:: Fraction.__round__()
Fraction.__round__(ndigits)
.. method:: __round__()
__round__(ndigits)
The first version returns the nearest :class:`int` to ``self``,
rounding half to even. The second version rounds ``self`` to the
nearest multiple of ``Fraction(1, 10**ndigits)`` (logically, if
``ndigits`` is negative), again rounding half toward even. Will be
accessible through :func:`round` in Py3k.
The first version returns the nearest :class:`int` to ``self``, rounding
half to even. The second version rounds ``self`` to the nearest multiple
of ``Fraction(1, 10**ndigits)`` (logically, if ``ndigits`` is negative),
again rounding half toward even. Will be accessible through :func:`round`
in Py3k.
.. seealso::
......
......@@ -47,33 +47,34 @@ The module defines the following items:
or passed as None, the global default timeout setting will be used).
.. data:: all_errors
.. attribute:: all_errors
The set of all exceptions (as a tuple) that methods of :class:`FTP` instances
may raise as a result of problems with the FTP connection (as opposed to
programming errors made by the caller). This set includes the four exceptions
listed below as well as :exc:`socket.error` and :exc:`IOError`.
The set of all exceptions (as a tuple) that methods of :class:`FTP`
instances may raise as a result of problems with the FTP connection (as
opposed to programming errors made by the caller). This set includes the
four exceptions listed below as well as :exc:`socket.error` and
:exc:`IOError`.
.. exception:: error_reply
.. exception:: error_reply
Exception raised when an unexpected reply is received from the server.
.. exception:: error_temp
.. exception:: error_temp
Exception raised when an error code in the range 400--499 is received.
.. exception:: error_perm
.. exception:: error_perm
Exception raised when an error code in the range 500--599 is received.
.. exception:: error_proto
.. exception:: error_proto
Exception raised when a reply is received from the server that does not begin
with a digit in the range 1--5.
Exception raised when a reply is received from the server that does not
begin with a digit in the range 1--5.
.. seealso::
......
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.
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