summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris McDonough <chrism@plope.com>2010-11-16 20:31:04 -0500
committerChris McDonough <chrism@plope.com>2010-11-16 20:31:04 -0500
commitb68aadc3867a95a6376bb2157cc93210eb62a104 (patch)
treee4b47fe1fc5e14edd8b9c0031544490c0a96ba6e
parentf4c3876685fa222eed96985bbdf37347ad362df2 (diff)
downloadpyramid-b68aadc3867a95a6376bb2157cc93210eb62a104.tar.gz
pyramid-b68aadc3867a95a6376bb2157cc93210eb62a104.tar.bz2
pyramid-b68aadc3867a95a6376bb2157cc93210eb62a104.zip
- The ``pyramid.settings.get_settings`` API is now deprecated. Use
``pyramid.threadlocals.get_registry().settings`` instead or use the ``settings`` attribute of the registry available from the request (``request.registry.settings``).
-rw-r--r--CHANGES.txt7
-rw-r--r--docs/narr/i18n.rst9
-rw-r--r--docs/narr/static.rst31
-rw-r--r--pyramid/configuration.py23
-rw-r--r--pyramid/settings.py13
-rw-r--r--pyramid/testing.py8
-rw-r--r--pyramid/tests/test_settings.py4
7 files changed, 58 insertions, 37 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index f25d0e83f..d132b4e71 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -8,6 +8,13 @@ Bug Fixes
``pyramid.chameleon_zpt`` of ``get_renderer``, ``get_template``,
``render_template``, and ``render_template_to_response``.
+Deprecations
+------------
+
+- The ``pyramid.settings.get_settings`` API is now deprecated. Use
+ ``pyramid.threadlocals.get_registry().settings`` instead or use the
+ ``settings`` attribute of the registry available from the request
+ (``request.registry.settings``).
1.0a3 (2010-11-16)
==================
diff --git a/docs/narr/i18n.rst b/docs/narr/i18n.rst
index 703883fb2..9e2071872 100644
--- a/docs/narr/i18n.rst
+++ b/docs/narr/i18n.rst
@@ -773,8 +773,8 @@ If this setting is supplied within the :app:`Pyramid` application
.. code-block:: python
:linenos:
- from pyramid.setttings import get_settings
- settings = get_settings()
+ from pyramid.threadlocal import get_current_registry
+ settings = get_current_registry().settings
default_locale_name = settings['default_locale_name']
"Detecting" Available Languages
@@ -822,8 +822,9 @@ Then as a part of the code of a custom :term:`locale negotiator`:
.. code-block:: py
- from pyramid.settings import get_settings
- languages = get_settings()['available_languages'].split()
+ from pyramid.threadlocal import get_current_registry
+ settings = get_current_registry().settings
+ languages = settings['available_languages'].split()
This is only a suggestion. You can create your own "available
languages" configuration scheme as necessary.
diff --git a/docs/narr/static.rst b/docs/narr/static.rst
index efeabd012..a01cbbabf 100644
--- a/docs/narr/static.rst
+++ b/docs/narr/static.rst
@@ -69,22 +69,21 @@ when generating a URL using :func:`pyramid.url.static_url`.
.. note::
Using :func:`pyramid.url.static_url` in conjunction with a
- :meth:`pyramid.configuration.Configurator.add_static_view` makes
- it possible to put static media on a separate webserver during
- production (if the ``name`` argument to
- :meth:`pyramid.configuration.Configurator.add_static_view` is a
- URL), while keeping static media package-internal and served by the
- development webserver during development (if the ``name`` argument
- to :meth:`pyramid.configuration.Configurator.add_static_view` is
- a view name). To create such a circumstance, we suggest using the
- :func:`pyramid.settings.get_settings` API in conjunction with a
- setting in the application ``.ini`` file named ``media_location``.
- Then set the value of ``media_location`` to either a view name or a
- URL depending on whether the application is being run in
- development or in production (use a different `.ini`` file for
- production than you do for development). This is just a suggestion
- for a pattern; any setting name other than ``media_location`` could
- be used.
+ :meth:`pyramid.configuration.Configurator.add_static_view` makes it
+ possible to put static media on a separate webserver during production (if
+ the ``name`` argument to
+ :meth:`pyramid.configuration.Configurator.add_static_view` is a URL),
+ while keeping static media package-internal and served by the development
+ webserver during development (if the ``name`` argument to
+ :meth:`pyramid.configuration.Configurator.add_static_view` is a view
+ name). To create such a circumstance, we suggest using the
+ :attr:`pyramid.registry.Registry.settings` API in conjunction with a
+ setting in the application ``.ini`` file named ``media_location``. Then
+ set the value of ``media_location`` to either a view name or a URL
+ depending on whether the application is being run in development or in
+ production (use a different `.ini`` file for production than you do for
+ development). This is just a suggestion for a pattern; any setting name
+ other than ``media_location`` could be used.
For example, :meth:`pyramid.configuration.Configurator.add_static_view` may
be fed a ``name`` argument which is ``http://example.com/images``:
diff --git a/pyramid/configuration.py b/pyramid/configuration.py
index cee65a982..3d1530406 100644
--- a/pyramid/configuration.py
+++ b/pyramid/configuration.py
@@ -570,11 +570,10 @@ class Configurator(object):
return subscriber
def add_settings(self, settings=None, **kw):
- """Augment the ``settings`` argument passed in to the
- Configurator constructor with one or more 'setting' key/value
- pairs. A setting is a single key/value pair in the
- dictionary-ish object returned from the API
- :func:`pyramid.settings.get_settings` and
+ """Augment the ``settings`` argument passed in to the Configurator
+ constructor with one or more 'setting' key/value pairs. A setting is
+ a single key/value pair in the dictionary-ish object returned from
+ the API :attr:`pyramid.registry.Registry.settings` and
:meth:`pyramid.configuration.Configurator.get_settings`.
You may pass a dictionary::
@@ -585,11 +584,10 @@ class Configurator(object):
config.add_settings(external_uri='http://example.com')
- This function is useful when you need to test code that calls the
- :func:`pyramid.settings.get_settings` API (or the
- :meth:`pyramid.configuration.Configurator.get_settings` API or
- accesses ``request.settings``) and which uses return values from that
- API.
+ This function is useful when you need to test code that accesses the
+ :attr:`pyramid.registry.Registry.settings` API (or the
+ :meth:`pyramid.configuration.Configurator.get_settings` API) and
+ which uses values from that API.
"""
if settings is None:
settings = {}
@@ -610,9 +608,8 @@ class Configurator(object):
.. note:: For backwards compatibility, dictionary keys can also be
looked up as attributes of the settings object.
- .. note:: the :class:`pyramid.settings.get_settings` and function
- performs the same duty and the settings attribute can also be
- accessed as :attr:`pyramid.registry.Registry.settings`
+ .. note:: the :attr:`pyramid.registry.Registry.settings` API
+ performs the same duty.
"""
return self.registry.settings
diff --git a/pyramid/settings.py b/pyramid/settings.py
index 96ad3336a..d6b0a6470 100644
--- a/pyramid/settings.py
+++ b/pyramid/settings.py
@@ -1,5 +1,6 @@
import os
+from zope.deprecation import deprecated
from zope.interface import implements
from pyramid.interfaces import ISettings
@@ -75,10 +76,22 @@ def get_settings():
.. note:: the
:class:`pyramid.configuration.Configurator.get_settings` method
performs the same duty.
+
+ .. warning:: This method is deprecated as of Pyramid 1.0. Use
+ ``pyramid.threadlocals.get_registry().settings`` instead or use the
+ ``settings`` attribute of the registry available from the request
+ (``request.registry.settings``).
"""
reg = get_current_registry()
return reg.settings
+deprecated(
+ 'get_settings',
+ '(pyramid.settings.get_settings is deprecated as of Pyramid 1.0. Use'
+ '``pyramid.threadlocals.get_registry().settings`` instead or use the '
+ '``settings`` attribute of the registry available from the request '
+ '(``request.registry.settings``)).')
+
def asbool(s):
""" Return the boolean value ``True`` if the case-lowered value of string
input ``s`` is any of ``t``, ``true``, ``y``, ``on``, or ``1``, otherwise
diff --git a/pyramid/testing.py b/pyramid/testing.py
index e8e843bff..84ab77935 100644
--- a/pyramid/testing.py
+++ b/pyramid/testing.py
@@ -277,7 +277,7 @@ def registerRoute(pattern, name, factory=None):
def registerSettings(dictarg=None, **kw):
"""Register one or more 'setting' key/value pairs. A setting is
a single key/value pair in the dictionary-ish object returned from
- the API :func:`pyramid.settings.get_settings`.
+ the API :attr:`pyramid.registry.Registry.settings`.
You may pass a dictionary::
@@ -287,9 +287,9 @@ def registerSettings(dictarg=None, **kw):
registerSettings(external_uri='http://example.com')
- Use of this function is required when you need to test code that
- calls the :func:`pyramid.settings.get_settings` API and which
- uses return values from that API.
+ Use of this function is required when you need to test code that calls
+ the :attr:`pyramid.registry.Registry.settings` API and which uses return
+ values from that API.
.. warning:: This API is deprecated as of :app:`Pyramid` 1.0.
Instead use the
diff --git a/pyramid/tests/test_settings.py b/pyramid/tests/test_settings.py
index 12b1174de..49c1e928f 100644
--- a/pyramid/tests/test_settings.py
+++ b/pyramid/tests/test_settings.py
@@ -184,9 +184,13 @@ class TestGetSettings(unittest.TestCase):
registry = Registry('testing')
self.config = Configurator(registry=registry)
self.config.begin()
+ from zope.deprecation import __show__
+ __show__.off()
def tearDown(self):
self.config.end()
+ from zope.deprecation import __show__
+ __show__.on()
def _callFUT(self):
from pyramid.settings import get_settings