o
    h>xd|5                     @   sJ  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 n e!yw   d Z Z Z Z Z Z ZZ Y nw zd dl"m#Z$ d dlZW n e!y   d dlZeZ$Y nw e%e$d
re$j&Z&n	e'dd dD Z&z
d dlm(Z( dZ)W n# e!y   dZ(zd dlm*Z* W n e!y   d dlm)Z* Y nw Y nw 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r#d dl;Z;e;<  dS 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   AD:\rfid_django\env\Lib\site-packages\serial/utilities/__init__.py	<genexpr>.   s    r   )r	         )	signature)getfullargspec)
getargspecc                 C   sd   t | drddd | jdD }n| j}t| tr$|dv r"d}|S | jdvr0| 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   sT   | d7 } t | d}g }|r(|r|r|d |ks|d| | d7 } t | d}|s|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   s  t | tst| }tdd|v rdnd|  zt }W n
 ty'   Y dS w t|| d k r2dS g }||  }z|j}W n t	yJ   |d }Y nw |dkrz|j
}W n t	ya   |d	 }Y nw || t|\}}}}	|r|d	 }
|	|
 }t|}t|d
rt|dr|jttvstt|j|ur|t| t|dk rz|j}W n t	y   |d }Y nw t|}|dur|tjvrttj|}|  |r| }|d | }|tjv rn|s|du rtd| |tjv 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_localsZargumentZargument_valueZargument_value_type	file_namemodule_name
path_partsparentZqualified_module_namer   r   r   r6   |   s   







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|s4|ttv r8|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   sD   rd   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)rb   r   r   r   
class_name  s   rg   Fc                 C   s   t d| } g }|s|  } |}| D ]}|dv r)|r!|s|r!| }|| d}qd}qd|}t|s;|ttv 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   ra   upperrF   r,   r   rI   r'   )rb   re   
charactersZcapitalize_nextsZcnr   r   r   rf   )  s"   


rf   c                 C   s.   t | drt| jtr| j}|S t| }|S )N_source)r+   r/   rk   strr?   	getsource)oresultr   r   r   
get_sourceX  s
   
rp   c                 C   s.  g }d}d}| D ]}|dv r%|dkr|d  | n| |g d}d}q|dv r\|dkr5|d  | n"|dkrQ|rI| |d  g|g  n|d  | n| |g d}d}q|d	v ry|dkrn|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)rb   wordsZcharacter_typeZacronymrj   r   r   r   camel_splita  sD   rx   c                 c   s<    t | D ]}|d dkrt| |}t|s||fV  qd S )Nr   rX   )rI   rJ   callable)rn   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 u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v 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      dS )NFr   r   r   r   r   __bool__     zUndefined.__bool__c                 C   r   )Nr   r   r   r   r   r   __hash__  r   zUndefined.__hash__c                 C   s   || u 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u r:t| }d}|jD ]}t||< qt|jD ]}z	|j| ||< W n ty2   Y  |S w |d8 }q|S t| j	 D ]\}}|j
tjju rQt||< qA|j
||< qA|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)]
    Nrr   r	   )r   r    r!   argsr~   rT   defaultsrA   
parametersitemsdefaultr?   	Parameterempty)rC   pdspecirz   rc   pr   r   r   parameters_defaults  s(   



r   c                 C   s   t | dr
t| jst | drUt| jrUt | dr/t| jr/z| d W n	 ty.   Y nw t | drOt| jrOz|  } W | S  tyN   |  } Y | S w |  } | S tdt|  )Nreadallreadseekr   z%s is not a file-like object)r+   ry   r   r   r   r   r>   r=   )datar   r   r   r     s6   


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   rd   rg   rf   rp   rx   r|   r~   objectr}   r   r   r.   doctesttestmodr   r   r   r   <module>   st   $ ,$


!
\4
/	8	#
