U
    ~d|5                     @   sV  d dl mZmZmZmZmZmZmZ ddlm	Z	 e	
  d dlZd dlZd dlZd dlmZ d dlmZ d dlmZ d dlZd dlZd dlmZ z,d d	lmZmZmZmZmZmZmZm Z  W n4 e!k
r   d Z Z Z Z Z Z ZZ Y nX zd dl"m#Z$ d dlZW n" e!k
r,   d dlZeZ$Y nX e%e$d
rBe$j&Z&ne'dd dD Z&zd dlm(Z( dZ)W nN e!k
r   dZ(zd dlm*Z* W n" e!k
r   d dlm)Z* Y nX Y nX e'eZ+dd Z,d+ddZ-d,ddZ.dd Z/dd Z0d-ddZ1dd Z2d d! Z3d"d# Z4dZ5G d$d% d%e6Z7e7 Z5d&d' Z8d(d) Z9e:d*krRd dl;Z;e;<  dS ).    )nested_scopes
generatorsdivisionabsolute_importwith_statementprint_functionunicode_literals   )compatibilityN)UnsupportedOperation)OrderedDict)	normalize)	iskeyword)UnionOptionalIterableTupleAnyCallableAnyStrIterator	Generatorc                 c   s   | ]
}|V  qd S N ).0nr   r   V/var/www/html/myproject/myenv/lib/python3.8/site-packages/serial/utilities/__init__.py	<genexpr>.   s     r   )r	         )	signature)getfullargspec)
getargspecc                 C   sb   t | dr(ddd | jdD }n| j}t| trF|dkr^d}n| jdkr^| jd | }|S )z
    >>> print(qualified_name(qualified_name))
    qualified_name

    >>> from serial import model
    >>> print(qualified_name(model.marshal))
    serial.model.marshal
    __qualname__.c                 s   s   | ]}|d  dkr|V  qdS )r   <Nr   )r   	name_partr   r   r   r   Q   s      z!qualified_name.<locals>.<genexpr>)builtins__builtin____main____init__N)hasattrjoinr#   split__name__
isinstance_Module
__module__)type_	type_namer   r   r   qualified_nameE   s    


r4   c                 C   sR   | d7 } t | d}g }|rN|r:|r.|d |ks:|d| | d7 } t | d}q|S )z
    >>> def my_function_a(): return calling_functions_qualified_names()
    >>> def my_function_b(): return my_function_a()
    >>> print(my_function())
    ['my_function_b', 'my_function_a']
    r	   )depthr   )calling_function_qualified_nameinsert)r5   namenamesr   r   r   !calling_functions_qualified_namesf   s    	
r:   c                 C   s6  t | ts.t| }tdd|kr"dnd|  zt }W n tk
rP   Y dS X t|| d k rfdS g }||  }z
|j}W n t	k
r   |d }Y nX |dkrNz
|j
}W n t	k
r   |d	 }Y nX || t|\}}}}	|rN|d	 }
|	|
 }t|}t|d
rNt|drN|jttks@tt|j|k	rN|t| t|dk r(z
|j}W n t	k
r   |d }Y nX t|}|dk	r|tjkrttj|}|  |r| }|d | }|tjkrqq|dkrtd| n$|tjkr(ttj| }|| dt|S )zf
    >>> def my_function(): return calling_function_qualified_name()
    >>> print(my_function())
    zbThe parameter `depth` for `serial.utilities.calling_function_qualified_name` must be an `int`, not
z:
%sz %s.Nr	   r   z<module>r   r.   r1   r   r$   z$The path "%s" is not a python module) r/   intrepr	TypeErrorinspectstack
IndexErrorlenfunctionAttributeErrorframeappendgetargvaluestyper+   r.   dirr'   getattrr4   filenamegetmodulenamesysmoduleslistospathr-   pop
ValueErrorr,   reversed)r5   Zdepth_representationr@   	name_list
frame_infoZframe_functionrE   	arguments_Zframe_localsargumentZargument_valueZargument_value_type	file_namemodule_name
path_partsparentZqualified_module_namer   r   r   r6   |   sz    








r6   c                 C   st   t ddt ddt ddt ddt dd	t d
dt ddtd|  }t|sh|ttkrp|d7 }|S )a  
    Converts a "camelCased" attribute/property name, or a name which conflicts with a python keyword, to a
    pep8-compliant property name.

    >>> print(property_name('theBirdsAndTheBees'))
    the_birds_and_the_bees

    >>> print(property_name('FYIThisIsAnAcronym'))
    fyi_this_is_an_acronym

    >>> print(property_name('in'))
    in_

    >>> print(property_name('id'))
    id_
    z__+rX   z[^\w]+ z([a-zA-Z])([0-9])z\1_\2z([0-9])([a-zA-Z])z([A-Z])([A-Z])([a-z])z\1_\2\3z([a-z])([A-Z])z([^\x20-\x7F]|\s)+NFKD)resubr   lowerr   rI   r'   )stringpnr   r   r   property_name   s@    re   c                 C   s   t | ddS )a   
    >>> print(class_name('the birds and the bees'))
    TheBirdsAndTheBees

    >>> print(class_name('the-birds-and-the-bees'))
    TheBirdsAndTheBees

    >>> print(class_name('**the - birds - and - the - bees**'))
    TheBirdsAndTheBees

    >>> print(class_name('FYI is an acronym'))
    FYIIsAnAcronym

    >>> print(class_name('in-you-go'))
    InYouGo

    >>> print(class_name('False'))
    False_

    >>> print(class_name('True'))
    True_

    >>> print(class_name('ABC Acronym'))
    ABCAcronym
    T)
