Commit 0d914d08 authored by Aymeric Augustin's avatar Aymeric Augustin
Browse files

[py3] Updated urllib/urllib2/urlparse imports.

Lots of functions were moved. Use explicit imports in all cases
to keey it easy to identify where the functions come from.
parent bdca5ea3
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
import urlparse
try:
    from urllib.parse import urlparse
except ImportError:     # Python 2
    from urlparse import urlparse
from functools import wraps
from django.conf import settings
from django.contrib.auth import REDIRECT_FIELD_NAME
@@ -21,9 +24,8 @@ def user_passes_test(test_func, login_url=None, redirect_field_name=REDIRECT_FIE
            path = request.build_absolute_uri()
            # If the login url is the same scheme and net location then just
            # use the path as the "next" url.
            login_scheme, login_netloc = urlparse.urlparse(login_url or
                                                        settings.LOGIN_URL)[:2]
            current_scheme, current_netloc = urlparse.urlparse(path)[:2]
            login_scheme, login_netloc = urlparse(login_url or settings.LOGIN_URL)[:2]
            current_scheme, current_netloc = urlparse(path)[:2]
            if ((not login_scheme or login_scheme == current_scheme) and
                (not login_netloc or login_netloc == current_netloc)):
                path = request.get_full_path()
+2 −4
Original line number Diff line number Diff line
from __future__ import unicode_literals

import urllib

from django.core.exceptions import ImproperlyConfigured
from django.core.mail import send_mail
from django.db import models
from django.db.models.manager import EmptyManager
from django.utils.crypto import get_random_string
from django.utils.encoding import smart_str
from django.utils.http import urlquote
from django.utils import six
from django.utils.translation import ugettext_lazy as _
from django.utils import timezone
@@ -268,7 +266,7 @@ class User(models.Model):
        return (self.username,)

    def get_absolute_url(self):
        return "/users/%s/" % urllib.quote(smart_str(self.username))
        return "/users/%s/" % urlquote(self.username)

    def is_anonymous(self):
        """
+5 −5
Original line number Diff line number Diff line
import os
import re
import urllib

from django.conf import settings
from django.contrib.sites.models import Site, RequestSite
@@ -10,6 +9,7 @@ from django.core.urlresolvers import reverse, NoReverseMatch
from django.http import QueryDict
from django.utils.encoding import force_unicode
from django.utils.html import escape
from django.utils.http import urlquote
from django.test import TestCase
from django.test.utils import override_settings

@@ -256,7 +256,7 @@ class LoginTest(AuthViewsTestCase):
            nasty_url = '%(url)s?%(next)s=%(bad_url)s' % {
                'url': login_url,
                'next': REDIRECT_FIELD_NAME,
                'bad_url': urllib.quote(bad_url),
                'bad_url': urlquote(bad_url),
            }
            response = self.client.post(nasty_url, {
                'username': 'testclient',
@@ -277,7 +277,7 @@ class LoginTest(AuthViewsTestCase):
            safe_url = '%(url)s?%(next)s=%(good_url)s' % {
                'url': login_url,
                'next': REDIRECT_FIELD_NAME,
                'good_url': urllib.quote(good_url),
                'good_url': urlquote(good_url),
            }
            response = self.client.post(safe_url, {
                    'username': 'testclient',
@@ -412,7 +412,7 @@ class LogoutTest(AuthViewsTestCase):
            nasty_url = '%(url)s?%(next)s=%(bad_url)s' % {
                'url': logout_url,
                'next': REDIRECT_FIELD_NAME,
                'bad_url': urllib.quote(bad_url),
                'bad_url': urlquote(bad_url),
            }
            self.login()
            response = self.client.get(nasty_url)
@@ -432,7 +432,7 @@ class LogoutTest(AuthViewsTestCase):
            safe_url = '%(url)s?%(next)s=%(good_url)s' % {
                'url': logout_url,
                'next': REDIRECT_FIELD_NAME,
                'good_url': urllib.quote(good_url),
                'good_url': urlquote(good_url),
            }
            self.login()
            response = self.client.get(safe_url)
+8 −5
Original line number Diff line number Diff line
import urlparse
try:
    from urllib.parse import urlparse, urlunparse
except ImportError:     # Python 2
    from urlparse import urlparse, urlunparse

from django.conf import settings
from django.core.urlresolvers import reverse
@@ -34,7 +37,7 @@ def login(request, template_name='registration/login.html',
    if request.method == "POST":
        form = authentication_form(data=request.POST)
        if form.is_valid():
            netloc = urlparse.urlparse(redirect_to)[1]
            netloc = urlparse(redirect_to)[1]

            # Use default setting if redirect_to is empty
            if not redirect_to:
@@ -80,7 +83,7 @@ def logout(request, next_page=None,
    auth_logout(request)
    redirect_to = request.REQUEST.get(redirect_field_name, '')
    if redirect_to:
        netloc = urlparse.urlparse(redirect_to)[1]
        netloc = urlparse(redirect_to)[1]
        # Security check -- don't allow redirection to a different host.
        if not (netloc and netloc != request.get_host()):
            return HttpResponseRedirect(redirect_to)
@@ -116,13 +119,13 @@ def redirect_to_login(next, login_url=None,
    if not login_url:
        login_url = settings.LOGIN_URL

    login_url_parts = list(urlparse.urlparse(login_url))
    login_url_parts = list(urlparse(login_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(urlparse.urlunparse(login_url_parts))
    return HttpResponseRedirect(urlunparse(login_url_parts))

# 4 views for password reset:
# - password_reset sends the mail
+6 −2
Original line number Diff line number Diff line
@@ -2,8 +2,12 @@
A few bits of helper functions for comment views.
"""

import urllib
import textwrap
try:
    from urllib.parse import urlencode
except ImportError:     # Python 2
    from urllib import urlencode

from django.http import HttpResponseRedirect
from django.core import urlresolvers
from django.shortcuts import render_to_response
@@ -33,7 +37,7 @@ def next_redirect(data, default, default_view, **get_kwargs):
            anchor = ''

        joiner = ('?' in next) and '&' or '?'
        next += joiner + urllib.urlencode(get_kwargs) + anchor
        next += joiner + urlencode(get_kwargs) + anchor
    return HttpResponseRedirect(next)

def confirmation_view(template, doc="Display a confirmation view."):
Loading