diff options
| -rw-r--r-- | CHANGES.txt | 3 | ||||
| -rw-r--r-- | HACKING.txt | 42 | ||||
| -rw-r--r-- | TODO.txt | 3 | ||||
| m--------- | docs/_themes | 0 | ||||
| -rw-r--r-- | docs/conf.py | 2 | ||||
| -rw-r--r-- | docs/index.rst | 3 | ||||
| -rw-r--r-- | docs/latexindex.rst | 40 | ||||
| -rw-r--r-- | docs/narr/install.rst | 245 | ||||
| -rw-r--r-- | docs/tutorials/bfg/index.rst | 2 | ||||
| -rw-r--r-- | docs/tutorials/modwsgi/index.rst | 2 | ||||
| -rw-r--r-- | docs/tutorials/wiki2/installation.rst | 6 | ||||
| -rw-r--r-- | hacking-tox.ini | 25 | ||||
| -rw-r--r-- | pyramid/i18n.py | 17 | ||||
| -rw-r--r-- | pyramid/request.py | 8 | ||||
| -rw-r--r-- | pyramid/tests/test_config/test_init.py | 11 | ||||
| -rw-r--r-- | pyramid/tests/test_i18n.py | 54 | ||||
| -rw-r--r-- | pyramid/tests/test_integration.py | 10 | ||||
| -rw-r--r-- | pyramid/tests/test_scripts/test_pdistreport.py | 1 | ||||
| -rw-r--r-- | pyramid/tests/test_url.py | 2 | ||||
| -rw-r--r-- | setup.py | 1 |
20 files changed, 258 insertions, 219 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index 48efad6d4..b805a12a0 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -4,6 +4,9 @@ Next Release Features -------- +- Add ``localizer`` property (reified) to the request. + See https://github.com/Pylons/pyramid/issues/508. + - Add ``pdistreport`` script, which prints the Python version in use, the Pyramid version in use, and the version number and location of all Python distributions currently installed. diff --git a/HACKING.txt b/HACKING.txt index 5b5dcc458..abfed6dab 100644 --- a/HACKING.txt +++ b/HACKING.txt @@ -16,13 +16,32 @@ checkout. - Check out a read-only copy of the Pyramid source:: - $ git clone git://github.com/Pylons/pyramid.git + $ git clone git://github.com/Pylons/pyramid.git . (alternately, create a writeable fork on GitHub and check that out). +Since pyramid is a framework and not an application, it can be +convenient to work against a sample application, preferably in its +own virtualenv. A quick way to achieve this is to (ab-)use ``tox`` +(http://codespeak.net/~hpk/tox/) with a custom configuration file that's part of +the checkout:: + + tox -c hacking-tox.ini + +This will create a python-2.7 based virtualenv named ``env27`` (pyramid's +``.gitconfig` ignores all top-level folders that start with ``env`` specifically +for this use case) and inside that a simple pyramid application named +``hacking`` that you can then fire up like so:: + + cd env27/hacking + ../bin/pserve development.ini + +Alternatively, if you don't want to install ``tox`` at this point, +you an achieve the same manually by following these steps: + - Create a virtualenv in which to install Pyramid:: - $ virtualenv2.6 --no-site-packages env + $ virtualenv env - Install ``setuptools-git`` into the virtualenv (for good measure, as we're using git to do version control):: @@ -93,9 +112,13 @@ Coding Style Running Tests -------------- -- To run tests for Pyramid on a single Python version, run ``python setup.py - test`` against the Python interpreter from virtualenv into which - you've ``setup.py develop``-ed Pyramid. +- To run all tests for Pyramid on a single Python version, run ``nosetests`` from + your development virtualenv (See *Using a Development Checkout* above). + +- To run individual tests (i.e. during development) you can use a regular + expression with the ``-t`` parameter courtesy of the `nose-selecttests + <https://pypi.python.org/pypi/nose-selecttests/>`_ plugin that's been installed (along with nose itself) via ``python setup.py dev``. The easiest usage is to + simply provide the verbatim name of the test you're working on. - To run the full set of Pyramid tests on all platforms, install ``tox`` (http://codespeak.net/~hpk/tox/) into a system Python. The ``tox`` console @@ -107,9 +130,16 @@ Running Tests example:: $ /usr/bin/easy_install tox - $ cd ~/hack-on-pyramid/pyramid + $ cd ~/hack-on-pyramid/ $ /usr/bin/tox +- The tests can also be run usign ``pytest`` (http://pytest.org/). This is + intended as a convenience for people who are more used or fond of ``pytest``. + Run the tests like so:: + + $ $VENV/bin/easy_install pytest + $ py.test --strict pyramid/ + Test Coverage ------------- @@ -56,9 +56,6 @@ Nice-to-Have app1" and "domain app1.localhost = app1"), ProxyPreserveHost and the nginx equivalent, preserving HTTPS URLs. -- Make "localizer" a property of request (instead of requiring - "get_localizer(request)"? - - Alias the stupid long default session factory name. - Debug option to print view matching decision (e.g. debug_viewlookup or so). diff --git a/docs/_themes b/docs/_themes -Subproject 8673c4a14f192c15f1949dc9862821e60f31604 +Subproject a181b85d4ca08fa109ee2786d4f1b5b17e9b458 diff --git a/docs/conf.py b/docs/conf.py index 4c6ed76ad..3a8076cdf 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -403,7 +403,7 @@ latex_elements = { 'wrapperclass': 'book', 'date': '', 'releasename': 'Version', - 'title': r'The Pyramid Web Application \newline Development Framework', + 'title': r'The Pyramid Web Framework', # 'pointsize':'12pt', # uncomment for 12pt version } diff --git a/docs/index.rst b/docs/index.rst index f899ddac3..d2a0008a8 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -129,7 +129,7 @@ platforms. tutorials/bfg/index.rst tutorials/modwsgi/index.rst -.. _api_documentation: +.. _html_api_documentation: API Documentation ================= @@ -204,5 +204,4 @@ Index and Glossary :hidden: glossary - latexindex diff --git a/docs/latexindex.rst b/docs/latexindex.rst index 13ba61648..eb14f5076 100644 --- a/docs/latexindex.rst +++ b/docs/latexindex.rst @@ -1,3 +1,5 @@ +:orphan: + .. _latexindex: ========================= @@ -28,8 +30,8 @@ Narrative Documentation narr/introduction narr/install - narr/configuration narr/firstapp + narr/configuration narr/project narr/startup narr/router @@ -50,6 +52,7 @@ Narrative Documentation narr/vhosting narr/testing narr/resources + narr/hellotraversal narr/muchadoabouttraversal narr/traversal narr/security @@ -60,6 +63,8 @@ Narrative Documentation narr/extending narr/advconfig narr/extconfig + narr/scaffolding + narr/upgrading narr/threadlocals narr/zca @@ -71,42 +76,21 @@ Tutorials .. toctree:: :maxdepth: 1 - tutorials/wiki/index.rst tutorials/wiki2/index.rst + tutorials/wiki/index.rst tutorials/bfg/index.rst tutorials/modwsgi/index.rst -.. _api_reference: +.. _api_documentation: -API Reference -@@@@@@@@@@@@@ +API Documentation +@@@@@@@@@@@@@@@@@ .. toctree:: :maxdepth: 1 + :glob: - api/authorization - api/authentication - api/config - api/events - api/exceptions - api/httpexceptions - api/i18n - api/interfaces - api/location - api/paster - api/registry - api/renderers - api/request - api/response - api/scripting - api/security - api/settings - api/testing - api/threadlocal - api/traversal - api/url - api/view - api/wsgi + api/* .. backmatter:: diff --git a/docs/narr/install.rst b/docs/narr/install.rst index ef5772f79..fb67b899b 100644 --- a/docs/narr/install.rst +++ b/docs/narr/install.rst @@ -9,49 +9,50 @@ Installing :app:`Pyramid` Before You Install ------------------ -You will need `Python <http://python.org>`_ version 2.6 or better to -run :app:`Pyramid`. +You will need `Python <http://python.org>`_ version 2.6 or better to run +:app:`Pyramid`. .. sidebar:: Python Versions - As of this writing, :app:`Pyramid` has been tested under Python 2.6, - Python 2.7, Python 3.2, and Python 3.3. :app:`Pyramid` does not - run under any version of Python before 2.6. + As of this writing, :app:`Pyramid` has been tested under Python 2.6, Python + 2.7, Python 3.2, and Python 3.3. :app:`Pyramid` does not run under any + version of Python before 2.6. -:app:`Pyramid` is known to run on all popular UNIX-like systems such as -Linux, Mac OS X, and FreeBSD as well as on Windows platforms. It is -also known to run on :term:`PyPy` (1.9+). +:app:`Pyramid` is known to run on all popular UNIX-like systems such as Linux, +Mac OS X, and FreeBSD as well as on Windows platforms. It is also known to run +on :term:`PyPy` (1.9+). -:app:`Pyramid` installation does not require the compilation of any -C code, so you need only a Python interpreter that meets the -requirements mentioned. +:app:`Pyramid` installation does not require the compilation of any C code, so +you need only a Python interpreter that meets the requirements mentioned. For Mac OS X Users ~~~~~~~~~~~~~~~~~~ From `Python.org <http://python.org/download/mac/>`_: - Python comes pre-installed on Mac OS X, but due to Apple's release - cycle, it's often one or even two years old. The overwhelming - recommendation of the "MacPython" community is to upgrade your - Python by downloading and installing a newer version from - `the Python standard release page <http://python.org/download/releases/>`_. + Python comes pre-installed on Mac OS X, but due to Apple's release cycle, + it's often one or even two years old. The overwhelming recommendation of + the "MacPython" community is to upgrade your Python by downloading and + installing a newer version from `the Python standard release page + <http://python.org/download/releases/>`_. -It is recommended to download one of the *installer* versions, unless you prefer to install your Python through a packgage manager (e.g., macports or homebrew) or to build your Python from source. +It is recommended to download one of the *installer* versions, unless you +prefer to install your Python through a packgage manager (e.g., macports or +homebrew) or to build your Python from source. -Unless you have a need for a specific earlier version, it is recommended -to install the latest 2.x or 3.x version of Python. +Unless you have a need for a specific earlier version, it is recommended to +install the latest 2.x or 3.x version of Python. -If you use an installer for your Python, then you can skip to the -section :ref:`installing_unix`. +If you use an installer for your Python, then you can skip to the section +:ref:`installing_unix`. If You Don't Yet Have A Python Interpreter (UNIX) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -If your system doesn't have a Python interpreter, and you're on UNIX, -you can either install Python using your operating system's package -manager *or* you can install Python from source fairly easily on any -UNIX system that has development tools. +If your system doesn't have a Python interpreter, and you're on UNIX, you can +either install Python using your operating system's package manager *or* you +can install Python from source fairly easily on any UNIX system that has +development tools. .. index:: pair: install; Python (from package, UNIX) @@ -59,9 +60,8 @@ UNIX system that has development tools. Package Manager Method ++++++++++++++++++++++ -You can use your system's "package manager" to install Python. -Each package manager is slightly different, but the "flavor" of -them is usually the same. +You can use your system's "package manager" to install Python. Each package +manager is slightly different, but the "flavor" of them is usually the same. For example, on a Debian or Ubuntu system, use the following command: @@ -82,28 +82,27 @@ invokable via ``python2.7`` from a shell prompt. Source Compile Method +++++++++++++++++++++ -It's useful to use a Python interpreter that *isn't* the "system" -Python interpreter to develop your software. The authors of -:app:`Pyramid` tend not to use the system Python for development -purposes; always a self-compiled one. Compiling Python is usually -easy, and often the "system" Python is compiled with options that -aren't optimal for web development. For an explanation, see +It's useful to use a Python interpreter that *isn't* the "system" Python +interpreter to develop your software. The authors of :app:`Pyramid` tend not +to use the system Python for development purposes; always a self-compiled one. +Compiling Python is usually easy, and often the "system" Python is compiled +with options that aren't optimal for web development. For an explanation, see https://github.com/Pylons/pyramid/issues/747. -To compile software on your UNIX system, typically you need -development tools. Often these can be installed via the package -manager. For example, this works to do so on an Ubuntu Linux system: +To compile software on your UNIX system, typically you need development tools. +Often these can be installed via the package manager. For example, this works +to do so on an Ubuntu Linux system: .. code-block:: text $ sudo apt-get install build-essential -On Mac OS X, installing `XCode -<http://developer.apple.com/tools/xcode/>`_ has much the same effect. +On Mac OS X, installing `XCode <http://developer.apple.com/tools/xcode/>`_ has +much the same effect. -Once you've got development tools installed on your system, you can -install a Python 2.7 interpreter from *source*, on the same system, -using the following commands: +Once you've got development tools installed on your system, you can install a +Python 2.7 interpreter from *source*, on the same system, using the following +commands: .. code-block:: text @@ -117,9 +116,8 @@ using the following commands: $ ./configure --prefix=$HOME/opt/Python-2.7.3 $ make && make install -Once these steps are performed, the Python interpreter will be -invokable via ``$HOME/opt/Python-2.7.3/bin/python`` from a shell -prompt. +Once these steps are performed, the Python interpreter will be invokable via +``$HOME/opt/Python-2.7.3/bin/python`` from a shell prompt. .. index:: pair: install; Python (from package, Windows) @@ -127,24 +125,21 @@ prompt. If You Don't Yet Have A Python Interpreter (Windows) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -If your Windows system doesn't have a Python interpreter, you'll need -to install it by downloading a Python 2.7-series interpreter -executable from `python.org's download section -<http://python.org/download/>`_ (the files labeled "Windows -Installer"). Once you've downloaded it, double click on the -executable and accept the defaults during the installation process. -You may also need to download and install the `Python for Windows -extensions <http://sourceforge.net/projects/pywin32/files/>`_. +If your Windows system doesn't have a Python interpreter, you'll need to +install it by downloading a Python 2.7-series interpreter executable from +`python.org's download section <http://python.org/download/>`_ (the files +labeled "Windows Installer"). Once you've downloaded it, double click on the +executable and accept the defaults during the installation process. You may +also need to download and install the Python for Windows extensions. .. warning:: - After you install Python on Windows, you may need to add the - ``C:\Python27`` directory to your environment's ``Path`` in order - to make it possible to invoke Python from a command prompt by - typing ``python``. To do so, right click ``My Computer``, select - ``Properties`` --> ``Advanced Tab`` --> ``Environment Variables`` - and add that directory to the end of the ``Path`` environment - variable. + After you install Python on Windows, you may need to add the ``C:\Python27`` + directory to your environment's ``Path`` in order to make it possible to + invoke Python from a command prompt by typing ``python``. To do so, right + click ``My Computer``, select ``Properties`` --> ``Advanced Tab`` --> + ``Environment Variables`` and add that directory to the end of the ``Path`` + environment variable. .. index:: single: installing on UNIX @@ -154,20 +149,19 @@ extensions <http://sourceforge.net/projects/pywin32/files/>`_. Installing :app:`Pyramid` on a UNIX System --------------------------------------------- -It is best practice to install :app:`Pyramid` into a "virtual" -Python environment in order to obtain isolation from any "system" -packages you've got installed in your Python version. This can be -done by using the :term:`virtualenv` package. Using a virtualenv will -also prevent :app:`Pyramid` from globally installing versions of -packages that are not compatible with your system Python. +It is best practice to install :app:`Pyramid` into a "virtual" Python +environment in order to obtain isolation from any "system" packages you've got +installed in your Python version. This can be done by using the +:term:`virtualenv` package. Using a virtualenv will also prevent +:app:`Pyramid` from globally installing versions of packages that are not +compatible with your system Python. To set up a virtualenv in which to install :app:`Pyramid`, first ensure that -:term:`setuptools` is installed. To do so, invoke -``import setuptools`` within the Python interpreter you'd like to run -:app:`Pyramid` under. +:term:`setuptools` is installed. To do so, invoke ``import setuptools`` within +the Python interpreter you'd like to run :app:`Pyramid` under. -The following command will not display anything if setuptools is -already installed: +The following command will not display anything if setuptools is already +installed: .. code-block:: text @@ -186,29 +180,28 @@ If ``import setuptools`` raises an :exc:`ImportError` as it does above, you will need to install setuptools manually. If you are using a "system" Python (one installed by your OS distributor or a -3rd-party packager such as Fink or MacPorts), you can usually install the -setuptools package by using your system's package manager. If -you cannot do this, or if you're using a self-installed version of Python, -you will need to install setuptools "by hand". Installing -setuptools "by hand" is always a reasonable thing to do, even -if your package manager already has a pre-chewed version of setuptools for -installation. +third-party packager such as Fink or MacPorts), you can usually install the +setuptools package by using your system's package manager. If you cannot do +this, or if you're using a self-installed version of Python, you will need to +install setuptools "by hand". Installing setuptools "by hand" is always a +reasonable thing to do, even if your package manager already has a pre-chewed +version of setuptools for installation. Installing Setuptools ~~~~~~~~~~~~~~~~~~~~~ To install setuptools by hand under Python 2, first download `ez_setup.py -<https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py>`_ then -invoke it using the Python interpreter into which you want to install setuptools. +<https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py>`_ then invoke +it using the Python interpreter into which you want to install setuptools. .. code-block:: text $ python ez_setup.py -Once this command is invoked, setuptools should be installed on your -system. If the command fails due to permission errors, you may need -to be the administrative user on your system to successfully invoke -the script. To remediate this, you may need to do: +Once this command is invoked, setuptools should be installed on your system. +If the command fails due to permission errors, you may need to be the +administrative user on your system to successfully invoke the script. To +remediate this, you may need to do: .. code-block:: text @@ -220,9 +213,9 @@ the script. To remediate this, you may need to do: Installing the ``virtualenv`` Package ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Once you've got setuptools installed, you should install the -:term:`virtualenv` package. To install the :term:`virtualenv` package into -your setuptools-enabled Python interpreter, use the ``easy_install`` command. +Once you've got setuptools installed, you should install the :term:`virtualenv` +package. To install the :term:`virtualenv` package into your +setuptools-enabled Python interpreter, use the ``easy_install`` command. .. warning:: @@ -235,16 +228,16 @@ your setuptools-enabled Python interpreter, use the ``easy_install`` command. Turing-complete. If you insist on using ``pyvenv``, you'll need to understand how to install - software such as ``setuptools`` into the virtual environment manually, - which this guide does not cover. + software such as ``setuptools`` into the virtual environment manually, which + this guide does not cover. .. code-block:: text $ easy_install virtualenv This command should succeed, and tell you that the virtualenv package is now -installed. If it fails due to permission errors, you may need to install it -as your system's administrative user. For example: +installed. If it fails due to permission errors, you may need to install it as +your system's administrative user. For example: .. code-block:: text @@ -263,36 +256,34 @@ you can then create a virtual environment. To do so, invoke the following: .. code-block:: text $ export VENV=~/env - $ virtualenv --no-site-packages $VENV + $ virtualenv $VENV New python executable in /home/foo/env/bin/python Installing setuptools.............done. -You can either follow the use of the environment variable, ``$VENV``, -or replace it with the root directory of the :term:`virtualenv`. -In that case, the `export` command can be skipped. -If you choose the former approach, ensure that it's an absolute path. +You can either follow the use of the environment variable, ``$VENV``, or +replace it with the root directory of the :term:`virtualenv`. In that case, the +`export` command can be skipped. If you choose the former approach, ensure that +it's an absolute path. .. warning:: - Using ``--no-site-packages`` when generating your - virtualenv is *very important*. This flag provides the necessary - isolation for running the set of packages required by - :app:`Pyramid`. If you do not specify ``--no-site-packages``, - it's possible that :app:`Pyramid` will not install properly into - the virtualenv, or, even if it does, may not run properly, - depending on the packages you've already got installed into your - Python's "main" site-packages dir. + Avoid using the ``--system-site-packages`` option when creating the + virtualenv unless you know what you are doing. For versions of virtualenv + prior to 1.7, make sure to use the ``--no-site-packages`` option, because + this option was formerly not the default and may produce undesirable + results. -.. warning:: *do not* use ``sudo`` to run the - ``virtualenv`` script. It's perfectly acceptable (and desirable) - to create a virtualenv as a normal user. +.. warning:: + + *do not* use ``sudo`` to run the ``virtualenv`` script. It's perfectly + acceptable (and desirable) to create a virtualenv as a normal user. Installing :app:`Pyramid` Into the Virtual Python Environment ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -After you've got your virtualenv installed, you may install -:app:`Pyramid` itself using the following commands: +After you've got your virtualenv installed, you may install :app:`Pyramid` +itself using the following commands: .. code-block:: text @@ -309,21 +300,22 @@ complete, as it downloads and installs a number of dependencies. Installing :app:`Pyramid` on a Windows System ------------------------------------------------- -You can use Pyramid on Windows under Python 2 or under Python 3. +You can use Pyramid on Windows under Python 2 or 3. -#. Install the most recent `Python 2.7.x or 3.3.x version +#. Download and install the most recent `Python 2.7.x or 3.3.x version <http://www.python.org/download/>`_ for your system. -#. Install the `Python for Windows extensions - <http://sourceforge.net/projects/pywin32/files/>`_. Make sure to - pick the right download for Python 2.7 or Python 3.3 and install it - using the same Python installation from the previous step. +#. Download and install the `Python for Windows extensions + <http://sourceforge.net/projects/pywin32/files/pywin32/>`_. Carefully read + the README.txt file at the end of the list of builds, and follow its + directions. Make sure you get the proper 32- or 64-bit build and Python + version. -#. Install latest :term:`setuptools` distribution into the Python you - obtained/installed/found in the step above: download `ez_setup.py - <https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py>`_ - and run it using the ``python`` interpreter of your Python 2.7 or 3.3 - installation using a command prompt: +#. Install latest :term:`setuptools` distribution into the Python from step 1 + above: download `ez_setup.py + <https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py>`_ and run + it using the ``python`` interpreter of your Python 2.7 or 3.3 installation + using a command prompt: .. code-block:: text @@ -348,17 +340,16 @@ You can use Pyramid on Windows under Python 2 or under Python 3. .. code-block:: text c:\> set VENV=c:\env - # modify the command according to the python version, e.g.: # for Python 2.7: - c:\> c:\Python27\Scripts\virtualenv --no-site-packages %VENV% + c:\> c:\Python27\Scripts\virtualenv %VENV% # for Python 3.3: - c:\> c:\Python33\Scripts\virtualenv --no-site-packages %VENV% + c:\> c:\Python33\Scripts\virtualenv %VENV% - You can either follow the use of the environment variable, ``%VENV%``, - or replace it with the root directory of the :term:`virtualenv`. - In that case, the `set` command can be skipped. - If you choose the former approach, ensure that it's an absolute path. + You can either follow the use of the environment variable, ``%VENV%``, or + replace it with the root directory of the :term:`virtualenv`. In that case, + the `set` command can be skipped. If you choose the former approach, ensure + that it's an absolute path. #. (Optional) Consider using ``%VENV%\Scripts\activate.bat`` to make your shell environment wired to use the virtualenv. diff --git a/docs/tutorials/bfg/index.rst b/docs/tutorials/bfg/index.rst index a50637279..1abb26466 100644 --- a/docs/tutorials/bfg/index.rst +++ b/docs/tutorials/bfg/index.rst @@ -60,7 +60,7 @@ Here's how to convert a :mod:`repoze.bfg` application to a .. code-block:: bash $ cd ~ - $ virtualenv --no-site-packages pyramidenv + $ virtualenv pyramidenv $ cd pyramidenv $ $VENV/bin/easy_install pyramid diff --git a/docs/tutorials/modwsgi/index.rst b/docs/tutorials/modwsgi/index.rst index e0021f8db..ddd968927 100644 --- a/docs/tutorials/modwsgi/index.rst +++ b/docs/tutorials/modwsgi/index.rst @@ -46,7 +46,7 @@ specific path information for commands and files. $ cd ~ $ mkdir modwsgi $ cd modwsgi - $ /usr/local/bin/virtualenv --no-site-packages env + $ /usr/local/bin/virtualenv env #. Install :app:`Pyramid` into the newly created virtualenv: diff --git a/docs/tutorials/wiki2/installation.rst b/docs/tutorials/wiki2/installation.rst index 17788cdde..e21bf7108 100644 --- a/docs/tutorials/wiki2/installation.rst +++ b/docs/tutorials/wiki2/installation.rst @@ -26,7 +26,7 @@ On UNIX .. code-block:: text $ export VENV=~/pyramidtut - $ virtualenv --no-site-packages $VENV + $ virtualenv $VENV New python executable in /home/foo/env/bin/python Installing setuptools.............done. @@ -46,13 +46,13 @@ Python 2.7: .. code-block:: text - c:\> c:\Python27\Scripts\virtualenv --no-site-packages %VENV% + c:\> c:\Python27\Scripts\virtualenv %VENV% Python 3.2: .. code-block:: text - c:\> c:\Python32\Scripts\virtualenv --no-site-packages %VENV% + c:\> c:\Python32\Scripts\virtualenv %VENV% Install Pyramid Into the Virtual Python Environment --------------------------------------------------- diff --git a/hacking-tox.ini b/hacking-tox.ini new file mode 100644 index 000000000..9520b7aef --- /dev/null +++ b/hacking-tox.ini @@ -0,0 +1,25 @@ +[tox] +envlist = + env27,ttw27-create,ttw27-install + +[testenv:env27] +envdir = env27 +basepython = python2.7 +usedevelop = True +deps = setuptools-git +commands = + python setup.py dev + +[testenv:ttw27-create] +envdir = env27 +usedevelop = True +changedir = env27 +commands = + pcreate -s starter hacking + +[testenv:ttw27-install] +envdir = env27 +usedevelop = True +changedir = env27/hacking +commands = + python setup.py develop diff --git a/pyramid/i18n.py b/pyramid/i18n.py index b4bc0eaa7..dc2c25f18 100644 --- a/pyramid/i18n.py +++ b/pyramid/i18n.py @@ -197,17 +197,15 @@ def make_localizer(current_locale_name, translation_directories): def get_localizer(request): """ Retrieve a :class:`pyramid.i18n.Localizer` object corresponding to the current request's locale name. """ - localizer = getattr(request, 'localizer', None) - if localizer is None: - # no locale object cached on request - try: - registry = request.registry - except AttributeError: - registry = get_current_registry() + # no locale object cached on request + try: + registry = request.registry + except AttributeError: + registry = get_current_registry() - current_locale_name = get_locale_name(request) - localizer = registry.queryUtility(ILocalizer, name=current_locale_name) + current_locale_name = get_locale_name(request) + localizer = registry.queryUtility(ILocalizer, name=current_locale_name) if localizer is None: # no localizer utility registered yet @@ -216,7 +214,6 @@ def get_localizer(request): registry.registerUtility(localizer, ILocalizer, name=current_locale_name) - request.localizer = localizer return localizer diff --git a/pyramid/request.py b/pyramid/request.py index 5bca5b1f0..5dedee4f1 100644 --- a/pyramid/request.py +++ b/pyramid/request.py @@ -24,6 +24,7 @@ from pyramid.compat import ( ) from pyramid.decorator import reify +from pyramid.i18n import get_localizer from pyramid.response import Response from pyramid.url import URLMethodsMixin from pyramid.util import InstancePropertyMixin @@ -383,6 +384,13 @@ class Request(BaseRequest, DeprecatedRequestMethodsMixin, URLMethodsMixin, def json_body(self): return json.loads(text_(self.body, self.charset)) + @reify + def localizer(self): + """ Convenience property to return a localizer by calling + :func:`pyramid.i18n.get_localizer`. """ + return get_localizer(self) + + def route_request_iface(name, bases=()): # zope.interface treats the __name__ as the __doc__ and changes __name__ # to None for interfaces that contain spaces if you do not pass a diff --git a/pyramid/tests/test_config/test_init.py b/pyramid/tests/test_config/test_init.py index 7c2880a18..b8cbbd676 100644 --- a/pyramid/tests/test_config/test_init.py +++ b/pyramid/tests/test_config/test_init.py @@ -1955,12 +1955,6 @@ class DummyRequest: self.params = {} self.cookies = {} -class DummyResponse: - status = '200 OK' - headerlist = () - app_iter = () - body = '' - class DummyThreadLocalManager(object): pushed = None popped = False @@ -1992,11 +1986,6 @@ class DummyRegistry(object): def queryUtility(self, *arg, **kw): return self.util -from pyramid.interfaces import IResponse -@implementer(IResponse) -class DummyResponse(object): - pass - from zope.interface import Interface class IOther(Interface): pass diff --git a/pyramid/tests/test_i18n.py b/pyramid/tests/test_i18n.py index bd4998b10..336e51b6a 100644 --- a/pyramid/tests/test_i18n.py +++ b/pyramid/tests/test_i18n.py @@ -230,39 +230,36 @@ class Test_get_localizer(unittest.TestCase): from pyramid.i18n import get_localizer return get_localizer(request) - def test_no_registry_on_request(self): + def test_default_localizer(self): + # `get_localizer` returns a default localizer for `en` + from pyramid.i18n import Localizer request = DummyRequest() - request.localizer = '123' result = self._callFUT(request) - self.assertEqual(result, '123') + self.assertEqual(result.__class__, Localizer) + self.assertEqual(result.locale_name, 'en') - def test_with_registry_on_request(self): + def test_custom_localizer_for_default_locale(self): from pyramid.threadlocal import get_current_registry + from pyramid.interfaces import ILocalizer registry = get_current_registry() + dummy = object() + registry.registerUtility(dummy, ILocalizer, name='en') request = DummyRequest() - request.localizer = '123' - request.registry = registry - result = self._callFUT(request) - self.assertEqual(result, '123') - - def test_locale_on_request(self): - request = DummyRequest() - request.localizer = 'abc' result = self._callFUT(request) - self.assertEqual(result, 'abc') + self.assertEqual(result, dummy) - def test_locale_from_registry(self): + def test_custom_localizer_for_custom_locale(self): from pyramid.threadlocal import get_current_registry from pyramid.interfaces import ILocalizer registry = get_current_registry() - locale = 'abc' - registry.registerUtility(locale, ILocalizer, name='en') + dummy = object() + registry.registerUtility(dummy, ILocalizer, name='ie') request = DummyRequest() - request.locale_name = 'en' + request.locale_name = 'ie' result = self._callFUT(request) - self.assertEqual(result, 'abc') + self.assertEqual(result, dummy) - def test_locale_from_mo(self): + def test_localizer_from_mo(self): from pyramid.threadlocal import get_current_registry from pyramid.interfaces import ITranslationDirectories from pyramid.i18n import Localizer @@ -278,7 +275,7 @@ class Test_get_localizer(unittest.TestCase): self.assertEqual(result.translate('Approve'), 'Approve') self.assertTrue(hasattr(result, 'pluralize')) - def test_locale_from_mo_bad_mo(self): + def test_localizer_from_mo_bad_mo(self): from pyramid.threadlocal import get_current_registry from pyramid.interfaces import ITranslationDirectories from pyramid.i18n import Localizer @@ -292,6 +289,23 @@ class Test_get_localizer(unittest.TestCase): self.assertEqual(result.translate('Approve', 'deformsite'), 'Approve') + def test_request_has_localizer(self): + from pyramid.threadlocal import get_current_registry + from pyramid.interfaces import ILocalizer + from pyramid.request import Request + # register mock localizer + dummy = object() + registry = get_current_registry() + registry.registerUtility(dummy, ILocalizer, name='en') + request = Request(environ={}) + self.assertEqual(request.localizer, dummy) + # `get_localizer` is only called once... + other = object() + registry.registerUtility(other, ILocalizer, name='en') + self.assertNotEqual(request.localizer, other) + self.assertEqual(request.localizer, dummy) + + class Test_default_locale_negotiator(unittest.TestCase): def setUp(self): cleanUp() diff --git a/pyramid/tests/test_integration.py b/pyramid/tests/test_integration.py index 66205e618..eda4ae9f3 100644 --- a/pyramid/tests/test_integration.py +++ b/pyramid/tests/test_integration.py @@ -72,7 +72,7 @@ class IntegrationBase(object): here = os.path.dirname(__file__) -class TestStaticAppBase(IntegrationBase): +class StaticAppBase(IntegrationBase): def test_basic(self): res = self.testapp.get('/minimal.pt', status=200) _assertBody(res.body, os.path.join(here, 'fixtures/minimal.pt')) @@ -198,10 +198,10 @@ class TestEventOnlySubscribers(IntegrationBase, unittest.TestCase): self.assertEqual(sorted(res.body.split()), [b'foobar', b'foobar2', b'foobaryup', b'foobaryup2']) -class TestStaticAppUsingAbsPath(TestStaticAppBase, unittest.TestCase): +class TestStaticAppUsingAbsPath(StaticAppBase, unittest.TestCase): package = 'pyramid.tests.pkgs.static_abspath' -class TestStaticAppUsingAssetSpec(TestStaticAppBase, unittest.TestCase): +class TestStaticAppUsingAssetSpec(StaticAppBase, unittest.TestCase): package = 'pyramid.tests.pkgs.static_assetspec' class TestStaticAppNoSubpath(unittest.TestCase): @@ -649,6 +649,10 @@ class AcceptContentTypeTest(unittest.TestCase): from webtest import TestApp self.testapp = TestApp(app) + def tearDown(self): + import pyramid.config + pyramid.config.global_registries.empty() + def test_ordering(self): res = self.testapp.get('/hello', headers={'Accept': 'application/json; q=1.0, text/plain; q=0.9'}, status=200) self.assertEqual(res.content_type, 'application/json') diff --git a/pyramid/tests/test_scripts/test_pdistreport.py b/pyramid/tests/test_scripts/test_pdistreport.py index a8316c0e5..e229667c5 100644 --- a/pyramid/tests/test_scripts/test_pdistreport.py +++ b/pyramid/tests/test_scripts/test_pdistreport.py @@ -1,5 +1,4 @@ import unittest -from pyramid.tests.test_scripts import dummy class TestPDistReportCommand(unittest.TestCase): def _callFUT(self, **kw): diff --git a/pyramid/tests/test_url.py b/pyramid/tests/test_url.py index 9841c143e..bf1c514c5 100644 --- a/pyramid/tests/test_url.py +++ b/pyramid/tests/test_url.py @@ -611,7 +611,6 @@ class TestURLMethodsMixin(unittest.TestCase): ('pyramid.tests:static/foo.css', request, {}) ) def test_static_url_abspath_integration_with_staticurlinfo(self): - import os from pyramid.interfaces import IStaticURLInfo from pyramid.config.views import StaticURLInfo info = StaticURLInfo() @@ -626,7 +625,6 @@ class TestURLMethodsMixin(unittest.TestCase): 'http://example.com:5432/absstatic/test_url.py') def test_static_url_noscheme_uses_scheme_from_request(self): - import os from pyramid.interfaces import IStaticURLInfo from pyramid.config.views import StaticURLInfo info = StaticURLInfo() @@ -65,6 +65,7 @@ docs_extras = [ testing_extras = tests_require + [ 'nose', + 'nose-selecttests', 'coverage', 'virtualenv', # for scaffolding tests ] |
