docs: def export(gandi, resource, output, force, intermediate):
      """ Write the certificate to <output> or <fqdn>.crt.
  
      Resource can be a CN or an ID
      """
      ids = []
      for res in resource:
          ids.extend(gandi.certificate.usable_ids(res))
  
      if output and len(ids) > 1:
          gandi.echo('Too many certs found, you must specify which cert you '
                     'want to export')
          return
  
      for id_ in set(ids):
          cert = gandi.certificate.info(id_)
          if 'cert' not in cert:
              continue
  
          if cert['status'] != 'valid':
              gandi.echo('The certificate must be in valid status to be '
                         'exported (%s).' % id_)
              continue
  
          cert_filename = cert['cn'].replace('*.', 'wildcard.', 1)
          crt_filename = output or cert_filename + '.crt'
          if not force and os.path.isfile(crt_filename):
              gandi.echo('The file %s already exists.' % crt_filename)
              continue
  
          crt = gandi.certificate.pretty_format_cert(cert)
          if crt:
              with open(crt_filename, 'w') as crt_file:
                  crt_file.write(crt)
                  gandi.echo('wrote %s' % crt_filename)
  
          package = cert['package']
          if 'bus' in package and intermediate:
              gandi.echo('Business certs do not need intermediates.')
          elif intermediate:
              crtf = 'pem'
              sha_version = cert['sha_version']
              type_ = package.split('_')[1]
              extra = ('sgc' if 'SGC' in package
                       and 'pro' in package
                       and sha_version == 1 else 'default')
  
              if extra == 'sgc':
                  crtf = 'pem'
  
              inters = gandi.certificate.urls[sha_version][type_][extra][crtf]
              if isinstance(inters, basestring):
                  inters = [inters]
  
              fhandle = open(cert_filename + '.inter.crt', 'w+b')
              for inter in inters:
                  if inter.startswith('http'):
                      data = requests.get(inter).text
                  else:
                      data = inter
                  fhandle.write(data.encode('latin1'))
  
              gandi.echo('wrote %s' % cert_filename + '.inter.crt')
              fhandle.close()
  
          return crt