%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/lazr/restfulclient/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/lazr/restfulclient/__pycache__/resource.cpython-312.pyc

�

}�;e̷���dZeZgd�ZddlmZddlmZddlm	Z	m
Z
	ddlmZm
Z
mZmZmZdd	lZej(dd
k\reZeZneZeZddlmZddlmZdd
lm Z m!Z!ddl"m#Z#ddl$m%Z%ddl&m'Z'e(�Z)Gd�d�Z*Gd�d�Z+Gd�de+�ZGd�de�Z,Gd�de�Z-Gd�de�Z.Gd�de+�Z/Gd�d e�Z0Gd!�d"e�Z1Gd#�d$e1�Z2Gd%�d&e�Z3y	#e$rddlmZmZmZddlm
Z
mZY��wxYw)'z)Common support for web service resources.)�
Collection�CollectionWithKeyBasedLookup�Entry�NamedOperation�Resource�ServiceRoot�)�Message)�BytesIO)�dumps�loads)�parse_qs�unquote�	urlencode�urljoin�urlparse)rrr
)rrN�)r)�__version__)�Browser�RestfulHttp)�DatetimeJSONEncoder)�	HTTPError)�URIc�$�eZdZdZd�Zdd�Zd�Zy)�HeaderDictionarya�A dictionary that bridges httplib2's and wadllib's expectations.

    httplib2 expects all header dictionary access to give lowercase
    header names. wadllib expects to access the header exactly as it's
    specified in the WADL file, which means the official HTTP header name.

    This class transforms keys to lowercase before doing a lookup on
    the underlying dictionary. That way wadllib can pass in the
    official header name and httplib2 will get the lowercased name.
    c��||_y�N)�wrapped_dictionary)�selfrs  �=/usr/lib/python3/dist-packages/lazr/restfulclient/resource.py�__init__zHeaderDictionary.__init__Ks
��"4���Nc�T�|jj|j��S�z2Retrieve a value, converting the key to lowercase.)r�get�lower)r�key�defaults   rr$zHeaderDictionary.getNs���&�&�*�*�3�9�9�;�7�7r!c�X�|j|t�}|turt|��|Sr#)r$�missing�KeyError)rr&�values   r�__getitem__zHeaderDictionary.__getitem__Rs)������g�&���G���3�-���r!r)�__name__�
__module__�__qualname__�__doc__r r$r,�r!rrr?s��	�5�8�r!rc� �eZdZdZdZd�Zd�Zy)�RestfulBasez=Base class for classes that know about lazr.restful services.�application/jsonc��i}|j�D]5\}}t|t�r|j}|||j	|�<�7|Sr)�items�
isinstancer�	self_link�_get_external_param_name)r�
dictionary�new_dictionaryr&r+s     r�_transform_resources_to_linksz)RestfulBase._transform_resources_to_links_sU����$�*�*�,�	G�J�C���%��*�����AF�N�4�8�8��=�>�	G��r!c��|S)aTurn a lazr.restful name into something to be sent over HTTP.

        For resources this may involve sticking '_link' or
        '_collection_link' on the end of the parameter name. For
        arguments to named operations, the parameter name is returned
        as is.
        r1�r�
