o
    6d_                     @   sb  d dl mZmZmZmZ d dlZd dlmZ d dlm	Z	 d dl
mZmZmZmZmZ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 dZerPd dlZd dlZe e!d	Z"d
Z#e$dZ%dZ&e"j'dddZ(e(j)ddde!dd e(j)ddde!dd e(j)ddde!dd e(j)ddde!dd e(j)d d!e!d"d# e(j)d$d%d&e!g d'd( G d)d* d*eZ*dS )+    )absolute_importdivisionprint_functionunicode_literalsN)CodeBackend)fmt_underscores)check_route_name_conflict	fmt_classfmt_funcfmt_namespacefmt_objfmt_typefmt_var)class_name_for_data_type)is_nullable_typeis_list_typeis_map_typeis_struct_type
is_tag_refis_union_typeis_user_defined_typeis_void_typeFargparsez# -*- coding: utf-8 -*-
# Auto-generated by Stone, do not modify.
# flake8: noqa
# pylint: skip-file

from abc import ABCMeta, abstractmethod
z:(?P<tag>[A-z]*):`(?P<val>.*?)`a+  If you do not consume the entire response body, then you must call close on the
response object, otherwise you will max out your available connections. We
recommend using the `contextlib.closing
<https://docs.python.org/2/library/contextlib.html#contextlib.closing>`_
context manager to ensure this.zpython-client-backendzGenerates a Python class with a method for each route. Extend the generated class and implement the abstract request() method. This class assumes that the python_types backend was used with the same output directory.)progdescriptionz-mz--module-nameTzQThe name of the Python module to generate. Please exclude the .py file extension.)requiredtypehelpz-cz--class-namezBThe name of the Python class that contains each route as a method.z-tz--types-packagez6The output Python package of the python_types backend.z-ez--error-class-pathz.exceptions.ApiErrorz}The path to the class that's raised when a route returns an error. The class name is inserted into the doc for route methods.)defaultr   r   z-wz--auth-typez(The auth type of the client to generate.)r   r   z-az--attribute-commentappendzRoute attributes that the backend will have access to and presumably expose in generated code. Use ":all" to select all attributes defined in stone_cfg.Route. Attributes will be exposed in the documentation, as the client doesn't use them.)actionr   r   r   c                   @   sz   e Zd ZeZdZdd Zdd Zdd Zdd	 Z	dddZ
	dddZdd Z			dddZdd Zdd Zdd ZdS )PythonClientBackendNc              
   C   sd  |  d| jj  | t d}|j D ]}|jD ]}|jr)| 	d d} nq|r. nq| 	  | 
|j  | 	  | 	  | 	d| jj  |  @ | 	d | 	  | 	d | 	d |   | 	d	 W d
   n1 sxw   Y  | 	  | |j  W d
   n1 sw   Y  W d
   d
S W d
   d
S 1 sw   Y  d
S )zGenerates a module called "base".

        The module will contain a base class that will have a method for
        each route across all namespaces.
        z%s.pyFzimport warningsTzclass %s(object):z__metaclass__ = ABCMetaz@abstractmethodz:def request(self, route, namespace, arg, arg_binary=None):passN)Zoutput_to_relative_pathargsmodule_nameZemit_rawbase
namespacesvaluesroutes
deprecatedemit_generate_imports
class_nameindent_generate_route_methods)selfapiZfound_deprecated	namespaceroute r3   sC:\Users\jesus\OneDrive\Desktop\erpjis_fastapi\backend\jisbackend\Lib\site-packages\stone/backends/python_client.pygenerate~   sD   






"zPythonClientBackend.generatec                 C   s0   |D ]}|j r| d| jjt|j qd S )Nzfrom {} import {})
data_typesr*   formatr#   types_packager   namer/   r&   r1   r3   r3   r4   r+      s
   z%PythonClientBackend._generate_importsc                 C   sH   d| _ |D ]}|jr!| d | d|j |   | | qdS )zvCreates methods for the routes in each namespace. All data types
        and routes are represented as Python classes.Nz,# ------------------------------------------z# Routes in {} namespace)cur_namespacer(   r*   r7   r9   _generate_routesr:   r3   r3   r4   r.      s   

z+PythonClientBackend._generate_route_methodsc                 C   s   || _ | jjdurdd | jjdD | _t| |jD ]Z}| jdu r:| || |j	ddkr9| ||d qd}|jdurG|j	d}|du rLqd	d |dD }| jD ]}||v rv| || |j	ddkrt| ||d  nqYqdS )
zV
        Generates Python methods that correspond to routes in the namespace.
        Nc                 S      g | ]}|   qS r3   striplower).0	auth_typer3   r3   r4   
