瀏覽代碼

[Django4.0 Warning] RemovedInDjango40Warning: django.utils.http.urlquote() is deprecated in favor of urllib.parse.quote()

ayush.goyal 4 年之前
父節點
當前提交
e27e0d9cef
共有 2 個文件被更改,包括 7 次插入6 次删除
  1. 3 2
      desktop/core/src/desktop/lib/export_csvxls.py
  2. 4 4
      desktop/core/src/desktop/middleware.py

+ 3 - 2
desktop/core/src/desktop/lib/export_csvxls.py

@@ -32,13 +32,14 @@ import tablib
 
 
 from django.http import StreamingHttpResponse, HttpResponse
 from django.http import StreamingHttpResponse, HttpResponse
 from django.utils.encoding import smart_str
 from django.utils.encoding import smart_str
-from django.utils.http import urlquote
 from desktop.lib import i18n
 from desktop.lib import i18n
 
 
 if sys.version_info[0] > 2:
 if sys.version_info[0] > 2:
   from io import BytesIO as string_io
   from io import BytesIO as string_io
+  from urllib.parse import quote
 else:
 else:
   from StringIO import StringIO as string_io
   from StringIO import StringIO as string_io
+  from django.utils.http import urlquote as quote
 
 
 
 
 LOG = logging.getLogger(__name__)
 LOG = logging.getLogger(__name__)
@@ -164,7 +165,7 @@ def make_response(generator, format, name, encoding=None, user_agent=None): #TOD
     format = format.encode('ascii')
     format = format.encode('ascii')
     resp['Content-Disposition'] = b'attachment; filename="%s.%s"' % (name, format)
     resp['Content-Disposition'] = b'attachment; filename="%s.%s"' % (name, format)
   except UnicodeEncodeError:
   except UnicodeEncodeError:
-    name = urlquote(name)
+    name = quote(name)
     if user_agent is not None and 'Firefox' in user_agent:
     if user_agent is not None and 'Firefox' in user_agent:
       # Preserving non-ASCII filename. See RFC https://tools.ietf.org/html/rfc6266#appendix-D, only FF works
       # Preserving non-ASCII filename. See RFC https://tools.ietf.org/html/rfc6266#appendix-D, only FF works
       resp['Content-Disposition'] = 'attachment; filename*="%s.%s"' % (name, format)
       resp['Content-Disposition'] = 'attachment; filename*="%s.%s"' % (name, format)

+ 4 - 4
desktop/core/src/desktop/middleware.py

@@ -43,7 +43,6 @@ from django.core import exceptions
 from django.http import HttpResponseNotAllowed, HttpResponseForbidden
 from django.http import HttpResponseNotAllowed, HttpResponseForbidden
 from django.urls import resolve
 from django.urls import resolve
 from django.http import HttpResponseRedirect, HttpResponse
 from django.http import HttpResponseRedirect, HttpResponse
-from django.utils.http import urlquote
 from django.utils.deprecation import MiddlewareMixin
 from django.utils.deprecation import MiddlewareMixin
 
 
 from hadoop import cluster
 from hadoop import cluster
@@ -66,9 +65,10 @@ from desktop.log.access import access_log, log_page_hit, access_warn
 if sys.version_info[0] > 2:
 if sys.version_info[0] > 2:
   from django.utils.translation import gettext as _
   from django.utils.translation import gettext as _
   from django.utils.http import url_has_allowed_host_and_scheme
   from django.utils.http import url_has_allowed_host_and_scheme
+  from urllib.parse import quote
 else:
 else:
   from django.utils.translation import ugettext as _
   from django.utils.translation import ugettext as _
-  from django.utils.http import is_safe_url as url_has_allowed_host_and_scheme
+  from django.utils.http import is_safe_url as url_has_allowed_host_and_scheme, urlquote as quote
 
 
 
 
 LOG = logging.getLogger(__name__)
 LOG = logging.getLogger(__name__)
@@ -384,11 +384,11 @@ class LoginAndPermissionMiddleware(MiddlewareMixin):
           'url': "%s?%s=%s" % (
           'url': "%s?%s=%s" % (
               settings.LOGIN_URL,
               settings.LOGIN_URL,
               REDIRECT_FIELD_NAME,
               REDIRECT_FIELD_NAME,
-              urlquote('/hue' + request.get_full_path().replace('is_embeddable=true', '').replace('&&', '&'))
+              quote('/hue' + request.get_full_path().replace('is_embeddable=true', '').replace('&&', '&'))
           )
           )
         }) # Remove embeddable so redirect from & to login works. Login page is not embeddable
         }) # Remove embeddable so redirect from & to login works. Login page is not embeddable
       else:
       else:
-        return HttpResponseRedirect("%s?%s=%s" % (settings.LOGIN_URL, REDIRECT_FIELD_NAME, urlquote(request.get_full_path())))
+        return HttpResponseRedirect("%s?%s=%s" % (settings.LOGIN_URL, REDIRECT_FIELD_NAME, quote(request.get_full_path())))
 
 
   def process_response(self, request, response):
   def process_response(self, request, response):
     if hasattr(request, 'ts') and hasattr(request, 'view_func'):
     if hasattr(request, 'ts') and hasattr(request, 'view_func'):