summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Merickel <michael@merickel.org>2018-11-14 20:35:39 -0600
committerMichael Merickel <michael@merickel.org>2018-11-14 20:36:00 -0600
commita705f56c3ebf34f25ab567d85b7d5b421983aa4a (patch)
tree515498bb3f375807db95391b240a7df3ab247aca /src
parent0b570220d9f442700eb97c5a5c4eca6ab03a1ee4 (diff)
downloadpyramid-a705f56c3ebf34f25ab567d85b7d5b421983aa4a.tar.gz
pyramid-a705f56c3ebf34f25ab567d85b7d5b421983aa4a.tar.bz2
pyramid-a705f56c3ebf34f25ab567d85b7d5b421983aa4a.zip
rely on webob for request.path_info and request.scheme
Diffstat (limited to 'src')
-rw-r--r--src/pyramid/compat.py17
-rw-r--r--src/pyramid/config/testing.py4
-rw-r--r--src/pyramid/config/views.py4
-rw-r--r--src/pyramid/scripts/pviews.py2
-rw-r--r--src/pyramid/static.py2
-rw-r--r--src/pyramid/traversal.py19
-rw-r--r--src/pyramid/urldispatch.py13
-rw-r--r--src/pyramid/view.py4
8 files changed, 23 insertions, 42 deletions
diff --git a/src/pyramid/compat.py b/src/pyramid/compat.py
index 10d3c4998..30fc10395 100644
--- a/src/pyramid/compat.py
+++ b/src/pyramid/compat.py
@@ -1,7 +1,4 @@
-import inspect
import platform
-import sys
-import types
WIN = platform.system() == 'Windows'
@@ -47,17 +44,3 @@ def native_(s, encoding='latin-1', errors='strict'):
if isinstance(s, str):
return s
return str(s, encoding, errors)
-
-
-# see PEP 3333 for why we encode WSGI PATH_INFO to latin-1 before
-# decoding it to utf-8
-def decode_path_info(path):
- return path.encode('latin-1').decode('utf-8')
-
-
-# see PEP 3333 for why we decode the path to latin-1
-from urllib.parse import unquote_to_bytes
-
-
-def unquote_bytes_to_wsgi(bytestring):
- return unquote_to_bytes(bytestring).decode('latin-1')
diff --git a/src/pyramid/config/testing.py b/src/pyramid/config/testing.py
index bba5054e6..9c998840a 100644
--- a/src/pyramid/config/testing.py
+++ b/src/pyramid/config/testing.py
@@ -9,7 +9,7 @@ from pyramid.interfaces import (
from pyramid.renderers import RendererHelper
-from pyramid.traversal import decode_path_info, split_path_info
+from pyramid.traversal import split_path_info
from pyramid.config.actions import action_method
@@ -95,7 +95,7 @@ class TestingConfiguratorMixin(object):
self.context = context
def __call__(self, request):
- path = decode_path_info(request.environ['PATH_INFO'])
+ path = request.path_info
ob = resources[path]
traversed = split_path_info(path)
return {
diff --git a/src/pyramid/config/views.py b/src/pyramid/config/views.py
index 484c0d754..412e30304 100644
--- a/src/pyramid/config/views.py
+++ b/src/pyramid/config/views.py
@@ -2192,9 +2192,7 @@ class StaticURLInfo(object):
parsed = urlparse(url)
if not parsed.scheme:
url = urlunparse(
- parsed._replace(
- scheme=request.environ['wsgi.url_scheme']
- )
+ parsed._replace(scheme=request.scheme)
)
subpath = quote(subpath)
result = urljoin(url, subpath)
diff --git a/src/pyramid/scripts/pviews.py b/src/pyramid/scripts/pviews.py
index 891dc4709..d2a4bfa40 100644
--- a/src/pyramid/scripts/pviews.py
+++ b/src/pyramid/scripts/pviews.py
@@ -70,7 +70,7 @@ class PViewsCommand(object):
def _find_multi_routes(self, mapper, request):
infos = []
- path = request.environ['PATH_INFO']
+ path = request.path_info
# find all routes that match path, regardless of predicates
for route in mapper.get_routes():
match = route.match(path)
diff --git a/src/pyramid/static.py b/src/pyramid/static.py
index b300df9ee..e3561e93e 100644
--- a/src/pyramid/static.py
+++ b/src/pyramid/static.py
@@ -88,7 +88,7 @@ class static_view(object):
if self.use_subpath:
path_tuple = request.subpath
else:
- path_tuple = traversal_path_info(request.environ['PATH_INFO'])
+ path_tuple = traversal_path_info(request.path_info)
path = _secure_path(path_tuple)
if path is None:
diff --git a/src/pyramid/traversal.py b/src/pyramid/traversal.py
index 429b12e23..e846881f3 100644
--- a/src/pyramid/traversal.py
+++ b/src/pyramid/traversal.py
@@ -1,4 +1,6 @@
from functools import lru_cache
+from urllib.parse import unquote_to_bytes
+
from zope.interface import implementer
from zope.interface.interfaces import IInterface
@@ -9,12 +11,7 @@ from pyramid.interfaces import (
VH_ROOT_KEY,
)
-from pyramid.compat import (
- native_,
- ascii_native_,
- decode_path_info,
- unquote_bytes_to_wsgi,
-)
+from pyramid.compat import native_, ascii_native_
from pyramid.encode import url_quote
from pyramid.exceptions import URLDecodeError
@@ -543,6 +540,16 @@ def split_path_info(path):
return tuple(clean)
+# see PEP 3333 for why we encode to latin-1 then decode to utf-8
+def decode_path_info(path):
+ return path.encode('latin-1').decode('utf-8')
+
+
+# see PEP 3333 for why we decode the path to latin-1
+def unquote_bytes_to_wsgi(bytestring):
+ return unquote_to_bytes(bytestring).decode('latin-1')
+
+
_segment_cache = {}
diff --git a/src/pyramid/urldispatch.py b/src/pyramid/urldispatch.py
index 6d25b2dd5..6348ae7e2 100644
--- a/src/pyramid/urldispatch.py
+++ b/src/pyramid/urldispatch.py
@@ -3,7 +3,7 @@ from zope.interface import implementer
from pyramid.interfaces import IRoutesMapper, IRoute
-from pyramid.compat import native_, text_, decode_path_info
+from pyramid.compat import text_
from pyramid.exceptions import URLDecodeError
@@ -75,10 +75,9 @@ class RoutesMapper(object):
return self.routes[name].generate(kw)
def __call__(self, request):
- environ = request.environ
try:
# empty if mounted under a path in mod_wsgi, for example
- path = decode_path_info(environ['PATH_INFO'] or '/')
+ path = request.path_info or '/'
except KeyError:
path = '/'
except UnicodeDecodeError as e:
@@ -202,14 +201,10 @@ def _compile_route(route):
return None
d = {}
for k, v in m.groupdict().items():
- # k and v will be Unicode 2.6.4 and lower doesnt accept unicode
- # kwargs as **kw, so we explicitly cast the keys to native
- # strings in case someone wants to pass the result as **kw
- nk = native_(k, 'ascii')
if k == remainder:
- d[nk] = split_path_info(v)
+ d[k] = split_path_info(v)
else:
- d[nk] = v
+ d[k] = v
return d
gen = ''.join(gen)
diff --git a/src/pyramid/view.py b/src/pyramid/view.py
index 9e85d7281..944ad93ea 100644
--- a/src/pyramid/view.py
+++ b/src/pyramid/view.py
@@ -15,8 +15,6 @@ from pyramid.interfaces import (
IExceptionViewClassifier,
)
-from pyramid.compat import decode_path_info
-
from pyramid.exceptions import ConfigurationError, PredicateMismatch
from pyramid.httpexceptions import (
@@ -305,7 +303,7 @@ class AppendSlashNotFoundViewFactory(object):
self.redirect_class = redirect_class
def __call__(self, context, request):
- path = decode_path_info(request.environ['PATH_INFO'] or '/')
+ path = request.path_info
registry = request.registry
mapper = registry.queryUtility(IRoutesMapper)
if mapper is not None and not path.endswith('/'):