+
    :hO                     
   R t . R+Ot^ RIt^ RIHt ^ RIt^ RIt^ RIt^ RIt^ RI	t	^ RI
t
^ RIHt ^ RIHu Ht ^ RIHtHt ^ RIHt RtRtR tR tR t ! R R
]4      t ! R R]4      t ! R R]4      t ! R R4      t ! R R4      t  ! R R]4      t! ! R R]!4      t" ! R  R]4      t# ! R! R"]] 4      t$ ! R# R] 4      t% ! R$ R]!] 4      t& ! R% R]4      t' ! R& R']4      t( ! R( R]!4      t) ! R) R	]4      t* ! R* R]4      t+R# ),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	WADLErrorN)quote)	urlencode)URImerge)iso_strptimez	xmlns:mapz http://www.w3.org/2001/XMLSchemac                    RV ,           # )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_tagr   =   s    3h>>    c                &    R\        V 4      ,           # )z#Turn a tag name into an XPath path.z./)r   r   s   &r   
wadl_xpathr   B   s    (8$$$r   c                 J    / pV  F  pVf   K	  VP                  V4       K  	  V# )z<Merge any number of dictionaries, some of which may be None.)update)dictsfinaldicts   *  r   _merge_dictsr   G   s*    ELL  Lr   c                       ] tR t^PtRtRtR# )r   zAAn exception having to do with the state of the WADL application.r   N__name__
__module____qualname____firstlineno____doc____static_attributes__r   r   r   r   r   P   s    Kr   c                       ] tR t^UtRtRtR# )r   a-  An 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.
r   Nr!   r   r   r   r   r   U   s    r   c                       ] tR t^_tRtRtR# )UnsupportedMediaTypeErrorzA media type was given that's not supported in this context.

A resource can only be bound to media types it has representations
of.
r   Nr!   r   r   r   r*   r*   _   s    r   r*   c                       ] tR t^gtRtRtR# )WADLBasez?A base class for objects that contain WADL-derived information.r   Nr!   r   r   r   r,   r,   g   s    Ir   r,   c                   8   a  ] tR t^kt o RtRR ltRR ltRtV tR# )HasParametersMixinzAA mixin class for objects that have associated Parameter objects.Nc                8   Vf   V P                   pVf   \        R4      hV P                  f   . # V P                  P                  \	        R4      4      pVf   . # V Uu. uF0  pVP
                  P                  R4      V9   g   K%  \        W$4      NK2  	  up# u upi )z6Find subsidiary parameters that have the given styles.z&Could not find any particular resourceparamstyle)resource
ValueErrortagfindallr   attribgetr   )selfstylesr2   
param_tags	param_tags   &&&  r   paramsHasParametersMixin.paramsn   s    }}HEFF88IXX%%j&9:
I!+<!+I##''0F: /	(.!+< 	< <s   "BBc                   \        W$4      p/ pV EF,  pVP                  pVP                  eT   Wr9   d@   W',          VP                  8w  d)   \        RW',          : RV: RVP                  : R24      hVP                  W'&   VP                   Uu. uF  qP
                  NK  	  p	p\        V	4      ^ 8  dA   Wr9   d;   W',          V	9  d.   \        RW',          : RV: RRP                  V	4      : R24      hV'       d+   VP                  '       d   Wr9  d   \        R	V,          4      hWr9   g   EK   W',          WW&   W' EK/  	  \        V4      ^ 8  d0   \        R
RP                  VP                  4       4      ,          4      hV# u upi )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.
zValue 'z' for parameter 'z' conflicts with fixed value ''zInvalid value 'z': valid values are: "z", ""z$No value for required parameter '%s'zUnrecognized parameter(s): '%s'z', ')
r   namefixed_valuer3   optionsvaluelenjoinis_requiredkeys)
r8   r<   param_valuesenforce_completenesskw_param_valuesvalidated_valuesr0   rA   optionrC   s
   &&&&,     r   validate_param_values(HasParametersMixin.validate_param_values}   so   " $LBE::D  ,((.%2C2CC$(4(:(:D(-(9(9&; < < &+%6%6"27--@-||-G@Gq T%9$*'9 $**D&++g2F"H I I %):):):0 !G#'"( ) )#)5); & &- . |q >%{{<+<+<+>?@ A A! As   Fr   N)T)	r"   r#   r$   r%   r&   r<   rN   r'   __classdictcell____classdict__s   @r   r.   r.   k   s     K<-  - r   r.   c                   <   a  ] tR t^t o RtR tR tR tR tRt	V t
