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: //lib/python3/dist-packages/lazr/restfulclient/__pycache__/resource.cpython-38.pyc
U

$o�U}��@s>dZeZddddddgZzddlmZWn ek
rHddlmZYnXzdd	lm	Z	m
Z
Wn$ek
r�dd	lm	Z	m
Z
YnXzdd
lm
Z
Wn ek
r�ddlmZ
YnXz ddlmZmZmZmZmZWn:ek
�rdd
lmZmZmZddlmZmZYnXddlZejddk�r4eZeZneZeZddlmZddl m!Z"ddl#m$Z$ddl%m&Z&m'Z'ddl(m)Z)ddl*m+Z+e,�Z-Gdd�d�Z.Gdd�d�Z/Gdd�de/�Z!Gdd�de!�Z0Gdd�de!�Z1Gd d�de!�Z2Gd!d�de/�Z3Gd"d�de!�Z4Gd#d�de!�Z5Gd$d�de5�Z6Gd%d&�d&e
�Z7dS)'z)Common support for web service resources.�
Collection�CollectionWithKeyBasedLookup�Entry�NamedOperation�Resource�ServiceRoot�)�Message)�dumps�loads)�BytesIO)�StringIO)�urljoin�urlparse�parse_qs�unquote�	urlencode)r
rr)rrN�)�URI)r)�__version__)�Browser�RestfulHttp)�DatetimeJSONEncoder)�	HTTPErrorc@s*eZdZdZdd�Zd	dd�Zdd�ZdS)
�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.
    cCs
||_dS�N)�wrapped_dictionary)�selfr�r�=/usr/lib/python3/dist-packages/lazr/restfulclient/resource.py�__init__VszHeaderDictionary.__init__NcCs|j�|���S�z2Retrieve a value, converting the key to lowercase.)r�get�lower)r�key�defaultrrrr!YszHeaderDictionary.getcCs |�|t�}|tkrt|��|Sr )r!�missing�KeyError)rr#�valuerrr�__getitem__]szHeaderDictionary.__getitem__)N)�__name__�
__module__�__qualname__�__doc__rr!r(rrrrrKs

rc@s$eZdZdZdZdd�Zdd�ZdS)�RestfulBasez=Base class for classes that know about lazr.restful services.�application/jsoncCs8i}|��D]&\}}t|t�r$|j}|||�|�<q|Sr)�items�
isinstancer�	self_link�_get_external_param_name)rZ
dictionaryZnew_dictionaryr#r'rrr�_transform_resources_to_linksjs
z)RestfulBase._transform_resources_to_linkscCs|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.
        r�r�
param_namerrrr2rsz$RestfulBase._get_external_param_nameN)r)r*r+r,�JSON_MEDIA_TYPEr3r2rrrrr-esr-c@s�eZdZdZdd�Ze�Ze�Ze�Ze	dd��Z
e	dd��Ze	dd	��Ze	d
d��Z
e	dd
��Ze
Zdd�Zdd�Zdd�Zdd�Zed'dd��Zd(dd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�ZdS))rz+Base class for lazr.restful HTTP resources.cCs$|dkr|}||jd<||jd<dS)z5Initialize with respect to a wadllib Resource object.N�_root�_wadl_resource)�__dict__�r�root�
wadl_resourcerrrr�s
zResource.__init__cCs|�|j�S)z,Name the collections this resource links to.)�_get_parameter_names�FIND_COLLECTIONS�rrrr�lp_collections�szResource.lp_collectionscCs|�|j�S)z(Name the entries this resource links to.)r=�FIND_ENTRIESr?rrr�
lp_entries�szResource.lp_entriescCs|�|j�S)z'Name this resource's scalar attributes.)r=�FIND_ATTRIBUTESr?rrr�
lp_attributes�szResource.lp_attributescCs�g}|jjD]�}|j��}|dkr4|j�ddg�}n>|dkrrdD]$}|j�|�}|dk	r@|��}qfq@|�|j�}|D]}|jdkrv|�|j	�qqvq|S)z.Name all of this resource's custom operations.r!�queryZplain�post)�!application/x-www-form-urlencoded�multipart/form-dataN�ws.op)
r8Zmethod_iter�namer"�request�params�get_representation_definition�resolve_definition�appendZfixed_value)r�names�methodrJrL�
media_type�
definition�paramrrr�
lp_operations�s&
�
zResource.lp_operationscCs|�|j|j|j�S)z;A hook into dir() that returns web service-derived members.)r=r>rArCr?rrr�__members__�s
�zResource.__members__cGs�g}|j�|j�D]�}|j}|j}|dkr~|dk	r~|jr~|�d�r`|j|kr||�|dd��q�|j	|kr�|�|dd��q|j
|kr|�|�q|S)z2Retrieve some subset of the resource's parameters.r1N�_collection_linki����)r8Z
parametersr6rJ�linkZ
can_follow�endswithr>rOrArC)r�kindsrP�	parameterrJrYrrrr=�s"��



zResource._get_parameter_namescCs|�|�dk	S)z8Does this resource have a parameter with the given name?N)r2r4rrr�lp_has_parameter�szResource.lp_has_parameterc	Cs�|��dD]r}|j�||�}|dk	rz|��Wntk
rLYqYnX|��dkr`dS|j}|j|j||jd�Sq|j�|�}|dkr�td|��|��S)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.
        )�_linkrWN)r5zNo such parameter: %s)	�_ensure_representationr8�
get_parameterZ	get_valuer&�linked_resource�_create_bound_resourcer7rJ)rr5�suffixrTrarrr�lp_get_parameter�s,�
�zResource.lp_get_parametercCsRd|i}|jjd|d�}|dkr0|jjd|d�}|dkrDtd|��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.
        rIr!)�query_paramsNrF)Zrepresentation_paramszNo operation with name: %s)r8Z
get_methodr&rr7)rZoperation_namerLrQrrr�lp_get_named_operations�zResource.lp_get_named_operationNr.TcCsj|j}t|�d}	t}
|�d�s2|dk	r6|�d�r6t}
|j�|	|
�}|dk	r`|j||||d�}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-pageNrW)�representation_definition)�type_urlrrrZr�RESOURCE_TYPE_CLASSESr!�bind)�clsr;�resource�representationZrepresentation_media_type�representation_needs_processingrhr5ri�
resource_typer$Zr_classrrrrbs$
���zResource._create_bound_resourcecCsd|dk	r||j_i}|dk	r$||d<|jjj|j|d�}||jjjkrJdS|j�||j�|jd<dS)�&Update this resource's representation.Nz
If-None-Match)�headersr8)	r8Z_urlr7�_browserr!ZNOT_MODIFIEDrkr6r9)r�new_url�etagrrrnrrr�
lp_refreshIs��zResource.lp_refreshcCsXz|�|�WStk
r YnXz|�|�WStk
rRtd||f��YnXdS)z@Try to retrive a named operation or parameter of the given name.z%s object has no attribute '%s'N)rfr&rd�AttributeError)r�attrrrr�__getattr__Zs�zResource.__getattr__cCs4|j�||j�}|j}t|�dkr0dd�|D�SdS)z0Find the set of possible values for a parameter.rcSsg|]
}|j�qSr)r')�.0Zoptionrrr�
<listcomp>lsz*Resource.lp_values_for.<locals>.<listcomp>N)r8r`r6�options�len)rr5r\r|rrr�
lp_values_forfs�zResource.lp_values_forcCs*dD] }||}|j�|�r|SqdS)z>What's this parameter's name in the underlying representation?)r^rW�N)r8r`)rr5rcrJrrrr2os

z!Resource._get_external_param_namecCs�|jjdkr�|jj�|j�}t|t�r0|�d�}t|�}t|t	�rv|d}|dk	rv||jj
krv|jj�|�}|j
|j_
|jj||jdd�|jd<dS)z5Make sure this resource has a representation fetched.N�utf-8�resource_type_linkF�ror8)r8rnr7rsr!r0�binary_type�decoder
�dictri�_wadl�get_resource_type�tagrkr6r9)rrn�	type_linkrprrrr_ws&




��
�zResource._ensure_representationcCs
||kS)zInequality operator.r�r�otherrrr�__ne__�szResource.__ne__)Nr.TNN)NN)r)r*r+r,r�objectr>rArC�propertyr@rBrDrUrVZ__methods__r=r]rdrf�classmethodrbrvryr~r2r_r�rrrrr}sB





$�4
	c@seZdZdZedd��ZdS)�ScalarValuez.A resource representing a single scalar value.cCs|��|jjS)zReturn the scalar value.)r_r8rnr?rrrr'�szScalarValue.valueN)r)r*r+r,r�r'rrrrr��sr�c@s2eZdZdZddd�Zdd�Zdd	�Zd
d�ZdS)
�
HostedFilezAA resource representing a file managed by a lazr.restful service.�rNcCs"|dkrt||||�Std��dS)z5Open the file on the server for read or write access.)r��w�'Invalid mode. Supported modes are: r, wN)�HostedFileBuffer�
ValueError)r�mode�content_type�filenamerrr�open�szHostedFile.opencCs|jj�|jj�dS)z Delete the file from the server.N)r7rs�deleter8�urlr?rrrr��szHostedFile.deletecGsgS)z4HostedFile objects define no web service parameters.r)rr[rrrr=�szHostedFile._get_parameter_namescCs|dk	o|jj|jjkS)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)r8r�r�rrr�__eq__�s	�zHostedFile.__eq__)r�NN)r)r*r+r,r�r�r=r�rrrrr��s

r�csVeZdZdZeed�Zdddddejf�fdd�	Z	e
dd��Zd	d
�Zdd�Z
�ZS)
rz�Entry point to the service. Subclass this for a service-specific client.

    :ivar credentials: The credentials instance used to access Launchpad.
    )r�r�Nrc	s�|dk	r<|ddkr|d7}|t|�7}|ddkr<|d7}t|�|_||_||_t||||||j|�|_|j�|j�|_	|j	�
d�}	|	�|j�|	�d�}
t
t|��d|
�dS)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
        Nrg�/rr.)�strr�	_root_uri�_base_client_name�credentialsr�_user_agentrsZget_wadl_applicationr�Zget_resource_by_pathrkr!�superrr)r�
authorizerZservice_root�cache�timeout�
proxy_info�versionZbase_client_nameZmax_retriesZ
root_resourceZ
bound_root��	__class__rrr�s2	
�
�zServiceRoot.__init__cCspdt}|jdkr$|jd|d}t�}||d<|jdk	rh|jj}t|�D]}||}|�||d�qL|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 %srz (�)z
User-AgentN)rr�rr��user_agent_params�sortedZ	set_param)rZbase_portion�messager�r#r'rrrr��s

zServiceRoot._user_agentcCst||||�Sr)r)rr�r�r�r�rrr�httpFactoryszServiceRoot.httpFactorycCs�t|�}|jdkr>|dd�dkr.|dd�}t|j�|��}|j�|�}t|t�r^|�	d�}zt
|�}Wn tk
r�td|��YnX|�d�}|dkr�td|��|jj
�|�}t|jj
||j�}|j|j||d	d
d�S)zLoad a resource given its URL.rN�r�r�z!%s doesn't serve a JSON document.r�z+Couldn't determine the resource type of %s.r.Fr�)rZschemer�r�rOrsr!r0r�r�r
r�r7r�r��WadlResourcer�rb)rr�Zparsed�documentrnr�rpr<rrr�load	s4



��zServiceRoot.load)r)r*r+r,r�r�rjrZMAX_RETRIESrr�r�r�r��
__classcell__rrr�rr�s��!
c@s8eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
rz=A class for a named operation to be invoked with GET or POST.cCs||_||_||_dS)z/Initialize with respect to a WADL Method objectN)r;rm�wadl_method)rr;rmr�rrrr'szNamedOperation.__init__cOs~t|�dkrtd��|jj}|�|�}|jj}|dkr>|j}n:|�d�}|dkrZ|�d�}|dk	sjtd��|�	|j
j�}tdd	�|D��}|�
�D] \}}	||kr�t|	td
�||<q�|dkr�|jjf|�}
d}i}n$|j��}
|jjf|�\}
}d|
i}|jjj|
||��|d
�\}}|jdk�r0|�|
||�S|dk�rl|jdk�rb|d}
|jj�|
�\}}n
|j
��|�|
||�SdS)z)Invoke the method and process the result.rz(Method must be called with keyword args.)r!�headr�rHNrGzYA POST named operation must define a multipart or form-urlencoded request representation.cSs*g|]"}|jdks t|j�dkr|j�qS)�binaryr)�typer}r|rJ)rzrTrrrr{Bs
�z+NamedOperation.__call__.<locals>.<listcomp>)rlrzContent-type)�
extra_headers��rF�-�location)r}�	TypeErrorr�rJr3rKrerM�AssertionErrorrLrmr8�setr/r	rZbuild_request_urlZbuild_representationr;rs�_request�upper�status�_handle_201_responserv�_handle_200_response)r�args�kwargsZhttp_methodrKrLrSZsend_as_is_paramsr#r'r�Zin_representationr�rR�response�contentrrr�__call__-s^
��
�
���


zNamedOperation.__call__cCsL|jj�t|��}|�d�}|j}|jj�|j	�\}}t
�|j|||d�S)z5Handle the creation of a new resource by fetching it.ZLocation�content-type)r�r�rkrr`rar;rsr�r�rrb)rr�r�r�Z
wadl_responseZwadl_parameterr<rrrr�os�
��z#NamedOperation._handle_201_responsec
Cs�|d}|jj}|�|�}|dkrL||jkrHt|t�r@|�d�}t|�S|St|t�r`|�d�}t|�}|dkrt|Sd|kr�d|kr�|d}|jj	�
|d�}t|jj	||j�}	n|�
�}t|jj	||j�}	tj|j|	||d|d�S)z)Process the return value of an operation.r�Nr�r1r�F)rorh)r�r�rMr6r0r�r�r
r;r�r�r�r�rNrrb)
rr�r�r�r�Zresponse_definitionrhr�rpr<rrrr�}sP��




�
�	���z#NamedOperation._handle_200_responsecCs|S)z/Named operation parameter names are sent as is.rr4rrrr2�sz'NamedOperation._get_external_param_nameN)	r)r*r+r,rr�r�r�r2rrrrr$sB6csjeZdZdZ�fdd�Zdd�Zdd�Zdd	�Z�fd
d�Zdd
�Z	dd�Z
d�fdd�	Zdd�Z�Z
S)rzBA class for an entry-type resource that can be updated with PATCH.cs2tt|��||�i|jd<tt|��||�dS)N�_dirty_attributes)r�rrr9r:r�rrr�s
zEntry.__init__cCsdt|j�j|jfS)z:Return the WADL resource type and the URL to the resource.z
<%s at %s>)rr�Zfragmentr1r?rrr�__repr__�s
�zEntry.__repr__cCs|jj�t|j��S)zDelete the resource.)r7rsr�rr1r?rrr�	lp_delete�szEntry.lp_deletecCs|jS)zReturn the URL to the resource.)r1r?rrr�__str__�sz
Entry.__str__cs,|dkr||jkr|j|Stt|��|�S)z-Try to retrive a parameter of the given name.r�)r�r�rry)rrJr�rrry�s

zEntry.__getattr__cCs,|�|�std|jj|f��||j|<dS)z$Set the parameter of the given name.z!'%s' object has no attribute '%s'N)r]rwr�r)r�)rrJr'rrr�__setattr__�s


�zEntry.__setattr__cCs,|dk	o*|j|jko*|j|jko*|j|jkS)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)r1�	http_etagr�r�rrrr��s
�
�
�zEntry.__eq__Ncs,t|dd�}tt|��||�|j��dS)rqr�N)�getattrr�rrvr��clear)rrtrur�rrrv�szEntry.lp_refreshcCs�|�|j�}i}t|dd�}|dk	r,||d<|jj�t|j�||�\}}|jdkr`|�	|d�|j�
�|d}|jdkr�||jkr�t|t
�r�|�d�}t|�}||j_||j_dS)	zSave changes to the entry.r�NzIf-Matchr�r�r���r�)r3r�r�r7rsZpatchrr1r�rvr�r6r0r�r�r
r8rnrR)rrnrrrur�r�r�Znew_representationrrr�lp_save�s,��



