summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/pyramid/authentication.py17
-rw-r--r--src/pyramid/compat.py13
-rw-r--r--src/pyramid/config/routes.py4
-rw-r--r--src/pyramid/config/views.py14
-rw-r--r--src/pyramid/csrf.py5
-rw-r--r--src/pyramid/encode.py7
-rw-r--r--src/pyramid/scripts/prequest.py4
-rw-r--r--tests/test_integration.py7
-rw-r--r--tests/test_traversal.py7
9 files changed, 28 insertions, 50 deletions
diff --git a/src/pyramid/authentication.py b/src/pyramid/authentication.py
index 7810745b5..05131a521 100644
--- a/src/pyramid/authentication.py
+++ b/src/pyramid/authentication.py
@@ -6,19 +6,14 @@ import hashlib
import base64
import re
import time as time_mod
+from urllib.parse import quote, unquote
import warnings
from zope.interface import implementer
from webob.cookies import CookieProfile
-from pyramid.compat import (
- url_unquote,
- url_quote,
- bytes_,
- ascii_native_,
- native_,
-)
+from pyramid.compat import bytes_, ascii_native_, native_
from pyramid.interfaces import IAuthenticationPolicy, IDebugLogger
@@ -724,11 +719,7 @@ class AuthTicket(object):
)
def cookie_value(self):
- v = '%s%08x%s!' % (
- self.digest(),
- int(self.time),
- url_quote(self.userid),
- )
+ v = '%s%08x%s!' % (self.digest(), int(self.time), quote(self.userid))
if self.tokens:
v += self.tokens + '!'
v += self.user_data
@@ -767,7 +758,7 @@ def parse_ticket(secret, ticket, ip, hashalg='md5'):
userid, data = ticket[digest_size + 8 :].split('!', 1)
except ValueError:
raise BadTicket('userid is not followed by !')
- userid = url_unquote(userid)
+ userid = unquote(userid)
if '!' in data:
tokens, user_data = data.split('!', 1)
else: # pragma: no cover (never generated)
diff --git a/src/pyramid/compat.py b/src/pyramid/compat.py
index 1010e93f1..10d3c4998 100644
--- a/src/pyramid/compat.py
+++ b/src/pyramid/compat.py
@@ -49,19 +49,6 @@ def native_(s, encoding='latin-1', errors='strict'):
return str(s, encoding, errors)
-from urllib import parse
-
-urlparse = parse
-from urllib.parse import quote as url_quote
-from urllib.parse import quote_plus as url_quote_plus
-from urllib.parse import unquote as url_unquote
-from urllib.parse import urlencode as url_encode
-from urllib.request import urlopen as url_open
-
-url_unquote_text = url_unquote
-url_unquote_native = url_unquote
-
-
# see PEP 3333 for why we encode WSGI PATH_INFO to latin-1 before
# decoding it to utf-8
def decode_path_info(path):
diff --git a/src/pyramid/config/routes.py b/src/pyramid/config/routes.py
index 52540c935..4b26b7481 100644
--- a/src/pyramid/config/routes.py
+++ b/src/pyramid/config/routes.py
@@ -1,7 +1,7 @@
import contextlib
+from urllib.parse import urlparse
import warnings
-from pyramid.compat import urlparse
from pyramid.interfaces import (
IRequest,
IRouteRequest,
@@ -358,7 +358,7 @@ class RoutesConfiguratorMixin(object):
# check for an external route; an external route is one which is
# is a full url (e.g. 'http://example.com/{id}')
- parsed = urlparse.urlparse(pattern)
+ parsed = urlparse(pattern)
external_url = pattern
if parsed.hostname:
diff --git a/src/pyramid/config/views.py b/src/pyramid/config/views.py
index 0039cd8fe..484c0d754 100644
--- a/src/pyramid/config/views.py
+++ b/src/pyramid/config/views.py
@@ -5,6 +5,7 @@ import operator
import os
import warnings
+from urllib.parse import quote, urljoin, urlparse, urlunparse
from webob.acceptparse import Accept
from zope.interface import Interface, implementedBy, implementer
from zope.interface.interfaces import IInterface
@@ -32,7 +33,7 @@ from pyramid.interfaces import (
from pyramid import renderers
from pyramid.asset import resolve_asset_spec
-from pyramid.compat import urlparse, url_quote, WIN
+from pyramid.compat import WIN
from pyramid.decorator import reify
@@ -77,9 +78,6 @@ from pyramid.config.predicates import (
sort_accept_offers,
)
-urljoin = urlparse.urljoin
-url_parse = urlparse.urlparse
-
DefaultViewMapper = DefaultViewMapper # bw-compat
preserve_view_attrs = preserve_view_attrs # bw-compat
requestonly = requestonly # bw-compat
@@ -2191,14 +2189,14 @@ class StaticURLInfo(object):
return request.route_url(route_name, **kw)
else:
app_url, qs, anchor = parse_url_overrides(request, kw)
- parsed = url_parse(url)
+ parsed = urlparse(url)
if not parsed.scheme:
- url = urlparse.urlunparse(
+ url = urlunparse(
parsed._replace(
scheme=request.environ['wsgi.url_scheme']
)
)
- subpath = url_quote(subpath)
+ subpath = quote(subpath)
result = urljoin(url, subpath)
return result + qs + anchor
@@ -2227,7 +2225,7 @@ class StaticURLInfo(object):
# make sure it ends with a slash
name = name + '/'
- if url_parse(name).netloc:
+ if urlparse(name).netloc:
# it's a URL
# url, spec, route_name
url = name
diff --git a/src/pyramid/csrf.py b/src/pyramid/csrf.py
index fba5d9baa..ece55ce10 100644
--- a/src/pyramid/csrf.py
+++ b/src/pyramid/csrf.py
@@ -1,10 +1,11 @@
+from urllib.parse import urlparse
import uuid
from webob.cookies import CookieProfile
from zope.interface import implementer
-from pyramid.compat import bytes_, urlparse, text_
+from pyramid.compat import bytes_, text_
from pyramid.exceptions import BadCSRFOrigin, BadCSRFToken
from pyramid.interfaces import ICSRFStoragePolicy
from pyramid.settings import aslist
@@ -303,7 +304,7 @@ def check_csrf_origin(request, trusted_origins=None, raises=True):
# Parse our origin so we we can extract the required information from
# it.
- originp = urlparse.urlparse(origin)
+ originp = urlparse(origin)
# Ensure that our Referer is also secure.
if originp.scheme != "https":
diff --git a/src/pyramid/encode.py b/src/pyramid/encode.py
index 1ed2c5a55..11d3a7787 100644
--- a/src/pyramid/encode.py
+++ b/src/pyramid/encode.py
@@ -1,7 +1,6 @@
-from pyramid.compat import (
- url_quote as _url_quote,
- url_quote_plus as _quote_plus,
-)
+from urllib.parse import quote as _url_quote
+from urllib.parse import quote_plus as _quote_plus
+
from pyramid.util import is_nonstr_iter
diff --git a/src/pyramid/scripts/prequest.py b/src/pyramid/scripts/prequest.py
index e8f5ff8b3..eb2032419 100644
--- a/src/pyramid/scripts/prequest.py
+++ b/src/pyramid/scripts/prequest.py
@@ -2,8 +2,8 @@ import base64
import argparse
import sys
import textwrap
+from urllib.parse import unquote
-from pyramid.compat import url_unquote
from pyramid.request import Request
from pyramid.scripts.common import get_config_loader
from pyramid.scripts.common import parse_vars
@@ -152,7 +152,7 @@ class PRequestCommand(object):
except ValueError:
qs = ''
- path = url_unquote(path)
+ path = unquote(path)
headers = {}
if self.args.login:
diff --git a/tests/test_integration.py b/tests/test_integration.py
index d57a7cf6e..0652d8ee8 100644
--- a/tests/test_integration.py
+++ b/tests/test_integration.py
@@ -4,6 +4,7 @@ import gc
import locale
import os
import unittest
+from urllib.parse import quote
from webtest import TestApp
from zope.interface import Interface
@@ -11,7 +12,7 @@ from pyramid.wsgi import wsgiapp
from pyramid.view import view_config
from pyramid.static import static_view
from pyramid.testing import skip_on
-from pyramid.compat import text_, url_quote
+from pyramid.compat import text_
from .pkgs.exceptionviewapp.models import AnException, NotAnException
@@ -108,7 +109,7 @@ class StaticAppBase(IntegrationBase):
os.makedirs(pathdir)
with open(path, 'wb') as fp:
fp.write(body)
- url = url_quote('/static/héhé/index.html')
+ url = quote('/static/héhé/index.html')
res = self.testapp.get(url, status=200)
self.assertEqual(res.body, body)
finally:
@@ -123,7 +124,7 @@ class StaticAppBase(IntegrationBase):
with open(path, 'wb') as fp:
fp.write(body)
try:
- url = url_quote('/static/héhé.html')
+ url = quote('/static/héhé.html')
res = self.testapp.get(url, status=200)
self.assertEqual(res.body, body)
finally:
diff --git a/tests/test_traversal.py b/tests/test_traversal.py
index ed5e0031e..252e99f6f 100644
--- a/tests/test_traversal.py
+++ b/tests/test_traversal.py
@@ -1,9 +1,10 @@
# -*- coding: utf-8 -*-
import unittest
+from urllib.parse import quote
from pyramid.testing import cleanUp
-from pyramid.compat import text_, native_, url_quote
+from pyramid.compat import text_, native_
class TraversalPathTests(unittest.TestCase):
@@ -14,7 +15,7 @@ class TraversalPathTests(unittest.TestCase):
def test_utf8(self):
la = b'La Pe\xc3\xb1a'
- encoded = url_quote(la)
+ encoded = quote(la)
decoded = text_(la, 'utf-8')
path = '/'.join([encoded, encoded])
result = self._callFUT(path)
@@ -24,7 +25,7 @@ class TraversalPathTests(unittest.TestCase):
from pyramid.exceptions import URLDecodeError
la = text_(b'La Pe\xc3\xb1a', 'utf-8').encode('utf-16')
- encoded = url_quote(la)
+ encoded = quote(la)
path = '/'.join([encoded, encoded])
self.assertRaises(URLDecodeError, self._callFUT, path)