HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //proc/thread-self/root/lib/python3/dist-packages/wadllib/__pycache__/application.cpython-38.pyc
U

��Q[���
@s�dZeZddddddddd	d
g
ZddlZdd
lmZddlZddlZddl	Z	ddl
Z
ddlZddlZzddl
mZWn ek
r�ddlmZYnXddlmmZddlmZmZddlmZmZddlmZdZdZdd�Zdd�Z dd�Z!Gdd
�d
e"�Z#Gdd�de#�Z$Gdd�de#�Z%Gdd�de&�Z'Gd d!�d!�Z(Gd"d#�d#e'�Z)Gd$d�de)�Z*Gd%d�de'�Z+Gd&d'�d'e'e(�Z,Gd(d�de(�Z-Gd)d�de)e(�Z.Gd*d�de'�Z/Gd+d,�d,e'�Z0Gd-d�de)�Z1Gd.d	�d	e'�Z2Gd/d�de'�Z3dS)0a�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/XMLSchemacCsd|S)z)Scope a tag name with the WADL namespace.z&{http://research.sun.com/wadl/2006/10}��Ztag_namerr�5/usr/lib/python3/dist-packages/wadllib/application.py�wadl_tagEsrcCsdt|�S)z#Turn a tag name into an XPath path.z./)rrrrr�
wadl_xpathJsrcGs$i}|D]}|dk	r|�|�q|S)z<Merge any number of dictionaries, some of which may be None.N)�update)Zdicts�final�dictrrr�_merge_dictsOs
rc@seZdZdZdS)r
zAAn exception having to do with the state of the WADL application.N��__name__�
__module__�__qualname__�__doc__rrrrr
Xsc@seZdZdZdS)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.
    Nrrrrrr]sc@seZdZdZdS)�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.
    Nrrrrrr!gsr!c@seZdZdZdS)�WADLBasez?A base class for objects that contain WADL-derived information.Nrrrrrr"osr"c@s$eZdZdZddd�Zd	dd�ZdS)
�HasParametersMixinzAA mixin class for objects that have associated Parameter objects.Ncs\�dkr|j��dkrtd��|jdkr,gS|j�td��}|dkrHgS��fdd�|D�S)z6Find subsidiary parameters that have the given styles.Nz&Could not find any particular resource�paramcs&g|]}|j�d��krt�|��qS)�style)�attrib�getr)�.0�	param_tag��resource�stylesrr�
<listcomp>�s�z-HasParametersMixin.params.<locals>.<listcomp>)r+�
ValueError�tag�findallr)�selfr,r+Z
param_tagsrr*r�paramsvs
�zHasParametersMixin.paramsTc	Kst||�}i}|D]�}|j}|jdk	r^||krT|||jkrTtd||||jf��|j||<dd�|jD�}t|�dkr�||kr�|||kr�td|||d�|�f��|r�|jr�||kr�td|��||kr||||<||=qt|�dk�rtd	d
�|�����|S)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.
        Nz=Value '%s' for parameter '%s' conflicts with fixed value '%s'cSsg|]
}|j�qSr)�value)r(�optionrrrr-�sz<HasParametersMixin.validate_param_values.<locals>.<listcomp>rz=Invalid value '%s' for parameter '%s': valid values are: "%s"z", "z$No value for required parameter '%s'zUnrecognized parameter(s): '%s'z', ')	r�name�fixed_valuer.�options�len�join�is_required�keys)	r1r2�param_valuesZenforce_completeness�kw_param_values�validated_valuesr$r5r7rrr�validate_param_values�sL

���

���
���z(HasParametersMixin.validate_param_values)N)T)rrrr r2r?rrrrr#ss
�r#c@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�WADLResolvableDefinitionz=A base class for objects whose definitions may be references.cCsd|_||_dS)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)r1rBrrr�__init__�sz!WADLResolvableDefinition.__init__cCs^|jdk	r|jS|��}|dkr*||_|S|j�|�}|�|�}|dkrTtd|��||_|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.
        N�No such XML ID: "%s")rA�_get_definition_urlrB�
lookup_xml_id�_definition_factory�KeyError)r1Z
object_url�xml_id�
definitionrrr�resolve_definition�s