param_names  rr9z$RestfulBase._get_external_param_namegs
���r!N)r-r.r/r0�JSON_MEDIA_TYPEr<r9r1r!rr3r3Zs��G�(�O��r!r3c���eZdZdZd�Ze�Ze�Ze�Ze	d��Z
e	d��Ze	d��Ze	d��Z
e	d��Ze
Zd�Zd	�Zd
�Zd�Ze					dd
��Zdd�Zd�Zd�Zd�Zd�Zd�Zy)rz+Base class for lazr.restful HTTP resources.c�H�|�|}||jd<||jd<y)z5Initialize with respect to a wadllib Resource object.N�_root�_wadl_resource)�__dict__)r�root�
wadl_resources   rr zResource.__init__us+���<��D�"&��
�
�g��*7��
�
�&�'r!c�8�|j|j�S)z,Name the collections this resource links to.)�_get_parameter_names�FIND_COLLECTIONS�rs r�lp_collectionszResource.lp_collections�s���(�(��)>�)>�?�?r!c�8�|j|j�S)z(Name the entries this resource links to.)rI�FIND_ENTRIESrKs r�
lp_entrieszResource.lp_entries�s���(�(��):�):�;�;r!c�8�|j|j�S)z'Name this resource's scalar attributes.)rI�FIND_ATTRIBUTESrKs r�
lp_attributeszResource.lp_attributes�s���(�(��)=�)=�>�>r!c���g}|jjD]�}|jj�}|dk(r|jjddg�}nV|dk(rQdD]1}|jj
|�}|��!|j�}nj|j�}D].}|jdk(s�|j|j�����|S)z.Name all of this resource's custom operations.r$�query�plain�post)�!application/x-www-form-urlencoded�multipart/form-data�ws.op)
rD�method_iter�namer%�request�params�get_representation_definition�resolve_definition�append�fixed_value)r�names�methodr[r]�
media_type�
definition�params        r�
lp_operationszResource.lp_operations�s���
���)�)�5�5�	�F��;�;�$�$�&�D��u�}����.�.���/A�B�����#�	�J�"(���!M�!M�"�"�J�"�-�%/�%B�%B�%D�
��	�$�*�*�4�+>�+>�?���
���:�:��(��L�L��!2�!2�3��
�!	�(�r!c�d�|j|j|j|j�S)z;A hook into dir() that returns web service-derived members.)rIrJrNrQrKs r�__members__zResource.__members__�s0���(�(��!�!�4�#4�#4�d�6J�6J�
�	
r!c��g}|jj|j�D]�}|j}|j}|dk7rg|�e|j
rY|j
d�r$|j|vs�N|j|dd��c|j|vs�r|j|dd���|j|vs��|j|���|S)z2Retrieve some subset of the resource's parameters.r8N�_collection_linki����)rD�
parametersr@r[�link�
can_follow�endswithrJr`rNrQ)r�kindsrb�	parameterr[rns      rrIzResource._get_parameter_names�s������,�,�7�7��8L�8L�M�	'�I��>�>�D��>�>�D��{�"�t�'7�D�O�O��=�=�!3�4��,�,��5����T�$�3�Z�0��(�(�E�1����T�#�2�Y�/��'�'�5�0��L�L��&�9	'�:�r!c�(�|j|�duS)z8Does this resource have a parameter with the given name?N)r9r>s  r�lp_has_parameterzResource.lp_has_parameter�s���,�,�Z�8��D�Dr!c��|j�dD]{}|jj||z�}|��$	|j�|j��y|j
}|j
|j||j��cS|jj|�}|�t	d|z��|j�S#t$rY��wxYw)z�Get the value of one of the resource's parameters.

        :return: A scalar value if the parameter is not a link. A new
                 Resource object, whose resource is bound to a
                 representation, if the parameter is a link.
        )�_linkrkN)r?zNo such parameter: %s)	�_ensure_representationrD�
get_parameter�	get_valuer*�linked_resource�_create_bound_resourcerCr[)rr?�suffixrfrzs     r�lp_get_parameterzResource.lp_get_parameter�s���	
�#�#�%�3�	�F��'�'�5�5�j�6�6I�J�E�� ���O�O�%�
�?�?�$�,� �"'�"7�"7���2�2��J�J��E�J�J�3���	�$�#�#�1�1�*�=���=��2�Z�?�@�@���� � ��! ����s�C�	C�Cc���d|i}|jjd|��}|�|jjd|��}|�td|z��t|j||�S)z�Get a custom operation with the given name.

        :return: A NamedOperation instance that can be called with
                 appropriate arguments to invoke the operation.
        rYr$)�query_paramsrV)�representation_paramszNo operation with name: %s)rD�
get_methodr*rrC)r�operation_namer]rcs    r�lp_get_named_operationzResource.lp_get_named_operation�sy���>�*���$�$�/�/��F�/�K���>��(�(�3�3��f�4��F��>��7�.�H�I�I��d�j�j�$��7�7r!Nc��|j}t|�d}	t}
|jd�s|�|jd�rt}
|j
j
|	|
�}|�|j||||��}n	|||�S)aCreate a lazr.restful Resource subclass from a wadllib Resource.

        :param resource: The wadllib Resource to wrap.
        :param representation: A previously fetched representation of
            this resource, to be reused. If not provided, this method
            will act just like the Resource constructor.
        :param representation_media_type: The media type of any previously
            fetched representation.
        :param representation_needs_processing: Set to False if the
            'representation' parameter should be used as
            is.
        :param representation_definition: A wadllib
            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.
        :param param_name: The name of the link that was followed to get
            to this resource.
        :return: An instance of the appropriate lazr.restful Resource
            subclass.
        ���z-pagerk)�representation_definition)�type_urlrrrpr�RESOURCE_TYPE_CLASSESr$�bind)�clsrF�resource�representation�representation_media_type�representation_needs_processingr�r?r��
resource_typer'�r_classs            rr{zResource._create_bound_resources���H�$�$�� ��*�2�.�
������W�%��"�z�':�':�;M�'N� �G��,�,�0�0���H���%� �}�}��)�/�*C�	%��H�
��t�X�&�&r!c�L�|�||j_i}|�||d<|jjj	|j|��}||jjj
k(ry|jj
||j�|jd<y)�&Update this resource's representation.Nz
If-None-Match)�headersrD)	rD�_urlrC�_browserr$�NOT_MODIFIEDr�r@rE)r�new_url�etagr�r�s     r�
lp_refreshzResource.lp_refreshHs�����'.�D���$�����'+�G�O�$����,�,�0�0�����1�
���T�Z�Z�0�0�=�=�=��+/�*=�*=�*B�*B��D�0�0�+
��
�
�&�'r!c��	|j|�S#t$rYnwxYw	|j|�S#t$rt|�d|�d���wxYw)z@Try to retrive a named operation or parameter of the given name.z object has no attribute '�')r�r*r}�AttributeError)r�attrs  r�__getattr__zResource.__getattr__[sd��	��.�.�t�4�4���	��	��	��(�(��.�.���	� �59�4�@��
�	�s��	��4�Ac���|jj||j�}|j}t	|�dkDr|D�cgc]}|j
��c}Sycc}w)z0Find the set of possible values for a parameter.rN)rDrxr@�options�lenr+)rr?rrr��options     r�
lp_values_forzResource.lp_values_forhsY���'�'�5�5���,�,�
�	��#�#���w�<�!��/6�7�V�F�L�L�7�7���8s�Ac�Z�dD]&}||z}|jj|�s�$|cSy)z>What's this parameter's name in the underlying representation?)rvrk�N)rDrx)rr?r|r[s    rr9z!Resource._get_external_param_namers9��7�	�F���&�D��"�"�0�0��6���	�r!c�4�|jj��|jjj	|j�}t|t�r|jd�}t|�}t|t�r`|d}|�Y||jjk7r@|jjj|�}|j|j_
|jj||jd��|j d<yy)z5Make sure this resource has a representation fetched.N�utf-8�resource_type_linkF�r�rD)rDr�rCr�r$r7�binary_type�decoder�dictr��_wadl�get_resource_type�tagr�r@rE)rr��	type_linkr�s    rrwzResource._ensure_representationzs������-�-�5�!�Z�Z�0�0�4�4�T�5H�5H�I�N��.�+�6�!/�!6�!6�w�!?��"�>�2�N��.�$�/�*�+?�@�	��)�!�T�%8�%8�%A�%A�A�$(�J�J�$4�$4�$F�$F�!�%�M�/<�.?�.?�D�'�'�+�.2�.A�.A�.F�.F���$�$�05�/G�/�D�M�M�*�+�36r!c��||k(S)zInequality operator.r1�r�others  r�__ne__zResource.__ne__�s���5�=� � r!)Nr4TNN�NN)r-r.r/r0r �objectrJrNrQ�propertyrLrOrRrgri�__methods__rIrtr}r��classmethodr{r�r�r�r9rwr�r1r!rrrrs���5�8��x���8�L��h�O�
�@��@��<��<��?��?�����6�
��
� �K� �DE�!�>8� �
�"4�(,�"&��9'��9'�v
�&����B!r!rc� �eZdZdZed��Zy)�ScalarValuez.A resource representing a single scalar value.c�N�|j�|jjS)zReturn the scalar value.)rwrDr�rKs rr+zScalarValue.value�s"��	
�#�#�%��"�"�1�1�1r!N)r-r.r/r0r�r+r1r!rr�r��s��8�
�2��2r!r�c�*�eZdZdZdd�Zd�Zd�Zd�Zy)�
HostedFilezAA resource representing a file managed by a lazr.restful service.Nc�<�|dvrt||||�Std��)z5Open the file on the server for read or write access.)�r�w�'Invalid mode. Supported modes are: r, w)�HostedFileBuffer�
ValueError)r�mode�content_type�filenames    r�openzHostedFile.open�s'���:��#�D�$��h�G�G��F�G�Gr!c�v�|jjj|jj�y)z Delete the file from the server.N)rCr��deleterD�urlrKs rr�zHostedFile.delete�s&���
�
���"�"�4�#6�#6�#:�#:�;r!c��gS)z4HostedFile objects define no web service parameters.r1)rrqs  rrIzHostedFile._get_parameter_names�s���	r!c�h�|duxr-|jj|jjk(S)aEquality comparison.

        Two hosted files are the same if they have the same URL.

        There is no need to check the contents because the only way to
        retrieve or modify the hosted file contents is to open a
        filehandle, which goes direct to the server.
        N)rDr�r�s  r�__eq__zHostedFile.__eq__�s7��
