Back to module index
Go to module by name
email
email.generator
Classes to generate plain text from a message object tree.
Classes
BytesGenerator
Generates a bytes version of a Message object tree.
Functionally identical to the base Generator except that the output is
bytes and not string. When surrogates were used in the input to encode
bytes, these are decoded back to bytes for output. If the policy has
cte_type set to 7bit, then the message is transformed such that the
non-ASCII bytes are properly content transfer encoded, using the charset
unknown-8bit.
The outfp object must accept bytes in its write method.
clone(self, fp)
Clone this generator with the exact same options.
flatten(self, msg, unixfrom=False, linesep=None)
Print the message object tree rooted at msg to the output file
specified when the Generator instance was created.
unixfrom is a flag that forces the printing of a Unix From_ delimiter
before the first object in the message tree. If the original message
has no From_ delimiter, a `standard' one is crafted. By default, this
is False to inhibit the printing of any From_ delimiter.
Note that for subobjects, no From_ line is printed.
linesep specifies the characters used to indicate a new line in
the output. The default value is determined by the policy specified
when the Generator instance was created or, if none was specified,
from the policy associated with the msg.
write(self, s)
BytesIO
Buffered I/O implementation using an in-memory bytes buffer.
close(self, /)
Disable all I/O operations.
detach(self, /)
Disconnect this buffer from its underlying raw stream and return it.
After the raw stream has been detached, the buffer is in an unusable
state.
fileno(self, /)
Returns underlying file descriptor if one exists.
OSError is raised if the IO object does not use a file descriptor.
flush(self, /)
Does nothing.
getbuffer(self, /)
Get a read-write view over the contents of the BytesIO object.
getvalue(self, /)
Retrieve the entire contents of the BytesIO object.
isatty(self, /)
Always returns False.
BytesIO objects are not connected to a TTY-like device.
read(self, size=-1, /)
Read at most size bytes, returned as a bytes object.
If the size argument is negative, read until EOF is reached.
Return an empty bytes object at EOF.
read1(self, size=-1, /)
Read at most size bytes, returned as a bytes object.
If the size argument is negative or omitted, read until EOF is reached.
Return an empty bytes object at EOF.
readable(self, /)
Returns True if the IO object can be read.
readinto(self, buffer, /)
Read bytes into buffer.
Returns number of bytes read (0 for EOF), or None if the object
is set not to block and has no data to read.
readinto1(self, buffer, /)
readline(self, size=-1, /)
Next line from the file, as a bytes object.
Retain newline. A non-negative size argument limits the maximum
number of bytes to return (an incomplete line may be returned then).
Return an empty bytes object at EOF.
readlines(self, size=None, /)
List of bytes objects, each a line from the file.
Call readline() repeatedly and return a list of the lines so read.
The optional size argument, if given, is an approximate bound on the
total number of bytes in the lines returned.
seek(self, pos, whence=0, /)
Change stream position.
Seek to byte offset pos relative to position indicated by whence:
0 Start of stream (the default). pos should be >= 0;
1 Current position - pos may be negative;
2 End of stream - pos usually negative.
Returns the new absolute position.
seekable(self, /)
Returns True if the IO object can be seeked.
tell(self, /)
Current file position, an integer.
truncate(self, size=None, /)
Truncate the file to at most size bytes.
Size defaults to the current file position, as returned by tell().
The current file position is unchanged. Returns the new size.
writable(self, /)
Returns True if the IO object can be written.
write(self, b, /)
Write bytes to file.
Return the number of bytes written.
writelines(self, lines, /)
Write lines to the file.
Note that newlines are not added. lines can be any iterable object
producing bytes-like objects. This is equivalent to calling write() for
each element.
closed = <attribute 'closed' of '_io.BytesIO' objects>
True if the file is closed.
DecodedGenerator
Generates a text representation of a message.
Like the Generator base class, except that non-text parts are substituted
with a format string representing the part.
clone(self, fp)
Clone this generator with the exact same options.
flatten(self, msg, unixfrom=False, linesep=None)
Print the message object tree rooted at msg to the output file
specified when the Generator instance was created.
unixfrom is a flag that forces the printing of a Unix From_ delimiter
before the first object in the message tree. If the original message
has no From_ delimiter, a `standard' one is crafted. By default, this
is False to inhibit the printing of any From_ delimiter.
Note that for subobjects, no From_ line is printed.
linesep specifies the characters used to indicate a new line in
the output. The default value is determined by the policy specified
when the Generator instance was created or, if none was specified,
from the policy associated with the msg.
write(self, s)
Generator
Generates output from a Message object tree.
This basic generator writes the message to the given file object as plain
text.
clone(self, fp)
Clone this generator with the exact same options.
flatten(self, msg, unixfrom=False, linesep=None)
Print the message object tree rooted at msg to the output file
specified when the Generator instance was created.
unixfrom is a flag that forces the printing of a Unix From_ delimiter
before the first object in the message tree. If the original message
has no From_ delimiter, a `standard' one is crafted. By default, this
is False to inhibit the printing of any From_ delimiter.
Note that for subobjects, no From_ line is printed.
linesep specifies the characters used to indicate a new line in
the output. The default value is determined by the policy specified
when the Generator instance was created or, if none was specified,
from the policy associated with the msg.
write(self, s)
StringIO
Text I/O implementation using an in-memory buffer.
The initial_value argument sets the value of object. The newline
argument is like the one of TextIOWrapper's constructor.
close(self, /)
Close the IO object.
Attempting any further operation after the object is closed
will raise a ValueError.
This method has no effect if the file is already closed.
detach(...)
Separate the underlying buffer from the TextIOBase and return it.
After the underlying buffer has been detached, the TextIO is in an
unusable state.
fileno(self, /)
Returns underlying file descriptor if one exists.
OSError is raised if the IO object does not use a file descriptor.
flush(self, /)
Flush write buffers, if applicable.
This is not implemented for read-only and non-blocking streams.
getvalue(self, /)
Retrieve the entire contents of the object.
isatty(self, /)
Return whether this is an 'interactive' stream.
Return False if it can't be determined.
read(self, size=-1, /)
Read at most size characters, returned as a string.
If the argument is negative or omitted, read until EOF
is reached. Return an empty string at EOF.
readable(self, /)
Returns True if the IO object can be read.
readline(self, size=-1, /)
Read until newline or EOF.
Returns an empty string if EOF is hit immediately.
readlines(self, hint=-1, /)
Return a list of lines from the stream.
hint can be specified to control the number of lines read: no more
lines will be read if the total size (in bytes/characters) of all
lines so far exceeds hint.
seek(self, pos, whence=0, /)
Change stream position.
Seek to character offset pos relative to position indicated by whence:
0 Start of stream (the default). pos should be >= 0;
1 Current position - pos must be 0;
2 End of stream - pos must be 0.
Returns the new absolute position.
seekable(self, /)
Returns True if the IO object can be seeked.
tell(self, /)
Tell the current file position.
truncate(self, pos=None, /)
Truncate size to pos.
The pos argument defaults to the current file position, as
returned by tell(). The current file position is unchanged.
Returns the new absolute position.
writable(self, /)
Returns True if the IO object can be written.
write(self, s, /)
Write string to file.
Returns the number of characters written, which is always equal to
the length of the string.
writelines(self, lines, /)
Write a list of lines to stream.
Line separators are not added, so it is usual for each of the
lines provided to have a line separator at the end.
closed = <attribute 'closed' of '_io.StringIO' objects>
encoding = <attribute 'encoding' of '_io._TextIOBase' objects>
Encoding of the text stream.
Subclasses should override.
errors = <attribute 'errors' of '_io._TextIOBase' objects>
The error setting of the decoder or encoder.
Subclasses should override.
line_buffering = <attribute 'line_buffering' of '_io.StringIO' objects>
newlines = <attribute 'newlines' of '_io.StringIO' objects>
Functions
deepcopy
deepcopy(x, memo=None, _nil=[])
Deep copy operation on arbitrary Python objects.
See the module's __doc__ string for more info.
Other members
NL = '\n'
NLCRE = re.compile('\\r\\n|\\r|\\n')
UNDERSCORE = '_'
fcre = re.compile('^From ', re.MULTILINE)
Modules
random
re
sys
time