parameters: (in_file, out_file, name=None, mode=None, *, backtick=False)
docstring: Uuencode file
docstring_summary: Uuencode file
docstring_tokens: Uuencode file
function: def encode(in_file, out_file, name=None, mode=None, *, backtick=False):
      """Uuencode file"""
      #
      # If in_file is a pathname open it and change defaults
      #
      opened_files = []
      try:
          if in_file == '-':
              in_file = sys.stdin.buffer
          elif isinstance(in_file, str):
              if name is None:
                  name = os.path.basename(in_file)
              if mode is None:
                  try:
                      mode = os.stat(in_file).st_mode
                  except AttributeError:
                      pass
              in_file = open(in_file, 'rb')
              opened_files.append(in_file)
          #
          # Open out_file if it is a pathname
          #
          if out_file == '-':
              out_file = sys.stdout.buffer
          elif isinstance(out_file, str):
              out_file = open(out_file, 'wb')
              opened_files.append(out_file)
          #
          # Set defaults for name and mode
          #
          if name is None:
              name = '-'
          if mode is None:
              mode = 0o666
  
          #
          # Remove newline chars from name
          #
          name = name.replace('\n','\\n')
          name = name.replace('\r','\\r')
  
          #
          # Write the data
          #
          out_file.write(('begin %o %s\n' % ((mode & 0o777), name)).encode("ascii"))
          data = in_file.read(45)
          while len(data) > 0:
              out_file.write(binascii.b2a_uu(data, backtick=backtick))
              data = in_file.read(45)
          if backtick:
              out_file.write(b'`\nend\n')
          else:
              out_file.write(b' \nend\n')
      finally:
          for f in opened_files:
              f.close()
function_tokens: def encode ( in_file , out_file , name = None , mode = None , * , backtick = False ) : # # If in_file is a pathname open it and change defaults # opened_files = [ ] try : if in_file == '-' : in_file = sys . stdin . buffer elif isinstance ( in_file , str ) : if name is None : name = os . path . basename ( in_file ) if mode is None : try : mode = os . stat ( in_file ) . st_mode except AttributeError : pass in_file = open ( in_file , 'rb' ) opened_files . append ( in_file ) # # Open out_file if it is a pathname # if out_file == '-' : out_file = sys . stdout . buffer elif isinstance ( out_file , str ) : out_file = open ( out_file , 'wb' ) opened_files . append ( out_file ) # # Set defaults for name and mode # if name is None : name = '-' if mode is None : mode = 0o666 # # Remove newline chars from name # name = name . replace ( '\n' , '\\n' ) name = name . replace ( '\r' , '\\r' ) # # Write the data # out_file . write ( ( 'begin %o %s\n' % ( ( mode & 0o777 ) , name ) ) . encode ( "ascii" ) ) data = in_file . read ( 45 ) while len ( data ) > 0 : out_file . write ( binascii . b2a_uu ( data , backtick = backtick ) ) data = in_file . read ( 45 ) if backtick : out_file . write ( b'`\nend\n' ) else : out_file . write ( b' \nend\n' ) finally : for f in opened_files : f . close ( )