def put(self, path, data={}, content_type=MULTIPART_CONTENT,
         follow=False, **extra):
    """
    Requests a response from the server using POST.
    """
    if content_type is MULTIPART_CONTENT:
        post_data = encode_multipart(BOUNDARY, data)
    else:
        # Encode the content so that the byte representation is correct.
        match = CONTENT_TYPE_RE.match(content_type)
        if match:
            charset = match.group(1)
        else:
            charset = settings.DEFAULT_CHARSET
        post_data = smart_str(data, encoding=charset)

    parsed = urlparse(path)
    r = {
        'CONTENT_LENGTH': len(post_data),
        'CONTENT_TYPE':   content_type,
        'PATH_INFO':      urllib.unquote(parsed[2]),
        'QUERY_STRING':   parsed[4],
        'REQUEST_METHOD': 'PUT',
        'wsgi.input':     FakePayload(post_data),
    }
    r.update(extra)

    response = self.request(**r)
    if follow:
        response = self._handle_redirects(response)
    return response
Example #2
0
 def _get_path(self, parsed):
     # If there are parameters, add them
     if parsed[3]:
         return urllib.unquote(parsed[2] + ";" + parsed[3])
     else:
         return urllib.unquote(parsed[2])