z+WADLResolvableDefinition.resolve_definitioncCs
t��dS)zxTransform an XML ID into a wadllib wrapper object.

        Which kind of object it is depends on the subclass.
        N��NotImplementedError�r1�idrrrrG�sz,WADLResolvableDefinition._definition_factorycCs
t��dS)zmFind the URL that identifies an external reference.

        How to do this depends on the subclass.
        NrL�r1rrrrE�sz,WADLResolvableDefinition._get_definition_urlN)rrrr rCrKrGrErrrrr@�s
	"r@cs�eZdZdZd'�fdd�	Zedd��Zedd	��Zed
d��Zd(d
d�Z	dd�Z
d)dd�Zd*dd�Zd+dd�Z
edd��Zd,dd�Zdd�Zdd�Zdd �Zd!d"�Zd-d#d$�Zd%d&�Z�ZS).rz/A resource, possibly bound to a representation.NTcs�tt|��|�||_t|t�r2|j�|�j|_n||_d|_	|dk	rx|dkrl|rdt
�t|��|_	qx||_	nt
d|��||_|dk	r�|dk	r�||_n|�|j�|_dS)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)�superrrC�_url�
isinstancerrB�get_resource_typer/�representation�json�loadsrr!�
media_type�representation_definition�get_representation_definition)r1rB�url�
resource_typerVrY�representation_needs_processingrZ��	__class__rrrC�s0
���
�zResource.__init__cCs|jS)z Return the URL to this resource.)rSrPrrrr\)szResource.urlcCsb|jdkrdS|jj�d�}|dk	r(|S|jj�d�}|dk	r^t|jj���}t|�d|SdS)z@Return the URL to the type definition for this resource, if any.N�typerO�#)r/r&r'rrB�
markup_urlZensureSlash�str)r1r\Ztype_id�baserrr�type_url.s
zResource.type_urlcCs|jjdS)zReturn the ID of this resource.rO)r/r&rPrrrrO@szResource.idrQcCst|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.
        )rrBr\r/)r1rVrYr^rZrrr�bindEs�z
Resource.bindcCsH|�d�j}|D]&}|��j}|j�d�|kr|Sqtd|��dS)z<Get a description of one of this resource's representations.ZGET�	mediaTypez4No definition for representation with media type %s.N)�
get_method�responserKr/r&r'r!)r1rYZdefault_get_responserV�representation_tagrrrr[[s

�z&Resource.get_representation_definitioncCsX|��D]J}|j�dd���}|dks2||��krt||�}|�|||�r|SqdS)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.
        r5�N)�_method_tag_iterr&r'�lowerr�is_described_by)r1Zhttp_methodrY�query_paramsZrepresentation_params�
method_tagr5�methodrrrries
�
zResource.get_methodcCs|�|��|�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_definitionr2�r1rYrrr�
parameters�s

��zResource.parameterscCs|�|��|�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.
        )rs�parameter_namesrtrrrrv�s

��zResource.parameter_namesccs|��D]}t||�VqdS)z6An iterator over the methods defined on this resource.N)rmr)r1rqrrr�method_iter�szResource.method_itercCsF|�|�}|j}|�td��D]"}|j�d�|krt||�SqdS)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.
        r$r5N)rsr/r0rr&r'r)r1�
param_namerYrJrkr)rrr�
get_parameter�s
zResource.get_parametercCs�|jdkrtd��|jdkr�|jdkr4td|j��|j|j}|dk	r�|�|j|j�\}}|t	kr�|dkr�zt
|�}WnPtk
r�ztjt
�|d�dd	��}Wntk
r�t|��YnXYnX|Std
|j��dS)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.
        Nz,Resource is not bound to any representation.rQ�plain�8Don't know how to find value for a parameter of type %s.)ZdateTime�datez%Y-%m-%dr�zEPath traversal not implemented for a representation of media type %s.)rVrrYr%rMr5�_dereference_namespacer/ra�XML_SCHEMA_NS_URIrr.�datetime�time�strptime)r1�	parameterr3�
namespace_urlZ	data_typerrr�get_parameter_value�sB
�

