
    hD                         d Z ddlZ	 ddlmZ ddlZddlZ G d dej                        Z
ddZddZy# e$ r	 ddlmZ Y 3w xY w)	ag  
Toolkit for exporting descriptors to other formats.

**Module Overview:**

::

  export_csv - Exports descriptors to a CSV
  export_csv_file - Writes exported CSV output to a file

.. deprecated:: 1.7.0

   This module will likely be removed in Stem 2.0 due to lack of usage. If you
   use this modle please `let me know <https://www.atagar.com/contact/>`_.
    N)StringIOc                       e Zd ZdZy)_ExportDialect
N)__name__
__module____qualname__lineterminator     `/var/www/betterdocs.net/sherlock_api/venv/lib/python3.12/site-packages/stem/descriptor/export.pyr   r      s    .r   r   c                 T    t               }t        || |||       |j                         S )a\  
  Provides a newline separated CSV for one or more descriptors. If simply
  provided with descriptors then the CSV contains all of its attributes,
  labeled with a header row. Either 'included_fields' or 'excluded_fields' can
  be used for more granular control over its attributes and the order.

  :param Descriptor,list descriptors: either a
    :class:`~stem.descriptor.Descriptor` or list of descriptors to be exported
  :param list included_fields: attributes to include in the csv
  :param list excluded_fields: attributes to exclude from the csv
  :param bool header: if **True** then the first line will be a comma separated
    list of the attribute names (**only supported in python 2.7 and higher**)

  :returns: **str** of the CSV for the descriptors, one per line
  :raises: **ValueError** if descriptors contain more than one descriptor type
  )r   export_csv_filegetvalue)descriptorsincluded_fieldsexcluded_fieldsheaderoutput_buffers        r   
export_csvr   #   s+    $ *--oPVW				!!r   c           
         t        |t        j                  j                        r|f}|syt	        |d         }|j
                  }t        |      }t        t        |d         j                               }|r.|D ](  }||vst        |d|ddj                  |             n!|D 	cg c]  }	|	j                  d      r|	 }}	|D ]  }	 |j                  |        t        j                  | |t!               d      }
|r.t        j"                  j%                         s|
j'                          |D ]  }t        |t        j                  j                        s!t        d	t	        |      j
                  z        |t	        |      k7  rt        d
|dt	        |      d      |
j)                  t        |              yc c}	w # t        $ r Y 	w xY w)a  
  Similar to :func:`stem.descriptor.export.export_csv`, except that the CSV is
  written directly to a file.

  :param file output_file: file to be written to
  :param Descriptor,list descriptors: either a
    :class:`~stem.descriptor.Descriptor` or list of descriptors to be exported
  :param list included_fields: attributes to include in the csv
  :param list excluded_fields: attributes to exclude from the csv
  :param bool header: if **True** then the first line will be a comma separated
    list of the attribute names (**only supported in python 2.7 and higher**)

  :returns: **str** of the CSV for the descriptors, one per line
  :raises: **ValueError** if descriptors contain more than one descriptor type
  Nr   z does not have a 'z' attribute, valid fields are: z, _ignore)dialectextrasactionz?Unable to export a descriptor CSV since %s is not a descriptor.zcTo export a descriptor CSV all of the descriptors must be of the same type. First descriptor was a z but we later got a .)
isinstancestem
descriptor
Descriptortyper   listsortedvarskeys
ValueErrorjoin
startswithremovecsv
DictWriterr   prereq_is_python_26writeheaderwriterow)output_filer   r   r   r   descriptor_typedescriptor_type_label	desc_attrfieldattrwriterdescs               r   r   r   :   s   " T__778.K	
Q(/)22)/ T+a.)..01)  K	i	Vkmrtxt}t}  H  uI  J  K  	KK )2N9MtNON eU# >>+.BRaij&DKK--/
  ddDOO667X[_`d[e[n[nnoo	DJ	&  Zo  qu  vz  q{  |  }  }
OODJ  O
  
s   )G  G G	GG)r   r   T)__doc__r*   	cStringIOr   ImportErroriostem.descriptorr   stem.prereqexcelr   r   r   r   r   r   <module>r?      sN        SYY ".9 E  s   4 AA