R# )WADLResolvableDefinitionz=A base class for objects whose definitions may be references.c                     RV n         Wn        R# )zInitialize with a WADL application.

:param application: A WADLDefinition. Relative links are
    assumed to be relative to this object's URL.
N_definitionapplication)r8   rY   s   &&r   __init__!WADLResolvableDefinition.__init__   s      &r   c                   V P                   e   V P                   # V P                  4       pVf	   W n         V # V P                  P                  V4      pV P	                  V4      pVf   \        RV,          4      hW0n         V# )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")rX   _get_definition_urlrY   lookup_xml_id_definition_factoryKeyError)r8   
object_urlxml_id
definitions   &   r   resolve_definition+WADLResolvableDefinition.resolve_definition   s     '###--/
  $K !!//
;--f5
 1J>??%r   c                    \        4       h)zhTransform an XML ID into a wadllib wrapper object.

Which kind of object it is depends on the subclass.
NotImplementedErrorr8   ids   &&r   r`   ,WADLResolvableDefinition._definition_factory       
 "##r   c                    \        4       h)z]Find the URL that identifies an external reference.

How to do this depends on the subclass.
rh   r8   s   &r   r^   ,WADLResolvableDefinition._get_definition_url   rm   r   rW   N)r"   r#   r$   r%   r&   rZ   re   r`   r^   r'   rQ   rR   s   @r   rU   rU      s"     G' D$$ $r   rU   c                      a a ] tR t^t oRtRV 3R llt]R 4       t]R 4       t]R 4       t	RR lt
R tRR ltRR	 ltRR
 lt]R 4       tRR ltR tR tR tR tRR ltR tRtVtV ;t# )r	   z/A resource, possibly bound to a representation.c                X  < \         SV `  V4       W n        \        V\        4      '       d,   V P
                  P                  V4      P                  V n        MW0n        RV n        Ve   VR8X  dq   V'       db   \        VR4      '       d+   \        P                  ! VP                  4       4      V n        M>\        P                  ! \	        V4      4      V n        MW@n        M\        RV,          4      hWPn        Ve/   Ve	   Wpn        R# V P!                  V P                  4      V n        R# R# )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/jsondecodez?This resource doesn't define a representation for media type %s)superrZ   _url
isinstancestrrY   get_resource_typer4   representationhasattrjsonloadsrt   r*   
media_typerepresentation_definitionget_representation_definition)	r8   rY   urlresource_typerz   r~   representation_needs_processingr   	__class__s	   &&&&&&&&r   rZ   Resource.__init__   s   * 	%	mS)) ''99-HLLDH %H"%//2~x88.2jj*113/5+ /3jj^9L.M+*8'/$&012 2 %%(41J. 66tG .	 &r   c                    V P                   # )z Return the URL to this resource.)rv   ro   s   &r   r   Resource.url$  s     yyr   c                Z   V P                   f   R# V P                   P                  P                  R4      pVe   V# V P                   P                  P                  R4      pVeG   \        V P                  P
                  4      P                  4       p\        V4      R,           V,           # R# )z@Return the URL to the type definition for this resource, if any.Ntyperk   #)r4   r6   r7   r   rY   
