PyDocs

Nav

Internet Data Handling

Policy

  • Policy(**kw)
Controls for how messages are interpreted and formatted.

Most of the classes and many of the methods in the email package accept
Policy objects as parameters.  A Policy object contains a set of values and
functions that control how input is interpreted and how output is rendered.
For example, the parameter 'raise_on_defect' controls whether or not an RFC
violation results in an error being raised or not, while 'max_line_length'
controls the maximum length of output lines when a Message is serialized.

Any valid attribute may be overridden when a Policy is created by passing
it as a keyword argument to the constructor.  Policy objects are immutable,
but a new Policy object can be created with only certain values changed by
calling the Policy instance with keyword arguments.  Policy objects can
also be added, producing a new Policy object in which the non-default
attributes set in the right hand operand overwrite those specified in the
left operand.

Settable attributes:

raise_on_defect     -- If true, then defects should be raised as errors.
                       Default: False.

linesep             -- string containing the value to use as separation
                       between output lines.  Default '\n'.

cte_type            -- Type of allowed content transfer encodings

                       7bit  -- ASCII only
                       8bit  -- Content-Transfer-Encoding: 8bit is allowed

                       Default: 8bit.  Also controls the disposition of
                       (RFC invalid) binary data in headers; see the
                       documentation of the binary_fold method.

max_line_length     -- maximum length of lines, excluding 'linesep',
                       during serialization.  None or 0 means no line
                       wrapping is done.  Default is 78.

mangle_from_        -- a flag that, when True escapes From_ lines in the
                       body of the message by putting a '>' in front of
                       them. This is used when the message is being
                       serialized by a generator. Default: False.

message_factory     -- the class to use to create new message objects.
                       If the value is None, the default is Message.

verify_generated_headers
                    -- if true, the generator verifies that each header
                       they are properly folded, so that a parser won't
                       treat it as multiple headers, start-of-body, or
                       part of another header.
                       This is a check against custom Header & fold()
                       implementations.
Members of Policy

c

clone
Return a new instance with specified attributes changed.
cte_type
Controls the type of Content Transfer Encodings that may be or are required to be used.

f

fold
Given the header name and the value from the model, return a string containing linesep characters that implement the folding of the header according to the policy controls.
fold_binary
Given the header name and the value from the model, return binary data containing linesep characters that implement the folding of the header according to the policy controls.

h

handle_defect
Based on policy, either raise defect or call register_defect.
header_fetch_parse
Given the header name and the value from the model, return the value to be returned to the application program that is requesting that header.
header_max_count
Return the maximum allowed number of headers named 'name'.
header_source_parse
Given a list of linesep terminated strings constituting the lines of a single header, return the (name, value) tuple that should be stored in the model.
header_store_parse
Given the header name and the value provided by the application program, return the (name, value) that should be stored in the model.

l

linesep
The string to be used to terminate lines in serialized output.

m

mangle_from_
If True, lines starting with “From “ in the body are escaped by putting a > in front of them.
max_line_length
The maximum length of any line in the serialized output, not counting the end of line character(s).
message_factory
A factory function for constructing a new empty message object.

r

raise_on_defect
If True, any defects encountered will be raised as errors.
register_defect
Record 'defect' on 'obj'.

v

verify_generated_headers
If True (the default), the generator will raise HeaderWriteError instead of writing a header that is improperly folded or delimited, such that it would be parsed as multiple headers or joined with ad…
0 Examples
No examples for email.policy/Policy.
See Also
No see-alsos for email.policy/Policy
0 Notes
No notes for Policy