z
Entry.lp_save)N)r)r*r+r,rr�r�r�ryr�r�rvr�r�rrr�rr�s
csPeZdZdZ�fdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
�ZS)rz4A collection-type resource that supports pagination.cstt|��||�dS)zCreate a collection object.N)r�rrr:r�rrrszCollection.__init__cCs0|j}t|t�r|St|t�r$|jStd��dS)znThe number of items in the collection.

        :return: length of the collection
        :rtype: int
        z collection size is not availableN)�
total_sizer0�intr�r'r�)rr�rrr�__len__s

zCollection.__len__ccsv|��|jj}|�|�di��D]
}|Vq"|�d�}|dkrBqr|jj�t|��}t|t	�rh|�
d�}t|�}qdS)zqIterate over the items in the collection.

        :return: iterator
        :rtype: sequence of `Entry`
        �entries�next_collection_linkNr�)r_r8rn�_convert_dicts_to_entriesr!r7rsrr0r�r�r
)rZcurrent_pagermZ	next_linkZnext_getrrr�__iter__1s
�


zCollection.__iter__cCsHt|t�r|�|�S|�t||d��}t|�dkr<td��|dSdS)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 rangerN)r0�slice�
_get_slicer}�
IndexError)rr#Zfound_slicerrrr(Es	