���
D��#�#�'�'�5�+?�+?�+C�+C�C�	
r!)r�NN)r-r.r/r0r�r�rIr�r1r!rr�r��s��K�H�<��
r!r�c�j��eZdZdZeed�Zdddddejf�fd�	Z	e
d��Zd�Zd�Z
�xZS)	rz�Entry point to the service. Subclass this for a service-specific client.

    :ivar credentials: The credentials instance used to access Launchpad.
    )r�r�Nr�c		����|�(|ddk7r|dz
}|t|�z
}|ddk7r|dz
}t|�|_||_||_t||||||j|�|_|jj|j�|_	|jjd�}	|	j|jj|	�d�}
tt|�?d|
�y)z�Root access to a lazr.restful API.

        :param credentials: The credentials used to access the service.
        :param service_root: The URL to the root of the web service.
        :type service_root: string
        Nr��/r�r4)�strr�	_root_uri�_base_client_name�credentialsr�_user_agentr��get_wadl_applicationr��get_resource_by_pathr�r$�superrr )r�
authorizer�service_root�cache�timeout�
proxy_info�version�base_client_name�max_retries�
root_resource�
bound_root�	__class__s           �rr zServiceRoot.__init__�s����"���B��3�&���#���C��L�(�L��B��3�&���#���\�*���"2���&�������������
��
��]�]�7�7����G��
��
�
�7�7��;�
�"�'�'��M�M���m�,�.@�
�
�	�k�4�)�$�
�;r!c��dtz}|jdk7r|jdz|zdz}t�}||d<|j�>|jj}t|�D]}||}|j
||d��|dS)a�The value for the User-Agent header.

        This will be something like:
        launchpadlib 1.6.1, lazr.restfulclient 1.0.0; application=apport

        That is, a string describing lazr.restfulclient and an
        optional custom client built on top, and parameters containing
        any authorization-specific information that identifies the
        user agent (such as the application name).
        zlazr.restfulclient %sr�z (�)z
