
    IR-e                     ,    d dl mZ  G d d          ZdS )   )utilsc                        e Zd ZdZi ZdZdZd Z fdZe	d             Z
e	dd            Ze	d             Ze	dd
            Ze	d             Ze	ddd            Ze	ddd            Ze	d             Z xZS )Basez6
    The abstract base class of all unit formats.
     c                     | S N )clsargskwargss      9lib/python3.11/site-packages/astropy/units/format/base.py__new__zBase.__new__   s	     
    c                     d| j         vr| j                                        | _        | t          j        | j        <    t                      j        di | d S )Nnamer	   )__dict____name__lowerr   r   registrysuper__init_subclass__)r
   r   	__class__s     r   r   zBase.__init_subclass__   sX     %%|))++CH"%ch!!++F+++++r   c                 6    |                     | j                  S r   )get_format_namer   )r
   units     r   _get_unit_namezBase._get_unit_name   s    ##CH---r   gc                 "    t          ||          S )ap  
        Formats a value in exponential notation.

        Parameters
        ----------
        val : number
            The value to be formatted

        format_spec : str, optional
            Format used to split up mantissa and exponent

        Returns
        -------
        str
            The value in exponential notation in a this class's format.
        )format)r
   valformat_specs      r   format_exponential_notationz Base.format_exponential_notation!   s    $ c;'''r   c                 "    d|v sd|v rd| dn|S )N/.()r	   )r
   numbers     r   _format_superscriptzBase._format_superscript5   s$     #v}6}}}}FJr   r   c                     |                      |          }|dk    r*||                     t          j        |                    z  }|S )zFormat the unit for this format class raised to the given power.

        This is overridden in Latex where the name of the unit can depend on the power
        (e.g., for degrees).
        r   )r   r)   r   format_power)r
   r   powerr   s       r   _format_unit_powerzBase._format_unit_power9   sH     !!$''A::C++E,>u,E,EFFFDr   c                 P      j                              fd|D                       S )Nc              3   J   K   | ]\  }}                     ||          V  d S r   )r-   ).0base_r,   r
   s      r   	<genexpr>z)Base._format_unit_list.<locals>.<genexpr>G   sH       
 
5AUEC""5%00
 
 
 
 
 
r   )_spacejoin)r
   unitss   ` r   _format_unit_listzBase._format_unit_listE   sA    z 
 
 
 
EJ
 
 
 
 
 	
r   inlinefractionc                    |du s|dk    st          d|d          | j        |v rd| d}|r|dk    r| d| S | | d	| S )
NTr7   z@format {cls.name!r} only supports inline fractions,not fraction=r%   r&   r'   1z/ z / )
ValueErrorr3   )r
   scale	numeratordenominatorr9   s        r   _format_fractionzBase._format_fractionK   s    D  H$8$8. (. . .  
 :$$,k,,,K 	-Y#%%,,{,,,444{444r   Tc                ,   |j         dk    rd}n|                     |j                   }t          |j                  r|r
|| j        z  }|r#t          j        |j        |j                  \  }}n)t          t          |j        |j                            }g }t          |          rVt          |          r| 
                    |          }nd}| 
                    |          }|                     ||||          }n|| 
                    |          z  }|S )a  Convert a unit to its string representation.

        Implementation for `~astropy.units.UnitBase.to_string`.

        Parameters
        ----------
        unit : |Unit|
            The unit to convert.
        fraction : {False|True|'inline'|'multiline'}, optional
            Options are as follows:

            - `False` : display unit bases with negative powers as they are
              (e.g., ``km s-1``);
            - 'inline' or `True` : use a single-line fraction (e.g., ``km / s``);
            - 'multiline' : use a multiline fraction (available for the
              ``latex``, ``console`` and ``unicode`` formats only; e.g.,
              ``$\mathrm{\frac{km}{s}}$``).

        Raises
        ------
        ValueError
            If ``fraction`` is not recognized.
        r    r;   r8   )r=   r"   lenbases_scale_unit_separatorr   get_grouped_by_powerspowerslistzipr6   r@   )r
   r   r9   sr>   r?   s         r   	to_stringzBase.to_stringY   s$   8 :??AA//
;;A tz?? 	6 /S.. !).)DJ* *&	;; !TZ!=!=>>	 ; 6y>> $ # 5 5i @ @II #I!33K@@((I{X(VVS**9555r   c                 2    t          d| j         d          )z4
        Convert a string to a unit object.
        zCan not parse with z format)NotImplementedErrorr   )r
   rJ   s     r   parsez
Base.parse   s     
 ""M"M"M"MNNNr   )r   )r   )r   
__module____qualname____doc__r   r3   rE   r   r   classmethodr   r"   r)   r-   r6   r@   rK   rN   __classcell__)r   s   @r   r   r      sj         HF  , , , , , . . [. ( ( ( [(& K K [K 	 	 	 [	 
 
 [

 IQ 5 5 5 5 [5 )- 6 6 6 6 [6p O O [O O O O Or   r   N)rB   r   r   r	   r   r   <module>rT      s]         RO RO RO RO RO RO RO RO RO ROr   