zCollection.__getitem__cCs�|jpd}|j}|dkr td��|dkr0td��|jj}|dk	rx|t|d�krx|d}t|�}|||�}|�d�}nd}g}|�|jjd|�}||}	|	t|�}
|
dk�rR|dk	�rR|j	j
�|�}t|t�r�|�
d�}t|�}|d}
||
d|
�7}|	t|�}
|�d�}|dk�r �qR|dk�r2t|
�}|
dkr�|
|kr�|�|d	|
�}q�|jdk	�rn|dd|j�}d
d�|�|�D�S)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.sizecSsg|]}|�qSrr)rzrmrrrr{�sz)Collection._get_slice.<locals>.<listcomp>)�start�stopr�r8rnr}r!�_with_url_query_variable_setr�r7rsr0r�r�r
�stepr�)rr�r�r�Zexisting_representationZ
entry_pageZfirst_page_sizeZentry_dictsZpage_urlZdesired_sizeZmore_neededZpage_getrnZcurrent_page_entriesrrrr�Ws^
��




��zCollection._get_sliceccsZ|D]P}|d}|d}|jj}|�|�}t|jj||j�}t�|j|||jd�VqdS)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.
        r1r�FN)	r8Zapplicationr�r�r�rrbr7r6)rr�Z
entry_dictZresource_urlr�Zwadl_applicationrprmrrrr��s&���z$Collection._convert_dicts_to_entriescCsBt|�}|jdkri}n
t|j�}t|�||<t|d�|_t|�S)z1A helper method to set a query variable in a URL.NT)rrErr�r)rr�ZvariableZ	new_valueZurirLrrrr��s

