%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/wadllib/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/wadllib/__pycache__/application.cpython-312.pyc

�

R
`���l�dZeZgd�ZddlZddlmZddlZddlZddl	Z	ddl
Z
ddlZddlZ	ddl
mZ	ddlmcmZddlmZmZddlmZmZddlmZd	Zd
Z d�Z!d�Z"d
�Z#Gd�de$�Z%Gd�de%�Z&Gd�de%�Z'Gd�de(�Z)Gd�d�Z*Gd�de)�Z+Gd�de+�Z,Gd�de)�Z-Gd�de)e*�Z.Gd �d!e*�Z/Gd"�d#e+e*�Z0Gd$�d%e)�Z1Gd&�d'e)�Z2Gd(�d)e+�Z3Gd*�d+e)�Z4Gd,�d-e)�Z5y#e$r	ddlmZY��wxYw#e$rddlmcmZY��wxYw).a�Navigate the resources exposed by a web service.

The wadllib library helps a web client navigate the resources
exposed by a web service. The service defines its resources in a
single WADL file. wadllib parses this file and gives access to the
resources defined inside. The client code can see the capabilities of
a given resource and make the corresponding HTTP requests.

If a request returns a representation of the resource, the client can
bind the string representation to the wadllib Resource object.
)
�Application�Link�Method�NoBoundRepresentationError�	Parameter�RepresentationDefinition�ResponseDefinition�Resource�ResourceType�	WADLError�N)�quote)�	urlencode)�URI�merge)�
_make_unicode�
_string_types)�iso_strptimez	xmlns:mapz http://www.w3.org/2001/XMLSchemac��d|zS)z)Scope a tag name with the WADL namespace.z&{http://research.sun.com/wadl/2006/10}���tag_names �5/usr/lib/python3/dist-packages/wadllib/application.py�wadl_tagrHs
��3�h�>�>�c��dt|�zS)z#Turn a tag name into an XPath path.z./)rrs r�
wadl_xpathrMs���(�8�$�$�$rc�@�i}|D]}|��|j|��|S)z<Merge any number of dictionaries, some of which may be None.)�update)�dicts�final�dicts   r�_merge_dictsr"Rs/���E�������L�L�����Lrc��eZdZdZy)rzAAn exception having to do with the state of the WADL application.N��__name__�
__module__�__qualname__�__doc__rrrrr[s��K�rrc��eZdZdZy)raAAn unbound resource was used where wadllib expected a bound resource.

    To obtain the value of a resource's parameter, you first must bind
    the resource to a representation. Otherwise the resource has no
    idea what the value is and doesn't even know if you've given it a
    parameter name that makes sense.
    Nr$rrrrr`s��rrc��eZdZdZy)�UnsupportedMediaTypeErrorz�A media type was given that's not supported in this context.

    A resource can only be bound to media types it has representations
    of.
    Nr$rrrr+r+js��rr+c��eZdZdZy)�WADLBasez?A base class for objects that contain WADL-derived information.Nr$rrrr-r-rs��Irr-c�"�eZdZdZdd�Z	dd�Zy)�HasParametersMixinzAA mixin class for objects that have associated Parameter objects.Nc��|�|j}|�td��|j�gS|jjt	d��}|�gS|D�cgc]+}|j
j
d�|vrt||���-c}Scc}w)z6Find subsidiary parameters that have the given styles.z&Could not find any particular resource�param�style)�resource�
ValueError�tag�findallr�attrib�getr)�self�stylesr3�
param_tags�	param_tags     r�paramszHasParametersMixin.paramsys������}�}�H����E�F�F��8�8���I��X�X�%�%�j��&9�:�
����I�!+�<���#�#�'�'��0�F�:��(�I�.�<�	<��<s�0B	c��t||�}i}|D]�}|j}|j�G||vr4|||jk7r"td||�d|�d|j�d���|j||<|jD�cgc]}|j
��}	}t
|	�dkDr2||vr.|||	vr'td||�d|�ddj|	��d	���|r|jr||vrtd
|z��||vs��||||<||=��t
|�dkDr+tddj|j��z��|Scc}w)
a�Make sure the given valueset is valid.

        A valueset might be invalid because it contradicts a fixed
        value or (if enforce_completeness is True) because it lacks a
        required value.

        :param params: A list of Parameter objects.
        :param param_values: A dictionary of parameter values. May include
           paramters whose names are not valid Python identifiers.
        :param enforce_completeness: If True, this method will raise
           an exception when the given value set lacks a value for a
           required parameter.
        :param kw_param_values: A dictionary of parameter values.
        :return: A dictionary of validated parameter values.
        zValue 'z' for parameter 'z' conflicts with fixed value '�'rzInvalid value 'z': valid values are: "z", "�"z$No value for required parameter '%s'zUnrecognized parameter(s): '%s'z', ')
r"�name�fixed_valuer4�options�value�len�join�is_required�keys)
r9r=�param_values�enforce_completeness�kw_param_values�validated_valuesr1rA�optionrCs
          r�validate_param_valuesz(HasParametersMixin.validate_param_values�s���"$�L�/�B�����	'�E��:�:�D�� � �,��L�(�$�T�*�e�.?�.?�?�$�(4�T�(:�D�(-�(9�(9�&;�<�<�&+�%6�%6��T�"�27�-�-�@��v�|�|�@�G�@��G��q� �T�\�%9� ��&�g�5� �$�T�*�D�&�+�+�g�2F�"H�I�I�%��):�):���,� �!G�#'�"(�)�)��|�#�)5�d�);� ��&� ��&�-	'�.�|��q� ��>�%�{�{�<�+<�+<�+>�?�@�A�
A����!As�E�N)T)r%r&r'r(r=rNrrrr/r/vs��K�
<� 48�- rr/c�(�eZdZdZd�Zd�Zd�Zd�Zy)�WADLResolvableDefinitionz=A base class for objects whose definitions may be references.c� �d|_||_y)z�Initialize with a WADL application.

        :param application: A WADLDefinition. Relative links are
            assumed to be relative to this object's URL.
        N)�_definition�application)r9rTs  r�__init__z!WADLResolvableDefinition.__init__�s�� ���&��rc���|j�|jS|j�}|�	||_|S|jj|�}|j	|�}|�td|z��||_|S)a�Return the definition of this object, wherever it is.

        Resource is a good example. A WADL <resource> tag
        may contain a large number of nested tags describing a
        resource, or it may just contain a 'type' attribute that
        references a <resource_type> which contains those same
        tags. Resource.resolve_definition() will return the original
        Resource object in the first case, and a
        ResourceType object in the second case.
        �No such XML ID: "%s")rS�_get_definition_urlrT�
lookup_xml_id�_definition_factory�KeyError)r9�
object_url�xml_id�
definitions    r�resolve_definitionz+WADLResolvableDefinition.resolve_definition�s������'��#�#�#��-�-�/�
��� $�D���K��!�!�/�/�
�;���-�-�f�5�
����1�J�>�?�?�%����rc��t��)zxTransform an XML ID into a wadllib wrapper object.

        Which kind of object it is depends on the subclass.
        ��NotImplementedError�r9�ids  rrZz,WADLResolvableDefinition._definition_factory��
��
"�#�#rc��t��)zmFind the URL that identifies an external reference.

        How to do this depends on the subclass.
        ra�r9s rrXz,WADLResolvableDefinition._get_definition_url�rerN)r%r&r'r(rUr_rZrXrrrrQrQ�s��G�'� �D$�$rrQc����eZdZdZ			d�fd�	Zed��Zed��Zed��Z			dd�Z	d�Z
		dd�Zdd	�Zdd
