def download(url, file_path = None): url_p = legacy.urlparse(url) path = url_p.path file_path = file_path or os.path.basename(path) file_path = file_path or DEFAULT_NAME response = legacy.urlopen(url) contents = response.read() file = open(file_path, "wb") try: file.write(contents) finally: file.close()
def redirect_to_login(next, login_url=None, redirect_field_name=REDIRECT_FIELD_NAME): """ Redirect the user to the login page, passing the given 'next' page. """ resolved_url = resolve_url(login_url or settings.LOGIN_URL) login_url_parts = list(urlparse(resolved_url)) if redirect_field_name: querystring = QueryDict(login_url_parts[4], mutable=True) querystring[redirect_field_name] = next login_url_parts[4] = querystring.urlencode(safe='/') return HttpResponseRedirect(urlunparse(login_url_parts))
def post_multipart(url, fields = (), files = ()): url_parsing = legacy.urlparse(url) host = url_parsing.hostname port = url_parsing.port path = url_parsing.path return _post_multipart(host, port, path, fields, files)