z'Collection._with_url_query_variable_set)r)r*r+r,rr�r�r(r�r�r�r�rrr�rrsUcs4eZdZdZ�fdd�Zdd�ZdZdd�Z�ZS)	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
s�t|t�rtt|��|�Sz|�|�}Wntk
rDtd��YnX|dkrVt|��||�}z|�	�Wn:t
k
r�}z|jjdkr�t|��n�W5d}~XYnX|S)z8Look up a slice, or a subordinate resource by unique ID.�unsubscriptable objectN�)
r0r�r�rr(�_get_url_from_id�NotImplementedErrorr�r&r_rr�r�)rr#r�Z
shim_resource�er�rrr(�s 

z(CollectionWithKeyBasedLookup.__getitem__c
Cs�z|�|�}Wntk
r*td��YnX|dkr<t|��|jdk	rbd}t|jjjd|j�}npz.|jj	�
|�}t|t�r�|�
d�}t|�}Wn8tk
r�}z|jjdkr�t|���W5d}~XYnX|d}t|jj||�}|j|j||dd�S)	z=Retrieve a member from this collection without looking it up.r�N�#r�r�r�F)rnro)r�r�r�r��
collection_ofr
r7r�Z
markup_urlrsr!r0r�r�r
rr�r�r&r�rb)rr#r�rnr�Zurl_get�errorrmrrrr��s:
�


�z%CollectionWithKeyBasedLookup.__call__NcCs
t��dS)z2Transform the unique ID of an object into its URL.N)r�)rr#rrrr� sz-CollectionWithKeyBasedLookup._get_url_from_id)	r)r*r+r,r(r�r�r�r�rrr�rr�s
0c@s*eZdZdZd	dd�Zdd�Zdd�ZdS)
r�z8The contents of a file hosted by a lazr.restful service.Nc
Cs�|jj|_|dkr�|dk	r"td��|dk	r2td��|jjj|jdd�\}}|d}|�d�}|d}t|�d	}	t|	�d
�d�}n:|dkr�d
}|dkr�td��|dkr�td��d}ntd��||_	||_
||_||_||_
t�||�dS)Nr�z8Files opened for read access can't specify content_type.z4Files opened for read access can't specify filename.T)Zreturn_responser�z
last-modifiedzcontent-location�r�rgr�rz8Files opened for write access must specify content_type.z4Files opened for write access must specify filename.r�)r8r�r�r7rsr!rr�split�hosted_filer�r�r��
last_modifiedrr)
rr�r�r�r�r�r'r�Zcontent_location�pathrrrr's:
�

zHostedFileBuffer.__init__cCsD|jdkr6d|j}|jjj�|j|��|jd|i�t	�
|�dS)Nr�zattachment; filename="%s"zContent-Disposition)r�r�r�r7rsZputr��getvaluer�r�close)rZdispositionrrrr�Os


�zHostedFileBuffer.closecCst�||�dSr)r�write)r�brrrr�WszHostedFileBuffer.write)NN)r)r*r+r,rr�r�rrrrr�%s
(r�)8r,r�Z
__metaclass__�__all__Z
email.messager�ImportErrorZ
email.MessageZjsonr	r
Z
simplejson�ior�	cStringIOrZurllib.parser
rrrrZurllib�sys�version_infor�Z	text_type�bytesr�ZunicodeZlazr.urirZwadllib.applicationrr�Zlazr.restfulclientrZlazr.restfulclient._browserrrZlazr.restfulclient._jsonrZlazr.restfulclient.errorsrr�r%rr-r�r�rrrrrr�rrrr�<module>sj�
 
c`:T