������zResource.get_parameter_valuecCsD|dk	r"d|kr"|�dd�\}}nd}|�t�}|�|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�:�rl)�splitr'�NS_MAP)r1r/r3�	namespace�ns_mapr�rrrr~�s
zResource._dereference_namespacecCs|jj�|�S)z-Given an ID, find a ResourceType for that ID.)rB�resource_typesr'rNrrrrG�szResource._definition_factorycCs|jj�d�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.
        ra�r/r&r'rPrrrrE�szResource._get_definition_urlcCs:|jdk	r|j��}n|dk	r*|�|�}ntd��|��S)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
        NzSResource is not bound to any representation, and no media media type was specified.)rVrZrKr[r)r1rYrJrrrrss
�z(Resource._find_representation_definitionccs(|��j}|�td��D]
}|VqdS)z+Iterate over this resource's <method> tags.rrN)rKr/r0r)r1rJrqrrrrm's
zResource._method_tag_iter)NNTN)rQTN)NNNN)N)N)N)N)rrrr rC�propertyr\rfrOrgr[rirurvrwryr�r~rGrErsrm�
__classcell__rrr_rr�s>�4


�

�
!




0	
#c@sfeZdZdZdd�Zedd��Zedd��Zedd	��Zed
d��Z	dd
d�Z
ddd�Zddd�ZdS)rz*A wrapper around an XML <method> tag.
    cCs||_|jj|_||_dS)zaInitialize with a <method> tag.

        :param method_tag: An ElementTree <method> tag.
        N)r+rBr/)r1r+rqrrrrC1s
zMethod.__init__cCst||j�td���S)z@Return the definition of a request that invokes the WADL method.�request)�RequestDefinitionr/�findrrPrrrr�:szMethod.requestcCst|j|j�td���S)z9Return the definition of the response to the WADL method.rj)rr+r/r�rrPrrrrj?s�zMethod.responsecCs|jj�d�S)z)The XML ID of the WADL method definition.rOr�rPrrrrOEsz	Method.idcCs|jj�d���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.
        r5�r/r&r'rnrPrrrr5JszMethod.nameNcKs|jj|f|�S)�4Return the request URL to use to invoke this method.)r��	build_url)r1r<r=rrr�build_request_urlSszMethod.build_request_urlcKs|jj||f|�S)z�Build a representation to be sent when invoking this method.

        :return: A 2-tuple of (media_type, representation).
        )r�rV)r1rYr<r=rrr�build_representationWs��zMethod.build_representationc	Cs�d}|dk	r$|j�|�}|dkr$dS|dk	rvt|�dkrv|j}|dkrJdSz|�|j|d�Wntk
rtYdSX|dks�t|�dkr�dS|dk	r�|�|�S|jjD]8}z|�|�|j	�|d�WdStk
r�Yq�Xq�dS)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.
        NFrT)
