class_docstr: 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: True.
  
  message_factory     -- the class to use to create new message objects.
                         If the value is None, the default is Message.
docstr: Based on policy, either raise defect or call register_defect.
  
      handle_defect(obj, defect)
  
  defect should be a Defect subclass, but in any case must be an
  Exception subclass.  obj is the object on which the defect should be
  registered if it is not raised.  If the raise_on_defect is True, the
  defect is raised as an error, otherwise the object and the defect are
  passed to register_defect.
  
  This method is intended to be called by parsers that discover defects.
  The email package parsers always call it with Defect instances.
docstr_tok: ["Based","on","policy",",","either","raise","defect","or","call","register_defect",".","handle_defect","(","obj",",","defect",")","defect","should","be","a","Defect","subclass",",","but","in","any","case","must","be","an","Exception","subclass",".","obj","is","the","object","on","which","the","defect","should","be","registered","if","it","is","not","raised",".","If","the","raise_on_defect","is","True",",","the","defect","is","raised","as","an","error",",","otherwise","the","object","and","the","defect","are","passed","to","register_defect",".","This","method","is","intended","to","be","called","by","parsers","that","discover","defects",".","The","email","package","parsers","always","call","it","with","Defect","instances","."]
code: def handle_defect(self, obj, defect):
      """Based on policy, either raise defect or call register_defect.
  
          handle_defect(obj, defect)
  
      defect should be a Defect subclass, but in any case must be an
      Exception subclass.  obj is the object on which the defect should be
      registered if it is not raised.  If the raise_on_defect is True, the
      defect is raised as an error, otherwise the object and the defect are
      passed to register_defect.
  
      This method is intended to be called by parsers that discover defects.
      The email package parsers always call it with Defect instances.
  
      """
      if self.raise_on_defect:
          raise defect
      self.register_defect(obj, defect)
  
imports: import abc
  from email import header
  from email import charset
  from email.utils import _has_surrogates
label_desc: Use image node_id 1 for calling the Policy obj's underlying member method code with example usage: obj.handle_defect(obj, defect) without return types