class_docstr: Python implementation of a format encoder. Override this class and
  add the decoding logic in the :meth:`encode` method.
  
  See :ref:`Writing Your Own File Codec in Python<file-codecs-py>`
class_docstr_tok: ["Python","implementation","of","a","format","encoder",".","Override","this","class","and","add","the","decoding","logic","in","the",":","meth",":","`","encode","`","method",".","See",":","ref",":","`","Writing","Your","Own","File","Codec","in","Python","<","file-codecs-py",">","`"]
docstr: If ``pushes_fd`` is ``True``, then this method will be used,
  and ``encode()`` will only be called once.
  
  :returns: A tuple of ``(bytes consumed, errcode)``.
      Err codes are from :data:`.ImageFile.ERRORS`.
docstr_tok: ["If","``","pushes_fd","``","is","``","True","``",",","then","this","method","will","be","used",",","and","``","encode","(",")","``","will","only","be","called","once",".",":","returns",":","A","tuple","of","``","(","bytes","consumed",",","errcode",")","``",".","Err","codes","are","from",":","data",":","`",".ImageFile.ERRORS","`","."]
code: def encode_to_pyfd(self):
      """
      If ``pushes_fd`` is ``True``, then this method will be used,
      and ``encode()`` will only be called once.
  
      :returns: A tuple of ``(bytes consumed, errcode)``.
          Err codes are from :data:`.ImageFile.ERRORS`.
      """
      if not self.pushes_fd:
          return 0, -8  # bad configuration
      bytes_consumed, errcode, data = self.encode(0)
      if data:
          self.fd.write(data)
      return bytes_consumed, errcode
  
imports: from __future__ import annotations
  import io
  import itertools
  import struct
  import sys
  from typing import Any, NamedTuple
  from .None import Image
  from ._deprecate import deprecate
  from ._util import is_path
label_desc: Use image node_id 3 for calling the PyEncoder obj's underlying member method code with example usage: obj.encode_to_pyfd() and returns: bytes_consumed,  errcode, int,  unknown