�
ӵ Yc @ s� d Z d d l Z d d l Z d d l Z d d l m Z d Z e j d e e f � Z
d Z d � Z d � Z
d e d
� Z d S( s- Utilities for dealing with streamed requests.i����Ni ( t
exceptionss "[^"\\]*(?:\\.[^"\\]*)*"s* ;\s*(%s|[^\s;=]+)\s*(?:=\s*(%s|[^;]+))?\s*i c C sP xI t j | � D]8 } | j � \ } } | d k r t j j | � d Sq Wd S( Nt filenamei ( t _OPTION_HEADER_PIECE_REt finditert groupst ost patht splitt None( t content_dispositiont matcht kt v( ( sJ /usr/lib/python2.7/site-packages/requests_toolbelt/downloadutils/stream.pyt
_get_filename s
c C s� | o t j j | � } | r. | r. | } nW t | j j d d � � } | sa t j d � � n | r t j j | | � } n | } | S( s�
Given a response and a path, return a file path for a download.
If a ``path`` parameter is a directory, this function will parse the
``Content-Disposition`` header on the response to determine the name of the
file as reported by the server, and return a file path in the specified
directory.
If ``path`` is empty or None, this function will return a path relative
to the process' current working directory.
If path is a full file path, return it.
:param response: A Response object from requests
:type response: requests.models.Response
:param str path: Directory or file path.
:returns: full file path to download as
:rtype: str
:raises: :class:`requests_toolbelt.exceptions.StreamingError`
s content-dispositiont s'