From c151adb1ee83eb34005a9883e748831e2b79de21 Mon Sep 17 00:00:00 2001 From: Michael Merickel Date: Tue, 15 Nov 2016 20:17:22 -0600 Subject: Revert "turn on warnings by default for ``pyramid.deprecation.RemoveInVersion19Warning``" This reverts commit 9c8d43a7101c2977f6bf388758f14c7c7fadcf71. --- pyramid/config/factories.py | 9 +--- pyramid/config/routes.py | 4 +- pyramid/config/settings.py | 17 +++++++ pyramid/config/views.py | 9 +--- pyramid/deprecation.py | 9 ---- pyramid/i18n.py | 18 ------- pyramid/interfaces.py | 12 ++--- pyramid/scripts/common.py | 12 +---- pyramid/security.py | 19 +++----- pyramid/session.py | 112 ++++++++++++++++++++++++++++++++++++++++++++ pyramid/traversal.py | 10 ++-- 11 files changed, 148 insertions(+), 83 deletions(-) delete mode 100644 pyramid/deprecation.py diff --git a/pyramid/config/factories.py b/pyramid/config/factories.py index 5c72ea73e..f0b6252ae 100644 --- a/pyramid/config/factories.py +++ b/pyramid/config/factories.py @@ -1,10 +1,6 @@ +from zope.deprecation import deprecated from zope.interface import implementer -from pyramid.deprecation import ( - RemoveInPyramid19Warning, - deprecated, -) - from pyramid.interfaces import ( IDefaultRootFactory, IRequestFactory, @@ -233,8 +229,7 @@ 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', - RemoveInPyramid19Warning) + 'add_request_method() with the property=True argument instead') @implementer(IRequestExtensions) diff --git a/pyramid/config/routes.py b/pyramid/config/routes.py index 5ec8fe2c0..90d4d47d2 100644 --- a/pyramid/config/routes.py +++ b/pyramid/config/routes.py @@ -1,7 +1,5 @@ import warnings -from pyramid.deprecation import RemoveInPyramid19Warning - from pyramid.compat import urlparse from pyramid.interfaces import ( IRequest, @@ -287,7 +285,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.'), - RemoveInPyramid19Warning, + DeprecationWarning, 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 af2b359c7..f9dbd752e 100644 --- a/pyramid/config/settings.py +++ b/pyramid/config/settings.py @@ -1,4 +1,5 @@ import os +import warnings from zope.interface import implementer @@ -152,3 +153,19 @@ 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 104254217..acdc00704 100644 --- a/pyramid/config/views.py +++ b/pyramid/config/views.py @@ -11,11 +11,6 @@ from zope.interface import ( ) from zope.interface.interfaces import IInterface -from pyramid.deprecation import ( - RemoveInPyramid19Warning, - RemoveInPyramid110Warning, -) - from pyramid.interfaces import ( IExceptionViewClassifier, IException, @@ -729,7 +724,7 @@ class ViewsConfiguratorMixin(object): 'See "Adding A Third Party View, Route, or Subscriber ' 'Predicate" in the "Hooks" chapter of the documentation ' 'for more information.'), - RemoveInPyramid19Warning, + DeprecationWarning, stacklevel=4, ) @@ -740,7 +735,7 @@ class ViewsConfiguratorMixin(object): 'instead or see "Checking CSRF Tokens Automatically" in the ' '"Sessions" chapter of the documentation for more ' 'information.'), - RemoveInPyramid110Warning, + DeprecationWarning, stacklevel=4, ) diff --git a/pyramid/deprecation.py b/pyramid/deprecation.py deleted file mode 100644 index dbb02720f..000000000 --- a/pyramid/deprecation.py +++ /dev/null @@ -1,9 +0,0 @@ -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 560be83d7..79209d342 100644 --- a/pyramid/i18n.py +++ b/pyramid/i18n.py @@ -10,10 +10,6 @@ from translationstring import ( from pyramid.compat import PY2 from pyramid.decorator import reify -from pyramid.deprecation import ( - RemoveInPyramid19Warning, - deprecated, -) from pyramid.interfaces import ( ILocalizer, @@ -170,13 +166,6 @@ 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 @@ -229,13 +218,6 @@ 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 33cf5408d..c1ddea63f 100644 --- a/pyramid/interfaces.py +++ b/pyramid/interfaces.py @@ -1,13 +1,11 @@ +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 @@ -426,8 +424,7 @@ 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.', - RemoveInPyramid19Warning, + 'renderers which have been split into their own packages.' ) class IViewMapper(Interface): @@ -851,8 +848,7 @@ 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.', - RemoveInPyramid19Warning, + 'See the "What\'s new In Pyramid 1.3" document for more details.' ) class IPEP302Loader(Interface): diff --git a/pyramid/scripts/common.py b/pyramid/scripts/common.py index f219e6d9a..fc141f6e2 100644 --- a/pyramid/scripts/common.py +++ b/pyramid/scripts/common.py @@ -1,11 +1,6 @@ import os -import logging -from logging.config import fileConfig -import sys -import warnings - from pyramid.compat import configparser -from pyramid.deprecation import RemoveInNextVersionWarning +from logging.config import fileConfig def parse_vars(args): """ @@ -34,11 +29,6 @@ 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 f3ad9ef65..82e6b73a9 100644 --- a/pyramid/security.py +++ b/pyramid/security.py @@ -1,9 +1,6 @@ +from zope.deprecation import deprecated from zope.interface import providedBy -from pyramid.deprecation import ( - RemoveInPyramid19Warning, - deprecated, -) from pyramid.interfaces import ( IAuthenticationPolicy, IAuthorizationPolicy, @@ -65,8 +62,7 @@ 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.', - RemoveInPyramid19Warning, + '"has_permission" method of the Pyramid request instead.' ) @@ -84,8 +80,7 @@ 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.', - RemoveInPyramid19Warning, + '"authenticated_userid" attribute of the Pyramid request instead.' ) def unauthenticated_userid(request): @@ -102,8 +97,7 @@ 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.', - RemoveInPyramid19Warning, + '"unauthenticated_userid" attribute of the Pyramid request instead.' ) def effective_principals(request): @@ -120,8 +114,7 @@ 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.', - RemoveInPyramid19Warning, + '"effective_principals" attribute of the Pyramid request instead.' ) def remember(request, userid=_marker, **kw): @@ -163,7 +156,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.', RemoveInPyramid19Warning) + 'argument instead.') userid = principal policy = _get_authentication_policy(request) if policy is None: diff --git a/pyramid/session.py b/pyramid/session.py index 513628ce7..47b80f617 100644 --- a/pyramid/session.py +++ b/pyramid/session.py @@ -5,6 +5,7 @@ import hmac import os import time +from zope.deprecation import deprecated from zope.interface import implementer from webob.cookies import SignedSerializer @@ -518,6 +519,117 @@ 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 5d49dce1d..963a76bb5 100644 --- a/pyramid/traversal.py +++ b/pyramid/traversal.py @@ -1,15 +1,12 @@ 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, @@ -814,8 +811,7 @@ 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.', - RemoveInPyramid19Warning, + 'See the "What\'s new In Pyramid 1.3" document for a further description.' ) @lru_cache(1000) -- cgit v1.2.3