r�r[r8r?rpr.ro�representationsr2r+)r1rYZquery_valuesZrepresentation_valuesrVr�rrrro`sL��
��
�zMethod.is_described_by)N)NN)NNN)
rrrr rCr�r�rjrOr5r�r�rorrrrr.s"	




�
	�c@sNeZdZdZdd�Zedd��Zedd��Zdd	d
�Zddd�Z	dd
d�Z
dS)r�zBA wrapper around the description of the request invoking a method.cCs$||_|jj|_|jj|_||_dS)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)rrr+rBr/)r1rrZrequest_tagrrrrC�s

zRequestDefinition.__init__cCs|�dg�S)z,Return the query parameters for this method.�query�r2rPrrrrp�szRequestDefinition.query_paramsccs,|j�td��D]}t|j|j|�VqdS)NrV)r/r0rrrBr+)r1rJrrrr��s�z!RequestDefinition.representationsNcCs*|jD]}|dks|j|kr|SqdS)z1Return the appropriate representation definition.N)r�rY�r1rYrVrrrr[�s

z/RequestDefinition.get_representation_definitioncKs,|�|�}|dkrtd|��|j|f|�S)z�Build a representation to be sent along with this request.

        :return: A 2-tuple of (media_type, representation).
        Nz,Cannot build representation of media type %s)r[�	TypeErrorrg)r1rYr<r=rJrrrrV�s
�z RequestDefinition.representationcKsT|j|j|f|�}|jj}t|�dkrPd|kr4d}nd}||tt|����7}|S)r�r�?�&)r?rpr+r\r8r
�sorted�items)r1r<r=r>r\�appendrrrr��s��zRequestDefinition.build_url)N)NN)N)rrrr rCr�rpr�r[rVr�rrrrr��s



r�c@sBeZdZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)rz;A wrapper around the description of a response to a method.NcCs|j|_||_||_||_dS)zgInitialize with a <response> tag.

        :param response_tag: An ElementTree <response> tag.
        N)rBr+r/�headers)r1r+Zresponse_tagr�rrrrC�szResponseDefinition.__init__ccs2td�}|j�|�D]}t|jj|j|�VqdS)z�Get an iterator over the representation definitions.

        These are the representations returned in response to an
        invocation of this method.
        rVN)rr/r0rr+rB)r1�pathrkrrr�__iter__�s�zResponseDefinition.__iter__cCst|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.
        )rr+r/)r1r�rrrrg�szResponseDefinition.bindcCsH|j�td��D]2}|j�d�|kr|j�d�dkrt||�SqdS)z,Find a header parameter within the response.r$r5r%�headerN)r/r0rr&r'r)r1rxr)rrrry�s�z ResponseDefinition.get_parametercCs8|jdkrtd��|jdkr*td|j��|j�|j�S)z:Find the value of a parameter, given the Parameter object.Nz,Response object is not bound to any headers.r�r{)r�rr%rMr'r5)r1r�rrrr��s
�
��z&ResponseDefinition.get_parameter_valuecCs.|jdkrdS|D]}|j|kr|SqdS)z8Get one of the possible representations of the response.N)r/rYr�rrrr[	s


z0ResponseDefinition.get_representation_definition)N)
rrrr rCr�rgryr�r[rrrrr�s

cszeZdZdZ�fdd�Z�fdd�Zdd�Zedd	��Zd
d�Z	dd
�Z
ddd�Zdd�Zdd�Z
dd�Zdd�Z�ZS)rz2A definition of the structure of a representation.cs tt|��|�||_||_dS)N)rRrrCr+r/)r1rBr+rkr_rrrCsz!RepresentationDefinition.__init__cstt|��ddg|�S)Nr�rz)rRrr2�r1r+r_rrr2s
�zRepresentationDefinition.paramscCsdd�|�|�D�S)z#Return the names of all parameters.cSsg|]
}|j�qSr)r5)r(r$rrrr-!sz<RepresentationDefinition.parameter_names.<locals>.<listcomp>r�r�rrrrvsz(RepresentationDefinition.parameter_namescCs|��jjdS)z4The media type of the representation described here.rh)rKr/r&rPrrrrY#sz#RepresentationDefinition.media_typec	Cs�tttjd��}d|}t�tj�}d||d}|dkrB|S|}d}dt�|�d�d	�}tj	||tj
d
�svq�|dt|�}|d7}qJ|S)z;Make a random boundary that does not appear in `all_parts`.r�z%%0%ddz===============z==Nrz^--z(--)?$�ascii)�flags�.)r8�repr�sys�maxsize�randomZ	randrange�re�escape�encode�search�	MULTILINErd)	r1Z	all_partsZ_widthZ_fmt�token�boundary�bZcounter�patternrrr�_make_boundary(s
z'RepresentationDefinition._make_boundarycCsP|D]<\}}|�|�d��|�d�|�|�d��|�d�q|�d�dS)z$Write MIME headers to a file object.�UTF-8s: �
N��writer�)r1�bufr��keyr3rrr�_write_headers:s
z'RepresentationDefinition._write_headersFcCs6|�d�|�|�d��|r(|�d�|�d�dS)z,Write a multipart boundary to a file object.s--r�r�Nr�)r1r�r��closingrrr�_write_boundaryCs


z(RepresentationDefinition._write_boundaryc
Cs�g}|D]�\}}}t��}|r8d}dt|�t|�f}nd}dt|�}|�|dd|fd|fg�|r�t|t�s�tdt|���|�|�nft|t	�s�td	t|���t
�d
|�}	|	dd�D]}
|�|
�d
��|�d�q�|�|	d�d
��|�
|���q|�d�|��}t��}dt|�}|�|dd|fg�|D]&}|�||�|�|�|�d��q>|j||dd�||��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-streamz#form-data; name="%s"; filename="%s"ztext/plain; charset="utf-8"zform-data; name="%s")zMIME-Versionz1.0zContent-TypezContent-Dispositionzbytes payload expected: %szstr payload expected: %sz
\r\n|\r|\nN���r�r�z"multipart/form-data; boundary="%s"T)r�)�io�BytesIOrr�rT�bytesr�rar�rdr�r�r�r��getvaluer�r9r�)
r1�partsZ
encoded_partsZ	is_binaryr5r3r�ZctypeZcdisp�lines�liner�Zencoded_partrrr�_generate_multipart_formKsR��

�
z1RepresentationDefinition._generate_multipart_formcKs�|��}|�|j�}|j||f|�}|j}|dkrDtt|����}nz|dkr�g}t�}	|D]2}
|�	|
j
|	�}||	k	rZ|�|
jdk|
j
|f�qZ|�
|�\}}n |dkr�t�|�}ntd|��||fS)zzBind the definition to parameter values, creating a document.

        :return: A 2-tuple (media_type, document).
        z!application/x-www-form-urlencodedzmultipart/form-data�binaryrQzUnsupported media type: '%s')rKr2r+r?rYr
r�r��objectr'r5r�rar�rW�dumpsr.)r1r<r=rJr2r>rY�docr�Zmissingr$r3rrrrg�s.��zRepresentationDefinition.bindcCs|jj�|�S)z9Turn a representation ID into a RepresentationDefinition.)rB�representation_definitionsr'rNrrrrG�sz,RepresentationDefinition._definition_factorycCs|jj�d�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.
        Zhrefr�rPrrrrE�sz,RepresentationDefinition._get_definition_url)F)rrrr rCr2rvr�rYr�r�r�r�rgrGrEr�rrr_rrs
	
@c@s�eZdZdZdd�Zedd��Zedd��Zedd	��Zed
d��Z	edd
��Z
dd�Zedd��Zedd��Z
edd��ZdS)rz5One of the parameters of a representation definition.cCs|j|_||_||_dS)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)rB�value_containerr/)r1r�r/rrrrC�s
zParameter.__init__cCs|jj�d�S)zThe name of this parameter.r5r�rPrrrr5�szParameter.namecCs|jj�d�S)zThe style of this parameter.r%r�rPrrrr%�szParameter.stylecCs|jj�d�S)zThe XSD type of this parameter.rar�rPrrrra�szParameter.typecCs|jj�d�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.
        Zfixedr�rPrrrr6�s	zParameter.fixed_valuecCs|jj�dd���dkS)z6Whether or not a value for this parameter is required.ZrequiredZfalse)�1�truer�rPrrrr:�s�zParameter.is_requiredcCs|j�|�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.
        )r�r�rPrrr�	get_value�szParameter.get_valuecs�fdd��j�td��D�S)z7Return the set of acceptable values for this parameter.csg|]}t�|��qSr)�Option)r(�
option_tagrPrrr-�s�z%Parameter.options.<locals>.<listcomp>r4)r/r0rrPrrPrr7�s
�zParameter.optionscCs&|j�td��}|dkrdSt||�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)r/r�rr)r1�link_tagrrrr��s	zParameter.linkcCs|j}|dkrtd��|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.
        Nz(This parameter isn't a link to anything.)r�r.�follow)r1r�rrr�linked_resources
zParameter.linked_resourceN)rrrr rCr�r5r%rar6r:r�r7r�r�rrrrr�s&





	


c@s$eZdZdZdd�Zedd��ZdS)r�z0One of a set of possible values for a parameter.cCs||_||_dS)z}Initialize the option.

        :param parameter: A Parameter.
        :param link_tag: An ElementTree <option> tag.
        N)r�r/)r1r�r�rrrrCszOption.__init__cCs|jj�d�S)Nr3r�rPrrrr3szOption.valueN)rrrr rCr�r3rrrrr�s	r�csHeZdZdZ�fdd�Zedd��Zedd��Zdd	�Zd
d�Z	�Z
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'.
    cs"tt|��|j�||_||_dS)zyInitialize the link.

        :param parameter: A Parameter.
        :param link_tag: An ElementTree <link> tag.
        N)rRrrCrBr�r/)r1r�r�r_rrrC(sz
Link.__init__cCs|jstd��|��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_followr
rKrPrrrr�2szLink.followcCs(z|��}Wntk
r"YdSXdS)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)rEr
)r1Zdefinition_urlrrrr�;s
zLink.can_followcCs t|j|j��|jj�|�j�S)z,Turn a resource type ID into a ResourceType.)rrBr�r�r�r'r/rNrrrrGHs
�zLink._definition_factorycCs"|jj�d�}|dkrtd��|S)z(Find the URL containing the definition .r]NzIParameter is a link, but not to a resource with a known WADL description.)r/r&r'r
)r1rarrrrENszLink._get_definition_url)rrrr rCr�r�r�rGrEr�rrr_rr!s


c@seZdZdZdd�ZdS)r	z,A wrapper around an XML <resource_type> tag.cCs
||_dS)zvInitialize with a <resource_type> tag.

        :param resource_type_tag: An ElementTree <resource_type> tag.
        N)r/)r1Zresource_type_tagrrrrCZszResourceType.__init__N)rrrr rCrrrrr	Wsc@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)rz1A WADL document made programmatically accessible.cCs�||_t|d�r|�|�|_n|�|�|_|j�td��|_|jj�	d�|_
i|_i|_|j�
td��D].}|j�	d�}|dk	rht|d|�}||j|<qh|j�
td��D]}|jd}t|�|j|<q�dS)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�	resourcesrerVrONr])rc�hasattr�_from_streamr��_from_stringr�rr�r&r'�
resource_baser�r�r0rr	)r1rc�markuprVrOrJr]rrrrCes(
�
zApplication.__init__cCsvd}d}g}t�||�D]R\}}|dkr4|�|�q|dkrF|��q|dkr|dkrZ|}|�tt|��qt�|�S)zrTurns markup into a document.

        Just a wrapper around ElementTree which keeps track of namespaces.
        )�start�start-ns�end-nsNr�r�r�)�ETZ	iterparser��pop�setr�rZElementTree)r1�streamZevents�rootr�Zevent�elemrrrr�~s
zApplication._from_streamcCs$t|t�s|�d�}|�t�|��S)zTurns markup into a document.r�)rTr�r�r�r�r�)r1r�rrrr��s

zApplication._from_stringcCs.|�|�}|j�|�}|dkr*td|��|S)z7Retrieve a resource type by the URL of its description.NrD)rFr�r'rH)r1Zresource_type_urlrIr]rrrrU�s

zApplication.get_resource_typecCs^t|j���}d|_|�d�r,t|���}n
|�|�}|j}d|_||krN|Std|��dS)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.
        NZhttpz,Can't look up definition in another url (%s))rrcZ
ensureNoSlashZfragment�
startswithZresolverM)r1r\Z
markup_uriZthis_uriZpossible_xml_idrrrrF�s

�zApplication.lookup_xml_idcsV�fdd�|jD�}t|�dkr$dSt|�dkr<td���t|t|j�d�|d�S)zpLocate one of the resources described by this document.

        :param path: The path to the resource.
        csg|]}|jd�kr|�qS�r�)r&)r(r+r�rrr-�s�z4Application.get_resource_by_path.<locals>.<listcomp>r�Nz+More than one resource defined with path %sTr)r�r8r
rrr�)r1r�Zmatchingrr�r�get_resource_by_path�s��z Application.get_resource_by_pathN)
rrrr rCr�r�rUrFr�rrrrrbs )4r raZ
__metaclass__�__all__r�Zemail.utilsrr�rWr�r�r�r�Zurllib.parser
�ImportErrorZurllibZxml.etree.cElementTreeZetreeZcElementTreer�Zlazr.urirrZwadllibrrZwadllib.iso_strptimerr�rrrr�	Exceptionr
rr!r�r"r#r@rrr�rrrr�rr	rrrrr�<module>sh�
	
B=>j9B!]6