User-Agent)rr�r	r��user_agent_params�sorted�	set_param)r�base_portion�messager�r&r+s      rr�zServiceRoot._user_agents���/��<���!�!�R�'��1�1�D�8�<�G�#�M�L��)�� ,�������'� $� 0� 0� B� B���/�0�
<��)�#�.���!�!�#�u�l�;�
<��|�$�$r!c��t||||�Sr)r)rr�r�r�r�s     r�httpFactoryzServiceRoot.httpFactory!s���:�u�g�z�B�Br!c��t|�}|jdk(r1|dddk(r|dd}t|jj	|��}|j
j
|�}t|t�r|jd�}	t|�}|j
d�}|�td|z��|jjj|�}t|jj||j �}|j#|j||d	d
��S#t$rtd|z��wxYw)zLoad a resource given its URL.r�N�r�r�z!%s doesn't serve a JSON document.r�z+Couldn't determine the resource type of %s.r4Fr�)r�schemer�r�r`r�r$r7r�r�rr�rCr�r��WadlResourcer�r{)rr��parsed�documentr�r�r�rGs        r�loadzServiceRoot.load$s<���#����=�=�B���2�A�w�#�~��!�"�g���d�n�n�+�+�C�0�1�C��=�=�$�$�S�)���h��,����w�/�H�	H�"�8�_�N�#�&�&�';�<�	����=��C��
��
�
�(�(�:�:�9�E�
�$�T�Z�Z�%5�%5�s�M�<M�<M�N�
��*�*��J�J����,1�+�
�	
���	H��@�3�F�G�G�	H�s�	D%�%D=)r-r.r/r0r�r�r�r�MAX_RETRIESr r�r�r�r��
__classcell__�r�s@rrr�sW����!�"���������'�'�.<�`�%��%�0C�
r!rc�.�eZdZdZd�Zd�Zd�Zd�Zd�Zy)rz=A class for a named operation to be invoked with GET or POST.c�.�||_||_||_y)z/Initialize with respect to a WADL Method objectN)rFr��wadl_method)rrFr�r�s    rr zNamedOperation.__init__Gs����	� ��
�&��r!c��t|�dkDrtd��|jj}|j	|�}|jj
}|dvr
|j}nR|jd�}|�|jd�}|�Jd��|j|jj�}|D�chc]5}|jdk(st|j�dkDr|j��7}}|j�D]\}	}
|	|vs�t|
t��||	<� |dvr!|jj di|��}d	}i}
n=|jj!�}|jj"di|��\}}d
|i}
|j$j&j)|||j+�|
��\}}|j,dk(r|j/|||�S|d
k(rW|j,dk(r.|d}|j$j&j)|�\}}n|jj1�|j3|||�Scc}w)z)Invoke the method and process the result.rz(Method must be called with keyword args.)r$�headr�rXrWzYA POST named operation must define a multipart or form-urlencoded request representation.�binary)r�r�zContent-type)�
extra_headers��rV�-�locationr1)r��	TypeErrorr�r[r<r\rr^r]r�rD�typer�r6rr�build_request_url�build_representationrFr��_request�upper�status�_handle_201_responser��_handle_200_response)r�args�kwargs�http_methodr\r]rerf�send_as_is_paramsr&r+r��in_representationr�rd�response�contents                 r�__call__zNamedOperation.__call__Msy���t�9�q�=��F�G�G��&�&�+�+���1�1�&�9���"�"�*�*���3�3��)�)�F� �>�>�%��J��!�$�B�B�7��
��)�
�:�
�)� �&�&�t�}�}�'C�'C�D�F� �
���z�z�X�%��U�]�]�);�a�)?�
�J�J�
��
�
�*�*�,�	B�J�C���+�+�!�%�-@�A��S�	�	B��3�3�4�$�"�"�4�4�<�t�<�C� "���M��"�"�4�4�6�C�6�� � �5�5�=��=�
��!�+�Z�8�M�!�I�I�.�.�7�7�������'�	8�
���'��?�?�c�!��,�,�S�(�G�D�D��f�$��?�?�c�)�"�:�.�C�(,�	�	�(:�(:�(C�(C�C�(H�%�H�g��M�M�,�,�.��,�,�S�(�G�D�D��c
s�>:Ic�F�|jjjt|��}|j	d�}|j
}|jjj|j�\}}tj|j|||d�S)z5Handle the creation of a new resource by fetching it.�Location�content-type)r�rr�rrxrzrFr�rr�rr{)rr�rr�
wadl_response�wadl_parameterrGs       rr	z#NamedOperation._handle_201_response�s����(�(�1�1�6�6��X�&�
�
�'�4�4�Z�@��&�6�6�
� �I�I�.�.�7�7�
�8I�8I�J���'��.�.��I�I�}�g�x��/G�
�	
r!c��|d}|jj}|j|�}|�=||jk(r,t	|t
�r|j
d�}t|�S|St	|t
�r|j
d�}t|�}|�|Sd|vr]d|vrY|d}|jjj|d�}t|jj||j�}	n;|j�}t|jj||j�}	tj|j|	||d|��S)z)Process the return value of an operation.rr�r8r�F)r�r�)r�rr^r@r7r�r�rrFr�r�r�r�r_rr{)
rr�rrr��response_definitionr�r�r�rGs
          rr