<listcomp>       z8PythonClientBackend._generate_routes.<locals>.<listcomp>,styledownloadTauthc                 S   r=   r3   r>   )rA   moder3   r3   r4   rC      rD   )
r;   r#   rB   splitsupported_auth_typesr   r(   _generate_route_helperattrsget)r/   r1   r2   Zroute_auth_attrZroute_auth_modesZbase_auth_typer3   r3   r4   r<      s2   



z$PythonClientBackend._generate_routesFc                 C   s  |j }|j}|jddk}|jddk}|r+|sJ d| j||||ddgd n| |||| |   d}d}	d}
|rDd	g}n|rId
g}|rQ|sQd}	t}
|jr]| |j| j	}nd}| j
||||j|||	|
|jd	 | | t|r~| d n't|r| jdd |jD dt|jjt|jd n
t|std| dt|jt|j|jdd|jdg}|r|d n|d | j|ddd |r| d t|r| d n| d nt|r| d n| d W d   n	1 sw   Y  |   dS ) a  Generate a Python method that corresponds to a route.

        :param namespace: Namespace that the route belongs to.
        :param stone.ir.ApiRoute route: IR node for the route.
        :param bool download_to_file: Whether a special version of the route
            that downloads the response body to a file should be generated.
            This can only be used for download-style routes.
        rF   ZuploadrG   z;download_to_file can only be set for download-style routes.Z_to_filedownload_path)method_name_suffix
extra_argsN)fbyteszContents to upload.)rO   strz#Path on local machine to save file.z!:class:`requests.models.Response`)overviewextra_request_argsextra_return_argfooterrM   z
arg = Nonec                 S   s   g | ]}|j qS r3   )r9   )rA   rR   r3   r3   r4   rC     s    z>PythonClientBackend._generate_route_helper.<locals>.<listcomp>zarg = {}.{})beforezUnhandled request type %rz{}.{}version'{}'argrR   Nonezr = self.requestF)compactz,self._save_body_to_file(download_path, r[1])zreturn Nonezreturn r[0]zreturn r)arg_data_typeresult_data_typerM   rN   _generate_route_method_declr-   DOCSTRING_CLOSE_RESPONSEdocprocess_doc_docf_generate_docstring_for_funcerror_data_type#_maybe_generate_deprecation_warningr   r*   r   generate_multiline_list
all_fieldsr7   r   r1   r9   r	   r   AssertionErrorr
   r[   r   )r/   r1   r2   Zdownload_to_filer`   ra   request_binary_bodyZresponse_binary_bodyrV   rW   rX   Zfunc_docstringr#   r3   r3   r4   rL      s   	






Hz*PythonClientBackend._generate_route_helper c                 C   s  dg}|r	||7 }|r| d t|rQ|jD ]8}t|jr(| d|j q|jrIt|jr5|jj	}	nd}	d|j| 
|	|j}
| |
 q| |j qnt|r[| d n
t|setd| t|j| |jd}t|j}| |d	||d
 dS )z+Generates the method prototype for a route.r/   rR   z{}=NoneNz{}={}r]   zUnhandled request type: %rrZ   z	def {}_{}:)r   r   rk   r   	data_typer7   r9   Zhas_defaultr   r1   _generate_python_valuer   r   r   rl   r
   r[   r   rj   )r/   r1   r2   r`   rm   rP   rQ   r#   fieldnsr]   method_nameZnamespace_namer3   r3   r4   rb   =  s:   





z/PythonClientBackend._generate_route_method_declc                 C   sV   |j r)d|j}|j jr|d|j jj7 }d|dg}| j|dddd d S d S )	Nz{} is deprecated.z Use {}.r\   DeprecationWarningzwarnings.warn)()F)rY   delimr_   )r)   r7   r9   Zbyrj   )r/   r2   msgr#   r3   r3   r4   ri   c  s   
z7PythonClientBackend._maybe_generate_deprecation_warningc
              
   C   sv  t |rg n|j}
