summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Merickel <michael@merickel.org>2016-11-14 22:34:28 -0600
committerMichael Merickel <michael@merickel.org>2016-11-15 19:48:08 -0600
commit9c8d43a7101c2977f6bf388758f14c7c7fadcf71 (patch)
treee4d66c77a8a5f05bec6b5fa3bbd40a742ef9b553
parentf5769191f4cd9e88cc8b4ce3b4a9f428204a26d6 (diff)
downloadpyramid-9c8d43a7101c2977f6bf388758f14c7c7fadcf71.tar.gz
pyramid-9c8d43a7101c2977f6bf388758f14c7c7fadcf71.tar.bz2
pyramid-9c8d43a7101c2977f6bf388758f14c7c7fadcf71.zip
turn on warnings by default for ``pyramid.deprecation.RemoveInVersion19Warning``
-rw-r--r--pyramid/config/factories.py9
-rw-r--r--pyramid/config/routes.py4
-rw-r--r--pyramid/config/settings.py17
-rw-r--r--pyramid/config/views.py9
-rw-r--r--pyramid/deprecation.py9
-rw-r--r--pyramid/i18n.py18
-rw-r--r--pyramid/interfaces.py12
-rw-r--r--pyramid/scripts/common.py12
-rw-r--r--pyramid/security.py19
-rw-r--r--pyramid/session.py112
-rw-r--r--pyramid/traversal.py10
11 files changed, 83 insertions, 148 deletions
diff --git a/pyramid/config/factories.py b/pyramid/config/factories.py
index f0b6252ae..5c72ea73e 100644
--- a/pyramid/config/factories.py
+++ b/pyramid/config/factories.py
@@ -1,6 +1,10 @@
-from zope.deprecation import deprecated
from zope.interface import implementer
+from pyramid.deprecation import (
+ RemoveInPyramid19Warning,
+ deprecated,
+)
+
from pyramid.interfaces import (
IDefaultRootFactory,
IRequestFactory,
@@ -229,7 +233,8 @@ class FactoriesConfiguratorMixin(object):
deprecated(
set_request_property,
'set_request_propery() is deprecated as of Pyramid 1.5; use '
- 'add_request_method() with the property=True argument instead')
+ 'add_request_method() with the property=True argument instead',
+ RemoveInPyramid19Warning)
@implementer(IRequestExtensions)
diff --git a/pyramid/config/routes.py b/pyramid/config/routes.py
index 90d4d47d2..5ec8fe2c0 100644
--- a/pyramid/config/routes.py
+++ b/pyramid/config/routes.py
@@ -1,5 +1,7 @@
import warnings
+from pyramid.deprecation import RemoveInPyramid19Warning
+
from pyramid.compat import urlparse
from pyramid.interfaces import (
IRequest,
@@ -285,7 +287,7 @@ class RoutesConfiguratorMixin(object):
'instead. See "Adding A Third Party View, Route, or '
'Subscriber Predicate" in the "Hooks" chapter of the '
'documentation for more information.'),
- DeprecationWarning,
+ RemoveInPyramid19Warning,
stacklevel=3
)
# these are route predicates; if they do not match, the next route
diff --git a/pyramid/config/settings.py b/pyramid/config/settings.py
index f9dbd752e..af2b359c7 100644
--- a/pyramid/config/settings.py
+++ b/pyramid/config/settings.py
@@ -1,5 +1,4 @@
import os
-import warnings
from zope.interface import implementer
@@ -153,19 +152,3 @@ class Settings(dict):
self.update(update)
- def __getattr__(self, name):
- try:
- val = self[name]
- # only deprecate on success; a probing getattr/hasattr should not
- # print this warning
- warnings.warn(
- 'Obtaining settings via attributes of the settings dictionary '
- 'is deprecated as of Pyramid 1.2; use settings["foo"] instead '
- 'of settings.foo',
- DeprecationWarning,
- 2
- )
- return val
- except KeyError:
- raise AttributeError(name)
-
diff --git a/pyramid/config/views.py b/pyramid/config/views.py
index acdc00704..104254217 100644
--- a/pyramid/config/views.py
+++ b/pyramid/config/views.py
@@ -11,6 +11,11 @@ from zope.interface import (
)
from zope.interface.interfaces import IInterface
+from pyramid.deprecation import (
+ RemoveInPyramid19Warning,
+ RemoveInPyramid110Warning,
+)
+
from pyramid.interfaces import (
IExceptionViewClassifier,
IException,
@@ -724,7 +729,7 @@ class ViewsConfiguratorMixin(object):
'See "Adding A Third Party View, Route, or Subscriber '
'Predicate" in the "Hooks" chapter of the documentation '
'for more information.'),
- DeprecationWarning,
+ RemoveInPyramid19Warning,
stacklevel=4,
)
@@ -735,7 +740,7 @@ class ViewsConfiguratorMixin(object):
'instead or see "Checking CSRF Tokens Automatically" in the '
'"Sessions" chapter of the documentation for more '
'information.'),
- DeprecationWarning,
+ RemoveInPyramid110Warning,
stacklevel=4,
)
diff --git a/pyramid/deprecation.py b/pyramid/deprecation.py
new file mode 100644
index 000000000..dbb02720f
--- /dev/null
+++ b/pyramid/deprecation.py
@@ -0,0 +1,9 @@
+from zope.deprecation import deprecated # noqa, internal api
+
+class RemoveInPyramid19Warning(DeprecationWarning):
+ pass
+
+class RemoveInPyramid110Warning(DeprecationWarning):
+ pass
+
+RemovedInNextVersionWarning = RemoveInPyramid19Warning
diff --git a/pyramid/i18n.py b/pyramid/i18n.py
index 79209d342..560be83d7 100644
--- a/pyramid/i18n.py
+++ b/pyramid/i18n.py
@@ -10,6 +10,10 @@ from translationstring import (
from pyramid.compat import PY2
from pyramid.decorator import reify
+from pyramid.deprecation import (
+ RemoveInPyramid19Warning,
+ deprecated,
+)
from pyramid.interfaces import (
ILocalizer,
@@ -166,6 +170,13 @@ def get_locale_name(request):
"""
return request.locale_name
+deprecated(
+ 'get_locale_name',
+ 'As of Pyramid 1.5 the "pyramid.i18n.get_locale_name" function is '
+ 'scheduled to be removed. Use "request.locale_name" instead.',
+ RemoveInPyramid19Warning,
+)
+
def make_localizer(current_locale_name, translation_directories):
""" Create a :class:`pyramid.i18n.Localizer` object
corresponding to the provided locale name from the
@@ -218,6 +229,13 @@ def get_localizer(request):
"""
return request.localizer
+deprecated(
+ 'get_localizer',
+ 'As of Pyramid 1.5 the "pyramid.i18n.get_localizer" method is scheduled '
+ 'to be removed. Use "request.locale_name" instead.',
+ RemoveInPyramid19Warning,
+)
+
class Translations(gettext.GNUTranslations, object):
"""An extended translation catalog class (ripped off from Babel) """
diff --git a/pyramid/interfaces.py b/pyramid/interfaces.py
index c1ddea63f..33cf5408d 100644
--- a/pyramid/interfaces.py
+++ b/pyramid/interfaces.py
@@ -1,11 +1,13 @@
-from zope.deprecation import deprecated
-
from zope.interface import (
Attribute,
Interface,
)
from pyramid.compat import PY2
+from pyramid.deprecation import (
+ RemoveInPyramid19Warning,
+ deprecated,
+)
# public API interfaces
@@ -424,7 +426,8 @@ deprecated(
'ITemplateRenderer',
'As of Pyramid 1.5 the, "pyramid.interfaces.ITemplateRenderer" interface '
'is scheduled to be removed. It was used by the Mako and Chameleon '
- 'renderers which have been split into their own packages.'
+ 'renderers which have been split into their own packages.',
+ RemoveInPyramid19Warning,
)
class IViewMapper(Interface):
@@ -848,7 +851,8 @@ deprecated(
'scheduled to be removed. Use the '
'"pyramid.config.Configurator.add_resource_url_adapter" method to register '
'a class that implements "pyramid.interfaces.IResourceURL" instead. '
- 'See the "What\'s new In Pyramid 1.3" document for more details.'
+ 'See the "What\'s new In Pyramid 1.3" document for more details.',
+ RemoveInPyramid19Warning,
)
class IPEP302Loader(Interface):
diff --git a/pyramid/scripts/common.py b/pyramid/scripts/common.py
index fc141f6e2..f219e6d9a 100644
--- a/pyramid/scripts/common.py
+++ b/pyramid/scripts/common.py
@@ -1,6 +1,11 @@
import os
-from pyramid.compat import configparser
+import logging
from logging.config import fileConfig
+import sys
+import warnings
+
+from pyramid.compat import configparser
+from pyramid.deprecation import RemoveInNextVersionWarning
def parse_vars(args):
"""
@@ -29,6 +34,11 @@ def setup_logging(config_uri, global_conf=None,
and ``here`` variables, similar to PasteDeploy config loading.
Extra defaults can optionally be specified as a dict in ``global_conf``.
"""
+ logging.captureWarnings(True)
+
+ if not sys.warnoptions:
+ warnings.simplefilter('default', RemoveInNextVersionWarning)
+
path = config_uri.split('#', 1)[0]
parser = configparser.ConfigParser()
parser.read([path])
diff --git a/pyramid/security.py b/pyramid/security.py
index 82e6b73a9..f3ad9ef65 100644
--- a/pyramid/security.py
+++ b/pyramid/security.py
@@ -1,6 +1,9 @@
-from zope.deprecation import deprecated
from zope.interface import providedBy
+from pyramid.deprecation import (
+ RemoveInPyramid19Warning,
+ deprecated,
+)
from pyramid.interfaces import (
IAuthenticationPolicy,
IAuthorizationPolicy,
@@ -62,7 +65,8 @@ deprecated(
'has_permission',
'As of Pyramid 1.5 the "pyramid.security.has_permission" API is now '
'deprecated. It will be removed in Pyramid 1.8. Use the '
- '"has_permission" method of the Pyramid request instead.'
+ '"has_permission" method of the Pyramid request instead.',
+ RemoveInPyramid19Warning,
)
@@ -80,7 +84,8 @@ deprecated(
'authenticated_userid',
'As of Pyramid 1.5 the "pyramid.security.authenticated_userid" API is now '
'deprecated. It will be removed in Pyramid 1.8. Use the '
- '"authenticated_userid" attribute of the Pyramid request instead.'
+ '"authenticated_userid" attribute of the Pyramid request instead.',
+ RemoveInPyramid19Warning,
)
def unauthenticated_userid(request):
@@ -97,7 +102,8 @@ deprecated(
'unauthenticated_userid',
'As of Pyramid 1.5 the "pyramid.security.unauthenticated_userid" API is '
'now deprecated. It will be removed in Pyramid 1.8. Use the '
- '"unauthenticated_userid" attribute of the Pyramid request instead.'
+ '"unauthenticated_userid" attribute of the Pyramid request instead.',
+ RemoveInPyramid19Warning,
)
def effective_principals(request):
@@ -114,7 +120,8 @@ deprecated(
'effective_principals',
'As of Pyramid 1.5 the "pyramid.security.effective_principals" API is '
'now deprecated. It will be removed in Pyramid 1.8. Use the '
- '"effective_principals" attribute of the Pyramid request instead.'
+ '"effective_principals" attribute of the Pyramid request instead.',
+ RemoveInPyramid19Warning,
)
def remember(request, userid=_marker, **kw):
@@ -156,7 +163,7 @@ def remember(request, userid=_marker, **kw):
'principal',
'The "principal" argument was deprecated in Pyramid 1.6. '
'It will be removed in Pyramid 1.9. Use the "userid" '
- 'argument instead.')
+ 'argument instead.', RemoveInPyramid19Warning)
userid = principal
policy = _get_authentication_policy(request)
if policy is None:
diff --git a/pyramid/session.py b/pyramid/session.py
index a3cbe5172..d00902f2a 100644
--- a/pyramid/session.py
+++ b/pyramid/session.py
@@ -5,7 +5,6 @@ import hmac
import os
import time
-from zope.deprecation import deprecated
from zope.interface import implementer
from webob.cookies import SignedSerializer
@@ -519,117 +518,6 @@ def BaseCookieSessionFactory(
return CookieSession
-
-def UnencryptedCookieSessionFactoryConfig(
- secret,
- timeout=1200,
- cookie_name='session',
- cookie_max_age=None,
- cookie_path='/',
- cookie_domain=None,
- cookie_secure=False,
- cookie_httponly=False,
- cookie_on_exception=True,
- signed_serialize=signed_serialize,
- signed_deserialize=signed_deserialize,
- ):
- """
- .. deprecated:: 1.5
- Use :func:`pyramid.session.SignedCookieSessionFactory` instead.
- Caveat: Cookies generated using ``SignedCookieSessionFactory`` are not
- compatible with cookies generated using
- ``UnencryptedCookieSessionFactory``, so existing user session data
- will be destroyed if you switch to it.
-
- Configure a :term:`session factory` which will provide unencrypted
- (but signed) cookie-based sessions. The return value of this
- function is a :term:`session factory`, which may be provided as
- the ``session_factory`` argument of a
- :class:`pyramid.config.Configurator` constructor, or used
- as the ``session_factory`` argument of the
- :meth:`pyramid.config.Configurator.set_session_factory`
- method.
-
- The session factory returned by this function will create sessions
- which are limited to storing fewer than 4000 bytes of data (as the
- payload must fit into a single cookie).
-
- Parameters:
-
- ``secret``
- A string which is used to sign the cookie.
-
- ``timeout``
- A number of seconds of inactivity before a session times out.
-
- ``cookie_name``
- The name of the cookie used for sessioning.
-
- ``cookie_max_age``
- The maximum age of the cookie used for sessioning (in seconds).
- Default: ``None`` (browser scope).
-
- ``cookie_path``
- The path used for the session cookie.
-
- ``cookie_domain``
- The domain used for the session cookie. Default: ``None`` (no domain).
-
- ``cookie_secure``
- The 'secure' flag of the session cookie.
-
- ``cookie_httponly``
- The 'httpOnly' flag of the session cookie.
-
- ``cookie_on_exception``
- If ``True``, set a session cookie even if an exception occurs
- while rendering a view.
-
- ``signed_serialize``
- A callable which takes more or less arbitrary Python data structure and
- a secret and returns a signed serialization in bytes.
- Default: ``signed_serialize`` (using pickle).
-
- ``signed_deserialize``
- A callable which takes a signed and serialized data structure in bytes
- and a secret and returns the original data structure if the signature
- is valid. Default: ``signed_deserialize`` (using pickle).
- """
-
- class SerializerWrapper(object):
- def __init__(self, secret):
- self.secret = secret
-
- def loads(self, bstruct):
- return signed_deserialize(bstruct, secret)
-
- def dumps(self, appstruct):
- return signed_serialize(appstruct, secret)
-
- serializer = SerializerWrapper(secret)
-
- return BaseCookieSessionFactory(
- serializer,
- cookie_name=cookie_name,
- max_age=cookie_max_age,
- path=cookie_path,
- domain=cookie_domain,
- secure=cookie_secure,
- httponly=cookie_httponly,
- timeout=timeout,
- reissue_time=0, # to keep session.accessed == session.renewed
- set_on_exception=cookie_on_exception,
- )
-
-deprecated(
- 'UnencryptedCookieSessionFactoryConfig',
- 'The UnencryptedCookieSessionFactoryConfig callable is deprecated as of '
- 'Pyramid 1.5. Use ``pyramid.session.SignedCookieSessionFactory`` instead.'
- ' Caveat: Cookies generated using SignedCookieSessionFactory are not '
- 'compatible with cookies generated using UnencryptedCookieSessionFactory, '
- 'so existing user session data will be destroyed if you switch to it.'
- )
-
def SignedCookieSessionFactory(
secret,
cookie_name='session',
diff --git a/pyramid/traversal.py b/pyramid/traversal.py
index 963a76bb5..5d49dce1d 100644
--- a/pyramid/traversal.py
+++ b/pyramid/traversal.py
@@ -1,12 +1,15 @@
import warnings
-from zope.deprecation import deprecated
-
from zope.interface import implementer
from zope.interface.interfaces import IInterface
from repoze.lru import lru_cache
+from pyramid.deprecation import (
+ RemoveInPyramid19Warning,
+ deprecated,
+)
+
from pyramid.interfaces import (
IResourceURL,
IRequestFactory,
@@ -811,7 +814,8 @@ deprecated(
'scheduled to be removed. Use the '
'"pyramid.config.Configurator.add_resource_url_adapter" method to register '
'a class that implements "pyramid.interfaces.IResourceURL" instead. '
- 'See the "What\'s new In Pyramid 1.3" document for a further description.'
+ 'See the "What\'s new In Pyramid 1.3" document for a further description.',
+ RemoveInPyramid19Warning,
)
@lru_cache(1000)