o
    6d                     @   s  d dl mZmZmZmZ d dlmZ d dlZd dlm	Z	m
Z
 d dlmZmZ d dlmZ d dlmZmZmZmZmZmZmZmZmZmZmZmZmZmZ dZerTd dlZed	ed
ededededededededediZ h dZ!edd Z"dd Z#d4ddZ$d5ddZ%dd Z&dd Z'd4ddZ(d d! Z)d"d# Z*d$d% Z+d&Z,	d4d'd(Z-d)d* Z.d+Z/e/j0d,d-Z1e/j0e,d-Z2d.d/ Z3d6d0d1Z4d6d2d3Z5dS )7    )absolute_importdivisionprint_functionunicode_literals)contextmanagerN)BackendCodeBackend)
fmt_pascalfmt_underscores)ApiNamespace)AnnotationTypeBooleanBytesFloat32Float64Int32Int64ListString	TimestampUInt32UInt64is_user_defined_typeis_aliasFboolbytesfloatintliststrdatetime>   classwhilebreakpasscontinueasyncforc                 c   s6    | j }d V  | j }||kr| d |   d S d S )Nr$   )linenoemit)ZcodegenZstarting_linenoZending_lineno r*   tC:\Users\jesus\OneDrive\Desktop\erpjis_fastapi\backend\jisbackend\Lib\site-packages\stone/backends/python_helpers.pyemit_pass_if_nothing_emitted:   s   
r,   c                 C   s   | t v r| d S | S )N_)_reserved_keywords)sr*   r*   r+   _rename_if_reservedD   s   r0   c                 C      t | }|r
t|S |S N)r	   r0   namecheck_reservedr/   r*   r*   r+   	fmt_classJ      r6      c                 C   s,   t | } |r
t| } |dkrd| |} | S )Nr8   z{}_v{})r
   r0   format)r4   r5   versionr*   r*   r+   fmt_funcN   s   r;   c                 C   s   t j| ddS )Nr8   )width)pprintpformat)or*   r*   r+   fmt_objV   s   r@   c                 C   s   t | jt| jS r2   )_type_tableget	__class__r6   r4   )	data_typer*   r*   r+   fmt_typeY      rE   c                 C   r1   r2   )r
   r0   r3   r*   r*   r+   fmt_var\   r7   rG   c                 C   s   d | |t|gS )N.)joinrG   )Zns_nameZdata_type_name
field_namer*   r*   r+   fmt_namespaced_var`   rF   rK   c                 C   s   t | S r2   )r0   )r4   r*   r*   r+   fmt_namespacec   s   rL   c                 C   sL   i }| j D ]}t|j|jd}||v r|| }td|||||< qdS )z
    Check name conflicts among generated route definitions. Raise a runtime exception when a
    conflict is encountered.
    )r:   z.There is a name conflict between {!r} and {!r}N)Zroutesr;   r4   r:   RuntimeErrorr9   )	namespaceZroute_by_nameZrouteZ
route_nameZother_router*   r*   r+   check_route_name_conflictf   s   


rO   z  # type: ignorec                 C   sR   |j dd}|s
dS |rtnd}|D ]}| dj|t|j|d q|   dS )z
    Both the true Python backend and the Python PEP 484 Type Stub backend have
    to perform the same imports.

    :param insert_type_ignore: add a MyPy type-ignore comment to the imports in
        the except: clause.
    T)Zconsider_annotation_typesN z;from {package} import {namespace_name}{type_ignore_comment})packageZnamespace_nametype_ignore_comment)Zget_imported_namespacesTYPE_IGNORE_COMMENTr)   r9   rL   r4   )backendrN   rQ   Zinsert_type_ignoreZimported_namespacesrR   nsr*   r*   r+   *generate_imports_for_referenced_namespacesw   s   

rV   c                 C   s<   |  d |  d |  dd |  d |  d d S )Nz# -*- coding: utf-8 -*-z)# Auto-generated by Stone, do not modify.z# @{}	generatedz# flake8: noqaz# pylint: skip-file)r)   r9   )rT   r*   r*   r+   generate_module_header   s
   


rX   zfrom stone.backends.python_rsrc import stone_base as bb{type_ignore_comment}
from stone.backends.python_rsrc import stone_validators as bv{type_ignore_comment}

rP   )rR   c                 C   s   ||kr| S d t|j| S )z
    Returns a name that can be used to reference `name` in namespace `name_ns`
    from `source_ns`.

    If `source_ns` and `name_ns` are the same, that's just `name`. Otherwise
    it's `name_ns`.`name`.
    z{}.{})r9   rL   r4   )r4   Zname_nsZ	source_nsr*   r*   r+   prefix_with_ns_if_necessary   s   	rY   c                 C   s@   t | st| sJ dt|  t| j}|rt|| j|S |S )a>  
    Returns the name of the Python class that maps to a user-defined type.
    The name is identical to the name in the spec.

    If ``ns`` is set to a Namespace and the namespace of `data_type` does
    not match, then a namespace prefix is added to the returned name.
    For example, ``foreign_ns.TypeName``.
    zExpected composite type, got %r)r   r   typer6   r4   rY   rN   )rD   rU   r4   r*   r*   r+   class_name_for_data_type   s   	

r[   c                 C   s.   t | tsJ t| j}|rt|| j|S |S )zL
    Same as class_name_for_data_type, but works with annotation types.
    )
isinstancer   r6   r4   rY   rN   )Zannotation_typerU   r4   r*   r*   r+   class_name_for_annotation_type   s
   
r]   )F)Fr8   r2   )6
__future__r   r   r   r   
contextlibr   r=   Zstone.backendr   r   Zstone.backends.helpersr	   r
   Zstone.irr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   Z_MYPYtypingrA   r.   r,   r0   r6   r;   r@   rE   rG   rK   rL   rO   rS   rV   rX   Z_validators_import_templater9   Zvalidators_importZ"validators_import_with_type_ignorerY   r[   r]   r*   r*   r*   r+   <module>   s\    @

	





