o
    ?Hh/                     @   s|   d Z ddlZddlmZmZmZ ddlmZ ddlm	Z	m
Z
mZmZ dd ZedZd	d
 Zdd ZG dd dejZdS )aL  
For the ``future`` package.

Adds this import line:

    from __future__ import division

at the top and changes any old-style divisions to be calls to
past.utils.old_div so the code runs as before on Py2.6/2.7 and has the same
behaviour on Py3.

If "from __future__ import division" is already in effect, this fixer does
nothing.
    N)LeafNodeComma)
fixer_base)tokenfuture_importtouch_import_topwrap_in_fn_callc                 C   s,   t j}| j|ko| jj|k o| jj|k S )zw
    __future__.division redefines the meaning of a single slash for division,
    so we match that and only that.
    )r   SLASHtypenext_siblingprev_sibling)nodeslash r   c/home/air/sanwanet/gpt-api/venv/lib/python3.10/site-packages/libfuturize/fixes/fix_division_safe.pymatch_division   s   r   z^[0-9]*[.][0-9]*$c                 C   s   t | jp	t | jS )N)
_is_floatyr   r   )r   r   r   r   	is_floaty"   s   r   c                 C   sV   t | tr	| d } t | trt| jS t | tr)t | jd tr)| jd jdkS dS )Nr   floatF)
isinstancelistr   const_rematchvaluer   children)exprr   r   r   r   &   s   


r   c                       s:   e Zd ZdZejZdZ fddZdd Z	dd Z
  ZS )	FixDivisionSafe   z4
    term<(not('/') any)+ '/' ((not('/') any))>
    c                    s"   t t| || d|jv | _dS )zO
        Skip this fixer if "__future__.division" is already imported.
        divisionN)superr   
start_treefuture_featuresskip)selftreename	__class__r   r   r!   >   s   zFixDivisionSafe.start_treec                 C   s   |j | jjkrXd}d}g }|jD ]1}|rd}qt|r:t|s:d}d|d _td|t |j	
 g |jdg}d}q||
  q|rXttdrRt|j ||jdS t|j |S dS )	z
        Since the tree needs to be fixed once and only once if and only if it
        matches, we can start discarding matches after the first.
        FT r   old_div)prefixfixers_applied)r,   )r   symstermr   r   r   r+   r	   r   r   cloneappendhasattrr   r,   )r$   r   matchedr#   r   childr   r   r   r   E   s,   


zFixDivisionSafe.matchc                 C   s$   | j rd S td| tdd| |S )Nr   z
past.utilsr*   )r#   r   r   )r$   r   resultsr   r   r   	transformh   s
   
zFixDivisionSafe.transform)__name__
__module____qualname__	run_orderr   r
   _accept_typePATTERNr!   r   r5   __classcell__r   r   r'   r   r   4   s    #r   )__doc__relib2to3.fixer_utilr   r   r   lib2to3r   libfuturize.fixer_utilr   r   r   r	   r   compiler   r   r   BaseFixr   r   r   r   r   <module>   s    
	