ó
pÁìVc           @  sV  d  Z  d d l m Z d d l Z d d l m Z d d l m Z d d l m	 Z	 d d l
 m Z d d l
 m Z m Z m Z d d	 l m Z d d
 l m Z d d l m Z d d l m Z d d l m Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ  d S(   uÅ   
Parsers are used to parse the content of incoming HTTP requests.

They give us a generic way of being able to handle various media types
on the request, such as form content or json encoded data.
iÿÿÿÿ(   t   unicode_literalsN(   t   settings(   t   StopFutureHandlers(   t	   QueryDict(   t   MultiPartParser(   t	   ChunkItert   MultiPartParserErrort   parse_header(   t   six(   t
   force_text(   t   parse(   t	   renderers(   t
   ParseErrort   DataAndFilesc           B  s   e  Z d  „  Z RS(   c         C  s   | |  _  | |  _ d  S(   N(   t   datat   files(   t   selfR   R   (    (    sp   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/parsers.pyt   __init__   s    	(   t   __name__t
   __module__R   (    (    (    sp   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/parsers.pyR      s   t
   BaseParserc           B  s#   e  Z d  Z d Z d d d „ Z RS(   u€   
    All parsers should extend `BaseParser`, specifying a `media_type`
    attribute, and overriding the `.parse()` method.
    c         C  s   t  d ƒ ‚ d S(   u¿   
        Given a stream to read from, return the parsed representation.
        Should return parsed data, or a `DataAndFiles` object consisting of the
        parsed data and files.
        u   .parse() must be overridden.N(   t   NotImplementedError(   R   t   streamt
   media_typet   parser_context(    (    sp   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/parsers.pyR
   )   s    N(   R   R   t   __doc__t   NoneR   R
   (    (    (    sp   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/parsers.pyR   !   s   t
   JSONParserc           B  s,   e  Z d  Z d Z e j Z d d d „ Z RS(   u&   
    Parses JSON-serialized data.
    u   application/jsonc         C  sz   | p	 i  } | j  d t j ƒ } y& | j ƒ  j | ƒ } t j | ƒ SWn, t k
 ru } t d t	 j
 | ƒ ƒ ‚ n Xd S(   uX   
        Parses the incoming bytestream as JSON and returns the resulting data.
        u   encodingu   JSON parse error - %sN(   t   getR   t   DEFAULT_CHARSETt   readt   decodet   jsont   loadst
   ValueErrorR   R   t	   text_type(   R   R   R   R   t   encodingR   t   exc(    (    sp   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/parsers.pyR
   :   s    N(	   R   R   R   R   R   t   JSONRenderert   renderer_classR   R
   (    (    (    sp   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/parsers.pyR   2   s   	t
   FormParserc           B  s#   e  Z d  Z d Z d d d „ Z RS(   u   
    Parser for form data.
    u!   application/x-www-form-urlencodedc         C  s=   | p	 i  } | j  d t j ƒ } t | j ƒ  d | ƒ} | S(   ut   
        Parses the incoming bytestream as a URL encoded form,
        and returns the resulting QueryDict.
        u   encodingR$   (   R   R   R   R   R   (   R   R   R   R   R$   R   (    (    sp   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/parsers.pyR
   O   s    N(   R   R   R   R   R   R
   (    (    (    sp   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/parsers.pyR(   H   s   R   c           B  s#   e  Z d  Z d Z d d d „ Z RS(   uF   
    Parser for multipart form data, which may include file data.
    u   multipart/form-datac         C  s¸   | p	 i  } | d } | j  d t j ƒ } | j j ƒ  } | | d <| j } y8 t | | | | ƒ } | j ƒ  \ }	 }
 t |	 |
 ƒ SWn, t	 k
 r³ } t
 d t j | ƒ ƒ ‚ n Xd S(   u	  
        Parses the incoming bytestream as a multipart encoded form,
        and returns a DataAndFiles object.

        `.data` will be a `QueryDict` containing all the form parameters.
        `.files` will be a `QueryDict` containing all the form files.
        u   requestu   encodingu   CONTENT_TYPEu   Multipart form parse error - %sN(   R   R   R   t   METAt   copyt   upload_handlerst   DjangoMultiPartParserR
   R   R   R   R   R#   (   R   R   R   R   t   requestR$   t   metaR+   t   parserR   R   R%   (    (    sp   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/parsers.pyR
   a   s    

	N(   R   R   R   R   R   R
   (    (    (    sp   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/parsers.pyR   Z   s   t   FileUploadParserc           B  s5   e  Z d  Z d Z d d d „ Z d „  Z d „  Z RS(   u&   
    Parser for file upload data.
    u   */*c         C  s‰  | p	 i  } | d } | j  d t j ƒ } | j } | j } |  j | | | ƒ } | j  d | j  d d ƒ ƒ }	 y( t | j  d | j  d d ƒ ƒ ƒ }
 Wn t t f k
 r· d }
 n XxM | D]E } | j
 d | |
 d | ƒ } | d k	 r¿ t i  i | d	 d
 6ƒ Sq¿ Wg  | D] } | j r| j ^ q} t d g | ƒ } t | | ƒ } d g t | ƒ } xZ t | ƒ D]L \ } } y | j d | |	 |
 | ƒ Wqot k
 rº| | d	  } PqoXqoWxm | D]e } x\ t | ƒ D]N \ } } t | ƒ } | j | | | ƒ } | | c | 7<| d k rÙPqÙqÙWqÆWxG t | ƒ D]9 \ } } | j | | ƒ } | r<t i  i | d
 6ƒ Sq<Wt d ƒ ‚ d S(   u  
        Treats the incoming bytestream as a raw file upload and returns
        a `DateAndFiles` object.

        `.data` will be None (we expect request body to be a file content).
        `.files` will be a `QueryDict` containing one 'file' element.
        u   requestu   encodingu   HTTP_CONTENT_TYPEu   CONTENT_TYPEu    u   HTTP_CONTENT_LENGTHu   CONTENT_LENGTHi    i   u   filei   i   i   uF   FileUpload parse error - none of upload handlers can handle the streamNI   €    iüÿÿ(   R   R   R   R)   R+   t   get_filenamet   intR"   t	   TypeErrorR   t   handle_raw_inputR   t
   chunk_sizet   minR   t   lent	   enumeratet   new_fileR   t   receive_data_chunkt   file_completeR   (   R   R   R   R   R-   R$   R.   R+   t   filenamet   content_typet   content_lengtht   handlert   resultt   xt   possible_sizesR5   t   chunkst   counterst   indext   chunkt   chunk_lengtht   file_obj(    (    sp   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/parsers.pyR
   ~   sX    	
			
		%	c         C  s    y | d d SWn t  k
 r# n Xy[ | d j } t | d j d ƒ ƒ } | d } d | k rp |  j | ƒ St | d ƒ SWn t t  t f k
 r› n Xd S(	   u   
        Detects the uploaded file name. First searches a 'filename' url kwarg.
        Then tries to parse Content-Disposition header.
        u   kwargsu   filenameu   requestu   HTTP_CONTENT_DISPOSITIONu   utf-8i   u	   filename*N(   t   KeyErrorR)   R   t   encodet   get_encoded_filenameR	   t   AttributeErrorR"   (   R   R   R   R   R.   t   dispositiont   filename_parm(    (    sp   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/parsers.pyR1   ¿   s    
c         C  sl   t  | d ƒ } y. | j d d ƒ \ } } } t j | ƒ } Wn' t t f k
 rg t  | d ƒ } n X| S(   uv   
        Handle encoded filenames per RFC6266. See also:
        http://tools.ietf.org/html/rfc2231#section-4
        u	   filename*u   'i   u   filename(   R	   t   splitt   urlparset   unquoteR"   t   LookupError(   R   RN   t   encoded_filenamet   charsett   langR<   (    (    sp   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/parsers.pyRK   Ó   s    N(   R   R   R   R   R   R
   R1   RK   (    (    (    sp   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/parsers.pyR0   x   s
   A	(!   R   t
   __future__R    R    t   django.confR   t   django.core.files.uploadhandlerR   t   django.httpR   t   django.http.multipartparserR   R,   R   R   R   t   django.utilsR   t   django.utils.encodingR	   t   django.utils.six.moves.urllibR
   RP   t   rest_frameworkR   t   rest_framework.exceptionsR   t   objectR   R   R   R(   R0   (    (    (    sp   /opt/seafile/seafile-server-5.1.3/seahub/thirdpart/djangorestframework-3.3.2-py2.7.egg/rest_framework/parsers.pyt   <module>   s$   