markup_urlensureSlashrx   )r8   r   type_idbases   &   r   type_urlResource.type_url)  s     88hhoo!!&)?J((//%%d+t''223??ADt9s?W,, r   c                <    V P                   P                  R,          # )zReturn the ID of this resource.rk   )r4   r6   ro   s   &r   rk   Resource.id;  s     xxt$$r   c           	     ^    \        V P                  V P                  V P                  WVV4      # )a7  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	   rY   r   r4   )r8   rz   r~   r   r   s   &&&&&r   bindResource.bind@  s.    " (($((DHH&713 	3r   c                    V P                  R4      P                  pV FA  pVP                  4       P                  pVP                  P                  R4      V8X  g   K?  Vu # 	  \        RV,          4      h)z<Get a description of one of this resource's representations.GET	mediaTypez4No definition for representation with media type %s.)
get_methodresponsere   r4   r6   r7   r*   )r8   r~   default_get_responserz   representation_tags   &&   r   r   &Resource.get_representation_definitionV  st    #u5>>2N!/!B!B!D!H!H!((,,[9ZG%% 3 ( )>@J)K L 	Lr   c                
   V P                  4        Fn  pVP                  P                  RR4      P                  4       pVe   WaP                  4       8X  g   KG  \	        W4      pVP                  W#V4      '       g   Kl  Vu # 	  R# )a  Look 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_iterr6   r7   lowerr   is_described_by)r8   http_methodr~   query_paramsrepresentation_params
method_tagrA   methods   &&&&&   r   r   Resource.get_method`  sz    0 //1J$$((4::<D"d.?.?.A&A1))**?A A!M 2 r   c                B    V P                  V4      P                  V 4      # )aN  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<   r8   r~   s   &&r   
parametersResource.parameters  s#     33t	%r   c                B    V P                  V4      P                  V 4      # )aR  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   &&r   r   Resource.parameter_names  s$     33'-	.r   c              #  V   "   V P                  4        F  p\        W4      x  K  	  R# 5i)z6An iterator over the methods defined on this resource.N)r   r   )r8   r   s   & r   method_iterResource.method_iter  s%      //1J** 2s   ')c                    V P                  V4      pVP                  pVP                  \        R4      4       F0  pVP                  P                  R4      V8X  g   K%  \        W4      u # 	  R# )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.
r0   rA   N)r   r4   r5   r   r6   r7   r   )r8   
param_namer~   rd   r   r;   s   &&&   r   get_parameterResource.get_parameter  sb     99*E
'^^+33Jw4GHI##F+z9 11 I r   c                x   V P                   f   \        R4      hV P                  R8X  d   VP                  R8w  d   \	        RVP                  ,          4      hV P                   VP
                  ,          pVeI   V P                  VP                  VP                  4      w  r4V\        8X  d   VR9   d    \        V4      pV# V# \	        RV P                  ,          4      h  \         dP     \        P                  ! \        P                  ! TR4      R,          !  p T#   \         d    \        T4      hi ; ii ; i)	zFind 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.rs   plain8Don't know how to find value for a parameter of type %s.z%Y-%m-%d:       NzEPath traversal not implemented for a representation of media type %s.)dateTimedate)rz   r   r~   r1   ri   rA   _dereference_namespacer4   r   XML_SCHEMA_NS_URIr   r3   datetimetimestrptime)r8   	parameterrD   namespace_url	data_types   &&   r   get_parameter_valueResource.get_parameter_value  sA    &,>@ @??00 '))!*12 2 ''	7E +/+F+FMM9>>,3(!%66%)==4 ,U 3 L5L! #G$(OO#4 5 	5 & 	44$,$5$5"&--z"B3"G%JE L  * 4 #-U"33	4	4s   4C D9+0DD55D9c                    Ve   RV9   d   VP                  R^4      w  r2MRpVP                  \        4      pVP                  VR4      pWR3# )zxSplits a value into namespace URI and value.

:param tag: A tag to use as context when mapping namespace
names to URIs.
N:r   )splitr7   NS_MAP)r8   r4   rD   	namespacens_mapr   s   &&&   r   r   Resource._dereference_namespace  sP     ${{32IuI

9d3##r   c                L    V P                   P                  P                  V4      # )z-Given an ID, find a ResourceType for that ID.)rY   resource_typesr7   rj   s   &&r   r`   Resource._definition_factory  s    ..22266r   c                L    V P                   P                  P                  R4      # )zReturn 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   r4   r6   r7   ro   s   &r   r^   Resource._get_definition_url       xx""6**r   c                    V P                   e+   V P                  P                  4       pVP                  4       # Ve"   V P                  V4      pVP                  4       # \	        R4      h)a  Get 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.)rz   r   re   r   r   )r8   r~   rd   s   && r   r   (Resource._find_representation_definition  st    * * 77JJLJ ,,.. #;;JGJ
 ,,.. -,- -r   c              #     "   V P                  4       P                  pVP                  \        R4      4       Rj  xL
  R#  L5i)z+Iterate over this resource's <method> tags.r   N)re   r4   r5   r   r8   rd   s   & r   r   Resource._method_tag_iter   s2     ,,.22
%%j&:;;;s   8AAA)rv   r~   rz   r   r4   )NNTN)rs   TN)NNNNrP   )r"   r#   r$   r%   r&   rZ   propertyr   r   rk   r   r   r   r   r   r   r   r   r   r`   r^   r   r   r'   rQ   __classcell__r   rS   s   @@r   r	   r	      s     95In    " % %3,LB%. + +
&-5^$7+ /D< <r   c                      a  ] tR tRt o RtR t]R 4       t]R 4       t]R 4       t	]R 4       t
RR	 ltRR
 ltRR ltRtV tR# )r   i&  z*A wrapper around an XML <method> tag.
    c                T    Wn         V P                   P                  V n        W n        R# )zQInitialize with a <method> tag.

