o
    i                     @   s   d dl mZmZ d dlmZ d dlmZ d dlZd dlZej	dd dkr,d dl
mZ nd dlmZ ej	d  dkr;eZd	d
 Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd ZdddZdS )    )CommentedSeqCommentedMap)
exceptions)compileN   )      )Iterabler   c                 c   sD    | D ]}t |trt |ttfst|D ]}|V  qq|V  qdS )z}
    Yield items from any nested iterable.

    >>> list(flatten([[1, 2, 3], [[4, 5], 6, 7]]))
    [1, 2, 3, 4, 5, 6, 7]
    N)
isinstancer	   strbytesflatten)itemsxsub_x r   N/home/ubuntu/transcripts/venv/lib/python3.10/site-packages/strictyaml/utils.pyr      s   r   c                 C   s   t | tttjfot | t S )a  
    Is a value a number or a non-number?

    >>> has_number_type(3.5)
    True

    >>> has_number_type(3)
    True

    >>> has_number_type(decimal.Decimal("3.5"))
    True

    >>> has_number_type("3.5")
    False

    >>> has_number_type(True)
    False
    )r
   intfloatdecimalDecimalboolvaluer   r   r   has_number_type   s   r   c                 C   s   t | tptt| dv S )zG
    Python 2/3 compatible way of checking if a value is a string.
    )z<type 'unicode'>z<type 'str'>z<class 'str'>)r
   unicoder   typer   r   r   r   	is_string7   s   r   c                 C      t d| duS )z
    Is a string a string of an integer?

    >>> is_integer("4")
    True

    >>> is_integer("4_000")
    True

    >>> is_integer("3.4")
    False
    z^[-+]?[0-9_]+$Nr   matchr   r   r   r   
is_integerB   s   r!   c                 C   r   )a-  
    Is a string a string of a hexademcial integer?

    >>> is_hexadecimal("0xa1")
    True

    >>> is_hexadecimal("0XA1")
    True

    >>> is_hexadecimal("0xa1x")
    False

    >>> is_hexadecimal("xa1")
    False

    >>> is_hexadecimal("a1")
    False

    >>> is_hexadecimal("1")
    False
    z^0[xX]+[a-fA-F0-9]+$Nr   r   r   r   r   is_hexadecimalR   s   r"   c                 C   r   )z
    Is a string a decimal?

    >>> is_decimal("4")
    True

    >>> is_decimal("4_000")
    True

    >>> is_decimal("3.5")
    True

    >>> is_decimal("4.")
    True

    >>> is_decimal("4.000_001")
    True

    >>> is_decimal("blah")
    False
    z-^[-+]?[0-9_]*(\.[0-9_]*)?([eE][-+]?[0-9_]+)?$Nr   r   r   r   r   
is_decimalk   s   r#   c                 C   r   )a  
    Is string a valid representation for positive or negative infinity?

    Valid formats are:
    [+/-]inf, [+/-]INF, [+/-]Inf, [+/-].inf, [+/-].INF and [+/-].Inf

    >>> is_infinity(".inf")
    True

    >>> is_infinity("+.INF")
    True

    >>> is_infinity("-.Inf")
    True

    >>> is_infinity("Inf")
    True

    >>> is_infinity("INF")
    True

    >>> is_infinity("-INF")
    True

    >>> is_infinity("infinitesimal")
    False
    z^[-+]?\.?(?:inf|Inf|INF)$Nr   r   r   r   r   is_infinity   s   r$   c                 C   r   )as  
    Is string a valid representation for 'not a number'?

    Valid formats are: nan, NaN, NAN, .nan, .NaN, .NAN.

    >>> is_not_a_number(".nan")
    True

    >>> is_not_a_number(".NaN")
    True

    >>> is_not_a_number("NAN")
    True

    >>> is_not_a_number("nan")
    True

    >>> is_not_a_number("nanan")
    False

    >>> is_not_a_number("1e5")
    False
    z^\.?(?:nan|NaN|NAN)$Nr   r   r   r   r   is_not_a_number   s   r%   c                 C   sv   g }d}d}|  dD ]-}|d dkrdnd}||7 }|t| | 7 }|||f |t| d 7 }|}q|S )z
    Start and end positions of comma separated text items.

    Commas and trailing spaces should not be included.

    >>> comma_separated_positions("ABC, 2,3")
    [(0, 3), (5, 6), (7, 8)]
    r   ,    )splitlenlstripappend)textchunksstartenditemspace_incrementr   r   r   comma_separated_positions   s   	r3   c                 C   s   t | trt| dkrtdtdd |  D S t | tr4t| dkr+tdtdd | D S t | t	r?| r=dS dS t | t
tfrJt| S t| sZtdt| j| | S )	a  
    Take dicts and lists and return a strictyaml.ruamel style
    structure of CommentedMaps, CommentedSeqs and
    data.

    If a validator is presented and the type is unknown,
    it is checked against the validator to see if it will
    turn it back in to YAML.
    r   z5Document must be built with non-empty dicts and listsc                 S   s    g | ]\}}t |t |fqS r   ruamel_structure).0keyr   r   r   r   
<listcomp>   s    z$ruamel_structure.<locals>.<listcomp>c                 S   s   g | ]}t |qS r   r4   )r6   r1   r   r   r   r8      s    yesnozDocument must be built from a combination of:
string, int, float, bool or nonempty list/dict

Instead, found variable with type '{}': '{}')r
   dictr*   r   'CannotBuildDocumentsFromEmptyDictOrListr   r   listr   r   r   r   r   r   "CannotBuildDocumentFromInvalidDataformatr   __name__)data	validatorr   r   r   r5      s4   



r5   )N)strictyaml.ruamel.commentsr   r   
strictyamlr   rer   r   sysversion_infocollections.abcr	   collectionsr   r   r   r   r   r!   r"   r#   r$   r%   r3   r5   r   r   r   r   <module>   s(    