z#NamedOperation._handle_200_response�sa����/��"�.�.�7�7���=�=�l�K�	"�%�,��t�3�3�3��g�{�3�%�n�n�W�5�G��W�~�%��N��g�{�+��n�n�W�-�G���>�����O��(�"�';�x�'G�
�;�'�C� �I�I�O�O�=�=��-�.��M�)��	�	����m�&7�&7��M�*�<�<�>�
&�)��	�	����&?�&C�&C��M��.�.��I�I����,1�&?�
/�
�	
r!c��|S)z/Named operation parameter names are sent as is.r1r>s  rr9z'NamedOperation._get_external_param_name�s���r!N)	r-r.r/r0r rr	r
r9r1r!rrrDs"��G�'�HE�T

�<
�|r!rc�\��eZdZdZ�fd�Zd�Zd�Zd�Z�fd�Zd�Z	d�Z
d�fd	�	Zd
�Z�xZ
S)rzBA class for an entry-type resource that can be updated with PATCH.c�t��tt|�||�i|jd<tt|�||�y)N�_dirty_attributes)r�rr rE�rrFrGr�s   �rr zEntry.__init__�s6���
�e�T�#�D�-�8�.0��
�
�)�*�
�e�T�#�D�-�8r!c�b�dt|j�j�d|j�d�S)z:Return the WADL resource type and the URL to the resource.�<z at �>)rr��fragmentr8rKs r�__repr__zEntry.__repr__�s)��
��'�'�(�1�1��N�N�
�	
r!c�r�|jjjt|j��S)zDelete the resource.)rCr�r�rr8rKs r�	lp_deletezEntry.lp_deletes&���z�z�"�"�)�)�#�d�n�n�*=�>�>r!c��|jS)zReturn the URL to the resource.)r8rKs r�__str__z
Entry.__str__s���~�~�r!c�n��|dk7r||jvr|j|Stt|�|�S)z-Try to retrive a parameter of the given name.r)rr�rr�)rr[r�s  �rr�zEntry.__getattr__
s=����&�&��t�-�-�-��-�-�d�3�3��U�D�-�d�3�3r!c��|j|�s&td|jj�d|�d���||j|<y)z$Set the parameter of the given name.r�z' object has no attribute 'N)rtr�r�r-r)rr[r+s   r�__setattr__zEntry.__setattr__sC���$�$�T�*� ��>�>�*�*�D�2��
�(-����t�$r!c��|duxrO|j|jk(xr4|j|jk(xr|j|jk(S)z�Equality operator.

        Two entries are the same if their self_link and http_etag
        attributes are the same, and if their dirty attribute dicts
        contain the same values.
        N)r8�	http_etagrr�s  rr�zEntry.__eq__sY��
���
B����%�/�/�1�
B����%�/�/�1�
B��&�&�%�*A�*A�A�		
r!c�|��t|dd�}tt|�||�|jj�y)r�r,N)�getattrr�rr�r�clear)rr�r�r�s   �rr�zEntry.lp_refresh(s4����t�[�$�/��
�e�T�%�g�t�4����$�$�&r!c�@�|j|j�}i}t|dd�}|�||d<|jjjt
|j�||�\}}|jdk(r|j|d�|jj�|d}|jdk(r_||jk(rOt|t�r|jd�}t|�}||j _||j _yyy)	zSave changes to the entry.r,NzIf-Matchrrr��r�)r<rr.rCr��patchrr8rr�r/r@r7r�r�rrDr�rd)rr�r�r�rrr��new_representations        r�lp_savez
Entry.lp_save.s���;�;��"�"�
�����t�[�$�/����"&�G�J��
!�J�J�/�/�5�5��������
���'��?�?�c�!��O�O�H�Z�0�1����$�$�&���/���?�?�c�!�l�d�6J�6J�&J��'�;�/�!�.�.��1��!&�w���1C�D���.�-9�D���*�'K�!r!r)r-r.r/r0r r#r%r'r�r*r�r�r4r�r�s@rrr�s3���L�
9�
�?��4�-�
�'�:r!rc�F��eZdZdZ�fd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
�xZS)	rz4A collection-type resource that supports pagination.c�.��tt|�||�y)zCreate a collection object.N)r�rr rs   �rr zCollection.__init__Ss���
�j�$�(��}�=r!c��|j}t|t�r|St|t�r|jStd��)znThe number of items in the collection.

        :return: length of the collection
        :rtype: int
        z collection size is not available)�
total_sizer7�intr�r+r)rr8s  r�__len__zCollection.__len__WsC���_�_�
��j�#�&���
�
�K�
0��#�#�#��>�?�?r!c#�K�|j�|jj}	|j|j	di��D]}|���|j	d�}|�y|j
jj	t|��}t|t�r|jd�}t|�}���w)zqIterate over the items in the collection.

        :return: iterator
        :rtype: sequence of `Entry`
        �entries�next_collection_linkNr�)rwrDr��_convert_dicts_to_entriesr$rCr�rr7r�r�r)r�current_pager��	next_link�next_gets     r�__iter__zCollection.__iter__is�����	
�#�#�%��*�*�9�9��� �:�:�� � ��B�/��
����
�%�(�(�)?�@�I�� ���z�z�*�*�.�.�s�9�~�>�H��(�K�0�#�?�?�7�3�� ��?�L��s�CCc��t|t�r|j|�S|jt||dz��}t|�dk7rt	d��|dS)acLook up a slice, or a subordinate resource by index.

        To discourage situations where a lazr.restful client fetches
        all of an enormous list, all collection slices must have a
        definitive end point. For performance reasons, all collection
        slices must be indexed from the start of the list rather than
        the end.
        r�zlist index out of ranger)r7�slice�
_get_slicer��
IndexError)rr&�found_slices   rr,zCollection.__getitem__~s[���c�5�!��?�?�3�'�'��/�/�%��S�1�W�*=�>�K��;��1�$� �!:�;�;��q�>�!r!c��|jxsd}|j}|dkrtd��|dkrtd��|jj}|�8|t|d�kr'|d}t|�}|||}|j
d�}n+d}g}|j|jjd|�}||z
}	|	t|�z
}
|
dkDr�|��|jjj
|�}t|t�r|jd�}t|�}|d}
||
d|
z
}|	t|�z
}
|j
d�}|�n2|�t|
�}|
dkDr|
|kr|j|d	|
�}|
dkDr|���|j�|dd|j�}|j!|�D�cgc]}|��c}Scc}w)
z!Retrieve a slice of a collection.rz6Collection slices must have a nonnegative start point.z>Collection slices must have a definite, nonnegative end point.Nr<r=zws.startr�zws.size)�start�stopr�rDr�r�r$�_with_url_query_variable_setr�rCr�r7r�r�r�stepr>)rrDrIrJ�existing_representation�
entry_page�first_page_size�entry_dicts�page_url�desired_size�more_needed�page_getr��current_page_entriesr�s               rrEzCollection._get_slice�s����� �q���z�z���1�9��K��
��!�8��)��
�
#'�"5�"5�"D�"D��"�.�5�3�#�I�.�<
�4
�&1��;�J�!�*�o�O�$�U�4�0�K�.�2�2�3I�J�H�#�O��K��8�8��#�#�'�'��U��H��e�|��"�S��%5�5���A�o�(�"6��z�z�*�*�.�.�x�8�H��(�K�0�#�?�?�7�3��"�8�_�N�#1�)�#<� ��/���=�=�K�&��[�)9�9�K�%�)�)�*@�A�H�����&�"%�&:�";���Q��;��#@� �<�<��i����1�A�o�(�"6�8�:�:�!�%�m����m�4�K�
!�:�:�;�G�
��
�
�	
��
s�5	Gc#�0K�|D]�}|d}|d}|jj}|j|�}t|jj||j�}t
j
|j|||jd�����y�w)aConvert dictionaries describing entries to Entry objects.

        The dictionaries come from the 'entries' field of the JSON
        dictionary you get when you GET a page of a collection. Each
        dictionary is the same as you'd get if you sent a GET request
        to the corresponding entry resource. So each of these
        dictionaries can be treated as a preprocessed representation
        of an entry resource, and turned into an Entry instance.

        :yield: A sequence of Entry instances.
        r8r�FN)	rD�applicationr�r�r�rr{rCr@)rr<�
entry_dict�resource_urlr��wadl_applicationr�r�s        rr>z$Collection._convert_dicts_to_entries�s�����"�	�J�%�k�2�L�!+�,@�!A��#�2�2�>�>��,�>�>�"��M�$��#�#�/�/���!�!��H�
�1�1��
�
�H�j�$�2F�2F���
�	�s�BBc��t|�}|j�i}nt|j�}t|�||<t	|d�|_t|�S)z1A helper method to set a query variable in a URL.T)rrTr
r�r)rr��variable�	new_value�urir]s      rrKz'Collection._with_url_query_variable_set	sM���#�h���9�9���F��c�i�i�(�F��y�>��x���f�d�+��	��3�x�r!)r-r.r/r0r r:rBr,rEr>rKr�r�s@rrrPs,���>�>�@�$+�*"�$[
�z�8	r!rc�2��eZdZdZ�fd�Zd�ZdZd�Z�xZS)rz�A collection-type resource that supports key-based lookup.

    This collection can be sliced, but any single index passed into
    __getitem__ will be treated as a custom lookup key.
    c�Z��t|t�rtt|�|�S	|j|�}|�t|��||�}	|j�|S#t$rtd��wxYw#t$r*}|jjdk(rt|���d}~wwxYw)z8Look up a slice, or a subordinate resource by unique ID.�unsubscriptable objectN�)