:param method_tag: An ElementTree <method> tag.
N)r2   rY   r4   )r8   r2   r   s   &&&r   rZ   Method.__init__)  s     
 !==44r   c                \    \        W P                  P                  \        R4      4      4      # )z@Return the definition of a request that invokes the WADL method.request)RequestDefinitionr4   findr   ro   s   &r   r   Method.request2  s!     !xx}}Z	5J'KLLr   c                r    \        V P                  V P                  P                  \	        R4      4      4      # )z9Return the definition of the response to the WADL method.r   )r   r2   r4   r   r   ro   s   &r   r   Method.response7  s.     "$--"&((--
:0F"GI 	Ir   c                L    V P                   P                  P                  R4      # )z)The XML ID of the WADL method definition.rk   r   ro   s   &r   rk   	Method.id=  s     xx""4((r   c                h    V P                   P                  P                  R4      P                  4       # )zThe 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   r4   r6   r7   r   ro   s   &r   rA   Method.nameB  s&     xx""6*0022r   Nc                <    V P                   P                  ! V3/ VB # )4Return the request URL to use to invoke this method.)r   	build_url)r8   rI   rK   s   &&,r   build_request_urlMethod.build_request_urlK  s    ||%%lFoFFr   c                <    V P                   P                  ! W3/ VB # )zrBuild a representation to be sent when invoking this method.

:return: A 2-tuple of (media_type, representation).
)r   rz   )r8   r~   rI   rK   s   &&&,r   build_representationMethod.build_representationO  s&     ||**9(79 	9r   c                   RpVe"   V P                   P                  V4      pVf   R# VeA   \        V4      ^ 8  d1   V P                   pVf   R#  VP                  VP                  VR4       Ve   \        V4      ^ 8X  d   R# Ve   VP                  V4      # V P                   P                   F1  p VP                  VP                  V P                  4      VR4        R# 	  R#   \
         d     R# i ; i  \
         d     KW  i ; i)a  Returns 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.
NFT)
r   r   rE   rN   r   r3   r   representationsr<   r2   )r8   r~   query_valuesrepresentation_valuesrz   r   s   &&&&  r   r   Method.is_described_byX  s   $ !!\\GGN%#L(9A(=llG --((,? "),-2%!11%' '"ll::N44"))$--8)52  ; '  "  s$   C$ 1,C6$C32C36DD)rY   r2   r4   rP   NN)NNN)r"   r#   r$   r%   r&   rZ   r   r   r   rk   rA   r   r   r   r'   rQ   rR   s   @r   r   r   &  sx      M M I I
 ) ) 3 3G95 5r   c                   h   a  ] tR tRt o RtR t]R 4       t]R 4       tRR lt	RR lt
RR	 ltR
tV tR# )r   i  zBA wrapper around the description of the request invoking a method.c                    Wn         V P                   P                  V n        V P                  P                  V n        W n        R# )zInitialize with a <request> tag.

:param resource: The resource to which this request can be sent.
:param request_tag: An ElementTree <request> tag.
N)r   r2   rY   r4   )r8   r   request_tags   &&&r   rZ   RequestDefinition.__init__  s1     ,,==44r   c                &    V P                  R.4      # )z,Return the query parameters for this method.query)r<   ro   s   &r   r   RequestDefinition.query_params  s     {{G9%%r   c              #     "   V P                   P                  \        R 4      4       F&  p\        V P                  V P
                  V4      x  K(  	  R# 5i)rz   N)r4   r5   r   r   rY   r2   r   s   & r   r   !RequestDefinition.representations  sC     ((**:6F+GHJ*  $--= = Is   AANc                ^    V P                    F  pVe   VP                  V8X  g   K  Vu # 	  R# )z1Return the appropriate representation definition.N)r   r~   r8   r~   rz   s   && r   r   /RequestDefinition.get_representation_definition  s0    "22N!^%>%>*%L%% 3 r   c                v    V P                  V4      pVf   \        RV,          4      hVP                  ! V3/ VB # )zpBuild 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)r   	TypeErrorr   )r8   r~   rI   rK   rd   s   &&&, r   rz    RequestDefinition.representation  sF     77
C
J() * *|???r   c                   V P                   ! V P                  V3/ VB pV P                  P                  p\	        V4      ^ 8  d<   RV9   d   RpMRpWE\        \        VP                  4       4      4      ,           ,          pV# )r   ?&)rN   r   r2   r   rE   r   sorteditems)r8   rI   rK   rL   r   appends   &&,   r   r   RequestDefinition.build_url  s|    55|@/>@mm 1$czIf-=-C-C-E&FGGGC
r   )rY   r   r2   r4   rP   r   )r"   r#   r$   r%   r&   rZ   r   r   r   r   rz   r   r'   rQ   rR   s   @r   r   r     sJ     L	 & & = =