capitalize)camel)rc   r   r   r   
class_name  s    rh   Fc                 C   s   t d| } g }|s|  } |}| D ]4}|dkrR|rB|s:|rB| }|| d}q"d}q"d|}t|sv|ttkr~|d7 }|S )a  
    >>> print(camel('the birds and the bees'))
    theBirdsAndTheBees

    >>> print(camel('the-birds-and-the-bees'))
    theBirdsAndTheBees

    >>> print(camel('**the - birds - and - the - bees**'))
    theBirdsAndTheBees

    >>> print(camel('FYI is an acronym'))
    fyiIsAnAcronym

    >>> print(camel('in-you-go'))
    inYouGo

    >>> print(camel('False'))
    false

    >>> print(camel('True'))
    true

    >>> print(camel('in'))
    in_
    r_   Z>abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789FTr^   rX   )r   rb   upperrF   r,   r   rI   r'   )rc   rf   
charactersZcapitalize_nextsZcnr   r   r   rg   )  s"    


rg   c                 C   s,   t | drt| jtr| j}n
t| }|S )N_source)r+   r/   rl   strr?   	getsource)oresultr   r   r   
get_sourceX  s    
rq   c                 C   s2  g }d}d}| D ]}|dkrL|dkr6|d  | n| |g d}d}q|dkr|dkrl|d  | nD|dkr|r| |d  g|g  q|d  | n| |g d}d}q|d	kr|dkr|d  | d
}n| |g d}d}q|dkr|d  | n| |g d}qtdd |D S )a  
    >>> print('(%s)' % ', '.join("'%s'" % s for s in camel_split('theBirdsAndTheBees')))
    ('the', 'Birds', 'And', 'The', 'Bees')
    >>> print('(%s)' % ', '.join("'%s'" % s for s in camel_split('theBirdsAndTheBees123')))
    ('the', 'Birds', 'And', 'The', 'Bees', '123')
    >>> print('(%s)' % ', '.join("'%s'" % s for s in camel_split('theBirdsAndTheBeesABC123')))
    ('the', 'Birds', 'And', 'The', 'Bees', 'ABC', '123')
    >>> print('(%s)' % ', '.join("'%s'" % s for s in camel_split('the-Birds-And-The-Bees-ABC--123')))
    ('the', '-', 'Birds', '-', 'And', '-', 'The', '-', 'Bees', '-', 'ABC', '--', '123')
    >>> print('(%s)' % ', '.join("'%s'" % s for s in camel_split('THEBirdsAndTheBees')))
    ('THE', 'Birds', 'And', 'The', 'Bees')
    NF
0123456789r   abcdefghijklmnopqrstuvwxyzr	   r   ABCDEFGHIJKLMNOPQRSTUVWXYZTr   c                 s   s   | ]}d  |V  qdS )r^   N)r,   )r   wr   r   r   r     s    zcamel_split.<locals>.<genexpr>)rF   rR   tuple)rc   wordsZcharacter_typeZacronymrk   r   r   r   camel_splita  sD    

ry   c                 c   s:   t | D ],}|d dkrt| |}t|s||fV  qd S )Nr   rX   )rI   rJ   callable)ro   avr   r   r   properties_values  s
    
r}   c                   @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )	Undefinedc                 C   s   t d k	rtdt|  d S )Nz%s may only be defined once.)	UNDEFINEDRuntimeErrorr=   selfr   r   r   r*     s    
zUndefined.__init__c                 C   s    | j dddtfkrdS d| j  S )Nr)   r'   r(   r   z%s.UNDEFINED)r1   r.   r   r   r   r   __repr__  s    zUndefined.__repr__c                 C   s   dS )NFr   r   r   r   r   __bool__  s    zUndefined.__bool__c                 C   s   dS )Nr   r   r   r   r   r   __hash__  s    zUndefined.__hash__c                 C   s   || kS r   r   )r   otherr   r   r   __eq__  s    zUndefined.__eq__N)r.   r1   r#   r*   r   r   r   r   r   r   r   r   r~     s
   r~   c              	   C   s   t  }tdkrvt| }d}|jD ]}t||< q t|jD ]:}z|j| ||< W n tk
rh   Y  qY nX |d8 }q8n:t| j	 D ]*\}}|j
tjjkrt||< q|j
||< q|S )a  
    Returns an ordered dictionary mapping a function's argument names to default values, or `UNDEFINED` in the case of
    positional arguments.

    >>> class X(object):
    ...
    ...    def __init__(self, a, b, c, d=1, e=2, f=3):
    ...        pass
    ...
    >>> print(list(parameters_defaults(X.__init__).items()))
    [('self', UNDEFINED), ('a', UNDEFINED), ('b', UNDEFINED), ('c', UNDEFINED), ('d', 1), ('e', 2), ('f', 3)]
    Nrs   r	   )r   r    r!   argsr   rT   defaultsrA   
parametersitemsdefaultr?   	Parameterempty)rC   pdspecir{   rd   pr   r   r   parameters_defaults  s"    


r   c                 C   s   t | drt| js(t | drt| jrt | dr`t| jr`z| d W n tk
r^   Y nX t | drt| jrz|  } W q tk
r   |  } Y qX n|  } | S tdt|  d S )Nreadallreadseekr   z%s is not a file-like object)r+   rz   r   r   r   r   r>   r=   )datar   r   r   r     s.    
r   r)   )r	   )r	   )F)=
__future__r   r   r   r   r   r   r   r^   r
   Zbackportr'   rP   rM   ior   collectionsr   unicodedatar   r`   r?   keywordr   typingr   r   r   r   r   r   r   r   ImportErrorcollections.abcabccollections_abcr+   r   rH   r    r"   r!   r0   r4   r:   r6   re   rh   rg   rq   ry   r}   r   objectr~   r   r   r.   doctesttestmodr   r   r   r   <module>   sf   $,&
!

\4
/	8	#