g }| jjr-|	r-| jjD ]}||	v r,|	| dur,|d||	|  q|
s5|s5|s5dS | d |rA| | |rY|rI|   | d |D ]}| |d qP|s^|
r|sb|rf|   |r|D ]!\}}}|rd|||}| j|dd qj| jd||dd qjt|r|
D ]X}|j	rt
|jrd|j| |j	| j}nd| ||j|j| |j	| j}| j|dd t
|jr| d	|j| ||j qd	|j| ||j}| | qn%t|r|j	r| jd
| |j	| jdd | d| || |s|r!|s!|
s!|   |rHg }t |r1|d n| ||}|| || | |d nt |rS| d n| ||}| d| t |s|jr| d| jj |   | jjddd }| d| |   | | || W d   n	1 sw   Y  |r|   | | | d dS )a  
        Generates a docstring for a function or method.

        This function is versatile. It will create a docstring using all the
        data that is provided.

        :param arg_data_type: The data type describing the argument to the
            route. The data type should be a struct, and each field will be
            treated as an input parameter of the method.
        :param result_data_type: The data type of the route result.
        :param error_data_type: The data type of the route result in the case
            of an error.
        :param str overview: A description of the route that will be located
            at the top of the docstring.
        :param extra_request_args: [(field name, field type, field doc), ...]
            Describes any additional parameters for the method that aren't a
            field in arg_data_type.
        :param str extra_return_arg: Name of an additional return type that. If
            this is specified, it is assumed that the return of the function
            will be a tuple of return_data_type and extra_return-arg.
        :param str footer: Additional notes at the end of the docstring.
        Nz{}: {}z"""zRoute attributes:z    z:param {} {}: {})Zsubsequent_prefixz:param {}: {}z:type {}: {}z:param arg: {}z:type arg: {}r^   z:rtype: z:rtype: Nonez
:rtype: {}z:raises: :class:`{}`.   z If this raises, {} will contain:)r   fieldsr#   Zattribute_commentr   r7   r*   Zemit_wrapped_textr   rd   r   rp   r9   re   rf   _format_type_in_docr   rj   Zerror_class_pathrsplitr-   )r/   r1   r`   ra   rh   rU   rV   rW   rX   rM   r}   Zattrs_lines	attributear9   Zdata_type_namerd   Z	field_docrr   r#   ZrtypeZerror_class_namer3   r3   r4   rg   p  s   














z0PythonClientBackend._generate_docstring_for_funcc                 C   s  |dkr|}d|vr| j jd | }d| jj|S |dkrJd|v r/|dd\}}t|}nd}d|v r>dt||dS d	| j jt||dS |d
kr\|dd\}}d||S |dkrw|dkrfdS |dksn|dkrud|	 S |S |dkrd|S t
d| )z
        Callback used as the handler argument to process_docs(). This converts
        Babel doc references to Sphinx-friendly annotations.
        r   rz   z:class:`{}.{}`r2   ro   r{   z
:meth:`{}`rZ   z:meth:`{}_{}`link z
`{} <{}>`_valnullr^   truefalsez``{}``rr   zUnknown doc ref tag %r)r;   r9   r7   r#   r8   rJ   intr
   r   
capitalizeRuntimeError)r/   tagr   Zfq_valr[   anchorr   r3   r3   r4   rf     s6   

zPythonClientBackend._docfc                 C   s   t |rdS t|rd| jj|jt|S t|r$d| ||j	S t
|r2d| ||j	S t|rFd| ||j| ||jS t|S )zo
        Returns a string that can be recognized by Sphinx as a type reference
        in a docstring.
        r^   z:class:`{}.{}.{}`zNullable[{}]zList[{}]zMap[{}, {}])r   r   r7   r#   r8   r9   r   r   r~   rp   r   r   Zkey_data_typeZvalue_data_type)r/   r1   rp   r3   r3   r4   r~   )  s(   z'PythonClientBackend._format_type_in_docc                 C   s0   t |rdt|jt|jt|jS t|S )Nz{}.{}.{})	r   r7   r   r9   r   Zunion_data_typer   Ztag_namer   )r/   r1   valuer3   r3   r4   rq   C  s   z*PythonClientBackend._generate_python_value)F)rn   N)NNNNNNN)__name__
__module____qualname___cmdline_parserZcmdline_parserrK   r5   r+   r.   r<   rL   rb   ri   rg   rf   r~   rq   r3   r3   r3   r4   r!   y   s&    #
#j
&
 $r!   )+
__future__r   r   r   r   reZstone.backendr   Zstone.backends.helpersr   Zstone.backends.python_helpersr   r	   r
   r   r   r   r   Zstone.backends.python_typesr   Zstone.irr   r   r   r   r   r   r   r   Z_MYPYtyping	importlibimport_modulerT   r   r%   compileZdoc_sub_tag_rerc   ArgumentParserr   add_argumentr!   r3   r3   r3   r4   <module>   s|    $	(

	