@ r   r   c                   L   a  ] tR tRt o RtRR ltR tR tR tR t	R	 t
R
tV tR# )r   i  z;A wrapper around the description of a response to a method.Nc                L    VP                   V n         Wn        W n        W0n        R# )zWInitialize with a <response> tag.

:param response_tag: An ElementTree <response> tag.
N)rY   r2   r4   headers)r8   r2   response_tagr  s   &&&&r   rZ   ResponseDefinition.__init__  s!    
 $// r   c              #     "   \        R4      pV P                  P                  V4       F0  p\        V P                  P
                  V P                  V4      x  K2  	  R# 5i)zGet an iterator over the representation definitions.

These are the representations returned in response to an
invocation of this method.
rz   N)r   r4   r5   r   r2   rY   )r8   pathr   s   &  r   __iter__ResponseDefinition.__iter__  sQ      *+"&(("2"24"8*))4==:LN N #9s   AAc                D    \        V P                  V P                  V4      # )zwBind the response to a set of HTTP headers.

A WADL response can have associated header parameters, but no
other kind.
)r   r2   r4   )r8   r  s   &&r   r   ResponseDefinition.bind  s     "$--7CCr   c                    V P                   P                  \        R4      4       FR  pVP                  P	                  R4      V8X  g   K%  VP                  P	                  R4      R8X  g   KG  \        W4      u # 	  R# )z,Find a header parameter within the response.r0   rA   r1   headerN)r4   r5   r   r6   r7   r   )r8   r   r;   s   && r   r    ResponseDefinition.get_parameter  sb    ))*W*=>I  $$V,
:!((,,W5A 11 ? r   c                    V P                   f   \        R4      hVP                  R8w  d   \        RVP                  ,          4      hV P                   P	                  VP
                  4      # )z:Find the value of a parameter, given the Parameter object.z,Response object is not bound to any headers.r  r   )r  r   r1   ri   r7   rA   )r8   r   s   &&r   r   &ResponseDefinition.get_parameter_value  sc    <<,>@ @??h&%&__-. . ||	//r   c                b    V P                   f   R# V  F  pVP                  V8X  g   K  Vu # 	  R# )z8Get one of the possible representations of the response.N)r4   r~   r  s   && r   r   0ResponseDefinition.get_representation_definition  s2    88"N((J6%% # r   )rY   r  r2   r4   rP   )r"   r#   r$   r%   r&   rZ   r  r   r   r   r   r'   rQ   rR   s   @r   r   r     s-     E	ND	0 r   c                      a a ] tR tRt oRtV 3R ltV 3R ltR t]R 4       t	R t
R tRR	 ltR
 tR tR tR tRtVtV ;t# )r   i  z2A definition of the structure of a representation.c                >   < \         SV `  V4       W n        W0n        R # rP   )ru   rZ   r2   r4   )r8   rY   r2   r   r   s   &&&&r   rZ   !RepresentationDefinition.__init__  s    % %r   c                (   < \         SV `  R R.V4      # )r  r   )ru   r<   )r8   r2   r   s   &&r   r<   RepresentationDefinition.params  s    w~w0(;;r   c                `    V P                  V4       Uu. uF  q"P                  NK  	  up# u upi )z#Return the names of all parameters.)r<   rA   )r8   r2   r0   s   && r   r   (RepresentationDefinition.parameter_names  s'    (,H(=>(=u

(=>>>s   +c                X    V P                  4       P                  P                  R,          # )z4The media type of the representation described here.r   )re   r4   r6   ro   s   &r   r~   #RepresentationDefinition.media_type  s$     &&(,,33K@@r   c                   \        \        \        P                  ^,
          4      4      pRV,          p\        P
                  ! \        P                  4      pRW4,          ,           R,           pVf   V# Tp^ p R\        P                  ! V4      ,           R,           P                  R4      p\        P                  ! W\        P                  R7      '       g    V# VR,           \        V4      ,           pV^,          pK  )	z;Make a random boundary that does not appear in `all_parts`.z%%0%ddz==z^--z(--)?$ascii)flags.z===============)rE   reprsysmaxsizerandom	randrangereescapeencodesearch	MULTILINErx   )	r8   	all_parts_width_fmttokenboundarybcounterpatterns	   &&       r   _make_boundary'RepresentationDefinition._make_boundary  s    T#++/*+&   -.5Oryy|+h6>>wGG99Wr||DD  3W-AqLGr   c                   V Fg  w  r4VP                  VP                  R4      4       VP                  R4       VP                  VP                  R4      4       VP                  R4       Ki  	  VP                  R4       R# )z$Write MIME headers to a file object.UTF-8s   :    
Nwriter8  )r8   bufr  keyrD   s   &&&  r   _write_headers'RepresentationDefinition._write_headers1  s^    !JCIIcjj)*IIeIIell7+,IIg	 "
 			'r   c                    VP                  R4       VP                  VP                  R4      4       V'       d   VP                  R4       VP                  R4       R# )z,Write a multipart boundary to a file object.s   --rF  rG  NrH  )r8   rJ  r?  closings   &&&&r   _write_boundary(RepresentationDefinition._write_boundary:  s>    		%		(//'*+IIe		'r   c                   . pV EF  w  r4p\         P                  ! 4       pV'       d!   RpR\        V4      : R\        V4      : R2pMRpR\        V4      ,          pV P                  VRRV3RV3.4       V'       dD   \	        V\
        4      '       g   \        R	\        V4      ,          4      hVP                  V4       M\	        V\        4      '       g   \        R
\        V4      ,          4      h\        P                  ! RV4      p	V	RR  F4  p
VP                  V
P                  R4      4       VP                  R4       K6  	  VP                  V	R,          P                  R4      4       VP                  VP                  4       4       EK  	  V P                  RP!                  V4      4      p\         P                  ! 4       pR\        V4      ,          pV P                  VRRV3.4       V F6  pV P#                  Wk4       VP                  V4       VP                  R4       K8  	  V P#                  WkRR7       WvP                  4       3# )a  Generate 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.
zapplication/octet-streamzform-data; name="z"; filename="r@   ztext/plain; charset="utf-8"zform-data; name="%s"zContent-TypezContent-Dispositionzbytes payload expected: %szstring payload expected: %sz
\r\n|\r|\nNrF  rG  z"multipart/form-data; boundary="%s"T)rO  )zMIME-Versionz1.0)ioBytesIOr   rL  rw   bytesr	  r   rI  rx   r6  r   r8  r  getvaluerC  rF   rP  )r8   partsencoded_parts	is_binaryrA   rD   rJ  ctypecdisplinesliner?  encoded_parts   &&           r   _generate_multipart_form1RepresentationDefinition._generate_multipart_formB  s    &+"IU**,C2 $Kt. 6.t<''&.& 
 !%//#$@4;$NOO		% !%--#5UCE E6!#2JDIIdkk'23IIg& ' 		%)**734  0? ',D &&w||M'BC jjl4uXFC#U#" 	 *L  /IIl#IIg * 	SD9lln$$r   c                R   V P                  4       pVP                  V P                  4      pV P                  ! WA3/ VB pV P                  pVR8X  d&   \        \        VP                  4       4      4      pWg3# VR8X  dz   . p\        4       p	V FQ  p
VP                  V
P                  V	4      pWJg   K&  VP                  V
P                  R8H  V
P                  V34       KS  	  V P                  V4      w  rgWg3# VR8X  d   \        P                  ! V4      pWg3# \!        RV,          4      h)zjBind the definition to parameter values, creating a document.

:return: A 2-tuple (media_type, document).
z!application/x-www-form-urlencodedzmultipart/form-databinaryrs   zUnsupported media type: '%s')re   r<   r2   rN   r~   r   r  r  objectr7   rA   r  r   r`  r|   dumpsr3   )r8   rI   rK   rd   r<   rL   r~   docrX  missingr0   rD   s   &&,         r   r   RepresentationDefinition.bind  s)   
 ,,.
""4==1555$35__
<<F#3#9#9#;<=C  00EhG(,,UZZA'LL%**"8%**e!LM   #;;EBOJ
 	 --**-.C  ;jHIIr   c                L    V P                   P                  P                  V4      # )z9Turn a representation ID into a RepresentationDefinition.)rY   representation_definitionsr7   rj   s   &&r   r`   ,RepresentationDefinition._definition_factory  s    ::>>rBBr   c                L    V P                   P                  P                  R4      # )zFind 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   ro   s   &r   r^   ,RepresentationDefinition._get_definition_url  r   r   )r2   r4   )F)r"   r#   r$   r%   r&   rZ   r<   r   r   r~   rC  rL  rP  r`  r   r`   r^   r'   rQ   r   r   s   @@r   r   r     sX     <&
<? A A$@%D4C+ +r   c                      a  ] tR tRt o RtR t]R 4       t]R 4       t]R 4       t	]R 4       t
]R 4       tR	 t]R
 4       t]R 4       t]R 4       tRtV tR# )r   i  z5One of the parameters of a representation definition.c                @    VP                   V n         Wn        W n        R# )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)rY   value_containerr4   )r8   rq  r4   s   &&&r   rZ   Parameter.__init__  s     +66.r   c                L    V P                   P                  P                  R4      # )zThe name of this parameter.rA   r   ro   s   &r   rA   Parameter.name       xx""6**r   c                L    V P                   P                  P                  R4      # )zThe style of this parameter.r1   r   ro   s   &r   r1   Parameter.style  s     xx""7++r   c                L    V P                   P                  P                  R4      # )zThe XSD type of this parameter.r   r   ro   s   &r   r   Parameter.type  ru  r   c                L    V P                   P                  P                  R4      # )a  The 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   ro   s   &r   rB   Parameter.fixed_value  s     xx""7++r   c                p    V P                   P                  P                  RR4      P                  4       R9   # )z6Whether or not a value for this parameter is required.requiredfalse)1truer   ro   s   &r   rG   Parameter.is_required  s2     ##J8>>@ ! 	"r   c                8    V P                   P                  V 4      # )zThe 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.
)rq  r   ro   s   &r   	get_valueParameter.get_value  s     ##77==r   c                    V P                   P                  \        R4      4       Uu. uF  p\        W4      NK  	  up# u upi )z7Return the set of acceptable values for this parameter.rM   )r4   r5   r   Option)r8   
option_tags   & r   rC   Parameter.options  sF     #'(("2"2:h3G"HJ"HJ t("HJ 	J Js   >c                l    V P                   P                  \        R4      4      pVf   R# \        W4      # )zGet 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)r4   r   r   r   )r8   link_tags   & r   r  Parameter.link  s/     88==F!34D##r   c                P    V P                   pVf   \        R4      hVP                  # )zFollow 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.)r  r3   follow)r8   r  s   & r   linked_resourceParameter.linked_resource  s(     yy<GHH{{r   )rY   r4   rq  N)r"   r#   r$   r%   r&   rZ   r   rA   r1   r   rB   rG   r  rC   r  r  r'   rQ   rR   s   @r   r   r     s     ? + + , , + + , , " "
> J J
 $ $  r   c                   :   a  ] tR tRt o RtR t]R 4       tRtV t	R# )r  i
  z0One of a set of possible values for a parameter.c                    Wn         W n        R# )zeInitialize the option.

