ruạṛ
a [��fJ � @ s\ d Z ddlmZ ddlZddlmZ dd� Zddd �Zd d� Zdd � Z G dd� dej �ZdS )zUtilities for the API class.� ��wrapsN)�utilc s: t �� j�}d|v ot|�dk}|r*� jS � fdd�}|S )a Create a search function for routing requests. Args: router(object): An object that implements the routing engine interface. Returns: callable: A function that accepts a request and invokes the router's find method. �req� c s � � | �S �N)�find)�pathr ��router� �v/sparta/input/_build_configuration/image_build+validate/lib/bmcenv/lib64/python3.9/site-packages/falcon/api_helpers.py�search_shim* s z'make_router_search.<locals>.search_shim)r �get_argnamesr �len)r � arg_names�supports_reqr r r r �make_router_search s r Fc C s g }g }g }| du rg } nt | t�s*| g} | D ]�}t�|d�}t�|d�}t�|d�}|st|st|std} t| �|���|r�t�|�} t| �dkr�|fdd�}|� }|r�|r�|�|� |r�|� d |� n|s�|r�|�||f� |r.|�|� q.t |�t |�t |�fS ) a6 Check middleware interface and prepare it to iterate. Args: middleware: list (or object) of input middleware independent_middleware: bool whether should prepare request and response middleware independently Returns: list: A tuple of prepared middleware tuples N�process_request�process_resource�process_responsez/{0} does not implement the middleware interface� c s t � �� fdd��}|S )Nc s � | ||� d S r r )r �resp�resource� req_succeeded�r r r �shim[ s z-prepare_middleware.<locals>.let.<locals>.shimr )r r r r r �letZ s zprepare_middleware.<locals>.letr )� isinstance�listr �get_bound_method� TypeError�formatr r �append�insert�tuple)� middleware�independent_middleware� request_mw�resource_mw�response_mw� componentr r r �msg�argsr r r r �prepare_middleware0 sF ��� r. c C s| d}| � d�}|du r:| j�� }d|v r.d}nd|v r:d}|durl|dkrT|�� }n|�� }||_|d |_|�dd � dS ) ak Serialize the given instance of HTTPError. This function determines which of the supported media types, if any, are acceptable by the client, and serializes the error to the preferred type. Currently, JSON and XML are the only supported media types. If the client accepts both JSON and XML with equal weight, JSON will be chosen. Other media types can be supported by using a custom error serializer. Note: If a custom media type is used and the type includes a "+json" or "+xml" suffix, the error will be serialized to JSON or XML, respectively. If this behavior is not desirable, a custom error serializer may be used to override this one. Args: req: Instance of ``falcon.Request`` resp: Instance of ``falcon.Response`` exception: Instance of ``falcon.HTTPError`` N)�application/xmlztext/xml�application/jsonz+jsonr0 z+xmlr/ z; charset=UTF-8�Vary�Accept)�client_prefers�accept�lower�to_json�to_xml�body�content_type� append_header)r r � exception�representation� preferredr4 r r r �default_serialize_erroru s r>