r7rDr�rr,�_get_url_from_id�NotImplementedErrorrr*rwrrr)rr&r��
shim_resource�er�s     �rr,z(CollectionWithKeyBasedLookup.__getitem__s�����c�5�!��5�t�H��M�M�	6��'�'��,�C��;��3�-���S�	�
�	��0�0�2����#�	6��4�5�5�	6���	��z�z� � �C�'��s�m�#���		�s#�A�
A7�A4�7	B*�%B%�%B*c��	|j|�}|�t|��|j�:d}t|jjjd|jz�}nW	|jjj|�}t|t�r|jd�}t|�}|d}t'|jj||�}|j)|j||d��S#t$rtd��wxYw#t$r*}|j j"dk(rt%|���d}~wwxYw)	z=Retrieve a member from this collection without looking it up.raN�#r�rbr�F)r�r�)rcrdrr��
collection_ofrrCr��
markup_urlr�r$r7r�r�rrrrr*r�r{)rr&r�r�r��url_get�errorr�s        rrz%CollectionWithKeyBasedLookup.__call__2sC��	6��'�'��,�C��;��S�/�!����)�"�N�!(��
�
� � �+�+�S�4�3E�3E�-E�"��	
��*�*�-�-�1�1�#�6���g�{�3�%�n�n�W�5�G�!&�w���"0�0D�!E����
�
� 0� 0�#�7I�J���*�*��J�J��)�,1�	+�
�	
��M#�	6��4�5�5�	6��8�
��>�>�(�(�C�/�"�3�-�'���	
�s$�C=�'AD�=D�	E�%E�ENc��t��)z2Transform the unique ID of an object into its URL.)rd)rr&s  rrcz-CollectionWithKeyBasedLookup._get_url_from_idhs��!�#�#r!)	r-r.r/r0r,rrircr�r�s@rrrs�����,0
�h�M�$r!rc�$�eZdZdZdd�Zd�Zd�Zy)r�z8The contents of a file hosted by a lazr.restful service.Nc�>�|jj|_|dk(r�|�td��|�td��|jjj|jd��\}}|d}|jd�}|d}t
|�d	}	t|	jd
�d�}n/|dk(rd
}|�td��|�td��d}ntd��||_	||_
||_||_||_
tj||�y)Nr�z8Files opened for read access can't specify content_type.z4Files opened for read access can't specify filename.T)�return_responserz
last-modifiedzcontent-location�r�r�r�r!z8Files opened for write access must specify content_type.z4Files opened for write access must specify filename.r�)rDr�r�rCr�r$rr�split�hosted_filer�r�r��
last_modifiedr
r )
rrsr�r�r�rr+rt�content_location�paths
          rr zHostedFileBuffer.__init__psP���-�-�1�1����3�;��'� �,����#� �M���*�/�/�8�8�<�<����$�=��O�H�e�$�N�3�L�$�L�L��9�M� (�(:�;���,�-�a�0�D��t�z�z�#��r�2�3�H�
�S�[��E��#� �,����� �M���!�M��F�G�G�&�����	�(��� ��
�*�������u�%r!c��|jdk(red|jz}|jjjj|j|j�|jd|i�tj|�y)Nr�zattachment; filename="%s"zContent-Disposition)r�r�rsrCr��putr��getvaluer�r
�close)r�dispositions  rrzzHostedFileBuffer.close�sk���9�9���5��
�
�E�K����"�"�+�+�/�/�����
�
���!�!�&��4�	
�	�
�
�d�r!c�0�tj||�yr)r
�write)r�bs  rr}zHostedFileBuffer.write�s���
�
�d�A�r!r�)r-r.r/r0r rzr}r1r!rr�r�ms��B�-&�^	�r!r�)4r0r�
__metaclass__�__all__�
email.messager	�ior
�jsonrr�urllib.parser
rrrr�ImportError�urllib�sys�version_infor��	text_type�bytesr��unicode�wadllib.applicationrr��lazr.restfulclientr�lazr.restfulclient._browserrr�lazr.restfulclient._jsonr�lazr.restfulclient.errorsr�lazr.urirr�r)rr3r�r�rrrrrr�r1r!r�<module>r�s"��&0��
���"���*�L�L�
����A��!���I��K��I��K�8�*�<�8�/��
�(����6��0k!�{�k!�\	2�(�2�
��
�Bv
�(�v
�rb�[�b�Jd:�H�d:�NB��B�JU$�:�U$�p>�w�>��M"�*�4�4�)�)�*�s�C0�0D
�	D


Zerion Mini Shell 1.0