:param parameter: A Parameter.
:param link_tag: An ElementTree <option> tag.
Nr   r4   )r8   r   r  s   &&&r   rZ   Option.__init__  s     #r   c                L    V P                   P                  P                  R 4      # )rD   r   ro   s   &r   rD   Option.value  s    xx""7++r   r  N)
r"   r#   r$   r%   r&   rZ   r   rD   r'   rQ   rR   s   @r   r  r  
  s!     : , ,r   r  c                   b   a a ] tR tRt oRtV 3R lt]R 4       t]R 4       tR t	R t
RtVtV ;t# )	r   i  zA 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                R   < \         SV `  VP                  4       Wn        W n        R# )zaInitialize the link.

:param parameter: A Parameter.
:param link_tag: An ElementTree <link> tag.
N)ru   rZ   rY   r   r4   )r8   r   r  r   s   &&&r   rZ   Link.__init__"  s"     	../"r   c                \    V P                   '       g   \        R4      hV P                  4       # )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   re   ro   s   &r   r  Link.follow,  s0      . / / &&((r   c                L     V P                  4        R#   \         d     R# i ; i)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)r^   r   ro   s   &r   r  Link.can_follow5  s,    	$$&   		s    ##c                    \        V P                  V P                  P                  4       V P                  P                  P                  V4      P                  4      # )z,Turn a resource type ID into a ResourceType.)r	   rY   r   r  r   r7   r4   rj   s   &&r   r`   Link._definition_factoryB  sG    dnn668++//3779 	9r   c                n    V P                   P                  P                  R4      pVf   \        R4      hV# )z(Find the URL containing the definition .r   zIParameter is a link, but not to a resource with a known WADL description.)r4   r6   r7   r   )r8   r   s   & r   r^   Link._get_definition_urlH  s6    xx""?3< = > >r   r  )r"   r#   r$   r%   r&   rZ   r   r  r  r`   r^   r'   rQ   r   r   s   @@r   r   r     sF      ) ) 
 
