pVc@sdZddlmZddlZddlmZddlZddlmZddlm Z ddl m Z ddl m Z dd lmZmZdd lmZdd lmZdd lmZmZmZmZdd lmZmZmZmZddlm Z ddl!m"Z"m#Z#ddl$m%Z%ddl&m'Z'ddl(m)Z)ddl*m+Z+dZ,de-fdYZ.de.fdYZ/de.fdYZ0de0fdYZ1de.fdYZ2de.fd YZ3d!e3fd"YZ4d#e.fd$YZ5dS(%u Renderers are used to serialize a response into specific media types. They give us a generic way of being able to handle various media types on the response, such as JSON encoded data or HTML output. REST framework also provides an HTML renderer that renders the browsable API. i(tunicode_literalsN(t OrderedDict(tforms(tImproperlyConfigured(tPage(t parse_header(tTemplatetloader(tencode_multipart(tsix(tVERSIONt exceptionst serializerststatus(tINDENT_SEPARATORStLONG_SEPARATORStSHORT_SEPARATORSttemplate_render(t ParseError(tis_form_media_typetoverride_method(t api_settings(tencoders(tget_breadcrumbs(tClassLookupDictcCs|dkrdS|S(Ni(tNone(tvalue((sr/opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/renderers.pyt zero_as_none#st BaseRenderercBs5eZdZdZdZdZdZdddZRS(u All renderers should extend this class, setting the `media_type` and `format` attributes, and override the `.render()` method. uutf-8utextcCstddS(Nu3Renderer class requires .render() to be implemented(tNotImplementedError(tselftdatataccepted_media_typetrenderer_context((sr/opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/renderers.pytrender2sN( t__name__t __module__t__doc__Rt media_typetformattcharsett render_styleR"(((sr/opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/renderers.pyR's t JSONRenderercBsTeZdZdZdZejZej Z ej Z dZdZdddZRS(u, Renderer which serializes to JSON. uapplication/jsonujsoncCs{|rkt|jd\}}y*tttt|dddSWqktttfk rgqkXn|j ddS(Nuasciiuindentii( RtencodeRtmaxtmintinttKeyErrort ValueErrort TypeErrortgetR(RR R!tbase_media_typetparams((sr/opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/renderers.pyt get_indentGs*c Cs|d krtS|pi}|j||}|d krU|jrLtnt}nt}tj|d|j d|d|j d|}t |t j r|jddjdd}t|jd S|S( uB Render `data` into JSON, returning a bytestring. tclstindentt ensure_asciit separatorsu
u\u2028u
u\u2029uutf-8N(RtbytesR5tcompactRRRtjsontdumpst encoder_classR8t isinstanceR t text_typetreplaceR+(RRR R!R7R9tret((sr/opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/renderers.pyR"Vs    N(R#R$R%R&R'Rt JSONEncoderR>Rt UNICODE_JSONR8t COMPACT_JSONR;RR(R5R"(((sr/opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/renderers.pyR*6s    tTemplateHTMLRenderercBseeZdZdZdZd ZddgZdZd d dZ dZ dZ d Z d Z RS( u_ An HTML renderer for use with templates. The data supplied to the Response object should be a dictionary that will be used as context for the template. The template name is determined by (in order of preference): 1. An explicit `.template_name` attribute set on the response. 2. An explicit `.template_name` attribute set on this class. 3. The return result of calling `view.get_template_names()`. For example: data = {'users': User.objects.all()} return Response(data, template_name='users.html') For pre-rendered HTML, see StaticHTMLRenderer. u text/htmluhtmlu%(status_code)s.htmluapi_exception.htmluutf-8c Cs|p i}|d}|d}|d}|jrE|j|}n!|j||}|j|}|j|||} t|| d|S(uQ Renders data to HTML, using Django's standard template rendering. The template name is determined by (in order of preference): 1. An explicit .template_name set on the response. 2. An explicit .template_name set on this class. 3. The return result of calling view.get_template_names(). uviewurequesturesponsetrequest(t exceptiontget_exception_templatetget_template_namestresolve_templatetresolve_contextR( RRR R!tviewRGtresponsettemplatettemplate_namestcontext((sr/opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/renderers.pyR"s     cCs tj|S(N(Rtselect_template(RRP((sr/opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/renderers.pyRKscCs|jr|j|dsuPUTuPATCHtinstanceu initial_dataurest_framework/horizontalu template_packustyle(uDELETEuOPTIONS(uPUTuPATCH(uPUTuPATCH(RRRR?RRRRRRRtanytparser_classestget_serializerRRRUtis_validtform_renderer_classR"R ( RRRMRRGRkRRtexisting_serializerthas_serializerthas_serializer_classt form_renderer((sr/opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/renderers.pytget_rendered_html_formsT            c st|dd}|rXt|dt rXt|dd}t|tr^d}q^nd}t|||D}|j||||sdS|jd}t|dd}t|dr6|r6|dkr|j d |}n |j }|} |j } |j j } d | d <| j |j| | ndg|jD]} | j^qF} g| D]}||f^qb| dd tjffdY}|SWdQXdS(u Returns a form that allows for arbitrary content types to be tunneled via standard HTML forms. (Which are typically application/x-www-form-urlencoded) u serializerumanyuinstanceNiurenderer_classuget_serializeruPUTuPATCHRiuindenttGenericContentFormc speZejdddddejdidd6Zejdddejdid d6dZRS( tlabelu Media typetchoicestinitialtwidgettattrsu content-typeu data-overrideuContentucontent( R#R$RRwtSelectt _content_typet CharFieldtTextareat_content((RRR(sr/opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/renderers.pyR&s  (uPUTuPATCH(RRRR?RRRRRURR R!tcopyR"RR&RtForm(RRRMRRGRkRtdefault_parsertrenderer_classRtacceptedRQRt media_typesR&R((RRRsr/opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/renderers.pytget_raw_data_forms4        % cCs |jS(N(t get_view_name(RRM((sr/opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/renderers.pytget_name5scCs,|tjtjfkrdS|jdtS(Nuthtml(R tHTTP_401_UNAUTHORIZEDtHTTP_403_FORBIDDENtget_view_descriptionR(RRMRS((sr/opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/renderers.pytget_description8scCst|j|S(N(Rtpath(RRG((sr/opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/renderers.pyR=sc Cs>t|d s t|d r$dSt|dd}t|trHnZ|dk r|dk ry|j|Wqttfk rdSXnt|tsdS|j}g}xQ|j D]F}t|dr|j |||}|r|j |qqqW|sdSt j |j} i|d6} t| | S(Nu get_querysetufilter_backendsu paginatoruto_htmluelements(RURRR?tlistt get_resultsR1R/t get_querysettfilter_backendstto_htmltappendRRgtfilter_templateR( RRRMRGt paginatortquerysettelementstbackendRRORQ((sr/opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/renderers.pytget_filter_form@s0   cCsl|d}|d}|d}|j|}|j||d|}|j||d|} |j||d|} | p~| } tt|j} d} |rd|j} |jr| d |j7} qn| | d     s:  "" CXzHS