�Z
ed��Zdd�Zd
�Zd�Zd�Zd�Zdd�Zd�Z�xZS)r	z/A resource, possibly bound to a representation.c���tt|�|�||_t	|t
�r+|jj|�j|_n||_d|_	|�A|dk(r.|r$tjt|��|_	n||_	ntd|z��||_|�+|�||_y|j!|j�|_yy)a[
        :param application: A WADLApplication.
        :param url: The URL to this resource.
        :param resource_type: An ElementTree <resource> or <resource_type> tag.
        :param representation: A string representation.
        :param media_type: The media type of the representation.
        :param representation_needs_processing: Set to False if the
            'representation' parameter should be used as
            is. Otherwise, it will be transformed from a string into
            an appropriate Python data structure, depending on its
            media type.
        :param representation_definition: A RepresentationDefinition
            object describing the structure of this
            representation. Used in cases when the representation
            isn't the result of sending a standard GET to the
            resource.
        N�application/jsonz?This resource doesn't define a representation for media type %s)�superr	rU�_url�
isinstancerrT�get_resource_typer5�representation�json�loadsrr+�
media_type�representation_definition�get_representation_definition)	r9rT�url�
resource_typerorr�representation_needs_processingrs�	__class__s	        �rrUzResource.__init__�s����*	�h��&�{�3���	��m�]�3��'�'�9�9�-�H�L�L�D�H�%�D�H�"����%��/�/�2�*.�*�*�%�n�5�+7�D�'�+9�D�'�/�$�&0�1�2�2�%����%�(�4�1J��.��6�6�t���G��.�	&rc��|jS)z Return the URL to this resource.)rlrgs rruzResource.url,s���y�y�rc�:�|j�y|jjjd�}|�|S|jjjd�}|�>t|jj
�j
�}t|�dz|zSy)z@Return the URL to the type definition for this resource, if any.N�typerd�#)r5r7r8rrT�
markup_url�ensureSlash�str)r9ru�type_id�bases    r�type_urlzResource.type_url1s����8�8����h�h�o�o�!�!�&�)���?��J��(�(�/�/�%�%�d�+�����t�'�'�2�2�3�?�?�A�D��t�9�s�?�W�,�,�rc�4�|jjdS)zReturn the ID of this resource.rd)r5r7rgs rrdzResource.idCs���x�x���t�$�$rc	�`�t|j|j|j||||�S)a�Bind the resource to a representation of that resource.

        :param representation: A string representation
        :param media_type: The media type of the representation.
        :param representation_needs_processing: Set to False if the
            'representation' parameter should be used as
            is.
        :param representation_definition: A RepresentationDefinition
            object describing the structure of this
            representation. Used in cases when the representation
            isn't the result of sending a standard GET to the
            resource.
        :return: A Resource bound to a particular representation.
        )r	rTrur5)r9rorrrwrss     r�bindz
Resource.bindHs0��"��(�(�$�(�(�D�H�H�&�
�7�1�3�	3rc���|jd�j}|D]>}|j�j}|jjd�|k(s�<|cSt
d|z��)z<Get a description of one of this resource's representations.�GET�	mediaTypez4No definition for representation with media type %s.)�
get_method�responser_r5r7r8r+)r9rr�default_get_responsero�representation_tags     rrtz&Resource.get_representation_definition^sy��#���u�5�>�>��2�	&�N�!/�!B�!B�!D�!H�!H��!�(�(�,�,�[�9�Z�G�%�%�	&�(�)>�@J�)K�L�	Lrc���|j�D]e}|jjdd�j�}|�||j�k(s�Ct	||�}|j|||�s�c|cSy)aLook up one of this resource's methods by HTTP method.

        :param http_method: The HTTP method used to invoke the desired
                            method. Case-insensitive and optional.

        :param media_type: The media type of the representation
                           accepted by the method. Optional.

        :param query_params: The names and values of any fixed query
                             parameters used to distinguish between
                             two methods that use the same HTTP
                             method. Optional.

        :param representation_params: The names and values of any
                             fixed representation parameters used to
                             distinguish between two methods that use
                             the same HTTP method and have the same
                             media type. Optional.

        :return: A MethodDefinition, or None if there's no definition
                  that fits the given constraints.
        rA�N)�_method_tag_iterr7r8�lowerr�is_described_by)r9�http_methodrr�query_params�representation_params�
method_tagrA�methods        rr�zResource.get_methodhs��0�/�/�1�	"�J��$�$�(�(���4�:�:�<�D��"�d�k�.?�.?�.A�&A���j�1���)�)�*�l�*?�A�!�M�
	"�rc�B�|j|�j|�S)a~A list of this resource's parameters.

        :param media_type: Media type of the representation definition
            whose parameters are being named. Must be present unless
            this resource is bound to a representation.

        :raise NoBoundRepresentationError: If this resource is not
            bound to a representation and media_type was not provided.
        )�_find_representation_definitionr=�r9rrs  r�
parameterszResource.parameters�s#���3�3�����t��	%rc�B�|j|�j|�S)a�A list naming this resource's parameters.

        :param media_type: Media type of the representation definition
            whose parameters are being named. Must be present unless
            this resource is bound to a representation.

        :raise NoBoundRepresentationError: If this resource is not
            bound to a representation and media_type was not provided.
        )r��parameter_namesr�s  rr�zResource.parameter_names�s$���3�3���'���-�	.rc#�RK�|j�D]}t||����y�w)z6An iterator over the methods defined on this resource.N)r�r)r9r�s  r�method_iterzResource.method_iter�s-�����/�/�1�	+�J���z�*�*�	+�s�%'c���|j|�}|j}|jtd��D].}|jjd�|k(s�"t
||�cSy)a�Find a parameter within a representation definition.

        :param param_name: Name of the parameter to find.

        :param media_type: Media type of the representation definition
            whose parameters are being named. Must be present unless
            this resource is bound to a representation.

        :raise NoBoundRepresentationError: If this resource is not
            bound to a representation and media_type was not provided.
        r1rAN)r�r5r6rr7r8r)r9�
param_namerrr^r�r<s      r�
get_parameterzResource.get_parameter�sh���9�9�*�E�
�'�^�^��+�3�3�J�w�4G�H�	2�I����#�#�F�+�z�9� ��y�1�1�	2�rc�2�|j�td��|jdk(r�|jdk7rt	d|jz��|j|j
}|�D|j
|j|j�\}}|tk(r|dvr	t|�}|S|St	d	|jz��#t$rF	tjtj|d�dd�}Y|S#t$rt|��wxYwwxYw)
z�Find the value of a parameter, given the Parameter object.

        :raise ValueError: If the parameter value can't be converted into
        its defined type.
        z,Resource is not bound to any representation.rj�plain�8Don't know how to find value for a parameter of type %s.)�dateTime�datez%Y-%m-%dr�zEPath traversal not implemented for a representation of media type %s.)rorrrr2rbrA�_dereference_namespacer5r{�XML_SCHEMA_NS_URIrr4�datetime�time�strptime)r9�	parameterrD�
namespace_url�	data_types     r�get_parameter_valuezResource.get_parameter_value�sE�����&�,�>�@�
@��?�?�0�0����'�)�)��!*���1�2�2��'�'�	���7�E�� �+/�+F�+F��M�M�9�>�>�,3�(�
�y�!�%6�6�!�%9�9�4� ,�U� 3���L�5�L�!�#G�$(�O�O�#4�5�	5��&�	4�4�$,�$5�$5�"&�-�-��z�"B�1�Q�"G�%J�E��L�� *�4�#-�U�"3�3�	4��	4�s� C�	D�)C=�=D�Dc��|�d|vr|jdd�\}}nd}|jt�}|j|d�}||fS)z�Splits a value into namespace URI and value.

        :param tag: A tag to use as context when mapping namespace
        names to URIs.
        N�:�r�)�splitr8�NS_MAP)r9r5rD�	namespace�ns_mapr�s      rr�zResource._dereference_namespace�sR�������$�{�{�3��2��I�u��I��������
�
�9�d�3�
��e�#�#rc�L�|jjj|�S)z-Given an ID, find a ResourceType for that ID.)rT�resource_typesr8rcs  rrZzResource._definition_factory�s�����.�.�2�2�2�6�6rc�L�|jjjd�S)z�Return the URL that shows where a resource is 'really' defined.

        If a resource's capabilities are defined by reference, the
        <resource> tag's 'type' attribute will contain the URL to the
        <resource_type> that defines them.
        r{�r5r7r8rgs rrXzResource._get_definition_url�����x�x���"�"�6�*�*rc���|j�*|jj�}|j�S|�!|j|�}|j�St	d��)a3Get the most appropriate representation definition.

        If media_type is provided, the most appropriate definition is
        the definition of the representation of that media type.

        If this resource is bound to a representation, the most
        appropriate definition is the definition of that
        representation. Otherwise, the most appropriate definition is
        the definition of the representation served in response to a
        standard GET.

        :param media_type: Media type of the definition to find. Must
            be present unless the resource is bound to a
            representation.

        :raise NoBoundRepresentationError: If this resource is not
            bound to a representation and media_type was not provided.

        :return: A RepresentationDefinition
        zSResource is not bound to any representation, and no media media type was specified.)rorsr_rtr)r9rrr^s   rr�z(Resource._find_representation_definitionst��*���*��7�7�J�J�L�J��,�,�.�.�
�
#��;�;�J�G�J�
�,�,�.�.�-�,�-�
-rc#�K�|j�j}|jtd��D]}|���y�w)z+Iterate over this resource's <method> tags.r�N)r_r5r6r)r9r^r�s   rr�zResource._method_tag_iter*s?�����,�,�.�2�2�
�$�,�,�Z��-A�B�	�J���	�s�?A)NNTN)rjTN)NNNNrO)r%r&r'r(rU�propertyrur�rdr�rtr�r�r�r�r�r�r�rZrXr�r��
__classcell__�rxs@rr	r	�s����9�26�15�+/�2I�h��������"�%��%�/A�-1�'+�3�,L�JN�)-��B%�.��+��+�
�&-5�`$�7�+� /�Frr	c�v�eZdZdZd�Zed��Zed��Zed��Zed��Z	dd�Z
		dd	�Z		d