9 r   c                   *   a  ] tR tRt o RtR tRtV tR# )r
   iQ  z,A wrapper around an XML <resource_type> tag.c                    Wn         R# )zfInitialize with a <resource_type> tag.

:param resource_type_tag: An ElementTree <resource_type> tag.
Nr4   )r8   resource_type_tags   &&r   rZ   ResourceType.__init__T  s	    
 %r   r  N)r"   r#   r$   r%   r&   rZ   r'   rQ   rR   s   @r   r
   r
   Q  s     6% %r   c                   H   a  ] tR tRt o RtR tR tR tR tR t	R t
R	tV tR
# )r   i\  z1A WADL document made programmatically accessible.c                   Wn         \        VR4      '       d   V P                  V4      V n        MV P	                  V4      V n        V P                  P                  \        R4      4      V n        V P                  P                  P                  R4      V n
        / V n        / V n        V P                  P                  \        R4      4       F?  pVP                  P                  R4      pVf   K$  \        V RV4      pWPP                  V&   KA  	  V P                  P                  \        R4      4       F.  pVP                  R,          p\        V4      V P                  V&   K0  	  R# )zParse 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   rz   rk   Nr   )r   r{   _from_streamrf  _from_stringr   r   r  r6   r7   resource_baserj  r   r5   r   r
   )r8   r   markuprz   rk   rd   r   s   &&&    r   rZ   Application.__init___  s     %66""((0DH((0DHz+'>?!^^2266v>*,' "hh..z:J/KLN&&**40B~5$0
6@//3 M "XX--j.IJM%%d+B&2=&AD# Kr   c                :   RpRp. p\         P                  ! W4       Ff  w  rVVR8X  d   VP                  V4       K  VR8X  d   VP                  4        K8  VR8X  g   KA  Vf   TpVP	                  \
        \        V4      4       Kh  	  \         P                  ! V4      # )zbTurns markup into a document.

Just a wrapper around ElementTree which keeps track of namespaces.
startstart-nsend-nsN)r  r  r  )ET	iterparser  popsetr   r   ElementTree)r8   streameventsrootr   eventelems   &&     r   r  Application._from_streamx  s    
 /<<7KE
"d#("

'!<Df. 8 ~~d##r   c                    \        V\        4      '       g   VP                  R4      pV P                  \        P
                  ! V4      4      # )zTurns markup into a document.rF  )rw   rV  r8  r  rT  rU  )r8   r  s   &&r   r  Application._from_string  s7    &%((]]7+F  F!344r   c                    V P                  V4      pV P                  P                  V4      pVf   \        RV,          4      hV# )z7Retrieve a resource type by the URL of its description.r]   )r_   r   r7   ra   )r8   resource_type_urlrc   r   s   &&  r   ry   Application.get_resource_type  sG    ##$56++//7 14EEFFr   c                4   \        V P                  4      P                  4       pRVn        VP	                  R4      '       d   \        V4      P                  4       pMVP                  V4      pVP                  pRVn        W28X  d   V# \        RV,          4      h)zA 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))r   r   ensureNoSlashfragment
startswithresolveri   )r8   r   
markup_urithis_uripossible_xml_ids   &&   r   r_   Application.lookup_xml_id  s     )779
"
>>&!!3x--/H "))#.H"++ ! #" " #-/2#3 4 	4r   c                0   V P                    Uu. uF  pVP                  R,          V8X  g   K  VNK!  	  pp\        V4      ^8  d   R# \        V4      ^8  d   \        RV,          4      h\	        V \        V P                  VR4      V^ ,          4      # u upi )z`Locate one of the resources described by this document.

:param path: The path to the resource.
r  Nz+More than one resource defined with path %sT)r  r6   rE   r   r	   r   r  )r8   r  r2   matchings   &&  r   get_resource_by_path Application.get_resource_by_path  s     .2^^ 8^v.$6 H^ 8x=1x=1I"# $ $%**D$7!F 	F8s
   BB)rf  r   rj  r  r   r  N)r"   r#   r$   r%   r&   rZ   r  r  ry   r_   r  r'   rQ   rR   s   @r   r   r   \  s/     ;B2$(54@F Fr   )
r   r   r   r   r   r   r   r	   r
   r   ),r&   __all__r   email.utilsr   rT  r|   r4  r6  r2  r   urllib.parser   xml.etree.ElementTreeetreer  r  lazr.urir   r   wadllib.iso_strptimer   r   r   r   r   r   	Exceptionr   r   r*   r,   r.   rU   r	   r   r   r   r   r   r  r   r
   r   r   r   r   <module>r     s1  "
   	   	 
  " " "  -	6 ?
%
		 	
 	 J J?  ? D:$x :$zy<' y<x	gX gT6"4 6r?+ ?D^+79K ^+B[ [|,X ,"3# 3l%8 %nF( nFr   