
    dC                        d dl mZ d dlZd dlZd dlmZ d dlmZ dZ	h dZ
ddddd	d	d
ZdZd Zd Zd Zd Zd Zd ZdS )    )annotationsN)coding)Variablez_.@+- !"#$%&\()*,:;<=>?[]^`{|}~>   intboolbytecharrealuintfloatint64shortdoublestringuint64ushortint32int16int8)r   r   uint32uint16uint8r   utf-8c                    t          | j                  }|t          v rQt          |         }|                     |          }|| k                                    st          d| d|           |} | S )a  Coerce an array to a data type that can be stored in a netCDF-3 file

    This function performs the dtype conversions as specified by the
    ``_nc3_dtype_coercions`` mapping:
        int64  -> int32
        uint64 -> int32
        uint32 -> int32
        uint16 -> int16
        uint8  -> int8
        bool   -> int8

    Data is checked for equality, or equivalence (non-NaN values) using the
    ``(cast_array == original_array).all()``.
    z'could not safely cast array from dtype z to )strdtype_nc3_dtype_coercionsastypeall
ValueError)arrr   	new_dtypecast_arrs       7lib/python3.11/site-packages/xarray/backends/netcdf3.pycoerce_nc3_dtyper%   /   s     	NNE$$$(/	::i((C$$&& 	P%PPYPP   J    c                   t          | t                    rnkt          | t                    r|                     t                    } n;t          t          j        |                     } | j        dk    rt          d          | S )N   z'netCDF attributes must be 1-dimensional)

isinstancebytesr   encodeSTRING_ENCODINGr%   np
atleast_1dndimr    )values    r$   encode_nc3_attr_valuer1   K   st    % H	E3		 H_-- u!5!566:>>FGGGLr&   c                >    d |                                  D             S )Nc                4    i | ]\  }}|t          |          S  )r1   ).0kvs      r$   
<dictcomp>z$encode_nc3_attrs.<locals>.<dictcomp>X   s'    BBBDAqA$Q''BBBr&   )items)attrss    r$   encode_nc3_attrsr;   W   s    BBEKKMMBBBBr&   c                6   t           j                            d          t           j                                        fD ]}|                    |           } t          | j                  }t          | j                  }t          | j
        ||| j                  S )NF)allows_unicode)r   stringsEncodedStringCoderCharacterArrayCoderr+   r%   datar;   r:   r   dimsencoding)varcoderrA   r:   s       r$   encode_nc3_variablerF   [   s    )))??**,,     ll3CH%%DSY''ECHdE3<888r&   c                v    |                                  p%t          |                     d                    dk    S )zrReturn True if the given UTF-8 encoded character is alphanumeric
    or multibyte.

    Input is not checked!
    r   r(   )isalnumlenr+   )cs    r$   _isalnumMUTF8rK   f   s0     99;;63qxx0011A56r&   c                X   t          | t                    sdS t          |                     d                    }t	          j        d|           | k    oX| t          voO|dk    oId| voE| d         dk    o9t          | d                   p| d         dk    ot          d	 | D                       S )
ar  Test whether an object can be validly converted to a netCDF-3
    dimension, variable or attribute name

    Earlier versions of the netCDF C-library reference implementation
    enforced a more restricted set of characters in creating new names,
    but permitted reading names containing arbitrary bytes. This
    specification extends the permitted characters in names to include
    multi-byte UTF-8 encoded Unicode and additional printing characters
    from the US-ASCII alphabet. The first character of a name must be
    alphanumeric, a multi-byte UTF-8 character, or '_' (reserved for
    special names with meaning to implementations, such as the
    "_FillValue" attribute). Subsequent characters may also include
    printing special characters, except for '/' which is not allowed in
    names. Names that have trailing space characters are also not
    permitted.
    Fr   NFCr   / _c              3  F   K   | ]}t          |          p|t          v V  d S )N)rK   _specialchars)r5   rJ   s     r$   	<genexpr>z$is_valid_nc3_name.<locals>.<genexpr>   s4      BB1a  6A$6BBBBBBr&   )	r)   r   rI   r+   unicodedata	normalize_reserved_namesrK   r   )s	num_bytess     r$   is_valid_nc3_namerZ   o   s    " a uAHHW%%&&I		ua	(	(A	- 	Co%	C!^	C \	C rUc\		C
 1Q4  1QqTS[	C BBBBBBBr&   )
__future__r   rU   numpyr-   xarrayr   xarray.core.variabler   rS   rW   r   r,   r%   r1   r;   rF   rK   rZ   r4   r&   r$   <module>r_      s    " " " " " "               ) ) ) ) ) ) 3  &      8	 	 	C C C9 9 97 7 7    r&   