d
�Zy)rz*A wrapper around an XML <method> tag.
    c�V�||_|jj|_||_y)zaInitialize with a <method> tag.

        :param method_tag: An ElementTree <method> tag.
        N)r3rTr5)r9r3r�s   rrUzMethod.__init__4s$��
!��
��=�=�4�4�����rc�^�t||jjtd���S)z@Return the definition of a request that invokes the WADL method.�request)�RequestDefinitionr5�findrrgs rr�zMethod.request=s#��!��t�x�x�}�}�Z�	�5J�'K�L�Lrc�r�t|j|jjt	d���S)z9Return the definition of the response to the WADL method.r�)rr3r5r�rrgs rr�zMethod.responseBs.��"�$�-�-�"&�(�(�-�-�
�:�0F�"G�I�	Irc�L�|jjjd�S)z)The XML ID of the WADL method definition.rdr�rgs rrdz	Method.idHs���x�x���"�"�4�(�(rc�h�|jjjd�j�S)z�The name of the WADL method definition.

        This is also the name of the HTTP method (GET, POST, etc.)
        that should be used to invoke the WADL method.
        rA�r5r7r8r�rgs rrAzMethod.nameMs&���x�x���"�"�6�*�0�0�2�2rNc�<�|jj|fi|��S)�4Return the request URL to use to invoke this method.)r��	build_url)r9rIrKs   r�build_request_urlzMethod.build_request_urlVs��%�t�|�|�%�%�l�F�o�F�Frc�>�|jj||fi|��S)z�Build a representation to be sent when invoking this method.

        :return: A 2-tuple of (media_type, representation).
        )r�ro)r9rrrIrKs    r�build_representationzMethod.build_representationZs*��+�t�|�|�*�*���9�(7�9�	9rc���d}|�|jj|�}|�y|�;t|�dkDr-|j}|�y	|j|j|d�|�t|�dk(ry|�|j
|�S|jjD]0}	|j|j|j�|d�yy#t
$rYywxYw#t
$rY�NwxYw)aReturns true if this method fits the given constraints.

        :param media_type: The method must accept this media type as a
                           representation.

        :param query_values: These key-value pairs must be acceptable
                           as values for this method's query
                           parameters. This need not be a complete set
                           of parameters acceptable to the method.

        :param representation_values: These key-value pairs must be
                           acceptable as values for this method's
                           representation parameters. Again, this need
                           not be a complete set of parameters
                           acceptable to the method.
        NFrT)
r�rtrErNr�r4r��representationsr=r3)r9rr�query_values�representation_valuesror�s      rr�zMethod.is_described_bycs��$���!�!�\�\�G�G���N��%���#��L�(9�A�(=��l�l�G����
��-�-��(�(�,��?�
"�)��(�)�Q�.���%�!�1�1�%�'�
'�"�l�l�:�:�	�N�
��4�4�"�)�)�$�-�-�8�)�5�2��	���'�
��
��"�
��
�s$�C�,C�	C�C�	C)�(C)rO�NN)NNN)
r%r&r'r(rUr�r�r�rdrAr�r�r�rrrrr1s������M��M��I��I�
�)��)��3��3�G�/3�*.�9�=A�.2�5rrc�N�eZdZdZd�Zed��Zed��Zd	d�Zd
d�Z	d	d�Z
y)r�zBA wrapper around the description of the request invoking a method.c��||_|jj|_|jj|_||_y)z�Initialize with a <request> tag.

        :param resource: The resource to which this request can be sent.
        :param request_tag: An ElementTree <request> tag.
        N)r�r3rTr5)r9r��request_tags   rrUzRequestDefinition.__init__�s5��������,�,��
��=�=�4�4�����rc�&�|jdg�S)z,Return the query parameters for this method.�query)r=rgs rr�zRequestDefinition.query_params�s���{�{�G�9�%�%rc#�K�|jjtd��D]%}t|j|j
|����'y�w)Nro)r5r6rrrTr3)r9r^s  rr�z!RequestDefinition.representations�sH�����(�(�*�*�:�6F�+G�H�	=�J�*�� � �$�-�-��=�
=�	=�s�AANc�P�|jD]}|�|j|k(s�|cSy)z1Return the appropriate representation definition.N)r�rr�r9rrros   rrtz/RequestDefinition.get_representation_definition�s5��"�2�2�	&�N��!�^�%>�%>�*�%L�%�%�	&�rc�j�|j|�}|�td|z��|j|fi|��S)z�Build a representation to be sent along with this request.

        :return: A 2-tuple of (media_type, representation).
        z,Cannot build representation of media type %s)rt�	TypeErrorr�)r9rrrIrKr^s     rroz RequestDefinition.representation�sH���7�7�
�C�
����J�(�)�*�
*��z���|�?��?�?rc���|j|j|fi|��}|jj}t	|�dkDr1d|vrd}nd}||tt
|j���zz
}|S)r�r�?�&)rNr�r3rurEr�sorted�items)r9rIrKrLru�appends      rr�zRequestDefinition.build_url�s���5�4�5�5����|�@�/>�@���m�m������ �1�$��c�z������6�I�f�-=�-C�-C�-E�&F�G�G�G�C��
rrOr�)r%r&r'r(rUr�r�r�rtror�rrrr�r��sB��L�	��&��&��=��=�
�
@�rr�c�6�eZdZdZd	d�Zd�Zd�Zd�Zd�Zd�Z	y)
rz;A wrapper around the description of a response to a method.Nc�P�|j|_||_||_||_y)zgInitialize with a <response> tag.

        :param response_tag: An ElementTree <response> tag.
        N)rTr3r5�headers)r9r3�response_tagr�s    rrUzResponseDefinition.__init__�s'��
$�/�/��� ��
������rc#�K�td�}|jj|�D]/}t|jj
|j|����1y�w)z�Get an iterator over the representation definitions.

        These are the representations returned in response to an
        invocation of this method.
        roN)rr5r6rr3rT)r9�pathr�s   r�__iter__zResponseDefinition.__iter__�sY�����*�+��"&�(�(�"2�"2�4�"8�	N��*��
�
�)�)�4�=�=�:L�N�
N�	N�s�AAc�D�t|j|j|�S)z�Bind the response to a set of HTTP headers.

        A WADL response can have associated header parameters, but no
        other kind.
        )rr3r5)r9r�s  rr�zResponseDefinition.bind�s��"�$�-�-����7�C�Crc���|jjtd��D]M}|jj	d�|k(s�"|jj	d�dk(s�At||�cSy)z,Find a header parameter within the response.r1rAr2�headerN)r5r6rr7r8r)r9r�r<s   rr�z ResponseDefinition.get_parameter�si�����)�)�*�W�*=�>�	2�I�� � �$�$�V�,�
�:��$�$�(�(��1�X�=� ��y�1�1�	2�rc���|j�td��|jdk7rtd|jz��|jj	|j
�S)z:Find the value of a parameter, given the Parameter object.z,Response object is not bound to any headers.r�r�)r�rr2rbr8rA)r9r�s  rr�z&ResponseDefinition.get_parameter_valuesc���<�<��,�>�@�
@��?�?�h�&�%��&�_�_�-�.�
.��|�|���	���/�/rc�R�|j�y|D]}|j|k(s�|cSy)z8Get one of the possible representations of the response.N)r5rrr�s   rrtz0ResponseDefinition.get_representation_definitions7���8�8���"�	&�N��(�(�J�6�%�%�	&�rrO)
r%r&r'r(rUr�r�r�r�rtrrrrr�s%��E��	N�D��	0�rrc�n��eZdZdZ�fd�Z�fd�Zd�Zed��Zd�Z	d�Z
d
d�Zd	�Zd
�Z
d�Zd�Z�xZS)rz2A definition of the structure of a representation.c�H��tt|�|�||_||_yrO)rkrrUr3r5)r9rTr3r�rxs    �rrUz!RepresentationDefinition.__init__s!���
�&��6�{�C� ��
�%��rc�0��tt|�ddg|�S)Nr�r�)rkrr=)r9r3rxs  �rr=zRepresentationDefinition.paramss"����-�t�;�
�g���*�	*rc�^�|j|�D�cgc]}|j��c}Scc}w)z#Return the names of all parameters.)r=rA)r9r3r1s   rr�z(RepresentationDefinition.parameter_names"s#��(,���H�(=�>�u��
�
�>�>��>s�*c�P�|j�jjdS)z4The media type of the representation described here.r�)r_r5r7rgs rrrz#RepresentationDefinition.media_type&s$���&�&�(�,�,�3�3�K�@�@rc��tttjdz
��}d|z}t	j
tj�}d||zzdz}|�|S|}d}	dt
j|�zdzjd�}t
j||tj�	�s	|S|d
zt|�z}|dz
}�j)z;Make a random boundary that does not appear in `all_parts`.r�z%%0%ddz===============z==rz^--z(--)?$�ascii)�flags�.)rE�repr�sys�maxsize�random�	randrange�re�escape�encode�search�	MULTILINEr)	r9�	all_parts�_width�_fmt�token�boundary�b�counter�patterns	         r�_make_boundaryz'RepresentationDefinition._make_boundary+s����T�#�+�+��/�*�+���&� ��� � ����-������.��5�����O�������r�y�y��|�+�h�6�>�>�w�G�G��9�9�W�i�r�|�|�D�����3���W��-�A��q�L�G�rc��|D]g\}}|j|jd��|jd�|j|jd��|jd��i|jd�y)z$Write MIME headers to a file object.�UTF-8s: �
N��writer)r9�bufr��keyrDs     r�_write_headersz'RepresentationDefinition._write_headers=se��!�	�J�C���I�I�c�j�j��)�*��I�I�e���I�I�e�l�l�7�+�,��I�I�g��		�
	�	�	�'�rc��|jd�|j|jd��|r|jd�|jd�y)z,Write a multipart boundary to a file object.s--rrNr)r9rr
�closings    r�_write_boundaryz(RepresentationDefinition._write_boundaryFs>���	�	�%���	�	�(�/�/�'�*�+���I�I�e���	�	�'�rc�6�g}|D�]Y\}}}tj�}|rd}dt|��dt|��d�}nd}dt|�z}|j|dd|fd	|fg�|r9t	|t
�st
d
t|�z��|j|�n�t	|t�st
dt|�z��tjd|�}	|	d
dD]3}
|j|
jd��|jd��5|j|	djd��|j|j����\|jdj!|��}tj�}dt|�z}|j|dd|fg�|D]6}|j#||�|j|�|jd��8|j#||d��||j�fS)aVGenerate a multipart/form-data message.

        This is very loosely based on the email module in the Python standard
        library.  However, that module doesn't really support directly embedding
        binary data in a form: various versions of Python have mangled line
        separators in different ways, and none of them get it quite right.
        Since we only need a tiny subset of MIME here, it's easier to implement
        it ourselves.

        :return: a tuple of two elements: the Content-Type of the message, and
            the entire encoded message as a byte string.
        zapplication/octet-streamzform-data; name="z
"; filename="r@ztext/plain; charset="utf-8"zform-data; name="%s")zMIME-Versionz1.0zContent-TypezContent-Dispositionzbytes payload expected: %szstring payload expected: %sz
\r\n|\r|\nN���rrz"multipart/form-data; boundary="%s"T)r)�io�BytesIOr
rrm�bytesr�r{rrrr�rr��getvaluerrFr)
r9�parts�
encoded_parts�	is_binaryrArDr�ctype�cdisp�lines�liner
�encoded_parts
             r�_generate_multipart_formz1RepresentationDefinition._generate_multipart_formNs	���
�&+�	1�"�I�t�U��*�*�,�C��2��
�$�K��t��.��6��.��t��<������'���'�&��.�&�
�
�!�%��/�#�$@�4��;�$N�O�O��	�	�%� �!�%��7�#�5��U��C�E�E������6��!�#�2�J�'�D��I�I�d�k�k�'�2�3��I�I�g�&�'��	�	�%��)�*�*�7�3�4�� � �����0�=	1�B�&�&�w�|�|�M�'B�C���j�j�l��4�u�X��F�����C�#�
�U�#�"�	�*�	�L�� � ��h�/��I�I�l�#��I�I�g��	�	
���S�(�D��9��c�l�l�n�$�$rc�>�|j�}|j|j�}|j||fi|��}|j}|dk(r&tt
|j���}||fS|dk(rwg}t�}	|D]N}
|j|
j|	�}||	us�$|j|
jdk(|
j|f��P|j|�\}}||fS|dk(rtj|�}||fSt!d|z��)zzBind the definition to parameter values, creating a document.

        :return: A 2-tuple (media_type, document).
        z!application/x-www-form-urlencodedzmultipart/form-data�binaryrjzUnsupported media type: '%s')r_r=r3rNrrrr�r��objectr8rAr�r{r(rp�dumpsr4)r9rIrKr^r=rLrr�docr �missingr1rDs            rr�zRepresentationDefinition.bind�s>��
�,�,�.�
��"�"�4�=�=�1��5�4�5�5��L�5�$3�5���_�_�
��<�<��F�#3�#9�#9�#;�<�=�C��3����0�
0��E��h�G��
N��(�,�,�U�Z�Z��A����'��L�L�%�*�*��"8�%�*�*�e�!L�M�
N�#�;�;�E�B�O�J��
�3���	�-�
-��*�*�-�.�C��3����;�j�H�I�Irc�L�|jjj|�S)z9Turn a representation ID into a RepresentationDefinition.)rT�representation_definitionsr8rcs  rrZz,RepresentationDefinition._definition_factory�s�����:�:�>�>�r�B�Brc�L�|jjjd�S)aFind the URL containing the representation's 'real' definition.

        If a representation's structure is defined by reference, the
        <representation> tag's 'href' attribute will contain the URL
        to the <representation> that defines the structure.
        �hrefr�rgs rrXz,RepresentationDefinition._get_definition_url�r�r)F)r%r&r'r(rUr=r�r�rrrrrr(r�rZrXr�r�s@rrrsP���<�&�
*�?��A��A��$��?%�B�4C�+rrc��eZdZdZd�Zed��Zed��Zed��Zed��Z	ed��Z
d�Zed	��Zed
��Z
ed��Zy)
rz5One of the parameters of a representation definition.c�B�|j|_||_||_y)a�Initialize with respect to a value container.

        :param value_container: Usually the resource whose representation
            has this parameter. If the resource is bound to a representation,
            you'll be able to find the value of this parameter in the
            representation. This may also be a server response whose headers
            define a value for this parameter.
        :tag: The ElementTree <param> tag for this parameter.
        N)rT�value_containerr5)r9r5r5s   rrUzParameter.__init__�s!��+�6�6���.�����rc�L�|jjjd�S)zThe name of this parameter.rAr�rgs rrAzParameter.name�����x�x���"�"�6�*�*rc�L�|jjjd�S)zThe style of this parameter.r2r�rgs rr2zParameter.style�s���x�x���"�"�7�+�+rc�L�|jjjd�S)zThe XSD type of this parameter.r{r�rgs rr{zParameter.type�r7rc�L�|jjjd�S)a9The value to which this parameter is fixed, if any.

        A fixed parameter must be present in invocations of a WADL
        method, and it must have a particular value. This is commonly
        used to designate one parameter as containing the name of the
        server-side operation to be invoked.
        �fixedr�rgs rrBzParameter.fixed_value�s���x�x���"�"�7�+�+rc�n�|jjjdd�j�dvS)z6Whether or not a value for this parameter is required.�required�false)�1�truer�rgs rrGzParameter.is_required�s2�������#�#�J��8�>�>�@� �!�	"rc�8�|jj|�S)z�The value of this parameter in the bound representation/headers.

        :raise NoBoundRepresentationError: If this parameter's value
               container is not bound to a representation or a set of
               headers.
        )r5r�rgs r�	get_valuezParameter.get_value�s���#�#�7�7��=�=rc��|jjtd��D�cgc]}t||���c}Scc}w)z7Return the set of acceptable values for this parameter.rM)r5r6r�Option)r9�
option_tags  rrCzParameter.options�sC��$(�8�8�#3�#3�J�x�4H�#I�K���t�Z�(�K�	K��Ks�=c�h�|jjtd��}|�yt||�S)z�Get the link to another resource.

        The link may be examined and, if its type is of a known WADL
        description, it may be followed.

        :return: A Link object, or None.
        �linkN)r5r�rr)r9�link_tags  rrGzParameter.link�s1���8�8�=�=��F�!3�4������D�(�#�#rc�L�|j}|�td��|jS)aFollow a link from this parameter to a new resource.

        This only works for parameters whose WADL definition includes a
        <link> tag that points to a known WADL description.

        :return: A Resource object for the resource at the other end
        of the link.
        z(This parameter isn't a link to anything.)rGr4�follow)r9rGs  r�linked_resourcezParameter.linked_resources(���y�y���<��G�H�H��{�{�rN)r%r&r'r(rUr�rAr2r{rBrGrBrCrGrKrrrrr�s���?���+��+��,��,��+��+��,��,��"��"�
>��K��K�
�$��$����rrc�&�eZdZdZd�Zed��Zy)rDz0One of a set of possible values for a parameter.c� �||_||_y)z}Initialize the option.

        :param parameter: A Parameter.
        :param link_tag: An ElementTree <option> tag.
        N)r�r5)r9r�rEs   rrUzOption.__init__s��#�����rc�L�|jjjd�S)NrDr�rgs rrDzOption.value s���x�x���"�"�7�+�+rN)r%r&r'r(rUr�rDrrrrDrDs��:���,��,rrDc�N��eZdZdZ�fd�Zed��Zed��Zd�Zd�Z	�xZ
S)rz�A link from one resource to another.

    Calling resolve_definition() on a Link will give you a Resource for the
    type of resource linked to. An alias for this is 'follow'.
    c�\��tt|�|j�||_||_y)zyInitialize the link.

        :param parameter: A Parameter.
        :param link_tag: An ElementTree <link> tag.
        N)rkrrUrTr�r5)r9r�rHrxs   �rrUz
Link.__init__,s(���	�d�D�"�9�#8�#8�9�"�����rc�P�|jstd��|j�S)z$Follow the link to another Resource.zfCannot follow a link when the target has no WADL description. Try using a general HTTP client instead.)�
can_followrr_rgs rrJzLink.follow6s.������.�/�
/��&�&�(�(rc�D�	|j�}y#t$rYywxYw)z�Can this link be followed within wadllib?

        wadllib can follow a link if it points to a resource that has
        a WADL definition.
        FT)rXr)r9�definition_urls  rrRzLink.can_follow?s.��	�!�5�5�7�N����	��	�s��	�c��t|j|jj�|jjj|�j�S)z,Turn a resource type ID into a ResourceType.)r	rTr�rBr�r8r5rcs  rrZzLink._definition_factoryLsG������d�n�n�6�6�8����+�+�/�/��3�7�7�9�	9rc�j�|jjjd�}|�td��|S)z(Find the URL containing the definition .rvzIParameter is a link, but not to a resource with a known WADL description.)r5r7r8r)r9r{s  rrXzLink._get_definition_urlRs6���x�x���"�"�?�3���<��=�>�
>��r)r%r&r'r(rUr�rJrRrZrXr�r�s@rrr%s?������)��)��
��
�9�rrc��eZdZdZd�Zy)r
z,A wrapper around an XML <resource_type> tag.c��||_y)zvInitialize with a <resource_type> tag.

        :param resource_type_tag: An ElementTree <resource_type> tag.
        N)r5)r9�resource_type_tags  rrUzResourceType.__init__^s��
%��rN)r%r&r'r(rUrrrr
r
[s
��6�%rr
c�4�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	y)	rz1A WADL document made programmatically accessible.c��||_t|d�r|j|�|_n|j	|�|_|jjt
d��|_|jjjd�|_
i|_i|_|jjt
d��D]<}|jjd�}|��!t|d|�}||j|<�>|jjt
d��D])}|jd}t|�|j|<�+y)z�Parse WADL and find the most important parts of the document.

        :param markup_url: The URL from which this document was obtained.
        :param markup: The WADL markup itself, or an open filehandle to it.
        �read�	resourcesr�rordNrv)r}�hasattr�_from_streamr-�_from_stringr�rr]r7r8�
resource_baser0r�r6rr
)r9r}�markuprordr^rvs       rrUzApplication.__init__is-��%����6�6�"��(�(��0�D�H��(�(��0�D�H������z�+�'>�?���!�^�^�2�2�6�6�v�>���*,��'� ���"�h�h�.�.�z�:J�/K�L�	A�N��&�&�*�*�4�0�B��~�5��$��0�
�6@��/�/��3�	A�"�X�X�-�-�j��.I�J�	B�M��%�%�d�+�B�&2�=�&A�D����#�	Brc� �d}d}g}tj||�D][\}}|dk(r|j|��|dk(r|j��3|dk(s�9|�|}|j	t
t
|���]tj|�S)zrTurns markup into a document.

        Just a wrapper around ElementTree which keeps track of namespaces.
        )�start�start-ns�end-nsNrerfrd)�ET�	iterparser��pop�setr�r!�ElementTree)r9�stream�events�rootr��event�elems       rr_zApplication._from_stream�s���
/�������<�<���7�	/�K�E�4��
�"��
�
�d�#��(�"��
�
���'�!��<��D������f��.�	/��~�~�d�#�#rc��t|t�s|jd�}|jt	j
|��S)zTurns markup into a document.r)rmrrr_rr)r9rbs  rr`zApplication._from_string�s4���&�%�(��]�]�7�+�F�� � ����F�!3�4�4rc�~�|j|�}|jj|�}|�td|z��|S)z7Retrieve a resource type by the URL of its description.rW)rYr�r8r[)r9�resource_type_urlr]rvs    rrnzApplication.get_resource_type�sG���#�#�$5�6���+�+�/�/��7�
�� ��1�4E�E�F�F��rc��t|j�j�}d|_|j	d�rt|�j�}n|j|�}|j}d|_||k(r|St
d|z��)z�A helper method for locating a part of a WADL document.

        :param url: The URL (with anchor) of the desired part of the
        WADL document.
        :return: The XML ID corresponding to the anchor.
        N�httpz,Can't look up definition in another url (%s))rr}�
ensureNoSlash�fragment�
startswith�resolverb)r9ru�
markup_uri�this_uri�possible_xml_ids     rrYzApplication.lookup_xml_id�s�������)�7�7�9�
�"�
���>�>�&�!��3�x�-�-�/�H�"�)�)�#�.�H�"�+�+�� ����z�!�#�"�"�#-�/2�#3�4�	4rc��|jD�cgc]}|jd|k(r|��}}t|�dkryt|�dkDrtd|z��t	|t|j|d�|d�Scc}w)zpLocate one of the resources described by this document.

        :param path: The path to the resource.
        r�r�Nz+More than one resource defined with path %sTr)r]r7rErr	rra)r9r�r3�matchings    r�get_resource_by_pathz Application.get_resource_by_path�s���.2�^�^�8�����v�.�$�6��8��8��x�=�1����x�=�1���I�"�#�$�
$���%��*�*�D�$�7��!��F�	F��8s�A<N)
r%r&r'r(rUr_r`rnrYrrrrrrfs&��;�B�2$�(5��4�@Frr)6r(r{�
__metaclass__�__all__r��email.utilsr
rrpr�rr�r��urllib.parser�ImportError�urllib�xml.etree.cElementTree�etree�cElementTreerg�xml.etree.ElementTreerk�lazr.urirr�wadllibrr�wadllib.iso_strptimerr�r�rrr"�	Exceptionrrr+r+r-r/rQr	rr�rrrrDrr
rrrr�<module>r�sx��"
��
�����	��
�	�
��!�&�'�'�'� ��.�	��6��?�
%�
�	�	�	�
����	��J�v�J�? �? �D:$�x�:$�zy�'�y�x	g�X�g�T6��"4�6�r?�+�?�D^+�7�9K�^+�B[��[�z,�X�,�"3�#�3�l%�8�%�nF�(�nF��a!�!� �!���'�&�&�'�s"�D�	D"�D�D�"D3�2D3

Zerion Mini Shell 1.0